author | zecke <zecke> | 2002-04-14 15:14:03 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-14 15:14:03 (UTC) |
commit | a0fe593db4e700989cc19e28b67a58f87823afeb (patch) (unidiff) | |
tree | 1a369409be81aa0feb15899b56adda6ec12b2591 | |
parent | 16dd1d47d51e6307be8d89d36571115cb7c8788c (diff) | |
download | opie-a0fe593db4e700989cc19e28b67a58f87823afeb.zip opie-a0fe593db4e700989cc19e28b67a58f87823afeb.tar.gz opie-a0fe593db4e700989cc19e28b67a58f87823afeb.tar.bz2 |
-menu restructure ( closer to the Zaurus)
-first Part of restoring journal I need to rewrite the whole crap later
qt journaled on a row basis which doesn't work anymore cause of
flexible sorting
-something I forgot ;)
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 106 | ||||
-rw-r--r-- | core/pim/todo/mainwindow.h | 14 | ||||
-rw-r--r-- | core/pim/todo/todotable.cpp | 148 | ||||
-rw-r--r-- | core/pim/todo/todotable.h | 7 |
4 files changed, 238 insertions, 37 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index b5cace9..883d78c 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -121,43 +121,66 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : | |||
121 | bar->setHorizontalStretchable( TRUE ); | 121 | bar->setHorizontalStretchable( TRUE ); |
122 | 122 | ||
123 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 123 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
124 | 124 | ||
125 | catMenu = new QPopupMenu( this ); | 125 | catMenu = new QPopupMenu( this ); |
126 | QPopupMenu *edit = new QPopupMenu( this ); | 126 | QPopupMenu *edit = new QPopupMenu( this ); |
127 | QPopupMenu *options = new QPopupMenu(this ); | ||
128 | |||
127 | contextMenu = new QPopupMenu( this ); | 129 | contextMenu = new QPopupMenu( this ); |
128 | 130 | ||
129 | bar = new QPEToolBar( this ); | 131 | bar = new QPEToolBar( this ); |
130 | 132 | ||
131 | QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ), | 133 | QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ), |
132 | QString::null, 0, this, 0 ); | 134 | QString::null, 0, this, 0 ); |
133 | connect( a, SIGNAL( activated() ), | 135 | connect( a, SIGNAL( activated() ), |
134 | this, SLOT( slotNew() ) ); | 136 | this, SLOT( slotNew() ) ); |
135 | a->addTo( bar ); | 137 | a->addTo( bar ); |
136 | a->addTo( edit ); | 138 | a->addTo( edit ); |
137 | 139 | ||
138 | a = new QAction( tr( "Edit" ), Resource::loadIconSet( "edit" ), | 140 | a = new QAction( tr( "Edit Task" ), Resource::loadIconSet( "edit" ), |
139 | QString::null, 0, this, 0 ); | 141 | QString::null, 0, this, 0 ); |
140 | connect( a, SIGNAL( activated() ), | 142 | connect( a, SIGNAL( activated() ), |
141 | this, SLOT( slotEdit() ) ); | 143 | this, SLOT( slotEdit() ) ); |
142 | a->addTo( bar ); | 144 | a->addTo( bar ); |
143 | a->addTo( edit ); | 145 | a->addTo( edit ); |
144 | a->addTo( contextMenu ); | 146 | a->addTo( contextMenu ); |
145 | a->setEnabled( FALSE ); | 147 | a->setEnabled( FALSE ); |
146 | editAction = a; | 148 | editAction = a; |
149 | edit->insertSeparator(); | ||
147 | 150 | ||
148 | a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ), | 151 | a = new QAction( tr( "Delete..." ), Resource::loadIconSet( "trash" ), |
149 | QString::null, 0, this, 0 ); | 152 | QString::null, 0, this, 0 ); |
150 | connect( a, SIGNAL( activated() ), | 153 | connect( a, SIGNAL( activated() ), |
151 | this, SLOT( slotDelete() ) ); | 154 | this, SLOT( slotDelete() ) ); |
152 | a->addTo( bar ); | 155 | a->addTo( bar ); |
153 | a->addTo( edit ); | 156 | a->addTo( edit ); |
154 | a->addTo( contextMenu ); | 157 | a->addTo( contextMenu ); |
155 | a->setEnabled( FALSE ); | 158 | a->setEnabled( FALSE ); |
156 | deleteAction = a; | 159 | deleteAction = a; |
157 | 160 | ||
161 | // delete All in category is missing.... | ||
162 | // set All Done | ||
163 | // set All Done in category | ||
164 | |||
165 | a = new QAction( QString::null, tr( "Delete all..."), 0, this, 0 ); | ||
166 | connect(a, SIGNAL( activated() ), | ||
167 | this, SLOT( slotDeleteAll() ) ); | ||
168 | a->addTo(edit ); | ||
169 | a->setEnabled( FALSE ); | ||
170 | deleteAllAction = a; | ||
171 | |||
172 | edit->insertSeparator(); | ||
173 | a = new QAction( QString::null, tr("Duplicate" ), 0, this, 0 ); | ||
174 | connect(a, SIGNAL( activated() ), | ||
175 | this, SLOT( slotDuplicate() ) ); | ||
176 | a->addTo(edit ); | ||
177 | a->setEnabled( FALSE ); | ||
178 | duplicateAction = a; | ||
179 | |||
180 | edit->insertSeparator(); | ||
158 | if ( Ir::supported() ) { | 181 | if ( Ir::supported() ) { |
159 | a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), | 182 | a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), |
160 | QString::null, 0, this, 0 ); | 183 | QString::null, 0, this, 0 ); |
161 | connect( a, SIGNAL( activated() ), | 184 | connect( a, SIGNAL( activated() ), |
162 | this, SLOT( slotBeam() ) ); | 185 | this, SLOT( slotBeam() ) ); |
163 | a->addTo( edit ); | 186 | a->addTo( edit ); |
@@ -166,13 +189,15 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : | |||
166 | 189 | ||
167 | a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), | 190 | a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), |
168 | QString::null, 0, this, 0 ); | 191 | QString::null, 0, this, 0 ); |
169 | connect( a, SIGNAL( activated() ), | 192 | connect( a, SIGNAL( activated() ), |
170 | this, SLOT( slotFind() ) ); | 193 | this, SLOT( slotFind() ) ); |
171 | a->addTo( bar ); | 194 | a->addTo( bar ); |
172 | a->addTo( edit ); | 195 | a->addTo( options ); |
196 | options->insertSeparator(); | ||
197 | |||
173 | if ( table->numRows() ) | 198 | if ( table->numRows() ) |
174 | a->setEnabled( TRUE ); | 199 | a->setEnabled( TRUE ); |
175 | else | 200 | else |
176 | a->setEnabled( FALSE ); | 201 | a->setEnabled( FALSE ); |
177 | 202 | ||
178 | //a->setEnabled( FALSE ); | 203 | //a->setEnabled( FALSE ); |
@@ -183,15 +208,30 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : | |||
183 | 208 | ||
184 | showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE ); | 209 | showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE ); |
185 | 210 | ||
186 | catMenu->setCheckable( true ); | 211 | catMenu->setCheckable( true ); |
187 | populateCategories(); | 212 | populateCategories(); |
188 | 213 | ||
189 | mb->insertItem( tr( "Data" ), edit ); | 214 | |
190 | mb->insertItem( tr( "View" ), catMenu ); | 215 | completedAction->addTo( options ); |
216 | completedAction->setOn( table->showCompleted() ); | ||
217 | showdeadlineAction->addTo( options ); | ||
218 | showdeadlineAction->setOn( table->showDeadline() ); | ||
219 | options->insertSeparator( ); | ||
220 | QList<QWidget> list; | ||
221 | list.append(table ); | ||
222 | OFontMenu *menu = new OFontMenu(this, "menu",list ); | ||
223 | menu->forceSize( table->horizontalHeader(), 10 ); | ||
224 | //catMenu->insertItem(tr("Fonts"), menu ); | ||
225 | list.clear(); | ||
226 | options->insertItem( tr("Fonts"), menu ); | ||
227 | |||
191 | 228 | ||
229 | mb->insertItem( tr( "Data" ), edit ); | ||
230 | mb->insertItem( tr( "Category" ), catMenu ); | ||
231 | mb->insertItem( tr( "Options"), options ); | ||
192 | resize( 200, 300 ); | 232 | resize( 200, 300 ); |
193 | if ( table->numRows() > 0 ) | 233 | if ( table->numRows() > 0 ) |
194 | currentEntryChanged( 0, 0 ); | 234 | currentEntryChanged( 0, 0 ); |
195 | connect( table, SIGNAL( signalEdit() ), | 235 | connect( table, SIGNAL( signalEdit() ), |
196 | this, SLOT( slotEdit() ) ); | 236 | this, SLOT( slotEdit() ) ); |
197 | connect( table, SIGNAL(signalShowMenu(const QPoint &)), | 237 | connect( table, SIGNAL(signalShowMenu(const QPoint &)), |
@@ -276,12 +316,36 @@ void TodoWindow::slotDelete() | |||
276 | 316 | ||
277 | if ( table->numRows() == 0 ) { | 317 | if ( table->numRows() == 0 ) { |
278 | currentEntryChanged( -1, 0 ); | 318 | currentEntryChanged( -1, 0 ); |
279 | findAction->setEnabled( FALSE ); | 319 | findAction->setEnabled( FALSE ); |
280 | } | 320 | } |
281 | } | 321 | } |
322 | void TodoWindow::slotDeleteAll() | ||
323 | { | ||
324 | if(syncing) { | ||
325 | QMessageBox::warning(this, tr("Todo"), | ||
326 | tr("Can not edit data, currently syncing")); | ||
327 | return; | ||
328 | } | ||
329 | |||
330 | //QString strName = table->text( table->currentRow(), 2 ).left( 30 ); | ||
331 | |||
332 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("Should I delete all tasks?") ) ) | ||
333 | return; | ||
334 | |||
335 | |||
336 | |||
337 | table->setPaintingEnabled( false ); | ||
338 | table->removeAllEntries(); | ||
339 | table->setPaintingEnabled( true ); | ||
340 | |||
341 | if ( table->numRows() == 0 ) { | ||
342 | currentEntryChanged( -1, 0 ); | ||
343 | findAction->setEnabled( FALSE ); | ||
344 | } | ||
345 | } | ||
282 | 346 | ||
283 | void TodoWindow::slotEdit() | 347 | void TodoWindow::slotEdit() |
284 | { | 348 | { |
285 | if(syncing) { | 349 | if(syncing) { |
286 | QMessageBox::warning(this, tr("Todo"), | 350 | QMessageBox::warning(this, tr("Todo"), |
287 | tr("Can not edit data, currently syncing")); | 351 | tr("Can not edit data, currently syncing")); |
@@ -304,13 +368,25 @@ void TodoWindow::slotEdit() | |||
304 | table->replaceCurrentEntry( todo ); | 368 | table->replaceCurrentEntry( todo ); |
305 | table->setPaintingEnabled( true ); | 369 | table->setPaintingEnabled( true ); |
306 | } | 370 | } |
307 | populateCategories(); | 371 | populateCategories(); |
308 | 372 | ||
309 | } | 373 | } |
310 | 374 | void TodoWindow::slotDuplicate() | |
375 | { | ||
376 | if(syncing) { | ||
377 | QMessageBox::warning(this, tr("Todo"), | ||
378 | tr("Can not edit data, currently syncing")); | ||
379 | return; | ||
380 | } | ||
381 | ToDoEvent ev = table->currentEntry(); | ||
382 | ToDoEvent ev2 = ToDoEvent( ev ); | ||
383 | table->setPaintingEnabled( false ); | ||
384 | table->addEntry( ev2 ); | ||
385 | table->setPaintingEnabled( true ); | ||
386 | } | ||
311 | void TodoWindow::slotShowPopup( const QPoint &p ) | 387 | void TodoWindow::slotShowPopup( const QPoint &p ) |
312 | { | 388 | { |
313 | contextMenu->popup( p ); | 389 | contextMenu->popup( p ); |
314 | } | 390 | } |
315 | 391 | ||
316 | void TodoWindow::showCompleted( bool s ) | 392 | void TodoWindow::showCompleted( bool s ) |
@@ -324,15 +400,19 @@ void TodoWindow::showCompleted( bool s ) | |||
324 | 400 | ||
325 | void TodoWindow::currentEntryChanged( int r, int ) | 401 | void TodoWindow::currentEntryChanged( int r, int ) |
326 | { | 402 | { |
327 | if ( r != -1 && table->rowHeight( r ) > 0 ) { | 403 | if ( r != -1 && table->rowHeight( r ) > 0 ) { |
328 | editAction->setEnabled( TRUE ); | 404 | editAction->setEnabled( TRUE ); |
329 | deleteAction->setEnabled( TRUE ); | 405 | deleteAction->setEnabled( TRUE ); |
406 | duplicateAction->setEnabled( TRUE ); | ||
407 | deleteAllAction->setEnabled( TRUE ); | ||
330 | } else { | 408 | } else { |
331 | editAction->setEnabled( FALSE ); | 409 | editAction->setEnabled( FALSE ); |
332 | deleteAction->setEnabled( FALSE ); | 410 | deleteAction->setEnabled( FALSE ); |
411 | duplicateAction->setEnabled( FALSE ); | ||
412 | deleteAllAction->setEnabled( FALSE ); | ||
333 | } | 413 | } |
334 | } | 414 | } |
335 | 415 | ||
336 | void TodoWindow::setCategory( int c ) | 416 | void TodoWindow::setCategory( int c ) |
337 | { | 417 | { |
338 | if ( c <= 0 ) return; | 418 | if ( c <= 0 ) return; |
@@ -355,28 +435,16 @@ void TodoWindow::setCategory( int c ) | |||
355 | table->setPaintingEnabled( true ); | 435 | table->setPaintingEnabled( true ); |
356 | } | 436 | } |
357 | 437 | ||
358 | void TodoWindow::populateCategories() | 438 | void TodoWindow::populateCategories() |
359 | { | 439 | { |
360 | catMenu->clear(); | 440 | catMenu->clear(); |
361 | |||
362 | QList<QWidget> list; | ||
363 | list.append(table ); | ||
364 | OFontMenu *menu = new OFontMenu(this, "menu",list ); | ||
365 | menu->forceSize( table->horizontalHeader(), 10 ); | ||
366 | catMenu->insertItem(tr("Fonts"), menu ); | ||
367 | |||
368 | completedAction->addTo( catMenu ); | ||
369 | completedAction->setOn( table->showCompleted() ); | ||
370 | showdeadlineAction->addTo( catMenu ); | ||
371 | showdeadlineAction->setOn( table->showDeadline() ); | ||
372 | catMenu->insertSeparator(); | ||
373 | int id, rememberId; | 441 | int id, rememberId; |
374 | id = 1; | 442 | id = 1; |
375 | catMenu->insertItem( tr( "All Categories" ), id++ ); | 443 | catMenu->insertItem( tr( "All Categories" ), id++ ); |
376 | // catMenu->insertSeparator(); | 444 | catMenu->insertSeparator(); |
377 | QStringList categories = table->categories(); | 445 | QStringList categories = table->categories(); |
378 | categories.append( tr( "Unfiled" ) ); | 446 | categories.append( tr( "Unfiled" ) ); |
379 | for ( QStringList::Iterator it = categories.begin(); | 447 | for ( QStringList::Iterator it = categories.begin(); |
380 | it != categories.end(); ++it ) { | 448 | it != categories.end(); ++it ) { |
381 | catMenu->insertItem( *it, id ); | 449 | catMenu->insertItem( *it, id ); |
382 | if ( *it == table->showCategory() ) | 450 | if ( *it == table->showCategory() ) |
diff --git a/core/pim/todo/mainwindow.h b/core/pim/todo/mainwindow.h index 9be7c66..b9172e1 100644 --- a/core/pim/todo/mainwindow.h +++ b/core/pim/todo/mainwindow.h | |||
@@ -55,26 +55,30 @@ protected slots: | |||
55 | void currentEntryChanged( int r, int c ); | 55 | void currentEntryChanged( int r, int c ); |
56 | void setCategory( int ); | 56 | void setCategory( int ); |
57 | void slotFind(); | 57 | void slotFind(); |
58 | void setDocument( const QString & ); | 58 | void setDocument( const QString & ); |
59 | void slotBeam(); | 59 | void slotBeam(); |
60 | void beamDone( Ir * ); | 60 | void beamDone( Ir * ); |
61 | 61 | void slotDeleteAll(); | |
62 | void slotDuplicate(); | ||
63 | |||
62 | protected: | 64 | protected: |
63 | void closeEvent( QCloseEvent *e ); | 65 | void closeEvent( QCloseEvent *e ); |
64 | 66 | ||
65 | private: | 67 | private: |
66 | void populateCategories(); | 68 | void populateCategories(); |
67 | 69 | ||
68 | private: | 70 | private: |
69 | TodoTable *table; | 71 | TodoTable *table; |
70 | QAction *editAction, | 72 | QAction *editAction, |
71 | *deleteAction, | 73 | *deleteAction, |
72 | *findAction, | 74 | *findAction, |
73 | * completedAction, | 75 | *completedAction, |
74 | *showdeadlineAction ; | 76 | *showdeadlineAction, |
77 | *deleteAllAction, | ||
78 | *duplicateAction; | ||
75 | QPopupMenu *contextMenu, *catMenu; | 79 | QPopupMenu *contextMenu, *catMenu; |
76 | 80 | ||
77 | bool syncing; | 81 | bool syncing; |
78 | }; | 82 | }; |
79 | 83 | ||
80 | #endif | 84 | #endif |
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index 2acd03c..401d2c8 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp | |||
@@ -19,37 +19,41 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | /* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de) | 20 | /* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de) |
21 | */ | 21 | */ |
22 | #include "todotable.h" | 22 | #include "todotable.h" |
23 | 23 | ||
24 | #include <opie/tododb.h> | 24 | #include <opie/tododb.h> |
25 | #include <opie/xmltree.h> | ||
26 | |||
25 | #include <qpe/categoryselect.h> | 27 | #include <qpe/categoryselect.h> |
26 | #include <qpe/xmlreader.h> | 28 | #include <qpe/xmlreader.h> |
27 | 29 | ||
28 | #include <qasciidict.h> | 30 | #include <qasciidict.h> |
29 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
30 | #include <qfile.h> | 32 | #include <qfile.h> |
31 | #include <qpainter.h> | 33 | #include <qpainter.h> |
32 | #include <qtextcodec.h> | 34 | #include <qtextcodec.h> |
33 | #include <qtimer.h> | 35 | #include <qtimer.h> |
34 | #include <qdatetime.h> | 36 | #include <qdatetime.h> |
37 | #include <qtextstream.h> | ||
35 | 38 | ||
36 | #include <qcursor.h> | 39 | #include <qcursor.h> |
37 | #include <qregexp.h> | 40 | #include <qregexp.h> |
38 | 41 | ||
39 | #include <errno.h> | 42 | #include <errno.h> |
40 | #include <stdlib.h> | 43 | #include <stdlib.h> |
41 | 44 | ||
42 | #include <stdio.h> | 45 | #include <stdio.h> |
46 | #include <iostream> | ||
43 | 47 | ||
48 | namespace { | ||
44 | 49 | ||
45 | 50 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); | |
46 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); | 51 | static QString journalFileName(); |
47 | 52 | static ToDoEvent xmlToEvent( XMLElement *ev ); | |
48 | static QString journalFileName(); | 53 | } |
49 | |||
50 | CheckItem::CheckItem( QTable *t, const QString &key ) | 54 | CheckItem::CheckItem( QTable *t, const QString &key ) |
51 | : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key ) | 55 | : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key ) |
52 | { | 56 | { |
53 | } | 57 | } |
54 | 58 | ||
55 | QString CheckItem::key() const | 59 | QString CheckItem::key() const |
@@ -406,22 +410,21 @@ bool TodoTable::save( const QString &fn ) | |||
406 | } | 410 | } |
407 | 411 | ||
408 | void TodoTable::load( const QString &fn ) | 412 | void TodoTable::load( const QString &fn ) |
409 | { | 413 | { |
410 | loadFile( fn, false ); | 414 | loadFile( fn, false ); |
411 | if ( QFile::exists(journalFileName()) ) { | 415 | if ( QFile::exists(journalFileName()) ) { |
412 | loadFile( journalFileName(), true ); | 416 | applyJournal( ); |
413 | save( fn ); | 417 | save( fn ); |
414 | } | 418 | } |
415 | // QTable::sortColumn(2,TRUE,TRUE); | 419 | // QTable::sortColumn(2,TRUE,TRUE); |
416 | // QTable::sortColumn(1,TRUE,TRUE); | 420 | // QTable::sortColumn(1,TRUE,TRUE); |
417 | QTable::sortColumn(0,TRUE,TRUE); | 421 | QTable::sortColumn(0,TRUE,TRUE); |
418 | setCurrentCell( 0, 2 ); | 422 | setCurrentCell( 0, 2 ); |
419 | setSorting(true ); | 423 | setSorting(true ); |
420 | } | 424 | } |
421 | |||
422 | void TodoTable::updateVisible() | 425 | void TodoTable::updateVisible() |
423 | { | 426 | { |
424 | if ( !isUpdatesEnabled() ) | 427 | if ( !isUpdatesEnabled() ) |
425 | return; | 428 | return; |
426 | 429 | ||
427 | if (showDeadl){ | 430 | if (showDeadl){ |
@@ -443,13 +446,13 @@ void TodoTable::updateVisible() | |||
443 | hide = true; | 446 | hide = true; |
444 | if ( !showCat.isEmpty() ) { | 447 | if ( !showCat.isEmpty() ) { |
445 | if ( showCat == tr( "Unfiled" ) ) { | 448 | if ( showCat == tr( "Unfiled" ) ) { |
446 | if ( vlCats.count() > 0 ) | 449 | if ( vlCats.count() > 0 ) |
447 | hide = true; | 450 | hide = true; |
448 | } else { | 451 | } else { |
449 | // do some comparing, we have to reverse our idea here... which idea - zecke | 452 | // do some comparing, we have to reverse our idea here... which idea? - zecke |
450 | if ( !hide ) { | 453 | if ( !hide ) { |
451 | hide = true; | 454 | hide = true; |
452 | for ( uint it = 0; it < vlCats.count(); ++it ) { | 455 | for ( uint it = 0; it < vlCats.count(); ++it ) { |
453 | if ( vlCats[it] == id ) { | 456 | if ( vlCats[it] == id ) { |
454 | hide = false; | 457 | hide = false; |
455 | break; | 458 | break; |
@@ -496,12 +499,13 @@ void TodoTable::setPaintingEnabled( bool e ) | |||
496 | 499 | ||
497 | void TodoTable::clear() | 500 | void TodoTable::clear() |
498 | { | 501 | { |
499 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); | 502 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
500 | it != todoList.end(); ++it ) { | 503 | it != todoList.end(); ++it ) { |
501 | ToDoEvent *todo = *it; | 504 | ToDoEvent *todo = *it; |
505 | updateJournal( todo, ACTION_REMOVE, 0 ); | ||
502 | delete todo; | 506 | delete todo; |
503 | } | 507 | } |
504 | todoList.clear(); | 508 | todoList.clear(); |
505 | for ( int r = 0; r < numRows(); ++r ) { | 509 | for ( int r = 0; r < numRows(); ++r ) { |
506 | for ( int c = 0; c < numCols(); ++c ) { | 510 | for ( int c = 0; c < numCols(); ++c ) { |
507 | if ( cellWidget( r, c ) ) | 511 | if ( cellWidget( r, c ) ) |
@@ -530,23 +534,40 @@ void TodoTable::slotCheckPriority(int row, int col ) | |||
530 | ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); | 534 | ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); |
531 | emit signalPriorityChanged( i->text().toInt() ); | 535 | emit signalPriorityChanged( i->text().toInt() ); |
532 | } | 536 | } |
533 | } | 537 | } |
534 | 538 | ||
535 | 539 | ||
536 | void TodoTable::updateJournal( const ToDoEvent &/*todo*/, journal_action action, int row ) | 540 | void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row ) |
537 | { | 541 | { |
538 | QFile f( journalFileName() ); | 542 | QFile f( journalFileName() ); |
539 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 543 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
540 | return; | 544 | return; |
541 | QString buf; | 545 | QString buf; |
542 | QCString str; | 546 | QCString str; |
543 | buf = "<Task"; | 547 | buf = "<Task"; |
544 | // todo.save( buf ); | 548 | // todo.save( buf ); |
545 | buf += " Action=\"" + QString::number( int(action) ) + "\""; | 549 | buf += " Action=\"" + QString::number( int(action) ) + "\""; |
546 | buf += " Row=\"" + QString::number( row ) + "\""; // better write the id | 550 | buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id |
551 | buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\""; | ||
552 | buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\""; | ||
553 | buf += " Priority=\"" + QString::number( todo.priority() ) + "\""; | ||
554 | QArray<int> arrat = todo.categories(); | ||
555 | QString attr; | ||
556 | for(uint i=0; i < arrat.count(); i++ ){ | ||
557 | attr.append(QString::number(arrat[i])+";" ); | ||
558 | } | ||
559 | if(!attr.isEmpty() ) // remove the last ; | ||
560 | attr.remove(attr.length()-1, 1 ); | ||
561 | buf += " Categories=\"" + attr + "\""; | ||
562 | buf += " Description=\"" + todo.description() + "\""; | ||
563 | if(todo.hasDate() ) { | ||
564 | buf += " DateYear=\""+QString::number( todo.date().year() ) + "\""; | ||
565 | buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\""; | ||
566 | buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\""; | ||
567 | } | ||
547 | buf += "/>\n"; | 568 | buf += "/>\n"; |
548 | str = buf.utf8(); | 569 | str = buf.utf8(); |
549 | f.writeBlock( str.data(), str.length() ); | 570 | f.writeBlock( str.data(), str.length() ); |
550 | f.close(); | 571 | f.close(); |
551 | } | 572 | } |
552 | 573 | ||
@@ -712,13 +733,61 @@ int TodoTable::showCategoryId() const | |||
712 | id = -1; | 733 | id = -1; |
713 | // if allcategories are selected, you get unfiled... | 734 | // if allcategories are selected, you get unfiled... |
714 | if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) ) | 735 | if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) ) |
715 | id = mCat.id( "Todo List", showCat ); | 736 | id = mCat.id( "Todo List", showCat ); |
716 | return id; | 737 | return id; |
717 | } | 738 | } |
718 | 739 | void TodoTable::applyJournal() | |
740 | { | ||
741 | // we need to hack | ||
742 | QFile file( journalFileName() ); | ||
743 | if( file.open(IO_ReadOnly ) ) { | ||
744 | QByteArray ar = file.readAll(); | ||
745 | file.close(); | ||
746 | QFile file2( journalFileName() + "_new" ); | ||
747 | if( file2.open(IO_WriteOnly ) ){ | ||
748 | QTextStream str(&file2 ); | ||
749 | str << QString::fromLatin1("<Tasks>") << endl; | ||
750 | str << ar.data(); | ||
751 | str << QString::fromLatin1("</Tasks>") << endl; | ||
752 | file2.close(); | ||
753 | } | ||
754 | XMLElement *root = XMLElement::load(journalFileName()+ "_new"); | ||
755 | XMLElement *el = root->firstChild(); | ||
756 | el = el->firstChild(); | ||
757 | while( el ){ | ||
758 | qWarning("journal: %s %s", el->attribute("Uid" ).latin1(), el->tagName().latin1() ); | ||
759 | doApply( el ); | ||
760 | el = el->nextChild(); | ||
761 | } | ||
762 | QFile::remove(journalFileName()+ "_new" ); | ||
763 | } | ||
764 | } | ||
765 | // check Action and decide | ||
766 | void TodoTable::doApply(XMLElement *el ) | ||
767 | { | ||
768 | QString dummy; | ||
769 | bool ok; | ||
770 | int action; | ||
771 | dummy = el->attribute("Action" ); | ||
772 | action = dummy.toInt(&ok ); | ||
773 | ToDoEvent ev = xmlToEvent( el ); | ||
774 | if( ok ){ | ||
775 | switch( action ){ | ||
776 | case ACTION_ADD: | ||
777 | addEntry( ev ); | ||
778 | break; | ||
779 | case ACTION_REMOVE:{ // find an entry with the same uid and remove it then | ||
780 | break; | ||
781 | } | ||
782 | case ACTION_REPLACE: | ||
783 | break; | ||
784 | } | ||
785 | } | ||
786 | } | ||
787 | namespace { | ||
719 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) | 788 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) |
720 | { | 789 | { |
721 | bool returnMe; | 790 | bool returnMe; |
722 | QArray<int> cats; | 791 | QArray<int> cats; |
723 | cats = task.categories(); | 792 | cats = task.categories(); |
724 | 793 | ||
@@ -738,16 +807,70 @@ static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) | |||
738 | } | 807 | } |
739 | 808 | ||
740 | static QString journalFileName() | 809 | static QString journalFileName() |
741 | { | 810 | { |
742 | QString str; | 811 | QString str; |
743 | str = getenv( "HOME" ); | 812 | str = getenv( "HOME" ); |
744 | str += "/.todojournal"; | 813 | str += "/.opie_todojournal"; |
745 | return str; | 814 | return str; |
746 | } | 815 | } |
816 | static ToDoEvent xmlToEvent( XMLElement *element ) | ||
817 | { | ||
818 | QString dummy; | ||
819 | ToDoEvent event; | ||
820 | bool ok; | ||
821 | int dumInt; | ||
822 | // completed | ||
823 | dummy = element->attribute("Completed" ); | ||
824 | dumInt = dummy.toInt(&ok ); | ||
825 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); | ||
826 | // hasDate | ||
827 | dummy = element->attribute("HasDate" ); | ||
828 | dumInt = dummy.toInt(&ok ); | ||
829 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); | ||
830 | // set the date | ||
831 | bool hasDa = dumInt; | ||
832 | if ( hasDa ) { //parse the date | ||
833 | int year, day, month = 0; | ||
834 | year = day = month; | ||
835 | // year | ||
836 | dummy = element->attribute("DateYear" ); | ||
837 | dumInt = dummy.toInt(&ok ); | ||
838 | if( ok ) year = dumInt; | ||
839 | // month | ||
840 | dummy = element->attribute("DateMonth" ); | ||
841 | dumInt = dummy.toInt(&ok ); | ||
842 | if(ok ) month = dumInt; | ||
843 | dummy = element->attribute("DateDay" ); | ||
844 | dumInt = dummy.toInt(&ok ); | ||
845 | if(ok ) day = dumInt; | ||
846 | // set the date | ||
847 | QDate date( year, month, day ); | ||
848 | event.setDate( date); | ||
849 | } | ||
850 | dummy = element->attribute("Priority" ); | ||
851 | dumInt = dummy.toInt(&ok ); | ||
852 | if(!ok ) dumInt = ToDoEvent::NORMAL; | ||
853 | event.setPriority( dumInt ); | ||
854 | //description | ||
855 | dummy = element->attribute("Description" ); | ||
856 | event.setDescription( dummy ); | ||
857 | // category | ||
858 | dummy = element->attribute("Categories" ); | ||
859 | QStringList ids = QStringList::split(";", dummy ); | ||
860 | event.setCategories( ids ); | ||
861 | |||
862 | //uid | ||
863 | dummy = element->attribute("Uid" ); | ||
864 | dumInt = dummy.toInt(&ok ); | ||
865 | if(ok ) event.setUid( dumInt ); | ||
866 | |||
867 | return event; | ||
868 | } | ||
747 | 869 | ||
870 | } | ||
748 | // int TodoTable::rowHeight( int ) const | 871 | // int TodoTable::rowHeight( int ) const |
749 | // { | 872 | // { |
750 | // return 18; | 873 | // return 18; |
751 | // } | 874 | // } |
752 | 875 | ||
753 | // int TodoTable::rowPos( int row ) const | 876 | // int TodoTable::rowPos( int row ) const |
@@ -756,6 +879,7 @@ static QString journalFileName() | |||
756 | // } | 879 | // } |
757 | 880 | ||
758 | // int TodoTable::rowAt( int pos ) const | 881 | // int TodoTable::rowAt( int pos ) const |
759 | // { | 882 | // { |
760 | // return QMIN( pos/18, numRows()-1 ); | 883 | // return QMIN( pos/18, numRows()-1 ); |
761 | // } | 884 | // } |
885 | |||
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h index 32df514..6917e04 100644 --- a/core/pim/todo/todotable.h +++ b/core/pim/todo/todotable.h | |||
@@ -89,14 +89,15 @@ class DueTextItem : public QTableItem | |||
89 | bool m_hasDate:1; | 89 | bool m_hasDate:1; |
90 | bool m_completed:1; | 90 | bool m_completed:1; |
91 | 91 | ||
92 | }; | 92 | }; |
93 | 93 | ||
94 | 94 | ||
95 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 95 | enum journal_action { ACTION_ADD=0, ACTION_REMOVE, ACTION_REPLACE }; |
96 | 96 | ||
97 | class XMLElement; | ||
97 | class TodoTable : public QTable | 98 | class TodoTable : public QTable |
98 | { | 99 | { |
99 | Q_OBJECT | 100 | Q_OBJECT |
100 | 101 | ||
101 | public: | 102 | public: |
102 | TodoTable( QWidget *parent = 0, const char * name = 0 ); | 103 | TodoTable( QWidget *parent = 0, const char * name = 0 ); |
@@ -117,14 +118,17 @@ public: | |||
117 | void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } | 118 | void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } |
118 | const QString &showCategory() const { return showCat; } | 119 | const QString &showCategory() const { return showCat; } |
119 | int showCategoryId() const; | 120 | int showCategoryId() const; |
120 | 121 | ||
121 | bool save( const QString &fn ); | 122 | bool save( const QString &fn ); |
122 | void load( const QString &fn ); | 123 | void load( const QString &fn ); |
124 | void applyJournal( ); | ||
123 | void clear(); | 125 | void clear(); |
124 | void removeCurrentEntry(); | 126 | void removeCurrentEntry(); |
127 | void removeAllEntries() { clear(); }; | ||
128 | //void removeAllEntriesInCategory(const QString &category ); | ||
125 | 129 | ||
126 | void setPaintingEnabled( bool e ); | 130 | void setPaintingEnabled( bool e ); |
127 | 131 | ||
128 | virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); | 132 | virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); |
129 | 133 | ||
130 | // int rowHeight( int ) const; | 134 | // int rowHeight( int ) const; |
@@ -150,12 +154,13 @@ private: | |||
150 | void updateJournal( const ToDoEvent &todo, journal_action action, int row = -1); | 154 | void updateJournal( const ToDoEvent &todo, journal_action action, int row = -1); |
151 | void mergeJournal(); | 155 | void mergeJournal(); |
152 | void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); | 156 | void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); |
153 | void journalFreeRemoveEntry( int row ); | 157 | void journalFreeRemoveEntry( int row ); |
154 | inline void realignTable( int row ); | 158 | inline void realignTable( int row ); |
155 | void loadFile( const QString &strFile, bool fromJournal = false ); | 159 | void loadFile( const QString &strFile, bool fromJournal = false ); |
160 | void doApply(XMLElement *el ); | ||
156 | 161 | ||
157 | private slots: | 162 | private slots: |
158 | void slotClicked( int row, int col, int button, const QPoint &pos ); | 163 | void slotClicked( int row, int col, int button, const QPoint &pos ); |
159 | void slotPressed( int row, int col, int button, const QPoint &pos ); | 164 | void slotPressed( int row, int col, int button, const QPoint &pos ); |
160 | void slotCheckPriority(int row, int col ); | 165 | void slotCheckPriority(int row, int col ); |
161 | void slotCurrentChanged(int row, int col ); | 166 | void slotCurrentChanged(int row, int col ); |