summaryrefslogtreecommitdiff
path: root/core/pim/todo/mainwindow.cpp
Unidiff
Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp634
1 files changed, 0 insertions, 634 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
deleted file mode 100644
index 974951e..0000000
--- a/core/pim/todo/mainwindow.cpp
+++ b/dev/null
@@ -1,634 +0,0 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 zecke
4** Copyright (C) 2002 Stefan Eilers (se, eilers.stefan@epost.de)
5**
6** This file is part of Qtopia Environment.
7**
8** This file may be distributed and/or modified under the terms of the
9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file.
12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17**
18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you.
20**
21**********************************************************************/
22
23#define QTOPIA_INTERNAL_FD
24
25#include "mainwindow.h"
26#include "todoentryimpl.h"
27#include "todotable.h"
28#include "todolabel.h"
29
30#include <opie/tododb.h>
31#include <opie/todovcalresource.h>
32#include <opie/ofontmenu.h>
33
34#include <qpe/qpeapplication.h>
35#include <qpe/config.h>
36#include <qpe/finddialog.h>
37#include <qpe/global.h>
38#include <qpe/ir.h>
39#include <qpe/qpemenubar.h>
40#include <qpe/qpemessagebox.h>
41#include <qpe/resource.h>
42//#include <qpe/task.h>
43#include <qpe/qpetoolbar.h>
44
45#include <qaction.h>
46#include <qarray.h>
47#include <qdatastream.h>
48#include <qdatetime.h>
49#include <qfile.h>
50#include <qmessagebox.h>
51#include <qpopupmenu.h>
52#include <qwidgetstack.h>
53
54#include <sys/stat.h>
55#include <sys/types.h>
56#include <fcntl.h>
57#include <unistd.h>
58
59#include <stdlib.h>
60
61static QString todolistXMLFilename()
62{
63 return Global::applicationFileName("todolist","todolist.xml");
64}
65
66static QString categoriesXMLFilename()
67{
68 return Global::applicationFileName("todolist","categories.xml");
69}
70
71TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f ) :
72 QMainWindow( parent, name, f ), syncing(FALSE)
73{
74// QTime t;
75// t.start();
76 mView = 0l;
77 mStack = new QWidgetStack(this, "main stack");
78 setCentralWidget( mStack );
79 setCaption( tr("Todo") );
80 QString str;
81 table = new TodoTable( this );
82 table->setColumnWidth( 2, 10 );
83 table->setPaintingEnabled( FALSE );
84 table->setUpdatesEnabled( FALSE );
85 table->viewport()->setUpdatesEnabled( FALSE );
86
87 {
88 str = todolistXMLFilename();
89 if ( str.isNull() )
90 QMessageBox::critical( this,
91 tr("Out of Space"),
92 tr("Unable to create startup files\n"
93 "Free up some space\n"
94 "before you enter any data") );
95 else
96 table->load( str );
97 }
98
99 // repeat for categories...
100 str = categoriesXMLFilename();
101 if ( str.isNull() )
102 QMessageBox::critical( this,
103 tr( "Out of Space" ),
104 tr( "Unable to create startup files\n"
105 "Free up some space\n"
106 "before you enter any data") );
107
108 mStack->addWidget(table, 1 );
109 mStack->raiseWidget( 1 );
110 setCentralWidget( mStack );
111 setToolBarsMovable( FALSE );
112
113// qDebug("after load: t=%d", t.elapsed() );
114
115 Config config( "todo" );
116 config.setGroup( "View" );
117 bool complete = config.readBoolEntry( "ShowComplete", true );
118 table->setShowCompleted( complete );
119
120 bool showdeadline = config.readBoolEntry("ShowDeadLine", true);
121 table->setShowDeadline (showdeadline);
122
123 QString category = config.readEntry( "Category", QString::null );
124 table->setShowCategory( category );
125
126 QPEToolBar *bar = new QPEToolBar( this );
127 bar->setHorizontalStretchable( TRUE );
128
129 QPEMenuBar *mb = new QPEMenuBar( bar );
130
131 catMenu = new QPopupMenu( this );
132 QPopupMenu *edit = new QPopupMenu( this );
133 QPopupMenu *options = new QPopupMenu(this );
134
135 contextMenu = new QPopupMenu( this );
136
137 bar = new QPEToolBar( this );
138
139 QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ),
140 QString::null, 0, this, 0 );
141 connect( a, SIGNAL( activated() ),
142 this, SLOT( slotNew() ) );
143 a->addTo( bar );
144 a->addTo( edit );
145
146 a = new QAction( tr( "Edit Task" ), Resource::loadIconSet( "edit" ),
147 QString::null, 0, this, 0 );
148 connect( a, SIGNAL( activated() ),
149 this, SLOT( slotEdit() ) );
150 a->addTo( bar );
151 a->addTo( edit );
152 a->addTo( contextMenu );
153 a->setEnabled( FALSE );
154 editAction = a;
155
156 a = new QAction( QString::null, tr("View Task"), 0, this, 0 );
157 a->addTo( edit );
158 a->addTo( contextMenu );
159 connect( a, SIGNAL( activated() ),
160 this, SLOT(slotShowDetails() ) );
161 viewAction = a;
162
163 edit->insertSeparator();
164
165 a = new QAction( tr( "Delete..." ), Resource::loadIconSet( "trash" ),
166 QString::null, 0, this, 0 );
167 connect( a, SIGNAL( activated() ),
168 this, SLOT( slotDelete() ) );
169 a->addTo( bar );
170 a->addTo( edit );
171 a->addTo( contextMenu );
172 a->setEnabled( FALSE );
173 deleteAction = a;
174
175 // delete All in category is missing....
176 // set All Done
177 // set All Done in category
178
179 a = new QAction( QString::null, tr( "Delete all..."), 0, this, 0 );
180 connect(a, SIGNAL( activated() ),
181 this, SLOT( slotDeleteAll() ) );
182 a->addTo(edit );
183 a->setEnabled( FALSE );
184 deleteAllAction = a;
185
186 edit->insertSeparator();
187 a = new QAction( QString::null, tr("Duplicate" ), 0, this, 0 );
188 connect(a, SIGNAL( activated() ),
189 this, SLOT( slotDuplicate() ) );
190 a->addTo(edit );
191 a->setEnabled( FALSE );
192 duplicateAction = a;
193 edit->insertSeparator();
194
195
196
197 if ( Ir::supported() ) {
198 a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ),
199 QString::null, 0, this, 0 );
200 connect( a, SIGNAL( activated() ),
201 this, SLOT( slotBeam() ) );
202 a->addTo( edit );
203 a->addTo( bar );
204 }
205
206 a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ),
207 QString::null, 0, this, 0 );
208 connect( a, SIGNAL( activated() ),
209 this, SLOT( slotFind() ) );
210// a->addTo( bar );
211 a->addTo( options );
212 options->insertSeparator();
213
214 if ( table->numRows() )
215 a->setEnabled( TRUE );
216 else
217 a->setEnabled( FALSE );
218
219 //a->setEnabled( FALSE );
220 findAction = a;
221// qDebug("mainwindow #2: t=%d", t.elapsed() );
222
223 completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE );
224
225 showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE );
226
227 catMenu->setCheckable( true );
228 populateCategories();
229
230
231 completedAction->addTo( options );
232 completedAction->setOn( table->showCompleted() );
233 showdeadlineAction->addTo( options );
234 showdeadlineAction->setOn( table->showDeadline() );
235 options->insertSeparator( );
236 QList<QWidget> list;
237 list.append(table );
238 OFontMenu *menu = new OFontMenu(this, "menu",list );
239 menu->forceSize( table->horizontalHeader(), 10 );
240 //catMenu->insertItem(tr("Fonts"), menu );
241 list.clear();
242 options->insertItem( tr("Fonts"), menu );
243
244
245 mb->insertItem( tr( "Data" ), edit );
246 mb->insertItem( tr( "Category" ), catMenu );
247 mb->insertItem( tr( "Options"), options );
248 resize( 200, 300 );
249 if ( table->numRows() > 0 )
250 currentEntryChanged( 0, 0 );
251 connect( table, SIGNAL( signalEdit() ),
252 this, SLOT( slotEdit() ) );
253 connect( table, SIGNAL(signalShowMenu(const QPoint &)),
254 this, SLOT( slotShowPopup(const QPoint &)) );
255
256// qDebug("mainwindow #3: t=%d", t.elapsed() );
257 table->updateVisible();
258 table->setUpdatesEnabled( TRUE );
259 table->setPaintingEnabled( TRUE );
260 table->viewport()->setUpdatesEnabled( TRUE );
261
262 // Initialize the table
263 table->updateVisible();
264
265 connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) );
266 connect( showdeadlineAction, SIGNAL( toggled(bool) ), this, SLOT( showDeadline(bool) ) );
267 connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) );
268 connect( table, SIGNAL( currentChanged( int, int ) ),
269 this, SLOT( currentEntryChanged( int, int ) ) );
270
271 connect( table, SIGNAL(showDetails(const ToDoEvent &) ),
272 this, SLOT(slotShowDetails(const ToDoEvent & ) ) );
273// qDebug("done: t=%d", t.elapsed() );
274}
275
276void TodoWindow::slotNew()
277{
278 if(syncing) {
279 QMessageBox::warning(this, tr("Todo"),
280 tr("Can not edit data, currently syncing"));
281 return;
282 }
283
284 int id;
285 id = -1;
286 QArray<int> ids;
287 ids = table->currentEntry().categories();
288 if ( ids.count() )
289 id = ids[0];
290 NewTaskDialog e( id, this, 0, TRUE );
291
292 ToDoEvent todo;
293
294#if defined(Q_WS_QWS) || defined(_WS_QWS_)
295 e.showMaximized();
296#endif
297 int ret = e.exec();
298// qWarning("finished" );
299 if ( ret == QDialog::Accepted ) {
300 table->setPaintingEnabled( false );
301 todo = e.todoEntry();
302 //todo.assignUid();
303 table->addEntry( todo );
304 table->setPaintingEnabled( true );
305 findAction->setEnabled( TRUE );
306 }
307 // I'm afraid we must call this every time now, otherwise
308 // spend expensive time comparing all these strings...
309 populateCategories();
310 mStack->raiseWidget(1 );
311}
312
313TodoWindow::~TodoWindow()
314{
315}
316
317void TodoWindow::slotDelete()
318{
319 if(syncing) {
320 QMessageBox::warning(this, tr("Todo"),
321 tr("Can not edit data, currently syncing"));
322 return;
323 }
324
325 if ( table->currentRow() == -1 )
326 return;
327
328 QString strName = table->text( table->currentRow(), 2 ).left( 30 );
329
330 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) )
331 return;
332
333
334
335 table->setPaintingEnabled( false );
336 table->removeCurrentEntry();
337 table->setPaintingEnabled( true );
338
339 if ( table->numRows() == 0 ) {
340 currentEntryChanged( -1, 0 );
341 findAction->setEnabled( FALSE );
342 }
343 mStack->raiseWidget(1);
344}
345void TodoWindow::slotDeleteAll()
346{
347 if(syncing) {
348 QMessageBox::warning(this, tr("Todo"),
349 tr("Can not edit data, currently syncing"));
350 return;
351 }
352
353 //QString strName = table->text( table->currentRow(), 2 ).left( 30 );
354
355 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks") ) )
356 return;
357
358
359
360 table->setPaintingEnabled( false );
361 table->removeAllEntries();
362 table->setPaintingEnabled( true );
363
364 if ( table->numRows() == 0 ) {
365 currentEntryChanged( -1, 0 );
366 findAction->setEnabled( FALSE );
367 }
368 mStack->raiseWidget(1 );
369}
370
371void TodoWindow::slotEdit()
372{
373 if(syncing) {
374 QMessageBox::warning(this, tr("Todo"),
375 tr("Can not edit data, currently syncing"));
376 return;
377 }
378
379 ToDoEvent todo = table->currentEntry();
380 qWarning("slotEdit" );
381 NewTaskDialog e( todo, this, 0, TRUE );
382 e.setCaption( tr( "Edit Task" ) );
383
384#if defined(Q_WS_QWS) || defined(_WS_QWS_)
385 e.showMaximized();
386#endif
387 int ret = e.exec();
388
389 if ( ret == QDialog::Accepted ) {
390 qWarning("Replacing now" );
391 table->setPaintingEnabled( false );
392 todo = e.todoEntry();
393 table->replaceCurrentEntry( todo );
394 table->setPaintingEnabled( true );
395 }
396 populateCategories();
397 mStack->raiseWidget( 1 );
398}
399void TodoWindow::slotDuplicate()
400{
401 if(syncing) {
402 QMessageBox::warning(this, tr("Todo"),
403 tr("Can not edit data, currently syncing"));
404 return;
405 }
406 ToDoEvent ev = table->currentEntry();
407 ToDoEvent ev2 = ToDoEvent( ev ); // what about the uid
408 int uid;
409 { // uid
410 Qtopia::UidGen *uidgen = new Qtopia::UidGen();
411 uid = uidgen->generate();
412 delete uidgen;
413 }
414 ev2.setUid( uid );
415 table->setPaintingEnabled( false );
416 table->addEntry( ev2 );
417 table->setPaintingEnabled( true );
418
419 mStack->raiseWidget( 1 );
420}
421void TodoWindow::slotShowPopup( const QPoint &p )
422{
423 contextMenu->popup( p );
424}
425
426void TodoWindow::showCompleted( bool s )
427{
428 if ( !table->isUpdatesEnabled() )
429 return;
430 table->setPaintingEnabled( false );
431 table->setShowCompleted( s );
432 table->setPaintingEnabled( true );
433 mStack->raiseWidget( 1 );
434}
435
436void TodoWindow::currentEntryChanged( int r, int )
437{
438 if ( r != -1 && table->rowHeight( r ) > 0 ) {
439 editAction->setEnabled( TRUE );
440 viewAction->setEnabled( TRUE );
441 deleteAction->setEnabled( TRUE );
442 duplicateAction->setEnabled( TRUE );
443 deleteAllAction->setEnabled( TRUE );
444 } else {
445 editAction->setEnabled( FALSE );
446 viewAction->setEnabled( FALSE );
447 deleteAction->setEnabled( FALSE );
448 duplicateAction->setEnabled( FALSE );
449 deleteAllAction->setEnabled( FALSE );
450 }
451}
452
453void TodoWindow::setCategory( int c )
454{
455 if ( c <= 0 ) return;
456 if ( !table->isUpdatesEnabled() )
457 return;
458 table->setPaintingEnabled( false );
459 for ( unsigned int i = 1; i < catMenu->count(); i++ )
460 catMenu->setItemChecked( i, c == (int)i );
461 if ( c == 1 ) {
462 table->setShowCategory( QString::null );
463 setCaption( tr("Todo") + " - " + tr( "All Categories" ) );
464 } else if ( c == (int)catMenu->count() - 1 ) {
465 table->setShowCategory( tr( "Unfiled" ) );
466 setCaption( tr("Todo") + " - " + tr( "Unfiled" ) );
467 } else {
468 QString cat = table->categories()[c - 2];
469 table->setShowCategory( cat );
470 setCaption( tr("Todo") + " - " + cat );
471 }
472 table->setPaintingEnabled( true );
473
474 mStack->raiseWidget( 1 );
475}
476
477void TodoWindow::populateCategories()
478{
479 catMenu->clear();
480 int id, rememberId;
481 id = 1;
482 rememberId = 0;
483 catMenu->insertItem( tr( "All Categories" ), id++ );
484 catMenu->insertSeparator();
485 QStringList categories = table->categories();
486 categories.append( tr( "Unfiled" ) );
487 for ( QStringList::Iterator it = categories.begin();
488 it != categories.end(); ++it ) {
489 catMenu->insertItem( *it, id );
490 if ( *it == table->showCategory() )
491 rememberId = id;
492 ++id;
493 }
494 if ( table->showCategory().isEmpty() )
495 setCategory( 1 );
496 else
497 setCategory( rememberId );
498}
499
500void TodoWindow::reload()
501{
502 table->clear();
503 table->load( todolistXMLFilename() );
504 syncing = FALSE;
505}
506
507void TodoWindow::flush()
508{
509 syncing = TRUE;
510 table->save( todolistXMLFilename() );
511}
512
513void TodoWindow::closeEvent( QCloseEvent *e )
514{
515 if( mStack->visibleWidget() != table ){
516 mStack->raiseWidget( 1 );
517 e->ignore();
518 return;
519 }
520 if(syncing) {
521 /* no need to save if in the middle of syncing */
522 e->accept();
523 return;
524 }
525
526 if ( table->save( todolistXMLFilename() ) ) {
527 e->accept();
528 // repeat for categories...
529 // if writing configs fail, it will emit an
530 // error, but I feel that it is "ok" for us to exit
531 // espically since we aren't told if the write succeeded...
532 Config config( "todo" );
533 config.setGroup( "View" );
534 config.writeEntry( "ShowComplete", table->showCompleted() );
535 config.writeEntry( "Category", table->showCategory() );
536 /* added 20.01.2k2 by se */
537 config.writeEntry( "ShowDeadLine", table->showDeadline());
538 } else {
539 if ( QMessageBox::critical( this, tr("Out of space"),
540 tr("Todo was unable\n"
541 "to save your changes.\n"
542 "Free up some space\n"
543 "and try again.\n"
544 "\nQuit Anyway?"),
545 QMessageBox::Yes|QMessageBox::Escape,
546 QMessageBox::No|QMessageBox::Default)
547 != QMessageBox::No )
548 e->accept();
549 else
550 e->ignore();
551 }
552}
553
554void TodoWindow::slotFind()
555{
556 // put everything back to view all for searching...
557 mStack->raiseWidget( 1 );
558 if ( !catMenu->isItemChecked( 0 ) )
559 setCategory( 0 );
560
561 FindDialog dlg( "Todo List", this );
562 QObject::connect( &dlg,
563 SIGNAL(signalFindClicked(const QString &,
564 bool, bool, int)),
565 table,
566 SLOT(slotDoFind(const QString&, bool, bool, int)) );
567 QObject::connect( table, SIGNAL(signalNotFound()), &dlg,
568 SLOT(slotNotFound()) );
569 QObject::connect( table, SIGNAL(signalWrapAround()), &dlg,
570 SLOT(slotWrapAround()) );
571 dlg.exec();
572 if ( table->numSelections() )
573 table->clearSelection();
574 table->clearFindRow();
575}
576
577
578void TodoWindow::setDocument( const QString &filename )
579{
580 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
581
582 ToDoDB todoDB(filename, new ToDoVCalResource() );
583 QValueList<ToDoEvent> tl = todoDB.rawToDos();
584 for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
585 table->addEntry( *it );
586 }
587}
588
589static const char * beamfile = "/tmp/obex/todo.vcs";
590
591void TodoWindow::slotBeam()
592{
593 unlink( beamfile ); // delete if exists
594 ToDoEvent c = table->currentEntry();
595 mkdir("/tmp/obex/", 0755);
596 ToDoDB todoDB( beamfile, new ToDoVCalResource() );
597 todoDB.addEvent( c );
598 todoDB.save();
599 Ir *ir = new Ir( this );
600 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
601 QString description = c.summary();
602 ir->send( beamfile, description, "text/x-vCalendar" );
603}
604
605void TodoWindow::beamDone( Ir *ir )
606{
607 delete ir;
608 unlink( beamfile );
609}
610
611void TodoWindow::showDeadline( bool s )
612{
613 if ( !table->isUpdatesEnabled() )
614 return;
615 table->setPaintingEnabled( false );
616 table->setShowDeadline( s );
617 table->setPaintingEnabled( true );
618 mStack->raiseWidget( 1 );
619}
620void TodoWindow::slotShowDetails()
621{
622 ToDoEvent event = table->currentEntry();
623 slotShowDetails( event );
624}
625void TodoWindow::slotShowDetails( const ToDoEvent &event )
626{
627 if( mView == 0l ){
628 mView = new TodoLabel(mStack);
629 mStack->addWidget( mView, 2 );
630 }
631 mView->init( event );
632 mView->sync();
633 mStack->raiseWidget( 2);
634}