summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/opimaccesstemplate.h2
-rw-r--r--libopie/pim/orecordlist.h5
-rw-r--r--libopie/pim/otodoaccesssql.cpp31
-rw-r--r--libopie/pim/otodoaccesssql.h3
-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
8 files changed, 58 insertions, 24 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
@@ -175,30 +175,28 @@ T OPimAccessTemplate<T>::find( int uid ) const{
return t;
}
template <class T>
T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
uint current, CacheDirection dir )const {
/*
* better do T.isEmpty()
* after a find this way we would
* avoid two finds in QCache...
*/
// 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;
}
template <class T>
void OPimAccessTemplate<T>::clear() {
invalidateCache();
m_backEnd->clear();
}
template <class T>
bool OPimAccessTemplate<T>::add( const T& t ) {
cache( t );
return m_backEnd->add( 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
@@ -100,24 +100,25 @@ public:
/**
* the end
*/
Iterator end();
/**
* the number of items in the list
*/
uint count()const;
T operator[]( uint i );
+ int uidAt(uint i );
// FIXME implemenent remove
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
private:
QArray<int> m_ids;
const Base* m_acc;
};
/* ok now implement it */
template <class T>
@@ -253,13 +254,17 @@ ORecordList<T>::Iterator ORecordList<T>::end() {
return it;
}
template <class T>
uint ORecordList<T>::count()const {
return m_ids.count();
}
template <class T>
T ORecordList<T>::operator[]( uint i ) {
/* forward */
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
@@ -232,56 +232,58 @@ namespace {
}
QString EffQuery::out()const {
QString str;
str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
.arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
.arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
return str;
}
};
OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
- : OTodoAccessBackend(), m_dict(15)
+ : OTodoAccessBackend(), m_dict(15), m_dirty(true)
{
QString fi = file;
if ( fi.isEmpty() )
fi = Global::applicationFileName( "todolist", "todolist.db" );
OSQLManager man;
m_driver = man.standard();
m_driver->setUrl(fi);
fillDict();
}
OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
}
bool OTodoAccessBackendSQL::load(){
if (!m_driver->open() )
return false;
CreateQuery creat;
OSQLResult res = m_driver->query(&creat );
- update();
- qWarning("loaded %d", m_uids.count() );
+ m_dirty = true;
return true;
}
bool OTodoAccessBackendSQL::reload(){
return load();
}
bool OTodoAccessBackendSQL::save(){
return m_driver->close();
}
QArray<int> OTodoAccessBackendSQL::allRecords()const {
+ if (m_dirty )
+ update();
+
return m_uids;
}
QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
QArray<int> ints(0);
return ints;
}
OTodo OTodoAccessBackendSQL::find(int uid ) const{
FindQuery query( uid );
return todo( m_driver->query(&query) );
}
OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
@@ -294,25 +296,25 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
// we try to cache 8 items
switch( dir ) {
/* forward */
case 0:
for (uint i = cur; i < ints.count() && size < 8; i++ ) {
qWarning("size %d %d", size, ints[i] );
search[size] = ints[i];
size++;
}
break;
/* 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++;
}
break;
}
search.resize( size );
FindQuery query( search );
OSQLResult res = m_driver->query( &query );
if ( res.state() != OSQLResult::Success )
return to;
return todo( res );
@@ -333,51 +335,54 @@ bool OTodoAccessBackendSQL::add( const OTodo& t) {
m_uids.resize( c+1 );
m_uids[c] = t.uid();
return true;
}
bool OTodoAccessBackendSQL::remove( int uid ) {
RemoveQuery rem( uid );
OSQLResult res = m_driver->query(&rem );
if ( res.state() == OSQLResult::Failure )
return false;
- update();
+ m_dirty = true;
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);
+ bool b= add(t);
+ m_dirty = false; // we changed some stuff but the UID stayed the same
+ return b;
}
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 ) {
+ qWarning("sorted %d, %d", asc, sortOrder );
QString query;
query = "select uid from todolist WHERE ";
/*
* Sort Filter stuff
* not that straight forward
*
*/
/* Category */
if ( sortFilter & 1 ) {
QString str;
if (cat != 0 ) str = QString::number( cat );
@@ -412,26 +417,29 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
query += "completed";
break;
case 1:
query += "priority";
break;
case 2:
query += "description";
break;
case 3:
query += "DueDate";
break;
}
- if ( !asc )
+
+ if ( !asc ) {
+ qWarning("not ascending!");
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();
@@ -492,31 +500,36 @@ void OTodoAccessBackendSQL::fillDict() {
m_dict.insert("Description" , new int(OTodo::Description) );
m_dict.insert("Summary" , new int(OTodo::Summary) );
m_dict.insert("Priority" , new int(OTodo::Priority) );
m_dict.insert("DateDay" , new int(OTodo::DateDay) );
m_dict.insert("DateMonth" , new int(OTodo::DateMonth) );
m_dict.insert("DateYear" , new int(OTodo::DateYear) );
m_dict.insert("Progress" , new int(OTodo::Progress) );
m_dict.insert("Completed", new int(OTodo::Completed) );
m_dict.insert("CrossReference", new int(OTodo::CrossReference) );
m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
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);
if ( res.state() != OSQLResult::Success )
return;
- m_uids = uids( res );
+ ((OTodoAccessBackendSQL*)this)->m_uids = uids( res );
}
QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
qWarning(" count = %d", list.count() );
int i = 0;
for (it = list.begin(); it != list.end(); ++it ) {
ints[i] = (*it).data("uid").toInt();
i++;
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
@@ -23,27 +23,28 @@ public:
OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )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 update()const;
void fillDict();
inline bool date( QDate& date, const QString& )const;
inline OTodo todo( const OSQLResult& )const;
inline OTodo todo( OSQLResultItem& )const;
inline QArray<int> uids( const OSQLResult& )const;
OTodo todo( int uid )const;
QAsciiDict<int> m_dict;
OSQLDriver* m_driver;
QArray<int> m_uids;
+ bool m_dirty : 1;
};
#endif
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
@@ -232,56 +232,58 @@ namespace {
}
QString EffQuery::out()const {
QString str;
str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
.arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
.arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
return str;
}
};
OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
- : OTodoAccessBackend(), m_dict(15)
+ : OTodoAccessBackend(), m_dict(15), m_dirty(true)
{
QString fi = file;
if ( fi.isEmpty() )
fi = Global::applicationFileName( "todolist", "todolist.db" );
OSQLManager man;
m_driver = man.standard();
m_driver->setUrl(fi);
fillDict();
}
OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
}
bool OTodoAccessBackendSQL::load(){
if (!m_driver->open() )
return false;
CreateQuery creat;
OSQLResult res = m_driver->query(&creat );
- update();
- qWarning("loaded %d", m_uids.count() );
+ m_dirty = true;
return true;
}
bool OTodoAccessBackendSQL::reload(){
return load();
}
bool OTodoAccessBackendSQL::save(){
return m_driver->close();
}
QArray<int> OTodoAccessBackendSQL::allRecords()const {
+ if (m_dirty )
+ update();
+
return m_uids;
}
QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
QArray<int> ints(0);
return ints;
}
OTodo OTodoAccessBackendSQL::find(int uid ) const{
FindQuery query( uid );
return todo( m_driver->query(&query) );
}
OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
@@ -294,25 +296,25 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
// we try to cache 8 items
switch( dir ) {
/* forward */
case 0:
for (uint i = cur; i < ints.count() && size < 8; i++ ) {
qWarning("size %d %d", size, ints[i] );
search[size] = ints[i];
size++;
}
break;
/* 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++;
}
break;
}
search.resize( size );
FindQuery query( search );
OSQLResult res = m_driver->query( &query );
if ( res.state() != OSQLResult::Success )
return to;
return todo( res );
@@ -333,51 +335,54 @@ bool OTodoAccessBackendSQL::add( const OTodo& t) {
m_uids.resize( c+1 );
m_uids[c] = t.uid();
return true;
}
bool OTodoAccessBackendSQL::remove( int uid ) {
RemoveQuery rem( uid );
OSQLResult res = m_driver->query(&rem );
if ( res.state() == OSQLResult::Failure )
return false;
- update();
+ m_dirty = true;
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);
+ bool b= add(t);
+ m_dirty = false; // we changed some stuff but the UID stayed the same
+ return b;
}
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 ) {
+ qWarning("sorted %d, %d", asc, sortOrder );
QString query;
query = "select uid from todolist WHERE ";
/*
* Sort Filter stuff
* not that straight forward
*
*/
/* Category */
if ( sortFilter & 1 ) {
QString str;
if (cat != 0 ) str = QString::number( cat );
@@ -412,26 +417,29 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
query += "completed";
break;
case 1:
query += "priority";
break;
case 2:
query += "description";
break;
case 3:
query += "DueDate";
break;
}
- if ( !asc )
+
+ if ( !asc ) {
+ qWarning("not ascending!");
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();
@@ -492,31 +500,36 @@ void OTodoAccessBackendSQL::fillDict() {
m_dict.insert("Description" , new int(OTodo::Description) );
m_dict.insert("Summary" , new int(OTodo::Summary) );
m_dict.insert("Priority" , new int(OTodo::Priority) );
m_dict.insert("DateDay" , new int(OTodo::DateDay) );
m_dict.insert("DateMonth" , new int(OTodo::DateMonth) );
m_dict.insert("DateYear" , new int(OTodo::DateYear) );
m_dict.insert("Progress" , new int(OTodo::Progress) );
m_dict.insert("Completed", new int(OTodo::Completed) );
m_dict.insert("CrossReference", new int(OTodo::CrossReference) );
m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
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);
if ( res.state() != OSQLResult::Success )
return;
- m_uids = uids( res );
+ ((OTodoAccessBackendSQL*)this)->m_uids = uids( res );
}
QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
qWarning(" count = %d", list.count() );
int i = 0;
for (it = list.begin(); it != list.end(); ++it ) {
ints[i] = (*it).data("uid").toInt();
i++;
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
@@ -23,27 +23,28 @@ public:
OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )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 update()const;
void fillDict();
inline bool date( QDate& date, const QString& )const;
inline OTodo todo( const OSQLResult& )const;
inline OTodo todo( OSQLResultItem& )const;
inline QArray<int> uids( const OSQLResult& )const;
OTodo todo( int uid )const;
QAsciiDict<int> m_dict;
OSQLDriver* m_driver;
QArray<int> m_uids;
+ bool m_dirty : 1;
};
#endif
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
@@ -175,30 +175,28 @@ T OPimAccessTemplate<T>::find( int uid ) const{
return t;
}
template <class T>
T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
uint current, CacheDirection dir )const {
/*
* better do T.isEmpty()
* after a find this way we would
* avoid two finds in QCache...
*/
// 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;
}
template <class T>
void OPimAccessTemplate<T>::clear() {
invalidateCache();
m_backEnd->clear();
}
template <class T>
bool OPimAccessTemplate<T>::add( const T& t ) {
cache( t );
return m_backEnd->add( t );
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
@@ -100,24 +100,25 @@ public:
/**
* the end
*/
Iterator end();
/**
* the number of items in the list
*/
uint count()const;
T operator[]( uint i );
+ int uidAt(uint i );
// FIXME implemenent remove
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
private:
QArray<int> m_ids;
const Base* m_acc;
};
/* ok now implement it */
template <class T>
@@ -253,13 +254,17 @@ ORecordList<T>::Iterator ORecordList<T>::end() {
return it;
}
template <class T>
uint ORecordList<T>::count()const {
return m_ids.count();
}
template <class T>
T ORecordList<T>::operator[]( uint i ) {
/* forward */
return m_acc->find( m_ids[i], m_ids, i );
}
+template <class T>
+int ORecordList<T>::uidAt( uint i ) {
+ return m_ids[i];
+}
#endif