Re: [patch] Sorting in TodoAccess SQL backend
Marcin Juszkiewicz <[email protected]>
| Newsgroups | gmane.comp.handhelds.opie.devel |
|---|---|
| Message-ID | <[email protected]> |
That version add filter by category. Is there a tool in OPIE which allow
to choose events/todos/entries from more then one category at once? If
yes then I will need to change code a bit more (now support one category
only).
Also changed default sorting to be by summary but this should be selected
by application, not by backend.
--
JID: hrw-jabber.org
Palmtop: Sharp Zaurus C760
OpenEmbedded/OpenZaurus developer
Hartley's Second Law:
Never sleep with anyone crazier than yourself.
_______________________________________________
http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex
Opie-devel mailing list
[email protected]
https://handhelds.org/mailman/listinfo/opie-devel
libopie-todoaccess-sql-sorted-v2.diff
(text/x-diff, 4 KB)
Index: otodoaccesssql.cpp
===================================================================
RCS file: /cvs/opie/libopie2/opiepim/backend/otodoaccesssql.cpp,v
retrieving revision 1.26
diff -u -r1.26 otodoaccesssql.cpp
--- otodoaccesssql.cpp 28 Dec 2004 14:19:26 -0000 1.26
+++ otodoaccesssql.cpp 2 Dec 2005 19:27:10 -0000
@@ -34,6 +34,7 @@
#include <opie2/osqlmanager.h>
#include <opie2/osqlquery.h>
+#include <opie2/otodoaccess.h>
#include <opie2/otodoaccesssql.h>
#include <opie2/opimstate.h>
#include <opie2/opimnotifymanager.h>
@@ -306,7 +307,7 @@
QString RemoveQuery::query()const {
QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
- qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
+ qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
return qu;
}
@@ -316,8 +317,8 @@
ClearQuery::~ClearQuery() {}
QString ClearQuery::query()const
{
- QString qu = "drop table todolist";
- return qu;
+ QString qu = "drop table todolist";
+ return qu;
}
FindQuery::FindQuery(int uid)
@@ -326,7 +327,7 @@
}
FindQuery::FindQuery(const QArray<int>& ints)
- : OSQLQuery(), m_uids(ints)
+ : OSQLQuery(), m_uids(ints)
{
}
@@ -553,12 +554,12 @@
return uids (m_driver->query(&ef) );
}
-#if 0
+#if 1
/*
*
*/
-QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
- int sortFilter, int cat ) {
+UIDArray OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
+ int sortFilter, const QArray<int>& categories ) const{
odebug << "sorted " << asc << ", " << sortOrder << "" << oendl;
QString query;
query = "select uid from todolist WHERE ";
@@ -570,17 +571,29 @@
*
*/
/* Category */
- if ( sortFilter & OPimTodoAccess::FilterCategory ) {
- QString str;
- if (cat != 0 ) str = QString::number( cat );
- query += " categories like '%" +str+"%' AND";
+ int cat;
+ QString cat_query = " categories LIKE '%";
+ bool check_cats = true;
+
+ for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
+ if(categories[cat_nu] == 0) {
+ check_cats = false;
+ continue;
+ }
+
+ cat_query += QString::number(categories[cat_nu]);
}
+
+ if(check_cats) {
+ query += cat_query + "%' AND ";
+ }
+
/* Show only overdue */
if ( sortFilter & OPimTodoAccess::OnlyOverDue ) {
QDate date = QDate::currentDate();
QString due;
QString base;
- base = QString("DueDate <= '%1-%2-%3' AND completed = 0")
+ base = QString("DueDate != '0000-00-00' AND DueDate <= '%1-%2-%3' AND completed = 0")
.arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
.arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
.arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
@@ -589,9 +602,8 @@
/* not show completed */
if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
query += " completed = 0 AND";
- }else{
- query += " ( completed = 1 OR completed = 0) AND";
}
+
/* strip the end */
query = query.remove( query.length()-3, 3 );
@@ -609,6 +621,7 @@
case OPimTodoAccess::Priority:
query += "priority";
break;
+ default:
case OPimTodoAccess::SortSummary:
query += "summary";
break;
Index: otodoaccesssql.h
===================================================================
RCS file: /cvs/opie/libopie2/opiepim/backend/otodoaccesssql.h,v
retrieving revision 1.14
diff -u -r1.14 otodoaccesssql.h
--- otodoaccesssql.h 28 Dec 2004 14:19:26 -0000 1.14
+++ otodoaccesssql.h 2 Dec 2005 19:27:10 -0000
@@ -67,6 +67,7 @@
QArray<UID> matchRegexp( const QRegExp &r ) const;
void removeAllCompleted();
+ UIDArray sorted( bool, int, int, const QArray<int>& )const;
private:
void update()const;