summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp27
-rw-r--r--core/pim/todo/todo.pro2
-rw-r--r--core/pim/todo/todoentryimpl.cpp53
-rw-r--r--core/pim/todo/todoentryimpl.h8
-rw-r--r--core/pim/todo/todotable.cpp274
-rw-r--r--core/pim/todo/todotable.h21
-rw-r--r--libopie/todoevent.cpp22
-rw-r--r--libopie/todoevent.h3
8 files changed, 134 insertions, 276 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 6709811..f3afa5f 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -11,41 +11,44 @@
** 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>
#include <qpe/qpemenubar.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
-#include <qpe/task.h>
+//#include <qpe/task.h>
#include <qpe/qpetoolbar.h>
#include <qaction.h>
#include <qarray.h>
#include <qdatastream.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
@@ -202,43 +205,43 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
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 );
- Task todo;
+ 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();
+ //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) {
@@ -262,33 +265,33 @@ void TodoWindow::slotDelete()
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;
}
- Task todo = table->currentEntry();
+ 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();
@@ -336,34 +339,33 @@ void TodoWindow::setCategory( int c )
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() );
- int id,
- rememberId;
+ 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 );
@@ -430,41 +432,44 @@ void TodoWindow::slotFind()
SLOT(slotDoFind(const QString&, bool, bool, int)) );
QObject::connect( table, SIGNAL(signalNotFound()), &dlg,
SLOT(slotNotFound()) );
QObject::connect( table, SIGNAL(signalWrapAround()), &dlg,
SLOT(slotWrapAround()) );
dlg.exec();
if ( table->numSelections() )
table->clearSelection();
table->clearFindRow();
}
void TodoWindow::setDocument( const QString &filename )
{
if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
- QValueList<Task> tl = Task::readVCalendar( filename );
- for( QValueList<Task>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
+ 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
- Task c = table->currentEntry();
+ ToDoEvent c = table->currentEntry();
mkdir("/tmp/obex/", 0755);
- Task::writeVCalendar( beamfile, c );
+ 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 );
}
diff --git a/core/pim/todo/todo.pro b/core/pim/todo/todo.pro
index 18f70fe..7f9ddd5 100644
--- a/core/pim/todo/todo.pro
+++ b/core/pim/todo/todo.pro
@@ -1,20 +1,20 @@
TEMPLATE = app
CONFIG = qt warn_on release
DESTDIR = $(OPIEDIR)/bin
HEADERS = mainwindow.h \
todotable.h \
todoentryimpl.h
SOURCES = main.cpp \
mainwindow.cpp \
todotable.cpp \
todoentryimpl.cpp
INTERFACES = todoentry.ui
TARGET = todolist
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
-LIBS += -lqpe
+LIBS += -lqpe -lopie
TRANSLATIONS = ../i18n/de/todolist.ts
TRANSLATIONS += ../i18n/pt_BR/todolist.ts
diff --git a/core/pim/todo/todoentryimpl.cpp b/core/pim/todo/todoentryimpl.cpp
index c957715..1dc1d44 100644
--- a/core/pim/todo/todoentryimpl.cpp
+++ b/core/pim/todo/todoentryimpl.cpp
@@ -7,136 +7,153 @@
** 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.
**
**********************************************************************/
#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/task.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 Task& task, QWidget *parent,
+NewTaskDialog::NewTaskDialog( const ToDoEvent& task, QWidget *parent,
const char *name, bool modal, WFlags fl )
: NewTaskDialogBase( parent, name, modal, fl ),
todo( task )
{
- todo.setCategories( task.categories() );
- if ( todo.hasDueDate() )
- date = todo.dueDate();
+ qWarning("setting category" );
+ todo.setCategory( task.category() );
+ if ( todo.hasDate() )
+ date = todo.date();
else
date = QDate::currentDate();
init();
comboPriority->setCurrentItem( task.priority() - 1 );
checkCompleted->setChecked( task.isCompleted() );
- checkDate->setChecked( task.hasDueDate() );
+ 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.setCategories( ids );
+ todo.setCategory( Qtopia::Record::idsToString( ids ) );
}
init();
}
void NewTaskDialog::init()
{
QPopupMenu *m1 = new QPopupMenu( this );
picker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( picker );
buttonDate->setPopup( m1 );
comboCategory->setCategories( todo.categories(), "Todo List", tr("Todo List") );
connect( picker, SIGNAL( dateClicked( int, int, int ) ),
this, SLOT( dateChanged( int, int, int ) ) );
buttonDate->setText( TimeString::longDateString( date ) );
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 ) );
}
/*!
*/
-Task NewTaskDialog::todoEntry()
+ToDoEvent NewTaskDialog::todoEntry()
{
- todo.setDueDate( date, checkDate->isChecked() );
- if ( comboCategory->currentCategory() != -1 ) {
- todo.setCategories( comboCategory->currentCategories() );
- }
- todo.setPriority( comboPriority->currentItem() + 1 );
- todo.setCompleted( checkCompleted->isChecked() );
-
- todo.setDescription( txtTodo->text() );
-
- return todo;
+ 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 ) );
+ qWarning("saving category");
+ }
+ 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/todoentryimpl.h b/core/pim/todo/todoentryimpl.h
index 932d66e..6407eb4 100644
--- a/core/pim/todo/todoentryimpl.h
+++ b/core/pim/todo/todoentryimpl.h
@@ -10,52 +10,52 @@
**
** 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.
**
**********************************************************************/
#ifndef NEWTASKDIALOG_H
#define NEWTASKDIALOG_H
#include "todoentry.h"
-#include <qpe/task.h>
+#include <opie/todoevent.h>
#include <qdatetime.h>
#include <qpalette.h>
class QLabel;
class QTimer;
class DateBookMonth;
class NewTaskDialog : public NewTaskDialogBase
{
Q_OBJECT
public:
- NewTaskDialog( const Task &task, QWidget *parent = 0, const char* name = 0,
+ NewTaskDialog( const ToDoEvent &task, QWidget *parent = 0, const char* name = 0,
bool modal = FALSE, WFlags fl = 0 );
NewTaskDialog( int id, QWidget* parent = 0, const char* name = 0,
bool modal = FALSE, WFlags fl = 0 );
~NewTaskDialog();
- Task todoEntry();
+ ToDoEvent todoEntry();
protected slots:
void dateChanged( int y, int m, int d );
protected:
virtual void accept();
private:
void init();
- Task todo;
+ ToDoEvent todo;
QDate date;
DateBookMonth *picker;
};
#endif // NEWTASKDIALOG_H
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 77d3389..2bb95a2 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -7,75 +7,76 @@
** 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.
**
**********************************************************************/
#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>
-static bool taskCompare( const Task &task, const QRegExp &r, int category );
+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());
- Task newTodo = parent->currentEntry();
+ 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 )
{
@@ -120,33 +121,33 @@ ComboItem::ComboItem( QTable *t, EditType et )
QWidget *ComboItem::createEditor() const
{
QString txt = text();
( (ComboItem*)this )->cb = new QComboBox( table()->viewport() );
cb->insertItem( "1" );
cb->insertItem( "2" );
cb->insertItem( "3" );
cb->insertItem( "4" );
cb->insertItem( "5" );
cb->setCurrentItem( txt.toInt() - 1 );
return cb;
}
void ComboItem::setContentFromEditor( QWidget *w )
{
TodoTable *parent = static_cast<TodoTable*>(table());
- Task newTodo = parent->currentEntry();
+ 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 );
}
@@ -181,38 +182,38 @@ TodoTable::TodoTable( QWidget *parent, const char *name )
horizontalHeader()->setLabel( 0, tr( "C." ) );
horizontalHeader()->setLabel( 1, tr( "Prior." ) );
horizontalHeader()->setLabel( 2, tr( "Description" ) );
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 Task &todo )
+void TodoTable::addEntry( const ToDoEvent &todo )
{
int row = numRows();
setNumRows( row + 1 );
updateJournal( todo, ACTION_ADD );
- insertIntoTable( new Task(todo), row );
+ 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 );
@@ -239,126 +240,103 @@ void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
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<Task> &list )
+void TodoTable::internalAddEntries( QList<ToDoEvent> &list )
{
setNumRows( list.count() );
int row = 0;
- Task *it;
+ ToDoEvent *it;
for ( it = list.first(); it; it = list.next() )
insertIntoTable( it, row++ );
}
-Task TodoTable::currentEntry() const
+ToDoEvent TodoTable::currentEntry() const
{
QTableItem *i = item( currentRow(), 0 );
if ( !i || rowHeight( currentRow() ) <= 0 )
- return Task();
- Task *todo = todoList[(CheckItem*)i];
+ 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 Task &todo, bool fromTableItem )
+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()
{
- Task *oldTodo;
+ 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() );
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 f( strNewFile );
- if ( !f.open( IO_WriteOnly|IO_Raw ) )
- return false;
-
- QString buf("<!DOCTYPE Tasks>\n<Tasks>\n");
- QCString str;
- int total_written;
-
- for ( QMap<CheckItem*, Task *>::Iterator it = todoList.begin();
+ 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;
- Task *todo = *it;
+ 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() );
- buf += "<Task";
- todo->save( buf );
- buf += " />\n";
- str = buf.utf8();
- total_written = f.writeBlock( str.data(), str.length() );
- if ( total_written != int(str.length()) ) {
- f.close();
- QFile::remove( strNewFile );
- return false;
- }
- buf = "";
- }
-
- buf += "</Tasks>\n";
- str = buf.utf8();
- total_written = f.writeBlock( str.data(), str.length() );
- if ( total_written != int(str.length()) ) {
- f.close();
- QFile::remove( strNewFile );
- return false;
+ todoDB.addEvent( *todo );
}
- f.close();
-
+ 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 );
save( fn );
@@ -367,33 +345,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!");
int visible = 0;
int id = mCat.id( "Todo List", showCat );
for ( int row = 0; row < numRows(); row++ ) {
CheckItem *ci = (CheckItem *)item( row, 0 );
- Task *t = todoList[ci];
+ 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;
@@ -427,35 +405,35 @@ void TodoTable::viewportPaintEvent( QPaintEvent *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*, Task *>::Iterator it = todoList.begin();
+ for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
it != todoList.end(); ++it ) {
- Task *todo = *it;
+ ToDoEvent *todo = *it;
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
@@ -464,260 +442,96 @@ void TodoTable::sortColumn( int col, bool /*ascending*/, bool /*wholeRows*/ )
// 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 Task &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 );
+ // 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 )
{
- QFile f( strFile );
- if ( !f.open(IO_ReadOnly) )
- return;
-
- int action, row;
- action = 0; row = 0;
-
- enum Attribute {
- FCompleted = 0,
- FHasDate,
- FPriority,
- FCategories,
- FDescription,
- FDateYear,
- FDateMonth,
- FDateDay,
- FUid,
- FAction,
- FRow
- };
-
- QAsciiDict<int> dict( 31 );
- QList<Task> list;
- dict.setAutoDelete( TRUE );
- dict.insert( "Completed", new int(FCompleted) );
- dict.insert( "HasDate", new int(FHasDate) );
- dict.insert( "Priority", new int(FPriority) );
- dict.insert( "Categories", new int(FCategories) );
- dict.insert( "Description", new int(FDescription) );
- dict.insert( "DateYear", new int(FDateYear) );
- dict.insert( "DateMonth", new int(FDateMonth) );
- dict.insert( "DateDay", new int(FDateDay) );
- dict.insert( "Uid", new int(FUid) );
- dict.insert( "Action", new int(FAction) );
- dict.insert( "Row", new int(FRow) );
-
- QByteArray ba = f.readAll();
- f.close();
- char* dt = ba.data();
- int len = ba.size();
- bool hasDueDate = FALSE;
-
- action = ACTION_ADD;
- int i = 0;
- char *point;
- while ( ( point = strstr( dt+i, "<Task " ) ) != NULL ) {
- // new Task
- i = point - dt;
- Task *todo = new Task;
- int dtY = 0, dtM = 0, dtD = 0;
-
- i += 5;
-
- while( 1 ) {
- while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
- ++i;
- if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
- break;
- // we have another attribute, read it.
- int j = i;
- while ( j < len && dt[j] != '=' )
- ++j;
- char *attr = dt+i;
- dt[j] = '\0';
- i = ++j; // skip =
- while ( i < len && dt[i] != '"' )
- ++i;
- j = ++i;
- bool haveUtf = FALSE;
- bool haveEnt = FALSE;
- while ( j < len && dt[j] != '"' ) {
- if ( ((unsigned char)dt[j]) > 0x7f )
- haveUtf = TRUE;
- if ( dt[j] == '&' )
- haveEnt = TRUE;
- ++j;
- }
- if ( i == j ) {
- // empty value
- i = j + 1;
- continue;
- }
- QCString value( dt+i, j-i+1 );
- i = j + 1;
- int *lookup = dict[ attr ];
- if ( !lookup ) {
- todo->setCustomField(attr, value);
- continue;
- }
- switch( *lookup ) {
- case FCompleted:
- todo->setCompleted( value.toInt() );
- break;
- case FHasDate:
- // leave...
- hasDueDate = value.toInt();
- break;
- case FPriority:
- todo->setPriority( value.toInt() );
- break;
- case FCategories: {
- //QString str = Qtopia::plainString( value );
- todo->setCategories( Qtopia::Record::idsFromString( value ) );
- break;
- }
- case FDescription:
- {
- QString str = (haveUtf ? QString::fromUtf8( value )
- : QString::fromLatin1( value ) );
- if ( haveEnt )
- str = Qtopia::plainString( str );
- todo->setDescription( str );
- break;
- }
- case FDateYear:
- dtY = value.toInt();
- break;
- case FDateMonth:
- dtM = value.toInt();
- break;
- case FDateDay:
- dtD = value.toInt();
- break;
- case FUid:
- todo->setUid( value.toInt() );
- break;
- case FAction:
- action = value.toInt();
- break;
- case FRow:
- row = value.toInt();
- break;
- default:
- qDebug( "huh??? missing enum? -- attr.: %s", attr );
- break;
- }
- }
-
- if ( dtY != 0 && dtM != 0 && dtD != 0 )
- todo->setDueDate( QDate( dtY, dtM, dtD), hasDueDate );
- else
- todo->setHasDueDate( hasDueDate );
-
-// if ( categoryList.find( todo.category() ) == categoryList.end() )
-// categoryList.append( todo.category() );
-
- // sadly we can't delay adding of items from the journal to get
- // the proper effect, but then, the journal should _never_ be
- // that huge
-
- switch( action ) {
- case ACTION_ADD:
- if ( fromJournal ) {
- int myrows = numRows();
- setNumRows( myrows + 1 );
- insertIntoTable( todo, myrows );
- delete todo;
- } else
- list.append( todo );
- break;
- case ACTION_REMOVE:
- journalFreeRemoveEntry( row );
- break;
- case ACTION_REPLACE:
- journalFreeReplaceEntry( *todo, row );
- delete todo;
- break;
- default:
- break;
- }
- }
-// qDebug("parsing done=%d", t.elapsed() );
- if ( list.count() > 0 ) {
- internalAddEntries( list );
- list.clear();
- }
+ 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 Task &todo, int row )
+void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
{
QString strTodo;
strTodo = todo.description().left(40).simplifyWhiteSpace();
if ( row == -1 ) {
- QMapIterator<CheckItem*, Task *> it;
+ 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 );
*(*it) = todo;
}
}
} else {
- Task *t = todoList[static_cast<CheckItem*>(item(row, 0))];
+ 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 );
- todoList.insert( static_cast<CheckItem*>(item(row,0)), new Task(todo) );
+ 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 )
{
@@ -801,33 +615,33 @@ void TodoTable::slotDoFind( const QString &findString, bool caseSensitive,
// 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;
}
-static bool taskCompare( const Task &task, const QRegExp &r, int category )
+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;
}
}
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h
index 4f3a064..2746ce7 100644
--- a/core/pim/todo/todotable.h
+++ b/core/pim/todo/todotable.h
@@ -10,33 +10,34 @@
**
** 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.
**
**********************************************************************/
#ifndef TODOTABLE_H
#define TODOTABLE_H
#include <qpe/categories.h>
#include <qpe/stringutil.h>
-#include <qpe/task.h>
+//#include <qpe/task.h>
+#include <opie/todoevent.h>
#include <qtable.h>
#include <qmap.h>
#include <qguardedptr.h>
class Node;
class QComboBox;
class QTimer;
class CheckItem : public QTableItem
{
public:
CheckItem( QTable *t, const QString &sortkey );
void setChecked( bool b );
void toggle();
@@ -73,37 +74,37 @@ 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 Task &todo );
+ void addEntry( const ToDoEvent &todo );
void clearFindRow() { currFindRow = -2; }
- Task currentEntry() const;
- void replaceCurrentEntry( const Task &todo, bool fromTableItem = false );
+ 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 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 );
@@ -115,66 +116,66 @@ public:
// 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<Task> &list);
- inline void insertIntoTable( Task *todo, int row );
- void updateJournal( const Task &todo, journal_action action, int row = -1);
+ 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 Task &todo, int row );
+ 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*, Task *> todoList;
+ QMap<CheckItem*, ToDoEvent *> todoList;
QStringList categoryList;
bool showComp;
QString showCat;
QTimer *menuTimer;
bool enablePainting;
Categories mCat;
int currFindRow;
};
-inline void TodoTable::insertIntoTable( Task *todo, int row )
+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 );
setItem( row, 0, chk );
setItem( row, 1, cmb );
setItem( row, 2, ti );
todoList.insert( chk, todo );
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp
index daa25f4..7dbf907 100644
--- a/libopie/todoevent.cpp
+++ b/libopie/todoevent.cpp
@@ -1,44 +1,61 @@
#include <opie/todoevent.h>
#include <qpe/palmtopuidgen.h>
#include <qpe/stringutil.h>
-//#include <qpe/palmtoprecord.h>
+#include <qpe/palmtoprecord.h>
ToDoEvent::ToDoEvent(const ToDoEvent &event )
{
*this = event;
}
ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category,
const QString &description, bool hasDate, QDate date, int uid )
{
qWarning("todoEvent c'tor" );
m_date = date;
m_isCompleted = completed;
m_hasDate = hasDate;
m_priority = priority;
m_category = category;
m_desc = Qtopia::simplifyMultiLineSpace(description );
if (uid == -1 ) {
Qtopia::UidGen *uidgen = new Qtopia::UidGen();
uid = uidgen->generate();
delete uidgen;
}// generate the ids
m_uid = uid;
}
+QArray<int> ToDoEvent::categories()const
+{
+ QArray<int> array(1); // currently the datebook can be only in one category
+ array = Qtopia::Record::idsFromString( category() );
+ return array;
+}
+bool ToDoEvent::match( const QRegExp &regExp )const
+{
+ if( QString::number( m_priority ).find( regExp ) != -1 ){
+ return true;
+ }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){
+ return true;
+ }else if(m_desc.find( regExp ) != -1 ){
+ return true;
+ }
+ return false;
+}
bool ToDoEvent::isCompleted() const
{
return m_isCompleted;
}
bool ToDoEvent::hasDate() const
{
return m_hasDate;
}
int ToDoEvent::priority()const
{
return m_priority;
}
QString ToDoEvent::category()const
{
return m_category;
}
@@ -51,33 +68,34 @@ QString ToDoEvent::description()const
return m_desc;
}
void ToDoEvent::setCompleted( bool completed )
{
m_isCompleted = completed;
}
void ToDoEvent::setHasDate( bool hasDate )
{
m_hasDate = hasDate;
}
void ToDoEvent::setDescription(const QString &desc )
{
m_desc = Qtopia::simplifyMultiLineSpace(desc );
}
void ToDoEvent::setCategory( const QString &cat )
{
- m_category = cat;
+ qWarning("setCategory %s", cat.latin1() );
+ m_category = cat;
}
void ToDoEvent::setPriority(int prio )
{
m_priority = prio;
}
void ToDoEvent::setDate( QDate date )
{
m_date = date;
}
bool ToDoEvent::isOverdue( )
{
if( m_hasDate )
return QDate::currentDate() > m_date;
return false;
}
bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{
diff --git a/libopie/todoevent.h b/libopie/todoevent.h
index bca7f6e..ac996a1 100644
--- a/libopie/todoevent.h
+++ b/libopie/todoevent.h
@@ -4,45 +4,48 @@
#include <qdatetime.h>
class ToDoEvent {
friend class ToDoDB;
public:
enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW };
ToDoEvent( bool completed = false, int priority = NORMAL,
const QString &category = QString::null,
const QString &description = QString::null ,
bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 );
ToDoEvent(const ToDoEvent & );
bool isCompleted() const;
bool hasDate() const;
int priority()const ;
QString category()const;
+ QArray<int> categories() const;
QDate date()const;
QString description()const;
int uid()const { return m_uid;};
void setCompleted(bool completed );
void setHasDate( bool hasDate );
// if the category doesn't exist we will create it
void setCategory( const QString &category );
void setPriority(int priority );
void setDate( QDate date );
void setDescription(const QString& );
bool isOverdue();
+ bool match( const QRegExp &r )const;
+
void setUid(int id) {m_uid = id; };
bool operator<(const ToDoEvent &toDoEvent )const;
bool operator<=(const ToDoEvent &toDoEvent )const;
bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); };
bool operator>(const ToDoEvent &toDoEvent )const;
bool operator>=(const ToDoEvent &toDoEvent)const;
bool operator==(const ToDoEvent &toDoEvent )const;
ToDoEvent &operator=(const ToDoEvent &toDoEvent );
private:
class ToDoEventPrivate;
ToDoEventPrivate *d;
QDate m_date;
bool m_isCompleted:1;
bool m_hasDate:1;
int m_priority;
QString m_category;