summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/opimaccessbackend.h19
-rw-r--r--libopie/pim/opimaccesstemplate.h144
-rw-r--r--libopie/pim/opimrecord.cpp6
-rw-r--r--libopie/pim/opimrecord.h2
-rw-r--r--libopie/pim/orecordlist.h124
-rw-r--r--libopie/pim/otemplatebase.h18
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h19
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h144
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp6
-rw-r--r--libopie2/opiepim/core/opimrecord.h2
-rw-r--r--libopie2/opiepim/core/otemplatebase.h18
-rw-r--r--libopie2/opiepim/orecordlist.h124
12 files changed, 388 insertions, 238 deletions
diff --git a/libopie/pim/opimaccessbackend.h b/libopie/pim/opimaccessbackend.h
index d9af589..8e744e7 100644
--- a/libopie/pim/opimaccessbackend.h
+++ b/libopie/pim/opimaccessbackend.h
@@ -1,29 +1,36 @@
#ifndef OPIE_PIM_ACCESS_BACKEND
#define OPIE_PIM_ACCESS_BACKEND
#include <qarray.h>
#include <opie/opimrecord.h>
template <class T = OPimRecord>
class OPimAccessBackend {
public:
- OPimAccessBackend() {
- }
- ~OPimAccessBackend() {
- }
+ OPimAccessBackend();
+ virtual ~OPimAccessBackend();
virtual void load() = 0;
virtual void reload() = 0;
virtual void save() = 0;
- virtual QArray<int> allRecords() = 0;
+ virtual QArray<int> allRecords()const = 0;
virtual QArray<int> queryByExample( const T& t, int sort ) = 0;
virtual T find(int uid ) = 0;
virtual void clear() = 0;
virtual bool add( const T& t ) = 0;
virtual bool remove( int uid ) = 0;
- virtual void replace( const T& t ) = 0;
+ virtual bool replace( const T& t ) = 0;
};
+template <class T>
+OPimAccessBackend<T>::OPimAccessBackend() {
+
+}
+template <class T>
+OPimAccessBackend<T>::~OPimAccessBackend() {
+
+}
+
#endif
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h
index f2a241d..e0708e1 100644
--- a/libopie/pim/opimaccesstemplate.h
+++ b/libopie/pim/opimaccesstemplate.h
@@ -1,82 +1,118 @@
#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
#define OPIE_PIM_ACCESS_TEMPLATE_H
#include <qarray.h>
#include <opie/opimrecord.h>
#include <opie/opimaccessbackend.h>
#include <opie/orecordlist.h>
+#include "otemplatebase.h"
+
template <class T = OPimRecord >
-class OPimAccessTemplate {
+class OPimAccessTemplate : public OTemplateBase<T> {
public:
typedef ORecordList<T> List;
typedef OPimAccessBackend<T> BackEnd;
- OPimAccessTemplate( BackEnd* end)
- : m_backEnd( end ) {
- }
- ~OPimAccessTemplate() {
- delete m_backEnd;
- }
- virtual void load() {
- m_backEnd->load();
- }
- virtual void reload() {
- m_backEnd->reload();
- }
- virtual void save() {
- m_backEnd->save();
- }
+ OPimAccessTemplate( BackEnd* end);
+ virtual ~OPimAccessTemplate();
+ virtual void load();
+ virtual void reload();
+ virtual void save();
/*
*do array to Records conversion
* QArray<int> ids
*/
- virtual List allRecords()const {
- QArray<int> ints = m_backEnd->allRecords();
-
- List lis( ints, this );
- return lis;
- }
- virtual List queryByExample( const T& t, int sortOrder ) {
- QArray<int> ints = m_backEnd->query( t, sortOrder );
- List lis( ints, this );
-
- return lis;
- }
- /* implement QCache here */
- virtual T find( int uid ) {
- T t = m_backEnd->find( uid );
- return t;
- }
+ virtual List allRecords()const;
+ virtual List queryByExample( const T& t, int sortOrder );
+ virtual T find( int uid );
/* invalidate cache here */
- virtual void clear() {
- invalidateCache();
- m_backEnd->clear();
- }
- virtual bool add( const T& t ) {
- return m_backEnd->add( t );
- }
+ virtual void clear() ;
+ virtual bool add( const T& t ) ;
/* only the uid matters */
- virtual bool remove( const T& t ) {
- /* remove from cache */
- return m_backEnd->remove( t.uid() );
- }
- virtual bool remove( int uid ) {
- /* remove from cache */
- return m_backEnd->remove(uid);
- }
- virtual bool replace( const T& t) {
- return m_backEnd->replace( t );
- }
+ virtual bool remove( const T& t );
+ virtual bool remove( int uid );
+ virtual bool replace( const T& t) ;
protected:
- void invalidateCache() {
-
- }
+ void invalidateCache();
+ BackEnd* backEnd();
BackEnd* m_backEnd;
};
+template <class T>
+OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
+ : OTemplateBase<T>(), m_backEnd( end )
+{
+
+}
+template <class T>
+OPimAccessTemplate<T>::~OPimAccessTemplate() {
+ qWarning("~OPimAccessTemplate<T>");
+ delete m_backEnd;
+}
+template <class T>
+void OPimAccessTemplate<T>::load() {
+ m_backEnd->load();
+}
+template <class T>
+void OPimAccessTemplate<T>::reload() {
+ m_backEnd->reload();
+}
+template <class T>
+void OPimAccessTemplate<T>::save() {
+ m_backEnd->save();
+}
+template <class T>
+OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
+ QArray<int> ints = m_backEnd->allRecords();
+ List lis(ints, this );
+ return lis;
+}
+template <class T>
+OPimAccessTemplate<T>::List
+OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) {
+ QArray<int> ints = m_backEnd->queryByExample( t, sortOrder );
+
+ List lis(ints, this );
+ return lis;
+}
+template <class T>
+T OPimAccessTemplate<T>::find( int uid ) {
+ T t = m_backEnd->find( uid );
+ return t;
+}
+template <class T>
+void OPimAccessTemplate<T>::clear() {
+ invalidateCache();
+ m_backEnd->clear();
+}
+template <class T>
+bool OPimAccessTemplate<T>::add( const T& t ) {
+ return m_backEnd->add( t );
+}
+template <class T>
+bool OPimAccessTemplate<T>::remove( const T& t ) {
+ return m_backEnd->remove( t.uid() );
+}
+template <class T>
+bool OPimAccessTemplate<T>::remove( int uid ) {
+ return m_backEnd->remove( uid );
+}
+template <class T>
+bool OPimAccessTemplate<T>::replace( const T& t ) {
+ return m_backEnd->replace( t );
+}
+template <class T>
+void OPimAccessTemplate<T>::invalidateCache() {
+
+}
+template <class T>
+OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
+ return m_backEnd;
+}
+
#endif
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp
index 88b6fde..60cdbf3 100644
--- a/libopie/pim/opimrecord.cpp
+++ b/libopie/pim/opimrecord.cpp
@@ -1,127 +1,133 @@
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
#include "opimrecord.h"
+Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
+
+
OPimRecord::OPimRecord( int uid )
: Qtopia::Record() {
setUid( uid );
}
OPimRecord::~OPimRecord() {
}
OPimRecord::OPimRecord( const OPimRecord& rec )
: Qtopia::Record( rec )
{
(*this) = rec;
}
OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
Qtopia::Record::operator=( rec );
m_relations = rec.m_relations;
return *this;
}
/*
* category names
*/
QStringList OPimRecord::categoryNames()const {
QStringList list;
QArray<int> cats = categories();
Categories catDB;
catDB.load( categoryFileName() );
for (uint i = 0; i < cats.count(); i++ ) {
list << catDB.label("Todo List", cats[i] );
}
return list;
}
void OPimRecord::setCategoryNames( const QStringList& ) {
}
void OPimRecord::addCategoryName( const QString& ) {
Categories catDB;
catDB.load( categoryFileName() );
}
bool OPimRecord::isEmpty()const {
return ( uid() == 0 );
}
QStringList OPimRecord::relatedApps()const{
QStringList list;
QMap<QString, QArray<int> >::ConstIterator it;
for ( it = m_relations.begin(); it != m_relations.end(); ++it ) {
list << it.key();
}
return list;
}
QArray<int> OPimRecord::relations(const QString& app )const {
QArray<int> tmp;
QMap<QString, QArray<int> >::ConstIterator it;
it = m_relations.find( app);
if ( it != m_relations.end() )
tmp = it.data();
return tmp;
}
void OPimRecord::clearRelation( const QString& app ) {
m_relations.remove( app );
}
void OPimRecord::addRelation( const QString& app, int id ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> tmp;
it = m_relations.find( app );
if ( it == m_relations.end() ) {
tmp.resize(1 );
tmp[0] = id;
}else{
tmp = it.data();
tmp.resize( tmp.size() + 1 );
tmp[tmp.size() - 1] = id;
}
m_relations.replace( app, tmp );
}
void OPimRecord::setRelations( const QString& app, QArray<int> ids ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> tmp;
it = m_relations.find( app);
if ( it == m_relations.end() ) {
tmp = ids;
}else{
tmp = it.data();
int offset = tmp.size()-1;
tmp.resize( tmp.size() + ids.size() );
for (uint i = 0; i < ids.size(); i++ ) {
tmp[offset+i] = ids[i];
}
}
m_relations.replace( app, tmp );
}
QString OPimRecord::crossToString()const {
QString str;
QMap<QString, QArray<int> >::ConstIterator it;
for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
QArray<int> id = it.data();
for ( uint i = 0; i < id.size(); ++i ) {
str += it.key() + "," + QString::number( i ) + ";";
}
}
str = str.remove( str.length()-1, 1); // strip the ;
//qWarning("IDS " + str );
return str;
}
/* if uid = 1 assign a new one */
void OPimRecord::setUid( int uid ) {
if ( uid == 1)
uid = uidGen().generate();
Qtopia::Record::setUid( uid );
};
+Qtopia::UidGen &OPimRecord::uidGen() {
+ return m_uidGen;
+}
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h
index 297ff12..e4d33d6 100644
--- a/libopie/pim/opimrecord.h
+++ b/libopie/pim/opimrecord.h
@@ -1,118 +1,120 @@
#ifndef OPIE_PIM_RECORD_H
#define OPIE_PIM_RECORD_H
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qpe/palmtoprecord.h>
class OPimRecord : public Qtopia::Record {
public:
/**
* uid of 0 isEmpty
* uid of 1 will be assigned a new one
*/
OPimRecord(int uid = 0);
~OPimRecord();
/**
* copy c'tor
*/
OPimRecord( const OPimRecord& rec );
/**
* copy operator
*/
OPimRecord &operator=( const OPimRecord& );
/**
* category names resolved
*/
QStringList categoryNames()const;
/**
* set category names they will be resolved
*/
void setCategoryNames( const QStringList& );
/**
* addCategoryName adds a name
* to the internal category list
*/
void addCategoryName( const QString& );
/**
* if a Record isEmpty
*/
virtual bool isEmpty()const;
/**
* toRichText summary
*/
virtual QString toRichText()const = 0;
/**
* a small one line summary
*/
virtual QString toShortText()const = 0;
/**
* the name of the Record
*/
virtual QString type()const = 0;
/**
* converts the internal structure to a map
*/
virtual QMap<int, QString> toMap()const = 0;
/**
* key value representation of extra items
*/
virtual QMap<QString, QString> toExtraMap()const = 0;
/**
* the name for a recordField
*/
virtual QString recordField(int)const = 0;
/**
* the related apps names
*/
QStringList relatedApps()const;
/**
* the realtions between an app
*/
QArray<int> relations( const QString& app )const;
/**
*
*/
void clearRelation( const QString& app );
/**
*
*/
void addRelation( const QString& app, int id );
/**
*
*/
void setRelations( const QString&, QArray<int> ids );
virtual void setUid( int uid );
protected:
+ Qtopia::UidGen &uidGen();
QString crossToString()const;
private:
class OPimRecordPrivate;
OPimRecordPrivate *d;
QMap<QString, QArray<int> > m_relations;
+ static Qtopia::UidGen m_uidGen;
};
#endif
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index 65c2169..a3955b0 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -1,159 +1,165 @@
#ifndef OPIE_RECORD_LIST_H
#define OPIE_RECORD_LIST_H
-#include <opie/opimaccesstemplate.h>
-#include <opie/opimrecord.h>
+#include <qarray.h>
+
+#include "otemplatebase.h"
+#include "opimrecord.h"
+
+
+template <class T = OPimRecord>
+class ORecordListIterator {
+public:
+ typedef OTemplateBase<T> Base;
+ ORecordListIterator( const QArray<int>, const Base* );
+ ORecordListIterator();
+ ~ORecordListIterator();
+ ORecordListIterator( const ORecordListIterator& );
+ ORecordListIterator &operator=(const ORecordListIterator& );
+ T &operator*();
+ ORecordListIterator &operator++();
+ ORecordListIterator &operator--();
+
+ bool operator==( const ORecordListIterator& it );
+ bool operator!=( const ORecordListIterator& it );
+
+private:
+ QArray<int> m_uids;
+ int m_current;
+ const Base* m_temp;
+ bool m_end : 1;
+ T m_record;
+
+ /* d pointer for future versions */
+ class IteratorPrivate;
+ IteratorPrivate *d;
+};
template <class T = OPimRecord >
class ORecordList {
public:
- class Iterator {
- friend class ORecordList;
- public:
- Iterator();
- ~Iterator();
- Iterator(const Iterator& );
- Iterator &operator=(const Iterator& );
- T &operator*();
- Iterator &operator++();
- Iterator &operator--();
-
- bool operator==( const Iterator& it );
- bool operator!=( const Iterator& it );
-
- private:
- Iterator( const QArray<int>,
- OPimAccessTemplate<T>* );
-
- QArray<int> m_uids;
- int m_current;
- OPimAccessTemplate* m_temp;
- bool m_end : 1;
- T m_record;
-
- /* d pointer for future versions */
- class IteratorPrivate;
- IteratorPrivate *d;
- };
+ typedef OTemplateBase<T> Base;
+ typedef ORecordListIterator<T> Iterator;
ORecordList( const QArray<int>& ids,
- OPimAccessTemplate<T>* acc );
+ const Base* );
~ORecordList();
Iterator begin();
Iterator end();
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
private:
QArray<int> m_ids;
- OPimAccessTemplate<T>* m_acc;
+ const Base* m_acc;
};
/* ok now implement it */
-template <class T= OPimRecord>
-ORecordList<T>::Iterator::Iterator() {
+template <class T>
+ORecordListIterator<T>::ORecordListIterator() {
m_current = 0;
m_temp = 0l;
m_end = true;
}
-template <class T= OPimRecord>
-ORecordList<T>::Iterator::~Iterator() {
+template <class T>
+ORecordListIterator<T>::~ORecordListIterator() {
/* nothing to delete */
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) {
+template <class T>
+ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
m_uids = it.m_uids;
m_current = it.m_current;
m_temp = it.m_temp;
m_end = it.m_end;
m_record = it.m_record;
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) {
+template <class T>
+ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
m_uids = it.m_uids;
m_current = it.m_current;
m_temp = it.m_temp;
m_end = it.m_end;
m_record = it.m_record;
return *this;
}
-template <class T = OPimRecord>
-T &ORecordList<T>::Iterator::operator*() {
+template <class T>
+T &ORecordListIterator<T>::operator*() {
if (!m_end )
m_record = m_temp->find( m_uids[m_current] );
else
- m_record = T;
+ m_record = T();
return m_record;
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() {
+template <class T>
+ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
if (m_current < m_uids.count() ) {
m_end = false;
++m_current;
}else
m_end = true;
return *this;
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() {
+template <class T>
+ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
if ( m_current > 0 ) {
--m_current;
m_end = false;
} else
m_end = true;
return *this;
}
-template <class T = OPimRecord>
-bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) {
+template <class T>
+bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
/* if both are at we're the same.... */
if ( m_end == it.m_end ) return true;
if ( m_uids != it.m_uids ) return false;
if ( m_current != it.m_current ) return false;
if ( m_temp != it.m_temp ) return false;
return true;
}
-template <class T = ORecordList>
-bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) {
+template <class T>
+bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
return !(*this == it );
}
-template <class T = ORecordList>
-ORecordList<T>::Iterator::Iterator( const QArray<int> uids,
- OPimAccessTemplate<T>* t )
+template <class T>
+ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids,
+ const Base* t )
: m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false )
{
}
-template <class T = ORecordList>
+
+template <class T>
ORecordList<T>::ORecordList( const QArray<int>& ids,
- OPimAccessTemplate<T>* acc )
+ const Base* acc )
: m_ids( ids ), m_acc( acc )
{
}
-template <class T = ORecordList>
+template <class T>
ORecordList<T>::~ORecordList() {
/* nothing to do here */
}
-template <class T = ORecordList>
+template <class T>
ORecordList<T>::Iterator ORecordList<T>::begin() {
Iterator it( m_ids, m_acc );
return it;
}
-template <class T = ORecordList>
+template <class T>
ORecordList<T>::Iterator ORecordList<T>::end() {
Iterator it( m_ids, m_acc );
it.m_end = true;
it.m_current = m_ids.count();
}
#endif
diff --git a/libopie/pim/otemplatebase.h b/libopie/pim/otemplatebase.h
new file mode 100644
index 0000000..41cc934
--- a/dev/null
+++ b/libopie/pim/otemplatebase.h
@@ -0,0 +1,18 @@
+#ifndef OPIE_TEMPLATE_BASE_H
+#define OPIE_TEMPLATE_BASE_H
+
+#include "opimrecord.h"
+
+template <class T = OPimRecord>
+class OTemplateBase {
+public:
+ OTemplateBase() {
+ };
+ virtual ~OTemplateBase() {
+ }
+ virtual T find( int uid ) = 0;
+
+};
+
+
+#endif
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index d9af589..8e744e7 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -1,29 +1,36 @@
#ifndef OPIE_PIM_ACCESS_BACKEND
#define OPIE_PIM_ACCESS_BACKEND
#include <qarray.h>
#include <opie/opimrecord.h>
template <class T = OPimRecord>
class OPimAccessBackend {
public:
- OPimAccessBackend() {
- }
- ~OPimAccessBackend() {
- }
+ OPimAccessBackend();
+ virtual ~OPimAccessBackend();
virtual void load() = 0;
virtual void reload() = 0;
virtual void save() = 0;
- virtual QArray<int> allRecords() = 0;
+ virtual QArray<int> allRecords()const = 0;
virtual QArray<int> queryByExample( const T& t, int sort ) = 0;
virtual T find(int uid ) = 0;
virtual void clear() = 0;
virtual bool add( const T& t ) = 0;
virtual bool remove( int uid ) = 0;
- virtual void replace( const T& t ) = 0;
+ virtual bool replace( const T& t ) = 0;
};
+template <class T>
+OPimAccessBackend<T>::OPimAccessBackend() {
+
+}
+template <class T>
+OPimAccessBackend<T>::~OPimAccessBackend() {
+
+}
+
#endif
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index f2a241d..e0708e1 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,82 +1,118 @@
#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
#define OPIE_PIM_ACCESS_TEMPLATE_H
#include <qarray.h>
#include <opie/opimrecord.h>
#include <opie/opimaccessbackend.h>
#include <opie/orecordlist.h>
+#include "otemplatebase.h"
+
template <class T = OPimRecord >
-class OPimAccessTemplate {
+class OPimAccessTemplate : public OTemplateBase<T> {
public:
typedef ORecordList<T> List;
typedef OPimAccessBackend<T> BackEnd;
- OPimAccessTemplate( BackEnd* end)
- : m_backEnd( end ) {
- }
- ~OPimAccessTemplate() {
- delete m_backEnd;
- }
- virtual void load() {
- m_backEnd->load();
- }
- virtual void reload() {
- m_backEnd->reload();
- }
- virtual void save() {
- m_backEnd->save();
- }
+ OPimAccessTemplate( BackEnd* end);
+ virtual ~OPimAccessTemplate();
+ virtual void load();
+ virtual void reload();
+ virtual void save();
/*
*do array to Records conversion
* QArray<int> ids
*/
- virtual List allRecords()const {
- QArray<int> ints = m_backEnd->allRecords();
-
- List lis( ints, this );
- return lis;
- }
- virtual List queryByExample( const T& t, int sortOrder ) {
- QArray<int> ints = m_backEnd->query( t, sortOrder );
- List lis( ints, this );
-
- return lis;
- }
- /* implement QCache here */
- virtual T find( int uid ) {
- T t = m_backEnd->find( uid );
- return t;
- }
+ virtual List allRecords()const;
+ virtual List queryByExample( const T& t, int sortOrder );
+ virtual T find( int uid );
/* invalidate cache here */
- virtual void clear() {
- invalidateCache();
- m_backEnd->clear();
- }
- virtual bool add( const T& t ) {
- return m_backEnd->add( t );
- }
+ virtual void clear() ;
+ virtual bool add( const T& t ) ;
/* only the uid matters */
- virtual bool remove( const T& t ) {
- /* remove from cache */
- return m_backEnd->remove( t.uid() );
- }
- virtual bool remove( int uid ) {
- /* remove from cache */
- return m_backEnd->remove(uid);
- }
- virtual bool replace( const T& t) {
- return m_backEnd->replace( t );
- }
+ virtual bool remove( const T& t );
+ virtual bool remove( int uid );
+ virtual bool replace( const T& t) ;
protected:
- void invalidateCache() {
-
- }
+ void invalidateCache();
+ BackEnd* backEnd();
BackEnd* m_backEnd;
};
+template <class T>
+OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
+ : OTemplateBase<T>(), m_backEnd( end )
+{
+
+}
+template <class T>
+OPimAccessTemplate<T>::~OPimAccessTemplate() {
+ qWarning("~OPimAccessTemplate<T>");
+ delete m_backEnd;
+}
+template <class T>
+void OPimAccessTemplate<T>::load() {
+ m_backEnd->load();
+}
+template <class T>
+void OPimAccessTemplate<T>::reload() {
+ m_backEnd->reload();
+}
+template <class T>
+void OPimAccessTemplate<T>::save() {
+ m_backEnd->save();
+}
+template <class T>
+OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
+ QArray<int> ints = m_backEnd->allRecords();
+ List lis(ints, this );
+ return lis;
+}
+template <class T>
+OPimAccessTemplate<T>::List
+OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) {
+ QArray<int> ints = m_backEnd->queryByExample( t, sortOrder );
+
+ List lis(ints, this );
+ return lis;
+}
+template <class T>
+T OPimAccessTemplate<T>::find( int uid ) {
+ T t = m_backEnd->find( uid );
+ return t;
+}
+template <class T>
+void OPimAccessTemplate<T>::clear() {
+ invalidateCache();
+ m_backEnd->clear();
+}
+template <class T>
+bool OPimAccessTemplate<T>::add( const T& t ) {
+ return m_backEnd->add( t );
+}
+template <class T>
+bool OPimAccessTemplate<T>::remove( const T& t ) {
+ return m_backEnd->remove( t.uid() );
+}
+template <class T>
+bool OPimAccessTemplate<T>::remove( int uid ) {
+ return m_backEnd->remove( uid );
+}
+template <class T>
+bool OPimAccessTemplate<T>::replace( const T& t ) {
+ return m_backEnd->replace( t );
+}
+template <class T>
+void OPimAccessTemplate<T>::invalidateCache() {
+
+}
+template <class T>
+OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
+ return m_backEnd;
+}
+
#endif
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index 88b6fde..60cdbf3 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -1,127 +1,133 @@
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
#include "opimrecord.h"
+Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
+
+
OPimRecord::OPimRecord( int uid )
: Qtopia::Record() {
setUid( uid );
}
OPimRecord::~OPimRecord() {
}
OPimRecord::OPimRecord( const OPimRecord& rec )
: Qtopia::Record( rec )
{
(*this) = rec;
}
OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
Qtopia::Record::operator=( rec );
m_relations = rec.m_relations;
return *this;
}
/*
* category names
*/
QStringList OPimRecord::categoryNames()const {
QStringList list;
QArray<int> cats = categories();
Categories catDB;
catDB.load( categoryFileName() );
for (uint i = 0; i < cats.count(); i++ ) {
list << catDB.label("Todo List", cats[i] );
}
return list;
}
void OPimRecord::setCategoryNames( const QStringList& ) {
}
void OPimRecord::addCategoryName( const QString& ) {
Categories catDB;
catDB.load( categoryFileName() );
}
bool OPimRecord::isEmpty()const {
return ( uid() == 0 );
}
QStringList OPimRecord::relatedApps()const{
QStringList list;
QMap<QString, QArray<int> >::ConstIterator it;
for ( it = m_relations.begin(); it != m_relations.end(); ++it ) {
list << it.key();
}
return list;
}
QArray<int> OPimRecord::relations(const QString& app )const {
QArray<int> tmp;
QMap<QString, QArray<int> >::ConstIterator it;
it = m_relations.find( app);
if ( it != m_relations.end() )
tmp = it.data();
return tmp;
}
void OPimRecord::clearRelation( const QString& app ) {
m_relations.remove( app );
}
void OPimRecord::addRelation( const QString& app, int id ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> tmp;
it = m_relations.find( app );
if ( it == m_relations.end() ) {
tmp.resize(1 );
tmp[0] = id;
}else{
tmp = it.data();
tmp.resize( tmp.size() + 1 );
tmp[tmp.size() - 1] = id;
}
m_relations.replace( app, tmp );
}
void OPimRecord::setRelations( const QString& app, QArray<int> ids ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> tmp;
it = m_relations.find( app);
if ( it == m_relations.end() ) {
tmp = ids;
}else{
tmp = it.data();
int offset = tmp.size()-1;
tmp.resize( tmp.size() + ids.size() );
for (uint i = 0; i < ids.size(); i++ ) {
tmp[offset+i] = ids[i];
}
}
m_relations.replace( app, tmp );
}
QString OPimRecord::crossToString()const {
QString str;
QMap<QString, QArray<int> >::ConstIterator it;
for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
QArray<int> id = it.data();
for ( uint i = 0; i < id.size(); ++i ) {
str += it.key() + "," + QString::number( i ) + ";";
}
}
str = str.remove( str.length()-1, 1); // strip the ;
//qWarning("IDS " + str );
return str;
}
/* if uid = 1 assign a new one */
void OPimRecord::setUid( int uid ) {
if ( uid == 1)
uid = uidGen().generate();
Qtopia::Record::setUid( uid );
};
+Qtopia::UidGen &OPimRecord::uidGen() {
+ return m_uidGen;
+}
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index 297ff12..e4d33d6 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -1,118 +1,120 @@
#ifndef OPIE_PIM_RECORD_H
#define OPIE_PIM_RECORD_H
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qpe/palmtoprecord.h>
class OPimRecord : public Qtopia::Record {
public:
/**
* uid of 0 isEmpty
* uid of 1 will be assigned a new one
*/
OPimRecord(int uid = 0);
~OPimRecord();
/**
* copy c'tor
*/
OPimRecord( const OPimRecord& rec );
/**
* copy operator
*/
OPimRecord &operator=( const OPimRecord& );
/**
* category names resolved
*/
QStringList categoryNames()const;
/**
* set category names they will be resolved
*/
void setCategoryNames( const QStringList& );
/**
* addCategoryName adds a name
* to the internal category list
*/
void addCategoryName( const QString& );
/**
* if a Record isEmpty
*/
virtual bool isEmpty()const;
/**
* toRichText summary
*/
virtual QString toRichText()const = 0;
/**
* a small one line summary
*/
virtual QString toShortText()const = 0;
/**
* the name of the Record
*/
virtual QString type()const = 0;
/**
* converts the internal structure to a map
*/
virtual QMap<int, QString> toMap()const = 0;
/**
* key value representation of extra items
*/
virtual QMap<QString, QString> toExtraMap()const = 0;
/**
* the name for a recordField
*/
virtual QString recordField(int)const = 0;
/**
* the related apps names
*/
QStringList relatedApps()const;
/**
* the realtions between an app
*/
QArray<int> relations( const QString& app )const;
/**
*
*/
void clearRelation( const QString& app );
/**
*
*/
void addRelation( const QString& app, int id );
/**
*
*/
void setRelations( const QString&, QArray<int> ids );
virtual void setUid( int uid );
protected:
+ Qtopia::UidGen &uidGen();
QString crossToString()const;
private:
class OPimRecordPrivate;
OPimRecordPrivate *d;
QMap<QString, QArray<int> > m_relations;
+ static Qtopia::UidGen m_uidGen;
};
#endif
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h
new file mode 100644
index 0000000..41cc934
--- a/dev/null
+++ b/libopie2/opiepim/core/otemplatebase.h
@@ -0,0 +1,18 @@
+#ifndef OPIE_TEMPLATE_BASE_H
+#define OPIE_TEMPLATE_BASE_H
+
+#include "opimrecord.h"
+
+template <class T = OPimRecord>
+class OTemplateBase {
+public:
+ OTemplateBase() {
+ };
+ virtual ~OTemplateBase() {
+ }
+ virtual T find( int uid ) = 0;
+
+};
+
+
+#endif
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h
index 65c2169..a3955b0 100644
--- a/libopie2/opiepim/orecordlist.h
+++ b/libopie2/opiepim/orecordlist.h
@@ -1,159 +1,165 @@
#ifndef OPIE_RECORD_LIST_H
#define OPIE_RECORD_LIST_H
-#include <opie/opimaccesstemplate.h>
-#include <opie/opimrecord.h>
+#include <qarray.h>
+
+#include "otemplatebase.h"
+#include "opimrecord.h"
+
+
+template <class T = OPimRecord>
+class ORecordListIterator {
+public:
+ typedef OTemplateBase<T> Base;
+ ORecordListIterator( const QArray<int>, const Base* );
+ ORecordListIterator();
+ ~ORecordListIterator();
+ ORecordListIterator( const ORecordListIterator& );
+ ORecordListIterator &operator=(const ORecordListIterator& );
+ T &operator*();
+ ORecordListIterator &operator++();
+ ORecordListIterator &operator--();
+
+ bool operator==( const ORecordListIterator& it );
+ bool operator!=( const ORecordListIterator& it );
+
+private:
+ QArray<int> m_uids;
+ int m_current;
+ const Base* m_temp;
+ bool m_end : 1;
+ T m_record;
+
+ /* d pointer for future versions */
+ class IteratorPrivate;
+ IteratorPrivate *d;
+};
template <class T = OPimRecord >
class ORecordList {
public:
- class Iterator {
- friend class ORecordList;
- public:
- Iterator();
- ~Iterator();
- Iterator(const Iterator& );
- Iterator &operator=(const Iterator& );
- T &operator*();
- Iterator &operator++();
- Iterator &operator--();
-
- bool operator==( const Iterator& it );
- bool operator!=( const Iterator& it );
-
- private:
- Iterator( const QArray<int>,
- OPimAccessTemplate<T>* );
-
- QArray<int> m_uids;
- int m_current;
- OPimAccessTemplate* m_temp;
- bool m_end : 1;
- T m_record;
-
- /* d pointer for future versions */
- class IteratorPrivate;
- IteratorPrivate *d;
- };
+ typedef OTemplateBase<T> Base;
+ typedef ORecordListIterator<T> Iterator;
ORecordList( const QArray<int>& ids,
- OPimAccessTemplate<T>* acc );
+ const Base* );
~ORecordList();
Iterator begin();
Iterator end();
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
private:
QArray<int> m_ids;
- OPimAccessTemplate<T>* m_acc;
+ const Base* m_acc;
};
/* ok now implement it */
-template <class T= OPimRecord>
-ORecordList<T>::Iterator::Iterator() {
+template <class T>
+ORecordListIterator<T>::ORecordListIterator() {
m_current = 0;
m_temp = 0l;
m_end = true;
}
-template <class T= OPimRecord>
-ORecordList<T>::Iterator::~Iterator() {
+template <class T>
+ORecordListIterator<T>::~ORecordListIterator() {
/* nothing to delete */
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) {
+template <class T>
+ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
m_uids = it.m_uids;
m_current = it.m_current;
m_temp = it.m_temp;
m_end = it.m_end;
m_record = it.m_record;
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) {
+template <class T>
+ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
m_uids = it.m_uids;
m_current = it.m_current;
m_temp = it.m_temp;
m_end = it.m_end;
m_record = it.m_record;
return *this;
}
-template <class T = OPimRecord>
-T &ORecordList<T>::Iterator::operator*() {
+template <class T>
+T &ORecordListIterator<T>::operator*() {
if (!m_end )
m_record = m_temp->find( m_uids[m_current] );
else
- m_record = T;
+ m_record = T();
return m_record;
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() {
+template <class T>
+ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
if (m_current < m_uids.count() ) {
m_end = false;
++m_current;
}else
m_end = true;
return *this;
}
-template <class T = OPimRecord>
-ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() {
+template <class T>
+ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
if ( m_current > 0 ) {
--m_current;
m_end = false;
} else
m_end = true;
return *this;
}
-template <class T = OPimRecord>
-bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) {
+template <class T>
+bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
/* if both are at we're the same.... */
if ( m_end == it.m_end ) return true;
if ( m_uids != it.m_uids ) return false;
if ( m_current != it.m_current ) return false;
if ( m_temp != it.m_temp ) return false;
return true;
}
-template <class T = ORecordList>
-bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) {
+template <class T>
+bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
return !(*this == it );
}
-template <class T = ORecordList>
-ORecordList<T>::Iterator::Iterator( const QArray<int> uids,
- OPimAccessTemplate<T>* t )
+template <class T>
+ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids,
+ const Base* t )
: m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false )
{
}
-template <class T = ORecordList>
+
+template <class T>
ORecordList<T>::ORecordList( const QArray<int>& ids,
- OPimAccessTemplate<T>* acc )
+ const Base* acc )
: m_ids( ids ), m_acc( acc )
{
}
-template <class T = ORecordList>
+template <class T>
ORecordList<T>::~ORecordList() {
/* nothing to do here */
}
-template <class T = ORecordList>
+template <class T>
ORecordList<T>::Iterator ORecordList<T>::begin() {
Iterator it( m_ids, m_acc );
return it;
}
-template <class T = ORecordList>
+template <class T>
ORecordList<T>::Iterator ORecordList<T>::end() {
Iterator it( m_ids, m_acc );
it.m_end = true;
it.m_current = m_ids.count();
}
#endif