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 @@ -34,2 +34,3 @@ #include <qpopupmenu.h> +#include <qpushbutton.h> #include <qwidgetstack.h> @@ -47,4 +48,8 @@ #include <qpe/qpemessagebox.h> +#include <qpe/alarmserver.h> +#include <qpe/timestring.h> +#include <qpe/qpeapplication.h> #include <opie/orecur.h> +#include <opie/opimnotifymanager.h> #include <opie/otodoaccessvcal.h> @@ -303,2 +308,6 @@ OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { cat = currentCatId(); + if ( m_curCat == QWidget::tr("Unfiled") ) + cat = -1; + + qWarning(" Category %d %s", cat, m_curCat.latin1() ); @@ -318,2 +327,5 @@ OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { + if ( m_curCat == QWidget::tr("Unfiled") ) + cat = -1; + return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); @@ -452,2 +464,3 @@ void MainWindow::slotDelete() { + handleAlarms( OTodo(), m_todoMgr.event( currentView()->current() ) ); m_todoMgr.remove( currentView()->current() ); @@ -643,5 +656,5 @@ void MainWindow::slotEdit( int uid ) { - OTodo todo = m_todoMgr.event( uid ); + OTodo old_todo = m_todoMgr.event( uid ); - todo = currentEditor()->edit(this, todo ); + OTodo todo = currentEditor()->edit(this, old_todo ); @@ -650,2 +663,3 @@ void MainWindow::slotEdit( int uid ) { qWarning("Replacing now" ); + handleAlarms( old_todo, todo ); m_todoMgr.update( todo.uid(), todo ); @@ -768,2 +782,3 @@ int MainWindow::create() { uid = todo.uid(); + handleAlarms( OTodo(), todo ); m_todoMgr.add( todo ); @@ -785,2 +800,5 @@ bool MainWindow::remove( int uid ) { + /* argh need to get the whole OEvent... to disable alarms -zecke */ + handleAlarms( OTodo(), m_todoMgr.event( uid ) ); + return m_todoMgr.remove( uid ); @@ -823 +841,112 @@ void MainWindow::slotReturnFromView() { } + +namespace { + OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, + const OPimNotifyManager::Alarms& newAls ) { + OPimNotifyManager::Alarms nonMatching; + OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); + OPimNotifyManager::Alarms::ConstIterator newIt; + for ( ; oldIt != oldAls.end(); ++oldIt ) { + bool found = false; + QDateTime oldDt = (*oldIt).dateTime(); + for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) { + if ( oldDt == (*newIt).dateTime() ) { + found = true; + break; + } + } + if (!found) + nonMatching.append( (*oldIt) ); + } + return nonMatching; + } + void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) { + OPimNotifyManager::Alarms::ConstIterator it; + for ( it = als.begin(); it != als.end(); ++it ) { + qWarning("Adding alarm for %s", (*it).dateTime().toString().latin1() ); + AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); + } + + } + void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) { + OPimNotifyManager::Alarms::ConstIterator it; + for ( it = als.begin(); it != als.end(); ++it ) { + qWarning("Removinf alarm for %s", (*it).dateTime().toString().latin1() ); + AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); + } + } +} + +void MainWindow::handleAlarms( const OTodo& oldTodo, const OTodo& newTodo) { + /* + * if oldTodo is not empty and has notifiers we need to find the deleted ones + */ + if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) { + OPimNotifyManager::Alarms removed; + OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms(); + if (!newTodo.hasNotifiers() ) + removed = oldAls; + else + removed = findNonMatching( oldAls, newTodo.notifiers().alarms() ); + + removeAlarms( removed, oldTodo.uid() ); + } + if ( newTodo.hasNotifiers() ) { + OPimNotifyManager::Alarms added; + if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() ) + added = newTodo.notifiers().alarms(); + else + added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() ); + + addAlarms( added, newTodo.uid() ); + } +} +/* we might have not loaded the db */ +void MainWindow::doAlarm( const QDateTime& dt, int uid ) { + m_todoMgr.load(); + + OTodo todo = m_todoMgr.event( uid ); + if (!todo.hasNotifiers() ) return; + + /* + * let's find the right alarm and find out if silent + * then show a richtext widget + */ + bool loud = false; + OPimNotifyManager::Alarms als = todo.notifiers().alarms(); + OPimNotifyManager::Alarms::Iterator it; + for ( it = als.begin(); it != als.end(); ++it ) { + if ( (*it).dateTime() == dt ) { + loud = ( (*it).sound() == OPimAlarm::Loud ); + break; + } + } + if (loud) + startAlarm(); + + QDialog dlg(this, 0, TRUE ); + QVBoxLayout* lay = new QVBoxLayout( &dlg ); + QTextView* view = new QTextView( &dlg ); + lay->addWidget( view ); + QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); + connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); + lay->addWidget( btnOk ); + + QString text = tr("<h1>Alarm at %0</h1><br>").arg( TimeString::dateString( dt ) ); + text += todo.toRichText(); + view->setText( text ); + + dlg.showMaximized(); + bool needToStay = dlg.exec(); + + if (loud) + killAlarm(); + + if (needToStay) { + showMaximized(); + raise(); + QPEApplication::setKeepRunning(); + setActiveWindow(); + } + +} |