-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 2 | ||||
-rw-r--r-- | libopie/pim/orecordlist.h | 5 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 31 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 3 |
4 files changed, 29 insertions, 12 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 92d7192..a0d8f63 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h @@ -185,10 +185,8 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, // qWarning("find it now %d", uid ); if (m_cache.contains( uid ) ) { - qWarning("m cache contains %d", uid); return m_cache.find( uid ); } T t = m_backEnd->find( uid, ar, current, dir ); - qWarning("found it and cache it now %d", uid); cache( t ); return t; diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 08f5c85..5404910 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h @@ -110,4 +110,5 @@ public: T operator[]( uint i ); + int uidAt(uint i ); // FIXME implemenent remove /* @@ -263,3 +264,7 @@ T ORecordList<T>::operator[]( uint i ) { return m_acc->find( m_ids[i], m_ids, i ); } +template <class T> +int ORecordList<T>::uidAt( uint i ) { + return m_ids[i]; +} #endif diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index a059dab..ea8b3c9 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp @@ -242,5 +242,5 @@ namespace { OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) - : OTodoAccessBackend(), m_dict(15) + : OTodoAccessBackend(), m_dict(15), m_dirty(true) { QString fi = file; @@ -262,6 +262,5 @@ bool OTodoAccessBackendSQL::load(){ OSQLResult res = m_driver->query(&creat ); - update(); - qWarning("loaded %d", m_uids.count() ); + m_dirty = true; return true; } @@ -274,4 +273,7 @@ bool OTodoAccessBackendSQL::save(){ } QArray<int> OTodoAccessBackendSQL::allRecords()const { + if (m_dirty ) + update(); + return m_uids; } @@ -304,5 +306,5 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, /* reverse */ case 1: - for (uint i = cur; i >= 0 && size < 8; i-- ) { + for (uint i = cur; i != 0 && size < 8; i-- ) { search[size] = ints[i]; size++; @@ -343,5 +345,5 @@ bool OTodoAccessBackendSQL::remove( int uid ) { return false; - update(); + m_dirty = true; return true; } @@ -353,5 +355,7 @@ bool OTodoAccessBackendSQL::remove( int uid ) { bool OTodoAccessBackendSQL::replace( const OTodo& t) { remove( t.uid() ); - return add(t); + bool b= add(t); + m_dirty = false; // we changed some stuff but the UID stayed the same + return b; } QArray<int> OTodoAccessBackendSQL::overDue() { @@ -370,4 +374,5 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { + qWarning("sorted %d, %d", asc, sortOrder ); QString query; query = "select uid from todolist WHERE "; @@ -422,6 +427,9 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, break; } - if ( !asc ) + + if ( !asc ) { + qWarning("not ascending!"); query += " DESC"; + } qWarning( query ); @@ -502,5 +510,10 @@ void OTodoAccessBackendSQL::fillDict() { m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); } -void OTodoAccessBackendSQL::update() { +/* + * need to be const so let's fool the + * compiler :( + */ +void OTodoAccessBackendSQL::update()const { + ((OTodoAccessBackendSQL*)this)->m_dirty = false; LoadQuery lo; OSQLResult res = m_driver->query(&lo); @@ -508,5 +521,5 @@ void OTodoAccessBackendSQL::update() { return; - m_uids = uids( res ); + ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); } QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index c1aa2ed..0f6dd2c 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h @@ -33,5 +33,5 @@ public: private: - void update(); + void update()const; void fillDict(); inline bool date( QDate& date, const QString& )const; @@ -44,4 +44,5 @@ private: OSQLDriver* m_driver; QArray<int> m_uids; + bool m_dirty : 1; }; |