Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 213 |
1 files changed, 156 insertions, 57 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index 9b2423b..b2b3b8f 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp @@ -43,8 +43,9 @@ #include <qpe/ir.h> #include <qpe/resource.h> #include <qpe/qpemessagebox.h> +#include <opie/orecur.h> #include <opie/otodoaccessvcal.h> #include "quickeditimpl.h" #include "todotemplatemanager.h" @@ -58,9 +59,11 @@ using namespace Todo; MainWindow::MainWindow( QWidget* parent, - const char* name ) { + const char* name ) + : OPimMainWindow("Todolist") +{ m_syncing = false; m_counter = 0; m_tempManager = new TemplateManager(); @@ -176,15 +179,12 @@ void MainWindow::initActions() { /* initialize the view menu */ a = new QAction( QString::null, tr("Show only over due"), 0, this, 0, TRUE ); - a->addTo( m_view ); + a->addTo( m_options ); a->setOn( showOverDue() ); connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) ); - m_view->insertSeparator(); - - m_bar->insertItem( tr("View"), m_view ); /* templates */ m_edit->insertItem(tr("New from template"), m_template, -1, 0 ); @@ -219,9 +219,8 @@ void MainWindow::initUI() { /** QPopupMenu */ m_edit = new QPopupMenu( this ); m_options = new QPopupMenu( this ); - m_view = new QPopupMenu( this ); m_catMenu = new QPopupMenu( this ); m_template = new QPopupMenu( this ); m_catMenu->setCheckable( TRUE ); @@ -253,26 +252,28 @@ void MainWindow::initShow() { MainWindow::~MainWindow() { delete templateManager(); } void MainWindow::connectBase( ViewBase* base) { - base->connectShow( this, SLOT(slotShow(int) ) ); - base->connectEdit( this, SLOT(slotEdit(int) ) ); - base->connectUpdateSmall( this, - SLOT(slotUpate1(int, const Todo::SmallTodo&) )); - base->connectUpdateBig( this, - SLOT(slotUpate2(int, const OTodo& ) ) ); - base->connectUpdateView( this, SLOT(slotUpdate3( QWidget* ) ) ) ; - base->connectRemove(&m_todoMgr, - SLOT(remove(int)) ); -} -QPopupMenu* MainWindow::contextMenu( int uid ) { + // once templates and signals mix we'll use it again +} +QPopupMenu* MainWindow::contextMenu( int , bool recur ) { QPopupMenu* menu = new QPopupMenu(); m_editAction->addTo( menu ); m_deleteAction->addTo( menu ); m_duplicateAction->addTo( menu ); + menu->insertSeparator(); + /* + * if this event recurs we allow + * to detach it. + * remove all + */ + if ( recur ) { + ; // FIXME + } + return menu; } QPopupMenu* MainWindow::options() { qWarning("Options"); @@ -280,11 +281,8 @@ QPopupMenu* MainWindow::options() { } QPopupMenu* MainWindow::edit() { return m_edit; } -QPopupMenu* MainWindow::view() { - return m_view; -} QToolBar* MainWindow::toolbar() { return m_tool; } OTodoAccess::List MainWindow::list()const { @@ -412,30 +410,9 @@ void MainWindow::slotNewFromTemplate( int id ) { populateCategories(); } } void MainWindow::slotNew() { - if(m_syncing) { - QMessageBox::warning(this, tr("Todo"), - tr("Can not edit data, currently syncing")); - return; - } - - - OTodo todo = currentEditor()->newTodo( currentCatId(), - this ); - - if ( currentEditor()->accepted() ) { - //todo.assignUid(); - 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( ); + create(); } void MainWindow::slotDuplicate() { if(m_syncing) { QMessageBox::warning(this, tr("Todo"), @@ -473,9 +450,8 @@ void MainWindow::slotDeleteAll() { tr("Can not edit data, currently syncing")); return; } - //QString strName = table->text( table->currentRow(), 2 ).left( 30 ); if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) ) return; @@ -493,10 +469,10 @@ void MainWindow::slotDeleteCompleted() { if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) ) return; - // FIXME - //m_todoMgr.remove( currentView()->completed() ); + + m_todoMgr.removeCompleted(); currentView()->updateView( ); } void MainWindow::slotFind() { @@ -551,20 +527,9 @@ void MainWindow::setDocument( const QString& fi) { } static const char *beamfile = "/tmp/opie-todo.vcs"; void MainWindow::slotBeam() { - ::unlink( beamfile ); - OTodo todo = event( currentView()->current() ); - OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); - OTodoAccess 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" ); - + beam( currentView()->current() ); } void MainWindow::beamDone( Ir* ir) { delete ir; ::unlink( beamfile ); @@ -703,4 +668,138 @@ void MainWindow::slotQuickEntered() { } QuickEditBase* MainWindow::quickEditor() { return m_curQuick; } +void MainWindow::slotComplete( int uid ) { + slotComplete( event(uid) ); +} +void MainWindow::slotComplete( const OTodo& todo ) { + OTodo to = todo; + to.setCompleted( !to.isCompleted() ); + to.setCompletedDate( QDate::currentDate() ); + + /* + * if the item does recur + * 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 + */ + if ( to.recurrence().doesRecur() && to.isCompleted() ) { + OTodo to2( to ); + + /* the spinned off one won't recur anymore */ + to.setRecurrence( ORecur() ); + + ORecur rec = to2.recurrence(); + rec.setStart( to.dueDate() ); + to2.setRecurrence( rec ); + /* + * if there is a next occurence + * from the duedate of the last recurrance + */ + QDate date; + if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { + QDate inval; + /* generate a new uid for the old record */ + to.setUid( 1 ); + + /* add the old one cause it has a new UID here cause it was spin off */ + m_todoMgr.add( to ); + + /* + * update the due date + * start date + * and complete date + */ + to2.setDueDate( date ); + to2.setStartDate( inval ); + 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, tr("Todo"), + tr("Can not edit data, currently syncing")); + return uid; + } + + + OTodo todo = currentEditor()->newTodo( currentCatId(), + this ); + + if ( currentEditor()->accepted() ) { + //todo.assignUid(); + uid = todo.uid(); + 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; + + return m_todoMgr.remove( uid ); +} +void MainWindow::beam( int uid, int ) { + ::unlink( beamfile ); + OTodo todo = event( uid ); + OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); + OTodoAccess 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 ) { + slotShow( uid ); +} +void MainWindow::edit( int uid ) { + slotEdit( uid ); +} +void MainWindow::add( const OPimRecord& rec) { + if ( rec.rtti() != OTodo::rtti() ) return; + + const OTodo& todo = static_cast<const OTodo&>(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(); +} +/* todo does not have the QDataStream<< and >> operators implemented :( + * FIXME + */ +OPimRecord* MainWindow::record( int rtti, const QByteArray& ) { + return 0l; +} |