summaryrefslogtreecommitdiff
path: root/core/pim/todo/todotable.cpp
Side-by-side diff
Diffstat (limited to 'core/pim/todo/todotable.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/todotable.cpp68
1 files changed, 64 insertions, 4 deletions
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
@@ -8,45 +8,48 @@
** 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
@@ -155,42 +158,55 @@ 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()) );
}
@@ -225,24 +241,29 @@ void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
}
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() );
@@ -256,24 +277,26 @@ void TodoTable::slotCurrentChanged( int, int )
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();
@@ -345,24 +368,33 @@ void TodoTable::load( const QString &fn )
// 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 )
@@ -446,25 +478,25 @@ void TodoTable::sortColumn( int col, bool /*ascending*/, bool /*wholeRows*/ )
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();
@@ -499,34 +531,62 @@ void TodoTable::loadFile( const QString &strFile, bool fromJournal )
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 );