summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h24
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp18
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp34
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.h19
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp231
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.h2
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp2
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h14
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp19
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h9
-rw-r--r--libopie2/opiepim/core/otimezone.cpp11
-rw-r--r--libopie2/opiepim/oevent.cpp13
-rw-r--r--libopie2/opiepim/oevent.h6
13 files changed, 333 insertions, 69 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 3567687..761ab9a 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -16,6 +16,18 @@
16 * ===================================================================== 16 * =====================================================================
17 * History: 17 * History:
18 * $Log$ 18 * $Log$
19 * Revision 1.9 2003/12/22 10:19:26 eilers
20 * Finishing implementation of sql-backend for datebook. But I have to
21 * port the PIM datebook application to use it, before I could debug the
22 * whole stuff.
23 * Thus, PIM-Database backend is finished, but highly experimental. And some
24 * parts are still generic. For instance, the "queryByExample()" methods are
25 * not (or not fully) implemented. Todo: custom-entries not stored.
26 * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
27 * expression search in the database, which is not supported by sqlite !
28 * Therefore we need either an extended sqlite or a workaround which would
29 * be very slow and memory consuming..
30 *
19 * Revision 1.8 2003/09/22 14:31:16 eilers 31 * Revision 1.8 2003/09/22 14:31:16 eilers
20 * Added first experimental incarnation of sql-backend for addressbook. 32 * Added first experimental incarnation of sql-backend for addressbook.
21 * Some modifications to be able to compile the todo sql-backend. 33 * Some modifications to be able to compile the todo sql-backend.
@@ -80,6 +92,7 @@
80#ifdef __USE_SQL 92#ifdef __USE_SQL
81#include "otodoaccesssql.h" 93#include "otodoaccesssql.h"
82#include "ocontactaccessbackend_sql.h" 94#include "ocontactaccessbackend_sql.h"
95#include "odatebookaccessbackend_sql.h"
83#endif 96#endif
84 97
85class OBackendPrivate; 98class OBackendPrivate;
@@ -143,7 +156,7 @@ class OBackendFactory
143 return (T*) new OTodoAccessBackendSQL(""); 156 return (T*) new OTodoAccessBackendSQL("");
144#else 157#else
145 if ( backend == "sql" ) 158 if ( backend == "sql" )
146 qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); 159 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!");
147#endif 160#endif
148 161
149 return (T*) new OTodoAccessXML( appName ); 162 return (T*) new OTodoAccessXML( appName );
@@ -153,13 +166,18 @@ class OBackendFactory
153 return (T*) new OContactAccessBackend_SQL(""); 166 return (T*) new OContactAccessBackend_SQL("");
154#else 167#else
155 if ( backend == "sql" ) 168 if ( backend == "sql" )
156 qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); 169 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!");
157#endif 170#endif
158 171
159 return (T*) new OContactAccessBackend_XML( appName ); 172 return (T*) new OContactAccessBackend_XML( appName );
160 case DATE: 173 case DATE:
174#ifdef __USE_SQL
161 if ( backend == "sql" ) 175 if ( backend == "sql" )
162 qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); 176 return (T*) new ODateBookAccessBackend_SQL("");
177#else
178 if ( backend == "sql" )
179 qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!");
180#endif
163 181
164 return (T*) new ODateBookAccessBackend_XML( appName ); 182 return (T*) new ODateBookAccessBackend_XML( appName );
165 default: 183 default:
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index dd9dbde..a5be4c8 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -14,6 +14,18 @@
14 * ===================================================================== 14 * =====================================================================
15 * History: 15 * History:
16 * $Log$ 16 * $Log$
17 * Revision 1.4 2003/12/22 10:19:26 eilers
18 * Finishing implementation of sql-backend for datebook. But I have to
19 * port the PIM datebook application to use it, before I could debug the
20 * whole stuff.
21 * Thus, PIM-Database backend is finished, but highly experimental. And some
22 * parts are still generic. For instance, the "queryByExample()" methods are
23 * not (or not fully) implemented. Todo: custom-entries not stored.
24 * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
25 * expression search in the database, which is not supported by sqlite !
26 * Therefore we need either an extended sqlite or a workaround which would
27 * be very slow and memory consuming..
28 *
17 * Revision 1.3 2003/12/08 15:18:10 eilers 29 * Revision 1.3 2003/12/08 15:18:10 eilers
18 * Committing unfinished sql implementation before merging to libopie2 starts.. 30 * Committing unfinished sql implementation before merging to libopie2 starts..
19 * 31 *
@@ -510,7 +522,7 @@ bool OContactAccessBackend_SQL::reload()
510 522
511bool OContactAccessBackend_SQL::save() 523bool OContactAccessBackend_SQL::save()
512{ 524{
513 return m_driver->close(); 525 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
514} 526}
515 527
516 528
@@ -518,8 +530,8 @@ void OContactAccessBackend_SQL::clear ()
518{ 530{
519 ClearQuery cle; 531 ClearQuery cle;
520 OSQLResult res = m_driver->query( &cle ); 532 OSQLResult res = m_driver->query( &cle );
521 CreateQuery qu; 533
522 res = m_driver->query(&qu); 534 reload();
523} 535}
524 536
525bool OContactAccessBackend_SQL::wasChangedExternally() 537bool OContactAccessBackend_SQL::wasChangedExternally()
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
index 8fa1a68..f0c5d65 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -127,7 +127,7 @@ ODateBookAccessBackend::ODateBookAccessBackend()
127ODateBookAccessBackend::~ODateBookAccessBackend() { 127ODateBookAccessBackend::~ODateBookAccessBackend() {
128 128
129} 129}
130OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDate& from, 130OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from,
131 const QDate& to ) { 131 const QDate& to ) {
132 OEffectiveEvent::ValueList tmpList; 132 OEffectiveEvent::ValueList tmpList;
133 OEvent::ValueList list = directNonRepeats(); 133 OEvent::ValueList list = directNonRepeats();
@@ -135,13 +135,39 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDate&
135 events( tmpList, list, from, to ); 135 events( tmpList, list, from, to );
136 repeat( tmpList, directRawRepeats(),from,to ); 136 repeat( tmpList, directRawRepeats(),from,to );
137 137
138 list = directRawRepeats(); 138 list = directRawRepeats(); // Useless, isn't it ? (eilers)
139 139
140 qHeapSort( tmpList ); 140 qHeapSort( tmpList );
141 return tmpList; 141 return tmpList;
142} 142}
143OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDateTime& dt ) { 143OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) {
144 OEffectiveEvent::ValueList day = effecticeEvents( dt.date(), dt.date() ); 144 OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() );
145 OEffectiveEvent::ValueList::Iterator it;
146
147 OEffectiveEvent::ValueList tmpList;
148 QDateTime dtTmp;
149 for ( it = day.begin(); it != day.end(); ++it ) {
150 dtTmp = QDateTime( (*it).date(), (*it).startTime() );
151 if ( QABS(dt.secsTo(dtTmp) ) < 60 )
152 tmpList.append( (*it) );
153 }
154
155 return tmpList;
156}
157
158OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
159 const QDate& to ) {
160 OEffectiveEvent::ValueList tmpList;
161 OEvent::ValueList list = directNonRepeats();
162
163 events( tmpList, list, from, to );
164
165 qHeapSort( tmpList );
166 return tmpList;
167}
168
169OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) {
170 OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
145 OEffectiveEvent::ValueList::Iterator it; 171 OEffectiveEvent::ValueList::Iterator it;
146 172
147 OEffectiveEvent::ValueList tmpList; 173 OEffectiveEvent::ValueList tmpList;
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h
index 3c02c42..3472ab3 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.h
@@ -60,13 +60,26 @@ public:
60 * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method 60 * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
61 * yourself 61 * yourself
62 */ 62 */
63 virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); 63 virtual OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to );
64 64
65 /** 65 /**
66 * this is an overloaded member function 66 * this is an overloaded member function
67 * @see effecticeEvents 67 * @see effectiveEvents( const QDate& from, const QDate& to )
68 */ 68 */
69 virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); 69 virtual OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start );
70
71 /**
72 * Effective Events are special event occuring during a time frame. This method does calcualte
73 * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
74 * yourself
75 */
76 virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to );
77
78 /**
79 * this is an overloaded member function
80 * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to )
81 */
82 virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start );
70 83
71private: 84private:
72 class Private; 85 class Private;
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index 9769bf7..e893b38 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -14,6 +14,18 @@
14 * ===================================================================== 14 * =====================================================================
15 * History: 15 * History:
16 * $Log$ 16 * $Log$
17 * Revision 1.2 2003/12/22 10:19:26 eilers
18 * Finishing implementation of sql-backend for datebook. But I have to
19 * port the PIM datebook application to use it, before I could debug the
20 * whole stuff.
21 * Thus, PIM-Database backend is finished, but highly experimental. And some
22 * parts are still generic. For instance, the "queryByExample()" methods are
23 * not (or not fully) implemented. Todo: custom-entries not stored.
24 * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
25 * expression search in the database, which is not supported by sqlite !
26 * Therefore we need either an extended sqlite or a workaround which would
27 * be very slow and memory consuming..
28 *
17 * Revision 1.1 2003/12/08 15:18:12 eilers 29 * Revision 1.1 2003/12/08 15:18:12 eilers
18 * Committing unfinished sql implementation before merging to libopie2 starts.. 30 * Committing unfinished sql implementation before merging to libopie2 starts..
19 * 31 *
@@ -26,25 +38,22 @@
26#include <qarray.h> 38#include <qarray.h>
27#include <qstringlist.h> 39#include <qstringlist.h>
28 40
29#include "orecur.h" 41#include <qpe/global.h>
30#include "odatebookaccessbackend_sql.h"
31 42
32#include <opie2/osqldriver.h> 43#include <opie2/osqldriver.h>
33#include <opie2/osqlresult.h>
34#include <opie2/osqlmanager.h> 44#include <opie2/osqlmanager.h>
35#include <opie2/osqlquery.h> 45#include <opie2/osqlquery.h>
36 46
37namespace { 47#include "orecur.h"
38 48#include "odatebookaccessbackend_sql.h"
39 49
40 50
41};
42 51
43ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 52ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
44 const QString& fileName ) 53 const QString& fileName )
45 : ODateBookAccessBackend(), m_driver( NULL ) 54 : ODateBookAccessBackend(), m_driver( NULL )
46{ 55{
47 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; 56 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName;
48 57
49 // Get the standart sql-driver from the OSQLManager.. 58 // Get the standart sql-driver from the OSQLManager..
50 OSQLManager man; 59 OSQLManager man;
@@ -57,6 +66,8 @@ ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
57} 66}
58 67
59ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { 68ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() {
69 if( m_driver )
70 delete m_driver;
60} 71}
61 72
62void ODateBookAccessBackend_SQL::initFields() 73void ODateBookAccessBackend_SQL::initFields()
@@ -78,13 +89,20 @@ void ODateBookAccessBackend_SQL::initFields()
78 m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); 89 m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" );
79 m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); 90 m_fieldMap.insert( OEvent::FREndDate, "REndDate" );
80 m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); 91 m_fieldMap.insert( OEvent::FRCreated, "RCreated" );
81 m_fieldMap.insert( OEvent::FRExeptions, "RExceptions" ); 92 m_fieldMap.insert( OEvent::FRExceptions, "RExceptions" );
82 m_fieldMap.insert( OEvent::FStart, "Start" ); 93 m_fieldMap.insert( OEvent::FStart, "Start" );
83 m_fieldMap.insert( OEvent::FEnd, "End" ); 94 m_fieldMap.insert( OEvent::FEnd, "End" );
84 m_fieldMap.insert( OEvent::FNote, "Note" ); 95 m_fieldMap.insert( OEvent::FNote, "Note" );
85 m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); 96 m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" );
86 m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); 97 m_fieldMap.insert( OEvent::FRecParent, "RecParent" );
87 m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); 98 m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" );
99
100 // Create a map that maps the column name to the id
101 QMapConstIterator<int, QString> it;
102 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
103 m_reverseFieldMap.insert( it.data(), it.key() );
104 }
105
88} 106}
89 107
90bool ODateBookAccessBackend_SQL::load() 108bool ODateBookAccessBackend_SQL::load()
@@ -99,12 +117,14 @@ bool ODateBookAccessBackend_SQL::load()
99 117
100 QMap<int, QString>::Iterator it; 118 QMap<int, QString>::Iterator it;
101 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 119 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
102 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( it.data() ); 120 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() );
103 } 121 }
104 qu += " );"; 122 qu += " );";
105 123
106 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; 124 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );";
107 125
126 qWarning( "command: %s", qu.latin1() );
127
108 OSQLRawQuery raw( qu ); 128 OSQLRawQuery raw( qu );
109 OSQLResult res = m_driver->query( &raw ); 129 OSQLResult res = m_driver->query( &raw );
110 if ( res.state() != OSQLResult::Success ) 130 if ( res.state() != OSQLResult::Success )
@@ -122,7 +142,7 @@ void ODateBookAccessBackend_SQL::update()
122 OSQLRawQuery raw( qu ); 142 OSQLRawQuery raw( qu );
123 OSQLResult res = m_driver->query( &raw ); 143 OSQLResult res = m_driver->query( &raw );
124 if ( res.state() != OSQLResult::Success ){ 144 if ( res.state() != OSQLResult::Success ){
125 m_uids.clear(); 145 // m_uids.clear();
126 return; 146 return;
127 } 147 }
128 148
@@ -130,42 +150,23 @@ void ODateBookAccessBackend_SQL::update()
130 150
131} 151}
132 152
133QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
134{
135 qWarning("extractUids");
136
137 OSQLResultItem::ValueList list = res.results();
138 OSQLResultItem::ValueList::Iterator it;
139 QArray<int> ints(list.count() );
140 qWarning(" count = %d", list.count() );
141
142 int i = 0;
143 for (it = list.begin(); it != list.end(); ++it ) {
144 ints[i] = (*it).data("uid").toInt();
145 i++;
146 }
147
148 return ints;
149
150}
151
152bool ODateBookAccessBackend_SQL::reload() 153bool ODateBookAccessBackend_SQL::reload()
153{ 154{
154 return load(); 155 return load();
155} 156}
156 157
157bool ODateBookAccessBackend_SQL::save() 158bool ODateBookAccessBackend_SQL::save()
158{ 159{
159 return m_driver->close(); 160 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
160} 161}
161 162
162QArray<int> ODateBookAccessBackend_SQL::allRecords()const 163QArray<int> ODateBookAccessBackend_SQL::allRecords()const
163{ 164{
164 return m_uids; 165 return m_uids;
165} 166}
166 167
167QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { 168QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) {
168 return QArray<int>(); 169 return QArray<int>();
169} 170}
170 171
171void ODateBookAccessBackend_SQL::clear() 172void ODateBookAccessBackend_SQL::clear()
@@ -176,46 +177,180 @@ void ODateBookAccessBackend_SQL::clear()
176 OSQLRawQuery raw( qu ); 177 OSQLRawQuery raw( qu );
177 OSQLResult res = m_driver->query( &raw ); 178 OSQLResult res = m_driver->query( &raw );
178 179
180 reload();
179} 181}
180 182
181 183
182OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ 184OEvent ODateBookAccessBackend_SQL::find( int uid ) const{
185 QString qu = "select *";
186 qu += "from datebook where uid = " + QString::number(uid);
187
188 OSQLRawQuery raw( qu );
189 OSQLResult res = m_driver->query( &raw );
190
191 OSQLResultItem resItem = res.first();
192
193 // Create Map for date event and insert UID
194 QMap<int,QString> dateEventMap;
195 dateEventMap.insert( OEvent::FUid, QString::number( uid ) );
196
197 // Now insert the data out of the columns into the map.
198 QMapConstIterator<int, QString> it;
199 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
200 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
201 }
202
203 // Last step: Put map into date event and return it
204 OEvent retDate( dateEventMap );
205
206 return retDate;
183} 207}
184 208
185bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) { 209bool ODateBookAccessBackend_SQL::add( const OEvent& ev )
186 return true; 210{
211 QMap<int,QString> eventMap = ev.toMap();
212
213 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
214 QMap<int, QString>::Iterator it;
215 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
216 if ( !eventMap[it.key()].isEmpty() )
217 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
218 else
219 qu += QString( ",\"\"" );
220 }
221 qu += " );";
222
223 // Add custom entries
224 int id = 0;
225 QMap<QString, QString> customMap = ev.toExtraMap();
226 for( QMap<QString, QString>::Iterator it = customMap.begin();
227 it != customMap.end(); ++it ){
228 qu += "insert into custom_data VALUES("
229 + QString::number( ev.uid() )
230 + ","
231 + QString::number( id++ )
232 + ",'"
233 + it.key() //.latin1()
234 + "',"
235 + "0" // Priority for future enhancements
236 + ",'"
237 + it.data() //.latin1()
238 + "');";
239 }
240 qWarning("add %s", qu.latin1() );
241
242 OSQLRawQuery raw( qu );
243 OSQLResult res = m_driver->query( &raw );
244 if ( res.state() != OSQLResult::Success ){
245 return false;
246 }
247
248 return true;
187} 249}
188bool ODateBookAccessBackend_SQL::remove( int uid ) {
189 250
190 return true; 251bool ODateBookAccessBackend_SQL::remove( int uid )
252{
253 QString qu = "DELETE from datebook where uid = "
254 + QString::number( uid ) + ";";
255 qu += "DELETE from custom_data where uid = "
256 + QString::number( uid ) + ";";
257
258 OSQLRawQuery raw( qu );
259 OSQLResult res = m_driver->query( &raw );
260 if ( res.state() != OSQLResult::Success ){
261 return false;
262 }
263
264 return true;
191} 265}
192bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) { 266
267bool ODateBookAccessBackend_SQL::replace( const OEvent& ev )
268{
193 remove( ev.uid() ); 269 remove( ev.uid() );
194 return add( ev ); 270 return add( ev );
195} 271}
196QArray<int> ODateBookAccessBackend_SQL::rawEvents()const { 272
273QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
274{
197 return allRecords(); 275 return allRecords();
198} 276}
199QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const {
200 277
201 return ints; 278QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
279{
280 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
281 OSQLRawQuery raw( qu );
282 OSQLResult res = m_driver->query( &raw );
283 if ( res.state() != OSQLResult::Success ){
284 QArray<int> nix;
285 return nix;
286 }
287
288 return extractUids( res );
202} 289}
203QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const {
204 290
205 return ints; 291QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
292{
293 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\"";
294 OSQLRawQuery raw( qu );
295 OSQLResult res = m_driver->query( &raw );
296 if ( res.state() != OSQLResult::Success ){
297 QArray<int> nix;
298 return nix;
299 }
300
301 return extractUids( res );
206} 302}
207OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() {
208 303
209 return list; 304OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
305{
306 QArray<int> nonRepUids = nonRepeats();
307 OEvent::ValueList list;
308
309 for (uint i = 0; i < nonRepUids.count(); ++i ){
310 list.append( find( nonRepUids[i] ) );
311 }
312
313 return list;
314
210} 315}
211OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() { 316OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
317{
318 QArray<int> rawRepUids = rawRepeats();
319 OEvent::ValueList list;
212 320
213 return list; 321 for (uint i = 0; i < rawRepUids.count(); ++i ){
322 list.append( find( rawRepUids[i] ) );
323 }
324
325 return list;
214} 326}
215 327
216 328
217QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 329QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
218{ 330{
331 QArray<int> null;
332 return null;
333}
334
335/* ===== Private Functions ========================================== */
336
337QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
338{
339 qWarning("extractUids");
340 QTime t;
341 t.start();
342 OSQLResultItem::ValueList list = res.results();
343 OSQLResultItem::ValueList::Iterator it;
344 QArray<int> ints(list.count() );
345 qWarning(" count = %d", list.count() );
346
347 int i = 0;
348 for (it = list.begin(); it != list.end(); ++it ) {
349 ints[i] = (*it).data("uid").toInt();
350 i++;
351 }
352 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
353
354 return ints;
219 355
220 return m_currentQuery;
221} 356}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
index 85e0d4f..f39e154 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
@@ -2,6 +2,7 @@
2#define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H 2#define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H
3 3
4#include <qmap.h> 4#include <qmap.h>
5#include <opie2/osqlresult.h>
5 6
6#include "odatebookaccessbackend.h" 7#include "odatebookaccessbackend.h"
7 8
@@ -45,6 +46,7 @@ private:
45 QArray<int> m_uids; 46 QArray<int> m_uids;
46 47
47 QMap<int, QString> m_fieldMap; 48 QMap<int, QString> m_fieldMap;
49 QMap<QString, int> m_reverseFieldMap;
48 50
49 OSQLDriver* m_driver; 51 OSQLDriver* m_driver;
50 52
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 75a0860..3764c7e 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -330,7 +330,7 @@ bool OTodoAccessBackendSQL::reload(){
330} 330}
331 331
332bool OTodoAccessBackendSQL::save(){ 332bool OTodoAccessBackendSQL::save(){
333 return m_driver->close(); 333 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
334} 334}
335QArray<int> OTodoAccessBackendSQL::allRecords()const { 335QArray<int> OTodoAccessBackendSQL::allRecords()const {
336 if (m_dirty ) 336 if (m_dirty )
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index 9b0a719..bd6da40 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -17,6 +17,18 @@
17 * ===================================================================== 17 * =====================================================================
18 * History: 18 * History:
19 * $Log$ 19 * $Log$
20 * Revision 1.10 2003/12/22 10:19:26 eilers
21 * Finishing implementation of sql-backend for datebook. But I have to
22 * port the PIM datebook application to use it, before I could debug the
23 * whole stuff.
24 * Thus, PIM-Database backend is finished, but highly experimental. And some
25 * parts are still generic. For instance, the "queryByExample()" methods are
26 * not (or not fully) implemented. Todo: custom-entries not stored.
27 * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
28 * expression search in the database, which is not supported by sqlite !
29 * Therefore we need either an extended sqlite or a workaround which would
30 * be very slow and memory consuming..
31 *
20 * Revision 1.9 2003/08/01 12:30:16 eilers 32 * Revision 1.9 2003/08/01 12:30:16 eilers
21 * Merging changes from BRANCH_1_0 to HEAD 33 * Merging changes from BRANCH_1_0 to HEAD
22 * 34 *
@@ -78,7 +90,7 @@
78 * done by the backend. 90 * done by the backend.
79 * This class is used to access the Contacts on a system. This class as any OPIE PIM 91 * This class is used to access the Contacts on a system. This class as any OPIE PIM
80 * class is backend independent. 92 * class is backend independent.
81 93 * @author Stefan Eilers, Holger Freyther
82 * @see OPimAccessTemplate 94 * @see OPimAccessTemplate
83 */ 95 */
84class OContactAccess: public QObject, public OPimAccessTemplate<OContact> 96class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp
index a3661a3..82934f9 100644
--- a/libopie2/opiepim/core/odatebookaccess.cpp
+++ b/libopie2/opiepim/core/odatebookaccess.cpp
@@ -56,11 +56,26 @@ ODateBookAccess::List ODateBookAccess::nonRepeats()const {
56 * @param to Include all events to... 56 * @param to Include all events to...
57 */ 57 */
58OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) { 58OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) {
59 return m_backEnd->effecticeEvents( from, to ); 59 return m_backEnd->effectiveEvents( from, to );
60} 60}
61/** 61/**
62 * @return all events at a given datetime 62 * @return all events at a given datetime
63 */ 63 */
64OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) { 64OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) {
65 return m_backEnd->effecticeEvents( start ); 65 return m_backEnd->effectiveEvents( start );
66}
67
68/**
69 * @return non repeating dates in the time span between from and to
70 * @param from Include all events from...
71 * @param to Include all events to...
72 */
73OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) {
74 return m_backEnd->effectiveNonRepeatingEvents( from, to );
75}
76/**
77 * @return all non repeating events at a given datetime
78 */
79OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) {
80 return m_backEnd->effectiveNonRepeatingEvents( start );
66} 81}
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index 7c7a63f..62196da 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -13,7 +13,7 @@
13 * Make sure to load and save the datebook this is not part of 13 * Make sure to load and save the datebook this is not part of
14 * destructing and creating the object 14 * destructing and creating the object
15 * 15 *
16 * @author Holger Freyther 16 * @author Holger Freyther, Stefan Eilers
17 */ 17 */
18class ODateBookAccess : public OPimAccessTemplate<OEvent> { 18class ODateBookAccess : public OPimAccessTemplate<OEvent> {
19public: 19public:
@@ -29,8 +29,11 @@ public:
29 /* return non repeating events */ 29 /* return non repeating events */
30 List nonRepeats()const; 30 List nonRepeats()const;
31 31
32 OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); 32 /* return non repeating events (from,to) */
33 OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ); 33 OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const;
34 OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const;
35 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
36 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const;
34 37
35private: 38private:
36 ODateBookAccessBackend* m_backEnd; 39 ODateBookAccessBackend* m_backEnd;
diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/otimezone.cpp
index b2bd3aa..34659c3 100644
--- a/libopie2/opiepim/core/otimezone.cpp
+++ b/libopie2/opiepim/core/otimezone.cpp
@@ -16,11 +16,16 @@ namespace {
16 } 16 }
17 QDateTime utcTime( time_t t, const QString& zone) { 17 QDateTime utcTime( time_t t, const QString& zone) {
18 QCString org = ::getenv( "TZ" ); 18 QCString org = ::getenv( "TZ" );
19#ifndef Q_OS_MACX // Following line causes bus errors on Mac
19 ::setenv( "TZ", zone.latin1(), true ); 20 ::setenv( "TZ", zone.latin1(), true );
20 ::tzset(); 21 ::tzset();
21 22
22 tm* broken = ::localtime( &t ); 23 tm* broken = ::localtime( &t );
23 ::setenv( "TZ", org, true ); 24 ::setenv( "TZ", org, true );
25#else
26#warning "Need a replacement for MacOSX!!"
27 tm* broken = ::localtime( &t );
28#endif
24 29
25 QDateTime ret; 30 QDateTime ret;
26 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); 31 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) );
@@ -41,12 +46,16 @@ namespace {
41 broken.tm_sec = t.second(); 46 broken.tm_sec = t.second();
42 47
43 QCString org = ::getenv( "TZ" ); 48 QCString org = ::getenv( "TZ" );
49#ifndef Q_OS_MACX // Following line causes bus errors on Mac
44 ::setenv( "TZ", str.latin1(), true ); 50 ::setenv( "TZ", str.latin1(), true );
45 ::tzset(); 51 ::tzset();
46 52
47 time_t ti = ::mktime( &broken ); 53 time_t ti = ::mktime( &broken );
48 ::setenv( "TZ", org, true ); 54 ::setenv( "TZ", org, true );
49 55#else
56#warning "Need a replacement for MacOSX!!"
57 time_t ti = ::mktime( &broken );
58#endif
50 return ti; 59 return ti;
51 } 60 }
52} 61}
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp
index ec05e77..9b31957 100644
--- a/libopie2/opiepim/oevent.cpp
+++ b/libopie2/opiepim/oevent.cpp
@@ -77,6 +77,15 @@ OEvent::OEvent( const OEvent& ev)
77{ 77{
78 data->ref(); 78 data->ref();
79} 79}
80
81OEvent::OEvent( const QMap<int, QString> map )
82 : OPimRecord( 0 )
83{
84 data = new Data;
85
86 fromMap( map );
87}
88
80OEvent::~OEvent() { 89OEvent::~OEvent() {
81 if ( data->deref() ) { 90 if ( data->deref() ) {
82 delete data; 91 delete data;
@@ -403,6 +412,10 @@ QMap<int, QString> OEvent::toMap()const {
403 retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] ); 412 retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] );
404 retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); 413 retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] );
405 retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); 414 retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] );
415 } else {
416 ORecur recur = recurrence();
417 QMap<int, QString> recFields = recur.toMap();
418 retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
406 } 419 }
407 420
408 return retMap; 421 return retMap;
diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h
index 9218c97..9eb948f 100644
--- a/libopie2/opiepim/oevent.h
+++ b/libopie2/opiepim/oevent.h
@@ -76,6 +76,12 @@ public:
76 * copy c'tor 76 * copy c'tor
77 */ 77 */
78 OEvent( const OEvent& ); 78 OEvent( const OEvent& );
79
80 /**
81 * Create OEvent, initialized by map
82 * @see enum RecordFields
83 */
84 OEvent( const QMap<int, QString> map );
79 ~OEvent(); 85 ~OEvent();
80 OEvent &operator=( const OEvent& ); 86 OEvent &operator=( const OEvent& );
81 87