author | zecke <zecke> | 2003-05-12 13:21:59 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-05-12 13:21:59 (UTC) |
commit | 9a4c9544a59f8395f2ec5e7c99028570f8bd8bd1 (patch) (unidiff) | |
tree | 8af13b984750f743b7f9f06bbf04b531b1a10ff2 /core/pim/todo/mainwindow.cpp | |
parent | a4c8b8912c9e87a2fd76103193e6b4f91c2a2c5d (diff) | |
download | opie-9a4c9544a59f8395f2ec5e7c99028570f8bd8bd1.zip opie-9a4c9544a59f8395f2ec5e7c99028570f8bd8bd1.tar.gz opie-9a4c9544a59f8395f2ec5e7c99028570f8bd8bd1.tar.bz2 |
Hospital Hacking Session
make more translatable
fix up GUI for Opie1.0 in regards what is implemnted
implement setting and removing of Alarms!!!!
Show Alarms once they got fired...
Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 133 |
1 files changed, 131 insertions, 2 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index c5cedc6..5119ae0 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -27,31 +27,36 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qmenubar.h> | 31 | #include <qmenubar.h> |
32 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
33 | #include <qtoolbar.h> | 33 | #include <qtoolbar.h> |
34 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <qpushbutton.h> | ||
35 | #include <qwidgetstack.h> | 36 | #include <qwidgetstack.h> |
36 | #include <qaction.h> | 37 | #include <qaction.h> |
37 | #include <qtimer.h> | 38 | #include <qtimer.h> |
38 | #include <qvbox.h> | 39 | #include <qvbox.h> |
39 | #include <qlayout.h> | 40 | #include <qlayout.h> |
40 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
41 | #include <qwhatsthis.h> | 42 | #include <qwhatsthis.h> |
42 | 43 | ||
43 | #include <qpe/applnk.h> | 44 | #include <qpe/applnk.h> |
44 | #include <qpe/config.h> | 45 | #include <qpe/config.h> |
45 | #include <qpe/ir.h> | 46 | #include <qpe/ir.h> |
46 | #include <qpe/resource.h> | 47 | #include <qpe/resource.h> |
47 | #include <qpe/qpemessagebox.h> | 48 | #include <qpe/qpemessagebox.h> |
49 | #include <qpe/alarmserver.h> | ||
50 | #include <qpe/timestring.h> | ||
51 | #include <qpe/qpeapplication.h> | ||
48 | 52 | ||
49 | #include <opie/orecur.h> | 53 | #include <opie/orecur.h> |
54 | #include <opie/opimnotifymanager.h> | ||
50 | #include <opie/otodoaccessvcal.h> | 55 | #include <opie/otodoaccessvcal.h> |
51 | 56 | ||
52 | #include "quickeditimpl.h" | 57 | #include "quickeditimpl.h" |
53 | #include "todotemplatemanager.h" | 58 | #include "todotemplatemanager.h" |
54 | #include "templateeditor.h" | 59 | #include "templateeditor.h" |
55 | #include "tableview.h" | 60 | #include "tableview.h" |
56 | 61 | ||
57 | #include "textviewshow.h" | 62 | #include "textviewshow.h" |
@@ -296,31 +301,38 @@ QToolBar* MainWindow::toolbar() { | |||
296 | } | 301 | } |
297 | OTodoAccess::List MainWindow::list()const { | 302 | OTodoAccess::List MainWindow::list()const { |
298 | return m_todoMgr.list(); | 303 | return m_todoMgr.list(); |
299 | } | 304 | } |
300 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { | 305 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { |
301 | int cat = 0; | 306 | int cat = 0; |
302 | if ( m_curCat != QWidget::tr("All Categories") ) | 307 | if ( m_curCat != QWidget::tr("All Categories") ) |
303 | cat = currentCatId(); | 308 | cat = currentCatId(); |
309 | if ( m_curCat == QWidget::tr("Unfiled") ) | ||
310 | cat = -1; | ||
311 | |||
312 | qWarning(" Category %d %s", cat, m_curCat.latin1() ); | ||
304 | 313 | ||
305 | int filter = 1; | 314 | int filter = 1; |
306 | 315 | ||
307 | if (!m_completed ) | 316 | if (!m_completed ) |
308 | filter |= 4; | 317 | filter |= 4; |
309 | if (m_overdue) | 318 | if (m_overdue) |
310 | filter |= 2; | 319 | filter |= 2; |
311 | 320 | ||
312 | return m_todoMgr.sorted( asc, sortOrder, filter, cat ); | 321 | return m_todoMgr.sorted( asc, sortOrder, filter, cat ); |
313 | } | 322 | } |
314 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { | 323 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { |
315 | int cat = 0; | 324 | int cat = 0; |
316 | if ( m_curCat != QWidget::tr("All Categories") ) | 325 | if ( m_curCat != QWidget::tr("All Categories") ) |
317 | cat = currentCatId(); | 326 | cat = currentCatId(); |
318 | 327 | ||
328 | if ( m_curCat == QWidget::tr("Unfiled") ) | ||
329 | cat = -1; | ||
330 | |||
319 | return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); | 331 | return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); |
320 | } | 332 | } |
321 | OTodo MainWindow::event( int uid ) { | 333 | OTodo MainWindow::event( int uid ) { |
322 | return m_todoMgr.event( uid ); | 334 | return m_todoMgr.event( uid ); |
323 | } | 335 | } |
324 | bool MainWindow::isSyncing()const { | 336 | bool MainWindow::isSyncing()const { |
325 | return m_syncing; | 337 | return m_syncing; |
326 | } | 338 | } |
@@ -445,16 +457,17 @@ void MainWindow::slotDelete() { | |||
445 | QMessageBox::warning(this, QWidget::tr("Todo"), | 457 | QMessageBox::warning(this, QWidget::tr("Todo"), |
446 | QWidget::tr("Can not edit data, currently syncing")); | 458 | QWidget::tr("Can not edit data, currently syncing")); |
447 | return; | 459 | return; |
448 | } | 460 | } |
449 | QString strName = currentView()->currentRepresentation(); | 461 | QString strName = currentView()->currentRepresentation(); |
450 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) | 462 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) |
451 | return; | 463 | return; |
452 | 464 | ||
465 | handleAlarms( OTodo(), m_todoMgr.event( currentView()->current() ) ); | ||
453 | m_todoMgr.remove( currentView()->current() ); | 466 | m_todoMgr.remove( currentView()->current() ); |
454 | currentView()->removeEvent( currentView()->current() ); | 467 | currentView()->removeEvent( currentView()->current() ); |
455 | raiseCurrentView(); | 468 | raiseCurrentView(); |
456 | } | 469 | } |
457 | void MainWindow::slotDeleteAll() { | 470 | void MainWindow::slotDeleteAll() { |
458 | if(m_syncing) { | 471 | if(m_syncing) { |
459 | QMessageBox::warning(this, QWidget::tr("Todo"), | 472 | QMessageBox::warning(this, QWidget::tr("Todo"), |
460 | QWidget::tr("Can not edit data, currently syncing")); | 473 | QWidget::tr("Can not edit data, currently syncing")); |
@@ -636,23 +649,24 @@ void MainWindow::slotShow( int uid ) { | |||
636 | void MainWindow::slotEdit( int uid ) { | 649 | void MainWindow::slotEdit( int uid ) { |
637 | if (uid == 1 ) return; | 650 | if (uid == 1 ) return; |
638 | if(m_syncing) { | 651 | if(m_syncing) { |
639 | QMessageBox::warning(this, QWidget::tr("Todo"), | 652 | QMessageBox::warning(this, QWidget::tr("Todo"), |
640 | QWidget::tr("Can not edit data, currently syncing")); | 653 | QWidget::tr("Can not edit data, currently syncing")); |
641 | return; | 654 | return; |
642 | } | 655 | } |
643 | 656 | ||
644 | OTodo todo = m_todoMgr.event( uid ); | 657 | OTodo old_todo = m_todoMgr.event( uid ); |
645 | 658 | ||
646 | todo = currentEditor()->edit(this, todo ); | 659 | OTodo todo = currentEditor()->edit(this, old_todo ); |
647 | 660 | ||
648 | /* if completed */ | 661 | /* if completed */ |
649 | if ( currentEditor()->accepted() ) { | 662 | if ( currentEditor()->accepted() ) { |
650 | qWarning("Replacing now" ); | 663 | qWarning("Replacing now" ); |
664 | handleAlarms( old_todo, todo ); | ||
651 | m_todoMgr.update( todo.uid(), todo ); | 665 | m_todoMgr.update( todo.uid(), todo ); |
652 | currentView()->replaceEvent( todo ); | 666 | currentView()->replaceEvent( todo ); |
653 | /* a Category might have changed */ | 667 | /* a Category might have changed */ |
654 | populateCategories(); | 668 | populateCategories(); |
655 | } | 669 | } |
656 | 670 | ||
657 | raiseCurrentView(); | 671 | raiseCurrentView(); |
658 | } | 672 | } |
@@ -761,16 +775,17 @@ int MainWindow::create() { | |||
761 | 775 | ||
762 | 776 | ||
763 | OTodo todo = currentEditor()->newTodo( currentCatId(), | 777 | OTodo todo = currentEditor()->newTodo( currentCatId(), |
764 | this ); | 778 | this ); |
765 | 779 | ||
766 | if ( currentEditor()->accepted() ) { | 780 | if ( currentEditor()->accepted() ) { |
767 | //todo.assignUid(); | 781 | //todo.assignUid(); |
768 | uid = todo.uid(); | 782 | uid = todo.uid(); |
783 | handleAlarms( OTodo(), todo ); | ||
769 | m_todoMgr.add( todo ); | 784 | m_todoMgr.add( todo ); |
770 | currentView()->addEvent( todo ); | 785 | currentView()->addEvent( todo ); |
771 | 786 | ||
772 | 787 | ||
773 | // I'm afraid we must call this every time now, otherwise | 788 | // I'm afraid we must call this every time now, otherwise |
774 | // spend expensive time comparing all these strings... | 789 | // spend expensive time comparing all these strings... |
775 | // but only call if we changed something -zecke | 790 | // but only call if we changed something -zecke |
776 | populateCategories(); | 791 | populateCategories(); |
@@ -778,16 +793,19 @@ int MainWindow::create() { | |||
778 | raiseCurrentView( ); | 793 | raiseCurrentView( ); |
779 | 794 | ||
780 | return uid; | 795 | return uid; |
781 | } | 796 | } |
782 | /* delete it silently... */ | 797 | /* delete it silently... */ |
783 | bool MainWindow::remove( int uid ) { | 798 | bool MainWindow::remove( int uid ) { |
784 | if (m_syncing) return false; | 799 | if (m_syncing) return false; |
785 | 800 | ||
801 | /* argh need to get the whole OEvent... to disable alarms -zecke */ | ||
802 | handleAlarms( OTodo(), m_todoMgr.event( uid ) ); | ||
803 | |||
786 | return m_todoMgr.remove( uid ); | 804 | return m_todoMgr.remove( uid ); |
787 | } | 805 | } |
788 | void MainWindow::beam( int uid) { | 806 | void MainWindow::beam( int uid) { |
789 | ::unlink( beamfile ); | 807 | ::unlink( beamfile ); |
790 | OTodo todo = event( uid ); | 808 | OTodo todo = event( uid ); |
791 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); | 809 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); |
792 | OTodoAccess acc( cal ); | 810 | OTodoAccess acc( cal ); |
793 | acc.load(); | 811 | acc.load(); |
@@ -816,8 +834,119 @@ void MainWindow::add( const OPimRecord& rec) { | |||
816 | // I'm afraid we must call this every time now, otherwise | 834 | // I'm afraid we must call this every time now, otherwise |
817 | // spend expensive time comparing all these strings... | 835 | // spend expensive time comparing all these strings... |
818 | // but only call if we changed something -zecke | 836 | // but only call if we changed something -zecke |
819 | populateCategories(); | 837 | populateCategories(); |
820 | } | 838 | } |
821 | void MainWindow::slotReturnFromView() { | 839 | void MainWindow::slotReturnFromView() { |
822 | raiseCurrentView(); | 840 | raiseCurrentView(); |
823 | } | 841 | } |
842 | |||
843 | namespace { | ||
844 | OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, | ||
845 | const OPimNotifyManager::Alarms& newAls ) { | ||
846 | OPimNotifyManager::Alarms nonMatching; | ||
847 | OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); | ||
848 | OPimNotifyManager::Alarms::ConstIterator newIt; | ||
849 | for ( ; oldIt != oldAls.end(); ++oldIt ) { | ||
850 | bool found = false; | ||
851 | QDateTime oldDt = (*oldIt).dateTime(); | ||
852 | for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) { | ||
853 | if ( oldDt == (*newIt).dateTime() ) { | ||
854 | found = true; | ||
855 | break; | ||
856 | } | ||
857 | } | ||
858 | if (!found) | ||
859 | nonMatching.append( (*oldIt) ); | ||
860 | } | ||
861 | return nonMatching; | ||
862 | } | ||
863 | void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) { | ||
864 | OPimNotifyManager::Alarms::ConstIterator it; | ||
865 | for ( it = als.begin(); it != als.end(); ++it ) { | ||
866 | qWarning("Adding alarm for %s", (*it).dateTime().toString().latin1() ); | ||
867 | AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); | ||
868 | } | ||
869 | |||
870 | } | ||
871 | void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) { | ||
872 | OPimNotifyManager::Alarms::ConstIterator it; | ||
873 | for ( it = als.begin(); it != als.end(); ++it ) { | ||
874 | qWarning("Removinf alarm for %s", (*it).dateTime().toString().latin1() ); | ||
875 | AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); | ||
876 | } | ||
877 | } | ||
878 | } | ||
879 | |||
880 | void MainWindow::handleAlarms( const OTodo& oldTodo, const OTodo& newTodo) { | ||
881 | /* | ||
882 | * if oldTodo is not empty and has notifiers we need to find the deleted ones | ||
883 | */ | ||
884 | if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) { | ||
885 | OPimNotifyManager::Alarms removed; | ||
886 | OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms(); | ||
887 | if (!newTodo.hasNotifiers() ) | ||
888 | removed = oldAls; | ||
889 | else | ||
890 | removed = findNonMatching( oldAls, newTodo.notifiers().alarms() ); | ||
891 | |||
892 | removeAlarms( removed, oldTodo.uid() ); | ||
893 | } | ||
894 | if ( newTodo.hasNotifiers() ) { | ||
895 | OPimNotifyManager::Alarms added; | ||
896 | if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() ) | ||
897 | added = newTodo.notifiers().alarms(); | ||
898 | else | ||
899 | added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() ); | ||
900 | |||
901 | addAlarms( added, newTodo.uid() ); | ||
902 | } | ||
903 | } | ||
904 | /* we might have not loaded the db */ | ||
905 | void MainWindow::doAlarm( const QDateTime& dt, int uid ) { | ||
906 | m_todoMgr.load(); | ||
907 | |||
908 | OTodo todo = m_todoMgr.event( uid ); | ||
909 | if (!todo.hasNotifiers() ) return; | ||
910 | |||
911 | /* | ||
912 | * let's find the right alarm and find out if silent | ||
913 | * then show a richtext widget | ||
914 | */ | ||
915 | bool loud = false; | ||
916 | OPimNotifyManager::Alarms als = todo.notifiers().alarms(); | ||
917 | OPimNotifyManager::Alarms::Iterator it; | ||
918 | for ( it = als.begin(); it != als.end(); ++it ) { | ||
919 | if ( (*it).dateTime() == dt ) { | ||
920 | loud = ( (*it).sound() == OPimAlarm::Loud ); | ||
921 | break; | ||
922 | } | ||
923 | } | ||
924 | if (loud) | ||
925 | startAlarm(); | ||
926 | |||
927 | QDialog dlg(this, 0, TRUE ); | ||
928 | QVBoxLayout* lay = new QVBoxLayout( &dlg ); | ||
929 | QTextView* view = new QTextView( &dlg ); | ||
930 | lay->addWidget( view ); | ||
931 | QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); | ||
932 | connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); | ||
933 | lay->addWidget( btnOk ); | ||
934 | |||
935 | QString text = tr("<h1>Alarm at %0</h1><br>").arg( TimeString::dateString( dt ) ); | ||
936 | text += todo.toRichText(); | ||
937 | view->setText( text ); | ||
938 | |||
939 | dlg.showMaximized(); | ||
940 | bool needToStay = dlg.exec(); | ||
941 | |||
942 | if (loud) | ||
943 | killAlarm(); | ||
944 | |||
945 | if (needToStay) { | ||
946 | showMaximized(); | ||
947 | raise(); | ||
948 | QPEApplication::setKeepRunning(); | ||
949 | setActiveWindow(); | ||
950 | } | ||
951 | |||
952 | } | ||