summaryrefslogtreecommitdiff
authorzecke <zecke>2002-03-21 00:26:39 (UTC)
committer zecke <zecke>2002-03-21 00:26:39 (UTC)
commit8bfe366ce8667addc539f11fc560250c306340ae (patch) (side-by-side diff)
tree4b890a47d86621d3e1f0aacde2485457862f02c8
parente8f15a98c611b0c6030e8210672b249b42107526 (diff)
downloadopie-8bfe366ce8667addc539f11fc560250c306340ae.zip
opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.gz
opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.bz2
Move todolist to tododb
Please test todolist
Diffstat (more/less context) (show 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.cpp37
-rw-r--r--core/pim/todo/todoentryimpl.h8
-rw-r--r--core/pim/todo/todotable.cpp258
-rw-r--r--core/pim/todo/todotable.h21
-rw-r--r--libopie/todoevent.cpp20
-rw-r--r--libopie/todoevent.h3
8 files changed, 117 insertions, 259 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
@@ -26,2 +26,5 @@
+#include <opie/tododb.h>
+#include <opie/todovcalresource.h>
+
#include <qpe/qpeapplication.h>
@@ -34,3 +37,3 @@
#include <qpe/resource.h>
-#include <qpe/task.h>
+//#include <qpe/task.h>
#include <qpe/qpetoolbar.h>
@@ -217,3 +220,3 @@ void TodoWindow::slotNew()
- Task todo;
+ ToDoEvent todo;
@@ -223,3 +226,3 @@ void TodoWindow::slotNew()
int ret = e.exec();
-
+ qWarning("finished" );
if ( ret == QDialog::Accepted ) {
@@ -227,3 +230,3 @@ void TodoWindow::slotNew()
todo = e.todoEntry();
- todo.assignUid();
+ //todo.assignUid();
table->addEntry( todo );
@@ -277,3 +280,3 @@ void TodoWindow::slotEdit()
- Task todo = table->currentEntry();
+ ToDoEvent todo = table->currentEntry();
@@ -351,4 +354,3 @@ void TodoWindow::populateCategories()
- int id,
- rememberId;
+ int id, rememberId;
id = 1;
@@ -445,4 +447,5 @@ void TodoWindow::setDocument( const QString &filename )
- 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 );
@@ -456,5 +459,7 @@ 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 );
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
@@ -16,3 +16,3 @@ INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
-LIBS += -lqpe
+LIBS += -lqpe -lopie
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
@@ -22,2 +22,5 @@
+#include <opie/todoevent.h>
+#include <opie/tododb.h>
+
#include <qpe/categoryselect.h>
@@ -26,4 +29,4 @@
#include <qpe/imageedit.h>
-#include <qpe/task.h>
#include <qpe/timestring.h>
+#include <qpe/palmtoprecord.h>
@@ -41,3 +44,3 @@
-NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent,
+NewTaskDialog::NewTaskDialog( const ToDoEvent& task, QWidget *parent,
const char *name, bool modal, WFlags fl )
@@ -46,5 +49,6 @@ NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent,
{
- todo.setCategories( task.categories() );
- if ( todo.hasDueDate() )
- date = todo.dueDate();
+ qWarning("setting category" );
+ todo.setCategory( task.category() );
+ if ( todo.hasDate() )
+ date = todo.date();
else
@@ -56,3 +60,3 @@ NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent,
checkCompleted->setChecked( task.isCompleted() );
- checkDate->setChecked( task.hasDueDate() );
+ checkDate->setChecked( task.hasDate() );
buttonDate->setText( TimeString::longDateString( date ) );
@@ -77,3 +81,3 @@ NewTaskDialog::NewTaskDialog( int id, QWidget* parent, const char* name, bool m
ids[0] = id;
- todo.setCategories( ids );
+ todo.setCategory( Qtopia::Record::idsToString( ids ) );
}
@@ -102,2 +106,3 @@ NewTaskDialog::~NewTaskDialog()
{
+ qWarning("d'tor" );
// no need to delete child widgets, Qt does it all for us
@@ -113,7 +118,18 @@ void NewTaskDialog::dateChanged( int y, int m, int d )
-Task NewTaskDialog::todoEntry()
+ToDoEvent NewTaskDialog::todoEntry()
{
- todo.setDueDate( date, checkDate->isChecked() );
+ qWarning("todoEntry()" );
+ if( checkDate->isChecked() ){
+ todo.setDate( date );
+ todo.setHasDate( true );
+ }else{
+ todo.setHasDate( false );
+ }
+ qWarning("todoEntry::category()" );
if ( comboCategory->currentCategory() != -1 ) {
- todo.setCategories( comboCategory->currentCategories() );
+ QArray<int> arr = comboCategory->currentCategories();
+ int id = arr[0];
+ qWarning("id 0: %d",id );
+ todo.setCategory( Qtopia::Record::idsToString( arr ) );
+ qWarning("saving category");
}
@@ -134,2 +150,3 @@ void NewTaskDialog::accept()
{
+ qWarning("accept" );
QString strText = txtTodo->text();
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
@@ -25,3 +25,3 @@
-#include <qpe/task.h>
+#include <opie/todoevent.h>
@@ -39,3 +39,3 @@ class NewTaskDialog : public NewTaskDialogBase
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 );
@@ -45,3 +45,3 @@ public:
- Task todoEntry();
+ ToDoEvent todoEntry();
@@ -55,3 +55,3 @@ private:
void init();
- Task todo;
+ ToDoEvent todo;
QDate date;
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
@@ -22,2 +22,3 @@
+#include <opie/tododb.h>
#include <qpe/categoryselect.h>
@@ -41,3 +42,3 @@
-static bool taskCompare( const Task &task, const QRegExp &r, int category );
+static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
@@ -64,3 +65,3 @@ void CheckItem::toggle()
TodoTable *parent = static_cast<TodoTable*>(table());
- Task newTodo = parent->currentEntry();
+ ToDoEvent newTodo = parent->currentEntry();
checked = !checked;
@@ -135,3 +136,3 @@ void ComboItem::setContentFromEditor( QWidget *w )
TodoTable *parent = static_cast<TodoTable*>(table());
- Task newTodo = parent->currentEntry();
+ ToDoEvent newTodo = parent->currentEntry();
@@ -196,3 +197,3 @@ TodoTable::TodoTable( QWidget *parent, const char *name )
-void TodoTable::addEntry( const Task &todo )
+void TodoTable::addEntry( const ToDoEvent &todo )
{
@@ -201,3 +202,3 @@ void TodoTable::addEntry( const Task &todo )
updateJournal( todo, ACTION_ADD );
- insertIntoTable( new Task(todo), row );
+ insertIntoTable( new ToDoEvent(todo), row );
setCurrentCell(row, currentColumn());
@@ -254,3 +255,3 @@ void TodoTable::slotCurrentChanged( int, int )
-void TodoTable::internalAddEntries( QList<Task> &list )
+void TodoTable::internalAddEntries( QList<ToDoEvent> &list )
{
@@ -258,3 +259,3 @@ void TodoTable::internalAddEntries( QList<Task> &list )
int row = 0;
- Task *it;
+ ToDoEvent *it;
for ( it = list.first(); it; it = list.next() )
@@ -264,3 +265,3 @@ void TodoTable::internalAddEntries( QList<Task> &list )
-Task TodoTable::currentEntry() const
+ToDoEvent TodoTable::currentEntry() const
{
@@ -268,4 +269,4 @@ Task TodoTable::currentEntry() const
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() );
@@ -275,3 +276,3 @@ Task TodoTable::currentEntry() const
-void TodoTable::replaceCurrentEntry( const Task &todo, bool fromTableItem )
+void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem )
{
@@ -288,3 +289,3 @@ void TodoTable::removeCurrentEntry()
{
- Task *oldTodo;
+ ToDoEvent *oldTodo;
int row = currentRow();
@@ -309,11 +310,5 @@ 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 ) {
@@ -321,3 +316,3 @@ bool TodoTable::save( const QString &fn )
continue;
- Task *todo = *it;
+ ToDoEvent *todo = *it;
// sync item with table
@@ -325,25 +320,8 @@ bool TodoTable::save( const QString &fn )
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 = "";
+ todoDB.addEvent( *todo );
}
-
- buf += "</Tasks>\n";
- str = buf.utf8();
- total_written = f.writeBlock( str.data(), str.length() );
- if ( total_written != int(str.length()) ) {
- f.close();
+ if(!todoDB.save() ){
QFile::remove( strNewFile );
return false;
- }
- f.close();
-
+ };
// now do the rename
@@ -382,3 +360,3 @@ void TodoTable::updateVisible()
CheckItem *ci = (CheckItem *)item( row, 0 );
- Task *t = todoList[ci];
+ ToDoEvent *t = todoList[ci];
QArray<int> vlCats = t->categories();
@@ -442,5 +420,5 @@ 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;
@@ -479,3 +457,3 @@ void TodoTable::slotCheckPriority(int row, int col )
-void TodoTable::updateJournal( const Task &todo, journal_action action, int row )
+void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row )
{
@@ -487,3 +465,3 @@ void TodoTable::updateJournal( const Task &todo, journal_action action, int row
buf = "<Task";
- todo.save( buf );
+ // todo.save( buf );
buf += " Action=\"" + QString::number( int(action) ) + "\"";
@@ -504,174 +482,10 @@ 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;
- }
+ 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() );
@@ -684,3 +498,3 @@ void TodoTable::loadFile( const QString &strFile, bool fromJournal )
-void TodoTable::journalFreeReplaceEntry( const Task &todo, int row )
+void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
{
@@ -689,3 +503,3 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row )
if ( row == -1 ) {
- QMapIterator<CheckItem*, Task *> it;
+ QMapIterator<CheckItem*, ToDoEvent *> it;
for ( it = todoList.begin(); it != todoList.end(); ++it ) {
@@ -700,3 +514,3 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row )
} 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)) );
@@ -706,3 +520,3 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row )
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) );
}
@@ -816,3 +630,3 @@ int TodoTable::showCategoryId() const
-static bool taskCompare( const Task &task, const QRegExp &r, int category )
+static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
{
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
@@ -25,3 +25,4 @@
#include <qpe/stringutil.h>
-#include <qpe/task.h>
+//#include <qpe/task.h>
+#include <opie/todoevent.h>
@@ -88,7 +89,7 @@ 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 );
@@ -130,7 +131,7 @@ private:
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 );
@@ -152,3 +153,3 @@ private:
- QMap<CheckItem*, Task *> todoList;
+ QMap<CheckItem*, ToDoEvent *> todoList;
QStringList categoryList;
@@ -163,3 +164,3 @@ private:
-inline void TodoTable::insertIntoTable( Task *todo, int row )
+inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row )
{
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp
index daa25f4..7dbf907 100644
--- a/libopie/todoevent.cpp
+++ b/libopie/todoevent.cpp
@@ -4,3 +4,3 @@
#include <qpe/stringutil.h>
-//#include <qpe/palmtoprecord.h>
+#include <qpe/palmtoprecord.h>
@@ -28,2 +28,19 @@ ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category,
}
+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
@@ -66,2 +83,3 @@ void ToDoEvent::setCategory( const QString &cat )
{
+ qWarning("setCategory %s", cat.latin1() );
m_category = cat;
diff --git a/libopie/todoevent.h b/libopie/todoevent.h
index bca7f6e..ac996a1 100644
--- a/libopie/todoevent.h
+++ b/libopie/todoevent.h
@@ -19,2 +19,3 @@ class ToDoEvent {
QString category()const;
+ QArray<int> categories() const;
QDate date()const;
@@ -32,2 +33,4 @@ class ToDoEvent {
+ bool match( const QRegExp &r )const;
+
void setUid(int id) {m_uid = id; };