author | eilers <eilers> | 2003-12-22 10:19:25 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-12-22 10:19:25 (UTC) |
commit | ae70312b1613e26b4ef89a2c9821d9531b82e987 (patch) (unidiff) | |
tree | 7eb70bc45ee29e94da27a18b0136eb4a14e59fa6 /libopie/pim | |
parent | 9e7aafdb7c76d29fee742d53131a73dd60aded2b (diff) | |
download | opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.zip opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.tar.gz opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.tar.bz2 |
Finishing implementation of sql-backend for datebook. But I have to
port the PIM datebook application to use it, before I could debug the
whole stuff.
Thus, PIM-Database backend is finished, but highly experimental. And some
parts are still generic. For instance, the "queryByExample()" methods are
not (or not fully) implemented. Todo: custom-entries not stored.
The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
expression search in the database, which is not supported by sqlite !
Therefore we need either an extended sqlite or a workaround which would
be very slow and memory consuming..
-rw-r--r-- | libopie/pim/obackendfactory.h | 24 | ||||
-rw-r--r-- | libopie/pim/ocontactaccess.h | 14 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_sql.cpp | 18 | ||||
-rw-r--r-- | libopie/pim/odatebookaccess.cpp | 19 | ||||
-rw-r--r-- | libopie/pim/odatebookaccess.h | 9 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend.cpp | 34 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend.h | 19 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend_sql.cpp | 231 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend_sql.h | 2 | ||||
-rw-r--r-- | libopie/pim/oevent.cpp | 13 | ||||
-rw-r--r-- | libopie/pim/oevent.h | 6 | ||||
-rw-r--r-- | libopie/pim/otimezone.cpp | 11 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 2 | ||||
-rw-r--r-- | libopie/pim/test/converter.cpp | 45 | ||||
-rwxr-xr-x | libopie/pim/test/converter.h | 18 | ||||
-rw-r--r-- | libopie/pim/test/converter.pro | 2 |
16 files changed, 394 insertions, 73 deletions
diff --git a/libopie/pim/obackendfactory.h b/libopie/pim/obackendfactory.h index 3567687..761ab9a 100644 --- a/libopie/pim/obackendfactory.h +++ b/libopie/pim/obackendfactory.h | |||
@@ -15,8 +15,20 @@ | |||
15 | * Version: $Id$ | 15 | * Version: $Id$ |
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. |
22 | * A lot of changes fill follow... | 34 | * A lot of changes fill follow... |
@@ -79,8 +91,9 @@ | |||
79 | 91 | ||
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 | ||
85 | class OBackendPrivate; | 98 | class OBackendPrivate; |
86 | 99 | ||
@@ -142,9 +155,9 @@ class OBackendFactory | |||
142 | if ( backend == "sql" ) | 155 | if ( backend == "sql" ) |
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 ); |
150 | case CONTACT: | 163 | case CONTACT: |
@@ -152,15 +165,20 @@ class OBackendFactory | |||
152 | if ( backend == "sql" ) | 165 | if ( backend == "sql" ) |
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: |
166 | return NULL; | 184 | return NULL; |
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h index 9b0a719..bd6da40 100644 --- a/libopie/pim/ocontactaccess.h +++ b/libopie/pim/ocontactaccess.h | |||
@@ -16,8 +16,20 @@ | |||
16 | * Version: $Id$ | 16 | * Version: $Id$ |
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 | * |
23 | * Revision 1.8.2.1 2003/06/30 14:34:19 eilers | 35 | * Revision 1.8.2.1 2003/06/30 14:34:19 eilers |
@@ -77,9 +89,9 @@ | |||
77 | * This is just a frontend for the real database handling which is | 89 | * This is just a frontend for the real database handling which is |
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 | */ |
84 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 96 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
85 | { | 97 | { |
diff --git a/libopie/pim/ocontactaccessbackend_sql.cpp b/libopie/pim/ocontactaccessbackend_sql.cpp index dd9dbde..a5be4c8 100644 --- a/libopie/pim/ocontactaccessbackend_sql.cpp +++ b/libopie/pim/ocontactaccessbackend_sql.cpp | |||
@@ -13,8 +13,20 @@ | |||
13 | * Version: $Id$ | 13 | * Version: $Id$ |
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 | * |
20 | * Revision 1.2 2003/09/29 07:44:26 eilers | 32 | * Revision 1.2 2003/09/29 07:44:26 eilers |
@@ -509,18 +521,18 @@ bool OContactAccessBackend_SQL::reload() | |||
509 | } | 521 | } |
510 | 522 | ||
511 | bool OContactAccessBackend_SQL::save() | 523 | bool 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 | ||
517 | void OContactAccessBackend_SQL::clear () | 529 | 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 | ||
525 | bool OContactAccessBackend_SQL::wasChangedExternally() | 537 | bool OContactAccessBackend_SQL::wasChangedExternally() |
526 | { | 538 | { |
diff --git a/libopie/pim/odatebookaccess.cpp b/libopie/pim/odatebookaccess.cpp index a3661a3..82934f9 100644 --- a/libopie/pim/odatebookaccess.cpp +++ b/libopie/pim/odatebookaccess.cpp | |||
@@ -55,12 +55,27 @@ ODateBookAccess::List ODateBookAccess::nonRepeats()const { | |||
55 | * @param from Include all events from... | 55 | * @param from Include all events from... |
56 | * @param to Include all events to... | 56 | * @param to Include all events to... |
57 | */ | 57 | */ |
58 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) { | 58 | OEffectiveEvent::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 | */ |
64 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) { | 64 | OEffectiveEvent::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 | */ | ||
73 | OEffectiveEvent::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 | */ | ||
79 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) { | ||
80 | return m_backEnd->effectiveNonRepeatingEvents( start ); | ||
66 | } | 81 | } |
diff --git a/libopie/pim/odatebookaccess.h b/libopie/pim/odatebookaccess.h index 7c7a63f..62196da 100644 --- a/libopie/pim/odatebookaccess.h +++ b/libopie/pim/odatebookaccess.h | |||
@@ -12,9 +12,9 @@ | |||
12 | * All access to the datebook should be done via this class. | 12 | * All access to the datebook should be done via this class. |
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 | */ |
18 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { | 18 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { |
19 | public: | 19 | public: |
20 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); | 20 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); |
@@ -28,10 +28,13 @@ public: | |||
28 | 28 | ||
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 | ||
35 | private: | 38 | private: |
36 | ODateBookAccessBackend* m_backEnd; | 39 | ODateBookAccessBackend* m_backEnd; |
37 | class Private; | 40 | class Private; |
diff --git a/libopie/pim/odatebookaccessbackend.cpp b/libopie/pim/odatebookaccessbackend.cpp index 8fa1a68..f0c5d65 100644 --- a/libopie/pim/odatebookaccessbackend.cpp +++ b/libopie/pim/odatebookaccessbackend.cpp | |||
@@ -126,23 +126,49 @@ ODateBookAccessBackend::ODateBookAccessBackend() | |||
126 | } | 126 | } |
127 | ODateBookAccessBackend::~ODateBookAccessBackend() { | 127 | ODateBookAccessBackend::~ODateBookAccessBackend() { |
128 | 128 | ||
129 | } | 129 | } |
130 | OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDate& from, | 130 | OEffectiveEvent::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(); |
134 | 134 | ||
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 | } |
143 | OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDateTime& dt ) { | 143 | OEffectiveEvent::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 | |||
158 | OEffectiveEvent::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 | |||
169 | OEffectiveEvent::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; |
148 | QDateTime dtTmp; | 174 | QDateTime dtTmp; |
diff --git a/libopie/pim/odatebookaccessbackend.h b/libopie/pim/odatebookaccessbackend.h index 3c02c42..3472ab3 100644 --- a/libopie/pim/odatebookaccessbackend.h +++ b/libopie/pim/odatebookaccessbackend.h | |||
@@ -59,15 +59,28 @@ public: | |||
59 | * Effective Events are special event occuring during a time frame. This method does calcualte | 59 | * Effective Events are special event occuring during a time frame. This method does calcualte |
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 | ||
71 | private: | 84 | private: |
72 | class Private; | 85 | class Private; |
73 | Private *d; | 86 | Private *d; |
diff --git a/libopie/pim/odatebookaccessbackend_sql.cpp b/libopie/pim/odatebookaccessbackend_sql.cpp index 9769bf7..e893b38 100644 --- a/libopie/pim/odatebookaccessbackend_sql.cpp +++ b/libopie/pim/odatebookaccessbackend_sql.cpp | |||
@@ -13,8 +13,20 @@ | |||
13 | * Version: $Id$ | 13 | * Version: $Id$ |
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 | * |
20 | * | 32 | * |
@@ -25,27 +37,24 @@ | |||
25 | 37 | ||
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 | ||
37 | namespace { | 47 | #include "orecur.h" |
38 | 48 | #include "odatebookaccessbackend_sql.h" | |
39 | 49 | ||
40 | 50 | ||
41 | }; | ||
42 | 51 | ||
43 | ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | 52 | ODateBookAccessBackend_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; |
51 | m_driver = man.standard(); | 60 | m_driver = man.standard(); |
@@ -56,8 +65,10 @@ ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | |||
56 | load(); | 65 | load(); |
57 | } | 66 | } |
58 | 67 | ||
59 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { | 68 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { |
69 | if( m_driver ) | ||
70 | delete m_driver; | ||
60 | } | 71 | } |
61 | 72 | ||
62 | void ODateBookAccessBackend_SQL::initFields() | 73 | void ODateBookAccessBackend_SQL::initFields() |
63 | { | 74 | { |
@@ -77,15 +88,22 @@ void ODateBookAccessBackend_SQL::initFields() | |||
77 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); | 88 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); |
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 | ||
90 | bool ODateBookAccessBackend_SQL::load() | 108 | bool ODateBookAccessBackend_SQL::load() |
91 | { | 109 | { |
@@ -98,14 +116,16 @@ bool ODateBookAccessBackend_SQL::load() | |||
98 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; | 116 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; |
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 ) |
111 | return false; | 131 | return false; |
@@ -121,52 +141,33 @@ void ODateBookAccessBackend_SQL::update() | |||
121 | QString qu = "select uid from datebook"; | 141 | QString qu = "select uid from datebook"; |
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 | ||
129 | m_uids = extractUids( res ); | 149 | m_uids = extractUids( res ); |
130 | 150 | ||
131 | } | 151 | } |
132 | 152 | ||
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 | bool ODateBookAccessBackend_SQL::reload() |
153 | { | 154 | { |
154 | return load(); | 155 | return load(); |
155 | } | 156 | } |
156 | 157 | ||
157 | bool ODateBookAccessBackend_SQL::save() | 158 | bool 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 | ||
162 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const | 163 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const |
163 | { | 164 | { |
164 | return m_uids; | 165 | return m_uids; |
165 | } | 166 | } |
166 | 167 | ||
167 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { | 168 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { |
168 | return QArray<int>(); | 169 | return QArray<int>(); |
169 | } | 170 | } |
170 | 171 | ||
171 | void ODateBookAccessBackend_SQL::clear() | 172 | void ODateBookAccessBackend_SQL::clear() |
172 | { | 173 | { |
@@ -175,47 +176,181 @@ void ODateBookAccessBackend_SQL::clear() | |||
175 | 176 | ||
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 | ||
182 | OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | 184 | OEvent 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 | ||
185 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) { | 209 | bool 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 | } |
188 | bool ODateBookAccessBackend_SQL::remove( int uid ) { | ||
189 | 250 | ||
190 | return true; | 251 | bool 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 | } |
192 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) { | 266 | |
267 | bool 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 | } |
196 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const { | 272 | |
273 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const | ||
274 | { | ||
197 | return allRecords(); | 275 | return allRecords(); |
198 | } | 276 | } |
199 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const { | ||
200 | 277 | ||
201 | return ints; | 278 | QArray<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 | } |
203 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const { | ||
204 | 290 | ||
205 | return ints; | 291 | QArray<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 | } |
207 | OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() { | ||
208 | 303 | ||
209 | return list; | 304 | OEvent::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 | } |
211 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() { | 316 | OEvent::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 | ||
217 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 329 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
218 | { | 330 | { |
331 | QArray<int> null; | ||
332 | return null; | ||
333 | } | ||
334 | |||
335 | /* ===== Private Functions ========================================== */ | ||
336 | |||
337 | QArray<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/libopie/pim/odatebookaccessbackend_sql.h b/libopie/pim/odatebookaccessbackend_sql.h index 85e0d4f..f39e154 100644 --- a/libopie/pim/odatebookaccessbackend_sql.h +++ b/libopie/pim/odatebookaccessbackend_sql.h | |||
@@ -1,8 +1,9 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H |
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 | ||
8 | class OSQLDriver; | 9 | class OSQLDriver; |
@@ -44,8 +45,9 @@ private: | |||
44 | QString m_fileName; | 45 | QString m_fileName; |
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 | ||
51 | class Private; | 53 | class Private; |
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp index ec05e77..9b31957 100644 --- a/libopie/pim/oevent.cpp +++ b/libopie/pim/oevent.cpp | |||
@@ -76,8 +76,17 @@ OEvent::OEvent( const OEvent& ev) | |||
76 | : OPimRecord( ev ), data( ev.data ) | 76 | : OPimRecord( ev ), data( ev.data ) |
77 | { | 77 | { |
78 | data->ref(); | 78 | data->ref(); |
79 | } | 79 | } |
80 | |||
81 | OEvent::OEvent( const QMap<int, QString> map ) | ||
82 | : OPimRecord( 0 ) | ||
83 | { | ||
84 | data = new Data; | ||
85 | |||
86 | fromMap( map ); | ||
87 | } | ||
88 | |||
80 | OEvent::~OEvent() { | 89 | OEvent::~OEvent() { |
81 | if ( data->deref() ) { | 90 | if ( data->deref() ) { |
82 | delete data; | 91 | delete data; |
83 | data = 0; | 92 | data = 0; |
@@ -402,8 +411,12 @@ QMap<int, QString> OEvent::toMap()const { | |||
402 | retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); | 411 | retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); |
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; |
409 | } | 422 | } |
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h index 9218c97..9eb948f 100644 --- a/libopie/pim/oevent.h +++ b/libopie/pim/oevent.h | |||
@@ -75,8 +75,14 @@ public: | |||
75 | /** | 75 | /** |
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 | ||
82 | QString description()const; | 88 | QString description()const; |
diff --git a/libopie/pim/otimezone.cpp b/libopie/pim/otimezone.cpp index b2bd3aa..34659c3 100644 --- a/libopie/pim/otimezone.cpp +++ b/libopie/pim/otimezone.cpp | |||
@@ -15,13 +15,18 @@ namespace { | |||
15 | return ret; | 15 | return ret; |
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 ) ); |
27 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); | 32 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); |
@@ -40,14 +45,18 @@ namespace { | |||
40 | broken.tm_min = t.minute(); | 45 | broken.tm_min = t.minute(); |
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 | } |
53 | OTimeZone::OTimeZone( const ZoneName& zone ) | 62 | OTimeZone::OTimeZone( const ZoneName& zone ) |
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 75a0860..3764c7e 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -329,9 +329,9 @@ bool OTodoAccessBackendSQL::reload(){ | |||
329 | return load(); | 329 | return load(); |
330 | } | 330 | } |
331 | 331 | ||
332 | bool OTodoAccessBackendSQL::save(){ | 332 | bool OTodoAccessBackendSQL::save(){ |
333 | return m_driver->close(); | 333 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
334 | } | 334 | } |
335 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 335 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
336 | if (m_dirty ) | 336 | if (m_dirty ) |
337 | update(); | 337 | update(); |
diff --git a/libopie/pim/test/converter.cpp b/libopie/pim/test/converter.cpp index 650d119..bfdb605 100644 --- a/libopie/pim/test/converter.cpp +++ b/libopie/pim/test/converter.cpp | |||
@@ -8,15 +8,23 @@ | |||
8 | #include <opie/ocontactaccess.h> | 8 | #include <opie/ocontactaccess.h> |
9 | #include <opie/ocontactaccessbackend_xml.h> | 9 | #include <opie/ocontactaccessbackend_xml.h> |
10 | #include <opie/ocontactaccessbackend_sql.h> | 10 | #include <opie/ocontactaccessbackend_sql.h> |
11 | 11 | ||
12 | #include <opie/odatebookaccess.h> | ||
13 | #include <opie/odatebookaccessbackend_xml.h> | ||
14 | #include <opie/odatebookaccessbackend_sql.h> | ||
15 | |||
16 | // #define _ADDRESSBOOK_ACCESS | ||
17 | |||
12 | Converter::Converter(){ | 18 | Converter::Converter(){ |
13 | } | 19 | } |
14 | 20 | ||
15 | void Converter::start_conversion(){ | 21 | void Converter::start_conversion(){ |
16 | qWarning("Converting Contacts from XML to SQL.."); | 22 | qWarning("Converting Contacts from XML to SQL.."); |
17 | 23 | ||
18 | // Creating backends to the requested databases.. | 24 | // Creating backends to the requested databases.. |
25 | |||
26 | #ifdef _ADDRESSBOOK_ACCESS | ||
19 | OContactAccessBackend* xmlBackend = new OContactAccessBackend_XML( "Converter", | 27 | OContactAccessBackend* xmlBackend = new OContactAccessBackend_XML( "Converter", |
20 | QString::null ); | 28 | QString::null ); |
21 | 29 | ||
22 | OContactAccessBackend* sqlBackend = new OContactAccessBackend_SQL( QString::null, | 30 | OContactAccessBackend* sqlBackend = new OContactAccessBackend_SQL( QString::null, |
@@ -25,16 +33,32 @@ void Converter::start_conversion(){ | |||
25 | OContactAccess* xmlAccess = new OContactAccess ( "addressbook_xml", | 33 | OContactAccess* xmlAccess = new OContactAccess ( "addressbook_xml", |
26 | QString::null , xmlBackend, true ); | 34 | QString::null , xmlBackend, true ); |
27 | 35 | ||
28 | OContactAccess* sqlAccess = new OContactAccess ( "addressbook_sql", | 36 | OContactAccess* sqlAccess = new OContactAccess ( "addressbook_sql", |
29 | QString::null , sqlBackend, true ); | 37 | QString::null ); |
30 | 38 | ||
39 | #else | ||
40 | ODateBookAccessBackend* xmlBackend = new ODateBookAccessBackend_XML( "Converter", | ||
41 | QString::null ); | ||
42 | |||
43 | ODateBookAccessBackend* sqlBackend = new ODateBookAccessBackend_SQL( QString::null, | ||
44 | QString::null ); | ||
45 | // Put the created backends into frontends to access them | ||
46 | ODateBookAccess* xmlAccess = new ODateBookAccess ( xmlBackend ); | ||
47 | |||
48 | ODateBookAccess* sqlAccess = new ODateBookAccess ( sqlBackend ); | ||
49 | |||
50 | xmlAccess->load(); | ||
51 | |||
52 | #endif | ||
53 | |||
31 | QTime t; | 54 | QTime t; |
32 | t.start(); | 55 | t.start(); |
33 | 56 | ||
34 | // Clean the sql-database.. | 57 | // Clean the sql-database.. |
35 | sqlAccess->clear(); | 58 | sqlAccess->clear(); |
36 | 59 | ||
60 | #ifdef _ADDRESSBOOK_ACCESS | ||
37 | // Now trasmit every contact from the xml database to the sql-database | 61 | // Now trasmit every contact from the xml database to the sql-database |
38 | OContactAccess::List contactList = xmlAccess->allRecords(); | 62 | OContactAccess::List contactList = xmlAccess->allRecords(); |
39 | m_progressBar->setTotalSteps( contactList.count() ); | 63 | m_progressBar->setTotalSteps( contactList.count() ); |
40 | int count = 0; | 64 | int count = 0; |
@@ -44,9 +68,24 @@ void Converter::start_conversion(){ | |||
44 | sqlAccess->add( *it ); | 68 | sqlAccess->add( *it ); |
45 | m_progressBar->setProgress( ++count ); | 69 | m_progressBar->setProgress( ++count ); |
46 | } | 70 | } |
47 | } | 71 | } |
48 | 72 | #else | |
73 | // Now transmit every contact from the xml database to the sql-database | ||
74 | ODateBookAccess::List dateList = xmlAccess->allRecords(); | ||
75 | m_progressBar->setTotalSteps( dateList.count() ); | ||
76 | qWarning( "Number of elements to copy: %d", dateList.count() ); | ||
77 | |||
78 | int count = 0; | ||
79 | if ( sqlAccess && xmlAccess ){ | ||
80 | ODateBookAccess::List::Iterator it; | ||
81 | for ( it = dateList.begin(); it != dateList.end(); ++it ){ | ||
82 | sqlAccess->add( *it ); | ||
83 | m_progressBar->setProgress( ++count ); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | #endif | ||
49 | // Delete the frontends. Backends will be deleted automatically, too ! | 88 | // Delete the frontends. Backends will be deleted automatically, too ! |
50 | delete sqlAccess; | 89 | delete sqlAccess; |
51 | 90 | ||
52 | qWarning("Conversion is finished and needed %d ms !", t.elapsed()); | 91 | qWarning("Conversion is finished and needed %d ms !", t.elapsed()); |
diff --git a/libopie/pim/test/converter.h b/libopie/pim/test/converter.h new file mode 100755 index 0000000..1cc2a7c --- a/dev/null +++ b/libopie/pim/test/converter.h | |||
@@ -0,0 +1,18 @@ | |||
1 | #ifndef _CONVERTER_H_ | ||
2 | #define _CONVERTER_H_ | ||
3 | |||
4 | |||
5 | #include "converter_base.h" | ||
6 | |||
7 | |||
8 | class Converter: public converter_base { | ||
9 | public: | ||
10 | Converter(); | ||
11 | |||
12 | void start_conversion(); | ||
13 | private: | ||
14 | |||
15 | }; | ||
16 | |||
17 | |||
18 | #endif | ||
diff --git a/libopie/pim/test/converter.pro b/libopie/pim/test/converter.pro index aa74bff..bd9c7a3 100644 --- a/libopie/pim/test/converter.pro +++ b/libopie/pim/test/converter.pro | |||
@@ -1,5 +1,5 @@ | |||
1 | TEMPLATE= app | 1 | # TEMPLATE= app |
2 | CONFIG = qt warn_on debug | 2 | CONFIG = qt warn_on debug |
3 | # CONFIG = qt warn_on release | 3 | # CONFIG = qt warn_on release |
4 | #HEADERS = | 4 | #HEADERS = |
5 | SOURCES = converter.cpp | 5 | SOURCES = converter.cpp |