summaryrefslogtreecommitdiff
path: root/core/pim/todo/mainwindow.cpp
authorzecke <zecke>2003-05-12 13:21:59 (UTC)
committer zecke <zecke>2003-05-12 13:21:59 (UTC)
commit9a4c9544a59f8395f2ec5e7c99028570f8bd8bd1 (patch) (unidiff)
tree8af13b984750f743b7f9f06bbf04b531b1a10ff2 /core/pim/todo/mainwindow.cpp
parenta4c8b8912c9e87a2fd76103193e6b4f91c2a2c5d (diff)
downloadopie-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.cpp133
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
@@ -33,4 +33,5 @@
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>
@@ -46,6 +47,10 @@
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
@@ -302,4 +307,8 @@ OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) {
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;
@@ -317,4 +326,7 @@ OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) {
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}
@@ -451,4 +463,5 @@ void MainWindow::slotDelete() {
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() );
@@ -642,11 +655,12 @@ void MainWindow::slotEdit( int uid ) {
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 );
@@ -767,4 +781,5 @@ int MainWindow::create() {
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 );
@@ -784,4 +799,7 @@ 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}
@@ -822,2 +840,113 @@ void MainWindow::slotReturnFromView() {
822 raiseCurrentView(); 840 raiseCurrentView();
823} 841}
842
843namespace {
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
880void 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 */
905void 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}