author | zecke <zecke> | 2002-11-30 11:20:47 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-11-30 11:20:47 (UTC) |
commit | fdda15344fdf7f71fd9e1e4db15ecc5e12224ddb (patch) (unidiff) | |
tree | 32e68b5b483dd3ce8041542e7d95f0b6d8dbf644 /core/pim/todo/mainwindow.cpp | |
parent | bd692f7ebe04e23151cce39baf311b925ccf91b1 (diff) | |
download | opie-fdda15344fdf7f71fd9e1e4db15ecc5e12224ddb.zip opie-fdda15344fdf7f71fd9e1e4db15ecc5e12224ddb.tar.gz opie-fdda15344fdf7f71fd9e1e4db15ecc5e12224ddb.tar.bz2 |
Back from hospital with new power
This versions clean up m failure on templates with Qt... in todoview
Implements Recurrance( backends to not safe it yet )
OPimState and Maintainer mode in some ways
and much more
This one also implements the OPimMainWindow specs
and has a small Memu replacement to get the toolbar in one line
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 213 |
1 files changed, 156 insertions, 57 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index 9b2423b..b2b3b8f 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -41,12 +41,13 @@ | |||
41 | #include <qpe/applnk.h> | 41 | #include <qpe/applnk.h> |
42 | #include <qpe/config.h> | 42 | #include <qpe/config.h> |
43 | #include <qpe/ir.h> | 43 | #include <qpe/ir.h> |
44 | #include <qpe/resource.h> | 44 | #include <qpe/resource.h> |
45 | #include <qpe/qpemessagebox.h> | 45 | #include <qpe/qpemessagebox.h> |
46 | 46 | ||
47 | #include <opie/orecur.h> | ||
47 | #include <opie/otodoaccessvcal.h> | 48 | #include <opie/otodoaccessvcal.h> |
48 | 49 | ||
49 | #include "quickeditimpl.h" | 50 | #include "quickeditimpl.h" |
50 | #include "todotemplatemanager.h" | 51 | #include "todotemplatemanager.h" |
51 | #include "templateeditor.h" | 52 | #include "templateeditor.h" |
52 | #include "tableview.h" | 53 | #include "tableview.h" |
@@ -56,13 +57,15 @@ | |||
56 | #include "mainwindow.h" | 57 | #include "mainwindow.h" |
57 | 58 | ||
58 | 59 | ||
59 | using namespace Todo; | 60 | using namespace Todo; |
60 | 61 | ||
61 | MainWindow::MainWindow( QWidget* parent, | 62 | MainWindow::MainWindow( QWidget* parent, |
62 | const char* name ) { | 63 | const char* name ) |
64 | : OPimMainWindow("Todolist") | ||
65 | { | ||
63 | 66 | ||
64 | m_syncing = false; | 67 | m_syncing = false; |
65 | m_counter = 0; | 68 | m_counter = 0; |
66 | m_tempManager = new TemplateManager(); | 69 | m_tempManager = new TemplateManager(); |
67 | m_tempManager->load(); | 70 | m_tempManager->load(); |
68 | 71 | ||
@@ -174,19 +177,16 @@ void MainWindow::initActions() { | |||
174 | m_bar->insertItem( tr("Category"), m_catMenu ); | 177 | m_bar->insertItem( tr("Category"), m_catMenu ); |
175 | m_bar->insertItem( tr("Options"), m_options ); | 178 | m_bar->insertItem( tr("Options"), m_options ); |
176 | 179 | ||
177 | /* initialize the view menu */ | 180 | /* initialize the view menu */ |
178 | a = new QAction( QString::null, tr("Show only over due"), | 181 | a = new QAction( QString::null, tr("Show only over due"), |
179 | 0, this, 0, TRUE ); | 182 | 0, this, 0, TRUE ); |
180 | a->addTo( m_view ); | 183 | a->addTo( m_options ); |
181 | a->setOn( showOverDue() ); | 184 | a->setOn( showOverDue() ); |
182 | connect(a, SIGNAL(toggled(bool)), | 185 | connect(a, SIGNAL(toggled(bool)), |
183 | this, SLOT(slotShowDue(bool) ) ); | 186 | this, SLOT(slotShowDue(bool) ) ); |
184 | m_view->insertSeparator(); | ||
185 | |||
186 | m_bar->insertItem( tr("View"), m_view ); | ||
187 | 187 | ||
188 | /* templates */ | 188 | /* templates */ |
189 | m_edit->insertItem(tr("New from template"), m_template, | 189 | m_edit->insertItem(tr("New from template"), m_template, |
190 | -1, 0 ); | 190 | -1, 0 ); |
191 | 191 | ||
192 | } | 192 | } |
@@ -217,13 +217,12 @@ void MainWindow::initUI() { | |||
217 | 217 | ||
218 | m_bar = new QMenuBar( m_tool ); | 218 | m_bar = new QMenuBar( m_tool ); |
219 | 219 | ||
220 | /** QPopupMenu */ | 220 | /** QPopupMenu */ |
221 | m_edit = new QPopupMenu( this ); | 221 | m_edit = new QPopupMenu( this ); |
222 | m_options = new QPopupMenu( this ); | 222 | m_options = new QPopupMenu( this ); |
223 | m_view = new QPopupMenu( this ); | ||
224 | m_catMenu = new QPopupMenu( this ); | 223 | m_catMenu = new QPopupMenu( this ); |
225 | m_template = new QPopupMenu( this ); | 224 | m_template = new QPopupMenu( this ); |
226 | 225 | ||
227 | m_catMenu->setCheckable( TRUE ); | 226 | m_catMenu->setCheckable( TRUE ); |
228 | m_template->setCheckable( TRUE ); | 227 | m_template->setCheckable( TRUE ); |
229 | 228 | ||
@@ -251,42 +250,41 @@ void MainWindow::initShow() { | |||
251 | m_stack->addWidget( m_curShow->widget() , m_counter++ ); | 250 | m_stack->addWidget( m_curShow->widget() , m_counter++ ); |
252 | } | 251 | } |
253 | MainWindow::~MainWindow() { | 252 | MainWindow::~MainWindow() { |
254 | delete templateManager(); | 253 | delete templateManager(); |
255 | } | 254 | } |
256 | void MainWindow::connectBase( ViewBase* base) { | 255 | void MainWindow::connectBase( ViewBase* base) { |
257 | base->connectShow( this, SLOT(slotShow(int) ) ); | 256 | // once templates and signals mix we'll use it again |
258 | base->connectEdit( this, SLOT(slotEdit(int) ) ); | 257 | } |
259 | base->connectUpdateSmall( this, | 258 | QPopupMenu* MainWindow::contextMenu( int , bool recur ) { |
260 | SLOT(slotUpate1(int, const Todo::SmallTodo&) )); | ||
261 | base->connectUpdateBig( this, | ||
262 | SLOT(slotUpate2(int, const OTodo& ) ) ); | ||
263 | base->connectUpdateView( this, SLOT(slotUpdate3( QWidget* ) ) ) ; | ||
264 | base->connectRemove(&m_todoMgr, | ||
265 | SLOT(remove(int)) ); | ||
266 | } | ||
267 | QPopupMenu* MainWindow::contextMenu( int uid ) { | ||
268 | QPopupMenu* menu = new QPopupMenu(); | 259 | QPopupMenu* menu = new QPopupMenu(); |
269 | 260 | ||
270 | m_editAction->addTo( menu ); | 261 | m_editAction->addTo( menu ); |
271 | m_deleteAction->addTo( menu ); | 262 | m_deleteAction->addTo( menu ); |
272 | m_duplicateAction->addTo( menu ); | 263 | m_duplicateAction->addTo( menu ); |
264 | |||
273 | menu->insertSeparator(); | 265 | menu->insertSeparator(); |
274 | 266 | ||
267 | /* | ||
268 | * if this event recurs we allow | ||
269 | * to detach it. | ||
270 | * remove all | ||
271 | */ | ||
272 | if ( recur ) { | ||
273 | ; // FIXME | ||
274 | } | ||
275 | |||
275 | return menu; | 276 | return menu; |
276 | } | 277 | } |
277 | QPopupMenu* MainWindow::options() { | 278 | QPopupMenu* MainWindow::options() { |
278 | qWarning("Options"); | 279 | qWarning("Options"); |
279 | return m_options; | 280 | return m_options; |
280 | } | 281 | } |
281 | QPopupMenu* MainWindow::edit() { | 282 | QPopupMenu* MainWindow::edit() { |
282 | return m_edit; | 283 | return m_edit; |
283 | } | 284 | } |
284 | QPopupMenu* MainWindow::view() { | ||
285 | return m_view; | ||
286 | } | ||
287 | QToolBar* MainWindow::toolbar() { | 285 | QToolBar* MainWindow::toolbar() { |
288 | return m_tool; | 286 | return m_tool; |
289 | } | 287 | } |
290 | OTodoAccess::List MainWindow::list()const { | 288 | OTodoAccess::List MainWindow::list()const { |
291 | return m_todoMgr.list(); | 289 | return m_todoMgr.list(); |
292 | } | 290 | } |
@@ -410,34 +408,13 @@ void MainWindow::slotNewFromTemplate( int id ) { | |||
410 | m_todoMgr.add( event ); | 408 | m_todoMgr.add( event ); |
411 | 409 | ||
412 | populateCategories(); | 410 | populateCategories(); |
413 | } | 411 | } |
414 | } | 412 | } |
415 | void MainWindow::slotNew() { | 413 | void MainWindow::slotNew() { |
416 | if(m_syncing) { | 414 | create(); |
417 | QMessageBox::warning(this, tr("Todo"), | ||
418 | tr("Can not edit data, currently syncing")); | ||
419 | return; | ||
420 | } | ||
421 | |||
422 | |||
423 | OTodo todo = currentEditor()->newTodo( currentCatId(), | ||
424 | this ); | ||
425 | |||
426 | if ( currentEditor()->accepted() ) { | ||
427 | //todo.assignUid(); | ||
428 | m_todoMgr.add( todo ); | ||
429 | currentView()->addEvent( todo ); | ||
430 | |||
431 | |||
432 | // I'm afraid we must call this every time now, otherwise | ||
433 | // spend expensive time comparing all these strings... | ||
434 | // but only call if we changed something -zecke | ||
435 | populateCategories(); | ||
436 | } | ||
437 | raiseCurrentView( ); | ||
438 | } | 415 | } |
439 | void MainWindow::slotDuplicate() { | 416 | void MainWindow::slotDuplicate() { |
440 | if(m_syncing) { | 417 | if(m_syncing) { |
441 | QMessageBox::warning(this, tr("Todo"), | 418 | QMessageBox::warning(this, tr("Todo"), |
442 | tr("Can not edit data, currently syncing")); | 419 | tr("Can not edit data, currently syncing")); |
443 | return; | 420 | return; |
@@ -471,13 +448,12 @@ void MainWindow::slotDeleteAll() { | |||
471 | if(m_syncing) { | 448 | if(m_syncing) { |
472 | QMessageBox::warning(this, tr("Todo"), | 449 | QMessageBox::warning(this, tr("Todo"), |
473 | tr("Can not edit data, currently syncing")); | 450 | tr("Can not edit data, currently syncing")); |
474 | return; | 451 | return; |
475 | } | 452 | } |
476 | 453 | ||
477 | //QString strName = table->text( table->currentRow(), 2 ).left( 30 ); | ||
478 | 454 | ||
479 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) ) | 455 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) ) |
480 | return; | 456 | return; |
481 | 457 | ||
482 | m_todoMgr.removeAll(); | 458 | m_todoMgr.removeAll(); |
483 | currentView()->clear(); | 459 | currentView()->clear(); |
@@ -491,14 +467,14 @@ void MainWindow::slotDeleteCompleted() { | |||
491 | return; | 467 | return; |
492 | } | 468 | } |
493 | 469 | ||
494 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) ) | 470 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) ) |
495 | return; | 471 | return; |
496 | 472 | ||
497 | // FIXME | 473 | |
498 | //m_todoMgr.remove( currentView()->completed() ); | 474 | m_todoMgr.removeCompleted(); |
499 | currentView()->updateView( ); | 475 | currentView()->updateView( ); |
500 | } | 476 | } |
501 | void MainWindow::slotFind() { | 477 | void MainWindow::slotFind() { |
502 | 478 | ||
503 | } | 479 | } |
504 | void MainWindow::slotEdit() { | 480 | void MainWindow::slotEdit() { |
@@ -549,24 +525,13 @@ void MainWindow::setDocument( const QString& fi) { | |||
549 | else | 525 | else |
550 | receiveFile(fi ); | 526 | receiveFile(fi ); |
551 | } | 527 | } |
552 | 528 | ||
553 | static const char *beamfile = "/tmp/opie-todo.vcs"; | 529 | static const char *beamfile = "/tmp/opie-todo.vcs"; |
554 | void MainWindow::slotBeam() { | 530 | void MainWindow::slotBeam() { |
555 | ::unlink( beamfile ); | 531 | beam( currentView()->current() ); |
556 | OTodo todo = event( currentView()->current() ); | ||
557 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); | ||
558 | OTodoAccess acc( cal ); | ||
559 | acc.load(); | ||
560 | acc.add( todo ); | ||
561 | acc.save(); | ||
562 | Ir* ir = new Ir(this ); | ||
563 | connect(ir, SIGNAL(done(Ir*) ), | ||
564 | this, SLOT(beamDone(Ir*) ) ); | ||
565 | ir->send( beamfile, todo.summary(), "text/x-vCalendar" ); | ||
566 | |||
567 | } | 532 | } |
568 | void MainWindow::beamDone( Ir* ir) { | 533 | void MainWindow::beamDone( Ir* ir) { |
569 | delete ir; | 534 | delete ir; |
570 | ::unlink( beamfile ); | 535 | ::unlink( beamfile ); |
571 | } | 536 | } |
572 | void MainWindow::receiveFile( const QString& filename ) { | 537 | void MainWindow::receiveFile( const QString& filename ) { |
@@ -701,6 +666,140 @@ void MainWindow::slotQuickEntered() { | |||
701 | currentView()->addEvent( todo ); | 666 | currentView()->addEvent( todo ); |
702 | raiseCurrentView(); | 667 | raiseCurrentView(); |
703 | } | 668 | } |
704 | QuickEditBase* MainWindow::quickEditor() { | 669 | QuickEditBase* MainWindow::quickEditor() { |
705 | return m_curQuick; | 670 | return m_curQuick; |
706 | } | 671 | } |
672 | void MainWindow::slotComplete( int uid ) { | ||
673 | slotComplete( event(uid) ); | ||
674 | } | ||
675 | void MainWindow::slotComplete( const OTodo& todo ) { | ||
676 | OTodo to = todo; | ||
677 | to.setCompleted( !to.isCompleted() ); | ||
678 | to.setCompletedDate( QDate::currentDate() ); | ||
679 | |||
680 | /* | ||
681 | * if the item does recur | ||
682 | * we need to spin it off | ||
683 | * and update the items duedate to the next | ||
684 | * possible recurrance of this item... | ||
685 | * the spinned off one will loose the | ||
686 | */ | ||
687 | if ( to.recurrence().doesRecur() && to.isCompleted() ) { | ||
688 | OTodo to2( to ); | ||
689 | |||
690 | /* the spinned off one won't recur anymore */ | ||
691 | to.setRecurrence( ORecur() ); | ||
692 | |||
693 | ORecur rec = to2.recurrence(); | ||
694 | rec.setStart( to.dueDate() ); | ||
695 | to2.setRecurrence( rec ); | ||
696 | /* | ||
697 | * if there is a next occurence | ||
698 | * from the duedate of the last recurrance | ||
699 | */ | ||
700 | QDate date; | ||
701 | if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { | ||
702 | QDate inval; | ||
703 | /* generate a new uid for the old record */ | ||
704 | to.setUid( 1 ); | ||
705 | |||
706 | /* add the old one cause it has a new UID here cause it was spin off */ | ||
707 | m_todoMgr.add( to ); | ||
708 | |||
709 | /* | ||
710 | * update the due date | ||
711 | * start date | ||
712 | * and complete date | ||
713 | */ | ||
714 | to2.setDueDate( date ); | ||
715 | to2.setStartDate( inval ); | ||
716 | to2.setCompletedDate( inval ); | ||
717 | to2.setCompleted( false ); | ||
718 | updateTodo( to2 ); | ||
719 | }else | ||
720 | updateTodo( to ); | ||
721 | }else | ||
722 | updateTodo( to ); | ||
723 | |||
724 | currentView()->updateView(); | ||
725 | raiseCurrentView(); | ||
726 | } | ||
727 | void MainWindow::flush() { | ||
728 | slotFlush(); | ||
729 | } | ||
730 | void MainWindow::reload() { | ||
731 | slotReload(); | ||
732 | } | ||
733 | int MainWindow::create() { | ||
734 | int uid = 0; | ||
735 | if(m_syncing) { | ||
736 | QMessageBox::warning(this, tr("Todo"), | ||
737 | tr("Can not edit data, currently syncing")); | ||
738 | return uid; | ||
739 | } | ||
740 | |||
741 | |||
742 | OTodo todo = currentEditor()->newTodo( currentCatId(), | ||
743 | this ); | ||
744 | |||
745 | if ( currentEditor()->accepted() ) { | ||
746 | //todo.assignUid(); | ||
747 | uid = todo.uid(); | ||
748 | m_todoMgr.add( todo ); | ||
749 | currentView()->addEvent( todo ); | ||
750 | |||
751 | |||
752 | // I'm afraid we must call this every time now, otherwise | ||
753 | // spend expensive time comparing all these strings... | ||
754 | // but only call if we changed something -zecke | ||
755 | populateCategories(); | ||
756 | } | ||
757 | raiseCurrentView( ); | ||
758 | |||
759 | return uid; | ||
760 | } | ||
761 | /* delete it silently... */ | ||
762 | bool MainWindow::remove( int uid ) { | ||
763 | if (m_syncing) return false; | ||
764 | |||
765 | return m_todoMgr.remove( uid ); | ||
766 | } | ||
767 | void MainWindow::beam( int uid, int ) { | ||
768 | ::unlink( beamfile ); | ||
769 | OTodo todo = event( uid ); | ||
770 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); | ||
771 | OTodoAccess acc( cal ); | ||
772 | acc.load(); | ||
773 | acc.add( todo ); | ||
774 | acc.save(); | ||
775 | Ir* ir = new Ir(this ); | ||
776 | connect(ir, SIGNAL(done(Ir*) ), | ||
777 | this, SLOT(beamDone(Ir*) ) ); | ||
778 | ir->send( beamfile, todo.summary(), "text/x-vCalendar" ); | ||
779 | } | ||
780 | void MainWindow::show( int uid ) { | ||
781 | slotShow( uid ); | ||
782 | } | ||
783 | void MainWindow::edit( int uid ) { | ||
784 | slotEdit( uid ); | ||
785 | } | ||
786 | void MainWindow::add( const OPimRecord& rec) { | ||
787 | if ( rec.rtti() != OTodo::rtti() ) return; | ||
788 | |||
789 | const OTodo& todo = static_cast<const OTodo&>(rec); | ||
790 | |||
791 | m_todoMgr.add(todo ); | ||
792 | currentView()->addEvent( todo ); | ||
793 | |||
794 | |||
795 | // I'm afraid we must call this every time now, otherwise | ||
796 | // spend expensive time comparing all these strings... | ||
797 | // but only call if we changed something -zecke | ||
798 | populateCategories(); | ||
799 | } | ||
800 | /* todo does not have the QDataStream<< and >> operators implemented :( | ||
801 | * FIXME | ||
802 | */ | ||
803 | OPimRecord* MainWindow::record( int rtti, const QByteArray& ) { | ||
804 | return 0l; | ||
805 | } | ||