summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp61
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h6
-rw-r--r--libopie2/opiepim/core/otodoaccess.h6
3 files changed, 65 insertions, 8 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 209e714..25536e0 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -287,52 +287,109 @@ bool OTodoAccessBackendSQL::remove( int uid ) {
return false;
update();
return true;
}
/*
* FIXME better set query
* but we need the cache for that
* now we remove
*/
bool OTodoAccessBackendSQL::replace( const OTodo& t) {
remove( t.uid() );
return add(t);
}
QArray<int> OTodoAccessBackendSQL::overDue() {
OverDueQuery qu;
return uids( m_driver->query(&qu ) );
}
QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s,
const QDate& t,
bool u) {
EffQuery ef(s, t, u );
return uids (m_driver->query(&ef) );
}
+/*
+ *
+ */
QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
int sortFilter, int cat ) {
- QArray<int> ints(0);
- return ints;
+ QString query;
+ query = "select uid from todolist WHERE ";
+
+ /*
+ * Sort Filter stuff
+ * not that straight forward
+ *
+ */
+ /* Category */
+ if ( sortFilter & 1 ) {
+ query += " categories like '%" +QString::number(cat)+"%' AND";
+ }
+ /* Show only overdue */
+ if ( sortFilter & 2 ) {
+ QDate date = QDate::currentDate();
+ QString due;
+ QString base;
+ base = QString("DueDate <= '%1-%2-%3' AND WHERE completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() );
+ query += " " + base + " AND";
+ }
+ /* not show completed */
+ if ( sortFilter & 4 ) {
+ query += " completed = 0 AND";
+ }else{
+ query += " ( completed = 1 OR completed = 0) AND";
+ }
+ /* srtip the end */
+ query = query.remove( query.length()-3, 3 );
+
+
+ /*
+ * sort order stuff
+ * quite straight forward
+ */
+ query += "ORDER BY ";
+ switch( sortOrder ) {
+ /* completed */
+ case 0:
+ query += "completed";
+ break;
+ case 1:
+ query += "priority";
+ break;
+ case 2:
+ query += "description";
+ break;
+ case 3:
+ query += "DueDate";
+ break;
+ }
+ if ( !asc )
+ query += " DESC";
+
+ qWarning( query );
+ OSQLRawQuery raw(query );
+ return uids( m_driver->query(&raw) );
}
bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
if ( str == "0-0-0" )
return false;
else{
int day, year, month;
QStringList list = QStringList::split("-", str );
year = list[0].toInt();
month = list[1].toInt();
day = list[2].toInt();
da.setYMD( year, month, day );
return true;
}
}
OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
if ( res.state() == OSQLResult::Failure ) {
OTodo to;
return to;
}
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it = list.begin();
bool has = false; QDate da = QDate::currentDate();
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 966628d..6c5f50a 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -11,36 +11,36 @@ class OTodoAccessBackendSQL : public OTodoAccessBackend {
public:
OTodoAccessBackendSQL( const QString& file );
~OTodoAccessBackendSQL();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
QArray<int> queryByExample( const OTodo& t, int sort );
OTodo find(int uid)const;
void clear();
bool add( const OTodo& t );
bool remove( int uid );
bool replace( const OTodo& t );
QArray<int> overDue();
QArray<int> effectiveToDos( const QDate& start,
const QDate& end, bool includeNoDates );
QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
private:
void update();
void fillDict();
- bool date( QDate& date, const QString& )const;
- OTodo todo( const OSQLResult& )const;
- QArray<int> uids( const OSQLResult& )const;
+ inline bool date( QDate& date, const QString& )const;
+ inline OTodo todo( const OSQLResult& )const;
+ inline QArray<int> uids( const OSQLResult& )const;
OTodo todo( int uid )const;
QAsciiDict<int> m_dict;
OSQLDriver* m_driver;
QArray<int> m_uids;
};
#endif
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h
index 12997aa..390ab0e 100644
--- a/libopie2/opiepim/core/otodoaccess.h
+++ b/libopie2/opiepim/core/otodoaccess.h
@@ -1,50 +1,50 @@
#ifndef OPIE_TODO_ACCESS_H
#define OPIE_TODO_ACCESS_H
#include <qobject.h>
#include <qvaluelist.h>
#include "otodo.h"
#include "otodoaccessbackend.h"
#include "opimaccesstemplate.h"
/**
* OTodoAccess
* the class to get access to
* the todolist
*/
class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
Q_OBJECT
public:
enum SortOrder { Completed = 0,
Priority,
Description,
Deadline };
- enum SortFilter{ ShowOverdue = 0,
- Category =1,
- OnlyOverDue= 2 };
+ enum SortFilter{ Category =1,
+ OnlyOverDue= 2,
+ DoNotShowCompleted =4 };
/**
* if you use 0l
* the default resource will be
* picked up
*/
OTodoAccess( OTodoAccessBackend* = 0l);
~OTodoAccess();
/* our functions here */
/**
* include todos from start to end
* includeNoDates whether or not to include
* events with no dates
*/
List effectiveToDos( const QDate& start,
const QDate& end,
bool includeNoDates = true );
/**
* start
* end date taken from the currentDate()
*/
List effectiveToDos( const QDate& start,