author | zecke <zecke> | 2003-04-13 18:07:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-04-13 18:07:10 (UTC) |
commit | 6f610544d3db6198c90105b70fab1cc84f5a1fbd (patch) (unidiff) | |
tree | 964d18f0a4cca7383a31810aa922876751c4a22c /libopie2/opiepim/backend | |
parent | 0b311079ff19798866291034663757103c6ba935 (diff) | |
download | opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.zip opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.tar.gz opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.tar.bz2 |
More API doc
QString -> const QString&
QString = 0l -> QString::null
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 26 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.h | 32 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | 18 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | 171 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.h | 46 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend.h | 45 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.h | 6 |
8 files changed, 237 insertions, 114 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 3a73210..ad6cf5a 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -16,6 +16,11 @@ | |||
16 | * ===================================================================== | 16 | * ===================================================================== |
17 | * History: | 17 | * History: |
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.6 2003/04/13 18:07:10 zecke | ||
20 | * More API doc | ||
21 | * QString -> const QString& | ||
22 | * QString = 0l -> QString::null | ||
23 | * | ||
19 | * Revision 1.5 2003/02/21 23:31:52 zecke | 24 | * Revision 1.5 2003/02/21 23:31:52 zecke |
20 | * Add XML datebookresource | 25 | * Add XML datebookresource |
21 | * -clean up todoaccessxml header | 26 | * -clean up todoaccessxml header |
@@ -63,7 +68,21 @@ | |||
63 | #include "otodoaccesssql.h" | 68 | #include "otodoaccesssql.h" |
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | 71 | /** | |
72 | * This class is our factory. It will give us the default implementations | ||
73 | * of at least Todolist, Contacts and Datebook. In the future this class will | ||
74 | * allow users to switch the backend with ( XML->SQLite ) without the need | ||
75 | * to recompile.# | ||
76 | * This class as the whole PIM Api is making use of templates | ||
77 | * | ||
78 | * <pre> | ||
79 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | ||
80 | * backend->load(); | ||
81 | * </pre> | ||
82 | * | ||
83 | * @author Stefan Eilers | ||
84 | * @version 0.1 | ||
85 | */ | ||
67 | template<class T> | 86 | template<class T> |
68 | class OBackendFactory | 87 | class OBackendFactory |
69 | { | 88 | { |
@@ -76,6 +95,11 @@ class OBackendFactory | |||
76 | DATE | 95 | DATE |
77 | }; | 96 | }; |
78 | 97 | ||
98 | /** | ||
99 | * Returns a backend implementation for backendName | ||
100 | * @param backendName the type of the backend | ||
101 | * @param appName will be passed on to the backend | ||
102 | */ | ||
79 | static T* Default( const QString backendName, const QString& appName ){ | 103 | static T* Default( const QString backendName, const QString& appName ){ |
80 | 104 | ||
81 | // __asm__("int3"); | 105 | // __asm__("int3"); |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index 821f5bf..ebeb42d 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -19,6 +19,11 @@ | |||
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
23 | * More API doc | ||
24 | * QString -> const QString& | ||
25 | * QString = 0l -> QString::null | ||
26 | * | ||
22 | * Revision 1.4 2002/11/13 14:14:51 eilers | 27 | * Revision 1.4 2002/11/13 14:14:51 eilers |
23 | * Added sorted for Contacts.. | 28 | * Added sorted for Contacts.. |
24 | * | 29 | * |
@@ -44,15 +49,26 @@ | |||
44 | #include "ocontact.h" | 49 | #include "ocontact.h" |
45 | #include "opimaccessbackend.h" | 50 | #include "opimaccessbackend.h" |
46 | 51 | ||
47 | #include "qregexp.h" | 52 | #include <qregexp.h> |
48 | 53 | ||
54 | /** | ||
55 | * This class represents the interface of all Contact Backends. | ||
56 | * Derivates of this class will be used to access the contacts. | ||
57 | * As implementation currently XML and vCard exist. This class needs to be implemented | ||
58 | * if you want to provide your own storage. | ||
59 | * In all queries a list of uids is passed on instead of loading the actual record! | ||
60 | * | ||
61 | * @see OContactAccessBackend_VCard | ||
62 | * @see OContactAccessBackend_XML | ||
63 | */ | ||
49 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 64 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
50 | public: | 65 | public: |
51 | OContactAccessBackend() {} | 66 | OContactAccessBackend() {} |
52 | virtual ~OContactAccessBackend() {} | 67 | virtual ~OContactAccessBackend() {} |
53 | 68 | ||
54 | 69 | ||
55 | /** Return if database was changed externally. | 70 | /** |
71 | * Return if database was changed externally. | ||
56 | * This may just make sense on file based databases like a XML-File. | 72 | * This may just make sense on file based databases like a XML-File. |
57 | * It is used to prevent to overwrite the current database content | 73 | * It is used to prevent to overwrite the current database content |
58 | * if the file was already changed by something else ! | 74 | * if the file was already changed by something else ! |
@@ -68,18 +84,24 @@ class OContactAccessBackend: public OPimAccessBackend<OContact> { | |||
68 | 84 | ||
69 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 85 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
70 | 86 | ||
71 | /** Return all possible settings. | 87 | /** |
88 | * Return all possible settings. | ||
72 | * @return All settings provided by the current backend | 89 | * @return All settings provided by the current backend |
73 | * (i.e.: query_WildCards & query_IgnoreCase) | 90 | * (i.e.: query_WildCards & query_IgnoreCase) |
74 | */ | 91 | */ |
75 | virtual const uint querySettings() = 0; | 92 | virtual const uint querySettings() = 0; |
76 | 93 | ||
77 | /** Check whether settings are correct. | 94 | /** |
95 | * Check whether settings are correct. | ||
78 | * @return <i>true</i> if the given settings are correct and possible. | 96 | * @return <i>true</i> if the given settings are correct and possible. |
79 | */ | 97 | */ |
80 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 98 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
81 | 99 | ||
82 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | 100 | /** |
101 | * FIXME!!! | ||
102 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category | ||
103 | */ | ||
104 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | ||
83 | 105 | ||
84 | }; | 106 | }; |
85 | #endif | 107 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index f24523f..270bef3 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -17,6 +17,11 @@ | |||
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.10 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.9 2003/03/21 10:33:09 eilers | 25 | * Revision 1.9 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
@@ -76,7 +81,7 @@ | |||
76 | 81 | ||
77 | #include <qfile.h> | 82 | #include <qfile.h> |
78 | 83 | ||
79 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 84 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): |
80 | m_dirty( false ), | 85 | m_dirty( false ), |
81 | m_file( filename ) | 86 | m_file( filename ) |
82 | { | 87 | { |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h index 93e2da3..712d769 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | |||
@@ -17,6 +17,11 @@ | |||
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.6 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.5 2003/03/21 10:33:09 eilers | 25 | * Revision 1.5 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
@@ -47,9 +52,14 @@ | |||
47 | 52 | ||
48 | class VObject; | 53 | class VObject; |
49 | 54 | ||
55 | /** | ||
56 | * This is the vCard 2.1 implementation of the Contact Storage | ||
57 | * @see OContactAccessBackend_XML | ||
58 | * @see OPimAccessBackend | ||
59 | */ | ||
50 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 60 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
51 | public: | 61 | public: |
52 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); | 62 | OContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null ); |
53 | 63 | ||
54 | bool load (); | 64 | bool load (); |
55 | bool reload(); | 65 | bool reload(); |
@@ -59,7 +69,7 @@ class OContactAccessBackend_VCard : public OContactAccessBackend { | |||
59 | bool add ( const OContact& newcontact ); | 69 | bool add ( const OContact& newcontact ); |
60 | bool remove ( int uid ); | 70 | bool remove ( int uid ); |
61 | bool replace ( const OContact& contact ); | 71 | bool replace ( const OContact& contact ); |
62 | 72 | ||
63 | OContact find ( int uid ) const; | 73 | OContact find ( int uid ) const; |
64 | QArray<int> allRecords() const; | 74 | QArray<int> allRecords() const; |
65 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 75 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
@@ -69,7 +79,7 @@ class OContactAccessBackend_VCard : public OContactAccessBackend { | |||
69 | bool hasQuerySettings (uint querySettings) const; | 79 | bool hasQuerySettings (uint querySettings) const; |
70 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 80 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
71 | bool wasChangedExternally(); | 81 | bool wasChangedExternally(); |
72 | 82 | ||
73 | private: | 83 | private: |
74 | OContact parseVObject( VObject* obj ); | 84 | OContact parseVObject( VObject* obj ); |
75 | VObject* createVObject( const OContact& c ); | 85 | VObject* createVObject( const OContact& c ); |
@@ -77,7 +87,7 @@ private: | |||
77 | QDate convVCardDateToDate( const QString& datestr ); | 87 | QDate convVCardDateToDate( const QString& datestr ); |
78 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 88 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
79 | VObject *safeAddProp( VObject* o, const char* prop); | 89 | VObject *safeAddProp( VObject* o, const char* prop); |
80 | 90 | ||
81 | bool m_dirty : 1; | 91 | bool m_dirty : 1; |
82 | QString m_file; | 92 | QString m_file; |
83 | QMap<int, OContact> m_map; | 93 | QMap<int, OContact> m_map; |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index c5a7820..661cd51 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -17,6 +17,11 @@ | |||
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 25 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
21 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | 26 | * g++ compliance fix: default arguments belong into the declaration, but not the definition |
22 | * | 27 | * |
@@ -93,7 +98,7 @@ | |||
93 | #include <qregexp.h> | 98 | #include <qregexp.h> |
94 | #include <qarray.h> | 99 | #include <qarray.h> |
95 | #include <qmap.h> | 100 | #include <qmap.h> |
96 | #include <qdatetime.h> | 101 | #include <qdatetime.h> |
97 | 102 | ||
98 | #include <qpe/global.h> | 103 | #include <qpe/global.h> |
99 | 104 | ||
@@ -107,7 +112,7 @@ | |||
107 | using namespace Opie; | 112 | using namespace Opie; |
108 | 113 | ||
109 | 114 | ||
110 | OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename ): | 115 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): |
111 | m_changed( false ) | 116 | m_changed( false ) |
112 | { | 117 | { |
113 | // Just m_contactlist should call delete if an entry | 118 | // Just m_contactlist should call delete if an entry |
@@ -116,32 +121,32 @@ OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString | |||
116 | m_uidToContact.setAutoDelete( false ); | 121 | m_uidToContact.setAutoDelete( false ); |
117 | 122 | ||
118 | m_appName = appname; | 123 | m_appName = appname; |
119 | 124 | ||
120 | /* Set journalfile name ... */ | 125 | /* Set journalfile name ... */ |
121 | m_journalName = getenv("HOME"); | 126 | m_journalName = getenv("HOME"); |
122 | m_journalName +="/.abjournal" + appname; | 127 | m_journalName +="/.abjournal" + appname; |
123 | 128 | ||
124 | /* Expecting to access the default filename if nothing else is set */ | 129 | /* Expecting to access the default filename if nothing else is set */ |
125 | if ( filename.isEmpty() ){ | 130 | if ( filename.isEmpty() ){ |
126 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 131 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
127 | } else | 132 | } else |
128 | m_fileName = filename; | 133 | m_fileName = filename; |
129 | 134 | ||
130 | /* Load Database now */ | 135 | /* Load Database now */ |
131 | load (); | 136 | load (); |
132 | } | 137 | } |
133 | 138 | ||
134 | bool OContactAccessBackend_XML::save() | 139 | bool OContactAccessBackend_XML::save() |
135 | { | 140 | { |
136 | 141 | ||
137 | if ( !m_changed ) | 142 | if ( !m_changed ) |
138 | return true; | 143 | return true; |
139 | 144 | ||
140 | QString strNewFile = m_fileName + ".new"; | 145 | QString strNewFile = m_fileName + ".new"; |
141 | QFile f( strNewFile ); | 146 | QFile f( strNewFile ); |
142 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 147 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
143 | return false; | 148 | return false; |
144 | 149 | ||
145 | int total_written; | 150 | int total_written; |
146 | int idx_offset = 0; | 151 | int idx_offset = 0; |
147 | QString out; | 152 | QString out; |
@@ -174,7 +179,7 @@ bool OContactAccessBackend_XML::save() | |||
174 | out = ""; | 179 | out = ""; |
175 | } | 180 | } |
176 | out += " </Contacts>\n</AddressBook>\n"; | 181 | out += " </Contacts>\n</AddressBook>\n"; |
177 | 182 | ||
178 | // Write Footer | 183 | // Write Footer |
179 | cstr = out.utf8(); | 184 | cstr = out.utf8(); |
180 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 185 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
@@ -184,7 +189,7 @@ bool OContactAccessBackend_XML::save() | |||
184 | return false; | 189 | return false; |
185 | } | 190 | } |
186 | f.close(); | 191 | f.close(); |
187 | 192 | ||
188 | // move the file over, I'm just going to use the system call | 193 | // move the file over, I'm just going to use the system call |
189 | // because, I don't feel like using QDir. | 194 | // because, I don't feel like using QDir. |
190 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 195 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
@@ -193,19 +198,19 @@ bool OContactAccessBackend_XML::save() | |||
193 | // remove the tmp file... | 198 | // remove the tmp file... |
194 | QFile::remove( strNewFile ); | 199 | QFile::remove( strNewFile ); |
195 | } | 200 | } |
196 | 201 | ||
197 | /* The journalfile should be removed now... */ | 202 | /* The journalfile should be removed now... */ |
198 | removeJournal(); | 203 | removeJournal(); |
199 | 204 | ||
200 | m_changed = false; | 205 | m_changed = false; |
201 | return true; | 206 | return true; |
202 | } | 207 | } |
203 | 208 | ||
204 | bool OContactAccessBackend_XML::load () | 209 | bool OContactAccessBackend_XML::load () |
205 | { | 210 | { |
206 | m_contactList.clear(); | 211 | m_contactList.clear(); |
207 | m_uidToContact.clear(); | 212 | m_uidToContact.clear(); |
208 | 213 | ||
209 | /* Load XML-File and journal if it exists */ | 214 | /* Load XML-File and journal if it exists */ |
210 | if ( !load ( m_fileName, false ) ) | 215 | if ( !load ( m_fileName, false ) ) |
211 | return false; | 216 | return false; |
@@ -216,11 +221,11 @@ bool OContactAccessBackend_XML::load () | |||
216 | * crash happened... | 221 | * crash happened... |
217 | */ | 222 | */ |
218 | load (m_journalName, true); | 223 | load (m_journalName, true); |
219 | 224 | ||
220 | return true; | 225 | return true; |
221 | } | 226 | } |
222 | 227 | ||
223 | void OContactAccessBackend_XML::clear () | 228 | void OContactAccessBackend_XML::clear () |
224 | { | 229 | { |
225 | m_contactList.clear(); | 230 | m_contactList.clear(); |
226 | m_uidToContact.clear(); | 231 | m_uidToContact.clear(); |
@@ -231,46 +236,46 @@ void OContactAccessBackend_XML::clear () | |||
231 | bool OContactAccessBackend_XML::wasChangedExternally() | 236 | bool OContactAccessBackend_XML::wasChangedExternally() |
232 | { | 237 | { |
233 | QFileInfo fi( m_fileName ); | 238 | QFileInfo fi( m_fileName ); |
234 | 239 | ||
235 | QDateTime lastmod = fi.lastModified (); | 240 | QDateTime lastmod = fi.lastModified (); |
236 | 241 | ||
237 | return (lastmod != m_readtime); | 242 | return (lastmod != m_readtime); |
238 | } | 243 | } |
239 | 244 | ||
240 | QArray<int> OContactAccessBackend_XML::allRecords() const | 245 | QArray<int> OContactAccessBackend_XML::allRecords() const |
241 | { | 246 | { |
242 | QArray<int> uid_list( m_contactList.count() ); | 247 | QArray<int> uid_list( m_contactList.count() ); |
243 | 248 | ||
244 | uint counter = 0; | 249 | uint counter = 0; |
245 | QListIterator<OContact> it( m_contactList ); | 250 | QListIterator<OContact> it( m_contactList ); |
246 | for( ; it.current(); ++it ){ | 251 | for( ; it.current(); ++it ){ |
247 | uid_list[counter++] = (*it)->uid(); | 252 | uid_list[counter++] = (*it)->uid(); |
248 | } | 253 | } |
249 | 254 | ||
250 | return ( uid_list ); | 255 | return ( uid_list ); |
251 | } | 256 | } |
252 | 257 | ||
253 | OContact OContactAccessBackend_XML::find ( int uid ) const | 258 | OContact OContactAccessBackend_XML::find ( int uid ) const |
254 | { | 259 | { |
255 | OContact foundContact; //Create empty contact | 260 | OContact foundContact; //Create empty contact |
256 | 261 | ||
257 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); | 262 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); |
258 | 263 | ||
259 | if ( found ){ | 264 | if ( found ){ |
260 | foundContact = *found; | 265 | foundContact = *found; |
261 | } | 266 | } |
262 | 267 | ||
263 | return ( foundContact ); | 268 | return ( foundContact ); |
264 | } | 269 | } |
265 | 270 | ||
266 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 271 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
267 | const QDateTime& d ) | 272 | const QDateTime& d ) |
268 | { | 273 | { |
269 | 274 | ||
270 | QArray<int> m_currentQuery( m_contactList.count() ); | 275 | QArray<int> m_currentQuery( m_contactList.count() ); |
271 | QListIterator<OContact> it( m_contactList ); | 276 | QListIterator<OContact> it( m_contactList ); |
272 | uint arraycounter = 0; | 277 | uint arraycounter = 0; |
273 | 278 | ||
274 | for( ; it.current(); ++it ){ | 279 | for( ; it.current(); ++it ){ |
275 | /* Search all fields and compare them with query object. Store them into list | 280 | /* Search all fields and compare them with query object. Store them into list |
276 | * if all fields matches. | 281 | * if all fields matches. |
@@ -290,26 +295,26 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
290 | queryDate = new QDate( query.anniversary() ); | 295 | queryDate = new QDate( query.anniversary() ); |
291 | checkDate = new QDate( (*it)->anniversary() ); | 296 | checkDate = new QDate( (*it)->anniversary() ); |
292 | } | 297 | } |
293 | 298 | ||
294 | if ( queryDate->isValid() ){ | 299 | if ( queryDate->isValid() ){ |
295 | if( checkDate->isValid() ){ | 300 | if( checkDate->isValid() ){ |
296 | if ( settings & OContactAccess::DateYear ){ | 301 | if ( settings & OContactAccess::DateYear ){ |
297 | if ( queryDate->year() != checkDate->year() ) | 302 | if ( queryDate->year() != checkDate->year() ) |
298 | allcorrect = false; | 303 | allcorrect = false; |
299 | } | 304 | } |
300 | if ( settings & OContactAccess::DateMonth ){ | 305 | if ( settings & OContactAccess::DateMonth ){ |
301 | if ( queryDate->month() != checkDate->month() ) | 306 | if ( queryDate->month() != checkDate->month() ) |
302 | allcorrect = false; | 307 | allcorrect = false; |
303 | } | 308 | } |
304 | if ( settings & OContactAccess::DateDay ){ | 309 | if ( settings & OContactAccess::DateDay ){ |
305 | if ( queryDate->day() != checkDate->day() ) | 310 | if ( queryDate->day() != checkDate->day() ) |
306 | allcorrect = false; | 311 | allcorrect = false; |
307 | } | 312 | } |
308 | if ( settings & OContactAccess::DateDiff ) { | 313 | if ( settings & OContactAccess::DateDiff ) { |
309 | QDate current; | 314 | QDate current; |
310 | // If we get an additional date, we | 315 | // If we get an additional date, we |
311 | // will take this date instead of | 316 | // will take this date instead of |
312 | // the current one.. | 317 | // the current one.. |
313 | if ( !d.date().isValid() ) | 318 | if ( !d.date().isValid() ) |
314 | current = QDate::currentDate(); | 319 | current = QDate::currentDate(); |
315 | else | 320 | else |
@@ -317,23 +322,23 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
317 | 322 | ||
318 | // We have to equalize the year, otherwise | 323 | // We have to equalize the year, otherwise |
319 | // the search will fail.. | 324 | // the search will fail.. |
320 | checkDate->setYMD( current.year(), | 325 | checkDate->setYMD( current.year(), |
321 | checkDate->month(), | 326 | checkDate->month(), |
322 | checkDate->day() ); | 327 | checkDate->day() ); |
323 | if ( *checkDate < current ) | 328 | if ( *checkDate < current ) |
324 | checkDate->setYMD( current.year()+1, | 329 | checkDate->setYMD( current.year()+1, |
325 | checkDate->month(), | 330 | checkDate->month(), |
326 | checkDate->day() ); | 331 | checkDate->day() ); |
327 | 332 | ||
328 | // Check whether the birthday/anniversary date is between | 333 | // Check whether the birthday/anniversary date is between |
329 | // the current/given date and the maximum date | 334 | // the current/given date and the maximum date |
330 | // ( maximum time range ) ! | 335 | // ( maximum time range ) ! |
331 | qWarning("Checking if %s is between %s and %s ! ", | 336 | qWarning("Checking if %s is between %s and %s ! ", |
332 | checkDate->toString().latin1(), | 337 | checkDate->toString().latin1(), |
333 | current.toString().latin1(), | 338 | current.toString().latin1(), |
334 | queryDate->toString().latin1() ); | 339 | queryDate->toString().latin1() ); |
335 | if ( current.daysTo( *queryDate ) >= 0 ){ | 340 | if ( current.daysTo( *queryDate ) >= 0 ){ |
336 | if ( !( ( *checkDate >= current ) && | 341 | if ( !( ( *checkDate >= current ) && |
337 | ( *checkDate <= *queryDate ) ) ){ | 342 | ( *checkDate <= *queryDate ) ) ){ |
338 | allcorrect = false; | 343 | allcorrect = false; |
339 | qWarning (" Nope!.."); | 344 | qWarning (" Nope!.."); |
@@ -345,7 +350,7 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
345 | allcorrect = false; | 350 | allcorrect = false; |
346 | } | 351 | } |
347 | } | 352 | } |
348 | 353 | ||
349 | delete queryDate; | 354 | delete queryDate; |
350 | queryDate = 0l; | 355 | queryDate = 0l; |
351 | delete checkDate; | 356 | delete checkDate; |
@@ -359,9 +364,9 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
359 | | OContactAccess::DateYear | 364 | | OContactAccess::DateYear |
360 | | OContactAccess::DateMonth | 365 | | OContactAccess::DateMonth |
361 | | OContactAccess::DateDay | 366 | | OContactAccess::DateDay |
362 | | OContactAccess::MatchOne | 367 | | OContactAccess::MatchOne |
363 | ) ){ | 368 | ) ){ |
364 | 369 | ||
365 | case OContactAccess::RegExp:{ | 370 | case OContactAccess::RegExp:{ |
366 | QRegExp expr ( query.field(i), | 371 | QRegExp expr ( query.field(i), |
367 | !(settings & OContactAccess::IgnoreCase), | 372 | !(settings & OContactAccess::IgnoreCase), |
@@ -397,10 +402,10 @@ QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, i | |||
397 | m_currentQuery[arraycounter++] = (*it)->uid(); | 402 | m_currentQuery[arraycounter++] = (*it)->uid(); |
398 | } | 403 | } |
399 | } | 404 | } |
400 | 405 | ||
401 | // Shrink to fit.. | 406 | // Shrink to fit.. |
402 | m_currentQuery.resize(arraycounter); | 407 | m_currentQuery.resize(arraycounter); |
403 | 408 | ||
404 | return m_currentQuery; | 409 | return m_currentQuery; |
405 | } | 410 | } |
406 | 411 | ||
@@ -409,16 +414,16 @@ QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | |||
409 | QArray<int> m_currentQuery( m_contactList.count() ); | 414 | QArray<int> m_currentQuery( m_contactList.count() ); |
410 | QListIterator<OContact> it( m_contactList ); | 415 | QListIterator<OContact> it( m_contactList ); |
411 | uint arraycounter = 0; | 416 | uint arraycounter = 0; |
412 | 417 | ||
413 | for( ; it.current(); ++it ){ | 418 | for( ; it.current(); ++it ){ |
414 | if ( (*it)->match( r ) ){ | 419 | if ( (*it)->match( r ) ){ |
415 | m_currentQuery[arraycounter++] = (*it)->uid(); | 420 | m_currentQuery[arraycounter++] = (*it)->uid(); |
416 | } | 421 | } |
417 | 422 | ||
418 | } | 423 | } |
419 | // Shrink to fit.. | 424 | // Shrink to fit.. |
420 | m_currentQuery.resize(arraycounter); | 425 | m_currentQuery.resize(arraycounter); |
421 | 426 | ||
422 | return m_currentQuery; | 427 | return m_currentQuery; |
423 | } | 428 | } |
424 | 429 | ||
@@ -427,7 +432,7 @@ const uint OContactAccessBackend_XML::querySettings() | |||
427 | return ( OContactAccess::WildCards | 432 | return ( OContactAccess::WildCards |
428 | | OContactAccess::IgnoreCase | 433 | | OContactAccess::IgnoreCase |
429 | | OContactAccess::RegExp | 434 | | OContactAccess::RegExp |
430 | | OContactAccess::ExactMatch | 435 | | OContactAccess::ExactMatch |
431 | | OContactAccess::DateDiff | 436 | | OContactAccess::DateDiff |
432 | | OContactAccess::DateYear | 437 | | OContactAccess::DateYear |
433 | | OContactAccess::DateMonth | 438 | | OContactAccess::DateMonth |
@@ -437,20 +442,20 @@ const uint OContactAccessBackend_XML::querySettings() | |||
437 | 442 | ||
438 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | 443 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const |
439 | { | 444 | { |
440 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 445 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
441 | * may be added with any of the other settings. IgnoreCase should never used alone. | 446 | * may be added with any of the other settings. IgnoreCase should never used alone. |
442 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 447 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
443 | */ | 448 | */ |
444 | 449 | ||
445 | if ( querySettings == OContactAccess::IgnoreCase ) | 450 | if ( querySettings == OContactAccess::IgnoreCase ) |
446 | return false; | 451 | return false; |
447 | 452 | ||
448 | switch ( querySettings & ~( OContactAccess::IgnoreCase | 453 | switch ( querySettings & ~( OContactAccess::IgnoreCase |
449 | | OContactAccess::DateDiff | 454 | | OContactAccess::DateDiff |
450 | | OContactAccess::DateYear | 455 | | OContactAccess::DateYear |
451 | | OContactAccess::DateMonth | 456 | | OContactAccess::DateMonth |
452 | | OContactAccess::DateDay | 457 | | OContactAccess::DateDay |
453 | ) | 458 | ) |
454 | ){ | 459 | ){ |
455 | case OContactAccess::RegExp: | 460 | case OContactAccess::RegExp: |
456 | return ( true ); | 461 | return ( true ); |
@@ -463,14 +468,14 @@ bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | |||
463 | } | 468 | } |
464 | } | 469 | } |
465 | 470 | ||
466 | // Currently only asc implemented.. | 471 | // Currently only asc implemented.. |
467 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 472 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
468 | { | 473 | { |
469 | QMap<QString, int> nameToUid; | 474 | QMap<QString, int> nameToUid; |
470 | QStringList names; | 475 | QStringList names; |
471 | QArray<int> m_currentQuery( m_contactList.count() ); | 476 | QArray<int> m_currentQuery( m_contactList.count() ); |
472 | 477 | ||
473 | // First fill map and StringList with all Names | 478 | // First fill map and StringList with all Names |
474 | // Afterwards sort namelist and use map to fill array to return.. | 479 | // Afterwards sort namelist and use map to fill array to return.. |
475 | QListIterator<OContact> it( m_contactList ); | 480 | QListIterator<OContact> it( m_contactList ); |
476 | for( ; it.current(); ++it ){ | 481 | for( ; it.current(); ++it ){ |
@@ -478,7 +483,7 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | |||
478 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); | 483 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); |
479 | } | 484 | } |
480 | names.sort(); | 485 | names.sort(); |
481 | 486 | ||
482 | int i = 0; | 487 | int i = 0; |
483 | if ( asc ){ | 488 | if ( asc ){ |
484 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | 489 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) |
@@ -487,9 +492,9 @@ QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | |||
487 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) | 492 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) |
488 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 493 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
489 | } | 494 | } |
490 | 495 | ||
491 | return m_currentQuery; | 496 | return m_currentQuery; |
492 | 497 | ||
493 | } | 498 | } |
494 | 499 | ||
495 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | 500 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) |
@@ -497,16 +502,16 @@ bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | |||
497 | //qWarning("odefaultbackend: ACTION::ADD"); | 502 | //qWarning("odefaultbackend: ACTION::ADD"); |
498 | updateJournal (newcontact, ACTION_ADD); | 503 | updateJournal (newcontact, ACTION_ADD); |
499 | addContact_p( newcontact ); | 504 | addContact_p( newcontact ); |
500 | 505 | ||
501 | m_changed = true; | 506 | m_changed = true; |
502 | 507 | ||
503 | return true; | 508 | return true; |
504 | } | 509 | } |
505 | 510 | ||
506 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) | 511 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) |
507 | { | 512 | { |
508 | m_changed = true; | 513 | m_changed = true; |
509 | 514 | ||
510 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); | 515 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); |
511 | 516 | ||
512 | if ( found ) { | 517 | if ( found ) { |
@@ -528,7 +533,7 @@ bool OContactAccessBackend_XML::replace ( const OContact &contact ) | |||
528 | bool OContactAccessBackend_XML::remove ( int uid ) | 533 | bool OContactAccessBackend_XML::remove ( int uid ) |
529 | { | 534 | { |
530 | m_changed = true; | 535 | m_changed = true; |
531 | 536 | ||
532 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); | 537 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); |
533 | 538 | ||
534 | if ( found ) { | 539 | if ( found ) { |
@@ -555,9 +560,9 @@ void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | |||
555 | } | 560 | } |
556 | 561 | ||
557 | /* This function loads the xml-database and the journalfile */ | 562 | /* This function loads the xml-database and the journalfile */ |
558 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 563 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
559 | { | 564 | { |
560 | 565 | ||
561 | /* We use the time of the last read to check if the file was | 566 | /* We use the time of the last read to check if the file was |
562 | * changed externally. | 567 | * changed externally. |
563 | */ | 568 | */ |
@@ -565,10 +570,10 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
565 | QFileInfo fi( filename ); | 570 | QFileInfo fi( filename ); |
566 | m_readtime = fi.lastModified (); | 571 | m_readtime = fi.lastModified (); |
567 | } | 572 | } |
568 | 573 | ||
569 | const int JOURNALACTION = Qtopia::Notes + 1; | 574 | const int JOURNALACTION = Qtopia::Notes + 1; |
570 | const int JOURNALROW = JOURNALACTION + 1; | 575 | const int JOURNALROW = JOURNALACTION + 1; |
571 | 576 | ||
572 | bool foundAction = false; | 577 | bool foundAction = false; |
573 | journal_action action = ACTION_ADD; | 578 | journal_action action = ACTION_ADD; |
574 | int journalKey = 0; | 579 | int journalKey = 0; |
@@ -576,7 +581,7 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
576 | QMap<QString, QString> customMap; | 581 | QMap<QString, QString> customMap; |
577 | QMap<QString, QString>::Iterator customIt; | 582 | QMap<QString, QString>::Iterator customIt; |
578 | QAsciiDict<int> dict( 47 ); | 583 | QAsciiDict<int> dict( 47 ); |
579 | 584 | ||
580 | dict.setAutoDelete( TRUE ); | 585 | dict.setAutoDelete( TRUE ); |
581 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 586 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
582 | dict.insert( "Title", new int(Qtopia::Title) ); | 587 | dict.insert( "Title", new int(Qtopia::Title) ); |
@@ -623,9 +628,9 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
623 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 628 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
624 | dict.insert( "action", new int(JOURNALACTION) ); | 629 | dict.insert( "action", new int(JOURNALACTION) ); |
625 | dict.insert( "actionrow", new int(JOURNALROW) ); | 630 | dict.insert( "actionrow", new int(JOURNALROW) ); |
626 | 631 | ||
627 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 632 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
628 | 633 | ||
629 | XMLElement *root = XMLElement::load( filename ); | 634 | XMLElement *root = XMLElement::load( filename ); |
630 | if(root != 0l ){ // start parsing | 635 | if(root != 0l ){ // start parsing |
631 | /* Parse all XML-Elements and put the data into the | 636 | /* Parse all XML-Elements and put the data into the |
@@ -634,7 +639,7 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
634 | XMLElement *element = root->firstChild(); | 639 | XMLElement *element = root->firstChild(); |
635 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 640 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
636 | element = element->firstChild(); | 641 | element = element->firstChild(); |
637 | 642 | ||
638 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 643 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
639 | while( element && !isJournal ){ | 644 | while( element && !isJournal ){ |
640 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 645 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
@@ -661,14 +666,14 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
661 | // element->tagName().latin1() ); | 666 | // element->tagName().latin1() ); |
662 | QString dummy; | 667 | QString dummy; |
663 | foundAction = false; | 668 | foundAction = false; |
664 | 669 | ||
665 | XMLElement::AttributeMap aMap = element->attributes(); | 670 | XMLElement::AttributeMap aMap = element->attributes(); |
666 | XMLElement::AttributeMap::Iterator it; | 671 | XMLElement::AttributeMap::Iterator it; |
667 | contactMap.clear(); | 672 | contactMap.clear(); |
668 | customMap.clear(); | 673 | customMap.clear(); |
669 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 674 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
670 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 675 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
671 | 676 | ||
672 | int *find = dict[ it.key() ]; | 677 | int *find = dict[ it.key() ]; |
673 | /* Unknown attributes will be stored as "Custom" elements */ | 678 | /* Unknown attributes will be stored as "Custom" elements */ |
674 | if ( !find ) { | 679 | if ( !find ) { |
@@ -677,7 +682,7 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
677 | customMap.insert( it.key(), it.data() ); | 682 | customMap.insert( it.key(), it.data() ); |
678 | continue; | 683 | continue; |
679 | } | 684 | } |
680 | 685 | ||
681 | /* Check if special conversion is needed and add attribute | 686 | /* Check if special conversion is needed and add attribute |
682 | * into Contact class | 687 | * into Contact class |
683 | */ | 688 | */ |
@@ -705,11 +710,11 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
705 | } | 710 | } |
706 | /* now generate the Contact contact */ | 711 | /* now generate the Contact contact */ |
707 | OContact contact( contactMap ); | 712 | OContact contact( contactMap ); |
708 | 713 | ||
709 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 714 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
710 | contact.setCustomField( customIt.key(), customIt.data() ); | 715 | contact.setCustomField( customIt.key(), customIt.data() ); |
711 | } | 716 | } |
712 | 717 | ||
713 | if (foundAction){ | 718 | if (foundAction){ |
714 | foundAction = false; | 719 | foundAction = false; |
715 | switch ( action ) { | 720 | switch ( action ) { |
@@ -734,7 +739,7 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
734 | /* Add contact to list */ | 739 | /* Add contact to list */ |
735 | addContact_p (contact); | 740 | addContact_p (contact); |
736 | } | 741 | } |
737 | 742 | ||
738 | /* Move to next element */ | 743 | /* Move to next element */ |
739 | element = element->nextChild(); | 744 | element = element->nextChild(); |
740 | } | 745 | } |
@@ -748,16 +753,16 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
748 | 753 | ||
749 | 754 | ||
750 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 755 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
751 | journal_action action ) | 756 | journal_action action ) |
752 | { | 757 | { |
753 | QFile f( m_journalName ); | 758 | QFile f( m_journalName ); |
754 | bool created = !f.exists(); | 759 | bool created = !f.exists(); |
755 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 760 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
756 | return; | 761 | return; |
757 | 762 | ||
758 | QString buf; | 763 | QString buf; |
759 | QCString str; | 764 | QCString str; |
760 | 765 | ||
761 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 766 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
762 | // get a XML-File which is readable by our parser. | 767 | // get a XML-File which is readable by our parser. |
763 | // This is just a cheat, but better than rewrite the parser. | 768 | // This is just a cheat, but better than rewrite the parser. |
@@ -766,7 +771,7 @@ void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | |||
766 | QCString cstr = buf.utf8(); | 771 | QCString cstr = buf.utf8(); |
767 | f.writeBlock( cstr.data(), cstr.length() ); | 772 | f.writeBlock( cstr.data(), cstr.length() ); |
768 | } | 773 | } |
769 | 774 | ||
770 | buf = "<Contact "; | 775 | buf = "<Contact "; |
771 | cnt.save( buf ); | 776 | cnt.save( buf ); |
772 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 777 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index 4d6a7ef..7b5365b 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h | |||
@@ -17,6 +17,11 @@ | |||
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.14 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.13 2003/03/21 10:33:09 eilers | 25 | * Revision 1.13 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
@@ -84,52 +89,57 @@ | |||
84 | #include <qdict.h> | 89 | #include <qdict.h> |
85 | 90 | ||
86 | /* the default xml implementation */ | 91 | /* the default xml implementation */ |
92 | /** | ||
93 | * This class is the XML implementation of a Contact backend | ||
94 | * it does implement everything available for OContact. | ||
95 | * @see OPimAccessBackend for more information of available methods | ||
96 | */ | ||
87 | class OContactAccessBackend_XML : public OContactAccessBackend { | 97 | class OContactAccessBackend_XML : public OContactAccessBackend { |
88 | public: | 98 | public: |
89 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ); | 99 | OContactAccessBackend_XML ( const QString& appname, const QString& filename = QString::null ); |
90 | 100 | ||
91 | bool save(); | 101 | bool save(); |
92 | 102 | ||
93 | bool load (); | 103 | bool load (); |
94 | 104 | ||
95 | void clear (); | 105 | void clear (); |
96 | 106 | ||
97 | bool wasChangedExternally(); | 107 | bool wasChangedExternally(); |
98 | 108 | ||
99 | QArray<int> allRecords() const; | 109 | QArray<int> allRecords() const; |
100 | 110 | ||
101 | OContact find ( int uid ) const; | 111 | OContact find ( int uid ) const; |
102 | 112 | ||
103 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 113 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
104 | 114 | ||
105 | QArray<int> matchRegexp( const QRegExp &r ) const; | 115 | QArray<int> matchRegexp( const QRegExp &r ) const; |
106 | 116 | ||
107 | const uint querySettings(); | 117 | const uint querySettings(); |
108 | 118 | ||
109 | bool hasQuerySettings (uint querySettings) const; | 119 | bool hasQuerySettings (uint querySettings) const; |
110 | 120 | ||
111 | // Currently only asc implemented.. | 121 | // Currently only asc implemented.. |
112 | QArray<int> sorted( bool asc, int , int , int ); | 122 | QArray<int> sorted( bool asc, int , int , int ); |
113 | bool add ( const OContact &newcontact ); | 123 | bool add ( const OContact &newcontact ); |
114 | 124 | ||
115 | bool replace ( const OContact &contact ); | 125 | bool replace ( const OContact &contact ); |
116 | 126 | ||
117 | bool remove ( int uid ); | 127 | bool remove ( int uid ); |
118 | bool reload(); | 128 | bool reload(); |
119 | 129 | ||
120 | private: | 130 | private: |
121 | 131 | ||
122 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 132 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
123 | 133 | ||
124 | void addContact_p( const OContact &newcontact ); | 134 | void addContact_p( const OContact &newcontact ); |
125 | 135 | ||
126 | /* This function loads the xml-database and the journalfile */ | 136 | /* This function loads the xml-database and the journalfile */ |
127 | bool load( const QString filename, bool isJournal ); | 137 | bool load( const QString filename, bool isJournal ); |
128 | 138 | ||
129 | 139 | ||
130 | void updateJournal( const OContact& cnt, journal_action action ); | 140 | void updateJournal( const OContact& cnt, journal_action action ); |
131 | void removeJournal(); | 141 | void removeJournal(); |
132 | 142 | ||
133 | protected: | 143 | protected: |
134 | bool m_changed; | 144 | bool m_changed; |
135 | QString m_journalName; | 145 | QString m_journalName; |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h index eb6e8fb..86ff298 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend.h | |||
@@ -6,25 +6,66 @@ | |||
6 | #include "opimaccessbackend.h" | 6 | #include "opimaccessbackend.h" |
7 | #include "oevent.h" | 7 | #include "oevent.h" |
8 | 8 | ||
9 | /** | ||
10 | * This class is the interface to the storage of Events. | ||
11 | * @see OPimAccessBackend | ||
12 | * | ||
13 | */ | ||
9 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { | 14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { |
10 | public: | 15 | public: |
11 | typedef int UID; | 16 | typedef int UID; |
17 | |||
18 | /** | ||
19 | * c'tor without parameter | ||
20 | */ | ||
12 | ODateBookAccessBackend(); | 21 | ODateBookAccessBackend(); |
13 | ~ODateBookAccessBackend(); | 22 | ~ODateBookAccessBackend(); |
14 | 23 | ||
24 | /** | ||
25 | * This method should return a list of UIDs containing | ||
26 | * all events. No filter should be applied | ||
27 | * @return list of events | ||
28 | */ | ||
15 | virtual QArray<UID> rawEvents()const = 0; | 29 | virtual QArray<UID> rawEvents()const = 0; |
30 | |||
31 | /** | ||
32 | * This method should return a list of UIDs containing | ||
33 | * all repeating events. No filter should be applied | ||
34 | * @return list of repeating events | ||
35 | */ | ||
16 | virtual QArray<UID> rawRepeats()const = 0; | 36 | virtual QArray<UID> rawRepeats()const = 0; |
37 | |||
38 | /** | ||
39 | * This mthod should return a list of UIDs containing all non | ||
40 | * repeating events. No filter should be applied | ||
41 | * @return list of nonrepeating events | ||
42 | */ | ||
17 | virtual QArray<UID> nonRepeats() const = 0; | 43 | virtual QArray<UID> nonRepeats() const = 0; |
18 | 44 | ||
19 | /** | 45 | /** |
20 | * these two methods are used if you do not implement | 46 | * If you do not want to implement the effectiveEvents methods below |
21 | * effectiveEvents... | 47 | * you need to supply it with directNonRepeats. |
48 | * This method can return empty lists if effectiveEvents is implememted | ||
22 | */ | 49 | */ |
23 | virtual OEvent::ValueList directNonRepeats() = 0; | 50 | virtual OEvent::ValueList directNonRepeats() = 0; |
51 | |||
52 | /** | ||
53 | * Same as above but return raw repeats! | ||
54 | */ | ||
24 | virtual OEvent::ValueList directRawRepeats() = 0; | 55 | virtual OEvent::ValueList directRawRepeats() = 0; |
25 | 56 | ||
26 | /* is implemented by default but you can reimplement it*/ | 57 | /* is implemented by default but you can reimplement it*/ |
58 | /** | ||
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 | ||
61 | * yourself | ||
62 | */ | ||
27 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); | 63 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); |
64 | |||
65 | /** | ||
66 | * this is an overloaded member function | ||
67 | * @see effecticeEvents | ||
68 | */ | ||
28 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); | 69 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); |
29 | 70 | ||
30 | }; | 71 | }; |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h index 563c31f..7848f7c 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h | |||
@@ -5,6 +5,12 @@ | |||
5 | 5 | ||
6 | #include "odatebookaccessbackend.h" | 6 | #include "odatebookaccessbackend.h" |
7 | 7 | ||
8 | /** | ||
9 | * This is the default XML implementation for DateBoook XML storage | ||
10 | * It fully implements the interface | ||
11 | * @see ODateBookAccessBackend | ||
12 | * @see OPimAccessBackend | ||
13 | */ | ||
8 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { | 14 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { |
9 | public: | 15 | public: |
10 | ODateBookAccessBackend_XML( const QString& appName, | 16 | ODateBookAccessBackend_XML( const QString& appName, |