-rw-r--r-- | core/pim/todo/mainwindow.cpp | 23 | ||||
-rw-r--r-- | core/pim/todo/mainwindow.h | 7 | ||||
-rw-r--r-- | core/pim/todo/todoentryimpl.cpp | 8 | ||||
-rw-r--r-- | core/pim/todo/todotable.cpp | 68 | ||||
-rw-r--r-- | core/pim/todo/todotable.h | 22 |
5 files changed, 119 insertions, 9 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index f3afa5f..33f13aa 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp @@ -1,34 +1,36 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. + Copyright (C) 2002 zecke + Copyright (C) 2002 Stefan Eilers ** ** 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. ** **********************************************************************/ #define QTOPIA_INTERNAL_FD #include "mainwindow.h" #include "todoentryimpl.h" #include "todotable.h" #include <opie/tododb.h> #include <opie/todovcalresource.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/finddialog.h> #include <qpe/global.h> #include <qpe/ir.h> @@ -78,64 +80,69 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : 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 ); + + /* added 20.01.2k2 by se */ + 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 ); 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" ), 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; a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ), @@ -145,85 +152,89 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : a->addTo( bar ); a->addTo( edit ); a->addTo( contextMenu ); a->setEnabled( FALSE ); deleteAction = a; 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 ); 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 ); + /* added 20.01.2k2 by se */ + showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE ); + catMenu->setCheckable( true ); populateCategories(); mb->insertItem( tr( "Task" ), edit ); mb->insertItem( tr( "View" ), catMenu ); 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 ); @@ -322,115 +333,119 @@ void TodoWindow::currentEntryChanged( int r, int ) deleteAction->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(); completedAction->addTo( catMenu ); completedAction->setOn( table->showCompleted() ); + showdeadlineAction->addTo( catMenu ); + showdeadlineAction->setOn( table->showDeadline() ); int id, rememberId; id = 1; catMenu->insertItem( tr( "All Categories" ), id++ ); // 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()); } else { if ( QMessageBox::critical( this, tr("Out of space"), tr("Todo was unable\n" "to save your changes.\n" "Free up some space\n" "and try again.\n" "\nQuit Anyway?"), QMessageBox::Yes|QMessageBox::Escape, QMessageBox::No|QMessageBox::Default) != QMessageBox::No ) e->accept(); else e->ignore(); } } void TodoWindow::slotFind() { // put everything back to view all for searching... if ( !catMenu->isItemChecked( 0 ) ) setCategory( 0 ); FindDialog dlg( "Todo List", this ); QObject::connect( &dlg, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), table, SLOT(slotDoFind(const QString&, bool, bool, int)) ); QObject::connect( table, SIGNAL(signalNotFound()), &dlg, SLOT(slotNotFound()) ); QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, SLOT(slotWrapAround()) ); @@ -444,32 +459,40 @@ void TodoWindow::slotFind() void TodoWindow::setDocument( const QString &filename ) { if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; ToDoDB todoDB(filename, new ToDoVCalResource() ); QValueList<ToDoEvent> tl = todoDB.rawToDos(); for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) { table->addEntry( *it ); } } static const char * beamfile = "/tmp/obex/todo.vcs"; void TodoWindow::slotBeam() { unlink( beamfile ); // delete if exists ToDoEvent c = table->currentEntry(); mkdir("/tmp/obex/", 0755); ToDoDB todoDB( beamfile, new ToDoVCalResource() ); todoDB.addEvent( c ); todoDB.save(); Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); QString description = c.description(); ir->send( beamfile, description, "text/x-vCalendar" ); } void TodoWindow::beamDone( Ir *ir ) { delete ir; unlink( beamfile ); } + +/* added 20.01.2k2 by se */ +void TodoWindow::showDeadline( bool s ) +{ + table->setPaintingEnabled( false ); + table->setShowDeadline( s ); + table->setPaintingEnabled( true ); +} diff --git a/core/pim/todo/mainwindow.h b/core/pim/todo/mainwindow.h index 856dcb4..a81c27c 100644 --- a/core/pim/todo/mainwindow.h +++ b/core/pim/todo/mainwindow.h @@ -18,57 +18,62 @@ ** not clear to you. ** **********************************************************************/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> class TodoTable; class QAction; class QPopupMenu; class Ir; 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 * ); protected: void closeEvent( QCloseEvent *e ); private: void populateCategories(); private: TodoTable *table; QAction *editAction, *deleteAction, *findAction, - * completedAction; + * completedAction, + *showdeadlineAction ; QPopupMenu *contextMenu, *catMenu; bool syncing; }; #endif diff --git a/core/pim/todo/todoentryimpl.cpp b/core/pim/todo/todoentryimpl.cpp index 1dc1d44..f938d61 100644 --- a/core/pim/todo/todoentryimpl.cpp +++ b/core/pim/todo/todoentryimpl.cpp @@ -19,65 +19,65 @@ **********************************************************************/ #include "todoentryimpl.h" #include <opie/todoevent.h> #include <opie/tododb.h> #include <qpe/categoryselect.h> #include <qpe/datebookmonth.h> #include <qpe/global.h> #include <qpe/imageedit.h> #include <qpe/timestring.h> #include <qpe/palmtoprecord.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qtoolbutton.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qlabel.h> #include <qtimer.h> #include <qapplication.h> NewTaskDialog::NewTaskDialog( const ToDoEvent& task, QWidget *parent, const char *name, bool modal, WFlags fl ) : NewTaskDialogBase( parent, name, modal, fl ), todo( task ) { qWarning("setting category" ); - todo.setCategory( task.category() ); + todo.setCategories( task.allCategories() ); if ( todo.hasDate() ) date = todo.date(); else date = QDate::currentDate(); init(); comboPriority->setCurrentItem( task.priority() - 1 ); checkCompleted->setChecked( task.isCompleted() ); checkDate->setChecked( task.hasDate() ); buttonDate->setText( TimeString::longDateString( date ) ); txtTodo->setText( task.description() ); } /* * Constructs a NewTaskDialog which is a child of 'parent', with the * name 'name' and widget flags set to 'f' * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ NewTaskDialog::NewTaskDialog( int id, QWidget* parent, const char* name, bool modal, WFlags fl ) : NewTaskDialogBase( parent, name, modal, fl ), date( QDate::currentDate() ) { if ( id != -1 ) { QArray<int> ids( 1 ); ids[0] = id; todo.setCategory( Qtopia::Record::idsToString( ids ) ); } @@ -99,61 +99,61 @@ void NewTaskDialog::init() picker->setDate( date.year(), date.month(), date.day() ); } /* * Destroys the object and frees any allocated resources */ NewTaskDialog::~NewTaskDialog() { qWarning("d'tor" ); // no need to delete child widgets, Qt does it all for us } void NewTaskDialog::dateChanged( int y, int m, int d ) { date = QDate( y, m, d ); buttonDate->setText( TimeString::longDateString( date ) ); } /*! */ ToDoEvent NewTaskDialog::todoEntry() { qWarning("todoEntry()" ); if( checkDate->isChecked() ){ todo.setDate( date ); todo.setHasDate( true ); }else{ todo.setHasDate( false ); } qWarning("todoEntry::category()" ); if ( comboCategory->currentCategory() != -1 ) { QArray<int> arr = comboCategory->currentCategories(); - int id = arr[0]; - qWarning("id 0: %d",id ); - todo.setCategory( Qtopia::Record::idsToString( arr ) ); + QStringList list; + list = QStringList::split(";", Qtopia::Record::idsToString( arr )) ; qWarning("saving category"); + todo.setCategories( list ); } todo.setPriority( comboPriority->currentItem() + 1 ); todo.setCompleted( checkCompleted->isChecked() ); todo.setDescription( txtTodo->text() ); return todo; } /*! */ void NewTaskDialog::accept() { qWarning("accept" ); QString strText = txtTodo->text(); if ( strText.isEmpty() ) { // hmm... just decline it then, the user obviously didn't care about it QDialog::reject(); return; } QDialog::accept(); } diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index 2bb95a2..3cd0c0e 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp @@ -1,72 +1,75 @@ /********************************************************************** ** 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 <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 <qcursor.h> #include <qregexp.h> #include <errno.h> #include <stdlib.h> +#include <stdio.h> + static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); static QString journalFileName(); 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 ); } @@ -135,165 +138,185 @@ void ComboItem::setContentFromEditor( QWidget *w ) { TodoTable *parent = static_cast<TodoTable*>(table()); ToDoEvent newTodo = parent->currentEntry(); if ( w->inherits( "QComboBox" ) ) setText( ( (QComboBox*)w )->currentText() ); else QTableItem::setContentFromEditor( w ); newTodo.setPriority( text().toInt() ); parent->replaceCurrentEntry( newTodo, true ); } void ComboItem::setText( const QString &s ) { if ( cb ) cb->setCurrentItem( s.toInt() - 1 ); QTableItem::setText( s ); } QString ComboItem::text() const { if ( cb ) return cb->currentText(); return QTableItem::text(); } TodoTable::TodoTable( QWidget *parent, const char *name ) // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR // : QTable( 0, 3, parent, name, TRUE ), // #else - : QTable( 0, 3, parent, name ), + : QTable( 0, 4, parent, name ), // #endif showComp( true ), enablePainting( true ), mCat( 0 ), - currFindRow( -2 ) + currFindRow( -2 ), + showDeadl( true) { mCat.load( categoryFileName() ); setSorting( TRUE ); setSelectionMode( NoSelection ); setColumnStretchable( 2, TRUE ); setColumnWidth( 0, 20 ); setColumnWidth( 1, 35 ); + setLeftMargin( 0 ); verticalHeader()->hide(); horizontalHeader()->setLabel( 0, tr( "C." ) ); horizontalHeader()->setLabel( 1, tr( "Prior." ) ); horizontalHeader()->setLabel( 2, tr( "Description" ) ); + + setColumnStretchable( 3, FALSE ); + setColumnWidth( 3, 20 ); + horizontalHeader()->setLabel( 3, tr( "Deadline" ) ); + + if (showDeadl){ + showColumn (3); + }else{ + hideColumn (3); + } + connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); connect( this, SIGNAL( valueChanged( int, int ) ), this, SLOT( slotCheckPriority( int, int ) ) ); connect( this, SIGNAL( currentChanged( int, int ) ), this, SLOT( slotCurrentChanged( int, int ) ) ); menuTimer = new QTimer( this ); connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); } void TodoTable::addEntry( const ToDoEvent &todo ) { int row = numRows(); setNumRows( row + 1 ); updateJournal( todo, ACTION_ADD ); insertIntoTable( new ToDoEvent(todo), row ); setCurrentCell(row, currentColumn()); updateVisible(); } void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) { if ( !cellGeometry( row, col ).contains(pos) ) return; // let's switch on the column number... switch ( col ) { case 0: { CheckItem *i = static_cast<CheckItem*>(item( row, col )); if ( i ) { int x = pos.x() - columnPos( col ); int y = pos.y() - rowPos( row ); int w = columnWidth( col ); int h = rowHeight( row ); if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize && y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) { i->toggle(); } emit signalDoneChanged( i->isChecked() ); } } break; case 1: break; case 2: // may as well edit it... menuTimer->stop(); // emit signalEdit(); break; + case 3: /* added 20.01.2k2 by se */ + // may as well edit it... + menuTimer->stop(); + emit signalEdit(); + break; } } void TodoTable::slotPressed( int row, int col, int, const QPoint &pos ) { if ( col == 2 && cellGeometry( row, col ).contains(pos) ) menuTimer->start( 750, TRUE ); } void TodoTable::slotShowMenu() { emit signalShowMenu( QCursor::pos() ); } void TodoTable::slotCurrentChanged( int, int ) { menuTimer->stop(); } void TodoTable::internalAddEntries( QList<ToDoEvent> &list ) { setNumRows( list.count() ); int row = 0; ToDoEvent *it; for ( it = list.first(); it; it = list.next() ) insertIntoTable( it, row++ ); } ToDoEvent TodoTable::currentEntry() const { + printf ("in currentEntry\n"); + QTableItem *i = item( currentRow(), 0 ); if ( !i || rowHeight( currentRow() ) <= 0 ) return ToDoEvent(); ToDoEvent *todo = todoList[(CheckItem*)i]; todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); return *todo; } void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) { int row = currentRow(); updateJournal( todo, ACTION_REPLACE, row ); if ( !fromTableItem ) { journalFreeReplaceEntry( todo, row ); updateVisible(); } } void TodoTable::removeCurrentEntry() { ToDoEvent *oldTodo; int row = currentRow(); CheckItem *chk; chk = static_cast<CheckItem*>(item(row, 0 )); if ( !chk ) return; oldTodo = todoList[chk]; todoList.remove( chk ); oldTodo->setCompleted( chk->isChecked() ); @@ -325,64 +348,73 @@ bool TodoTable::save( const QString &fn ) 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 ); save( fn ); } // QTable::sortColumn(2,TRUE,TRUE); // QTable::sortColumn(1,TRUE,TRUE); QTable::sortColumn(0,TRUE,TRUE); setCurrentCell( 0, 2 ); } void TodoTable::updateVisible() { if ( !isUpdatesEnabled() ) return; // qDebug("--> updateVisible!"); + /* added 20.01.2k2 by se */ + 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... 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 { @@ -426,127 +458,155 @@ void TodoTable::clear() 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, TRUE, 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 ) + "\""; 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 ); + + /* added 20.01.2k2 by se */ + if (showDeadl){ + if (todo.hasDate()){ + QDate *today = new QDate (QDate::currentDate()); + if (today){ + item (row, 3)->setText (tr ("%1").arg(today->daysTo(todo.date()))); + delete (today); + } + }else{ + item (row, 3)->setText ("n.d."); + } + } + *(*it) = todo; } } } else { ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))]; todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); delete t; static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() ); static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); item( row, 2 )->setText( strTodo ); + + /* added 20.01.2k2 by se */ + if (showDeadl){ + if (todo.hasDate()){ + QDate *today = new QDate (QDate::currentDate()); + if (today){ + item (row, 3)->setText (tr ("%1").arg(today->daysTo(todo.date()))); + delete (today); + } + }else{ + item (row, 3)->setText ("n.d."); + } + } + todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) ); } } void TodoTable::journalFreeRemoveEntry( int row ) { CheckItem *chk; chk = static_cast<CheckItem*>(item(row, 0 )); if ( !chk ) return; todoList.remove( chk ); realignTable( row ); } void TodoTable::keyPressEvent( QKeyEvent *e ) { if ( e->key() == Key_Space || e->key() == Key_Return ) { switch ( currentColumn() ) { case 0: { CheckItem *i = static_cast<CheckItem*>(item(currentRow(), currentColumn())); if ( i ) i->toggle(); break; } case 1: break; case 2: emit signalEdit(); default: break; diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h index 2746ce7..288ff90 100644 --- a/core/pim/todo/todotable.h +++ b/core/pim/todo/todotable.h @@ -69,140 +69,162 @@ private: }; class TodoTextItem : public QTableItem { public: TodoTextItem( QTable *t, const QString & str ) :QTableItem( t, QTableItem::Never, str ) {} QString key () const { return Qtopia::buildSortKey( text() ); } }; enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; 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; } + /* added 20.01.2k2 by se */ + 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 clear(); void removeCurrentEntry(); 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 ); 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; + + /* added 20.01.2k2 by se */ + bool showDeadl; }; 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 ); + /* added 20.01.2k2 by se */ + QTableItem *dl = NULL; + if (todo->hasDate()){ + QDate *today = new QDate (QDate::currentDate()); + if (today){ + dl = new TodoTextItem (this, tr ("%1"). + arg(today->daysTo(todo->date()))); + delete (today); + } + }else{ + dl = new TodoTextItem (this,"n.d."); + } + setItem( row, 3, dl); + setItem( row, 0, chk ); setItem( row, 1, cmb ); setItem( row, 2, ti ); + todoList.insert( chk, todo ); } inline void TodoTable::realignTable( int row ) { QTableItem *ti1, *ti2, *ti3; int totalRows = numRows(); for ( int curr = row; curr < totalRows - 1; curr++ ) { // this is bad, we must take the item out and then // set it. In the end, it behaves no worse (time wise) // then the old way of saving the entries to file, clearing // the table re-reading in the file and resetting the table ti1 = item( curr + 1, 0 ); ti2 = item( curr + 1, 1 ); ti3 = item( curr + 1, 2 ); takeItem( ti1 ); takeItem( ti2 ); takeItem( ti3 ); setItem( curr, 0, ti1 ); setItem( curr, 1, ti2 ); setItem( curr, 2, ti3 ); } setNumRows( totalRows - 1 ); } #endif |