Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 27 |
1 files changed, 16 insertions, 11 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 | |||
@@ -3,57 +3,60 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_FD | 21 | #define QTOPIA_INTERNAL_FD |
22 | 22 | ||
23 | #include "mainwindow.h" | 23 | #include "mainwindow.h" |
24 | #include "todoentryimpl.h" | 24 | #include "todoentryimpl.h" |
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> |
29 | #include <qpe/finddialog.h> | 32 | #include <qpe/finddialog.h> |
30 | #include <qpe/global.h> | 33 | #include <qpe/global.h> |
31 | #include <qpe/ir.h> | 34 | #include <qpe/ir.h> |
32 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
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 | ||
38 | #include <qaction.h> | 41 | #include <qaction.h> |
39 | #include <qarray.h> | 42 | #include <qarray.h> |
40 | #include <qdatastream.h> | 43 | #include <qdatastream.h> |
41 | #include <qdatetime.h> | 44 | #include <qdatetime.h> |
42 | #include <qfile.h> | 45 | #include <qfile.h> |
43 | #include <qmessagebox.h> | 46 | #include <qmessagebox.h> |
44 | #include <qpopupmenu.h> | 47 | #include <qpopupmenu.h> |
45 | 48 | ||
46 | #include <sys/stat.h> | 49 | #include <sys/stat.h> |
47 | #include <sys/types.h> | 50 | #include <sys/types.h> |
48 | #include <fcntl.h> | 51 | #include <fcntl.h> |
49 | #include <unistd.h> | 52 | #include <unistd.h> |
50 | 53 | ||
51 | #include <stdlib.h> | 54 | #include <stdlib.h> |
52 | 55 | ||
53 | static QString todolistXMLFilename() | 56 | static QString todolistXMLFilename() |
54 | { | 57 | { |
55 | return Global::applicationFileName("todolist","todolist.xml"); | 58 | return Global::applicationFileName("todolist","todolist.xml"); |
56 | } | 59 | } |
57 | 60 | ||
58 | static QString categoriesXMLFilename() | 61 | static QString categoriesXMLFilename() |
59 | { | 62 | { |
@@ -194,59 +197,59 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : | |||
194 | connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); | 197 | connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); |
195 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); | 198 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); |
196 | connect( table, SIGNAL( currentChanged( int, int ) ), | 199 | connect( table, SIGNAL( currentChanged( int, int ) ), |
197 | this, SLOT( currentEntryChanged( int, int ) ) ); | 200 | this, SLOT( currentEntryChanged( int, int ) ) ); |
198 | 201 | ||
199 | // qDebug("done: t=%d", t.elapsed() ); | 202 | // qDebug("done: t=%d", t.elapsed() ); |
200 | } | 203 | } |
201 | 204 | ||
202 | void TodoWindow::slotNew() | 205 | void TodoWindow::slotNew() |
203 | { | 206 | { |
204 | if(syncing) { | 207 | if(syncing) { |
205 | QMessageBox::warning(this, tr("Todo"), | 208 | QMessageBox::warning(this, tr("Todo"), |
206 | tr("Can not edit data, currently syncing")); | 209 | tr("Can not edit data, currently syncing")); |
207 | return; | 210 | return; |
208 | } | 211 | } |
209 | 212 | ||
210 | int id; | 213 | int id; |
211 | id = -1; | 214 | id = -1; |
212 | QArray<int> ids; | 215 | QArray<int> ids; |
213 | ids = table->currentEntry().categories(); | 216 | ids = table->currentEntry().categories(); |
214 | if ( ids.count() ) | 217 | if ( ids.count() ) |
215 | id = ids[0]; | 218 | id = ids[0]; |
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_) |
221 | e.showMaximized(); | 224 | e.showMaximized(); |
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 ); |
231 | findAction->setEnabled( TRUE ); | 234 | findAction->setEnabled( TRUE ); |
232 | } | 235 | } |
233 | // I'm afraid we must call this every time now, otherwise | 236 | // I'm afraid we must call this every time now, otherwise |
234 | // spend expensive time comparing all these strings... | 237 | // spend expensive time comparing all these strings... |
235 | populateCategories(); | 238 | populateCategories(); |
236 | } | 239 | } |
237 | 240 | ||
238 | TodoWindow::~TodoWindow() | 241 | TodoWindow::~TodoWindow() |
239 | { | 242 | { |
240 | } | 243 | } |
241 | 244 | ||
242 | void TodoWindow::slotDelete() | 245 | void TodoWindow::slotDelete() |
243 | { | 246 | { |
244 | if(syncing) { | 247 | if(syncing) { |
245 | QMessageBox::warning(this, tr("Todo"), | 248 | QMessageBox::warning(this, tr("Todo"), |
246 | tr("Can not edit data, currently syncing")); | 249 | tr("Can not edit data, currently syncing")); |
247 | return; | 250 | return; |
248 | } | 251 | } |
249 | 252 | ||
250 | if ( table->currentRow() == -1 ) | 253 | if ( table->currentRow() == -1 ) |
251 | return; | 254 | return; |
252 | 255 | ||
@@ -254,49 +257,49 @@ void TodoWindow::slotDelete() | |||
254 | 257 | ||
255 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) | 258 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) |
256 | return; | 259 | return; |
257 | 260 | ||
258 | 261 | ||
259 | 262 | ||
260 | table->setPaintingEnabled( false ); | 263 | table->setPaintingEnabled( false ); |
261 | table->removeCurrentEntry(); | 264 | table->removeCurrentEntry(); |
262 | table->setPaintingEnabled( true ); | 265 | table->setPaintingEnabled( true ); |
263 | 266 | ||
264 | if ( table->numRows() == 0 ) { | 267 | if ( table->numRows() == 0 ) { |
265 | currentEntryChanged( -1, 0 ); | 268 | currentEntryChanged( -1, 0 ); |
266 | findAction->setEnabled( FALSE ); | 269 | findAction->setEnabled( FALSE ); |
267 | } | 270 | } |
268 | } | 271 | } |
269 | 272 | ||
270 | void TodoWindow::slotEdit() | 273 | void TodoWindow::slotEdit() |
271 | { | 274 | { |
272 | if(syncing) { | 275 | if(syncing) { |
273 | QMessageBox::warning(this, tr("Todo"), | 276 | QMessageBox::warning(this, tr("Todo"), |
274 | tr("Can not edit data, currently syncing")); | 277 | tr("Can not edit data, currently syncing")); |
275 | return; | 278 | return; |
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 ); |
281 | e.setCaption( tr( "Edit Task" ) ); | 284 | e.setCaption( tr( "Edit Task" ) ); |
282 | 285 | ||
283 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 286 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
284 | e.showMaximized(); | 287 | e.showMaximized(); |
285 | #endif | 288 | #endif |
286 | int ret = e.exec(); | 289 | int ret = e.exec(); |
287 | 290 | ||
288 | if ( ret == QDialog::Accepted ) { | 291 | if ( ret == QDialog::Accepted ) { |
289 | table->setPaintingEnabled( false ); | 292 | table->setPaintingEnabled( false ); |
290 | todo = e.todoEntry(); | 293 | todo = e.todoEntry(); |
291 | table->replaceCurrentEntry( todo ); | 294 | table->replaceCurrentEntry( todo ); |
292 | table->setPaintingEnabled( true ); | 295 | table->setPaintingEnabled( true ); |
293 | } | 296 | } |
294 | populateCategories(); | 297 | populateCategories(); |
295 | 298 | ||
296 | } | 299 | } |
297 | 300 | ||
298 | void TodoWindow::slotShowPopup( const QPoint &p ) | 301 | void TodoWindow::slotShowPopup( const QPoint &p ) |
299 | { | 302 | { |
300 | contextMenu->popup( p ); | 303 | contextMenu->popup( p ); |
301 | } | 304 | } |
302 | 305 | ||
@@ -328,50 +331,49 @@ void TodoWindow::setCategory( int c ) | |||
328 | table->setPaintingEnabled( false ); | 331 | table->setPaintingEnabled( false ); |
329 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) | 332 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) |
330 | catMenu->setItemChecked( i, c == (int)i ); | 333 | catMenu->setItemChecked( i, c == (int)i ); |
331 | if ( c == 1 ) { | 334 | if ( c == 1 ) { |
332 | table->setShowCategory( QString::null ); | 335 | table->setShowCategory( QString::null ); |
333 | setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); | 336 | setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); |
334 | } else if ( c == (int)catMenu->count() - 1 ) { | 337 | } else if ( c == (int)catMenu->count() - 1 ) { |
335 | table->setShowCategory( tr( "Unfiled" ) ); | 338 | table->setShowCategory( tr( "Unfiled" ) ); |
336 | setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); | 339 | setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); |
337 | } else { | 340 | } else { |
338 | QString cat = table->categories()[c - 2]; | 341 | QString cat = table->categories()[c - 2]; |
339 | table->setShowCategory( cat ); | 342 | table->setShowCategory( cat ); |
340 | setCaption( tr("Todo") + " - " + cat ); | 343 | setCaption( tr("Todo") + " - " + cat ); |
341 | } | 344 | } |
342 | table->setPaintingEnabled( true ); | 345 | table->setPaintingEnabled( true ); |
343 | } | 346 | } |
344 | 347 | ||
345 | void TodoWindow::populateCategories() | 348 | void TodoWindow::populateCategories() |
346 | { | 349 | { |
347 | catMenu->clear(); | 350 | catMenu->clear(); |
348 | 351 | ||
349 | completedAction->addTo( catMenu ); | 352 | completedAction->addTo( catMenu ); |
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++ ); |
356 | // catMenu->insertSeparator(); | 358 | // catMenu->insertSeparator(); |
357 | QStringList categories = table->categories(); | 359 | QStringList categories = table->categories(); |
358 | categories.append( tr( "Unfiled" ) ); | 360 | categories.append( tr( "Unfiled" ) ); |
359 | for ( QStringList::Iterator it = categories.begin(); | 361 | for ( QStringList::Iterator it = categories.begin(); |
360 | it != categories.end(); ++it ) { | 362 | it != categories.end(); ++it ) { |
361 | catMenu->insertItem( *it, id ); | 363 | catMenu->insertItem( *it, id ); |
362 | if ( *it == table->showCategory() ) | 364 | if ( *it == table->showCategory() ) |
363 | rememberId = id; | 365 | rememberId = id; |
364 | ++id; | 366 | ++id; |
365 | } | 367 | } |
366 | if ( table->showCategory().isEmpty() ) | 368 | if ( table->showCategory().isEmpty() ) |
367 | setCategory( 1 ); | 369 | setCategory( 1 ); |
368 | else | 370 | else |
369 | setCategory( rememberId ); | 371 | setCategory( rememberId ); |
370 | } | 372 | } |
371 | 373 | ||
372 | void TodoWindow::reload() | 374 | void TodoWindow::reload() |
373 | { | 375 | { |
374 | table->clear(); | 376 | table->clear(); |
375 | table->load( todolistXMLFilename() ); | 377 | table->load( todolistXMLFilename() ); |
376 | syncing = FALSE; | 378 | syncing = FALSE; |
377 | } | 379 | } |
@@ -422,49 +424,52 @@ void TodoWindow::slotFind() | |||
422 | if ( !catMenu->isItemChecked( 0 ) ) | 424 | if ( !catMenu->isItemChecked( 0 ) ) |
423 | setCategory( 0 ); | 425 | setCategory( 0 ); |
424 | 426 | ||
425 | FindDialog dlg( "Todo List", this ); | 427 | FindDialog dlg( "Todo List", this ); |
426 | QObject::connect( &dlg, | 428 | QObject::connect( &dlg, |
427 | SIGNAL(signalFindClicked(const QString &, | 429 | SIGNAL(signalFindClicked(const QString &, |
428 | bool, bool, int)), | 430 | bool, bool, int)), |
429 | table, | 431 | table, |
430 | SLOT(slotDoFind(const QString&, bool, bool, int)) ); | 432 | SLOT(slotDoFind(const QString&, bool, bool, int)) ); |
431 | QObject::connect( table, SIGNAL(signalNotFound()), &dlg, | 433 | QObject::connect( table, SIGNAL(signalNotFound()), &dlg, |
432 | SLOT(slotNotFound()) ); | 434 | SLOT(slotNotFound()) ); |
433 | QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, | 435 | QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, |
434 | SLOT(slotWrapAround()) ); | 436 | SLOT(slotWrapAround()) ); |
435 | dlg.exec(); | 437 | dlg.exec(); |
436 | if ( table->numSelections() ) | 438 | if ( table->numSelections() ) |
437 | table->clearSelection(); | 439 | table->clearSelection(); |
438 | table->clearFindRow(); | 440 | table->clearFindRow(); |
439 | } | 441 | } |
440 | 442 | ||
441 | 443 | ||
442 | void TodoWindow::setDocument( const QString &filename ) | 444 | void TodoWindow::setDocument( const QString &filename ) |
443 | { | 445 | { |
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 | } |
450 | } | 453 | } |
451 | 454 | ||
452 | static const char * beamfile = "/tmp/obex/todo.vcs"; | 455 | static const char * beamfile = "/tmp/obex/todo.vcs"; |
453 | 456 | ||
454 | void TodoWindow::slotBeam() | 457 | 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 * ) ) ); |
462 | QString description = c.description(); | 467 | QString description = c.description(); |
463 | ir->send( beamfile, description, "text/x-vCalendar" ); | 468 | ir->send( beamfile, description, "text/x-vCalendar" ); |
464 | } | 469 | } |
465 | 470 | ||
466 | void TodoWindow::beamDone( Ir *ir ) | 471 | void TodoWindow::beamDone( Ir *ir ) |
467 | { | 472 | { |
468 | delete ir; | 473 | delete ir; |
469 | unlink( beamfile ); | 474 | unlink( beamfile ); |
470 | } | 475 | } |