-rw-r--r-- | core/pim/todo/mainwindow.cpp | 120 |
1 files changed, 102 insertions, 18 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index 5119ae0..6725951 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp @@ -72,4 +72,5 @@ MainWindow::MainWindow( QWidget* parent, { m_syncing = false; + m_showing = false; m_counter = 0; m_tempManager = new TemplateManager(); @@ -162,4 +163,5 @@ void MainWindow::initActions() { } +#if 0 // Options menu a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), @@ -169,5 +171,7 @@ void MainWindow::initActions() { m_findAction = a; + m_options->insertSeparator(); +#endif m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), @@ -353,4 +357,5 @@ void MainWindow::slotReload() { void MainWindow::closeEvent( QCloseEvent* e ) { if (m_stack->visibleWidget() == currentShow()->widget() ) { + m_showing = false; raiseCurrentView(); e->ignore(); @@ -410,5 +415,5 @@ void MainWindow::populateTemplates() { * slotNewFromTemplate * We use the edit widget to do - * the config but we setUid(-1) + * the config but we setUid(1) * to get a new uid */ @@ -426,10 +431,12 @@ void MainWindow::slotNewFromTemplate( int id ) { if ( currentEditor()->accepted() ) { /* assign new todo */ - event.setUid( -1 ); - currentView()->addEvent( event ); + event.setUid( 1 ); + handleAlarms( OTodo(), event ); m_todoMgr.add( event ); + currentView()->addEvent( event ); populateCategories(); } + raiseCurrentView(); } void MainWindow::slotNew() { @@ -439,10 +446,10 @@ void MainWindow::slotDuplicate() { if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), - QWidget::tr("Can not edit data, currently syncing")); + QWidget::tr("Data can not be edited, currently syncing")); return; } OTodo ev = m_todoMgr.event( currentView()->current() ); /* let's generate a new uid */ - ev.setUid(-1); + ev.setUid(1); m_todoMgr.add( ev ); @@ -456,5 +463,5 @@ void MainWindow::slotDelete() { if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), - QWidget::tr("Can not edit data, currently syncing")); + QWidget::tr("Data can not be edited, currently syncing")); return; } @@ -463,13 +470,29 @@ void MainWindow::slotDelete() { return; - handleAlarms( OTodo(), m_todoMgr.event( currentView()->current() ) ); + handleAlarms( m_todoMgr.event( currentView()->current() ), OTodo() ); m_todoMgr.remove( currentView()->current() ); currentView()->removeEvent( currentView()->current() ); raiseCurrentView(); } +void MainWindow::slotDelete(int uid ) { + if( uid == 0 ) return; + if(m_syncing) { + QMessageBox::warning(this, QWidget::tr("Todo"), + QWidget::tr("Data can not be edited, currently syncing")); + return; + } + OTodo to = m_todoMgr.event(uid); + if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) ) + return; + + handleAlarms(to, OTodo() ); + m_todoMgr.remove( to.uid() ); + currentView()->removeEvent( to.uid() ); + raiseCurrentView(); +} void MainWindow::slotDeleteAll() { if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), - QWidget::tr("Can not edit data, currently syncing")); + QWidget::tr("Data can not be edited, currently syncing")); return; } @@ -487,5 +510,5 @@ void MainWindow::slotDeleteCompleted() { if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), - QWidget::tr("Can not edit data, currently syncing")); + QWidget::tr("Data can not be edited, currently syncing")); return; } @@ -567,8 +590,11 @@ void MainWindow::beamDone( Ir* ir) { void MainWindow::receiveFile( const QString& filename ) { OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); + OTodoAccess acc( cal ); acc.load(); OTodoAccess::List list = acc.allRecords(); + if (list.count()){ + QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); @@ -583,4 +609,5 @@ void MainWindow::receiveFile( const QString& filename ) { } } +} void MainWindow::slotFlush() { @@ -635,4 +662,11 @@ ViewBase* MainWindow::currentView() { } void MainWindow::raiseCurrentView() { + // due QPE/Application/todolist show(int) + // we might not have the populateCategories slot called once + // we would show the otodo but then imediately switch to the currentView + // if we're initially showing we shouldn't raise the table + // in returnFromView we fix up m_showing + if (m_showing ) return; + m_stack->raiseWidget( m_curView->widget() ); } @@ -643,13 +677,24 @@ void MainWindow::slotShowDue(bool ov) { } void MainWindow::slotShow( int uid ) { + if ( uid == 0 ) return; qWarning("slotShow"); currentShow()->slotShow( event( uid ) ); m_stack->raiseWidget( currentShow()->widget() ); } +void MainWindow::slotShowNext() { + int l = currentView()->next(); + if (l!=0) + slotShow(l); +} +void MainWindow::slotShowPrev() { + int l = currentView()->prev(); + if (l!=0) + slotShow(l); +} void MainWindow::slotEdit( int uid ) { - if (uid == 1 ) return; + if (uid == 0 ) return; if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), - QWidget::tr("Can not edit data, currently syncing")); + QWidget::tr("Data can't be edited, currently syncing")); return; } @@ -661,5 +706,4 @@ void MainWindow::slotEdit( int uid ) { /* if completed */ if ( currentEditor()->accepted() ) { - qWarning("Replacing now" ); handleAlarms( old_todo, todo ); m_todoMgr.update( todo.uid(), todo ); @@ -719,4 +763,8 @@ void MainWindow::slotComplete( const OTodo& todo ) { * possible recurrance of this item... * the spinned off one will loose the + * recurrence. + * We calculate the difference between the old due date and the + * new one and add this diff to start, completed and alarm dates + * -zecke */ if ( to.hasRecurrence() && to.isCompleted() ) { @@ -735,4 +783,6 @@ void MainWindow::slotComplete( const OTodo& todo ) { QDate date; if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { + int dayDiff = to.dueDate().daysTo( date ); + qWarning("day diff is %d", dayDiff ); QDate inval; /* generate a new uid for the old record */ @@ -748,7 +798,28 @@ void MainWindow::slotComplete( const OTodo& todo ) { */ to2.setDueDate( date ); - to2.setStartDate( inval ); + rec.setStart( date ); + to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week + + /* move start date */ + if (to2.hasStartDate() ) + to2.setStartDate( to2.startDate().addDays( dayDiff ) ); + + /* now the alarms */ + if (to2.hasNotifiers() ) { + OPimNotifyManager::Alarms _als = to2.notifiers().alarms(); + OPimNotifyManager::Alarms als; + + /* 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( OTodo(), todo ); + } to2.setCompletedDate( inval ); to2.setCompleted( false ); + updateTodo( to2 ); }else @@ -770,7 +841,8 @@ int MainWindow::create() { if(m_syncing) { QMessageBox::warning(this, QWidget::tr("Todo"), - QWidget::tr("Can not edit data, currently syncing")); + QWidget::tr("Data can not be edited, currently syncing")); return uid; } + m_todoMgr.load(); @@ -805,5 +877,9 @@ bool MainWindow::remove( int uid ) { } void MainWindow::beam( int uid) { + if( uid == 0 ) return; + ::unlink( beamfile ); + m_todoMgr.load(); + OTodo todo = event( uid ); OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); @@ -818,11 +894,17 @@ void MainWindow::beam( int uid) { } 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() != OTodo::rtti() ) return; + m_todoMgr.load(); // might not be loaded const OTodo& todo = static_cast<const OTodo&>(rec); @@ -838,4 +920,5 @@ void MainWindow::add( const OPimRecord& rec) { } void MainWindow::slotReturnFromView() { + m_showing = false; raiseCurrentView(); } @@ -933,5 +1016,5 @@ void MainWindow::doAlarm( const QDateTime& dt, int uid ) { lay->addWidget( btnOk ); - QString text = tr("<h1>Alarm at %0</h1><br>").arg( TimeString::dateString( dt ) ); + QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); text += todo.toRichText(); view->setText( text ); @@ -944,9 +1027,10 @@ void MainWindow::doAlarm( const QDateTime& dt, int uid ) { if (needToStay) { - showMaximized(); - raise(); +// showMaximized(); +// raise(); QPEApplication::setKeepRunning(); - setActiveWindow(); +// setActiveWindow(); } } + |