-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.h | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 28 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.h | 6 |
9 files changed, 65 insertions, 15 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 401a3c1..14207be 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp @@ -425,16 +425,17 @@ QArray<int> OPimContactAccessBackend_SQL::allRecords() const if ( m_changed ) ((OPimContactAccessBackend_SQL*)this)->update(); return m_uids; } bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) { + qDebug("add in contact SQL-Backend"); InsertQuery ins( newcontact ); OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; int c = m_uids.count(); m_uids.resize( c+1 ); diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 4f9b504..67f267f 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp @@ -47,16 +47,17 @@ #include <qpe/global.h> #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <opie2/ocontactaccessbackend_xml.h> +#include <opie2/opimresolver.h> namespace Opie { OPimContactAccess::OPimContactAccess ( const QString appname, const QString , OPimContactAccessBackend* end, bool autosync ): OPimAccessTemplate<OPimContact>( end ) { /* take care of the backend. If there is no one defined, we @@ -144,9 +145,14 @@ void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) save (); } else if ( msg == "reload()" ) { qWarning ("OPimContactAccess: Received reload()"); reload (); emit signalChanged ( this ); } } +int OPimContactAccess::rtti() const +{ + return OPimResolver::AddressBook; +} + } diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index cf5333a..4429b6f 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h @@ -122,16 +122,21 @@ class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> bool wasChangedExternally()const; /** Save contacts database. * Save is more a "commit". After calling this function, all changes are public available. * @return true if successful */ bool save(); + + /** + * Return identification of used records + */ + int rtti() const; signals: /* Signal is emitted if the database was changed. Therefore * we may need to reload to stay consistent. * @param which Pointer to the database who created this event. This pointer * is useful if an application has to handle multiple databases at the same time. * @see reload() */ diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index ac310c1..29298ea 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp @@ -23,16 +23,17 @@ -_. . . )=. = 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 <opie2/obackendfactory.h> #include <opie2/odatebookaccess.h> +#include <opie2/opimresolver.h> namespace Opie { /** * Simple constructor * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation * will be used! * @param back The backend to be used or 0 for the default backend * @param ac What kind of access is intended @@ -103,10 +104,14 @@ OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const Q return m_backEnd->effectiveNonRepeatingEvents( from, to ); } /** * @return all non repeating events at a given datetime */ OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { return m_backEnd->effectiveNonRepeatingEvents( start ); } +int ODateBookAccess::rtti() const +{ + return OPimResolver::DateBook; +} } diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h index 6c9290f..c6c3598 100644 --- a/libopie2/opiepim/core/odatebookaccess.h +++ b/libopie2/opiepim/core/odatebookaccess.h @@ -59,16 +59,22 @@ public: List nonRepeats()const; /* return non repeating events (from,to) */ OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; + /** + * Return identification of used records + */ + int rtti() const; + + private: ODateBookAccessBackend* m_backEnd; class Private; Private* d; }; } diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index f1bcc44..d4c5fbb 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -1,11 +1,12 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author <main-author@whereever.org> + 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, @@ -132,16 +133,23 @@ public: /** * 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& ); + // Needed for real generic access (eilers) + // Info: Take this if you are working with OPimRecord, which is a generic base class, and + // you need to add it into any database, you cannot generate a reference to + // it and casting may be not approriate, too. + // But take care that the accessing database is compatible to the real type of OPimRecord !! + 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 ); @@ -266,25 +274,39 @@ 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 */ - if ( rec.rtti() == T::rtti() ) { - const T &t = static_cast<const T&>(rec); + T tempInstance; + if ( rec.rtti() == tempInstance.rtti() ) { + const T& t = static_cast<const T&>(rec); return add(t); } 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 ); + } + 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 ); diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index 58cbfeb..b48dfed 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h @@ -1,11 +1,11 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author <main-author@whereever.org> + 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, @@ -44,20 +44,21 @@ namespace Opie { * You may not want to use that interface internaly * POOR mans interface */ class OPimBasePrivate; struct OPimBase { /** * return the rtti */ - virtual int rtti()= 0; + 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? @@ -85,34 +86,25 @@ public: /** * read ahead find */ virtual T find( int uid, const QArray<int>& items, uint current, CacheDirection dir = Forward )const = 0; virtual void cache( const T& )const = 0; virtual void setSaneCacheSize( int ) = 0; - /* reimplement of OPimBase */ - int rtti(); OPimRecord* record()const; OPimRecord* record(int uid )const; static T* rec(); private: OTemplateBasePrivate *d; }; -/* - * implementation - */ -template <class T> -int -OTemplateBase<T>::rtti() { - return T::rtti(); -} + 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 ); diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 83750d5..6fa0089 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp @@ -28,16 +28,17 @@ */ #include <qdatetime.h> #include <qpe/alarmserver.h> // #include "otodoaccesssql.h" #include <opie2/otodoaccess.h> #include <opie2/obackendfactory.h> +#include <opie2/opimresolver.h> namespace Opie { OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) { // if (end == 0l ) // m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); @@ -85,9 +86,15 @@ void OPimTodoAccess::removeAllCompleted() { } QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ return m_todoBackEnd->supports(); } bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ return backendSupport(ar).testBit( attr ); } + +int OPimTodoAccess::rtti() const +{ + return OPimResolver::TodoList; +} + } diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index 51f3793..3f5af30 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h @@ -111,16 +111,22 @@ public: QBitArray backendSupport( const QString& backend = QString::null )const; /** * see above but for a specefic attribute. This method was added for convience * @param attr The attribute to be queried for * @param backend Will be used in the future when we support multiple backends */ bool backendSupports( int attr, const QString& backend = QString::null )const; + + + /** + * Return identification of used records + */ + int rtti() const; signals: /** * if the OPimTodoAccess was changed */ void changed( const OPimTodoAccess* ); void changed( const OPimTodoAccess*, int uid ); void added( const OPimTodoAccess*, int uid ); void removed( const OPimTodoAccess*, int uid ); |