summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiedb/config.in2
-rw-r--r--libopie2/opiedb/libopiedb2.control4
-rw-r--r--libopie2/opiedb/opiedb.pro2
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp42
-rw-r--r--libopie2/opiedb/osqlitedriver.h4
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h7
-rw-r--r--libopie2/opiepim/core/opimcontactfields.h2
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h6
8 files changed, 30 insertions, 39 deletions
diff --git a/libopie2/opiedb/config.in b/libopie2/opiedb/config.in
index 4d85609..0d74887 100644
--- a/libopie2/opiedb/config.in
+++ b/libopie2/opiedb/config.in
@@ -1,7 +1,7 @@
1 config LIBOPIE2DB 1 config LIBOPIE2DB
2 boolean "libopie2db (database related classes)" 2 boolean "libopie2db (database related classes)"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP
5 comment "libopie2db needs a libqpe, sqlite and libopie2core" 5 comment "libopie2db needs a libqpe, libsqlite3 and libopie2core"
6 depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP) 6 depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP)
7 7
diff --git a/libopie2/opiedb/libopiedb2.control b/libopie2/opiedb/libopiedb2.control
index 4859c46..29fae78 100644
--- a/libopie2/opiedb/libopiedb2.control
+++ b/libopie2/opiedb/libopiedb2.control
@@ -1,10 +1,10 @@
1Package: libopiedb2 1Package: libopiedb2
2Files: lib/libopiedb2.so* 2Files: lib/libopiedb2.so*
3Priority: optional 3Priority: optional
4Section: opie/system 4Section: opie/system
5Maintainer: Opie Team <opie@handhelds.org> 5Maintainer: Opie Team <opie@handhelds.org>
6Architecture: arm 6Architecture: arm
7Version: 1.8.2-$SUB_VERSION.2 7Version: 1.8.2-$SUB_VERSION.2
8Depends: libqpe1, libopiecore2 (1.8.2), libsqlite0 | sqlite 8Depends: libqpe1, libopiecore2 (1.8.2), libsqlite3 | sqlite3
9Provides: libopiedb2 9Provides: libopiedb2
10Description: Opie library 2.0 DB 10Description: Opie library 2.1 DB
diff --git a/libopie2/opiedb/opiedb.pro b/libopie2/opiedb/opiedb.pro
index 8432674..f727995 100644
--- a/libopie2/opiedb/opiedb.pro
+++ b/libopie2/opiedb/opiedb.pro
@@ -1,43 +1,43 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = osqlbackend.h \ 4HEADERS = osqlbackend.h \
5 osqldriver.h \ 5 osqldriver.h \
6 osqlerror.h \ 6 osqlerror.h \
7 osqlmanager.h \ 7 osqlmanager.h \
8 osqlquery.h \ 8 osqlquery.h \
9 osqlresult.h \ 9 osqlresult.h \
10 osqltable.h \ 10 osqltable.h \
11 osqlbackendmanager.h \ 11 osqlbackendmanager.h \
12 osqlitedriver.h 12 osqlitedriver.h
13 13
14SOURCES = osqlbackend.cpp \ 14SOURCES = osqlbackend.cpp \
15 osqldriver.cpp \ 15 osqldriver.cpp \
16 osqlerror.cpp \ 16 osqlerror.cpp \
17 osqlmanager.cpp \ 17 osqlmanager.cpp \
18 osqlquery.cpp \ 18 osqlquery.cpp \
19 osqlresult.cpp \ 19 osqlresult.cpp \
20 osqltable.cpp \ 20 osqltable.cpp \
21 osqlbackendmanager.cpp \ 21 osqlbackendmanager.cpp \
22 osqlitedriver.cpp 22 osqlitedriver.cpp
23 23
24TARGET = opiedb2 24TARGET = opiedb2
25VERSION = 1.9.0 25VERSION = 1.9.0
26INCLUDEPATH = $(OPIEDIR)/include 26INCLUDEPATH = $(OPIEDIR)/include
27DEPENDPATH = $(OPIEDIR)/include 27DEPENDPATH = $(OPIEDIR)/include
28LIBS += -lopiecore2 -lqpe -lsqlite 28LIBS += -lopiecore2 -lqpe -lsqlite3
29 29
30!contains( platform, x11 ) { 30!contains( platform, x11 ) {
31 include ( $(OPIEDIR)/include.pro ) 31 include ( $(OPIEDIR)/include.pro )
32} 32}
33 33
34contains( platform, x11 ) { 34contains( platform, x11 ) {
35 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 35 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
36} 36}
37 37
38!isEmpty( LIBSQLITE_INC_DIR ) { 38!isEmpty( LIBSQLITE_INC_DIR ) {
39 INCLUDEPATH = $$LIBSQLITE_INC_DIR $$INCLUDEPATH 39 INCLUDEPATH = $$LIBSQLITE_INC_DIR $$INCLUDEPATH
40} 40}
41!isEmpty( LIBSQLITE_LIB_DIR ) { 41!isEmpty( LIBSQLITE_LIB_DIR ) {
42 LIBS = -L$$LIBSQLITE_LIB_DIR $$LIBS 42 LIBS = -L$$LIBSQLITE_LIB_DIR $$LIBS
43} 43}
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index c8b560f..816223e 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -58,163 +58,167 @@ OSQLiteDriver::OSQLiteDriver( QLibrary *lib )
58 58
59OSQLiteDriver::~OSQLiteDriver() { 59OSQLiteDriver::~OSQLiteDriver() {
60 close(); 60 close();
61} 61}
62 62
63 63
64QString OSQLiteDriver::id()const { 64QString OSQLiteDriver::id()const {
65 return QString::fromLatin1("SQLite"); 65 return QString::fromLatin1("SQLite");
66} 66}
67 67
68void OSQLiteDriver::setUserName( const QString& ) {} 68void OSQLiteDriver::setUserName( const QString& ) {}
69 69
70 70
71void OSQLiteDriver::setPassword( const QString& ) {} 71void OSQLiteDriver::setPassword( const QString& ) {}
72 72
73 73
74void OSQLiteDriver::setUrl( const QString& url ) { 74void OSQLiteDriver::setUrl( const QString& url ) {
75 m_url = url; 75 m_url = url;
76} 76}
77 77
78 78
79void OSQLiteDriver::setOptions( const QStringList& ) { 79void OSQLiteDriver::setOptions( const QStringList& ) {
80} 80}
81 81
82/* 82/*
83 * Functions to patch a regex search into sqlite 83 * Functions to patch a regex search into sqlite
84 */ 84 */
85int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ 85int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){
86 int res; 86 int res;
87 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ 87 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){
88 if (reg->regex_raw != NULL) { 88 if (reg->regex_raw != NULL) {
89 free(reg->regex_raw); 89 free(reg->regex_raw);
90 regfree(&reg->regex_c); 90 regfree(&reg->regex_c);
91 } 91 }
92 reg->regex_raw = (char *)malloc(strlen(zPattern)+1); 92 reg->regex_raw = (char *)malloc(strlen(zPattern)+1);
93 strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1); 93 strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1);
94 res = regcomp(&reg->regex_c, zPattern, REG_EXTENDED); 94 res = regcomp(&reg->regex_c, zPattern, REG_EXTENDED);
95 if ( res != 0 ) { 95 if ( res != 0 ) {
96 printf("Regcomp failed with code %u on string %s\n",res,zPattern); 96 printf("Regcomp failed with code %u on string %s\n",res,zPattern);
97 free(reg->regex_raw); 97 free(reg->regex_raw);
98 reg->regex_raw=NULL; 98 reg->regex_raw=NULL;
99 return 0; 99 return 0;
100 } 100 }
101 } 101 }
102 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0); 102 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0);
103 return res; 103 return res;
104} 104}
105 105
106void rlikeFunc(sqlite_func *context, int arg, const char **argv){ 106void rlikeFunc( sqlite3_context* context, int count, sqlite3_value** values ){
107 if( arg < 2 || argv[0]==0 || argv[1]==0 ){ 107 const unsigned char* argv0 = sqlite3_value_text( values[0] );
108 printf("One of arguments Null!!\n"); 108 const unsigned char* argv1 = sqlite3_value_text( values[1] );
109 if( count < 2 || argv0 == 0 || argv1 == 0 ){
110 qWarning( "One of arguments Null!!\n" );
109 return; 111 return;
110 } 112 }
111 sqlite_set_result_int(context, 113 sqlite3_result_int(context, sqliteRlikeCompare((const char*)argv0,
112 sqliteRlikeCompare((const char*)argv[0], 114 (const char*)argv1,
113 (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); 115 (sqregex *) sqlite3_user_data( context ) ));
114} 116}
115 117
116/* 118/*
117 * try to open a db specified via setUrl 119 * try to open a db specified via setUrl
118 * and options 120 * and options
119 */ 121 */
120bool OSQLiteDriver::open() { 122bool OSQLiteDriver::open() {
121 char *error;
122
123 odebug << "OSQLiteDriver::open: about to open" << oendl; 123 odebug << "OSQLiteDriver::open: about to open" << oendl;
124 m_sqlite = sqlite_open(m_url.local8Bit(), 124
125 0, 125 int error = sqlite3_open( m_url.utf8(),
126 &error ); 126 &m_sqlite );
127 127
128 /* failed to open */ 128 /* failed to open */
129 if (m_sqlite == 0l ) { 129 if ( error != SQLITE_OK ) {
130 // FIXME set the last error 130 // FIXME set the last error
131 owarn << "OSQLiteDriver::open: " << error << "" << oendl; 131 owarn << "OSQLiteDriver::open: " << error << "" << oendl;
132 free( error ); 132 sqlite3_close( m_sqlite );
133 return false; 133 return false;
134 } 134 }
135 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) 135 if ( sqlite3_create_function( m_sqlite, "rlike", 2, SQLITE_UTF8, &sqreg, rlikeFunc, NULL, NULL ) != SQLITE_OK ){
136 odebug << "Unable to create user defined function!" << oendl; 136 odebug << "Unable to create user defined function!" << oendl;
137 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) 137 return false;
138 odebug << "Unable to set rlike function result type!" << oendl; 138 }
139
139 sqreg.regex_raw = NULL; 140 sqreg.regex_raw = NULL;
141
140 return true; 142 return true;
141} 143}
142 144
143 145
144/* close the db 146/* close the db
145 * sqlite closes them without 147 * sqlite closes them without
146 * telling failure or success 148 * telling failure or success
147 */ 149 */
148bool OSQLiteDriver::close() { 150bool OSQLiteDriver::close() {
149 if (m_sqlite ) 151 if ( m_sqlite ){
150 sqlite_close( m_sqlite ), m_sqlite=0l; 152 sqlite3_close( m_sqlite );
153 m_sqlite=0l;
154 }
151 if (sqreg.regex_raw != NULL){ 155 if (sqreg.regex_raw != NULL){
152 odebug << "Freeing regex on close" << oendl; 156 odebug << "Freeing regex on close" << oendl;
153 free(sqreg.regex_raw); 157 free(sqreg.regex_raw);
154 sqreg.regex_raw=NULL; 158 sqreg.regex_raw=NULL;
155 regfree(&sqreg.regex_c); 159 regfree(&sqreg.regex_c);
156 } 160 }
157 return true; 161 return true;
158} 162}
159 163
160 164
161/* Query */ 165/* Query */
162OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 166OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
163 if ( !m_sqlite ) { 167 if ( !m_sqlite ) {
164 // FIXME set error code 168 // FIXME set error code
165 OSQLResult result( OSQLResult::Failure ); 169 OSQLResult result( OSQLResult::Failure );
166 return result; 170 return result;
167 } 171 }
168 Query query; 172 Query query;
169 query.driver = this; 173 query.driver = this;
170 char *err; 174 char *err;
171 /* SQLITE_OK 0 if return code > 0 == failure */ 175 /* SQLITE_OK 0 if return code > 0 == failure */
172 if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { 176 if ( sqlite3_exec( m_sqlite, qu->query().utf8(), &call_back, &query, &err ) > SQLITE_OK ) {
173 owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; 177 owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl;
174 free( err ); 178 free( err );
175 // FixMe Errors 179 // FixMe Errors
176 } 180 }
177 181
178 OSQLResult result(OSQLResult::Success, 182 OSQLResult result(OSQLResult::Success,
179 query.items, 183 query.items,
180 query.errors ); 184 query.errors );
181 return result; 185 return result;
182} 186}
183 187
184 188
185OSQLTable::ValueList OSQLiteDriver::tables() const { 189OSQLTable::ValueList OSQLiteDriver::tables() const {
186 return OSQLTable::ValueList(); 190 return OSQLTable::ValueList();
187} 191}
188 192
189 193
190OSQLError OSQLiteDriver::lastError() { 194OSQLError OSQLiteDriver::lastError() {
191 OSQLError error; 195 OSQLError error;
192 return error; 196 return error;
193}; 197};
194 198
195 199
196/* handle a callback add the row to the global 200/* handle a callback add the row to the global
197 * OSQLResultItem 201 * OSQLResultItem
198 */ 202 */
199int OSQLiteDriver::handleCallBack( int, char**, char** ) { 203int OSQLiteDriver::handleCallBack( int, char**, char** ) {
200 return 0; 204 return 0;
201} 205}
202 206
203 207
204/* callback_handler add the values to the list*/ 208/* callback_handler add the values to the list*/
205int OSQLiteDriver::call_back( void* voi, int argc, 209int OSQLiteDriver::call_back( void* voi, int argc,
206 char** argv, char** columns) { 210 char** argv, char** columns) {
207 Query* qu = (Query*)voi; 211 Query* qu = (Query*)voi;
208 212
209 //copy them over to a OSQLResultItem 213 //copy them over to a OSQLResultItem
210 QMap<QString, QString> tableString; 214 QMap<QString, QString> tableString;
211 QMap<int, QString> tableInt; 215 QMap<int, QString> tableInt;
212 for (int i = 0; i < argc; i++ ) { 216 for (int i = 0; i < argc; i++ ) {
213 217
214 tableInt.insert( i, QString::fromUtf8( argv[i] ) ); 218 tableInt.insert( i, QString::fromUtf8( argv[i] ) );
215 tableString.insert( QString::fromUtf8( columns[i] ), 219 tableString.insert( QString::fromUtf8( columns[i] ),
216 QString::fromUtf8( argv[i] ) ); 220 QString::fromUtf8( argv[i] ) );
217 } 221 }
218 OSQLResultItem item( tableString, tableInt ); 222 OSQLResultItem item( tableString, tableInt );
219 qu->items.append( item ); 223 qu->items.append( item );
220 224
diff --git a/libopie2/opiedb/osqlitedriver.h b/libopie2/opiedb/osqlitedriver.h
index e38fd52..4990a11 100644
--- a/libopie2/opiedb/osqlitedriver.h
+++ b/libopie2/opiedb/osqlitedriver.h
@@ -1,51 +1,51 @@
1#ifndef OSQL_LITE_DRIVER_H 1#ifndef OSQL_LITE_DRIVER_H
2#define OSQL_LITE_DRIVER_H 2#define OSQL_LITE_DRIVER_H
3 3
4#include <sqlite.h> 4#include <sqlite3.h>
5#include <sys/types.h> 5#include <sys/types.h>
6#include <regex.h> 6#include <regex.h>
7 7
8#include "osqldriver.h" 8#include "osqldriver.h"
9#include "osqlerror.h" 9#include "osqlerror.h"
10#include "osqlresult.h" 10#include "osqlresult.h"
11 11
12namespace Opie { 12namespace Opie {
13namespace DB { 13namespace DB {
14namespace Internal { 14namespace Internal {
15 15
16struct sqregex { 16struct sqregex {
17 char *regex_raw; 17 char *regex_raw;
18 regex_t regex_c; 18 regex_t regex_c;
19}; 19};
20 20
21class OSQLiteDriver : public OSQLDriver { 21class OSQLiteDriver : public OSQLDriver {
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 OSQLiteDriver( QLibrary *lib = 0l ); 24 OSQLiteDriver( QLibrary *lib = 0l );
25 ~OSQLiteDriver(); 25 ~OSQLiteDriver();
26 QString id()const; 26 QString id()const;
27 void setUserName( const QString& ); 27 void setUserName( const QString& );
28 void setPassword( const QString& ); 28 void setPassword( const QString& );
29 void setUrl( const QString& url ); 29 void setUrl( const QString& url );
30 void setOptions( const QStringList& ); 30 void setOptions( const QStringList& );
31 bool open(); 31 bool open();
32 bool close(); 32 bool close();
33 OSQLError lastError(); 33 OSQLError lastError();
34 OSQLResult query( OSQLQuery* ); 34 OSQLResult query( OSQLQuery* );
35 OSQLTable::ValueList tables()const; 35 OSQLTable::ValueList tables()const;
36 36
37private: 37private:
38 OSQLError m_lastE; 38 OSQLError m_lastE;
39 OSQLResult m_result; 39 OSQLResult m_result;
40 OSQLResultItem m_items; 40 OSQLResultItem m_items;
41 int handleCallBack( int, char**, char** ); 41 int handleCallBack( int, char**, char** );
42 static int call_back( void*, int, char**, char** ); 42 static int call_back( void*, int, char**, char** );
43 QString m_url; 43 QString m_url;
44 sqlite *m_sqlite; 44 sqlite3 *m_sqlite;
45 sqregex sqreg; 45 sqregex sqreg;
46}; 46};
47} 47}
48} 48}
49} 49}
50 50
51#endif 51#endif
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 7ab1ea5..f936d4e 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -133,190 +133,183 @@ public:
133 * clears the backend and invalidates the backend 133 * clears the backend and invalidates the backend
134 */ 134 */
135 void clear() ; 135 void clear() ;
136 136
137 /** 137 /**
138 * add T to the backend 138 * add T to the backend
139 * @param t The item to add. 139 * @param t The item to add.
140 * @return <i>true</i> if added successfully. 140 * @return <i>true</i> if added successfully.
141 */ 141 */
142 virtual bool add( const T& t ) ; 142 virtual bool add( const T& t ) ;
143 143
144 bool add( const OPimRecord& ); 144 bool add( const OPimRecord& );
145 /** 145 /**
146 * Add an Opie PimRecord. 146 * Add an Opie PimRecord.
147 * Info: Take this if you are working with OPimRecords and you need to add it into any database. 147 * Info: Take this if you are working with OPimRecords and you need to add it into any database.
148 * But take care that the accessing database is compatible to the real type of OPimRecord !! 148 * But take care that the accessing database is compatible to the real type of OPimRecord !!
149 * Otherwise this access will be rejected ! 149 * Otherwise this access will be rejected !
150 */ 150 */
151 bool add( const OPimRecord* ); 151 bool add( const OPimRecord* );
152 152
153 153
154 /* only the uid matters */ 154 /* only the uid matters */
155 /** 155 /**
156 * remove T from the backend 156 * remove T from the backend
157 * @param t The item to remove 157 * @param t The item to remove
158 * @return <i>true</i> if successful. 158 * @return <i>true</i> if successful.
159 */ 159 */
160 virtual bool remove( const T& t ); 160 virtual bool remove( const T& t );
161 161
162 /** 162 /**
163 * remove the OPimRecord with uid 163 * remove the OPimRecord with uid
164 * @param uid The ID of the item to remove 164 * @param uid The ID of the item to remove
165 * @return <i>true</i> if successful. 165 * @return <i>true</i> if successful.
166 */ 166 */
167 bool remove( int uid ); 167 bool remove( int uid );
168 bool remove( const OPimRecord& ); 168 bool remove( const OPimRecord& );
169 169
170 /** 170 /**
171 * replace T from backend 171 * replace T from backend
172 * @param t The item to replace 172 * @param t The item to replace
173 * @return <i>true</i> if successful. 173 * @return <i>true</i> if successful.
174 */ 174 */
175 virtual bool replace( const T& t) ; 175 virtual bool replace( const T& t) ;
176 176
177 void setReadAhead( uint count ); 177 void setReadAhead( uint count );
178 /** 178 /**
179 * @internal 179 * @internal
180 */ 180 */
181 virtual T cacheFind( int uid )const;
182 void cache( const T& )const; 181 void cache( const T& )const;
183 void setSaneCacheSize( int ); 182 void setSaneCacheSize( int );
184 183
185 QArray<int> records()const; 184 QArray<int> records()const;
186protected: 185protected:
187 /** 186 /**
188 * invalidate the cache 187 * invalidate the cache
189 */ 188 */
190 void invalidateCache(); 189 void invalidateCache();
191 190
192 void setBackEnd( BackEnd* end ); 191 void setBackEnd( BackEnd* end );
193 /** 192 /**
194 * returns the backend 193 * returns the backend
195 */ 194 */
196 BackEnd* backEnd(); 195 BackEnd* backEnd();
197 BackEnd* m_backEnd; 196 BackEnd* m_backEnd;
198 197
199 Cache m_cache; 198 Cache m_cache;
200 199
201private: 200private:
202 OPimAccessTemplatePrivate *d; 201 OPimAccessTemplatePrivate *d;
203 202
204}; 203};
205 204
206template <class T> 205template <class T>
207OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 206OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
208 : OTemplateBase<T>(), m_backEnd( end ) 207 : OTemplateBase<T>(), m_backEnd( end )
209{ 208{
210 if (end ) 209 if (end )
211 end->setFrontend( this ); 210 end->setFrontend( this );
212} 211}
213template <class T> 212template <class T>
214OPimAccessTemplate<T>::~OPimAccessTemplate() { 213OPimAccessTemplate<T>::~OPimAccessTemplate() {
215 owarn << "~OPimAccessTemplate<T>" << oendl; 214 owarn << "~OPimAccessTemplate<T>" << oendl;
216 delete m_backEnd; 215 delete m_backEnd;
217} 216}
218template <class T> 217template <class T>
219bool OPimAccessTemplate<T>::load() { 218bool OPimAccessTemplate<T>::load() {
220 invalidateCache(); 219 invalidateCache();
221 return m_backEnd->load(); 220 return m_backEnd->load();
222} 221}
223template <class T> 222template <class T>
224bool OPimAccessTemplate<T>::reload() { 223bool OPimAccessTemplate<T>::reload() {
225 invalidateCache(); 224 invalidateCache();
226 return m_backEnd->reload(); 225 return m_backEnd->reload();
227} 226}
228template <class T> 227template <class T>
229bool OPimAccessTemplate<T>::save() { 228bool OPimAccessTemplate<T>::save() {
230 return m_backEnd->save(); 229 return m_backEnd->save();
231} 230}
232template <class T> 231template <class T>
233typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 232typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
234 QArray<int> ints = m_backEnd->allRecords(); 233 QArray<int> ints = m_backEnd->allRecords();
235 List lis(ints, this ); 234 List lis(ints, this );
236 return lis; 235 return lis;
237} 236}
238template <class T> 237template <class T>
239typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { 238typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
240 QArray<int> ints = m_backEnd->matchRegexp( r ); 239 QArray<int> ints = m_backEnd->matchRegexp( r );
241 List lis(ints, this ); 240 List lis(ints, this );
242 return lis; 241 return lis;
243} 242}
244template <class T> 243template <class T>
245QArray<int> OPimAccessTemplate<T>::records()const { 244QArray<int> OPimAccessTemplate<T>::records()const {
246 return m_backEnd->allRecords(); 245 return m_backEnd->allRecords();
247} 246}
248template <class T> 247template <class T>
249typename OPimAccessTemplate<T>::List 248typename OPimAccessTemplate<T>::List
250OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 249OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
251 QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); 250 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
252 251
253 List lis(ints, this ); 252 List lis(ints, this );
254 return lis; 253 return lis;
255} 254}
256template <class T> 255template <class T>
257T OPimAccessTemplate<T>::find( int uid ) const{ 256T OPimAccessTemplate<T>::find( int uid ) const{
258 // First search in cache.. 257 // First search in cache..
259 if ( m_cache.contains( uid ) ) 258 if ( m_cache.contains( uid ) )
260 return m_cache.find( uid ); 259 return m_cache.find( uid );
261 260
262 T t = m_backEnd->find( uid ); 261 T t = m_backEnd->find( uid );
263 cache( t ); 262 cache( t );
264 263
265 return t; 264 return t;
266} 265}
267 266
268template <class T> 267template <class T>
269T OPimAccessTemplate<T>::cacheFind( int uid ) const
270{
271 return m_cache.find( uid );
272}
273
274template <class T>
275T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 268T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
276 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 269 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
277 /* 270 /*
278 * better do T.isEmpty() 271 * better do T.isEmpty()
279 * after a find this way we would 272 * after a find this way we would
280 * avoid two finds in QCache... 273 * avoid two finds in QCache...
281 */ 274 */
282 // owarn << "find it now " << uid << oendl; 275 // owarn << "find it now " << uid << oendl;
283 if ( m_cache.contains( uid ) ) { 276 if ( m_cache.contains( uid ) ) {
284 return m_cache.find( uid ); 277 return m_cache.find( uid );
285 } 278 }
286 279
287 T t = m_backEnd->find( uid, ar, current, dir ); 280 T t = m_backEnd->find( uid, ar, current, dir );
288 cache( t ); 281 cache( t );
289 return t; 282 return t;
290} 283}
291template <class T> 284template <class T>
292void OPimAccessTemplate<T>::clear() { 285void OPimAccessTemplate<T>::clear() {
293 invalidateCache(); 286 invalidateCache();
294 m_backEnd->clear(); 287 m_backEnd->clear();
295} 288}
296template <class T> 289template <class T>
297bool OPimAccessTemplate<T>::add( const T& t ) { 290bool OPimAccessTemplate<T>::add( const T& t ) {
298 cache( t ); 291 cache( t );
299 return m_backEnd->add( t ); 292 return m_backEnd->add( t );
300} 293}
301 294
302template <class T> 295template <class T>
303bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { 296bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) {
304 /* same type */ 297 /* same type */
305 T tempInstance; 298 T tempInstance;
306 if ( rec.rtti() == tempInstance.rtti() ) { 299 if ( rec.rtti() == tempInstance.rtti() ) {
307 const T& t = static_cast<const T&>(rec); 300 const T& t = static_cast<const T&>(rec);
308 return add(t); 301 return add(t);
309 } else { 302 } else {
310 owarn << "Adding not possible: Objecttype mismatch" << oendl; 303 owarn << "Adding not possible: Objecttype mismatch" << oendl;
311 } 304 }
312 return false; 305 return false;
313} 306}
314 307
315template <class T> 308template <class T>
316bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { 309bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
317 /* same type, but pointer */ 310 /* same type, but pointer */
318 T tempInstance; 311 T tempInstance;
319 if ( rec -> rtti() == tempInstance.rtti() ) { 312 if ( rec -> rtti() == tempInstance.rtti() ) {
320 const T* t = static_cast<const T*>(rec); 313 const T* t = static_cast<const T*>(rec);
321 return add( *t ); 314 return add( *t );
322 } else { 315 } else {
diff --git a/libopie2/opiepim/core/opimcontactfields.h b/libopie2/opiepim/core/opimcontactfields.h
index 3aa3894..2e42951 100644
--- a/libopie2/opiepim/core/opimcontactfields.h
+++ b/libopie2/opiepim/core/opimcontactfields.h
@@ -1,51 +1,51 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) Stefan Eielrs <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OCONTACTFIELDS_H 30#ifndef OCONTACTFIELDS_H
31#define OCONTACTFIELDS_H 31#define OCONTACTFIELDS_H
32 32
33class QStringList; 33class QStringList;
34 34
35/* OPIE */ 35/* OPIE */
36#include <opie2/opimcontact.h> 36#include <opie2/opimcontact.h>
37 37
38/* QT */ 38/* QT */
39#include <qmap.h> 39#include <qmap.h>
40#include <qstring.h> 40#include <qstring.h>
41 41
42#define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" 42#define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order"
43#define DEFAULT_FIELD_ORDER "__________" 43#define DEFAULT_FIELD_ORDER "__________"
44 44
45namespace Opie 45namespace Opie
46{ 46{
47class OPimContactFields 47class OPimContactFields
48{ 48{
49 49
50 public: 50 public:
51 OPimContactFields(); 51 OPimContactFields();
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
index ec9a94e..787486c 100644
--- a/libopie2/opiepim/core/opimtemplatebase.h
+++ b/libopie2/opiepim/core/opimtemplatebase.h
@@ -48,89 +48,83 @@ namespace Opie {
48class OPimBasePrivate; 48class OPimBasePrivate;
49struct OPimBase { 49struct OPimBase {
50 /** 50 /**
51 * return the rtti 51 * return the rtti
52 */ 52 */
53 virtual int rtti() const = 0; 53 virtual int rtti() const = 0;
54 virtual OPimRecord* record()const = 0; 54 virtual OPimRecord* record()const = 0;
55 virtual OPimRecord* record(int uid)const = 0; 55 virtual OPimRecord* record(int uid)const = 0;
56 virtual bool add( const OPimRecord& ) = 0; 56 virtual bool add( const OPimRecord& ) = 0;
57 virtual bool add( const OPimRecord* ) = 0; 57 virtual bool add( const OPimRecord* ) = 0;
58 virtual bool remove( int uid ) = 0; 58 virtual bool remove( int uid ) = 0;
59 virtual bool remove( const OPimRecord& ) = 0; 59 virtual bool remove( const OPimRecord& ) = 0;
60 virtual void clear() = 0; 60 virtual void clear() = 0;
61 virtual bool load() = 0; 61 virtual bool load() = 0;
62 virtual bool save() = 0; 62 virtual bool save() = 0;
63 virtual QArray<int> records()const = 0; 63 virtual QArray<int> records()const = 0;
64 /* 64 /*
65 * ADD editing here? 65 * ADD editing here?
66 * -zecke 66 * -zecke
67 */ 67 */
68private: 68private:
69 OPimBasePrivate* d; 69 OPimBasePrivate* d;
70 70
71}; 71};
72/** 72/**
73 * internal template base 73 * internal template base
74 * Attention: T needs to implement the copy c'tor!!! 74 * Attention: T needs to implement the copy c'tor!!!
75 */ 75 */
76class OTemplateBasePrivate; 76class OTemplateBasePrivate;
77template <class T = OPimRecord> 77template <class T = OPimRecord>
78class OTemplateBase : public OPimBase { 78class OTemplateBase : public OPimBase {
79public: 79public:
80 /** Look ahead direction of cache */ 80 /** Look ahead direction of cache */
81 enum CacheDirection { Forward=0, Reverse }; 81 enum CacheDirection { Forward=0, Reverse };
82 82
83 OTemplateBase() { 83 OTemplateBase() {
84 }; 84 };
85 virtual ~OTemplateBase() { 85 virtual ~OTemplateBase() {
86 } 86 }
87 virtual T find( int uid )const = 0; 87 virtual T find( int uid )const = 0;
88 88
89 /** 89 /**
90 * read ahead find 90 * read ahead find
91 */ 91 */
92 virtual T find( int uid, const QArray<int>& items, 92 virtual T find( int uid, const QArray<int>& items,
93 uint current, CacheDirection dir = Forward )const = 0; 93 uint current, CacheDirection dir = Forward )const = 0;
94 94
95 /** 95 /**
96 * Find in Cache..
97 * Returns empty object if nothing found.
98 */
99 virtual T cacheFind( int uid )const = 0;
100
101 /**
102 * Put element into Cache 96 * Put element into Cache
103 */ 97 */
104 virtual void cache( const T& )const = 0; 98 virtual void cache( const T& )const = 0;
105 virtual void setSaneCacheSize( int ) = 0; 99 virtual void setSaneCacheSize( int ) = 0;
106 100
107 OPimRecord* record()const; 101 OPimRecord* record()const;
108 OPimRecord* record(int uid )const; 102 OPimRecord* record(int uid )const;
109 static T* rec(); 103 static T* rec();
110 104
111 105
112private: 106private:
113 OTemplateBasePrivate *d; 107 OTemplateBasePrivate *d;
114}; 108};
115 109
116 110
117template <class T> 111template <class T>
118OPimRecord* OTemplateBase<T>::record()const { 112OPimRecord* OTemplateBase<T>::record()const {
119 T* t = new T; 113 T* t = new T;
120 return t; 114 return t;
121} 115}
122template <class T> 116template <class T>
123OPimRecord* OTemplateBase<T>::record(int uid )const { 117OPimRecord* OTemplateBase<T>::record(int uid )const {
124 T t2 = find(uid ); 118 T t2 = find(uid );
125 T* t1 = new T(t2); 119 T* t1 = new T(t2);
126 120
127 return t1; 121 return t1;
128}; 122};
129template <class T> 123template <class T>
130T* OTemplateBase<T>::rec() { 124T* OTemplateBase<T>::rec() {
131 return new T; 125 return new T;
132} 126}
133 127
134} 128}
135 129
136#endif 130#endif