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.cpp148
1 files changed, 136 insertions, 12 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 2acd03c..401d2c8 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -13,49 +13,53 @@
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
/* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de)
*/
#include "todotable.h"
#include <opie/tododb.h>
+#include <opie/xmltree.h>
+
#include <qpe/categoryselect.h>
#include <qpe/xmlreader.h>
#include <qasciidict.h>
#include <qcombobox.h>
#include <qfile.h>
#include <qpainter.h>
#include <qtextcodec.h>
#include <qtimer.h>
#include <qdatetime.h>
+#include <qtextstream.h>
#include <qcursor.h>
#include <qregexp.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
+#include <iostream>
+namespace {
-
-static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
-
-static QString journalFileName();
-
+ static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
+ static QString journalFileName();
+ static ToDoEvent xmlToEvent( XMLElement *ev );
+}
CheckItem::CheckItem( QTable *t, const QString &key )
: QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key )
{
}
QString CheckItem::key() const
{
return sortKey;
}
void CheckItem::setChecked( bool b )
{
@@ -400,34 +404,33 @@ bool TodoTable::save( const QString &fn )
qWarning( "problem renaming file %s to %s errno %d",
strNewFile.latin1(), fn.latin1(), errno );
// remove the journal
QFile::remove( journalFileName() );
return true;
}
void TodoTable::load( const QString &fn )
{
loadFile( fn, false );
if ( QFile::exists(journalFileName()) ) {
- loadFile( journalFileName(), true );
+ applyJournal( );
save( fn );
}
// QTable::sortColumn(2,TRUE,TRUE);
// QTable::sortColumn(1,TRUE,TRUE);
QTable::sortColumn(0,TRUE,TRUE);
setCurrentCell( 0, 2 );
setSorting(true );
}
-
void TodoTable::updateVisible()
{
if ( !isUpdatesEnabled() )
return;
if (showDeadl){
showColumn (3);
adjustColumn(3);
}else{
hideColumn (3);
adjustColumn(2);
}
@@ -437,25 +440,25 @@ void TodoTable::updateVisible()
for ( int row = 0; row < numRows(); row++ ) {
CheckItem *ci = (CheckItem *)item( row, 0 );
ToDoEvent *t = todoList[ci];
QArray<int> vlCats = t->categories();
bool hide = false;
if ( !showComp && ci->isChecked() )
hide = true;
if ( !showCat.isEmpty() ) {
if ( showCat == tr( "Unfiled" ) ) {
if ( vlCats.count() > 0 )
hide = true;
} else {
- // do some comparing, we have to reverse our idea here... which idea - zecke
+ // do some comparing, we have to reverse our idea here... which idea? - zecke
if ( !hide ) {
hide = true;
for ( uint it = 0; it < vlCats.count(); ++it ) {
if ( vlCats[it] == id ) {
hide = false;
break;
}
}
}
}
}
if ( hide ) {
@@ -490,24 +493,25 @@ void TodoTable::setPaintingEnabled( bool e )
viewport()->update();
} else {
enablePainting = false;
}
}
}
void TodoTable::clear()
{
for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
it != todoList.end(); ++it ) {
ToDoEvent *todo = *it;
+ updateJournal( todo, ACTION_REMOVE, 0 );
delete todo;
}
todoList.clear();
for ( int r = 0; r < numRows(); ++r ) {
for ( int c = 0; c < numCols(); ++c ) {
if ( cellWidget( r, c ) )
clearCellWidget( r, c );
clearCell( r, c );
}
}
setNumRows( 0 );
}
@@ -524,35 +528,52 @@ 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 ) + "\""; // better write the id
+ buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id
+ buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\"";
+ buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\"";
+ buf += " Priority=\"" + QString::number( todo.priority() ) + "\"";
+ QArray<int> arrat = todo.categories();
+ QString attr;
+ for(uint i=0; i < arrat.count(); i++ ){
+ attr.append(QString::number(arrat[i])+";" );
+ }
+ if(!attr.isEmpty() ) // remove the last ;
+ attr.remove(attr.length()-1, 1 );
+ buf += " Categories=\"" + attr + "\"";
+ buf += " Description=\"" + todo.description() + "\"";
+ if(todo.hasDate() ) {
+ buf += " DateYear=\""+QString::number( todo.date().year() ) + "\"";
+ buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\"";
+ buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\"";
+ }
buf += "/>\n";
str = buf.utf8();
f.writeBlock( str.data(), str.length() );
f.close();
}
void TodoTable::rowHeightChanged( int row )
{
if ( enablePainting )
QTable::rowHeightChanged( row );
}
@@ -706,25 +727,73 @@ void TodoTable::slotDoFind( const QString &findString, bool caseSensitive,
}
}
int TodoTable::showCategoryId() const
{
int id;
id = -1;
// if allcategories are selected, you get unfiled...
if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) )
id = mCat.id( "Todo List", showCat );
return id;
}
-
+void TodoTable::applyJournal()
+{
+ // we need to hack
+ QFile file( journalFileName() );
+ if( file.open(IO_ReadOnly ) ) {
+ QByteArray ar = file.readAll();
+ file.close();
+ QFile file2( journalFileName() + "_new" );
+ if( file2.open(IO_WriteOnly ) ){
+ QTextStream str(&file2 );
+ str << QString::fromLatin1("<Tasks>") << endl;
+ str << ar.data();
+ str << QString::fromLatin1("</Tasks>") << endl;
+ file2.close();
+ }
+ XMLElement *root = XMLElement::load(journalFileName()+ "_new");
+ XMLElement *el = root->firstChild();
+ el = el->firstChild();
+ while( el ){
+ qWarning("journal: %s %s", el->attribute("Uid" ).latin1(), el->tagName().latin1() );
+ doApply( el );
+ el = el->nextChild();
+ }
+ QFile::remove(journalFileName()+ "_new" );
+ }
+}
+// check Action and decide
+void TodoTable::doApply(XMLElement *el )
+{
+ QString dummy;
+ bool ok;
+ int action;
+ dummy = el->attribute("Action" );
+ action = dummy.toInt(&ok );
+ ToDoEvent ev = xmlToEvent( el );
+ if( ok ){
+ switch( action ){
+ case ACTION_ADD:
+ addEntry( ev );
+ break;
+ case ACTION_REMOVE:{ // find an entry with the same uid and remove it then
+ break;
+ }
+ case ACTION_REPLACE:
+ break;
+ }
+ }
+}
+namespace {
static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
{
bool returnMe;
QArray<int> cats;
cats = task.categories();
returnMe = false;
if ( (category == -1 && cats.count() == 0) || category == -2 )
returnMe = task.match( r );
else {
int i;
for ( i = 0; i < int(cats.count()); i++ ) {
@@ -732,30 +801,85 @@ static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
returnMe = task.match( r );
break;
}
}
}
return returnMe;
}
static QString journalFileName()
{
QString str;
str = getenv( "HOME" );
- str += "/.todojournal";
+ str += "/.opie_todojournal";
return str;
}
+static ToDoEvent xmlToEvent( XMLElement *element )
+{
+ QString dummy;
+ ToDoEvent event;
+ bool ok;
+ int dumInt;
+ // completed
+ dummy = element->attribute("Completed" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) event.setCompleted( dumInt == 0 ? false : true );
+ // hasDate
+ dummy = element->attribute("HasDate" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) event.setHasDate( dumInt == 0 ? false: true );
+ // set the date
+ bool hasDa = dumInt;
+ if ( hasDa ) { //parse the date
+ int year, day, month = 0;
+ year = day = month;
+ // year
+ dummy = element->attribute("DateYear" );
+ dumInt = dummy.toInt(&ok );
+ if( ok ) year = dumInt;
+ // month
+ dummy = element->attribute("DateMonth" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) month = dumInt;
+ dummy = element->attribute("DateDay" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) day = dumInt;
+ // set the date
+ QDate date( year, month, day );
+ event.setDate( date);
+ }
+ dummy = element->attribute("Priority" );
+ dumInt = dummy.toInt(&ok );
+ if(!ok ) dumInt = ToDoEvent::NORMAL;
+ event.setPriority( dumInt );
+ //description
+ dummy = element->attribute("Description" );
+ event.setDescription( dummy );
+ // category
+ dummy = element->attribute("Categories" );
+ QStringList ids = QStringList::split(";", dummy );
+ event.setCategories( ids );
+
+ //uid
+ dummy = element->attribute("Uid" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) event.setUid( dumInt );
+
+ return event;
+}
+}
// int TodoTable::rowHeight( int ) const
// {
// return 18;
// }
// int TodoTable::rowPos( int row ) const
// {
// return 18*row;
// }
// int TodoTable::rowAt( int pos ) const
// {
// return QMIN( pos/18, numRows()-1 );
// }
+