author | zecke <zecke> | 2002-03-21 00:26:39 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-03-21 00:26:39 (UTC) |
commit | 8bfe366ce8667addc539f11fc560250c306340ae (patch) (unidiff) | |
tree | 4b890a47d86621d3e1f0aacde2485457862f02c8 | |
parent | e8f15a98c611b0c6030e8210672b249b42107526 (diff) | |
download | opie-8bfe366ce8667addc539f11fc560250c306340ae.zip opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.gz opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.bz2 |
Move todolist to tododb
Please test todolist
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 27 | ||||
-rw-r--r-- | core/pim/todo/todo.pro | 2 | ||||
-rw-r--r-- | core/pim/todo/todoentryimpl.cpp | 53 | ||||
-rw-r--r-- | core/pim/todo/todoentryimpl.h | 8 | ||||
-rw-r--r-- | core/pim/todo/todotable.cpp | 274 | ||||
-rw-r--r-- | core/pim/todo/todotable.h | 21 | ||||
-rw-r--r-- | libopie/todoevent.cpp | 22 | ||||
-rw-r--r-- | libopie/todoevent.h | 3 |
8 files changed, 134 insertions, 276 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index 6709811..f3afa5f 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -25,4 +25,7 @@ | |||
25 | #include "todotable.h" | 25 | #include "todotable.h" |
26 | 26 | ||
27 | #include <opie/tododb.h> | ||
28 | #include <opie/todovcalresource.h> | ||
29 | |||
27 | #include <qpe/qpeapplication.h> | 30 | #include <qpe/qpeapplication.h> |
28 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
@@ -33,5 +36,5 @@ | |||
33 | #include <qpe/qpemessagebox.h> | 36 | #include <qpe/qpemessagebox.h> |
34 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
35 | #include <qpe/task.h> | 38 | //#include <qpe/task.h> |
36 | #include <qpe/qpetoolbar.h> | 39 | #include <qpe/qpetoolbar.h> |
37 | 40 | ||
@@ -216,5 +219,5 @@ void TodoWindow::slotNew() | |||
216 | NewTaskDialog e( id, this, 0, TRUE ); | 219 | NewTaskDialog e( id, this, 0, TRUE ); |
217 | 220 | ||
218 | Task todo; | 221 | ToDoEvent todo; |
219 | 222 | ||
220 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 223 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
@@ -222,9 +225,9 @@ void TodoWindow::slotNew() | |||
222 | #endif | 225 | #endif |
223 | int ret = e.exec(); | 226 | int ret = e.exec(); |
224 | 227 | qWarning("finished" ); | |
225 | if ( ret == QDialog::Accepted ) { | 228 | if ( ret == QDialog::Accepted ) { |
226 | table->setPaintingEnabled( false ); | 229 | table->setPaintingEnabled( false ); |
227 | todo = e.todoEntry(); | 230 | todo = e.todoEntry(); |
228 | todo.assignUid(); | 231 | //todo.assignUid(); |
229 | table->addEntry( todo ); | 232 | table->addEntry( todo ); |
230 | table->setPaintingEnabled( true ); | 233 | table->setPaintingEnabled( true ); |
@@ -276,5 +279,5 @@ void TodoWindow::slotEdit() | |||
276 | } | 279 | } |
277 | 280 | ||
278 | Task todo = table->currentEntry(); | 281 | ToDoEvent todo = table->currentEntry(); |
279 | 282 | ||
280 | NewTaskDialog e( todo, this, 0, TRUE ); | 283 | NewTaskDialog e( todo, this, 0, TRUE ); |
@@ -350,6 +353,5 @@ void TodoWindow::populateCategories() | |||
350 | completedAction->setOn( table->showCompleted() ); | 353 | completedAction->setOn( table->showCompleted() ); |
351 | 354 | ||
352 | int id, | 355 | int id, rememberId; |
353 | rememberId; | ||
354 | id = 1; | 356 | id = 1; |
355 | catMenu->insertItem( tr( "All Categories" ), id++ ); | 357 | catMenu->insertItem( tr( "All Categories" ), id++ ); |
@@ -444,6 +446,7 @@ void TodoWindow::setDocument( const QString &filename ) | |||
444 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; | 446 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; |
445 | 447 | ||
446 | QValueList<Task> tl = Task::readVCalendar( filename ); | 448 | ToDoDB todoDB(filename, new ToDoVCalResource() ); |
447 | for( QValueList<Task>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | 449 | QValueList<ToDoEvent> tl = todoDB.rawToDos(); |
450 | for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | ||
448 | table->addEntry( *it ); | 451 | table->addEntry( *it ); |
449 | } | 452 | } |
@@ -455,7 +458,9 @@ void TodoWindow::slotBeam() | |||
455 | { | 458 | { |
456 | unlink( beamfile ); // delete if exists | 459 | unlink( beamfile ); // delete if exists |
457 | Task c = table->currentEntry(); | 460 | ToDoEvent c = table->currentEntry(); |
458 | mkdir("/tmp/obex/", 0755); | 461 | mkdir("/tmp/obex/", 0755); |
459 | Task::writeVCalendar( beamfile, c ); | 462 | ToDoDB todoDB( beamfile, new ToDoVCalResource() ); |
463 | todoDB.addEvent( c ); | ||
464 | todoDB.save(); | ||
460 | Ir *ir = new Ir( this ); | 465 | Ir *ir = new Ir( this ); |
461 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 466 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
diff --git a/core/pim/todo/todo.pro b/core/pim/todo/todo.pro index 18f70fe..7f9ddd5 100644 --- a/core/pim/todo/todo.pro +++ b/core/pim/todo/todo.pro | |||
@@ -15,5 +15,5 @@ TARGET = todolist | |||
15 | INCLUDEPATH += $(OPIEDIR)/include | 15 | INCLUDEPATH += $(OPIEDIR)/include |
16 | DEPENDPATH+= $(OPIEDIR)/include | 16 | DEPENDPATH+= $(OPIEDIR)/include |
17 | LIBS += -lqpe | 17 | LIBS += -lqpe -lopie |
18 | 18 | ||
19 | TRANSLATIONS = ../i18n/de/todolist.ts | 19 | TRANSLATIONS = ../i18n/de/todolist.ts |
diff --git a/core/pim/todo/todoentryimpl.cpp b/core/pim/todo/todoentryimpl.cpp index c957715..1dc1d44 100644 --- a/core/pim/todo/todoentryimpl.cpp +++ b/core/pim/todo/todoentryimpl.cpp | |||
@@ -21,10 +21,13 @@ | |||
21 | #include "todoentryimpl.h" | 21 | #include "todoentryimpl.h" |
22 | 22 | ||
23 | #include <opie/todoevent.h> | ||
24 | #include <opie/tododb.h> | ||
25 | |||
23 | #include <qpe/categoryselect.h> | 26 | #include <qpe/categoryselect.h> |
24 | #include <qpe/datebookmonth.h> | 27 | #include <qpe/datebookmonth.h> |
25 | #include <qpe/global.h> | 28 | #include <qpe/global.h> |
26 | #include <qpe/imageedit.h> | 29 | #include <qpe/imageedit.h> |
27 | #include <qpe/task.h> | ||
28 | #include <qpe/timestring.h> | 30 | #include <qpe/timestring.h> |
31 | #include <qpe/palmtoprecord.h> | ||
29 | 32 | ||
30 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
@@ -40,12 +43,13 @@ | |||
40 | 43 | ||
41 | 44 | ||
42 | NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent, | 45 | NewTaskDialog::NewTaskDialog( const ToDoEvent& task, QWidget *parent, |
43 | const char *name, bool modal, WFlags fl ) | 46 | const char *name, bool modal, WFlags fl ) |
44 | : NewTaskDialogBase( parent, name, modal, fl ), | 47 | : NewTaskDialogBase( parent, name, modal, fl ), |
45 | todo( task ) | 48 | todo( task ) |
46 | { | 49 | { |
47 | todo.setCategories( task.categories() ); | 50 | qWarning("setting category" ); |
48 | if ( todo.hasDueDate() ) | 51 | todo.setCategory( task.category() ); |
49 | date = todo.dueDate(); | 52 | if ( todo.hasDate() ) |
53 | date = todo.date(); | ||
50 | else | 54 | else |
51 | date = QDate::currentDate(); | 55 | date = QDate::currentDate(); |
@@ -55,5 +59,5 @@ NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent, | |||
55 | 59 | ||
56 | checkCompleted->setChecked( task.isCompleted() ); | 60 | checkCompleted->setChecked( task.isCompleted() ); |
57 | checkDate->setChecked( task.hasDueDate() ); | 61 | checkDate->setChecked( task.hasDate() ); |
58 | buttonDate->setText( TimeString::longDateString( date ) ); | 62 | buttonDate->setText( TimeString::longDateString( date ) ); |
59 | 63 | ||
@@ -76,5 +80,5 @@ NewTaskDialog::NewTaskDialog( int id, QWidget* parent, const char* name, bool m | |||
76 | QArray<int> ids( 1 ); | 80 | QArray<int> ids( 1 ); |
77 | ids[0] = id; | 81 | ids[0] = id; |
78 | todo.setCategories( ids ); | 82 | todo.setCategory( Qtopia::Record::idsToString( ids ) ); |
79 | } | 83 | } |
80 | init(); | 84 | init(); |
@@ -101,4 +105,5 @@ void NewTaskDialog::init() | |||
101 | NewTaskDialog::~NewTaskDialog() | 105 | NewTaskDialog::~NewTaskDialog() |
102 | { | 106 | { |
107 | qWarning("d'tor" ); | ||
103 | // no need to delete child widgets, Qt does it all for us | 108 | // no need to delete child widgets, Qt does it all for us |
104 | } | 109 | } |
@@ -112,16 +117,27 @@ void NewTaskDialog::dateChanged( int y, int m, int d ) | |||
112 | */ | 117 | */ |
113 | 118 | ||
114 | Task NewTaskDialog::todoEntry() | 119 | ToDoEvent NewTaskDialog::todoEntry() |
115 | { | 120 | { |
116 | todo.setDueDate( date, checkDate->isChecked() ); | 121 | qWarning("todoEntry()" ); |
117 | if ( comboCategory->currentCategory() != -1 ) { | 122 | if( checkDate->isChecked() ){ |
118 | todo.setCategories( comboCategory->currentCategories() ); | 123 | todo.setDate( date ); |
119 | } | 124 | todo.setHasDate( true ); |
120 | todo.setPriority( comboPriority->currentItem() + 1 ); | 125 | }else{ |
121 | todo.setCompleted( checkCompleted->isChecked() ); | 126 | todo.setHasDate( false ); |
122 | 127 | } | |
123 | todo.setDescription( txtTodo->text() ); | 128 | qWarning("todoEntry::category()" ); |
124 | 129 | if ( comboCategory->currentCategory() != -1 ) { | |
125 | return todo; | 130 | QArray<int> arr = comboCategory->currentCategories(); |
131 | int id = arr[0]; | ||
132 | qWarning("id 0: %d",id ); | ||
133 | todo.setCategory( Qtopia::Record::idsToString( arr ) ); | ||
134 | qWarning("saving category"); | ||
135 | } | ||
136 | todo.setPriority( comboPriority->currentItem() + 1 ); | ||
137 | todo.setCompleted( checkCompleted->isChecked() ); | ||
138 | |||
139 | todo.setDescription( txtTodo->text() ); | ||
140 | |||
141 | return todo; | ||
126 | } | 142 | } |
127 | 143 | ||
@@ -133,4 +149,5 @@ Task NewTaskDialog::todoEntry() | |||
133 | void NewTaskDialog::accept() | 149 | void NewTaskDialog::accept() |
134 | { | 150 | { |
151 | qWarning("accept" ); | ||
135 | QString strText = txtTodo->text(); | 152 | QString strText = txtTodo->text(); |
136 | if ( strText.isEmpty() ) { | 153 | if ( strText.isEmpty() ) { |
diff --git a/core/pim/todo/todoentryimpl.h b/core/pim/todo/todoentryimpl.h index 932d66e..6407eb4 100644 --- a/core/pim/todo/todoentryimpl.h +++ b/core/pim/todo/todoentryimpl.h | |||
@@ -24,5 +24,5 @@ | |||
24 | #include "todoentry.h" | 24 | #include "todoentry.h" |
25 | 25 | ||
26 | #include <qpe/task.h> | 26 | #include <opie/todoevent.h> |
27 | 27 | ||
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
@@ -38,5 +38,5 @@ class NewTaskDialog : public NewTaskDialogBase | |||
38 | 38 | ||
39 | public: | 39 | public: |
40 | NewTaskDialog( const Task &task, QWidget *parent = 0, const char* name = 0, | 40 | NewTaskDialog( const ToDoEvent &task, QWidget *parent = 0, const char* name = 0, |
41 | bool modal = FALSE, WFlags fl = 0 ); | 41 | bool modal = FALSE, WFlags fl = 0 ); |
42 | NewTaskDialog( int id, QWidget* parent = 0, const char* name = 0, | 42 | NewTaskDialog( int id, QWidget* parent = 0, const char* name = 0, |
@@ -44,5 +44,5 @@ public: | |||
44 | ~NewTaskDialog(); | 44 | ~NewTaskDialog(); |
45 | 45 | ||
46 | Task todoEntry(); | 46 | ToDoEvent todoEntry(); |
47 | 47 | ||
48 | protected slots: | 48 | protected slots: |
@@ -54,5 +54,5 @@ protected: | |||
54 | private: | 54 | private: |
55 | void init(); | 55 | void init(); |
56 | Task todo; | 56 | ToDoEvent todo; |
57 | QDate date; | 57 | QDate date; |
58 | DateBookMonth *picker; | 58 | DateBookMonth *picker; |
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index 77d3389..2bb95a2 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp | |||
@@ -21,4 +21,5 @@ | |||
21 | #include "todotable.h" | 21 | #include "todotable.h" |
22 | 22 | ||
23 | #include <opie/tododb.h> | ||
23 | #include <qpe/categoryselect.h> | 24 | #include <qpe/categoryselect.h> |
24 | #include <qpe/xmlreader.h> | 25 | #include <qpe/xmlreader.h> |
@@ -40,5 +41,5 @@ | |||
40 | 41 | ||
41 | 42 | ||
42 | static bool taskCompare( const Task &task, const QRegExp &r, int category ); | 43 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); |
43 | 44 | ||
44 | static QString journalFileName(); | 45 | static QString journalFileName(); |
@@ -63,5 +64,5 @@ void CheckItem::toggle() | |||
63 | { | 64 | { |
64 | TodoTable *parent = static_cast<TodoTable*>(table()); | 65 | TodoTable *parent = static_cast<TodoTable*>(table()); |
65 | Task newTodo = parent->currentEntry(); | 66 | ToDoEvent newTodo = parent->currentEntry(); |
66 | checked = !checked; | 67 | checked = !checked; |
67 | newTodo.setCompleted( checked ); | 68 | newTodo.setCompleted( checked ); |
@@ -134,5 +135,5 @@ void ComboItem::setContentFromEditor( QWidget *w ) | |||
134 | { | 135 | { |
135 | TodoTable *parent = static_cast<TodoTable*>(table()); | 136 | TodoTable *parent = static_cast<TodoTable*>(table()); |
136 | Task newTodo = parent->currentEntry(); | 137 | ToDoEvent newTodo = parent->currentEntry(); |
137 | 138 | ||
138 | if ( w->inherits( "QComboBox" ) ) | 139 | if ( w->inherits( "QComboBox" ) ) |
@@ -195,10 +196,10 @@ TodoTable::TodoTable( QWidget *parent, const char *name ) | |||
195 | } | 196 | } |
196 | 197 | ||
197 | void TodoTable::addEntry( const Task &todo ) | 198 | void TodoTable::addEntry( const ToDoEvent &todo ) |
198 | { | 199 | { |
199 | int row = numRows(); | 200 | int row = numRows(); |
200 | setNumRows( row + 1 ); | 201 | setNumRows( row + 1 ); |
201 | updateJournal( todo, ACTION_ADD ); | 202 | updateJournal( todo, ACTION_ADD ); |
202 | insertIntoTable( new Task(todo), row ); | 203 | insertIntoTable( new ToDoEvent(todo), row ); |
203 | setCurrentCell(row, currentColumn()); | 204 | setCurrentCell(row, currentColumn()); |
204 | updateVisible(); | 205 | updateVisible(); |
@@ -253,9 +254,9 @@ void TodoTable::slotCurrentChanged( int, int ) | |||
253 | } | 254 | } |
254 | 255 | ||
255 | void TodoTable::internalAddEntries( QList<Task> &list ) | 256 | void TodoTable::internalAddEntries( QList<ToDoEvent> &list ) |
256 | { | 257 | { |
257 | setNumRows( list.count() ); | 258 | setNumRows( list.count() ); |
258 | int row = 0; | 259 | int row = 0; |
259 | Task *it; | 260 | ToDoEvent *it; |
260 | for ( it = list.first(); it; it = list.next() ) | 261 | for ( it = list.first(); it; it = list.next() ) |
261 | insertIntoTable( it, row++ ); | 262 | insertIntoTable( it, row++ ); |
@@ -263,10 +264,10 @@ void TodoTable::internalAddEntries( QList<Task> &list ) | |||
263 | 264 | ||
264 | 265 | ||
265 | Task TodoTable::currentEntry() const | 266 | ToDoEvent TodoTable::currentEntry() const |
266 | { | 267 | { |
267 | QTableItem *i = item( currentRow(), 0 ); | 268 | QTableItem *i = item( currentRow(), 0 ); |
268 | if ( !i || rowHeight( currentRow() ) <= 0 ) | 269 | if ( !i || rowHeight( currentRow() ) <= 0 ) |
269 | return Task(); | 270 | return ToDoEvent(); |
270 | Task *todo = todoList[(CheckItem*)i]; | 271 | ToDoEvent *todo = todoList[(CheckItem*)i]; |
271 | todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); | 272 | todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); |
272 | todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); | 273 | todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); |
@@ -274,5 +275,5 @@ Task TodoTable::currentEntry() const | |||
274 | } | 275 | } |
275 | 276 | ||
276 | void TodoTable::replaceCurrentEntry( const Task &todo, bool fromTableItem ) | 277 | void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) |
277 | { | 278 | { |
278 | int row = currentRow(); | 279 | int row = currentRow(); |
@@ -287,5 +288,5 @@ void TodoTable::replaceCurrentEntry( const Task &todo, bool fromTableItem ) | |||
287 | void TodoTable::removeCurrentEntry() | 288 | void TodoTable::removeCurrentEntry() |
288 | { | 289 | { |
289 | Task *oldTodo; | 290 | ToDoEvent *oldTodo; |
290 | int row = currentRow(); | 291 | int row = currentRow(); |
291 | CheckItem *chk; | 292 | CheckItem *chk; |
@@ -308,43 +309,20 @@ bool TodoTable::save( const QString &fn ) | |||
308 | { | 309 | { |
309 | QString strNewFile = fn + ".new"; | 310 | QString strNewFile = fn + ".new"; |
310 | QFile f( strNewFile ); | 311 | QFile::remove( strNewFile ); // just to be sure |
311 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 312 | ToDoDB todoDB( strNewFile ); |
312 | return false; | 313 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
313 | |||
314 | QString buf("<!DOCTYPE Tasks>\n<Tasks>\n"); | ||
315 | QCString str; | ||
316 | int total_written; | ||
317 | |||
318 | for ( QMap<CheckItem*, Task *>::Iterator it = todoList.begin(); | ||
319 | it != todoList.end(); ++it ) { | 314 | it != todoList.end(); ++it ) { |
320 | if ( !item( it.key()->row(), 0 ) ) | 315 | if ( !item( it.key()->row(), 0 ) ) |
321 | continue; | 316 | continue; |
322 | Task *todo = *it; | 317 | ToDoEvent *todo = *it; |
323 | // sync item with table | 318 | // sync item with table |
324 | todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); | 319 | todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); |
325 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); | 320 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); |
326 | buf += "<Task"; | 321 | todoDB.addEvent( *todo ); |
327 | todo->save( buf ); | ||
328 | buf += " />\n"; | ||
329 | str = buf.utf8(); | ||
330 | total_written = f.writeBlock( str.data(), str.length() ); | ||
331 | if ( total_written != int(str.length()) ) { | ||
332 | f.close(); | ||
333 | QFile::remove( strNewFile ); | ||
334 | return false; | ||
335 | } | ||
336 | buf = ""; | ||
337 | } | ||
338 | |||
339 | buf += "</Tasks>\n"; | ||
340 | str = buf.utf8(); | ||
341 | total_written = f.writeBlock( str.data(), str.length() ); | ||
342 | if ( total_written != int(str.length()) ) { | ||
343 | f.close(); | ||
344 | QFile::remove( strNewFile ); | ||
345 | return false; | ||
346 | } | 322 | } |
347 | f.close(); | 323 | if(!todoDB.save() ){ |
348 | 324 | QFile::remove( strNewFile ); | |
325 | return false; | ||
326 | }; | ||
349 | // now do the rename | 327 | // now do the rename |
350 | if ( ::rename( strNewFile, fn ) < 0 ) | 328 | if ( ::rename( strNewFile, fn ) < 0 ) |
@@ -381,5 +359,5 @@ void TodoTable::updateVisible() | |||
381 | for ( int row = 0; row < numRows(); row++ ) { | 359 | for ( int row = 0; row < numRows(); row++ ) { |
382 | CheckItem *ci = (CheckItem *)item( row, 0 ); | 360 | CheckItem *ci = (CheckItem *)item( row, 0 ); |
383 | Task *t = todoList[ci]; | 361 | ToDoEvent *t = todoList[ci]; |
384 | QArray<int> vlCats = t->categories(); | 362 | QArray<int> vlCats = t->categories(); |
385 | bool hide = false; | 363 | bool hide = false; |
@@ -441,7 +419,7 @@ void TodoTable::setPaintingEnabled( bool e ) | |||
441 | void TodoTable::clear() | 419 | void TodoTable::clear() |
442 | { | 420 | { |
443 | for ( QMap<CheckItem*, Task *>::Iterator it = todoList.begin(); | 421 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
444 | it != todoList.end(); ++it ) { | 422 | it != todoList.end(); ++it ) { |
445 | Task *todo = *it; | 423 | ToDoEvent *todo = *it; |
446 | delete todo; | 424 | delete todo; |
447 | } | 425 | } |
@@ -478,5 +456,5 @@ void TodoTable::slotCheckPriority(int row, int col ) | |||
478 | 456 | ||
479 | 457 | ||
480 | void TodoTable::updateJournal( const Task &todo, journal_action action, int row ) | 458 | void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row ) |
481 | { | 459 | { |
482 | QFile f( journalFileName() ); | 460 | QFile f( journalFileName() ); |
@@ -486,5 +464,5 @@ void TodoTable::updateJournal( const Task &todo, journal_action action, int row | |||
486 | QCString str; | 464 | QCString str; |
487 | buf = "<Task"; | 465 | buf = "<Task"; |
488 | todo.save( buf ); | 466 | // todo.save( buf ); |
489 | buf += " Action=\"" + QString::number( int(action) ) + "\""; | 467 | buf += " Action=\"" + QString::number( int(action) ) + "\""; |
490 | buf += " Row=\"" + QString::number( row ) + "\""; | 468 | buf += " Row=\"" + QString::number( row ) + "\""; |
@@ -503,190 +481,26 @@ void TodoTable::rowHeightChanged( int row ) | |||
503 | void TodoTable::loadFile( const QString &strFile, bool fromJournal ) | 481 | void TodoTable::loadFile( const QString &strFile, bool fromJournal ) |
504 | { | 482 | { |
505 | QFile f( strFile ); | ||
506 | if ( !f.open(IO_ReadOnly) ) | ||
507 | return; | ||
508 | |||
509 | int action, row; | ||
510 | action = 0; row = 0; | ||
511 | |||
512 | enum Attribute { | ||
513 | FCompleted = 0, | ||
514 | FHasDate, | ||
515 | FPriority, | ||
516 | FCategories, | ||
517 | FDescription, | ||
518 | FDateYear, | ||
519 | FDateMonth, | ||
520 | FDateDay, | ||
521 | FUid, | ||
522 | FAction, | ||
523 | FRow | ||
524 | }; | ||
525 | |||
526 | QAsciiDict<int> dict( 31 ); | ||
527 | QList<Task> list; | ||
528 | dict.setAutoDelete( TRUE ); | ||
529 | dict.insert( "Completed", new int(FCompleted) ); | ||
530 | dict.insert( "HasDate", new int(FHasDate) ); | ||
531 | dict.insert( "Priority", new int(FPriority) ); | ||
532 | dict.insert( "Categories", new int(FCategories) ); | ||
533 | dict.insert( "Description", new int(FDescription) ); | ||
534 | dict.insert( "DateYear", new int(FDateYear) ); | ||
535 | dict.insert( "DateMonth", new int(FDateMonth) ); | ||
536 | dict.insert( "DateDay", new int(FDateDay) ); | ||
537 | dict.insert( "Uid", new int(FUid) ); | ||
538 | dict.insert( "Action", new int(FAction) ); | ||
539 | dict.insert( "Row", new int(FRow) ); | ||
540 | |||
541 | QByteArray ba = f.readAll(); | ||
542 | f.close(); | ||
543 | char* dt = ba.data(); | ||
544 | int len = ba.size(); | ||
545 | bool hasDueDate = FALSE; | ||
546 | |||
547 | action = ACTION_ADD; | ||
548 | int i = 0; | ||
549 | char *point; | ||
550 | while ( ( point = strstr( dt+i, "<Task " ) ) != NULL ) { | ||
551 | // new Task | ||
552 | i = point - dt; | ||
553 | Task *todo = new Task; | ||
554 | int dtY = 0, dtM = 0, dtD = 0; | ||
555 | |||
556 | i += 5; | ||
557 | |||
558 | while( 1 ) { | ||
559 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | ||
560 | ++i; | ||
561 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | ||
562 | break; | ||
563 | // we have another attribute, read it. | ||
564 | int j = i; | ||
565 | while ( j < len && dt[j] != '=' ) | ||
566 | ++j; | ||
567 | char *attr = dt+i; | ||
568 | dt[j] = '\0'; | ||
569 | i = ++j; // skip = | ||
570 | while ( i < len && dt[i] != '"' ) | ||
571 | ++i; | ||
572 | j = ++i; | ||
573 | bool haveUtf = FALSE; | ||
574 | bool haveEnt = FALSE; | ||
575 | while ( j < len && dt[j] != '"' ) { | ||
576 | if ( ((unsigned char)dt[j]) > 0x7f ) | ||
577 | haveUtf = TRUE; | ||
578 | if ( dt[j] == '&' ) | ||
579 | haveEnt = TRUE; | ||
580 | ++j; | ||
581 | } | ||
582 | if ( i == j ) { | ||
583 | // empty value | ||
584 | i = j + 1; | ||
585 | continue; | ||
586 | } | ||
587 | QCString value( dt+i, j-i+1 ); | ||
588 | i = j + 1; | ||
589 | int *lookup = dict[ attr ]; | ||
590 | if ( !lookup ) { | ||
591 | todo->setCustomField(attr, value); | ||
592 | continue; | ||
593 | } | ||
594 | switch( *lookup ) { | ||
595 | case FCompleted: | ||
596 | todo->setCompleted( value.toInt() ); | ||
597 | break; | ||
598 | case FHasDate: | ||
599 | // leave... | ||
600 | hasDueDate = value.toInt(); | ||
601 | break; | ||
602 | case FPriority: | ||
603 | todo->setPriority( value.toInt() ); | ||
604 | break; | ||
605 | case FCategories: { | ||
606 | //QString str = Qtopia::plainString( value ); | ||
607 | todo->setCategories( Qtopia::Record::idsFromString( value ) ); | ||
608 | break; | ||
609 | } | ||
610 | case FDescription: | ||
611 | { | ||
612 | QString str = (haveUtf ? QString::fromUtf8( value ) | ||
613 | : QString::fromLatin1( value ) ); | ||
614 | if ( haveEnt ) | ||
615 | str = Qtopia::plainString( str ); | ||
616 | todo->setDescription( str ); | ||
617 | break; | ||
618 | } | ||
619 | case FDateYear: | ||
620 | dtY = value.toInt(); | ||
621 | break; | ||
622 | case FDateMonth: | ||
623 | dtM = value.toInt(); | ||
624 | break; | ||
625 | case FDateDay: | ||
626 | dtD = value.toInt(); | ||
627 | break; | ||
628 | case FUid: | ||
629 | todo->setUid( value.toInt() ); | ||
630 | break; | ||
631 | case FAction: | ||
632 | action = value.toInt(); | ||
633 | break; | ||
634 | case FRow: | ||
635 | row = value.toInt(); | ||
636 | break; | ||
637 | default: | ||
638 | qDebug( "huh??? missing enum? -- attr.: %s", attr ); | ||
639 | break; | ||
640 | } | ||
641 | } | ||
642 | |||
643 | if ( dtY != 0 && dtM != 0 && dtD != 0 ) | ||
644 | todo->setDueDate( QDate( dtY, dtM, dtD), hasDueDate ); | ||
645 | else | ||
646 | todo->setHasDueDate( hasDueDate ); | ||
647 | |||
648 | // if ( categoryList.find( todo.category() ) == categoryList.end() ) | ||
649 | // categoryList.append( todo.category() ); | ||
650 | |||
651 | 483 | ||
652 | // sadly we can't delay adding of items from the journal to get | 484 | QList<ToDoEvent> list; |
653 | // the proper effect, but then, the journal should _never_ be | 485 | ToDoDB todoDB; |
654 | // that huge | 486 | QValueList<ToDoEvent> vaList = todoDB.rawToDos(); |
655 | 487 | for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ | |
656 | switch( action ) { | 488 | list.append( new ToDoEvent( (*it) ) ); |
657 | case ACTION_ADD: | 489 | } |
658 | if ( fromJournal ) { | 490 | vaList.clear(); |
659 | int myrows = numRows(); | 491 | // qDebug("parsing done=%d", t.elapsed() ); |
660 | setNumRows( myrows + 1 ); | 492 | if ( list.count() > 0 ) { |
661 | insertIntoTable( todo, myrows ); | 493 | internalAddEntries( list ); |
662 | delete todo; | 494 | list.clear(); |
663 | } else | 495 | } |
664 | list.append( todo ); | ||
665 | break; | ||
666 | case ACTION_REMOVE: | ||
667 | journalFreeRemoveEntry( row ); | ||
668 | break; | ||
669 | case ACTION_REPLACE: | ||
670 | journalFreeReplaceEntry( *todo, row ); | ||
671 | delete todo; | ||
672 | break; | ||
673 | default: | ||
674 | break; | ||
675 | } | ||
676 | } | ||
677 | // qDebug("parsing done=%d", t.elapsed() ); | ||
678 | if ( list.count() > 0 ) { | ||
679 | internalAddEntries( list ); | ||
680 | list.clear(); | ||
681 | } | ||
682 | // qDebug("loading done: t=%d", t.elapsed() ); | 496 | // qDebug("loading done: t=%d", t.elapsed() ); |
683 | } | 497 | } |
684 | 498 | ||
685 | void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) | 499 | void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row ) |
686 | { | 500 | { |
687 | QString strTodo; | 501 | QString strTodo; |
688 | strTodo = todo.description().left(40).simplifyWhiteSpace(); | 502 | strTodo = todo.description().left(40).simplifyWhiteSpace(); |
689 | if ( row == -1 ) { | 503 | if ( row == -1 ) { |
690 | QMapIterator<CheckItem*, Task *> it; | 504 | QMapIterator<CheckItem*, ToDoEvent *> it; |
691 | for ( it = todoList.begin(); it != todoList.end(); ++it ) { | 505 | for ( it = todoList.begin(); it != todoList.end(); ++it ) { |
692 | if ( *(*it) == todo ) { | 506 | if ( *(*it) == todo ) { |
@@ -699,5 +513,5 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) | |||
699 | } | 513 | } |
700 | } else { | 514 | } else { |
701 | Task *t = todoList[static_cast<CheckItem*>(item(row, 0))]; | 515 | ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))]; |
702 | todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); | 516 | todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); |
703 | delete t; | 517 | delete t; |
@@ -705,5 +519,5 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) | |||
705 | static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); | 519 | static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); |
706 | item( row, 2 )->setText( strTodo ); | 520 | item( row, 2 )->setText( strTodo ); |
707 | todoList.insert( static_cast<CheckItem*>(item(row,0)), new Task(todo) ); | 521 | todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) ); |
708 | } | 522 | } |
709 | } | 523 | } |
@@ -815,5 +629,5 @@ int TodoTable::showCategoryId() const | |||
815 | } | 629 | } |
816 | 630 | ||
817 | static bool taskCompare( const Task &task, const QRegExp &r, int category ) | 631 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) |
818 | { | 632 | { |
819 | bool returnMe; | 633 | bool returnMe; |
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h index 4f3a064..2746ce7 100644 --- a/core/pim/todo/todotable.h +++ b/core/pim/todo/todotable.h | |||
@@ -24,5 +24,6 @@ | |||
24 | #include <qpe/categories.h> | 24 | #include <qpe/categories.h> |
25 | #include <qpe/stringutil.h> | 25 | #include <qpe/stringutil.h> |
26 | #include <qpe/task.h> | 26 | //#include <qpe/task.h> |
27 | #include <opie/todoevent.h> | ||
27 | 28 | ||
28 | #include <qtable.h> | 29 | #include <qtable.h> |
@@ -87,9 +88,9 @@ class TodoTable : public QTable | |||
87 | public: | 88 | public: |
88 | TodoTable( QWidget *parent = 0, const char * name = 0 ); | 89 | TodoTable( QWidget *parent = 0, const char * name = 0 ); |
89 | void addEntry( const Task &todo ); | 90 | void addEntry( const ToDoEvent &todo ); |
90 | void clearFindRow() { currFindRow = -2; } | 91 | void clearFindRow() { currFindRow = -2; } |
91 | 92 | ||
92 | Task currentEntry() const; | 93 | ToDoEvent currentEntry() const; |
93 | void replaceCurrentEntry( const Task &todo, bool fromTableItem = false ); | 94 | void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false ); |
94 | 95 | ||
95 | QStringList categories(); | 96 | QStringList categories(); |
@@ -129,9 +130,9 @@ private: | |||
129 | void updateVisible(); | 130 | void updateVisible(); |
130 | void viewportPaintEvent( QPaintEvent * ); | 131 | void viewportPaintEvent( QPaintEvent * ); |
131 | void internalAddEntries( QList<Task> &list); | 132 | void internalAddEntries( QList<ToDoEvent> &list); |
132 | inline void insertIntoTable( Task *todo, int row ); | 133 | inline void insertIntoTable( ToDoEvent *todo, int row ); |
133 | void updateJournal( const Task &todo, journal_action action, int row = -1); | 134 | void updateJournal( const ToDoEvent &todo, journal_action action, int row = -1); |
134 | void mergeJournal(); | 135 | void mergeJournal(); |
135 | void journalFreeReplaceEntry( const Task &todo, int row ); | 136 | void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); |
136 | void journalFreeRemoveEntry( int row ); | 137 | void journalFreeRemoveEntry( int row ); |
137 | inline void realignTable( int row ); | 138 | inline void realignTable( int row ); |
@@ -151,5 +152,5 @@ private: | |||
151 | friend class TodoWindow; | 152 | friend class TodoWindow; |
152 | 153 | ||
153 | QMap<CheckItem*, Task *> todoList; | 154 | QMap<CheckItem*, ToDoEvent *> todoList; |
154 | QStringList categoryList; | 155 | QStringList categoryList; |
155 | bool showComp; | 156 | bool showComp; |
@@ -162,5 +163,5 @@ private: | |||
162 | 163 | ||
163 | 164 | ||
164 | inline void TodoTable::insertIntoTable( Task *todo, int row ) | 165 | inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) |
165 | { | 166 | { |
166 | QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') | 167 | QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') |
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp index daa25f4..7dbf907 100644 --- a/libopie/todoevent.cpp +++ b/libopie/todoevent.cpp | |||
@@ -3,5 +3,5 @@ | |||
3 | #include <qpe/palmtopuidgen.h> | 3 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/stringutil.h> | 4 | #include <qpe/stringutil.h> |
5 | //#include <qpe/palmtoprecord.h> | 5 | #include <qpe/palmtoprecord.h> |
6 | 6 | ||
7 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) | 7 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) |
@@ -27,4 +27,21 @@ ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category, | |||
27 | m_uid = uid; | 27 | m_uid = uid; |
28 | } | 28 | } |
29 | QArray<int> ToDoEvent::categories()const | ||
30 | { | ||
31 | QArray<int> array(1); // currently the datebook can be only in one category | ||
32 | array = Qtopia::Record::idsFromString( category() ); | ||
33 | return array; | ||
34 | } | ||
35 | bool ToDoEvent::match( const QRegExp ®Exp )const | ||
36 | { | ||
37 | if( QString::number( m_priority ).find( regExp ) != -1 ){ | ||
38 | return true; | ||
39 | }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ | ||
40 | return true; | ||
41 | }else if(m_desc.find( regExp ) != -1 ){ | ||
42 | return true; | ||
43 | } | ||
44 | return false; | ||
45 | } | ||
29 | bool ToDoEvent::isCompleted() const | 46 | bool ToDoEvent::isCompleted() const |
30 | { | 47 | { |
@@ -65,5 +82,6 @@ void ToDoEvent::setDescription(const QString &desc ) | |||
65 | void ToDoEvent::setCategory( const QString &cat ) | 82 | void ToDoEvent::setCategory( const QString &cat ) |
66 | { | 83 | { |
67 | m_category = cat; | 84 | qWarning("setCategory %s", cat.latin1() ); |
85 | m_category = cat; | ||
68 | } | 86 | } |
69 | void ToDoEvent::setPriority(int prio ) | 87 | void ToDoEvent::setPriority(int prio ) |
diff --git a/libopie/todoevent.h b/libopie/todoevent.h index bca7f6e..ac996a1 100644 --- a/libopie/todoevent.h +++ b/libopie/todoevent.h | |||
@@ -18,4 +18,5 @@ class ToDoEvent { | |||
18 | int priority()const ; | 18 | int priority()const ; |
19 | QString category()const; | 19 | QString category()const; |
20 | QArray<int> categories() const; | ||
20 | QDate date()const; | 21 | QDate date()const; |
21 | QString description()const; | 22 | QString description()const; |
@@ -31,4 +32,6 @@ class ToDoEvent { | |||
31 | bool isOverdue(); | 32 | bool isOverdue(); |
32 | 33 | ||
34 | bool match( const QRegExp &r )const; | ||
35 | |||
33 | void setUid(int id) {m_uid = id; }; | 36 | void setUid(int id) {m_uid = id; }; |
34 | bool operator<(const ToDoEvent &toDoEvent )const; | 37 | bool operator<(const ToDoEvent &toDoEvent )const; |