-rw-r--r-- | core/pim/todo/mainwindow.cpp | 106 | ||||
-rw-r--r-- | core/pim/todo/mainwindow.h | 14 | ||||
-rw-r--r-- | core/pim/todo/todotable.cpp | 148 | ||||
-rw-r--r-- | core/pim/todo/todotable.h | 7 |
4 files changed, 238 insertions, 37 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index b5cace9..883d78c 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp @@ -79,346 +79,414 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : table->setPaintingEnabled( FALSE ); table->setUpdatesEnabled( FALSE ); table->viewport()->setUpdatesEnabled( FALSE ); { str = todolistXMLFilename(); if ( str.isNull() ) QMessageBox::critical( this, tr("Out of Space"), tr("Unable to create startup files\n" "Free up some space\n" "before you enter any data") ); else table->load( str ); } // repeat for categories... str = categoriesXMLFilename(); if ( str.isNull() ) QMessageBox::critical( this, tr( "Out of Space" ), tr( "Unable to create startup files\n" "Free up some space\n" "before you enter any data") ); setCentralWidget( table ); setToolBarsMovable( FALSE ); // qDebug("after load: t=%d", t.elapsed() ); Config config( "todo" ); config.setGroup( "View" ); bool complete = config.readBoolEntry( "ShowComplete", true ); table->setShowCompleted( complete ); bool showdeadline = config.readBoolEntry("ShowDeadLine", true); table->setShowDeadline (showdeadline); QString category = config.readEntry( "Category", QString::null ); table->setShowCategory( category ); QPEToolBar *bar = new QPEToolBar( this ); bar->setHorizontalStretchable( TRUE ); QPEMenuBar *mb = new QPEMenuBar( bar ); catMenu = new QPopupMenu( this ); QPopupMenu *edit = new QPopupMenu( this ); + QPopupMenu *options = new QPopupMenu(this ); + contextMenu = new QPopupMenu( this ); bar = new QPEToolBar( this ); QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); a->addTo( bar ); a->addTo( edit ); - a = new QAction( tr( "Edit" ), Resource::loadIconSet( "edit" ), + a = new QAction( tr( "Edit Task" ), Resource::loadIconSet( "edit" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); a->addTo( bar ); a->addTo( edit ); a->addTo( contextMenu ); a->setEnabled( FALSE ); editAction = a; + edit->insertSeparator(); - a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ), + a = new QAction( tr( "Delete..." ), Resource::loadIconSet( "trash" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); a->addTo( bar ); a->addTo( edit ); a->addTo( contextMenu ); a->setEnabled( FALSE ); deleteAction = a; + // delete All in category is missing.... + // set All Done + // set All Done in category + + a = new QAction( QString::null, tr( "Delete all..."), 0, this, 0 ); + connect(a, SIGNAL( activated() ), + this, SLOT( slotDeleteAll() ) ); + a->addTo(edit ); + a->setEnabled( FALSE ); + deleteAllAction = a; + + edit->insertSeparator(); + a = new QAction( QString::null, tr("Duplicate" ), 0, this, 0 ); + connect(a, SIGNAL( activated() ), + this, SLOT( slotDuplicate() ) ); + a->addTo(edit ); + a->setEnabled( FALSE ); + duplicateAction = a; + + edit->insertSeparator(); if ( Ir::supported() ) { a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); a->addTo( edit ); a->addTo( bar ); } a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); a->addTo( bar ); - a->addTo( edit ); + a->addTo( options ); + options->insertSeparator(); + if ( table->numRows() ) a->setEnabled( TRUE ); else a->setEnabled( FALSE ); //a->setEnabled( FALSE ); findAction = a; // qDebug("mainwindow #2: t=%d", t.elapsed() ); completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE ); showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE ); catMenu->setCheckable( true ); populateCategories(); - mb->insertItem( tr( "Data" ), edit ); - mb->insertItem( tr( "View" ), catMenu ); + + completedAction->addTo( options ); + completedAction->setOn( table->showCompleted() ); + showdeadlineAction->addTo( options ); + showdeadlineAction->setOn( table->showDeadline() ); + options->insertSeparator( ); + QList<QWidget> list; + list.append(table ); + OFontMenu *menu = new OFontMenu(this, "menu",list ); + menu->forceSize( table->horizontalHeader(), 10 ); + //catMenu->insertItem(tr("Fonts"), menu ); + list.clear(); + options->insertItem( tr("Fonts"), menu ); + + mb->insertItem( tr( "Data" ), edit ); + mb->insertItem( tr( "Category" ), catMenu ); + mb->insertItem( tr( "Options"), options ); resize( 200, 300 ); if ( table->numRows() > 0 ) currentEntryChanged( 0, 0 ); connect( table, SIGNAL( signalEdit() ), this, SLOT( slotEdit() ) ); connect( table, SIGNAL(signalShowMenu(const QPoint &)), this, SLOT( slotShowPopup(const QPoint &)) ); // qDebug("mainwindow #3: t=%d", t.elapsed() ); table->updateVisible(); table->setUpdatesEnabled( TRUE ); table->setPaintingEnabled( TRUE ); table->viewport()->setUpdatesEnabled( TRUE ); connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); connect( showdeadlineAction, SIGNAL( toggled(bool) ), this, SLOT( showDeadline(bool) ) ); connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); connect( table, SIGNAL( currentChanged( int, int ) ), this, SLOT( currentEntryChanged( int, int ) ) ); // qDebug("done: t=%d", t.elapsed() ); } void TodoWindow::slotNew() { if(syncing) { QMessageBox::warning(this, tr("Todo"), tr("Can not edit data, currently syncing")); return; } int id; id = -1; QArray<int> ids; ids = table->currentEntry().categories(); if ( ids.count() ) id = ids[0]; NewTaskDialog e( id, this, 0, TRUE ); ToDoEvent todo; #if defined(Q_WS_QWS) || defined(_WS_QWS_) e.showMaximized(); #endif int ret = e.exec(); qWarning("finished" ); if ( ret == QDialog::Accepted ) { table->setPaintingEnabled( false ); todo = e.todoEntry(); //todo.assignUid(); table->addEntry( todo ); table->setPaintingEnabled( true ); findAction->setEnabled( TRUE ); } // I'm afraid we must call this every time now, otherwise // spend expensive time comparing all these strings... populateCategories(); } TodoWindow::~TodoWindow() { } void TodoWindow::slotDelete() { if(syncing) { QMessageBox::warning(this, tr("Todo"), tr("Can not edit data, currently syncing")); return; } if ( table->currentRow() == -1 ) return; QString strName = table->text( table->currentRow(), 2 ).left( 30 ); if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) return; table->setPaintingEnabled( false ); table->removeCurrentEntry(); table->setPaintingEnabled( true ); if ( table->numRows() == 0 ) { currentEntryChanged( -1, 0 ); findAction->setEnabled( FALSE ); } } +void TodoWindow::slotDeleteAll() +{ + if(syncing) { + QMessageBox::warning(this, tr("Todo"), + tr("Can not edit data, currently syncing")); + return; + } + + //QString strName = table->text( table->currentRow(), 2 ).left( 30 ); + + if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("Should I delete all tasks?") ) ) + return; + + + + table->setPaintingEnabled( false ); + table->removeAllEntries(); + table->setPaintingEnabled( true ); + + if ( table->numRows() == 0 ) { + currentEntryChanged( -1, 0 ); + findAction->setEnabled( FALSE ); + } +} void TodoWindow::slotEdit() { if(syncing) { QMessageBox::warning(this, tr("Todo"), tr("Can not edit data, currently syncing")); return; } ToDoEvent todo = table->currentEntry(); NewTaskDialog e( todo, this, 0, TRUE ); e.setCaption( tr( "Edit Task" ) ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) e.showMaximized(); #endif int ret = e.exec(); if ( ret == QDialog::Accepted ) { table->setPaintingEnabled( false ); todo = e.todoEntry(); table->replaceCurrentEntry( todo ); table->setPaintingEnabled( true ); } populateCategories(); } - +void TodoWindow::slotDuplicate() +{ + if(syncing) { + QMessageBox::warning(this, tr("Todo"), + tr("Can not edit data, currently syncing")); + return; + } + ToDoEvent ev = table->currentEntry(); + ToDoEvent ev2 = ToDoEvent( ev ); + table->setPaintingEnabled( false ); + table->addEntry( ev2 ); + table->setPaintingEnabled( true ); +} void TodoWindow::slotShowPopup( const QPoint &p ) { contextMenu->popup( p ); } void TodoWindow::showCompleted( bool s ) { if ( !table->isUpdatesEnabled() ) return; table->setPaintingEnabled( false ); table->setShowCompleted( s ); table->setPaintingEnabled( true ); } void TodoWindow::currentEntryChanged( int r, int ) { if ( r != -1 && table->rowHeight( r ) > 0 ) { editAction->setEnabled( TRUE ); deleteAction->setEnabled( TRUE ); + duplicateAction->setEnabled( TRUE ); + deleteAllAction->setEnabled( TRUE ); } else { editAction->setEnabled( FALSE ); deleteAction->setEnabled( FALSE ); + duplicateAction->setEnabled( FALSE ); + deleteAllAction->setEnabled( FALSE ); } } void TodoWindow::setCategory( int c ) { if ( c <= 0 ) return; if ( !table->isUpdatesEnabled() ) return; table->setPaintingEnabled( false ); for ( unsigned int i = 1; i < catMenu->count(); i++ ) catMenu->setItemChecked( i, c == (int)i ); if ( c == 1 ) { table->setShowCategory( QString::null ); setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); } else if ( c == (int)catMenu->count() - 1 ) { table->setShowCategory( tr( "Unfiled" ) ); setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); } else { QString cat = table->categories()[c - 2]; table->setShowCategory( cat ); setCaption( tr("Todo") + " - " + cat ); } table->setPaintingEnabled( true ); } void TodoWindow::populateCategories() { catMenu->clear(); - - QList<QWidget> list; - list.append(table ); - OFontMenu *menu = new OFontMenu(this, "menu",list ); - menu->forceSize( table->horizontalHeader(), 10 ); - catMenu->insertItem(tr("Fonts"), menu ); - - completedAction->addTo( catMenu ); - completedAction->setOn( table->showCompleted() ); - showdeadlineAction->addTo( catMenu ); - showdeadlineAction->setOn( table->showDeadline() ); - catMenu->insertSeparator(); int id, rememberId; id = 1; catMenu->insertItem( tr( "All Categories" ), id++ ); -// catMenu->insertSeparator(); + catMenu->insertSeparator(); QStringList categories = table->categories(); categories.append( tr( "Unfiled" ) ); for ( QStringList::Iterator it = categories.begin(); it != categories.end(); ++it ) { catMenu->insertItem( *it, id ); if ( *it == table->showCategory() ) rememberId = id; ++id; } if ( table->showCategory().isEmpty() ) setCategory( 1 ); else setCategory( rememberId ); } void TodoWindow::reload() { table->clear(); table->load( todolistXMLFilename() ); syncing = FALSE; } void TodoWindow::flush() { syncing = TRUE; table->save( todolistXMLFilename() ); } void TodoWindow::closeEvent( QCloseEvent *e ) { if(syncing) { /* no need to save if in the middle of syncing */ e->accept(); return; } if ( table->save( todolistXMLFilename() ) ) { e->accept(); // repeat for categories... // if writing configs fail, it will emit an // error, but I feel that it is "ok" for us to exit // espically since we aren't told if the write succeeded... Config config( "todo" ); config.setGroup( "View" ); config.writeEntry( "ShowComplete", table->showCompleted() ); config.writeEntry( "Category", table->showCategory() ); /* added 20.01.2k2 by se */ config.writeEntry( "ShowDeadLine", table->showDeadline()); diff --git a/core/pim/todo/mainwindow.h b/core/pim/todo/mainwindow.h index 9be7c66..b9172e1 100644 --- a/core/pim/todo/mainwindow.h +++ b/core/pim/todo/mainwindow.h @@ -13,70 +13,74 @@ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> class TodoTable; class QAction; class QPopupMenu; class Ir; class OFontMenu; class TodoWindow : public QMainWindow { Q_OBJECT public: TodoWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~TodoWindow(); public slots: void flush(); void reload(); protected slots: void slotNew(); void slotDelete(); void slotEdit(); void slotShowPopup( const QPoint & ); void showCompleted( bool ); /* added 20.01.2k2 by se */ void showDeadline( bool ); void currentEntryChanged( int r, int c ); void setCategory( int ); void slotFind(); void setDocument( const QString & ); void slotBeam(); void beamDone( Ir * ); - + void slotDeleteAll(); + void slotDuplicate(); + protected: void closeEvent( QCloseEvent *e ); private: void populateCategories(); private: TodoTable *table; QAction *editAction, - *deleteAction, - *findAction, - * completedAction, - *showdeadlineAction ; + *deleteAction, + *findAction, + *completedAction, + *showdeadlineAction, + *deleteAllAction, + *duplicateAction; QPopupMenu *contextMenu, *catMenu; bool syncing; }; #endif diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index 2acd03c..401d2c8 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp @@ -1,97 +1,101 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ /* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de) */ #include "todotable.h" #include <opie/tododb.h> +#include <opie/xmltree.h> + #include <qpe/categoryselect.h> #include <qpe/xmlreader.h> #include <qasciidict.h> #include <qcombobox.h> #include <qfile.h> #include <qpainter.h> #include <qtextcodec.h> #include <qtimer.h> #include <qdatetime.h> +#include <qtextstream.h> #include <qcursor.h> #include <qregexp.h> #include <errno.h> #include <stdlib.h> #include <stdio.h> +#include <iostream> +namespace { - -static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); - -static QString journalFileName(); - + static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); + static QString journalFileName(); + static ToDoEvent xmlToEvent( XMLElement *ev ); +} CheckItem::CheckItem( QTable *t, const QString &key ) : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key ) { } QString CheckItem::key() const { return sortKey; } void CheckItem::setChecked( bool b ) { checked = b; table()->updateCell( row(), col() ); } void CheckItem::toggle() { TodoTable *parent = static_cast<TodoTable*>(table()); ToDoEvent newTodo = parent->currentEntry(); checked = !checked; newTodo.setCompleted( checked ); table()->updateCell( row(), col() ); parent->replaceCurrentEntry( newTodo, true ); } bool CheckItem::isChecked() const { return checked; } static const int BoxSize = 10; void CheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool ) { p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); int marg = ( cr.width() - BoxSize ) / 2; int x = 0; int y = ( cr.height() - BoxSize ) / 2; p->setPen( QPen( cg.text() ) ); p->drawRect( x + marg, y, BoxSize, BoxSize ); p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); p->setPen( darkGreen ); x += 1; y += 1; if ( checked ) { @@ -364,231 +368,248 @@ void TodoTable::removeCurrentEntry() chk = static_cast<CheckItem*>(item(row, 0 )); if ( !chk ) return; oldTodo = todoList[chk]; todoList.remove( chk ); oldTodo->setCompleted( chk->isChecked() ); oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() ); realignTable( row ); updateVisible(); updateJournal( *oldTodo, ACTION_REMOVE, row ); delete oldTodo; } bool TodoTable::save( const QString &fn ) { QString strNewFile = fn + ".new"; QFile::remove( strNewFile ); // just to be sure ToDoDB todoDB( strNewFile ); for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); it != todoList.end(); ++it ) { if ( !item( it.key()->row(), 0 ) ) continue; ToDoEvent *todo = *it; // sync item with table todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); todoDB.addEvent( *todo ); } if(!todoDB.save() ){ QFile::remove( strNewFile ); return false; }; // now do the rename if ( ::rename( strNewFile, fn ) < 0 ) qWarning( "problem renaming file %s to %s errno %d", strNewFile.latin1(), fn.latin1(), errno ); // remove the journal QFile::remove( journalFileName() ); return true; } void TodoTable::load( const QString &fn ) { loadFile( fn, false ); if ( QFile::exists(journalFileName()) ) { - loadFile( journalFileName(), true ); + applyJournal( ); save( fn ); } // QTable::sortColumn(2,TRUE,TRUE); // QTable::sortColumn(1,TRUE,TRUE); QTable::sortColumn(0,TRUE,TRUE); setCurrentCell( 0, 2 ); setSorting(true ); } - void TodoTable::updateVisible() { if ( !isUpdatesEnabled() ) return; if (showDeadl){ showColumn (3); adjustColumn(3); }else{ hideColumn (3); adjustColumn(2); } int visible = 0; int id = mCat.id( "Todo List", showCat ); for ( int row = 0; row < numRows(); row++ ) { CheckItem *ci = (CheckItem *)item( row, 0 ); ToDoEvent *t = todoList[ci]; QArray<int> vlCats = t->categories(); bool hide = false; if ( !showComp && ci->isChecked() ) hide = true; if ( !showCat.isEmpty() ) { if ( showCat == tr( "Unfiled" ) ) { if ( vlCats.count() > 0 ) hide = true; } else { - // do some comparing, we have to reverse our idea here... which idea - zecke + // do some comparing, we have to reverse our idea here... which idea? - zecke if ( !hide ) { hide = true; for ( uint it = 0; it < vlCats.count(); ++it ) { if ( vlCats[it] == id ) { hide = false; break; } } } } } if ( hide ) { if ( currentRow() == row ) setCurrentCell( -1, 0 ); if ( rowHeight( row ) > 0 ) hideRow( row ); } else { if ( rowHeight( row ) == 0 ) { showRow( row ); adjustRow( row ); } visible++; } } if ( !visible ) setCurrentCell( -1, 0 ); } void TodoTable::viewportPaintEvent( QPaintEvent *pe ) { if ( enablePainting ) QTable::viewportPaintEvent( pe ); } void TodoTable::setPaintingEnabled( bool e ) { if ( e != enablePainting ) { if ( !enablePainting ) { enablePainting = true; rowHeightChanged( 0 ); viewport()->update(); } else { enablePainting = false; } } } void TodoTable::clear() { for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); it != todoList.end(); ++it ) { ToDoEvent *todo = *it; + updateJournal( todo, ACTION_REMOVE, 0 ); delete todo; } todoList.clear(); for ( int r = 0; r < numRows(); ++r ) { for ( int c = 0; c < numCols(); ++c ) { if ( cellWidget( r, c ) ) clearCellWidget( r, c ); clearCell( r, c ); } } setNumRows( 0 ); } void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ ) { // The default for wholeRows is false, however // for this todo table we want to exchange complete // rows when sorting. Also, we always want ascending, since // the values have a logical order. QTable::sortColumn( col, ascending, TRUE ); updateVisible(); } void TodoTable::slotCheckPriority(int row, int col ) { // kludgey work around to make forward along the updated priority... if ( col == 1 ) { // let everyone know!! ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); emit signalPriorityChanged( i->text().toInt() ); } } -void TodoTable::updateJournal( const ToDoEvent &/*todo*/, journal_action action, int row ) +void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row ) { QFile f( journalFileName() ); if ( !f.open(IO_WriteOnly|IO_Append) ) return; QString buf; QCString str; buf = "<Task"; // todo.save( buf ); buf += " Action=\"" + QString::number( int(action) ) + "\""; - buf += " Row=\"" + QString::number( row ) + "\""; // better write the id + buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id + buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\""; + buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\""; + buf += " Priority=\"" + QString::number( todo.priority() ) + "\""; + QArray<int> arrat = todo.categories(); + QString attr; + for(uint i=0; i < arrat.count(); i++ ){ + attr.append(QString::number(arrat[i])+";" ); + } + if(!attr.isEmpty() ) // remove the last ; + attr.remove(attr.length()-1, 1 ); + buf += " Categories=\"" + attr + "\""; + buf += " Description=\"" + todo.description() + "\""; + if(todo.hasDate() ) { + buf += " DateYear=\""+QString::number( todo.date().year() ) + "\""; + buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\""; + buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\""; + } buf += "/>\n"; str = buf.utf8(); f.writeBlock( str.data(), str.length() ); f.close(); } void TodoTable::rowHeightChanged( int row ) { if ( enablePainting ) QTable::rowHeightChanged( row ); } void TodoTable::loadFile( const QString &strFile, bool fromJournal ) { QList<ToDoEvent> list; ToDoDB todoDB; QValueList<ToDoEvent> vaList = todoDB.rawToDos(); for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ list.append( new ToDoEvent( (*it) ) ); } vaList.clear(); // qDebug("parsing done=%d", t.elapsed() ); if ( list.count() > 0 ) { internalAddEntries( list ); list.clear(); } // qDebug("loading done: t=%d", t.elapsed() ); } void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row ) { QString strTodo; strTodo = todo.description().left(40).simplifyWhiteSpace(); if ( row == -1 ) { QMapIterator<CheckItem*, ToDoEvent *> it; for ( it = todoList.begin(); it != todoList.end(); ++it ) { if ( *(*it) == todo ) { row = it.key()->row(); it.key()->setChecked( todo.isCompleted() ); static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); item( row, 2 )->setText( strTodo ); if (showDeadl){ static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo ); } *(*it) = todo; @@ -670,92 +691,195 @@ void TodoTable::slotDoFind( const QString &findString, bool caseSensitive, rows = numRows(); static bool wrapAround = true; if ( !backwards ) { for ( row = currFindRow + 1; row < rows; row++ ) { chk = static_cast<CheckItem*>( item(row, 0) ); if ( taskCompare(*(todoList[chk]), r, category) ) break; } } else { for ( row = currFindRow - 1; row > -1; row-- ) { chk = static_cast<CheckItem*>( item(row, 0) ); if ( taskCompare(*(todoList[chk]), r, category) ) break; } } if ( row >= rows || row < 0 ) { if ( row < 0 ) currFindRow = rows; else currFindRow = -1; if ( wrapAround ) emit signalWrapAround(); else emit signalNotFound(); wrapAround = !wrapAround; } else { currFindRow = row; QTableSelection foundSelection; foundSelection.init( currFindRow, 0 ); foundSelection.expandTo( currFindRow, numCols() - 1 ); addSelection( foundSelection ); setCurrentCell( currFindRow, numCols() - 1 ); // we should always be able to wrap around and find this again, // so don't give confusing not found message... wrapAround = true; } } int TodoTable::showCategoryId() const { int id; id = -1; // if allcategories are selected, you get unfiled... if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) ) id = mCat.id( "Todo List", showCat ); return id; } - +void TodoTable::applyJournal() +{ + // we need to hack + QFile file( journalFileName() ); + if( file.open(IO_ReadOnly ) ) { + QByteArray ar = file.readAll(); + file.close(); + QFile file2( journalFileName() + "_new" ); + if( file2.open(IO_WriteOnly ) ){ + QTextStream str(&file2 ); + str << QString::fromLatin1("<Tasks>") << endl; + str << ar.data(); + str << QString::fromLatin1("</Tasks>") << endl; + file2.close(); + } + XMLElement *root = XMLElement::load(journalFileName()+ "_new"); + XMLElement *el = root->firstChild(); + el = el->firstChild(); + while( el ){ + qWarning("journal: %s %s", el->attribute("Uid" ).latin1(), el->tagName().latin1() ); + doApply( el ); + el = el->nextChild(); + } + QFile::remove(journalFileName()+ "_new" ); + } +} +// check Action and decide +void TodoTable::doApply(XMLElement *el ) +{ + QString dummy; + bool ok; + int action; + dummy = el->attribute("Action" ); + action = dummy.toInt(&ok ); + ToDoEvent ev = xmlToEvent( el ); + if( ok ){ + switch( action ){ + case ACTION_ADD: + addEntry( ev ); + break; + case ACTION_REMOVE:{ // find an entry with the same uid and remove it then + break; + } + case ACTION_REPLACE: + break; + } + } +} +namespace { static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) { bool returnMe; QArray<int> cats; cats = task.categories(); returnMe = false; if ( (category == -1 && cats.count() == 0) || category == -2 ) returnMe = task.match( r ); else { int i; for ( i = 0; i < int(cats.count()); i++ ) { if ( cats[i] == category ) { returnMe = task.match( r ); break; } } } return returnMe; } static QString journalFileName() { QString str; str = getenv( "HOME" ); - str += "/.todojournal"; + str += "/.opie_todojournal"; return str; } +static ToDoEvent xmlToEvent( XMLElement *element ) +{ + QString dummy; + ToDoEvent event; + bool ok; + int dumInt; + // completed + dummy = element->attribute("Completed" ); + dumInt = dummy.toInt(&ok ); + if(ok ) event.setCompleted( dumInt == 0 ? false : true ); + // hasDate + dummy = element->attribute("HasDate" ); + dumInt = dummy.toInt(&ok ); + if(ok ) event.setHasDate( dumInt == 0 ? false: true ); + // set the date + bool hasDa = dumInt; + if ( hasDa ) { //parse the date + int year, day, month = 0; + year = day = month; + // year + dummy = element->attribute("DateYear" ); + dumInt = dummy.toInt(&ok ); + if( ok ) year = dumInt; + // month + dummy = element->attribute("DateMonth" ); + dumInt = dummy.toInt(&ok ); + if(ok ) month = dumInt; + dummy = element->attribute("DateDay" ); + dumInt = dummy.toInt(&ok ); + if(ok ) day = dumInt; + // set the date + QDate date( year, month, day ); + event.setDate( date); + } + dummy = element->attribute("Priority" ); + dumInt = dummy.toInt(&ok ); + if(!ok ) dumInt = ToDoEvent::NORMAL; + event.setPriority( dumInt ); + //description + dummy = element->attribute("Description" ); + event.setDescription( dummy ); + // category + dummy = element->attribute("Categories" ); + QStringList ids = QStringList::split(";", dummy ); + event.setCategories( ids ); + + //uid + dummy = element->attribute("Uid" ); + dumInt = dummy.toInt(&ok ); + if(ok ) event.setUid( dumInt ); + + return event; +} +} // int TodoTable::rowHeight( int ) const // { // return 18; // } // int TodoTable::rowPos( int row ) const // { // return 18*row; // } // int TodoTable::rowAt( int pos ) const // { // return QMIN( pos/18, numRows()-1 ); // } + diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h index 32df514..6917e04 100644 --- a/core/pim/todo/todotable.h +++ b/core/pim/todo/todotable.h @@ -47,157 +47,162 @@ public: void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); private: bool checked; QString sortKey; }; class ComboItem : public QTableItem { public: ComboItem( QTable *t, EditType et ); QWidget *createEditor() const; void setContentFromEditor( QWidget *w ); void setText( const QString &s ); int alignment() const { return Qt::AlignCenter; } QString text() const; private: QGuardedPtr<QComboBox> cb; }; class TodoTextItem : public QTableItem { public: TodoTextItem( QTable *t, const QString & str ) :QTableItem( t, QTableItem::Never, str ) {} QString key () const { return Qtopia::buildSortKey( text() ); } }; class DueTextItem : public QTableItem { public: DueTextItem( QTable *t, ToDoEvent *ev ); QString key() const; void setToDoEvent( const ToDoEvent *ev ); void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); private: int m_off; bool m_hasDate:1; bool m_completed:1; }; -enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; +enum journal_action { ACTION_ADD=0, ACTION_REMOVE, ACTION_REPLACE }; +class XMLElement; class TodoTable : public QTable { Q_OBJECT public: TodoTable( QWidget *parent = 0, const char * name = 0 ); void addEntry( const ToDoEvent &todo ); void clearFindRow() { currFindRow = -2; } ToDoEvent currentEntry() const; void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false ); QStringList categories(); void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); } bool showCompleted() const { return showComp; } void setShowDeadline (bool sd) {showDeadl = sd; updateVisible();} bool showDeadline() const { return showDeadl;} void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } const QString &showCategory() const { return showCat; } int showCategoryId() const; bool save( const QString &fn ); void load( const QString &fn ); + void applyJournal( ); void clear(); void removeCurrentEntry(); + void removeAllEntries() { clear(); }; + //void removeAllEntriesInCategory(const QString &category ); void setPaintingEnabled( bool e ); virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); // int rowHeight( int ) const; // int rowPos( int row ) const; // virtual int rowAt( int pos ) const; signals: void signalEdit(); void signalDoneChanged( bool b ); void signalPriorityChanged( int i ); void signalShowMenu( const QPoint & ); void signalNotFound(); void signalWrapAround(); protected: void keyPressEvent( QKeyEvent *e ); private: void updateVisible(); void viewportPaintEvent( QPaintEvent * ); void internalAddEntries( QList<ToDoEvent> &list); inline void insertIntoTable( ToDoEvent *todo, int row ); void updateJournal( const ToDoEvent &todo, journal_action action, int row = -1); void mergeJournal(); void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); void journalFreeRemoveEntry( int row ); inline void realignTable( int row ); void loadFile( const QString &strFile, bool fromJournal = false ); + void doApply(XMLElement *el ); private slots: void slotClicked( int row, int col, int button, const QPoint &pos ); void slotPressed( int row, int col, int button, const QPoint &pos ); void slotCheckPriority(int row, int col ); void slotCurrentChanged(int row, int col ); void slotDoFind( const QString &findString, bool caseSensetive, bool backwards, int category ); void slotShowMenu(); void rowHeightChanged( int row ); private: friend class TodoWindow; QMap<CheckItem*, ToDoEvent *> todoList; QStringList categoryList; bool showComp; QString showCat; QTimer *menuTimer; bool enablePainting; Categories mCat; int currFindRow; bool showDeadl:1; }; inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) { QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') + todo->priority() ) + Qtopia::buildSortKey( todo->description() ); CheckItem *chk = new CheckItem( this, sortKey ); chk->setChecked( todo->isCompleted() ); ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); cmb->setText( QString::number( todo->priority() ) ); QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); ti->setReplaceable( false ); DueTextItem *due = new DueTextItem(this, todo ); setItem( row, 3, due); setItem( row, 0, chk ); setItem( row, 1, cmb ); setItem( row, 2, ti ); todoList.insert( chk, todo ); } |