-rw-r--r-- | libopie2/opiedb/config.in | 2 | ||||
-rw-r--r-- | libopie2/opiedb/libopiedb2.control | 4 | ||||
-rw-r--r-- | libopie2/opiedb/opiedb.pro | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 98 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimcontactfields.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 6 |
8 files changed, 58 insertions, 67 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 @@ config LIBOPIE2DB boolean "libopie2db (database related classes)" default "y" depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP - comment "libopie2db needs a libqpe, sqlite and libopie2core" + comment "libopie2db needs a libqpe, libsqlite3 and libopie2core" depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP) 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 @@ Package: libopiedb2 Files: lib/libopiedb2.so* Priority: optional Section: opie/system Maintainer: Opie Team <opie@handhelds.org> Architecture: arm Version: 1.8.2-$SUB_VERSION.2 -Depends: libqpe1, libopiecore2 (1.8.2), libsqlite0 | sqlite +Depends: libqpe1, libopiecore2 (1.8.2), libsqlite3 | sqlite3 Provides: libopiedb2 -Description: Opie library 2.0 DB +Description: 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 @@ TEMPLATE = lib CONFIG += qt warn_on DESTDIR = $(OPIEDIR)/lib HEADERS = osqlbackend.h \ osqldriver.h \ osqlerror.h \ osqlmanager.h \ osqlquery.h \ osqlresult.h \ osqltable.h \ osqlbackendmanager.h \ osqlitedriver.h SOURCES = osqlbackend.cpp \ osqldriver.cpp \ osqlerror.cpp \ osqlmanager.cpp \ osqlquery.cpp \ osqlresult.cpp \ osqltable.cpp \ osqlbackendmanager.cpp \ osqlitedriver.cpp TARGET = opiedb2 VERSION = 1.9.0 INCLUDEPATH = $(OPIEDIR)/include DEPENDPATH = $(OPIEDIR)/include -LIBS += -lopiecore2 -lqpe -lsqlite +LIBS += -lopiecore2 -lqpe -lsqlite3 !contains( platform, x11 ) { include ( $(OPIEDIR)/include.pro ) } contains( platform, x11 ) { LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib } !isEmpty( LIBSQLITE_INC_DIR ) { INCLUDEPATH = $$LIBSQLITE_INC_DIR $$INCLUDEPATH } !isEmpty( LIBSQLITE_LIB_DIR ) { LIBS = -L$$LIBSQLITE_LIB_DIR $$LIBS } 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 @@ -1,228 +1,232 @@ /* This file is part of the Opie Project =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "osqlquery.h" #include "osqlitedriver.h" #include <opie2/odebug.h> #include <stdlib.h> #include <stdio.h> namespace Opie { namespace DB { namespace Internal { namespace { struct Query { OSQLError::ValueList errors; OSQLResultItem::ValueList items; OSQLiteDriver *driver; }; } OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) : OSQLDriver( lib ) { m_sqlite = 0l; } OSQLiteDriver::~OSQLiteDriver() { close(); } QString OSQLiteDriver::id()const { return QString::fromLatin1("SQLite"); } void OSQLiteDriver::setUserName( const QString& ) {} void OSQLiteDriver::setPassword( const QString& ) {} void OSQLiteDriver::setUrl( const QString& url ) { m_url = url; } void OSQLiteDriver::setOptions( const QStringList& ) { } /* * Functions to patch a regex search into sqlite */ int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ int res; if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ if (reg->regex_raw != NULL) { free(reg->regex_raw); regfree(®->regex_c); } reg->regex_raw = (char *)malloc(strlen(zPattern)+1); strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1); res = regcomp(®->regex_c, zPattern, REG_EXTENDED); if ( res != 0 ) { printf("Regcomp failed with code %u on string %s\n",res,zPattern); free(reg->regex_raw); reg->regex_raw=NULL; return 0; } } res = (regexec(®->regex_c, zString, 0, NULL, 0)==0); return res; } -void rlikeFunc(sqlite_func *context, int arg, const char **argv){ - if( arg < 2 || argv[0]==0 || argv[1]==0 ){ - printf("One of arguments Null!!\n"); - return; +void rlikeFunc( sqlite3_context* context, int count, sqlite3_value** values ){ + const unsigned char* argv0 = sqlite3_value_text( values[0] ); + const unsigned char* argv1 = sqlite3_value_text( values[1] ); + if( count < 2 || argv0 == 0 || argv1 == 0 ){ + qWarning( "One of arguments Null!!\n" ); + return; } - sqlite_set_result_int(context, - sqliteRlikeCompare((const char*)argv[0], - (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); + sqlite3_result_int(context, sqliteRlikeCompare((const char*)argv0, + (const char*)argv1, + (sqregex *) sqlite3_user_data( context ) )); } /* * try to open a db specified via setUrl * and options */ bool OSQLiteDriver::open() { - char *error; - odebug << "OSQLiteDriver::open: about to open" << oendl; - m_sqlite = sqlite_open(m_url.local8Bit(), - 0, - &error ); + + int error = sqlite3_open( m_url.utf8(), + &m_sqlite ); /* failed to open */ - if (m_sqlite == 0l ) { + if ( error != SQLITE_OK ) { // FIXME set the last error owarn << "OSQLiteDriver::open: " << error << "" << oendl; - free( error ); + sqlite3_close( m_sqlite ); return false; } - if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) - odebug << "Unable to create user defined function!" << oendl; - if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) - odebug << "Unable to set rlike function result type!" << oendl; + if ( sqlite3_create_function( m_sqlite, "rlike", 2, SQLITE_UTF8, &sqreg, rlikeFunc, NULL, NULL ) != SQLITE_OK ){ + odebug << "Unable to create user defined function!" << oendl; + return false; + } + sqreg.regex_raw = NULL; + return true; } /* close the db * sqlite closes them without * telling failure or success */ bool OSQLiteDriver::close() { - if (m_sqlite ) - sqlite_close( m_sqlite ), m_sqlite=0l; - if (sqreg.regex_raw != NULL){ - odebug << "Freeing regex on close" << oendl; - free(sqreg.regex_raw); - sqreg.regex_raw=NULL; - regfree(&sqreg.regex_c); - } - return true; + if ( m_sqlite ){ + sqlite3_close( m_sqlite ); + m_sqlite=0l; + } + if ( sqreg.regex_raw != NULL){ + odebug << "Freeing regex on close" << oendl; + free( sqreg.regex_raw ); + sqreg.regex_raw = NULL; + regfree( &sqreg.regex_c ); + } + return true; } /* Query */ OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { - if ( !m_sqlite ) { - // FIXME set error code - OSQLResult result( OSQLResult::Failure ); - return result; - } - Query query; - query.driver = this; - char *err; - /* SQLITE_OK 0 if return code > 0 == failure */ - if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { - owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; - free( err ); - // FixMe Errors - } - - OSQLResult result(OSQLResult::Success, - query.items, - query.errors ); - return result; + if ( !m_sqlite ) { + // FIXME set error code + OSQLResult result( OSQLResult::Failure ); + return result; + } + Query query; + query.driver = this; + char *err; + /* SQLITE_OK 0 if return code > 0 == failure */ + if ( sqlite3_exec( m_sqlite, qu->query().utf8(), &call_back, &query, &err ) > SQLITE_OK ) { + owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; + free( err ); + // FixMe Errors + } + + OSQLResult result(OSQLResult::Success, + query.items, + query.errors ); + return result; } OSQLTable::ValueList OSQLiteDriver::tables() const { return OSQLTable::ValueList(); } OSQLError OSQLiteDriver::lastError() { OSQLError error; return error; }; /* handle a callback add the row to the global * OSQLResultItem */ int OSQLiteDriver::handleCallBack( int, char**, char** ) { return 0; } /* callback_handler add the values to the list*/ int OSQLiteDriver::call_back( void* voi, int argc, - char** argv, char** columns) { + char** argv, char** columns ) { Query* qu = (Query*)voi; //copy them over to a OSQLResultItem QMap<QString, QString> tableString; QMap<int, QString> tableInt; for (int i = 0; i < argc; i++ ) { tableInt.insert( i, QString::fromUtf8( argv[i] ) ); tableString.insert( QString::fromUtf8( columns[i] ), QString::fromUtf8( argv[i] ) ); } OSQLResultItem item( tableString, tableInt ); qu->items.append( item ); return ((Query*)voi)->driver->handleCallBack( argc, argv, columns ); } }}} // namespace OPIE::DB::Internal 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 @@ #ifndef OSQL_LITE_DRIVER_H #define OSQL_LITE_DRIVER_H -#include <sqlite.h> +#include <sqlite3.h> #include <sys/types.h> #include <regex.h> #include "osqldriver.h" #include "osqlerror.h" #include "osqlresult.h" namespace Opie { namespace DB { namespace Internal { struct sqregex { char *regex_raw; regex_t regex_c; }; class OSQLiteDriver : public OSQLDriver { Q_OBJECT public: OSQLiteDriver( QLibrary *lib = 0l ); ~OSQLiteDriver(); QString id()const; void setUserName( const QString& ); void setPassword( const QString& ); void setUrl( const QString& url ); void setOptions( const QStringList& ); bool open(); bool close(); OSQLError lastError(); OSQLResult query( OSQLQuery* ); OSQLTable::ValueList tables()const; private: OSQLError m_lastE; OSQLResult m_result; OSQLResultItem m_items; int handleCallBack( int, char**, char** ); static int call_back( void*, int, char**, char** ); QString m_url; - sqlite *m_sqlite; + sqlite3 *m_sqlite; sqregex sqreg; }; } } } #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 @@ -1,380 +1,373 @@ /* This file is part of the Opie Project Copyright (C) Holger Freyther <zecke@handhelds.org> Copyright (C) Stefan Eilers <eilers.stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OPIE_PIM_ACCESS_TEMPLATE_H #define OPIE_PIM_ACCESS_TEMPLATE_H /* OPIE */ #include <opie2/opimrecord.h> #include <opie2/opimaccessbackend.h> #include <opie2/opimrecordlist.h> #include <opie2/opimtemplatebase.h> #include <opie2/odebug.h> /* QT */ #include <qarray.h> namespace Opie { class OPimAccessTemplatePrivate; /** * Thats the frontend to our OPIE PIM * Library. Either you want to use it's * interface or you want to implement * your own Access lib * Just create a OPimRecord and inherit from * the templates */ template <class T = OPimRecord > class OPimAccessTemplate : public OTemplateBase<T> { public: enum Access { Random = 0, SortedAccess }; typedef OPimRecordList<T> List; typedef OPimAccessBackend<T> BackEnd; typedef OPimCache<T> Cache; /** * 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(); /** * 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>&, uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )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. */ 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( 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; void setSaneCacheSize( int ); QArray<int> records()const; protected: /** * invalidate the cache */ void invalidateCache(); void setBackEnd( BackEnd* end ); /** * returns the backend */ BackEnd* backEnd(); BackEnd* m_backEnd; Cache m_cache; private: OPimAccessTemplatePrivate *d; }; template <class T> OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) : OTemplateBase<T>(), m_backEnd( end ) { if (end ) end->setFrontend( this ); } template <class T> OPimAccessTemplate<T>::~OPimAccessTemplate() { owarn << "~OPimAccessTemplate<T>" << oendl; delete m_backEnd; } template <class T> bool OPimAccessTemplate<T>::load() { invalidateCache(); return m_backEnd->load(); } template <class T> bool OPimAccessTemplate<T>::reload() { invalidateCache(); return m_backEnd->reload(); } template <class T> bool OPimAccessTemplate<T>::save() { return m_backEnd->save(); } template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { QArray<int> ints = m_backEnd->allRecords(); List lis(ints, this ); return lis; } template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { QArray<int> ints = m_backEnd->matchRegexp( r ); List lis(ints, this ); return lis; } template <class T> QArray<int> OPimAccessTemplate<T>::records()const { return m_backEnd->allRecords(); } template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); List lis(ints, this ); return lis; } template <class T> T OPimAccessTemplate<T>::find( int uid ) const{ // First search in cache.. if ( m_cache.contains( uid ) ) return m_cache.find( uid ); T t = m_backEnd->find( uid ); cache( t ); return t; } template <class T> -T OPimAccessTemplate<T>::cacheFind( int uid ) const -{ - return m_cache.find( uid ); -} - -template <class T> T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, uint current, typename OTemplateBase<T>::CacheDirection dir )const { /* * better do T.isEmpty() * after a find this way we would * avoid two finds in QCache... */ // owarn << "find it now " << uid << oendl; if ( m_cache.contains( uid ) ) { return m_cache.find( uid ); } T t = m_backEnd->find( uid, ar, current, dir ); 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 ); } template <class T> bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { /* same type */ T tempInstance; if ( rec.rtti() == tempInstance.rtti() ) { const T& t = static_cast<const T&>(rec); return add(t); } else { owarn << "Adding not possible: Objecttype mismatch" << oendl; } return false; } template <class T> bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { /* same type, but pointer */ T tempInstance; if ( rec -> rtti() == tempInstance.rtti() ) { const T* t = static_cast<const T*>(rec); return add( *t ); } else { owarn << "Adding not possible: Objecttype mismatch" << oendl; } return false; } template <class T> bool OPimAccessTemplate<T>::remove( const T& t ) { return remove( t.uid() ); } template <class T> bool OPimAccessTemplate<T>::remove( int uid ) { m_cache.remove( uid ); return m_backEnd->remove( uid ); } template <class T> bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { return remove( rec.uid() ); } template <class T> bool OPimAccessTemplate<T>::replace( const T& t ) { m_cache.replace( t ); return m_backEnd->replace( t ); } template <class T> void OPimAccessTemplate<T>::invalidateCache() { m_cache.invalidate(); } template <class T> typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { return m_backEnd; } template <class T> bool OPimAccessTemplate<T>::wasChangedExternally()const { return false; } template <class T> void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { m_backEnd = end; if (m_backEnd ) m_backEnd->setFrontend( this ); } template <class T> void OPimAccessTemplate<T>::cache( const T& t ) const{ /* hacky we need to work around the const*/ ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); } template <class T> void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { m_cache.setSize( size ); } template <class T> void OPimAccessTemplate<T>::setReadAhead( uint count ) { m_backEnd->setReadAhead( count ); } } #endif 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,102 +1,102 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author <main-author@whereever.org> + Copyright (C) Stefan Eielrs <eilers.stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OCONTACTFIELDS_H #define OCONTACTFIELDS_H class QStringList; /* OPIE */ #include <opie2/opimcontact.h> /* QT */ #include <qmap.h> #include <qstring.h> #define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" #define DEFAULT_FIELD_ORDER "__________" namespace Opie { class OPimContactFields { public: OPimContactFields(); ~OPimContactFields(); /** Set the index for combo boxes. * Sets the <b>index</b> of combo <b>num</b>. * @param num selects the number of the combo * @param index sets the index in the combo */ void setFieldOrder( int num, int index ); /** Get the index for combo boxes. * Returns the index of combo <b>num</b> or defindex * if none was defined.. * @param num Selects the number of the combo * @param defIndex will be returned if none was defined (either * globally in the config file, nor by the contact which was used * by loadFromRecord() ) */ int getFieldOrder( int num, int defIndex ); /** Store fieldorder to contact. */ void saveToRecord( OPimContact& ); /** Get Fieldorder from contact. */ void loadFromRecord( const OPimContact& ); private: QString fieldOrder; QString globalFieldOrder; bool changedFieldOrder; public: static QStringList personalfields( bool sorted = true, bool translated = false ); static QStringList phonefields( bool sorted = true, bool translated = false ); static QStringList detailsfields( bool sorted = true, bool translated = false ); static QStringList fields( bool sorted = true, bool translated = false ); static QStringList trpersonalfields( bool sorted = true ); static QStringList untrpersonalfields( bool sorted = true ); static QStringList trphonefields( bool sorted = true ); static QStringList untrphonefields( bool sorted = true ); static QStringList trdetailsfields( bool sorted = true ); static QStringList untrdetailsfields( bool sorted = true ); static QStringList trfields( bool sorted = true ); static QStringList untrfields( bool sorted = true ); static QMap<int, QString> idToTrFields(); static QMap<QString, int> trFieldsToId(); static QMap<int, QString> idToUntrFields(); static QMap<QString, int> untrFieldsToId(); }; } #endif 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 @@ -1,136 +1,130 @@ /* This file is part of the Opie Project Copyright (C) Holger Freyther <zecke@handhelds.org> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OTEMPLATEBASE_H #define OTEMPLATEBASE_H /* OPIE */ #include <opie2/opimrecord.h> #include <opie2/opimcache.h> /* QT */ #include <qarray.h> namespace Opie { /** * Templates do not have a base class, This is why * we've this class * this is here to give us the possibility * to have a common base class * You may not want to use that interface internaly * POOR mans interface */ class OPimBasePrivate; struct OPimBase { /** * return the rtti */ virtual int rtti() const = 0; virtual OPimRecord* record()const = 0; virtual OPimRecord* record(int uid)const = 0; virtual bool add( const OPimRecord& ) = 0; virtual bool add( const OPimRecord* ) = 0; virtual bool remove( int uid ) = 0; virtual bool remove( const OPimRecord& ) = 0; virtual void clear() = 0; virtual bool load() = 0; virtual bool save() = 0; virtual QArray<int> records()const = 0; /* * ADD editing here? * -zecke */ private: OPimBasePrivate* d; }; /** * internal template base * Attention: T needs to implement the copy c'tor!!! */ class OTemplateBasePrivate; template <class T = OPimRecord> class OTemplateBase : public OPimBase { public: /** Look ahead direction of cache */ enum CacheDirection { Forward=0, Reverse }; OTemplateBase() { }; virtual ~OTemplateBase() { } virtual T find( int uid )const = 0; /** * read ahead find */ virtual T find( int uid, const QArray<int>& items, uint current, CacheDirection dir = Forward )const = 0; /** - * Find in Cache.. - * Returns empty object if nothing found. - */ - virtual T cacheFind( int uid )const = 0; - - /** * Put element into Cache */ virtual void cache( const T& )const = 0; virtual void setSaneCacheSize( int ) = 0; OPimRecord* record()const; OPimRecord* record(int uid )const; static T* rec(); private: OTemplateBasePrivate *d; }; template <class T> OPimRecord* OTemplateBase<T>::record()const { T* t = new T; return t; } template <class T> OPimRecord* OTemplateBase<T>::record(int uid )const { T t2 = find(uid ); T* t1 = new T(t2); return t1; }; template <class T> T* OTemplateBase<T>::rec() { return new T; } } #endif |