author | eilers <eilers> | 2003-12-08 15:18:10 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-12-08 15:18:10 (UTC) |
commit | 6974a4bbdc674a2a5d41d801f80035a183faedb5 (patch) (unidiff) | |
tree | 09a719ef263047e92ffb866da13168b7f7d41f23 /libopie/pim | |
parent | 7f2f736597490fd1592d7ed1f40e4abf824673c0 (diff) | |
download | opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.zip opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.tar.gz opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.tar.bz2 |
Committing unfinished sql implementation before merging to libopie2 starts..
-rw-r--r-- | libopie/pim/ocontactaccessbackend_sql.cpp | 11 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_sql.h | 5 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend_sql.cpp | 221 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend_sql.h | 60 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend_xml.cpp | 12 | ||||
-rw-r--r-- | libopie/pim/oevent.cpp | 131 | ||||
-rw-r--r-- | libopie/pim/oevent.h | 36 | ||||
-rw-r--r-- | libopie/pim/orecur.cpp | 8 | ||||
-rw-r--r-- | libopie/pim/orecur.h | 1 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 5 |
10 files changed, 470 insertions, 20 deletions
diff --git a/libopie/pim/ocontactaccessbackend_sql.cpp b/libopie/pim/ocontactaccessbackend_sql.cpp index 132c9fc..dd9dbde 100644 --- a/libopie/pim/ocontactaccessbackend_sql.cpp +++ b/libopie/pim/ocontactaccessbackend_sql.cpp | |||
@@ -16,2 +16,5 @@ | |||
16 | * $Log$ | 16 | * $Log$ |
17 | * Revision 1.3 2003/12/08 15:18:10 eilers | ||
18 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
19 | * | ||
17 | * Revision 1.2 2003/09/29 07:44:26 eilers | 20 | * Revision 1.2 2003/09/29 07:44:26 eilers |
@@ -456,3 +459,4 @@ namespace { | |||
456 | OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, | 459 | OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, |
457 | const QString& filename ): m_changed(false) | 460 | const QString& filename ): |
461 | OContactAccessBackend(), m_changed(false), m_driver( NULL ) | ||
458 | { | 462 | { |
@@ -478,2 +482,7 @@ OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname | |||
478 | 482 | ||
483 | OContactAccessBackend_SQL::~OContactAccessBackend_SQL () | ||
484 | { | ||
485 | if( m_driver ) | ||
486 | delete m_driver; | ||
487 | } | ||
479 | 488 | ||
diff --git a/libopie/pim/ocontactaccessbackend_sql.h b/libopie/pim/ocontactaccessbackend_sql.h index bb22551..b8f1d8d 100644 --- a/libopie/pim/ocontactaccessbackend_sql.h +++ b/libopie/pim/ocontactaccessbackend_sql.h | |||
@@ -18,2 +18,5 @@ | |||
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.2 2003/12/08 15:18:11 eilers | ||
20 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
21 | * | ||
19 | * Revision 1.1 2003/09/22 14:31:16 eilers | 22 | * Revision 1.1 2003/09/22 14:31:16 eilers |
@@ -49,2 +52,4 @@ class OContactAccessBackend_SQL : public OContactAccessBackend { | |||
49 | 52 | ||
53 | ~OContactAccessBackend_SQL (); | ||
54 | |||
50 | bool save(); | 55 | bool save(); |
diff --git a/libopie/pim/odatebookaccessbackend_sql.cpp b/libopie/pim/odatebookaccessbackend_sql.cpp new file mode 100644 index 0000000..9769bf7 --- a/dev/null +++ b/libopie/pim/odatebookaccessbackend_sql.cpp | |||
@@ -0,0 +1,221 @@ | |||
1 | /* | ||
2 | * SQL Backend for the OPIE-Calender Database. | ||
3 | * | ||
4 | * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * ===================================================================== | ||
13 | * Version: $Id$ | ||
14 | * ===================================================================== | ||
15 | * History: | ||
16 | * $Log$ | ||
17 | * Revision 1.1 2003/12/08 15:18:12 eilers | ||
18 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
19 | * | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | |||
26 | #include <qarray.h> | ||
27 | #include <qstringlist.h> | ||
28 | |||
29 | #include "orecur.h" | ||
30 | #include "odatebookaccessbackend_sql.h" | ||
31 | |||
32 | #include <opie2/osqldriver.h> | ||
33 | #include <opie2/osqlresult.h> | ||
34 | #include <opie2/osqlmanager.h> | ||
35 | #include <opie2/osqlquery.h> | ||
36 | |||
37 | namespace { | ||
38 | |||
39 | |||
40 | |||
41 | }; | ||
42 | |||
43 | ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | ||
44 | const QString& fileName ) | ||
45 | : ODateBookAccessBackend(), m_driver( NULL ) | ||
46 | { | ||
47 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; | ||
48 | |||
49 | // Get the standart sql-driver from the OSQLManager.. | ||
50 | OSQLManager man; | ||
51 | m_driver = man.standard(); | ||
52 | m_driver->setUrl( m_fileName ); | ||
53 | |||
54 | initFields(); | ||
55 | |||
56 | load(); | ||
57 | } | ||
58 | |||
59 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { | ||
60 | } | ||
61 | |||
62 | void ODateBookAccessBackend_SQL::initFields() | ||
63 | { | ||
64 | |||
65 | // This map contains the translation of the fieldtype id's to | ||
66 | // the names of the table columns | ||
67 | m_fieldMap.insert( OEvent::FUid, "uid" ); | ||
68 | m_fieldMap.insert( OEvent::FCategories, "Categories" ); | ||
69 | m_fieldMap.insert( OEvent::FDescription, "Description" ); | ||
70 | m_fieldMap.insert( OEvent::FLocation, "Location" ); | ||
71 | m_fieldMap.insert( OEvent::FType, "Type" ); | ||
72 | m_fieldMap.insert( OEvent::FAlarm, "Alarm" ); | ||
73 | m_fieldMap.insert( OEvent::FSound, "Sound" ); | ||
74 | m_fieldMap.insert( OEvent::FRType, "RType" ); | ||
75 | m_fieldMap.insert( OEvent::FRWeekdays, "RWeekdays" ); | ||
76 | m_fieldMap.insert( OEvent::FRPosition, "RPosition" ); | ||
77 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); | ||
78 | m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); | ||
79 | m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); | ||
80 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); | ||
81 | m_fieldMap.insert( OEvent::FRExeptions, "RExceptions" ); | ||
82 | m_fieldMap.insert( OEvent::FStart, "Start" ); | ||
83 | m_fieldMap.insert( OEvent::FEnd, "End" ); | ||
84 | m_fieldMap.insert( OEvent::FNote, "Note" ); | ||
85 | m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); | ||
86 | m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); | ||
87 | m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); | ||
88 | } | ||
89 | |||
90 | bool ODateBookAccessBackend_SQL::load() | ||
91 | { | ||
92 | if (!m_driver->open() ) | ||
93 | return false; | ||
94 | |||
95 | // Don't expect that the database exists. | ||
96 | // It is save here to create the table, even if it | ||
97 | // do exist. ( Is that correct for all databases ?? ) | ||
98 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; | ||
99 | |||
100 | QMap<int, QString>::Iterator it; | ||
101 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | ||
102 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( it.data() ); | ||
103 | } | ||
104 | qu += " );"; | ||
105 | |||
106 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; | ||
107 | |||
108 | OSQLRawQuery raw( qu ); | ||
109 | OSQLResult res = m_driver->query( &raw ); | ||
110 | if ( res.state() != OSQLResult::Success ) | ||
111 | return false; | ||
112 | |||
113 | update(); | ||
114 | |||
115 | return true; | ||
116 | } | ||
117 | |||
118 | void ODateBookAccessBackend_SQL::update() | ||
119 | { | ||
120 | |||
121 | QString qu = "select uid from datebook"; | ||
122 | OSQLRawQuery raw( qu ); | ||
123 | OSQLResult res = m_driver->query( &raw ); | ||
124 | if ( res.state() != OSQLResult::Success ){ | ||
125 | m_uids.clear(); | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | m_uids = extractUids( res ); | ||
130 | |||
131 | } | ||
132 | |||
133 | QArray<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 | |||
152 | bool ODateBookAccessBackend_SQL::reload() | ||
153 | { | ||
154 | return load(); | ||
155 | } | ||
156 | |||
157 | bool ODateBookAccessBackend_SQL::save() | ||
158 | { | ||
159 | return m_driver->close(); | ||
160 | } | ||
161 | |||
162 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const | ||
163 | { | ||
164 | return m_uids; | ||
165 | } | ||
166 | |||
167 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { | ||
168 | return QArray<int>(); | ||
169 | } | ||
170 | |||
171 | void ODateBookAccessBackend_SQL::clear() | ||
172 | { | ||
173 | QString qu = "drop table datebook;"; | ||
174 | qu += "drop table custom_data;"; | ||
175 | |||
176 | OSQLRawQuery raw( qu ); | ||
177 | OSQLResult res = m_driver->query( &raw ); | ||
178 | |||
179 | } | ||
180 | |||
181 | |||
182 | OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | ||
183 | } | ||
184 | |||
185 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) { | ||
186 | return true; | ||
187 | } | ||
188 | bool ODateBookAccessBackend_SQL::remove( int uid ) { | ||
189 | |||
190 | return true; | ||
191 | } | ||
192 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) { | ||
193 | remove( ev.uid() ); | ||
194 | return add( ev ); | ||
195 | } | ||
196 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const { | ||
197 | return allRecords(); | ||
198 | } | ||
199 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const { | ||
200 | |||
201 | return ints; | ||
202 | } | ||
203 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const { | ||
204 | |||
205 | return ints; | ||
206 | } | ||
207 | OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() { | ||
208 | |||
209 | return list; | ||
210 | } | ||
211 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() { | ||
212 | |||
213 | return list; | ||
214 | } | ||
215 | |||
216 | |||
217 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | ||
218 | { | ||
219 | |||
220 | return m_currentQuery; | ||
221 | } | ||
diff --git a/libopie/pim/odatebookaccessbackend_sql.h b/libopie/pim/odatebookaccessbackend_sql.h new file mode 100644 index 0000000..85e0d4f --- a/dev/null +++ b/libopie/pim/odatebookaccessbackend_sql.h | |||
@@ -0,0 +1,60 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H | ||
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H | ||
3 | |||
4 | #include <qmap.h> | ||
5 | |||
6 | #include "odatebookaccessbackend.h" | ||
7 | |||
8 | class OSQLDriver; | ||
9 | |||
10 | /** | ||
11 | * This is the default SQL implementation for DateBoook SQL storage | ||
12 | * It fully implements the interface | ||
13 | * @see ODateBookAccessBackend | ||
14 | * @see OPimAccessBackend | ||
15 | */ | ||
16 | class ODateBookAccessBackend_SQL : public ODateBookAccessBackend { | ||
17 | public: | ||
18 | ODateBookAccessBackend_SQL( const QString& appName, | ||
19 | const QString& fileName = QString::null); | ||
20 | ~ODateBookAccessBackend_SQL(); | ||
21 | |||
22 | bool load(); | ||
23 | bool reload(); | ||
24 | bool save(); | ||
25 | |||
26 | QArray<int> allRecords()const; | ||
27 | QArray<int> matchRegexp(const QRegExp &r) const; | ||
28 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); | ||
29 | OEvent find( int uid )const; | ||
30 | void clear(); | ||
31 | bool add( const OEvent& ev ); | ||
32 | bool remove( int uid ); | ||
33 | bool replace( const OEvent& ev ); | ||
34 | |||
35 | QArray<UID> rawEvents()const; | ||
36 | QArray<UID> rawRepeats()const; | ||
37 | QArray<UID> nonRepeats()const; | ||
38 | |||
39 | OEvent::ValueList directNonRepeats(); | ||
40 | OEvent::ValueList directRawRepeats(); | ||
41 | |||
42 | private: | ||
43 | bool loadFile(); | ||
44 | QString m_fileName; | ||
45 | QArray<int> m_uids; | ||
46 | |||
47 | QMap<int, QString> m_fieldMap; | ||
48 | |||
49 | OSQLDriver* m_driver; | ||
50 | |||
51 | class Private; | ||
52 | Private *d; | ||
53 | |||
54 | void initFields(); | ||
55 | void update(); | ||
56 | QArray<int> extractUids( OSQLResult& res ) const; | ||
57 | |||
58 | }; | ||
59 | |||
60 | #endif | ||
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp index 39c43c5..929d004 100644 --- a/libopie/pim/odatebookaccessbackend_xml.cpp +++ b/libopie/pim/odatebookaccessbackend_xml.cpp | |||
@@ -79,3 +79,3 @@ namespace { | |||
79 | FNote, | 79 | FNote, |
80 | FCreated, | 80 | FCreated, // Should't this be called FRCreated ? |
81 | FTimeZone, | 81 | FTimeZone, |
@@ -85,2 +85,4 @@ namespace { | |||
85 | }; | 85 | }; |
86 | |||
87 | // FIXME: Use OEvent::toMap() here !! (eilers) | ||
86 | inline void save( const OEvent& ev, QString& buf ) { | 88 | inline void save( const OEvent& ev, QString& buf ) { |
@@ -277,3 +279,3 @@ bool ODateBookAccessBackend_XML::remove( int uid ) { | |||
277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 279 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
278 | replace( ev.uid() ); | 280 | replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers) |
279 | return add( ev ); | 281 | return add( ev ); |
@@ -323,2 +325,4 @@ OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | |||
323 | } | 325 | } |
326 | |||
327 | // FIXME: Use OEvent::fromMap() (eilers) | ||
324 | bool ODateBookAccessBackend_XML::loadFile() { | 328 | bool ODateBookAccessBackend_XML::loadFile() { |
@@ -361,3 +365,3 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
361 | dict.insert( "note", new int(FNote) ); | 365 | dict.insert( "note", new int(FNote) ); |
362 | dict.insert( "created", new int(FCreated) ); | 366 | dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? |
363 | dict.insert( "recparent", new int(FRecParent) ); | 367 | dict.insert( "recparent", new int(FRecParent) ); |
@@ -446,2 +450,4 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
446 | } | 450 | } |
451 | |||
452 | // FIXME: Use OEvent::fromMap() which makes this obsolete.. (eilers) | ||
447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 453 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp index 7bcf944..c916297 100644 --- a/libopie/pim/oevent.cpp +++ b/libopie/pim/oevent.cpp | |||
@@ -1,2 +1,3 @@ | |||
1 | #include <qshared.h> | 1 | #include <qshared.h> |
2 | #include <qarray.h> | ||
2 | 3 | ||
@@ -358,6 +359,132 @@ void OEvent::deref() { | |||
358 | } | 359 | } |
359 | // FIXME | 360 | // Exporting Event data to map. Using the same |
361 | // encoding as ODateBookAccessBackend_xml does.. | ||
362 | // Thus, we could remove the stuff there and use this | ||
363 | // for it and for all other places.. | ||
364 | // Encoding should happen at one place, only ! (eilers) | ||
360 | QMap<int, QString> OEvent::toMap()const { | 365 | QMap<int, QString> OEvent::toMap()const { |
361 | return QMap<int, QString>(); | 366 | QMap<int, QString> retMap; |
367 | |||
368 | retMap.insert( OEvent::FUid, QString::number( uid() ) ); | ||
369 | retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) )); | ||
370 | retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) ); | ||
371 | retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) ); | ||
372 | retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" ); | ||
373 | OPimAlarm alarm = notifiers().alarms()[0]; | ||
374 | retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); | ||
375 | retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" ); | ||
376 | |||
377 | OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); | ||
378 | retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OTimeZone::utc() ) ) ) ); | ||
379 | retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OTimeZone::utc() ) ) ) ); | ||
380 | retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) ); | ||
381 | retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? "None" : timeZone() ); | ||
382 | if( parent() ) | ||
383 | retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); | ||
384 | if( children().count() ){ | ||
385 | QArray<int> childr = children(); | ||
386 | QString buf; | ||
387 | for ( uint i = 0; i < childr.count(); i++ ) { | ||
388 | if ( i != 0 ) buf += " "; | ||
389 | buf += QString::number( childr[i] ); | ||
390 | } | ||
391 | retMap.insert( OEvent::FRecChildren, buf ); | ||
392 | } | ||
393 | |||
394 | // Add recurrence stuff | ||
395 | if( hasRecurrence() ){ | ||
396 | ORecur recur = recurrence(); | ||
397 | QMap<int, QString> recFields = recur.toMap(); | ||
398 | retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); | ||
399 | retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] ); | ||
400 | retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] ); | ||
401 | retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] ); | ||
402 | retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); | ||
403 | retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] ); | ||
404 | retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); | ||
405 | retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); | ||
406 | } | ||
407 | |||
408 | return retMap; | ||
409 | } | ||
410 | |||
411 | void OEvent::fromMap( const QMap<int, QString>& map ) | ||
412 | { | ||
413 | |||
414 | // We just want to set the UID if it is really stored. | ||
415 | if ( !map[OEvent::FUid].isEmpty() ) | ||
416 | setUid( map[OEvent::FUid].toInt() ); | ||
417 | |||
418 | setCategories( idsFromString( map[OEvent::FCategories] ) ); | ||
419 | setDescription( map[OEvent::FDescription] ); | ||
420 | setLocation( map[OEvent::FLocation] ); | ||
421 | |||
422 | if ( map[OEvent::FType] == "AllDay" ) | ||
423 | setAllDay( true ); | ||
424 | else | ||
425 | setAllDay( false ); | ||
426 | |||
427 | int alarmTime = -1; | ||
428 | if( !map[OEvent::FAlarm].isEmpty() ) | ||
429 | alarmTime = map[OEvent::FAlarm].toInt(); | ||
430 | |||
431 | int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); | ||
432 | if ( ( alarmTime != -1 ) ){ | ||
433 | QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); | ||
434 | OPimAlarm al( sound , dt ); | ||
435 | notifiers().add( al ); | ||
436 | } | ||
437 | if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){ | ||
438 | setTimeZone( map[OEvent::FTimeZone] ); | ||
439 | } | ||
440 | |||
441 | time_t start = (time_t) map[OEvent::FStart].toLong(); | ||
442 | time_t end = (time_t) map[OEvent::FEnd].toLong(); | ||
443 | |||
444 | /* AllDay is always in UTC */ | ||
445 | if ( isAllDay() ) { | ||
446 | OTimeZone utc = OTimeZone::utc(); | ||
447 | setStartDateTime( utc.fromUTCDateTime( start ) ); | ||
448 | setEndDateTime ( utc.fromUTCDateTime( end ) ); | ||
449 | setTimeZone( "UTC"); // make sure it is really utc | ||
450 | }else { | ||
451 | /* to current date time */ | ||
452 | // qWarning(" Start is %d", start ); | ||
453 | OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); | ||
454 | QDateTime date = zone.toDateTime( start ); | ||
455 | qWarning(" Start is %s", date.toString().latin1() ); | ||
456 | setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | ||
457 | |||
458 | date = zone.toDateTime( end ); | ||
459 | setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | ||
460 | } | ||
461 | |||
462 | if ( !map[OEvent::FRecParent].isEmpty() ) | ||
463 | setParent( map[OEvent::FRecParent].toInt() ); | ||
464 | |||
465 | if ( !map[OEvent::FRecChildren].isEmpty() ){ | ||
466 | QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); | ||
467 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
468 | addChild( (*it).toInt() ); | ||
469 | } | ||
362 | } | 470 | } |
471 | |||
472 | // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. | ||
473 | if( !map[OEvent::FRType].isEmpty() ){ | ||
474 | QMap<int, QString> recFields; | ||
475 | recFields.insert( ORecur::RType, map[OEvent::FRType] ); | ||
476 | recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] ); | ||
477 | recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] ); | ||
478 | recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] ); | ||
479 | recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] ); | ||
480 | recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] ); | ||
481 | recFields.insert( ORecur::Created, map[OEvent::FRCreated] ); | ||
482 | recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] ); | ||
483 | ORecur recur( recFields ); | ||
484 | setRecurrence( recur ); | ||
485 | } | ||
486 | |||
487 | } | ||
488 | |||
489 | |||
363 | int OEvent::parent()const { | 490 | int OEvent::parent()const { |
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h index 30f442e..9218c97 100644 --- a/libopie/pim/oevent.h +++ b/libopie/pim/oevent.h | |||
@@ -43,17 +43,26 @@ public: | |||
43 | * RecordFields contain possible attributes | 43 | * RecordFields contain possible attributes |
44 | * used in the Results of toMap().. | ||
44 | */ | 45 | */ |
45 | enum RecordFields { | 46 | enum RecordFields { |
46 | Uid = Qtopia::UID_ID, | 47 | FUid = Qtopia::UID_ID, |
47 | Category = Qtopia::CATEGORY_ID, | 48 | FCategories = Qtopia::CATEGORY_ID, |
48 | Description, | 49 | FDescription = 0, |
49 | Location, | 50 | FLocation, |
50 | Alarm, | 51 | FType, |
51 | Reminder, | 52 | FAlarm, |
52 | Recurrence, | 53 | FSound, |
53 | Note, | 54 | FRType, |
54 | Created, | 55 | FRWeekdays, |
55 | StartDate, | 56 | FRPosition, |
56 | EndDate, | 57 | FRFreq, |
57 | AllDay, | 58 | FRHasEndDate, |
58 | TimeZone | 59 | FREndDate, |
60 | FRCreated, | ||
61 | FRExceptions, | ||
62 | FStart, | ||
63 | FEnd, | ||
64 | FNote, | ||
65 | FTimeZone, | ||
66 | FRecParent, | ||
67 | FRecChildren, | ||
59 | }; | 68 | }; |
@@ -134,2 +143,3 @@ public: | |||
134 | QMap<int, QString> toMap()const; | 143 | QMap<int, QString> toMap()const; |
144 | void fromMap( const QMap<int, QString>& map ); | ||
135 | QString recordField(int )const; | 145 | QString recordField(int )const; |
diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp index 8c9ad46..f46f22e 100644 --- a/libopie/pim/orecur.cpp +++ b/libopie/pim/orecur.cpp | |||
@@ -36,2 +36,10 @@ ORecur::ORecur() { | |||
36 | } | 36 | } |
37 | |||
38 | ORecur::ORecur( const QMap<int, QString>& map ) | ||
39 | { | ||
40 | ORecur(); | ||
41 | fromMap( map ); | ||
42 | } | ||
43 | |||
44 | |||
37 | ORecur::ORecur( const ORecur& rec) | 45 | ORecur::ORecur( const ORecur& rec) |
diff --git a/libopie/pim/orecur.h b/libopie/pim/orecur.h index 47901b0..7750c12 100644 --- a/libopie/pim/orecur.h +++ b/libopie/pim/orecur.h | |||
@@ -24,2 +24,3 @@ public: | |||
24 | ORecur(); | 24 | ORecur(); |
25 | ORecur( const QMap<int, QString>& map ); | ||
25 | ORecur( const ORecur& ); | 26 | ORecur( const ORecur& ); |
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 3913661..75a0860 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -301,3 +301,3 @@ namespace { | |||
301 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 301 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
302 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) | 302 | : OTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) |
303 | { | 303 | { |
@@ -313,3 +313,6 @@ OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | |||
313 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 313 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
314 | if( m_driver ) | ||
315 | delete m_driver; | ||
314 | } | 316 | } |
317 | |||
315 | bool OTodoAccessBackendSQL::load(){ | 318 | bool OTodoAccessBackendSQL::load(){ |