-rw-r--r-- | core/pim/todo/mainwindow.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index 924fde1..2002e87 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp @@ -817,193 +817,194 @@ void MainWindow::slotComplete( const OPimTodo& todo ) { /* for every alarm move the day */ for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) { OPimAlarm al = (*it); al.setDateTime( al.dateTime().addDays( dayDiff ) ); als.append( al ); } to2.notifiers().setAlarms( als ); handleAlarms( OPimTodo(), todo ); } to2.setCompletedDate( inval ); to2.setCompleted( false ); updateTodo( to2 ); }else updateTodo( to ); }else updateTodo( to ); currentView()->updateView(); raiseCurrentView(); } void MainWindow::flush() { slotFlush(); } void MainWindow::reload() { slotReload(); } int MainWindow::create() { int uid = 0; if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), QWidget::tr("Data can not be edited, currently syncing")); return uid; } m_todoMgr.load(); OPimTodo todo = currentEditor()->newTodo( currentCatId(), this ); if ( currentEditor()->accepted() ) { //todo.assignUid(); uid = todo.uid(); handleAlarms( OPimTodo(), 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... // but only call if we changed something -zecke populateCategories(); } raiseCurrentView( ); 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( OPimTodo(), m_todoMgr.event( uid ) ); return m_todoMgr.remove( uid ); } void MainWindow::beam( int uid) { if( uid == 0 ) return; ::unlink( beamfile ); m_todoMgr.load(); OPimTodo todo = event( uid ); OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(QString::fromLatin1(beamfile) ); OPimTodoAccess acc( cal ); acc.load(); acc.add( todo ); acc.save(); Ir* ir = new Ir(this ); connect(ir, SIGNAL(done(Ir*) ), this, SLOT(beamDone(Ir*) ) ); ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); } void MainWindow::show( int uid ) { m_todoMgr.load(); // might not be loaded yet m_showing = true; slotShow( uid ); raise(); QPEApplication::setKeepRunning(); } void MainWindow::edit( int uid ) { m_todoMgr.load(); slotEdit( uid ); } void MainWindow::add( const OPimRecord& rec) { - if ( rec.rtti() != OPimTodo::rtti() ) return; + OPimTodo test; + if ( rec.rtti() != test.rtti() ) return; m_todoMgr.load(); // might not be loaded const OPimTodo& todo = static_cast<const OPimTodo&>(rec); 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... // but only call if we changed something -zecke populateCategories(); } void MainWindow::slotReturnFromView() { m_showing = false; 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 ) { owarn << "Adding alarm for " << (*it).dateTime().toString() << oendl; 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 ) { owarn << "Removinf alarm for " << (*it).dateTime().toString() << oendl; AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); } } } void MainWindow::handleAlarms( const OPimTodo& oldTodo, const OPimTodo& 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(); OPimTodo 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 ); |