summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimaccesstemplate.h
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h345
1 files changed, 247 insertions, 98 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index f936d4e..2deb92a 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -42,2 +42,3 @@
#include <qarray.h>
+#include <qdatetime.h>
@@ -58,2 +59,5 @@ class OPimAccessTemplate : public OTemplateBase<T> {
public:
+ /**
+ *
+ */
enum Access {
@@ -66,116 +70,64 @@ public:
- /**
- * c'tor BackEnd
- * enum Access a small hint on how to handle the backend
- */
+ //@{
OPimAccessTemplate( BackEnd* end);
-
virtual ~OPimAccessTemplate();
+ //@}
- /**
- * load from the backend
- */
+ //@{
bool load();
-
- /** Reload database.
- * You should execute this function if the external database
- * was changed.
- * This function will load the external database and afterwards
- * rejoin the local changes. Therefore the local database will be set consistent.
- */
virtual bool reload();
-
- /** Save contacts database.
- * Save is more a "commit". After calling this function, all changes are public available.
- * @return true if successful
- */
bool save();
+ void clear() ;
+ //@}
+
- /**
- * if the resource was changed externally
- * You should use the signal handling instead of polling possible changes !
- * zecke: Do you implement a signal for otodoaccess ?
- */
bool wasChangedExternally()const;
- /**
- * return a List of records
- * you can iterate over them
- */
+ //@{
virtual List allRecords()const;
-
- /**
- * return a List of records
- * that match the regex
- */
virtual List matchRegexp( const QRegExp &r ) const;
-
- /**
- * queryByExample.
- * @see otodoaccess, ocontactaccess
- */
virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
-
- /**
- * find the OPimRecord uid
- */
- T find( int uid )const;
-
- /**
- * read ahead cache find method ;)
- */
- T find( int uid, const QArray<int>&,
+ virtual T find( UID uid )const;
+ virtual T find( UID uid, const QArray<int>&,
uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
+ virtual List sorted( const List&, bool ascending, int sortOrder,
+ int sortFilter, int cat )const;
+ virtual List sorted( const List&, bool ascending, int sortOrder,
+ int sortFilter, const QArray<UID>& cats )const;
+ virtual List sorted( bool ascending, int sortOrder, int sortFilter, int cat )const;
+ virtual List sorted( bool ascending, int sortOrder, int sortOrder,
+ const QArray<UID>& cats )const;
+ //@}
-
- /* invalidate cache here */
/**
- * clears the backend and invalidates the backend
- */
- void clear() ;
-
- /**
- * add T to the backend
- * @param t The item to add.
- * @return <i>true</i> if added successfully.
+ * (Re)Implementation
*/
+ //@{
+ UIDArray matchRegexpSimple( const QRegExp& r )const;
+ UIDArray queryByExampleSimple( const OPimRecord*, int, const QDateTime& )const;
+ UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
+ int sortFilter, int cat )const;
+ UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
+ int sortFilter, const QArray<int>& )const;
+ UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
+ int cat )const;
+ UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
+ const QArray<int>& )const;
+ OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const;
+ OPimOccurrence::List occurrences( const QDateTime& dt )const;
+ //@}
+
+ //@{
virtual bool add( const T& t ) ;
-
bool add( const OPimRecord& );
- /**
- * Add an Opie PimRecord.
- * Info: Take this if you are working with OPimRecords and you need to add it into any database.
- * But take care that the accessing database is compatible to the real type of OPimRecord !!
- * Otherwise this access will be rejected !
- */
bool add( const OPimRecord* );
-
-
- /* only the uid matters */
- /**
- * remove T from the backend
- * @param t The item to remove
- * @return <i>true</i> if successful.
- */
virtual bool remove( const T& t );
-
- /**
- * remove the OPimRecord with uid
- * @param uid The ID of the item to remove
- * @return <i>true</i> if successful.
- */
- bool remove( int uid );
+ bool remove( UID uid );
bool remove( const OPimRecord& );
-
- /**
- * replace T from backend
- * @param t The item to replace
- * @return <i>true</i> if successful.
- */
virtual bool replace( const T& t) ;
+ //@}
+
void setReadAhead( uint count );
- /**
- * @internal
- */
+ virtual T cacheFind( int uid )const;
void cache( const T& )const;
@@ -183,3 +135,3 @@ public:
- QArray<int> records()const;
+ QArray<UID> records()const;
protected:
@@ -204,2 +156,6 @@ private:
+/**
+ * c'tor BackEnd
+ * enum Access a small hint on how to handle the backend
+ */
template <class T>
@@ -213,5 +169,8 @@ template <class T>
OPimAccessTemplate<T>::~OPimAccessTemplate() {
- owarn << "~OPimAccessTemplate<T>" << oendl;
delete m_backEnd;
}
+
+/**
+ * load from the backend
+ */
template <class T>
@@ -221,2 +180,9 @@ bool OPimAccessTemplate<T>::load() {
}
+
+/** Reload database.
+ * You should execute this function if the external database
+ * was changed.
+ * This function will load the external database and afterwards
+ * rejoin the local changes. Therefore the local database will be set consistent.
+ */
template <class T>
@@ -226,2 +192,8 @@ bool OPimAccessTemplate<T>::reload() {
}
+
+/**
+ * Save contacts database.
+ * Save is more a "commit". After calling this function, all changes are public available.
+ * @return true if successful
+ */
template <class T>
@@ -230,2 +202,8 @@ bool OPimAccessTemplate<T>::save() {
}
+
+
+/**
+ * return a List of records
+ * you can iterate over them
+ */
template <class T>
@@ -236,2 +214,7 @@ typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
}
+
+/**
+ * return a List of records
+ * that match the regex
+ */
template <class T>
@@ -242,2 +225,6 @@ typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const Q
}
+
+/**
+ * find the OPimRecord uid
+ */
template <class T>
@@ -246,2 +233,8 @@ QArray<int> OPimAccessTemplate<T>::records()const {
}
+
+
+/**
+ * queryByExample.
+ * @see otodoaccess, ocontactaccess
+ */
template <class T>
@@ -254,4 +247,5 @@ OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime
}
+
template <class T>
-T OPimAccessTemplate<T>::find( int uid ) const{
+T OPimAccessTemplate<T>::find( UID uid ) const{
// First search in cache..
@@ -267,3 +261,12 @@ T OPimAccessTemplate<T>::find( int uid ) const{
template <class T>
-T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
+T OPimAccessTemplate<T>::cacheFind( int uid ) const
+{
+ return m_cache.find( uid );
+}
+
+/**
+ * read ahead cache find method ;)
+ */
+template <class T>
+T OPimAccessTemplate<T>::find( UID uid, const QArray<int>& ar,
uint current, typename OTemplateBase<T>::CacheDirection dir )const {
@@ -274,6 +277,5 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
*/
- // owarn << "find it now " << uid << oendl;
- if ( m_cache.contains( uid ) ) {
+ if (m_cache.contains( uid ) )
return m_cache.find( uid );
- }
+
@@ -283,2 +285,6 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
}
+
+/**
+ * clears the backend and invalidates the backend
+ */
template <class T>
@@ -288,2 +294,9 @@ void OPimAccessTemplate<T>::clear() {
}
+
+
+/**
+ * add T to the backend
+ * @param t The item to add.
+ * @return <i>true</i> if added successfully.
+ */
template <class T>
@@ -307,2 +320,8 @@ bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) {
+/**
+ * Add an Opie PimRecord.
+ * Info: Take this if you are working with OPimRecords and you need to add it into any database.
+ * But take care that the accessing database is compatible to the real type of OPimRecord !!
+ * Otherwise this access will be rejected !
+ */
template <class T>
@@ -320,2 +339,7 @@ bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
+/**
+ * remove T from the backend
+ * @param t The item to remove
+ * @return <i>true</i> if successful.
+ */
template <class T>
@@ -324,4 +348,10 @@ bool OPimAccessTemplate<T>::remove( const T& t ) {
}
+
+/**
+ * remove the OPimRecord with uid
+ * @param uid The ID of the item to remove
+ * @return <i>true</i> if successful.
+ */
template <class T>
-bool OPimAccessTemplate<T>::remove( int uid ) {
+bool OPimAccessTemplate<T>::remove( UID uid ) {
m_cache.remove( uid );
@@ -333,2 +363,8 @@ bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
}
+
+/**
+ * replace T from backend
+ * @param t The item to replace
+ * @return <i>true</i> if successful.
+ */
template <class T>
@@ -338,2 +374,6 @@ bool OPimAccessTemplate<T>::replace( const T& t ) {
}
+
+/**
+ * @internal
+ */
template <class T>
@@ -346,2 +386,8 @@ typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
}
+
+/**
+ * if the resource was changed externally
+ * You should use the signal handling instead of polling possible changes !
+ * zecke: Do you implement a signal for otodoaccess ?
+ */
template <class T>
@@ -370,2 +416,105 @@ void OPimAccessTemplate<T>::setReadAhead( uint count ) {
+
+template <class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
+ bool ascending, int sortOrder,
+ int sortFilter, int cat )const {
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+ UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template<class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
+ bool ascending, int sortOrder,
+ int sortFilter, const QArray<UID>& cats )const {
+ UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template<class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
+ int sortFilter, int cat )const {
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+ UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template<class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
+ int sortFilter, const QArray<UID>& cats )const {
+ UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template <class T>
+OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDate& start,
+ const QDate& end ) const {
+ /*
+ * Some magic involved to go from single OPimBackendOccurrence
+ * to multiple OPimOccurrence's
+ */
+ return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( start, end ) );
+}
+
+template<class T>
+OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDateTime& dt )const {
+ return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( dt ) );
+}
+
+/*
+ *Implementations!!
+ */
+template <class T>
+UIDArray OPimAccessTemplate<T>::matchRegexpSimple( const QRegExp &r )const {
+ return m_backEnd->matchRegexp( r );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::queryByExampleSimple( const OPimRecord* rec,
+ int settings,
+ const QDateTime& d )const {
+ return m_backEnd->queryByExample( rec, settings, d );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
+ bool ascending,
+ int sortOrder, int sortFilter,
+ int cat ) const{
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+ return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
+ bool ascending,
+ int sortOrder, int sortFilter,
+ const QArray<int>& cats ) const{
+ return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
+ int sortOrder, int sortFilter,
+ int cat ) const{
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+
+ return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
+ int sortOrder, int sortFilter,
+ const QArray<int>& cats ) const{
+ return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
+}
}