summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/opimcache.h4
-rw-r--r--libopie/pim/otodoaccesssql.cpp81
-rw-r--r--libopie/pim/otodoaccesssql.h3
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp81
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h3
-rw-r--r--libopie2/opiepim/core/opimcache.h4
6 files changed, 162 insertions, 14 deletions
diff --git a/libopie/pim/opimcache.h b/libopie/pim/opimcache.h
index 067f6e7..839550c 100644
--- a/libopie/pim/opimcache.h
+++ b/libopie/pim/opimcache.h
@@ -52,25 +52,27 @@ OPimCacheItem<T>::~OPimCacheItem() {
52 52
53} 53}
54template <class T> 54template <class T>
55T OPimCacheItem<T>::record()const { 55T OPimCacheItem<T>::record()const {
56 return m_t; 56 return m_t;
57} 57}
58template <class T> 58template <class T>
59void OPimCacheItem<T>::setRecord( const T& t ) { 59void OPimCacheItem<T>::setRecord( const T& t ) {
60 m_t = t; 60 m_t = t;
61} 61}
62// Cache 62// Cache
63template <class T> 63template <class T>
64OPimCache<T>::OPimCache() { 64OPimCache<T>::OPimCache()
65 : m_cache(100, 53 )
66{
65 m_cache.setAutoDelete( TRUE ); 67 m_cache.setAutoDelete( TRUE );
66} 68}
67template <class T> 69template <class T>
68OPimCache<T>::~OPimCache() { 70OPimCache<T>::~OPimCache() {
69 71
70} 72}
71template <class T> 73template <class T>
72bool OPimCache<T>::contains(int uid )const { 74bool OPimCache<T>::contains(int uid )const {
73 Item* it = m_cache.find( uid, FALSE ); 75 Item* it = m_cache.find( uid, FALSE );
74 if (!it) 76 if (!it)
75 return false; 77 return false;
76 return true; 78 return true;
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp
index 8add9f7..a059dab 100644
--- a/libopie/pim/otodoaccesssql.cpp
+++ b/libopie/pim/otodoaccesssql.cpp
@@ -72,27 +72,31 @@ namespace {
72 ClearQuery(); 72 ClearQuery();
73 ~ClearQuery(); 73 ~ClearQuery();
74 QString query()const; 74 QString query()const;
75 75
76 }; 76 };
77 77
78 /** 78 /**
79 * a find query 79 * a find query
80 */ 80 */
81 class FindQuery : public OSQLQuery { 81 class FindQuery : public OSQLQuery {
82 public: 82 public:
83 FindQuery(int uid); 83 FindQuery(int uid);
84 FindQuery(const QArray<int>& );
84 ~FindQuery(); 85 ~FindQuery();
85 QString query()const; 86 QString query()const;
86 private: 87 private:
88 QString single()const;
89 QString multi()const;
90 QArray<int> m_uids;
87 int m_uid; 91 int m_uid;
88 }; 92 };
89 93
90 /** 94 /**
91 * overdue query 95 * overdue query
92 */ 96 */
93 class OverDueQuery : public OSQLQuery { 97 class OverDueQuery : public OSQLQuery {
94 public: 98 public:
95 OverDueQuery(); 99 OverDueQuery();
96 ~OverDueQuery(); 100 ~OverDueQuery();
97 QString query()const; 101 QString query()const;
98 }; 102 };
@@ -129,24 +133,25 @@ namespace {
129 } 133 }
130 134
131 InsertQuery::InsertQuery( const OTodo& todo ) 135 InsertQuery::InsertQuery( const OTodo& todo )
132 : OSQLQuery(), m_todo( todo ) { 136 : OSQLQuery(), m_todo( todo ) {
133 } 137 }
134 InsertQuery::~InsertQuery() { 138 InsertQuery::~InsertQuery() {
135 } 139 }
136 /* 140 /*
137 * converts from a OTodo to a query 141 * converts from a OTodo to a query
138 * we leave out X-Ref + Alarms 142 * we leave out X-Ref + Alarms
139 */ 143 */
140 QString InsertQuery::query()const{ 144 QString InsertQuery::query()const{
145
141 int year, month, day; 146 int year, month, day;
142 year = month = day = 0; 147 year = month = day = 0;
143 if (m_todo.hasDueDate() ) { 148 if (m_todo.hasDueDate() ) {
144 QDate date = m_todo.dueDate(); 149 QDate date = m_todo.dueDate();
145 year = date.year(); 150 year = date.year();
146 month = date.month(); 151 month = date.month();
147 day = date.day(); 152 day = date.day();
148 } 153 }
149 QString qu; 154 QString qu;
150 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; 155 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',";
151 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; 156 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ",";
152 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; 157 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',";
@@ -166,31 +171,49 @@ namespace {
166 171
167 172
168 ClearQuery::ClearQuery() 173 ClearQuery::ClearQuery()
169 : OSQLQuery() {} 174 : OSQLQuery() {}
170 ClearQuery::~ClearQuery() {} 175 ClearQuery::~ClearQuery() {}
171 QString ClearQuery::query()const { 176 QString ClearQuery::query()const {
172 QString qu = "drop table todolist"; 177 QString qu = "drop table todolist";
173 return qu; 178 return qu;
174 } 179 }
175 FindQuery::FindQuery(int uid) 180 FindQuery::FindQuery(int uid)
176 : OSQLQuery(), m_uid(uid ) { 181 : OSQLQuery(), m_uid(uid ) {
177 } 182 }
183 FindQuery::FindQuery(const QArray<int>& ints)
184 : OSQLQuery(), m_uids(ints){
185 }
178 FindQuery::~FindQuery() { 186 FindQuery::~FindQuery() {
179 } 187 }
180 QString FindQuery::query()const{ 188 QString FindQuery::query()const{
189 if (m_uids.count() == 0 )
190 return single();
191 else
192 return multi();
193 }
194 QString FindQuery::single()const{
181 QString qu = "select uid, categories, completed, progress, summary, "; 195 QString qu = "select uid, categories, completed, progress, summary, ";
182 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); 196 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid);
183 return qu; 197 return qu;
184 } 198 }
199 QString FindQuery::multi()const {
200 QString qu = "select uid, categories, completed, progress, summary, ";
201 qu += "DueDate, priority, description from todolist where ";
202 for (uint i = 0; i < m_uids.count(); i++ ) {
203 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
204 }
205 qu.remove( qu.length()-2, 2 );
206 return qu;
207 }
185 208
186 OverDueQuery::OverDueQuery(): OSQLQuery() {} 209 OverDueQuery::OverDueQuery(): OSQLQuery() {}
187 OverDueQuery::~OverDueQuery() {} 210 OverDueQuery::~OverDueQuery() {}
188 QString OverDueQuery::query()const { 211 QString OverDueQuery::query()const {
189 QDate date = QDate::currentDate(); 212 QDate date = QDate::currentDate();
190 QString str; 213 QString str;
191 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 214 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
192 215
193 return str; 216 return str;
194 } 217 }
195 218
196 219
@@ -252,24 +275,57 @@ bool OTodoAccessBackendSQL::save(){
252QArray<int> OTodoAccessBackendSQL::allRecords()const { 275QArray<int> OTodoAccessBackendSQL::allRecords()const {
253 return m_uids; 276 return m_uids;
254} 277}
255QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ 278QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
256 QArray<int> ints(0); 279 QArray<int> ints(0);
257 return ints; 280 return ints;
258} 281}
259OTodo OTodoAccessBackendSQL::find(int uid ) const{ 282OTodo OTodoAccessBackendSQL::find(int uid ) const{
260 FindQuery query( uid ); 283 FindQuery query( uid );
261 return todo( m_driver->query(&query) ); 284 return todo( m_driver->query(&query) );
262 285
263} 286}
287OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
288 uint cur, Frontend::CacheDirection dir ) const{
289 qWarning("searching for %d", uid );
290 QArray<int> search( 8 );
291 uint size =0;
292 OTodo to;
293
294 // we try to cache 8 items
295 switch( dir ) {
296 /* forward */
297 case 0:
298 for (uint i = cur; i < ints.count() && size < 8; i++ ) {
299 qWarning("size %d %d", size, ints[i] );
300 search[size] = ints[i];
301 size++;
302 }
303 break;
304 /* reverse */
305 case 1:
306 for (uint i = cur; i >= 0 && size < 8; i-- ) {
307 search[size] = ints[i];
308 size++;
309 }
310 break;
311 }
312 search.resize( size );
313 FindQuery query( search );
314 OSQLResult res = m_driver->query( &query );
315 if ( res.state() != OSQLResult::Success )
316 return to;
317
318 return todo( res );
319}
264void OTodoAccessBackendSQL::clear() { 320void OTodoAccessBackendSQL::clear() {
265 ClearQuery cle; 321 ClearQuery cle;
266 OSQLResult res = m_driver->query( &cle ); 322 OSQLResult res = m_driver->query( &cle );
267 CreateQuery qu; 323 CreateQuery qu;
268 res = m_driver->query(&qu); 324 res = m_driver->query(&qu);
269} 325}
270bool OTodoAccessBackendSQL::add( const OTodo& t) { 326bool OTodoAccessBackendSQL::add( const OTodo& t) {
271 InsertQuery ins( t ); 327 InsertQuery ins( t );
272 OSQLResult res = m_driver->query( &ins ); 328 OSQLResult res = m_driver->query( &ins );
273 329
274 if ( res.state() == OSQLResult::Failure ) 330 if ( res.state() == OSQLResult::Failure )
275 return false; 331 return false;
@@ -384,32 +440,45 @@ bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
384 da.setYMD( year, month, day ); 440 da.setYMD( year, month, day );
385 return true; 441 return true;
386 } 442 }
387} 443}
388OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ 444OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
389 if ( res.state() == OSQLResult::Failure ) { 445 if ( res.state() == OSQLResult::Failure ) {
390 OTodo to; 446 OTodo to;
391 return to; 447 return to;
392 } 448 }
393 449
394 OSQLResultItem::ValueList list = res.results(); 450 OSQLResultItem::ValueList list = res.results();
395 OSQLResultItem::ValueList::Iterator it = list.begin(); 451 OSQLResultItem::ValueList::Iterator it = list.begin();
396 452 qWarning("todo1");
453 OTodo to = todo( (*it) );
454 cache( to );
455 ++it;
456
457 for ( ; it != list.end(); ++it ) {
458 qWarning("caching");
459 cache( todo( (*it) ) );
460 }
461 return to;
462}
463OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
464 qWarning("todo");
397 bool has = false; QDate da = QDate::currentDate(); 465 bool has = false; QDate da = QDate::currentDate();
398 has = date( da, (*it).data("DueDate") ); 466 has = date( da, item.data("DueDate") );
399 QStringList cats = QStringList::split(";", (*it).data("categories") ); 467 QStringList cats = QStringList::split(";", item.data("categories") );
400 468
401 OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), 469 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
402 cats, (*it).data("summary"), (*it).data("description"), 470 cats, item.data("summary"), item.data("description"),
403 (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); 471 item.data("progress").toUShort(), has, da,
472 item.data("uid").toInt() );
404 return to; 473 return to;
405} 474}
406OTodo OTodoAccessBackendSQL::todo( int uid )const { 475OTodo OTodoAccessBackendSQL::todo( int uid )const {
407 FindQuery find( uid ); 476 FindQuery find( uid );
408 return todo( m_driver->query(&find) ); 477 return todo( m_driver->query(&find) );
409} 478}
410/* 479/*
411 * update the dict 480 * update the dict
412 */ 481 */
413void OTodoAccessBackendSQL::fillDict() { 482void OTodoAccessBackendSQL::fillDict() {
414 /* initialize dict */ 483 /* initialize dict */
415 /* 484 /*
diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h
index 6c5f50a..c1aa2ed 100644
--- a/libopie/pim/otodoaccesssql.h
+++ b/libopie/pim/otodoaccesssql.h
@@ -1,46 +1,49 @@
1#ifndef OPIE_PIM_ACCESS_SQL_H 1#ifndef OPIE_PIM_ACCESS_SQL_H
2#define OPIE_PIM_ACCESS_SQL_H 2#define OPIE_PIM_ACCESS_SQL_H
3 3
4#include <qasciidict.h> 4#include <qasciidict.h>
5 5
6#include "otodoaccessbackend.h" 6#include "otodoaccessbackend.h"
7 7
8class OSQLDriver; 8class OSQLDriver;
9class OSQLResult; 9class OSQLResult;
10class OSQLResultItem;
10class OTodoAccessBackendSQL : public OTodoAccessBackend { 11class OTodoAccessBackendSQL : public OTodoAccessBackend {
11public: 12public:
12 OTodoAccessBackendSQL( const QString& file ); 13 OTodoAccessBackendSQL( const QString& file );
13 ~OTodoAccessBackendSQL(); 14 ~OTodoAccessBackendSQL();
14 15
15 bool load(); 16 bool load();
16 bool reload(); 17 bool reload();
17 bool save(); 18 bool save();
18 QArray<int> allRecords()const; 19 QArray<int> allRecords()const;
19 20
20 QArray<int> queryByExample( const OTodo& t, int sort ); 21 QArray<int> queryByExample( const OTodo& t, int sort );
21 OTodo find(int uid)const; 22 OTodo find(int uid)const;
23 OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
22 void clear(); 24 void clear();
23 bool add( const OTodo& t ); 25 bool add( const OTodo& t );
24 bool remove( int uid ); 26 bool remove( int uid );
25 bool replace( const OTodo& t ); 27 bool replace( const OTodo& t );
26 28
27 QArray<int> overDue(); 29 QArray<int> overDue();
28 QArray<int> effectiveToDos( const QDate& start, 30 QArray<int> effectiveToDos( const QDate& start,
29 const QDate& end, bool includeNoDates ); 31 const QDate& end, bool includeNoDates );
30 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); 32 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
31 33
32private: 34private:
33 void update(); 35 void update();
34 void fillDict(); 36 void fillDict();
35 inline bool date( QDate& date, const QString& )const; 37 inline bool date( QDate& date, const QString& )const;
36 inline OTodo todo( const OSQLResult& )const; 38 inline OTodo todo( const OSQLResult& )const;
39 inline OTodo todo( OSQLResultItem& )const;
37 inline QArray<int> uids( const OSQLResult& )const; 40 inline QArray<int> uids( const OSQLResult& )const;
38 OTodo todo( int uid )const; 41 OTodo todo( int uid )const;
39 42
40 QAsciiDict<int> m_dict; 43 QAsciiDict<int> m_dict;
41 OSQLDriver* m_driver; 44 OSQLDriver* m_driver;
42 QArray<int> m_uids; 45 QArray<int> m_uids;
43}; 46};
44 47
45 48
46#endif 49#endif
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 8add9f7..a059dab 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -72,27 +72,31 @@ namespace {
72 ClearQuery(); 72 ClearQuery();
73 ~ClearQuery(); 73 ~ClearQuery();
74 QString query()const; 74 QString query()const;
75 75
76 }; 76 };
77 77
78 /** 78 /**
79 * a find query 79 * a find query
80 */ 80 */
81 class FindQuery : public OSQLQuery { 81 class FindQuery : public OSQLQuery {
82 public: 82 public:
83 FindQuery(int uid); 83 FindQuery(int uid);
84 FindQuery(const QArray<int>& );
84 ~FindQuery(); 85 ~FindQuery();
85 QString query()const; 86 QString query()const;
86 private: 87 private:
88 QString single()const;
89 QString multi()const;
90 QArray<int> m_uids;
87 int m_uid; 91 int m_uid;
88 }; 92 };
89 93
90 /** 94 /**
91 * overdue query 95 * overdue query
92 */ 96 */
93 class OverDueQuery : public OSQLQuery { 97 class OverDueQuery : public OSQLQuery {
94 public: 98 public:
95 OverDueQuery(); 99 OverDueQuery();
96 ~OverDueQuery(); 100 ~OverDueQuery();
97 QString query()const; 101 QString query()const;
98 }; 102 };
@@ -129,24 +133,25 @@ namespace {
129 } 133 }
130 134
131 InsertQuery::InsertQuery( const OTodo& todo ) 135 InsertQuery::InsertQuery( const OTodo& todo )
132 : OSQLQuery(), m_todo( todo ) { 136 : OSQLQuery(), m_todo( todo ) {
133 } 137 }
134 InsertQuery::~InsertQuery() { 138 InsertQuery::~InsertQuery() {
135 } 139 }
136 /* 140 /*
137 * converts from a OTodo to a query 141 * converts from a OTodo to a query
138 * we leave out X-Ref + Alarms 142 * we leave out X-Ref + Alarms
139 */ 143 */
140 QString InsertQuery::query()const{ 144 QString InsertQuery::query()const{
145
141 int year, month, day; 146 int year, month, day;
142 year = month = day = 0; 147 year = month = day = 0;
143 if (m_todo.hasDueDate() ) { 148 if (m_todo.hasDueDate() ) {
144 QDate date = m_todo.dueDate(); 149 QDate date = m_todo.dueDate();
145 year = date.year(); 150 year = date.year();
146 month = date.month(); 151 month = date.month();
147 day = date.day(); 152 day = date.day();
148 } 153 }
149 QString qu; 154 QString qu;
150 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; 155 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',";
151 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; 156 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ",";
152 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; 157 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',";
@@ -166,31 +171,49 @@ namespace {
166 171
167 172
168 ClearQuery::ClearQuery() 173 ClearQuery::ClearQuery()
169 : OSQLQuery() {} 174 : OSQLQuery() {}
170 ClearQuery::~ClearQuery() {} 175 ClearQuery::~ClearQuery() {}
171 QString ClearQuery::query()const { 176 QString ClearQuery::query()const {
172 QString qu = "drop table todolist"; 177 QString qu = "drop table todolist";
173 return qu; 178 return qu;
174 } 179 }
175 FindQuery::FindQuery(int uid) 180 FindQuery::FindQuery(int uid)
176 : OSQLQuery(), m_uid(uid ) { 181 : OSQLQuery(), m_uid(uid ) {
177 } 182 }
183 FindQuery::FindQuery(const QArray<int>& ints)
184 : OSQLQuery(), m_uids(ints){
185 }
178 FindQuery::~FindQuery() { 186 FindQuery::~FindQuery() {
179 } 187 }
180 QString FindQuery::query()const{ 188 QString FindQuery::query()const{
189 if (m_uids.count() == 0 )
190 return single();
191 else
192 return multi();
193 }
194 QString FindQuery::single()const{
181 QString qu = "select uid, categories, completed, progress, summary, "; 195 QString qu = "select uid, categories, completed, progress, summary, ";
182 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); 196 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid);
183 return qu; 197 return qu;
184 } 198 }
199 QString FindQuery::multi()const {
200 QString qu = "select uid, categories, completed, progress, summary, ";
201 qu += "DueDate, priority, description from todolist where ";
202 for (uint i = 0; i < m_uids.count(); i++ ) {
203 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
204 }
205 qu.remove( qu.length()-2, 2 );
206 return qu;
207 }
185 208
186 OverDueQuery::OverDueQuery(): OSQLQuery() {} 209 OverDueQuery::OverDueQuery(): OSQLQuery() {}
187 OverDueQuery::~OverDueQuery() {} 210 OverDueQuery::~OverDueQuery() {}
188 QString OverDueQuery::query()const { 211 QString OverDueQuery::query()const {
189 QDate date = QDate::currentDate(); 212 QDate date = QDate::currentDate();
190 QString str; 213 QString str;
191 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 214 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
192 215
193 return str; 216 return str;
194 } 217 }
195 218
196 219
@@ -252,24 +275,57 @@ bool OTodoAccessBackendSQL::save(){
252QArray<int> OTodoAccessBackendSQL::allRecords()const { 275QArray<int> OTodoAccessBackendSQL::allRecords()const {
253 return m_uids; 276 return m_uids;
254} 277}
255QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ 278QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
256 QArray<int> ints(0); 279 QArray<int> ints(0);
257 return ints; 280 return ints;
258} 281}
259OTodo OTodoAccessBackendSQL::find(int uid ) const{ 282OTodo OTodoAccessBackendSQL::find(int uid ) const{
260 FindQuery query( uid ); 283 FindQuery query( uid );
261 return todo( m_driver->query(&query) ); 284 return todo( m_driver->query(&query) );
262 285
263} 286}
287OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
288 uint cur, Frontend::CacheDirection dir ) const{
289 qWarning("searching for %d", uid );
290 QArray<int> search( 8 );
291 uint size =0;
292 OTodo to;
293
294 // we try to cache 8 items
295 switch( dir ) {
296 /* forward */
297 case 0:
298 for (uint i = cur; i < ints.count() && size < 8; i++ ) {
299 qWarning("size %d %d", size, ints[i] );
300 search[size] = ints[i];
301 size++;
302 }
303 break;
304 /* reverse */
305 case 1:
306 for (uint i = cur; i >= 0 && size < 8; i-- ) {
307 search[size] = ints[i];
308 size++;
309 }
310 break;
311 }
312 search.resize( size );
313 FindQuery query( search );
314 OSQLResult res = m_driver->query( &query );
315 if ( res.state() != OSQLResult::Success )
316 return to;
317
318 return todo( res );
319}
264void OTodoAccessBackendSQL::clear() { 320void OTodoAccessBackendSQL::clear() {
265 ClearQuery cle; 321 ClearQuery cle;
266 OSQLResult res = m_driver->query( &cle ); 322 OSQLResult res = m_driver->query( &cle );
267 CreateQuery qu; 323 CreateQuery qu;
268 res = m_driver->query(&qu); 324 res = m_driver->query(&qu);
269} 325}
270bool OTodoAccessBackendSQL::add( const OTodo& t) { 326bool OTodoAccessBackendSQL::add( const OTodo& t) {
271 InsertQuery ins( t ); 327 InsertQuery ins( t );
272 OSQLResult res = m_driver->query( &ins ); 328 OSQLResult res = m_driver->query( &ins );
273 329
274 if ( res.state() == OSQLResult::Failure ) 330 if ( res.state() == OSQLResult::Failure )
275 return false; 331 return false;
@@ -384,32 +440,45 @@ bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
384 da.setYMD( year, month, day ); 440 da.setYMD( year, month, day );
385 return true; 441 return true;
386 } 442 }
387} 443}
388OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ 444OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
389 if ( res.state() == OSQLResult::Failure ) { 445 if ( res.state() == OSQLResult::Failure ) {
390 OTodo to; 446 OTodo to;
391 return to; 447 return to;
392 } 448 }
393 449
394 OSQLResultItem::ValueList list = res.results(); 450 OSQLResultItem::ValueList list = res.results();
395 OSQLResultItem::ValueList::Iterator it = list.begin(); 451 OSQLResultItem::ValueList::Iterator it = list.begin();
396 452 qWarning("todo1");
453 OTodo to = todo( (*it) );
454 cache( to );
455 ++it;
456
457 for ( ; it != list.end(); ++it ) {
458 qWarning("caching");
459 cache( todo( (*it) ) );
460 }
461 return to;
462}
463OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
464 qWarning("todo");
397 bool has = false; QDate da = QDate::currentDate(); 465 bool has = false; QDate da = QDate::currentDate();
398 has = date( da, (*it).data("DueDate") ); 466 has = date( da, item.data("DueDate") );
399 QStringList cats = QStringList::split(";", (*it).data("categories") ); 467 QStringList cats = QStringList::split(";", item.data("categories") );
400 468
401 OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), 469 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
402 cats, (*it).data("summary"), (*it).data("description"), 470 cats, item.data("summary"), item.data("description"),
403 (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); 471 item.data("progress").toUShort(), has, da,
472 item.data("uid").toInt() );
404 return to; 473 return to;
405} 474}
406OTodo OTodoAccessBackendSQL::todo( int uid )const { 475OTodo OTodoAccessBackendSQL::todo( int uid )const {
407 FindQuery find( uid ); 476 FindQuery find( uid );
408 return todo( m_driver->query(&find) ); 477 return todo( m_driver->query(&find) );
409} 478}
410/* 479/*
411 * update the dict 480 * update the dict
412 */ 481 */
413void OTodoAccessBackendSQL::fillDict() { 482void OTodoAccessBackendSQL::fillDict() {
414 /* initialize dict */ 483 /* initialize dict */
415 /* 484 /*
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 6c5f50a..c1aa2ed 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -1,46 +1,49 @@
1#ifndef OPIE_PIM_ACCESS_SQL_H 1#ifndef OPIE_PIM_ACCESS_SQL_H
2#define OPIE_PIM_ACCESS_SQL_H 2#define OPIE_PIM_ACCESS_SQL_H
3 3
4#include <qasciidict.h> 4#include <qasciidict.h>
5 5
6#include "otodoaccessbackend.h" 6#include "otodoaccessbackend.h"
7 7
8class OSQLDriver; 8class OSQLDriver;
9class OSQLResult; 9class OSQLResult;
10class OSQLResultItem;
10class OTodoAccessBackendSQL : public OTodoAccessBackend { 11class OTodoAccessBackendSQL : public OTodoAccessBackend {
11public: 12public:
12 OTodoAccessBackendSQL( const QString& file ); 13 OTodoAccessBackendSQL( const QString& file );
13 ~OTodoAccessBackendSQL(); 14 ~OTodoAccessBackendSQL();
14 15
15 bool load(); 16 bool load();
16 bool reload(); 17 bool reload();
17 bool save(); 18 bool save();
18 QArray<int> allRecords()const; 19 QArray<int> allRecords()const;
19 20
20 QArray<int> queryByExample( const OTodo& t, int sort ); 21 QArray<int> queryByExample( const OTodo& t, int sort );
21 OTodo find(int uid)const; 22 OTodo find(int uid)const;
23 OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
22 void clear(); 24 void clear();
23 bool add( const OTodo& t ); 25 bool add( const OTodo& t );
24 bool remove( int uid ); 26 bool remove( int uid );
25 bool replace( const OTodo& t ); 27 bool replace( const OTodo& t );
26 28
27 QArray<int> overDue(); 29 QArray<int> overDue();
28 QArray<int> effectiveToDos( const QDate& start, 30 QArray<int> effectiveToDos( const QDate& start,
29 const QDate& end, bool includeNoDates ); 31 const QDate& end, bool includeNoDates );
30 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); 32 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
31 33
32private: 34private:
33 void update(); 35 void update();
34 void fillDict(); 36 void fillDict();
35 inline bool date( QDate& date, const QString& )const; 37 inline bool date( QDate& date, const QString& )const;
36 inline OTodo todo( const OSQLResult& )const; 38 inline OTodo todo( const OSQLResult& )const;
39 inline OTodo todo( OSQLResultItem& )const;
37 inline QArray<int> uids( const OSQLResult& )const; 40 inline QArray<int> uids( const OSQLResult& )const;
38 OTodo todo( int uid )const; 41 OTodo todo( int uid )const;
39 42
40 QAsciiDict<int> m_dict; 43 QAsciiDict<int> m_dict;
41 OSQLDriver* m_driver; 44 OSQLDriver* m_driver;
42 QArray<int> m_uids; 45 QArray<int> m_uids;
43}; 46};
44 47
45 48
46#endif 49#endif
diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h
index 067f6e7..839550c 100644
--- a/libopie2/opiepim/core/opimcache.h
+++ b/libopie2/opiepim/core/opimcache.h
@@ -52,25 +52,27 @@ OPimCacheItem<T>::~OPimCacheItem() {
52 52
53} 53}
54template <class T> 54template <class T>
55T OPimCacheItem<T>::record()const { 55T OPimCacheItem<T>::record()const {
56 return m_t; 56 return m_t;
57} 57}
58template <class T> 58template <class T>
59void OPimCacheItem<T>::setRecord( const T& t ) { 59void OPimCacheItem<T>::setRecord( const T& t ) {
60 m_t = t; 60 m_t = t;
61} 61}
62// Cache 62// Cache
63template <class T> 63template <class T>
64OPimCache<T>::OPimCache() { 64OPimCache<T>::OPimCache()
65 : m_cache(100, 53 )
66{
65 m_cache.setAutoDelete( TRUE ); 67 m_cache.setAutoDelete( TRUE );
66} 68}
67template <class T> 69template <class T>
68OPimCache<T>::~OPimCache() { 70OPimCache<T>::~OPimCache() {
69 71
70} 72}
71template <class T> 73template <class T>
72bool OPimCache<T>::contains(int uid )const { 74bool OPimCache<T>::contains(int uid )const {
73 Item* it = m_cache.find( uid, FALSE ); 75 Item* it = m_cache.find( uid, FALSE );
74 if (!it) 76 if (!it)
75 return false; 77 return false;
76 return true; 78 return true;