Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 136 |
1 files changed, 110 insertions, 26 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 @@ -70,8 +70,9 @@ MainWindow::MainWindow( QWidget* parent, const char* name ) : OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp ) { m_syncing = false; + m_showing = false; m_counter = 0; m_tempManager = new TemplateManager(); m_tempManager->load(); @@ -160,16 +161,19 @@ void MainWindow::initActions() { a->addTo( m_edit ); a->addTo( m_tool ); } +#if 0 // Options menu a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), QString::null, 0, this, 0 ); connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); a->addTo( m_options ); m_findAction = a; + m_options->insertSeparator(); +#endif m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), 0, this, 0, TRUE ); m_completedAction->addTo( m_options ); @@ -351,8 +355,9 @@ void MainWindow::slotReload() { raiseCurrentView(); } void MainWindow::closeEvent( QCloseEvent* e ) { if (m_stack->visibleWidget() == currentShow()->widget() ) { + m_showing = false; raiseCurrentView(); e->ignore(); return; } @@ -408,9 +413,9 @@ 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 */ /* * first we get the name of the template @@ -424,27 +429,29 @@ void MainWindow::slotNewFromTemplate( int id ) { event ); 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() { create(); } 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 ); currentView()->addEvent( ev ); raiseCurrentView(); @@ -454,24 +461,40 @@ void MainWindow::slotDelete() { return; 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; } QString strName = currentView()->currentRepresentation(); if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) 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; } @@ -485,9 +508,9 @@ void MainWindow::slotDeleteAll() { } 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; } if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) @@ -565,22 +588,26 @@ void MainWindow::beamDone( Ir* ir) { ::unlink( beamfile ); } void MainWindow::receiveFile( const QString& filename ) { OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); + OTodoAccess acc( cal ); acc.load(); OTodoAccess::List list = acc.allRecords(); - QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); + if (list.count()){ - if ( QMessageBox::information(this, QWidget::tr("New Tasks"), - message, QMessageBox::Ok, - QMessageBox::Cancel ) == QMessageBox::Ok ) { - OTodoAccess::List::Iterator it; - for ( it = list.begin(); it != list.end(); ++it ) - m_todoMgr.add( (*it) ); + QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); - currentView()->updateView(); + if ( QMessageBox::information(this, QWidget::tr("New Tasks"), + message, QMessageBox::Ok, + QMessageBox::Cancel ) == QMessageBox::Ok ) { + OTodoAccess::List::Iterator it; + for ( it = list.begin(); it != list.end(); ++it ) + m_todoMgr.add( (*it) ); + + currentView()->updateView(); + } } } void MainWindow::slotFlush() { @@ -633,25 +660,43 @@ int MainWindow::currentCatId() { ViewBase* MainWindow::currentView() { return m_curView; } 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() ); } void MainWindow::slotShowDue(bool ov) { m_overdue = ov; currentView()->showOverDue( ov ); raiseCurrentView(); } 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; } OTodo old_todo = m_todoMgr.event( uid ); @@ -659,9 +704,8 @@ void MainWindow::slotEdit( int uid ) { 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 */ @@ -717,8 +761,12 @@ void MainWindow::slotComplete( const OTodo& todo ) { * we need to spin it off * and update the items duedate to the next * 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() ) { OTodo to2( to ); @@ -733,8 +781,10 @@ void MainWindow::slotComplete( const OTodo& todo ) { * from the duedate of the last recurrance */ 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 */ to.setUid( 1 ); @@ -746,11 +796,32 @@ void MainWindow::slotComplete( const OTodo& todo ) { * start date * and complete date */ 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 updateTodo( to ); }else @@ -768,11 +839,12 @@ void MainWindow::reload() { int MainWindow::create() { int uid = 0; 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(); OTodo todo = currentEditor()->newTodo( currentCatId(), this ); @@ -803,9 +875,13 @@ bool MainWindow::remove( int uid ) { return m_todoMgr.remove( 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) ); OTodoAccess acc( cal ); acc.load(); @@ -816,15 +892,21 @@ void MainWindow::beam( int uid) { 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() != OTodo::rtti() ) return; + m_todoMgr.load(); // might not be loaded const OTodo& todo = static_cast<const OTodo&>(rec); m_todoMgr.add(todo ); @@ -836,8 +918,9 @@ void MainWindow::add( const OPimRecord& rec) { // but only call if we changed something -zecke populateCategories(); } void MainWindow::slotReturnFromView() { + m_showing = false; raiseCurrentView(); } namespace { @@ -931,9 +1014,9 @@ void MainWindow::doAlarm( const QDateTime& dt, int uid ) { 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 ) ); + QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); text += todo.toRichText(); view->setText( text ); dlg.showMaximized(); @@ -942,11 +1025,12 @@ void MainWindow::doAlarm( const QDateTime& dt, int uid ) { if (loud) killAlarm(); if (needToStay) { - showMaximized(); - raise(); +// showMaximized(); +// raise(); QPEApplication::setKeepRunning(); - setActiveWindow(); +// setActiveWindow(); } } + |