summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
Unidiff
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp31
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h3
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h2
-rw-r--r--libopie2/opiepim/orecordlist.h5
4 files changed, 29 insertions, 12 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index a059dab..ea8b3c9 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -241,7 +241,7 @@ namespace {
241}; 241};
242 242
243OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) 243OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
244 : OTodoAccessBackend(), m_dict(15) 244 : OTodoAccessBackend(), m_dict(15), m_dirty(true)
245{ 245{
246 QString fi = file; 246 QString fi = file;
247 if ( fi.isEmpty() ) 247 if ( fi.isEmpty() )
@@ -261,8 +261,7 @@ bool OTodoAccessBackendSQL::load(){
261 CreateQuery creat; 261 CreateQuery creat;
262 OSQLResult res = m_driver->query(&creat ); 262 OSQLResult res = m_driver->query(&creat );
263 263
264 update(); 264 m_dirty = true;
265 qWarning("loaded %d", m_uids.count() );
266 return true; 265 return true;
267} 266}
268bool OTodoAccessBackendSQL::reload(){ 267bool OTodoAccessBackendSQL::reload(){
@@ -273,6 +272,9 @@ bool OTodoAccessBackendSQL::save(){
273 return m_driver->close(); 272 return m_driver->close();
274} 273}
275QArray<int> OTodoAccessBackendSQL::allRecords()const { 274QArray<int> OTodoAccessBackendSQL::allRecords()const {
275 if (m_dirty )
276 update();
277
276 return m_uids; 278 return m_uids;
277} 279}
278QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ 280QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
@@ -303,7 +305,7 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
303 break; 305 break;
304 /* reverse */ 306 /* reverse */
305 case 1: 307 case 1:
306 for (uint i = cur; i >= 0 && size < 8; i-- ) { 308 for (uint i = cur; i != 0 && size < 8; i-- ) {
307 search[size] = ints[i]; 309 search[size] = ints[i];
308 size++; 310 size++;
309 } 311 }
@@ -342,7 +344,7 @@ bool OTodoAccessBackendSQL::remove( int uid ) {
342 if ( res.state() == OSQLResult::Failure ) 344 if ( res.state() == OSQLResult::Failure )
343 return false; 345 return false;
344 346
345 update(); 347 m_dirty = true;
346 return true; 348 return true;
347} 349}
348/* 350/*
@@ -352,7 +354,9 @@ bool OTodoAccessBackendSQL::remove( int uid ) {
352 */ 354 */
353bool OTodoAccessBackendSQL::replace( const OTodo& t) { 355bool OTodoAccessBackendSQL::replace( const OTodo& t) {
354 remove( t.uid() ); 356 remove( t.uid() );
355 return add(t); 357 bool b= add(t);
358 m_dirty = false; // we changed some stuff but the UID stayed the same
359 return b;
356} 360}
357QArray<int> OTodoAccessBackendSQL::overDue() { 361QArray<int> OTodoAccessBackendSQL::overDue() {
358 OverDueQuery qu; 362 OverDueQuery qu;
@@ -369,6 +373,7 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s,
369 */ 373 */
370QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 374QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
371 int sortFilter, int cat ) { 375 int sortFilter, int cat ) {
376 qWarning("sorted %d, %d", asc, sortOrder );
372 QString query; 377 QString query;
373 query = "select uid from todolist WHERE "; 378 query = "select uid from todolist WHERE ";
374 379
@@ -421,8 +426,11 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
421 query += "DueDate"; 426 query += "DueDate";
422 break; 427 break;
423 } 428 }
424 if ( !asc ) 429
430 if ( !asc ) {
431 qWarning("not ascending!");
425 query += " DESC"; 432 query += " DESC";
433 }
426 434
427 qWarning( query ); 435 qWarning( query );
428 OSQLRawQuery raw(query ); 436 OSQLRawQuery raw(query );
@@ -501,13 +509,18 @@ void OTodoAccessBackendSQL::fillDict() {
501 m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); 509 m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
502 m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); 510 m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
503} 511}
504void OTodoAccessBackendSQL::update() { 512/*
513 * need to be const so let's fool the
514 * compiler :(
515 */
516void OTodoAccessBackendSQL::update()const {
517 ((OTodoAccessBackendSQL*)this)->m_dirty = false;
505 LoadQuery lo; 518 LoadQuery lo;
506 OSQLResult res = m_driver->query(&lo); 519 OSQLResult res = m_driver->query(&lo);
507 if ( res.state() != OSQLResult::Success ) 520 if ( res.state() != OSQLResult::Success )
508 return; 521 return;
509 522
510 m_uids = uids( res ); 523 ((OTodoAccessBackendSQL*)this)->m_uids = uids( res );
511} 524}
512QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 525QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
513 526
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index c1aa2ed..0f6dd2c 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -32,7 +32,7 @@ public:
32 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); 32 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
33 33
34private: 34private:
35 void update(); 35 void update()const;
36 void fillDict(); 36 void fillDict();
37 inline bool date( QDate& date, const QString& )const; 37 inline bool date( QDate& date, const QString& )const;
38 inline OTodo todo( const OSQLResult& )const; 38 inline OTodo todo( const OSQLResult& )const;
@@ -43,6 +43,7 @@ private:
43 QAsciiDict<int> m_dict; 43 QAsciiDict<int> m_dict;
44 OSQLDriver* m_driver; 44 OSQLDriver* m_driver;
45 QArray<int> m_uids; 45 QArray<int> m_uids;
46 bool m_dirty : 1;
46}; 47};
47 48
48 49
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 92d7192..a0d8f63 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -184,12 +184,10 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
184 */ 184 */
185 // qWarning("find it now %d", uid ); 185 // qWarning("find it now %d", uid );
186 if (m_cache.contains( uid ) ) { 186 if (m_cache.contains( uid ) ) {
187 qWarning("m cache contains %d", uid);
188 return m_cache.find( uid ); 187 return m_cache.find( uid );
189 } 188 }
190 189
191 T t = m_backEnd->find( uid, ar, current, dir ); 190 T t = m_backEnd->find( uid, ar, current, dir );
192 qWarning("found it and cache it now %d", uid);
193 cache( t ); 191 cache( t );
194 return t; 192 return t;
195} 193}
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h
index 08f5c85..5404910 100644
--- a/libopie2/opiepim/orecordlist.h
+++ b/libopie2/opiepim/orecordlist.h
@@ -109,6 +109,7 @@ public:
109 uint count()const; 109 uint count()const;
110 110
111 T operator[]( uint i ); 111 T operator[]( uint i );
112 int uidAt(uint i );
112 // FIXME implemenent remove 113 // FIXME implemenent remove
113 /* 114 /*
114 ConstIterator begin()const; 115 ConstIterator begin()const;
@@ -262,4 +263,8 @@ T ORecordList<T>::operator[]( uint i ) {
262 /* forward */ 263 /* forward */
263 return m_acc->find( m_ids[i], m_ids, i ); 264 return m_acc->find( m_ids[i], m_ids, i );
264} 265}
266template <class T>
267int ORecordList<T>::uidAt( uint i ) {
268 return m_ids[i];
269}
265#endif 270#endif