summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/backend') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.h1
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp6
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.h2
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp27
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h1
5 files changed, 24 insertions, 13 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h
index 3bad6b7..7944a2c 100644
--- a/libopie2/opiepim/backend/otodoaccessbackend.h
+++ b/libopie2/opiepim/backend/otodoaccessbackend.h
@@ -1,20 +1,21 @@
#ifndef OPIE_TODO_ACCESS_BACKEND_H
#define OPIE_TODO_ACCESS_BACKEND_H
#include "otodo.h"
#include "opimaccessbackend.h"
class OTodoAccessBackend : public OPimAccessBackend<OTodo> {
public:
OTodoAccessBackend();
~OTodoAccessBackend();
virtual QArray<int> effectiveToDos( const QDate& start,
const QDate& end,
bool includeNoDates ) = 0;
virtual QArray<int> overDue() = 0;
virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
int cat ) = 0;
+ virtual void removeAllCompleted() = 0;
};
#endif
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp
index ac70ea0..e96cc3c 100644
--- a/libopie2/opiepim/backend/otodoaccessvcal.cpp
+++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp
@@ -133,48 +133,54 @@ bool OTodoAccessVCal::save() {
vo = vobjByEvent( it.data() );
addVObjectProp(obj, vo );
}
writeVObject( file.directHandle(), obj );
cleanVObject( obj );
cleanStrTbl();
m_dirty = false;
return true;
}
void OTodoAccessVCal::clear() {
m_map.clear();
m_dirty = true;
}
bool OTodoAccessVCal::add( const OTodo& to ) {
m_map.insert( to.uid(), to );
m_dirty = true;
return true;
}
bool OTodoAccessVCal::remove( int uid ) {
m_map.remove( uid );
m_dirty = true;
return true;
}
+void OTodoAccessVCal::removeAllCompleted() {
+ for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) {
+ if ( (*it).isCompleted() )
+ m_map.remove( it );
+ }
+}
bool OTodoAccessVCal::replace( const OTodo& to ) {
m_map.replace( to.uid(), to );
m_dirty = true;
return true;
}
OTodo OTodoAccessVCal::find(int uid )const {
return m_map[uid];
}
QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) {
QArray<int> ar(0);
return ar;
}
QArray<int> OTodoAccessVCal::allRecords()const {
QArray<int> ar( m_map.count() );
QMap<int, OTodo>::ConstIterator it;
int i = 0;
for ( it = m_map.begin(); it != m_map.end(); ++it ) {
ar[i] = it.key();
i++;
}
return ar;
}
QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int ) {
QArray<int> ar(0);
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.h b/libopie2/opiepim/backend/otodoaccessvcal.h
index 4499a7e..452f602 100644
--- a/libopie2/opiepim/backend/otodoaccessvcal.h
+++ b/libopie2/opiepim/backend/otodoaccessvcal.h
@@ -5,31 +5,33 @@
class OTodoAccessVCal : public OTodoAccessBackend {
public:
OTodoAccessVCal(const QString& );
~OTodoAccessVCal();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
QArray<int> queryByExample( const OTodo& t, int sort );
QArray<int> effectiveToDos( const QDate& start,
const QDate& end,
bool includeNoDates );
QArray<int> overDue();
QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
int cat );
OTodo find(int uid)const;
void clear();
bool add( const OTodo& );
bool remove( int uid );
bool replace( const OTodo& );
+ void removeAllCompleted();
+
private:
bool m_dirty : 1;
QString m_file;
QMap<int, OTodo> m_map;
};
#endif
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index c1682c6..b2dfe80 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -7,68 +7,72 @@
#include <opie/xmltree.h>
#include "otodoaccessxml.h"
OTodoAccessXML::OTodoAccessXML( const QString& appName,
const QString& fileName )
: OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
{
if (!fileName.isEmpty() )
m_file = fileName;
else
m_file = Global::applicationFileName( "todolist", "todolist.xml" );
}
OTodoAccessXML::~OTodoAccessXML() {
}
bool OTodoAccessXML::load() {
m_opened = true;
m_changed = false;
/* initialize dict */
/*
* UPDATE dict if you change anything!!!
*/
- QAsciiDict<int> dict(15);
+ QAsciiDict<int> dict(21);
dict.setAutoDelete( TRUE );
dict.insert("Categories" , new int(OTodo::Category) );
dict.insert("Uid" , new int(OTodo::Uid) );
dict.insert("HasDate" , new int(OTodo::HasDate) );
dict.insert("Completed" , new int(OTodo::Completed) );
dict.insert("Description" , new int(OTodo::Description) );
dict.insert("Summary" , new int(OTodo::Summary) );
dict.insert("Priority" , new int(OTodo::Priority) );
dict.insert("DateDay" , new int(OTodo::DateDay) );
dict.insert("DateMonth" , new int(OTodo::DateMonth) );
dict.insert("DateYear" , new int(OTodo::DateYear) );
dict.insert("Progress" , new int(OTodo::Progress) );
dict.insert("Completed", new int(OTodo::Completed) );
dict.insert("CrossReference", new int(OTodo::CrossReference) );
- dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
- dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
+ dict.insert("State", new int(OTodo::State) );
+ dict.insert("Recurrence", new int(OTodo::Recurrence) );
+ dict.insert("Alarms", new int(OTodo::Alarms) );
+ dict.insert("Reminders", new int(OTodo::Reminders) );
+ dict.insert("Notifiers", new int(OTodo::Notifiers) );
+ dict.insert("Maintainer", new int(OTodo::Maintainer) );
// here the custom XML parser from TT it's GPL
- // but we want to push that to TT.....
+ // but we want to push OpiePIM... to TT.....
QFile f(m_file );
if (!f.open(IO_ReadOnly) )
return false;
QByteArray ba = f.readAll();
f.close();
char* dt = ba.data();
int len = ba.size();
int i = 0;
char *point;
const char* collectionString = "<Task ";
while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
i = point -dt;
i+= strlen(collectionString);
OTodo ev;
m_year = m_month = m_day = 0;
while ( TRUE ) {
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.
@@ -315,96 +319,87 @@ void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
break;
case OTodo::DateYear:
m_year = val.toInt();
break;
case OTodo::Progress:
ev.setProgress( val.toInt() );
break;
case OTodo::CrossReference:
{
/*
* A cross refernce looks like
* appname,id;appname,id
* we need to split it up
*/
QStringList refs = QStringList::split(';', val );
QStringList::Iterator strIt;
for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) {
int pos = (*strIt).find(',');
if ( pos > -1 )
; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() );
}
break;
}
- case OTodo::HasAlarmDateTime:
- ev.setHasAlarmDateTime( val.toInt() );
- break;
- case OTodo::AlarmDateTime: {
- /* this sounds better ;) zecke */
- ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) );
- break;
- }
default:
break;
}
}
QString OTodoAccessXML::toString( const OTodo& ev )const {
QString str;
str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
str += "Categories=\"" + toString( ev.categories() ) + "\" ";
str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
if ( ev.hasDueDate() ) {
str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
}
// qWarning( "Uid %d", ev.uid() );
str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
// append the extra options
/* FIXME Qtopia::Record this is currently not
* possible you can set custom fields
* but don' iterate over the list
* I may do #define private protected
* for this case - cough --zecke
*/
/*
QMap<QString, QString> extras = ev.extras();
QMap<QString, QString>::Iterator extIt;
for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
str += extIt.key() + "=\"" + extIt.data() + "\" ";
*/
// cross refernce
- str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" ";
return str;
}
QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
return Qtopia::Record::idsToString( ints );
}
/* internal class for sorting
*
* Inspired by todoxmlio.cpp from TT
*/
struct OTodoXMLContainer {
OTodo todo;
};
namespace {
inline QString string( const OTodo& todo) {
return todo.summary().isEmpty() ?
todo.description().left(20 ) :
todo.summary();
}
inline int completed( const OTodo& todo1, const OTodo& todo2) {
int ret = 0;
@@ -595,24 +590,30 @@ QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
if ((*it).isCompleted() && comp ) {
qWarning("completed continue!");
continue;
}
OTodoXMLContainer* con = new OTodoXMLContainer();
con->todo = (*it);
vector.insert(item, con );
item++;
}
qWarning("XXX %d Items added", item);
vector.resize( item );
/* sort it now */
vector.sort();
/* now get the uids */
QArray<int> array( vector.count() );
for (uint i= 0; i < vector.count(); i++ ) {
array[i] = ( vector.at(i) )->todo.uid();
}
qWarning("array count = %d %d", array.count(), vector.count() );
return array;
};
+void OTodoAccessXML::removeAllCompleted() {
+ for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
+ if ( (*it).isCompleted() )
+ m_events.remove( it );
+ }
+}
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h
index dc41c32..93609fe 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.h
+++ b/libopie2/opiepim/backend/otodoaccessxml.h
@@ -8,48 +8,49 @@
namespace Opie {
class XMLElement;
};
class OTodoAccessXML : public OTodoAccessBackend {
public:
/**
* fileName if Empty we will use the default path
*/
OTodoAccessXML( const QString& appName,
const QString& fileName = QString::null );
~OTodoAccessXML();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
QArray<int> queryByExample( const OTodo&, int querysettings );
OTodo find( int uid )const;
void clear();
bool add( const OTodo& );
bool remove( int uid );
+ void removeAllCompleted();
bool replace( const OTodo& );
/* our functions */
QArray<int> effectiveToDos( const QDate& start,
const QDate& end,
bool includeNoDates );
QArray<int> overDue();
QArray<int> sorted( bool asc, int sortOrder,
int sortFilter, int cat );
private:
void todo( QAsciiDict<int>*, OTodo&,const QCString&,const QString& );
QString toString( const OTodo& )const;
QString toString( const QArray<int>& ints ) const;
QMap<int, OTodo> m_events;
QString m_file;
QString m_app;
bool m_opened : 1;
bool m_changed : 1;
class OTodoAccessXMLPrivate;
OTodoAccessXMLPrivate* d;
int m_year, m_month, m_day;
};