summaryrefslogtreecommitdiff
path: root/libopie
Side-by-side diff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/orecordlist.h17
-rw-r--r--libopie/pim/otodo.cpp1
-rw-r--r--libopie/pim/otodoaccess.cpp8
-rw-r--r--libopie/pim/otodoaccess.h16
-rw-r--r--libopie/pim/otodoaccessbackend.h2
-rw-r--r--libopie/pim/otodoaccessxml.cpp145
-rw-r--r--libopie/pim/otodoaccessxml.h2
7 files changed, 183 insertions, 8 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index c63d813..1fd0741 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -48,3 +48,3 @@ public:
bool operator!=( const ORecordListIterator& it );
-
+
/**
@@ -53,3 +53,3 @@ public:
uint current()const;
-
+
/**
@@ -58,3 +58,3 @@ public:
uint count()const;
-
+
/**
@@ -103,3 +103,3 @@ public:
Iterator end();
-
+
/**
@@ -108,3 +108,4 @@ public:
uint count()const;
-
+
+ T operator[]( uint i );
// FIXME implemenent remove
@@ -148,3 +149,3 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIter
m_end = it.m_end;
-// m_record = it.m_record;
+ m_record = it.m_record;
@@ -254,2 +255,6 @@ return m_ids.count();
}
+template <class T>
+T ORecordList<T>::operator[]( uint i ) {
+ return m_acc->find( m_ids[i] );
+}
#endif
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index 6dd4c0e..eb9dad3 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -174,2 +174,3 @@ void OTodo::setPriority(int prio )
{
+ qWarning("set priority %d", prio);
changeOrModify();
diff --git a/libopie/pim/otodoaccess.cpp b/libopie/pim/otodoaccess.cpp
index 8ec09bc..f51da29 100644
--- a/libopie/pim/otodoaccess.cpp
+++ b/libopie/pim/otodoaccess.cpp
@@ -70,2 +70,8 @@ void OTodoAccess::delAlarm( int uid) {
}
-
+/* sort order */
+OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
+ QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
+ filter, cat );
+ OTodoAccess::List list( ints, this );
+ return list;
+}
diff --git a/libopie/pim/otodoaccess.h b/libopie/pim/otodoaccess.h
index c43efe9..12997aa 100644
--- a/libopie/pim/otodoaccess.h
+++ b/libopie/pim/otodoaccess.h
@@ -19,2 +19,9 @@ class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
public:
+ enum SortOrder { Completed = 0,
+ Priority,
+ Description,
+ Deadline };
+ enum SortFilter{ ShowOverdue = 0,
+ Category =1,
+ OnlyOverDue= 2 };
/**
@@ -22,3 +29,3 @@ public:
* the default resource will be
- * icked up
+ * picked up
*/
@@ -50,2 +57,8 @@ public:
List overDue();
+
+ /**
+ *
+ */
+ List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
+
/**
@@ -73,2 +86,3 @@ signals:
private:
+ int m_cat;
OTodoAccessBackend* m_todoBackEnd;
diff --git a/libopie/pim/otodoaccessbackend.h b/libopie/pim/otodoaccessbackend.h
index ebe2189..3bad6b7 100644
--- a/libopie/pim/otodoaccessbackend.h
+++ b/libopie/pim/otodoaccessbackend.h
@@ -14,2 +14,4 @@ public:
virtual QArray<int> overDue() = 0;
+ virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
+ int cat ) = 0;
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index 5fe733c..692483e 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -1,2 +1,3 @@
#include <qfile.h>
+#include <qvector.h>
@@ -258,2 +259,3 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con
case OTodo::Priority:
+ qWarning("ParsePriority " + it.data() );
ev.setPriority( it.data().toInt() );
@@ -366 +368,144 @@ QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
}
+
+/* internal class for sorting */
+
+struct OTodoXMLContainer {
+ OTodo todo;
+};
+ /*
+ * Returns:
+ * 0 if item1 == item2
+ *
+ * non-zero if item1 != item2
+ *
+ * This function returns int rather than bool so that reimplementations
+ * can return one of three values and use it to sort by:
+ *
+ * 0 if item1 == item2
+ *
+ * > 0 (positive integer) if item1 > item2
+ *
+ * < 0 (negative integer) if item1 < item2
+ *
+ */
+class OTodoXMLVector : public QVector<OTodoXMLContainer> {
+public:
+ OTodoXMLVector(int size, bool asc, int sort)
+ : QVector<OTodoXMLContainer>( size )
+ {
+ setAutoDelete( true );
+ m_asc = asc;
+ m_sort = sort;
+ }
+ /* return the summary/description */
+ QString string( const OTodo& todo) {
+ return todo.summary().isEmpty() ?
+ todo.description().left(20 ) :
+ todo.summary();
+ }
+ /**
+ * we take the sortorder( switch on it )
+ *
+ */
+ int compareItems( Item d1, Item d2 ) {
+ qWarning("compare items");
+ int ret =0;
+ OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
+ OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
+
+ /* same item */
+ if ( con1->todo.uid() == con2->todo.uid() )
+ return 0;
+ qWarning("m_sort %d", m_sort );
+
+ switch ( m_sort ) {
+ /* completed */
+ case 0: {
+ ret = 0;
+ if ( con1->todo.isCompleted() ) ret++;
+ if ( con2->todo.isCompleted() ) ret--;
+ break;
+ }
+ /* priority */
+ case 1: {
+ ret = con1->todo.priority() - con2->todo.priority();
+ qWarning(" priority %d %d %d", ret,
+ con1->todo.priority(),
+ con2->todo.priority()
+ );
+ break;
+ }
+ /* description */
+ case 2: {
+ QString str1 = string( con1->todo );
+ QString str2 = string( con2->todo );
+ ret = QString::compare( str1, str2 );
+ break;
+ }
+ /* deadline */
+ case 3: {
+ /* either bot got a dueDate
+ * or one of them got one
+ */
+ if ( con1->todo.hasDueDate() &&
+ con2->todo.hasDueDate() )
+ ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() );
+ else if ( con1->todo.hasDueDate() )
+ ret = -1;
+ else if ( con2->todo.hasDueDate() )
+ ret = 0;
+ break;
+ }
+ default:
+ ret = 0;
+ break;
+ };
+
+ /* twist it we're not ascending*/
+ if (!m_asc)
+ ret = ret * -1;
+ return ret;
+ }
+ private:
+ bool m_asc;
+ int m_sort;
+
+};
+
+QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
+ int sortFilter, int cat ) {
+ OTodoXMLVector vector(m_events.count(), asc,sortOrder );
+ QMap<int, OTodo>::Iterator it;
+ int item = 0;
+
+ bool bCat = sortFilter & 1 ? true : false;
+ bool bOver = sortFilter & 0 ? true : false;
+ bool bOnly = split & 2 ? true : false;
+ for ( it = m_events.begin(); it != m_events.end(); ++it ) {
+
+ /* show category */
+ if ( bCat )
+ if (!(*it).categories().contains( cat ) )
+ continue;
+ /* isOverdue but we should not show overdue */
+ if ( (*it).isOverdue() && ( !bOver || !bOnly ) )
+ continue;
+ if ( !(*it).isOverdue() && bOnly )
+ continue;
+
+
+ OTodoXMLContainer* con = new OTodoXMLContainer();
+ con->todo = (*it);
+ vector.insert(item, con );
+ 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();
+ }
+ return array;
+};
diff --git a/libopie/pim/otodoaccessxml.h b/libopie/pim/otodoaccessxml.h
index be9109d..6886bab 100644
--- a/libopie/pim/otodoaccessxml.h
+++ b/libopie/pim/otodoaccessxml.h
@@ -38,2 +38,4 @@ public:
QArray<int> overDue();
+ QArray<int> sorted( bool asc, int sortOrder,
+ int sortFilter, int cat );
private: