summaryrefslogtreecommitdiff
authoreilers <eilers>2004-04-28 09:22:02 (UTC)
committer eilers <eilers>2004-04-28 09:22:02 (UTC)
commit134b7accd6bdc8fbc160a42f7c52c585e73f4add (patch) (unidiff)
tree5e221e990d0c94e38d816e147762f205733b0e72
parent8ce67859c54234dabd88e17a0bc72369ea8301a3 (diff)
downloadopie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.zip
opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.tar.gz
opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.tar.bz2
Some modifications to alow use of generic OPimRecords without need to
cast them manually to the right type
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp1
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp6
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h5
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp5
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h6
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h28
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h16
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp7
-rw-r--r--libopie2/opiepim/core/otodoaccess.h6
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
@@ -429,8 +429,9 @@ QArray<int> OPimContactAccessBackend_SQL::allRecords() const
429} 429}
430 430
431bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) 431bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact )
432{ 432{
433 qDebug("add in contact SQL-Backend");
433 InsertQuery ins( newcontact ); 434 InsertQuery ins( newcontact );
434 OSQLResult res = m_driver->query( &ins ); 435 OSQLResult res = m_driver->query( &ins );
435 436
436 if ( res.state() == OSQLResult::Failure ) 437 if ( res.state() == OSQLResult::Failure )
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
@@ -51,8 +51,9 @@
51#include <unistd.h> 51#include <unistd.h>
52#include <stdlib.h> 52#include <stdlib.h>
53 53
54#include <opie2/ocontactaccessbackend_xml.h> 54#include <opie2/ocontactaccessbackend_xml.h>
55#include <opie2/opimresolver.h>
55 56
56namespace Opie { 57namespace Opie {
57 58
58OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 59OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
@@ -148,5 +149,10 @@ void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
148 emit signalChanged ( this ); 149 emit signalChanged ( this );
149 } 150 }
150} 151}
151 152
153int OPimContactAccess::rtti() const
154{
155 return OPimResolver::AddressBook;
156}
157
152} 158}
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
@@ -126,8 +126,13 @@ class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
126 * Save is more a "commit". After calling this function, all changes are public available. 126 * Save is more a "commit". After calling this function, all changes are public available.
127 * @return true if successful 127 * @return true if successful
128 */ 128 */
129 bool save(); 129 bool save();
130
131 /**
132 * Return identification of used records
133 */
134 int rtti() const;
130 135
131 signals: 136 signals:
132 /* Signal is emitted if the database was changed. Therefore 137 /* Signal is emitted if the database was changed. Therefore
133 * we may need to reload to stay consistent. 138 * we may need to reload to stay consistent.
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
@@ -27,8 +27,9 @@
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#include <opie2/obackendfactory.h> 29#include <opie2/obackendfactory.h>
30#include <opie2/odatebookaccess.h> 30#include <opie2/odatebookaccess.h>
31#include <opie2/opimresolver.h>
31 32
32namespace Opie { 33namespace Opie {
33/** 34/**
34 * Simple constructor 35 * Simple constructor
@@ -107,6 +108,10 @@ OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const Q
107 */ 108 */
108OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { 109OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const {
109 return m_backEnd->effectiveNonRepeatingEvents( start ); 110 return m_backEnd->effectiveNonRepeatingEvents( start );
110} 111}
112int ODateBookAccess::rtti() const
113{
114 return OPimResolver::DateBook;
115}
111 116
112} 117}
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
@@ -63,8 +63,14 @@ public:
63 OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; 63 OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const;
64 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; 64 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
65 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; 65 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const;
66 66
67 /**
68 * Return identification of used records
69 */
70 int rtti() const;
71
72
67private: 73private:
68 ODateBookAccessBackend* m_backEnd; 74 ODateBookAccessBackend* m_backEnd;
69 class Private; 75 class Private;
70 Private* d; 76 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,7 +1,8 @@
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) Holger Freyther <zecke@handhelds.org>
4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 6 .=l.
6 .>+-= 7 .>+-=
7 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
@@ -136,8 +137,15 @@ public:
136 * @return <i>true</i> if added successfully. 137 * @return <i>true</i> if added successfully.
137 */ 138 */
138 virtual bool add( const T& t ) ; 139 virtual bool add( const T& t ) ;
139 bool add( const OPimRecord& ); 140 bool add( const OPimRecord& );
141 // Needed for real generic access (eilers)
142 // Info: Take this if you are working with OPimRecord, which is a generic base class, and
143 // you need to add it into any database, you cannot generate a reference to
144 // it and casting may be not approriate, too.
145 // But take care that the accessing database is compatible to the real type of OPimRecord !!
146 bool add( const OPimRecord* );
147
140 148
141 /* only the uid matters */ 149 /* only the uid matters */
142 /** 150 /**
143 * remove T from the backend 151 * remove T from the backend
@@ -270,17 +278,31 @@ template <class T>
270bool OPimAccessTemplate<T>::add( const T& t ) { 278bool OPimAccessTemplate<T>::add( const T& t ) {
271 cache( t ); 279 cache( t );
272 return m_backEnd->add( t ); 280 return m_backEnd->add( t );
273} 281}
282
274template <class T> 283template <class T>
275bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 284bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
276 /* same type */ 285 /* same type */
277 if ( rec.rtti() == T::rtti() ) { 286 T tempInstance;
278 const T &t = static_cast<const T&>(rec); 287 if ( rec.rtti() == tempInstance.rtti() ) {
288 const T& t = static_cast<const T&>(rec);
279 return add(t); 289 return add(t);
280 } 290 }
281 return false; 291 return false;
282} 292}
293
294template <class T>
295bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
296 /* same type, but pointer */
297 T tempInstance;
298 if ( rec -> rtti() == tempInstance.rtti() ) {
299 const T* t = static_cast<const T*>(rec);
300 return add( *t );
301 }
302 return false;
303}
304
283template <class T> 305template <class T>
284bool OPimAccessTemplate<T>::remove( const T& t ) { 306bool OPimAccessTemplate<T>::remove( const T& t ) {
285 return remove( t.uid() ); 307 return remove( t.uid() );
286} 308}
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,7 +1,7 @@
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) Holger Freyther <zecke@handhelds.org>
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
@@ -48,12 +48,13 @@ class OPimBasePrivate;
48struct OPimBase { 48struct OPimBase {
49 /** 49 /**
50 * return the rtti 50 * return the rtti
51 */ 51 */
52 virtual int rtti()= 0; 52 virtual int rtti() const = 0;
53 virtual OPimRecord* record()const = 0; 53 virtual OPimRecord* record()const = 0;
54 virtual OPimRecord* record(int uid)const = 0; 54 virtual OPimRecord* record(int uid)const = 0;
55 virtual bool add( const OPimRecord& ) = 0; 55 virtual bool add( const OPimRecord& ) = 0;
56 virtual bool add( const OPimRecord* ) = 0;
56 virtual bool remove( int uid ) = 0; 57 virtual bool remove( int uid ) = 0;
57 virtual bool remove( const OPimRecord& ) = 0; 58 virtual bool remove( const OPimRecord& ) = 0;
58 virtual void clear() = 0; 59 virtual void clear() = 0;
59 virtual bool load() = 0; 60 virtual bool load() = 0;
@@ -89,26 +90,17 @@ public:
89 uint current, CacheDirection dir = Forward )const = 0; 90 uint current, CacheDirection dir = Forward )const = 0;
90 virtual void cache( const T& )const = 0; 91 virtual void cache( const T& )const = 0;
91 virtual void setSaneCacheSize( int ) = 0; 92 virtual void setSaneCacheSize( int ) = 0;
92 93
93 /* reimplement of OPimBase */
94 int rtti();
95 OPimRecord* record()const; 94 OPimRecord* record()const;
96 OPimRecord* record(int uid )const; 95 OPimRecord* record(int uid )const;
97 static T* rec(); 96 static T* rec();
98 97
99private: 98private:
100 OTemplateBasePrivate *d; 99 OTemplateBasePrivate *d;
101}; 100};
102 101
103/* 102
104 * implementation
105 */
106template <class T>
107int
108OTemplateBase<T>::rtti() {
109 return T::rtti();
110}
111template <class T> 103template <class T>
112OPimRecord* OTemplateBase<T>::record()const { 104OPimRecord* OTemplateBase<T>::record()const {
113 T* t = new T; 105 T* t = new T;
114 return t; 106 return t;
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
@@ -32,8 +32,9 @@
32 32
33// #include "otodoaccesssql.h" 33// #include "otodoaccesssql.h"
34#include <opie2/otodoaccess.h> 34#include <opie2/otodoaccess.h>
35#include <opie2/obackendfactory.h> 35#include <opie2/obackendfactory.h>
36#include <opie2/opimresolver.h>
36 37
37namespace Opie { 38namespace Opie {
38OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) 39OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
39 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) 40 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end )
@@ -89,5 +90,11 @@ QBitArray OPimTodoAccess::backendSupport( const QString& ) const{
89bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ 90bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{
90 return backendSupport(ar).testBit( attr ); 91 return backendSupport(ar).testBit( attr );
91} 92}
92 93
94
95int OPimTodoAccess::rtti() const
96{
97 return OPimResolver::TodoList;
98}
99
93} 100}
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
@@ -115,8 +115,14 @@ public:
115 * @param attr The attribute to be queried for 115 * @param attr The attribute to be queried for
116 * @param backend Will be used in the future when we support multiple backends 116 * @param backend Will be used in the future when we support multiple backends
117 */ 117 */
118 bool backendSupports( int attr, const QString& backend = QString::null )const; 118 bool backendSupports( int attr, const QString& backend = QString::null )const;
119
120
121 /**
122 * Return identification of used records
123 */
124 int rtti() const;
119signals: 125signals:
120 /** 126 /**
121 * if the OPimTodoAccess was changed 127 * if the OPimTodoAccess was changed
122 */ 128 */