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 @@ -29,12 +29,13 @@ #include <unistd.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qtoolbar.h> #include <qpopupmenu.h> +#include <qpushbutton.h> #include <qwidgetstack.h> #include <qaction.h> #include <qtimer.h> #include <qvbox.h> #include <qlayout.h> #include <qlineedit.h> @@ -42,14 +43,18 @@ #include <qpe/applnk.h> #include <qpe/config.h> #include <qpe/ir.h> #include <qpe/resource.h> #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> #include "quickeditimpl.h" #include "todotemplatemanager.h" #include "templateeditor.h" #include "tableview.h" @@ -298,12 +303,16 @@ OTodoAccess::List MainWindow::list()const { return m_todoMgr.list(); } OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { int cat = 0; if ( m_curCat != QWidget::tr("All Categories") ) cat = currentCatId(); + if ( m_curCat == QWidget::tr("Unfiled") ) + cat = -1; + + qWarning(" Category %d %s", cat, m_curCat.latin1() ); int filter = 1; if (!m_completed ) filter |= 4; if (m_overdue) @@ -313,12 +322,15 @@ OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { } OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { int cat = 0; if ( m_curCat != QWidget::tr("All Categories") ) cat = currentCatId(); + if ( m_curCat == QWidget::tr("Unfiled") ) + cat = -1; + return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); } OTodo MainWindow::event( int uid ) { return m_todoMgr.event( uid ); } bool MainWindow::isSyncing()const { @@ -447,12 +459,13 @@ void MainWindow::slotDelete() { return; } QString strName = currentView()->currentRepresentation(); if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) return; + handleAlarms( OTodo(), m_todoMgr.event( currentView()->current() ) ); m_todoMgr.remove( currentView()->current() ); currentView()->removeEvent( currentView()->current() ); raiseCurrentView(); } void MainWindow::slotDeleteAll() { if(m_syncing) { @@ -638,19 +651,20 @@ void MainWindow::slotEdit( int uid ) { if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), QWidget::tr("Can not edit data, currently syncing")); return; } - 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 ); /* if completed */ if ( currentEditor()->accepted() ) { qWarning("Replacing now" ); + handleAlarms( old_todo, todo ); m_todoMgr.update( todo.uid(), todo ); currentView()->replaceEvent( todo ); /* a Category might have changed */ populateCategories(); } @@ -763,12 +777,13 @@ int MainWindow::create() { OTodo todo = currentEditor()->newTodo( currentCatId(), this ); if ( currentEditor()->accepted() ) { //todo.assignUid(); uid = todo.uid(); + handleAlarms( OTodo(), todo ); m_todoMgr.add( todo ); currentView()->addEvent( todo ); // I'm afraid we must call this every time now, otherwise // spend expensive time comparing all these strings... @@ -780,12 +795,15 @@ int MainWindow::create() { return uid; } /* delete it silently... */ bool MainWindow::remove( int uid ) { if (m_syncing) return false; + /* argh need to get the whole OEvent... to disable alarms -zecke */ + handleAlarms( OTodo(), m_todoMgr.event( uid ) ); + return m_todoMgr.remove( uid ); } void MainWindow::beam( int uid) { ::unlink( beamfile ); OTodo todo = event( uid ); OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); @@ -818,6 +836,117 @@ void MainWindow::add( const OPimRecord& rec) { // but only call if we changed something -zecke populateCategories(); } void MainWindow::slotReturnFromView() { raiseCurrentView(); } + +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(); + } + +} |