-rw-r--r-- | libopie/pim/odatebookaccessbackend_xml.cpp | 2 | ||||
-rw-r--r-- | libopie/pim/opimrecord.h | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp index 5ea945c..39c43c5 100644 --- a/libopie/pim/odatebookaccessbackend_xml.cpp +++ b/libopie/pim/odatebookaccessbackend_xml.cpp | |||
@@ -1,606 +1,606 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | 3 | ||
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | 6 | ||
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/mman.h> | 8 | #include <sys/mman.h> |
9 | #include <sys/stat.h> | 9 | #include <sys/stat.h> |
10 | 10 | ||
11 | #include <unistd.h> | 11 | #include <unistd.h> |
12 | 12 | ||
13 | #include <qasciidict.h> | 13 | #include <qasciidict.h> |
14 | #include <qfile.h> | 14 | #include <qfile.h> |
15 | 15 | ||
16 | #include <qtopia/global.h> | 16 | #include <qtopia/global.h> |
17 | #include <qtopia/stringutil.h> | 17 | #include <qtopia/stringutil.h> |
18 | #include <qtopia/timeconversion.h> | 18 | #include <qtopia/timeconversion.h> |
19 | 19 | ||
20 | #include "opimnotifymanager.h" | 20 | #include "opimnotifymanager.h" |
21 | #include "orecur.h" | 21 | #include "orecur.h" |
22 | #include "otimezone.h" | 22 | #include "otimezone.h" |
23 | #include "odatebookaccessbackend_xml.h" | 23 | #include "odatebookaccessbackend_xml.h" |
24 | 24 | ||
25 | namespace { | 25 | namespace { |
26 | // FROM TT again | 26 | // FROM TT again |
27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
28 | { | 28 | { |
29 | char needleChar; | 29 | char needleChar; |
30 | char haystackChar; | 30 | char haystackChar; |
31 | if (!needle || !haystack || !hLen || !nLen) | 31 | if (!needle || !haystack || !hLen || !nLen) |
32 | return 0; | 32 | return 0; |
33 | 33 | ||
34 | const char* hsearch = haystack; | 34 | const char* hsearch = haystack; |
35 | 35 | ||
36 | if ((needleChar = *needle++) != 0) { | 36 | if ((needleChar = *needle++) != 0) { |
37 | nLen--; //(to make up for needle++) | 37 | nLen--; //(to make up for needle++) |
38 | do { | 38 | do { |
39 | do { | 39 | do { |
40 | if ((haystackChar = *hsearch++) == 0) | 40 | if ((haystackChar = *hsearch++) == 0) |
41 | return (0); | 41 | return (0); |
42 | if (hsearch >= haystack + hLen) | 42 | if (hsearch >= haystack + hLen) |
43 | return (0); | 43 | return (0); |
44 | } while (haystackChar != needleChar); | 44 | } while (haystackChar != needleChar); |
45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
46 | hsearch--; | 46 | hsearch--; |
47 | } | 47 | } |
48 | return ((char *)hsearch); | 48 | return ((char *)hsearch); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | namespace { | 52 | namespace { |
53 | time_t start, end, created, rp_end; | 53 | time_t start, end, created, rp_end; |
54 | ORecur* rec; | 54 | ORecur* rec; |
55 | ORecur* recur() { | 55 | ORecur* recur() { |
56 | if (!rec) | 56 | if (!rec) |
57 | rec = new ORecur; | 57 | rec = new ORecur; |
58 | 58 | ||
59 | return rec; | 59 | return rec; |
60 | } | 60 | } |
61 | int alarmTime; | 61 | int alarmTime; |
62 | int snd; | 62 | int snd; |
63 | enum Attribute{ | 63 | enum Attribute{ |
64 | FDescription = 0, | 64 | FDescription = 0, |
65 | FLocation, | 65 | FLocation, |
66 | FCategories, | 66 | FCategories, |
67 | FUid, | 67 | FUid, |
68 | FType, | 68 | FType, |
69 | FAlarm, | 69 | FAlarm, |
70 | FSound, | 70 | FSound, |
71 | FRType, | 71 | FRType, |
72 | FRWeekdays, | 72 | FRWeekdays, |
73 | FRPosition, | 73 | FRPosition, |
74 | FRFreq, | 74 | FRFreq, |
75 | FRHasEndDate, | 75 | FRHasEndDate, |
76 | FREndDate, | 76 | FREndDate, |
77 | FRStart, | 77 | FRStart, |
78 | FREnd, | 78 | FREnd, |
79 | FNote, | 79 | FNote, |
80 | FCreated, | 80 | FCreated, |
81 | FTimeZone, | 81 | FTimeZone, |
82 | FRecParent, | 82 | FRecParent, |
83 | FRecChildren, | 83 | FRecChildren, |
84 | FExceptions | 84 | FExceptions |
85 | }; | 85 | }; |
86 | inline void save( const OEvent& ev, QString& buf ) { | 86 | inline void save( const OEvent& ev, QString& buf ) { |
87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); | 87 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); |
88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; | 88 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; |
89 | if (!ev.location().isEmpty() ) | 89 | if (!ev.location().isEmpty() ) |
90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; | 90 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; |
91 | 91 | ||
92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 92 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 93 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
94 | 94 | ||
95 | if (ev.isAllDay() ) | 95 | if (ev.isAllDay() ) |
96 | buf += " type=\"AllDay\""; | 96 | buf += " type=\"AllDay\""; // is that all ?? (eilers) |
97 | 97 | ||
98 | if (ev.hasNotifiers() ) { | 98 | if (ev.hasNotifiers() ) { |
99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 99 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 100 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 101 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
102 | if ( alarm.sound() == OPimAlarm::Loud ) | 102 | if ( alarm.sound() == OPimAlarm::Loud ) |
103 | buf += "loud"; | 103 | buf += "loud"; |
104 | else | 104 | else |
105 | buf += "silent"; | 105 | buf += "silent"; |
106 | buf += "\""; | 106 | buf += "\""; |
107 | } | 107 | } |
108 | if ( ev.hasRecurrence() ) { | 108 | if ( ev.hasRecurrence() ) { |
109 | buf += ev.recurrence().toString(); | 109 | buf += ev.recurrence().toString(); |
110 | } | 110 | } |
111 | 111 | ||
112 | /* | 112 | /* |
113 | * fscking timezones :) well, we'll first convert | 113 | * fscking timezones :) well, we'll first convert |
114 | * the QDateTime to a QDateTime in UTC time | 114 | * the QDateTime to a QDateTime in UTC time |
115 | * and then we'll create a nice time_t | 115 | * and then we'll create a nice time_t |
116 | */ | 116 | */ |
117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 117 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; | 118 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; |
119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; | 119 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; |
120 | if (!ev.note().isEmpty() ) { | 120 | if (!ev.note().isEmpty() ) { |
121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 121 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
122 | } | 122 | } |
123 | 123 | ||
124 | buf += " timezone=\""; | 124 | buf += " timezone=\""; |
125 | if ( ev.timeZone().isEmpty() ) | 125 | if ( ev.timeZone().isEmpty() ) |
126 | buf += "None"; | 126 | buf += "None"; |
127 | else | 127 | else |
128 | buf += ev.timeZone(); | 128 | buf += ev.timeZone(); |
129 | buf += "\""; | 129 | buf += "\""; |
130 | 130 | ||
131 | if (ev.parent() != 0 ) { | 131 | if (ev.parent() != 0 ) { |
132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 132 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
133 | } | 133 | } |
134 | 134 | ||
135 | if (ev.children().count() != 0 ) { | 135 | if (ev.children().count() != 0 ) { |
136 | QArray<int> children = ev.children(); | 136 | QArray<int> children = ev.children(); |
137 | buf += " recchildren=\""; | 137 | buf += " recchildren=\""; |
138 | for ( uint i = 0; i < children.count(); i++ ) { | 138 | for ( uint i = 0; i < children.count(); i++ ) { |
139 | if ( i != 0 ) buf += " "; | 139 | if ( i != 0 ) buf += " "; |
140 | buf += QString::number( children[i] ); | 140 | buf += QString::number( children[i] ); |
141 | } | 141 | } |
142 | buf+= "\""; | 142 | buf+= "\""; |
143 | } | 143 | } |
144 | 144 | ||
145 | // skip custom writing | 145 | // skip custom writing |
146 | } | 146 | } |
147 | 147 | ||
148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { | 148 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { |
149 | QMap<int, OEvent>::ConstIterator it; | 149 | QMap<int, OEvent>::ConstIterator it; |
150 | QString buf; | 150 | QString buf; |
151 | QCString str; | 151 | QCString str; |
152 | int total_written; | 152 | int total_written; |
153 | for ( it = list.begin(); it != list.end(); ++it ) { | 153 | for ( it = list.begin(); it != list.end(); ++it ) { |
154 | buf = "<event"; | 154 | buf = "<event"; |
155 | save( it.data(), buf ); | 155 | save( it.data(), buf ); |
156 | buf += " />\n"; | 156 | buf += " />\n"; |
157 | str = buf.utf8(); | 157 | str = buf.utf8(); |
158 | 158 | ||
159 | total_written = file.writeBlock(str.data(), str.length() ); | 159 | total_written = file.writeBlock(str.data(), str.length() ); |
160 | if ( total_written != int(str.length() ) ) | 160 | if ( total_written != int(str.length() ) ) |
161 | return false; | 161 | return false; |
162 | } | 162 | } |
163 | return true; | 163 | return true; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 167 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
168 | const QString& fileName ) | 168 | const QString& fileName ) |
169 | : ODateBookAccessBackend() { | 169 | : ODateBookAccessBackend() { |
170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 170 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
171 | m_changed = false; | 171 | m_changed = false; |
172 | } | 172 | } |
173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 173 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
174 | } | 174 | } |
175 | bool ODateBookAccessBackend_XML::load() { | 175 | bool ODateBookAccessBackend_XML::load() { |
176 | return loadFile(); | 176 | return loadFile(); |
177 | } | 177 | } |
178 | bool ODateBookAccessBackend_XML::reload() { | 178 | bool ODateBookAccessBackend_XML::reload() { |
179 | clear(); | 179 | clear(); |
180 | return load(); | 180 | return load(); |
181 | } | 181 | } |
182 | bool ODateBookAccessBackend_XML::save() { | 182 | bool ODateBookAccessBackend_XML::save() { |
183 | if (!m_changed) return true; | 183 | if (!m_changed) return true; |
184 | 184 | ||
185 | int total_written; | 185 | int total_written; |
186 | QString strFileNew = m_name + ".new"; | 186 | QString strFileNew = m_name + ".new"; |
187 | 187 | ||
188 | QFile f( strFileNew ); | 188 | QFile f( strFileNew ); |
189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 189 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
190 | 190 | ||
191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 191 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 192 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
193 | buf += "<events>\n"; | 193 | buf += "<events>\n"; |
194 | QCString str = buf.utf8(); | 194 | QCString str = buf.utf8(); |
195 | total_written = f.writeBlock( str.data(), str.length() ); | 195 | total_written = f.writeBlock( str.data(), str.length() ); |
196 | if ( total_written != int(str.length() ) ) { | 196 | if ( total_written != int(str.length() ) ) { |
197 | f.close(); | 197 | f.close(); |
198 | QFile::remove( strFileNew ); | 198 | QFile::remove( strFileNew ); |
199 | return false; | 199 | return false; |
200 | } | 200 | } |
201 | 201 | ||
202 | if (!forAll( m_raw, f ) ) { | 202 | if (!forAll( m_raw, f ) ) { |
203 | f.close(); | 203 | f.close(); |
204 | QFile::remove( strFileNew ); | 204 | QFile::remove( strFileNew ); |
205 | return false; | 205 | return false; |
206 | } | 206 | } |
207 | if (!forAll( m_rep, f ) ) { | 207 | if (!forAll( m_rep, f ) ) { |
208 | f.close(); | 208 | f.close(); |
209 | QFile::remove( strFileNew ); | 209 | QFile::remove( strFileNew ); |
210 | return false; | 210 | return false; |
211 | } | 211 | } |
212 | 212 | ||
213 | buf = "</events>\n</DATEBOOK>\n"; | 213 | buf = "</events>\n</DATEBOOK>\n"; |
214 | str = buf.utf8(); | 214 | str = buf.utf8(); |
215 | total_written = f.writeBlock( str.data(), str.length() ); | 215 | total_written = f.writeBlock( str.data(), str.length() ); |
216 | if ( total_written != int(str.length() ) ) { | 216 | if ( total_written != int(str.length() ) ) { |
217 | f.close(); | 217 | f.close(); |
218 | QFile::remove( strFileNew ); | 218 | QFile::remove( strFileNew ); |
219 | return false; | 219 | return false; |
220 | } | 220 | } |
221 | f.close(); | 221 | f.close(); |
222 | 222 | ||
223 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 223 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
224 | QFile::remove( strFileNew ); | 224 | QFile::remove( strFileNew ); |
225 | return false; | 225 | return false; |
226 | } | 226 | } |
227 | 227 | ||
228 | m_changed = false; | 228 | m_changed = false; |
229 | return true; | 229 | return true; |
230 | } | 230 | } |
231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 231 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 232 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
233 | uint i = 0; | 233 | uint i = 0; |
234 | QMap<int, OEvent>::ConstIterator it; | 234 | QMap<int, OEvent>::ConstIterator it; |
235 | 235 | ||
236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 236 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
237 | ints[i] = it.key(); | 237 | ints[i] = it.key(); |
238 | i++; | 238 | i++; |
239 | } | 239 | } |
240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 240 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
241 | ints[i] = it.key(); | 241 | ints[i] = it.key(); |
242 | i++; | 242 | i++; |
243 | } | 243 | } |
244 | 244 | ||
245 | return ints; | 245 | return ints; |
246 | } | 246 | } |
247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { | 247 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { |
248 | return QArray<int>(); | 248 | return QArray<int>(); |
249 | } | 249 | } |
250 | void ODateBookAccessBackend_XML::clear() { | 250 | void ODateBookAccessBackend_XML::clear() { |
251 | m_changed = true; | 251 | m_changed = true; |
252 | m_raw.clear(); | 252 | m_raw.clear(); |
253 | m_rep.clear(); | 253 | m_rep.clear(); |
254 | } | 254 | } |
255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
256 | if ( m_raw.contains( uid ) ) | 256 | if ( m_raw.contains( uid ) ) |
257 | return m_raw[uid]; | 257 | return m_raw[uid]; |
258 | else | 258 | else |
259 | return m_rep[uid]; | 259 | return m_rep[uid]; |
260 | } | 260 | } |
261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
262 | m_changed = true; | 262 | m_changed = true; |
263 | if (ev.hasRecurrence() ) | 263 | if (ev.hasRecurrence() ) |
264 | m_rep.insert( ev.uid(), ev ); | 264 | m_rep.insert( ev.uid(), ev ); |
265 | else | 265 | else |
266 | m_raw.insert( ev.uid(), ev ); | 266 | m_raw.insert( ev.uid(), ev ); |
267 | 267 | ||
268 | return true; | 268 | return true; |
269 | } | 269 | } |
270 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 270 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
271 | m_changed = true; | 271 | m_changed = true; |
272 | m_rep.remove( uid ); | 272 | m_rep.remove( uid ); |
273 | m_rep.remove( uid ); | 273 | m_rep.remove( uid ); |
274 | 274 | ||
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
278 | replace( ev.uid() ); | 278 | replace( ev.uid() ); |
279 | return add( ev ); | 279 | return add( ev ); |
280 | } | 280 | } |
281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
282 | return allRecords(); | 282 | return allRecords(); |
283 | } | 283 | } |
284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
285 | QArray<int> ints( m_rep.count() ); | 285 | QArray<int> ints( m_rep.count() ); |
286 | uint i = 0; | 286 | uint i = 0; |
287 | QMap<int, OEvent>::ConstIterator it; | 287 | QMap<int, OEvent>::ConstIterator it; |
288 | 288 | ||
289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
290 | ints[i] = it.key(); | 290 | ints[i] = it.key(); |
291 | i++; | 291 | i++; |
292 | } | 292 | } |
293 | 293 | ||
294 | return ints; | 294 | return ints; |
295 | } | 295 | } |
296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
297 | QArray<int> ints( m_raw.count() ); | 297 | QArray<int> ints( m_raw.count() ); |
298 | uint i = 0; | 298 | uint i = 0; |
299 | QMap<int, OEvent>::ConstIterator it; | 299 | QMap<int, OEvent>::ConstIterator it; |
300 | 300 | ||
301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
302 | ints[i] = it.key(); | 302 | ints[i] = it.key(); |
303 | i++; | 303 | i++; |
304 | } | 304 | } |
305 | 305 | ||
306 | return ints; | 306 | return ints; |
307 | } | 307 | } |
308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
309 | OEvent::ValueList list; | 309 | OEvent::ValueList list; |
310 | QMap<int, OEvent>::ConstIterator it; | 310 | QMap<int, OEvent>::ConstIterator it; |
311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
312 | list.append( it.data() ); | 312 | list.append( it.data() ); |
313 | 313 | ||
314 | return list; | 314 | return list; |
315 | } | 315 | } |
316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
317 | OEvent::ValueList list; | 317 | OEvent::ValueList list; |
318 | QMap<int, OEvent>::ConstIterator it; | 318 | QMap<int, OEvent>::ConstIterator it; |
319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
320 | list.append( it.data() ); | 320 | list.append( it.data() ); |
321 | 321 | ||
322 | return list; | 322 | return list; |
323 | } | 323 | } |
324 | bool ODateBookAccessBackend_XML::loadFile() { | 324 | bool ODateBookAccessBackend_XML::loadFile() { |
325 | m_changed = false; | 325 | m_changed = false; |
326 | 326 | ||
327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
328 | if ( fd < 0 ) return false; | 328 | if ( fd < 0 ) return false; |
329 | 329 | ||
330 | struct stat attribute; | 330 | struct stat attribute; |
331 | if ( ::fstat(fd, &attribute ) == -1 ) { | 331 | if ( ::fstat(fd, &attribute ) == -1 ) { |
332 | ::close( fd ); | 332 | ::close( fd ); |
333 | return false; | 333 | return false; |
334 | } | 334 | } |
335 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 335 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
336 | if ( map_addr == ( (caddr_t)-1) ) { | 336 | if ( map_addr == ( (caddr_t)-1) ) { |
337 | ::close( fd ); | 337 | ::close( fd ); |
338 | return false; | 338 | return false; |
339 | } | 339 | } |
340 | 340 | ||
341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
342 | ::close( fd ); | 342 | ::close( fd ); |
343 | 343 | ||
344 | QAsciiDict<int> dict(FExceptions+1); | 344 | QAsciiDict<int> dict(FExceptions+1); |
345 | dict.setAutoDelete( true ); | 345 | dict.setAutoDelete( true ); |
346 | dict.insert( "description", new int(FDescription) ); | 346 | dict.insert( "description", new int(FDescription) ); |
347 | dict.insert( "location", new int(FLocation) ); | 347 | dict.insert( "location", new int(FLocation) ); |
348 | dict.insert( "categories", new int(FCategories) ); | 348 | dict.insert( "categories", new int(FCategories) ); |
349 | dict.insert( "uid", new int(FUid) ); | 349 | dict.insert( "uid", new int(FUid) ); |
350 | dict.insert( "type", new int(FType) ); | 350 | dict.insert( "type", new int(FType) ); |
351 | dict.insert( "alarm", new int(FAlarm) ); | 351 | dict.insert( "alarm", new int(FAlarm) ); |
352 | dict.insert( "sound", new int(FSound) ); | 352 | dict.insert( "sound", new int(FSound) ); |
353 | dict.insert( "rtype", new int(FRType) ); | 353 | dict.insert( "rtype", new int(FRType) ); |
354 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 354 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
355 | dict.insert( "rposition", new int(FRPosition) ); | 355 | dict.insert( "rposition", new int(FRPosition) ); |
356 | dict.insert( "rfreq", new int(FRFreq) ); | 356 | dict.insert( "rfreq", new int(FRFreq) ); |
357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
358 | dict.insert( "enddt", new int(FREndDate) ); | 358 | dict.insert( "enddt", new int(FREndDate) ); |
359 | dict.insert( "start", new int(FRStart) ); | 359 | dict.insert( "start", new int(FRStart) ); |
360 | dict.insert( "end", new int(FREnd) ); | 360 | dict.insert( "end", new int(FREnd) ); |
361 | dict.insert( "note", new int(FNote) ); | 361 | dict.insert( "note", new int(FNote) ); |
362 | dict.insert( "created", new int(FCreated) ); | 362 | dict.insert( "created", new int(FCreated) ); |
363 | dict.insert( "recparent", new int(FRecParent) ); | 363 | dict.insert( "recparent", new int(FRecParent) ); |
364 | dict.insert( "recchildren", new int(FRecChildren) ); | 364 | dict.insert( "recchildren", new int(FRecChildren) ); |
365 | dict.insert( "exceptions", new int(FExceptions) ); | 365 | dict.insert( "exceptions", new int(FExceptions) ); |
366 | dict.insert( "timezone", new int(FTimeZone) ); | 366 | dict.insert( "timezone", new int(FTimeZone) ); |
367 | 367 | ||
368 | char* dt = (char*)map_addr; | 368 | char* dt = (char*)map_addr; |
369 | int len = attribute.st_size; | 369 | int len = attribute.st_size; |
370 | int i = 0; | 370 | int i = 0; |
371 | char* point; | 371 | char* point; |
372 | const char* collectionString = "<event "; | 372 | const char* collectionString = "<event "; |
373 | int strLen = ::strlen(collectionString); | 373 | int strLen = ::strlen(collectionString); |
374 | int *find; | 374 | int *find; |
375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { | 375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { |
376 | i = point -dt; | 376 | i = point -dt; |
377 | i+= strLen; | 377 | i+= strLen; |
378 | 378 | ||
379 | alarmTime = -1; | 379 | alarmTime = -1; |
380 | snd = 0; // silent | 380 | snd = 0; // silent |
381 | 381 | ||
382 | OEvent ev; | 382 | OEvent ev; |
383 | rec = 0; | 383 | rec = 0; |
384 | 384 | ||
385 | while ( TRUE ) { | 385 | while ( TRUE ) { |
386 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 386 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
387 | ++i; | 387 | ++i; |
388 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 388 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
389 | break; | 389 | break; |
390 | 390 | ||
391 | 391 | ||
392 | // we have another attribute, read it. | 392 | // we have another attribute, read it. |
393 | int j = i; | 393 | int j = i; |
394 | while ( j < len && dt[j] != '=' ) | 394 | while ( j < len && dt[j] != '=' ) |
395 | ++j; | 395 | ++j; |
396 | QCString attr( dt+i, j-i+1); | 396 | QCString attr( dt+i, j-i+1); |
397 | 397 | ||
398 | i = ++j; // skip = | 398 | i = ++j; // skip = |
399 | 399 | ||
400 | // find the start of quotes | 400 | // find the start of quotes |
401 | while ( i < len && dt[i] != '"' ) | 401 | while ( i < len && dt[i] != '"' ) |
402 | ++i; | 402 | ++i; |
403 | j = ++i; | 403 | j = ++i; |
404 | 404 | ||
405 | bool haveUtf = FALSE; | 405 | bool haveUtf = FALSE; |
406 | bool haveEnt = FALSE; | 406 | bool haveEnt = FALSE; |
407 | while ( j < len && dt[j] != '"' ) { | 407 | while ( j < len && dt[j] != '"' ) { |
408 | if ( ((unsigned char)dt[j]) > 0x7f ) | 408 | if ( ((unsigned char)dt[j]) > 0x7f ) |
409 | haveUtf = TRUE; | 409 | haveUtf = TRUE; |
410 | if ( dt[j] == '&' ) | 410 | if ( dt[j] == '&' ) |
411 | haveEnt = TRUE; | 411 | haveEnt = TRUE; |
412 | ++j; | 412 | ++j; |
413 | } | 413 | } |
414 | if ( i == j ) { | 414 | if ( i == j ) { |
415 | // empty value | 415 | // empty value |
416 | i = j + 1; | 416 | i = j + 1; |
417 | continue; | 417 | continue; |
418 | } | 418 | } |
419 | 419 | ||
420 | QCString value( dt+i, j-i+1 ); | 420 | QCString value( dt+i, j-i+1 ); |
421 | i = j + 1; | 421 | i = j + 1; |
422 | 422 | ||
423 | QString str = (haveUtf ? QString::fromUtf8( value ) | 423 | QString str = (haveUtf ? QString::fromUtf8( value ) |
424 | : QString::fromLatin1( value ) ); | 424 | : QString::fromLatin1( value ) ); |
425 | if ( haveEnt ) | 425 | if ( haveEnt ) |
426 | str = Qtopia::plainString( str ); | 426 | str = Qtopia::plainString( str ); |
427 | 427 | ||
428 | /* | 428 | /* |
429 | * add key + value | 429 | * add key + value |
430 | */ | 430 | */ |
431 | find = dict[attr.data()]; | 431 | find = dict[attr.data()]; |
432 | if (!find) | 432 | if (!find) |
433 | ev.setCustomField( attr, str ); | 433 | ev.setCustomField( attr, str ); |
434 | else { | 434 | else { |
435 | setField( ev, *find, str ); | 435 | setField( ev, *find, str ); |
436 | } | 436 | } |
437 | } | 437 | } |
438 | /* time to finalize */ | 438 | /* time to finalize */ |
439 | finalizeRecord( ev ); | 439 | finalizeRecord( ev ); |
440 | delete rec; | 440 | delete rec; |
441 | } | 441 | } |
442 | ::munmap(map_addr, attribute.st_size ); | 442 | ::munmap(map_addr, attribute.st_size ); |
443 | m_changed = false; // changed during add | 443 | m_changed = false; // changed during add |
444 | 444 | ||
445 | return true; | 445 | return true; |
446 | } | 446 | } |
447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
448 | /* AllDay is alway in UTC */ | 448 | /* AllDay is alway in UTC */ |
449 | if ( ev.isAllDay() ) { | 449 | if ( ev.isAllDay() ) { |
450 | OTimeZone utc = OTimeZone::utc(); | 450 | OTimeZone utc = OTimeZone::utc(); |
451 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 451 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
452 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 452 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
453 | ev.setTimeZone( "UTC"); // make sure it is really utc | 453 | ev.setTimeZone( "UTC"); // make sure it is really utc |
454 | }else { | 454 | }else { |
455 | /* to current date time */ | 455 | /* to current date time */ |
456 | // qWarning(" Start is %d", start ); | 456 | // qWarning(" Start is %d", start ); |
457 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 457 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
458 | QDateTime date = zone.toDateTime( start ); | 458 | QDateTime date = zone.toDateTime( start ); |
459 | qWarning(" Start is %s", date.toString().latin1() ); | 459 | qWarning(" Start is %s", date.toString().latin1() ); |
460 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | 460 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); |
461 | 461 | ||
462 | date = zone.toDateTime( end ); | 462 | date = zone.toDateTime( end ); |
463 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | 463 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); |
464 | } | 464 | } |
465 | if ( rec && rec->doesRecur() ) { | 465 | if ( rec && rec->doesRecur() ) { |
466 | OTimeZone utc = OTimeZone::utc(); | 466 | OTimeZone utc = OTimeZone::utc(); |
467 | ORecur recu( *rec ); // call copy c'tor; | 467 | ORecur recu( *rec ); // call copy c'tor; |
468 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 468 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
469 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 469 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
470 | recu.setStart( ev.startDateTime().date() ); | 470 | recu.setStart( ev.startDateTime().date() ); |
471 | ev.setRecurrence( recu ); | 471 | ev.setRecurrence( recu ); |
472 | } | 472 | } |
473 | 473 | ||
474 | if (alarmTime != -1 ) { | 474 | if (alarmTime != -1 ) { |
475 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 475 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
476 | OPimAlarm al( snd , dt ); | 476 | OPimAlarm al( snd , dt ); |
477 | ev.notifiers().add( al ); | 477 | ev.notifiers().add( al ); |
478 | } | 478 | } |
479 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { | 479 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { |
480 | qWarning("already contains assign uid"); | 480 | qWarning("already contains assign uid"); |
481 | ev.setUid( 1 ); | 481 | ev.setUid( 1 ); |
482 | } | 482 | } |
483 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); | 483 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); |
484 | if ( ev.hasRecurrence() ) | 484 | if ( ev.hasRecurrence() ) |
485 | m_rep.insert( ev.uid(), ev ); | 485 | m_rep.insert( ev.uid(), ev ); |
486 | else | 486 | else |
487 | m_raw.insert( ev.uid(), ev ); | 487 | m_raw.insert( ev.uid(), ev ); |
488 | 488 | ||
489 | } | 489 | } |
490 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { | 490 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { |
491 | // qWarning(" setting %s", value.latin1() ); | 491 | // qWarning(" setting %s", value.latin1() ); |
492 | switch( id ) { | 492 | switch( id ) { |
493 | case FDescription: | 493 | case FDescription: |
494 | e.setDescription( value ); | 494 | e.setDescription( value ); |
495 | break; | 495 | break; |
496 | case FLocation: | 496 | case FLocation: |
497 | e.setLocation( value ); | 497 | e.setLocation( value ); |
498 | break; | 498 | break; |
499 | case FCategories: | 499 | case FCategories: |
500 | e.setCategories( e.idsFromString( value ) ); | 500 | e.setCategories( e.idsFromString( value ) ); |
501 | break; | 501 | break; |
502 | case FUid: | 502 | case FUid: |
503 | e.setUid( value.toInt() ); | 503 | e.setUid( value.toInt() ); |
504 | break; | 504 | break; |
505 | case FType: | 505 | case FType: |
506 | if ( value == "AllDay" ) { | 506 | if ( value == "AllDay" ) { |
507 | e.setAllDay( true ); | 507 | e.setAllDay( true ); |
508 | e.setTimeZone( "UTC" ); | 508 | e.setTimeZone( "UTC" ); |
509 | } | 509 | } |
510 | break; | 510 | break; |
511 | case FAlarm: | 511 | case FAlarm: |
512 | alarmTime = value.toInt(); | 512 | alarmTime = value.toInt(); |
513 | break; | 513 | break; |
514 | case FSound: | 514 | case FSound: |
515 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; | 515 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; |
516 | break; | 516 | break; |
517 | // recurrence stuff | 517 | // recurrence stuff |
518 | case FRType: | 518 | case FRType: |
519 | if ( value == "Daily" ) | 519 | if ( value == "Daily" ) |
520 | recur()->setType( ORecur::Daily ); | 520 | recur()->setType( ORecur::Daily ); |
521 | else if ( value == "Weekly" ) | 521 | else if ( value == "Weekly" ) |
522 | recur()->setType( ORecur::Weekly); | 522 | recur()->setType( ORecur::Weekly); |
523 | else if ( value == "MonthlyDay" ) | 523 | else if ( value == "MonthlyDay" ) |
524 | recur()->setType( ORecur::MonthlyDay ); | 524 | recur()->setType( ORecur::MonthlyDay ); |
525 | else if ( value == "MonthlyDate" ) | 525 | else if ( value == "MonthlyDate" ) |
526 | recur()->setType( ORecur::MonthlyDate ); | 526 | recur()->setType( ORecur::MonthlyDate ); |
527 | else if ( value == "Yearly" ) | 527 | else if ( value == "Yearly" ) |
528 | recur()->setType( ORecur::Yearly ); | 528 | recur()->setType( ORecur::Yearly ); |
529 | else | 529 | else |
530 | recur()->setType( ORecur::NoRepeat ); | 530 | recur()->setType( ORecur::NoRepeat ); |
531 | break; | 531 | break; |
532 | case FRWeekdays: | 532 | case FRWeekdays: |
533 | recur()->setDays( value.toInt() ); | 533 | recur()->setDays( value.toInt() ); |
534 | break; | 534 | break; |
535 | case FRPosition: | 535 | case FRPosition: |
536 | recur()->setPosition( value.toInt() ); | 536 | recur()->setPosition( value.toInt() ); |
537 | break; | 537 | break; |
538 | case FRFreq: | 538 | case FRFreq: |
539 | recur()->setFrequency( value.toInt() ); | 539 | recur()->setFrequency( value.toInt() ); |
540 | break; | 540 | break; |
541 | case FRHasEndDate: | 541 | case FRHasEndDate: |
542 | recur()->setHasEndDate( value.toInt() ); | 542 | recur()->setHasEndDate( value.toInt() ); |
543 | break; | 543 | break; |
544 | case FREndDate: { | 544 | case FREndDate: { |
545 | rp_end = (time_t) value.toLong(); | 545 | rp_end = (time_t) value.toLong(); |
546 | break; | 546 | break; |
547 | } | 547 | } |
548 | case FRStart: { | 548 | case FRStart: { |
549 | start = (time_t) value.toLong(); | 549 | start = (time_t) value.toLong(); |
550 | break; | 550 | break; |
551 | } | 551 | } |
552 | case FREnd: { | 552 | case FREnd: { |
553 | end = ( (time_t) value.toLong() ); | 553 | end = ( (time_t) value.toLong() ); |
554 | break; | 554 | break; |
555 | } | 555 | } |
556 | case FNote: | 556 | case FNote: |
557 | e.setNote( value ); | 557 | e.setNote( value ); |
558 | break; | 558 | break; |
559 | case FCreated: | 559 | case FCreated: |
560 | created = value.toInt(); | 560 | created = value.toInt(); |
561 | break; | 561 | break; |
562 | case FRecParent: | 562 | case FRecParent: |
563 | e.setParent( value.toInt() ); | 563 | e.setParent( value.toInt() ); |
564 | break; | 564 | break; |
565 | case FRecChildren:{ | 565 | case FRecChildren:{ |
566 | QStringList list = QStringList::split(' ', value ); | 566 | QStringList list = QStringList::split(' ', value ); |
567 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 567 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
568 | e.addChild( (*it).toInt() ); | 568 | e.addChild( (*it).toInt() ); |
569 | } | 569 | } |
570 | } | 570 | } |
571 | break; | 571 | break; |
572 | case FExceptions:{ | 572 | case FExceptions:{ |
573 | QStringList list = QStringList::split(' ', value ); | 573 | QStringList list = QStringList::split(' ', value ); |
574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
575 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); | 575 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); |
576 | qWarning("adding exception %s", date.toString().latin1() ); | 576 | qWarning("adding exception %s", date.toString().latin1() ); |
577 | recur()->exceptions().append( date ); | 577 | recur()->exceptions().append( date ); |
578 | } | 578 | } |
579 | } | 579 | } |
580 | break; | 580 | break; |
581 | case FTimeZone: | 581 | case FTimeZone: |
582 | if ( value != "None" ) | 582 | if ( value != "None" ) |
583 | e.setTimeZone( value ); | 583 | e.setTimeZone( value ); |
584 | break; | 584 | break; |
585 | default: | 585 | default: |
586 | break; | 586 | break; |
587 | } | 587 | } |
588 | } | 588 | } |
589 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 589 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
590 | { | 590 | { |
591 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); | 591 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); |
592 | uint arraycounter = 0; | 592 | uint arraycounter = 0; |
593 | QMap<int, OEvent>::ConstIterator it; | 593 | QMap<int, OEvent>::ConstIterator it; |
594 | 594 | ||
595 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) | 595 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) |
596 | if ( it.data().match( r ) ) | 596 | if ( it.data().match( r ) ) |
597 | m_currentQuery[arraycounter++] = it.data().uid(); | 597 | m_currentQuery[arraycounter++] = it.data().uid(); |
598 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) | 598 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) |
599 | if ( it.data().match( r ) ) | 599 | if ( it.data().match( r ) ) |
600 | m_currentQuery[arraycounter++] = it.data().uid(); | 600 | m_currentQuery[arraycounter++] = it.data().uid(); |
601 | 601 | ||
602 | // Shrink to fit.. | 602 | // Shrink to fit.. |
603 | m_currentQuery.resize(arraycounter); | 603 | m_currentQuery.resize(arraycounter); |
604 | 604 | ||
605 | return m_currentQuery; | 605 | return m_currentQuery; |
606 | } | 606 | } |
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h index 563b19c..3d774e2 100644 --- a/libopie/pim/opimrecord.h +++ b/libopie/pim/opimrecord.h | |||
@@ -1,157 +1,158 @@ | |||
1 | #ifndef OPIE_PIM_RECORD_H | 1 | #ifndef OPIE_PIM_RECORD_H |
2 | #define OPIE_PIM_RECORD_H | 2 | #define OPIE_PIM_RECORD_H |
3 | 3 | ||
4 | #include <qdatastream.h> | 4 | #include <qdatastream.h> |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qstringlist.h> | 7 | #include <qstringlist.h> |
8 | 8 | ||
9 | /* | 9 | /* |
10 | * we need to get customMap which is private... | 10 | * we need to get customMap which is private... |
11 | */ | 11 | */ |
12 | #define private protected | 12 | #define private protected |
13 | #include <qpe/palmtoprecord.h> | 13 | #include <qpe/palmtoprecord.h> |
14 | #undef private | 14 | #undef private |
15 | 15 | ||
16 | #include <opie/opimxrefmanager.h> | 16 | #include <opie/opimxrefmanager.h> |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * This is the base class for | 19 | * This is the base class for |
20 | * all PIM Records | 20 | * all PIM Records |
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | class OPimRecord : public Qtopia::Record { | 23 | class OPimRecord : public Qtopia::Record { |
24 | public: | 24 | public: |
25 | /** | 25 | /** |
26 | * c'tor | 26 | * c'tor |
27 | * uid of 0 isEmpty | 27 | * uid of 0 isEmpty |
28 | * uid of 1 will be assigned a new one | 28 | * uid of 1 will be assigned a new one |
29 | */ | 29 | */ |
30 | OPimRecord(int uid = 0); | 30 | OPimRecord(int uid = 0); |
31 | ~OPimRecord(); | 31 | ~OPimRecord(); |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * copy c'tor | 34 | * copy c'tor |
35 | */ | 35 | */ |
36 | OPimRecord( const OPimRecord& rec ); | 36 | OPimRecord( const OPimRecord& rec ); |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * copy operator | 39 | * copy operator |
40 | */ | 40 | */ |
41 | OPimRecord &operator=( const OPimRecord& ); | 41 | OPimRecord &operator=( const OPimRecord& ); |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * category names resolved | 44 | * category names resolved |
45 | */ | 45 | */ |
46 | QStringList categoryNames( const QString& appname )const; | 46 | QStringList categoryNames( const QString& appname )const; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * set category names they will be resolved | 49 | * set category names they will be resolved |
50 | */ | 50 | */ |
51 | void setCategoryNames( const QStringList& ); | 51 | void setCategoryNames( const QStringList& ); |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * addCategoryName adds a name | 54 | * addCategoryName adds a name |
55 | * to the internal category list | 55 | * to the internal category list |
56 | */ | 56 | */ |
57 | void addCategoryName( const QString& ); | 57 | void addCategoryName( const QString& ); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * if a Record isEmpty | 60 | * if a Record isEmpty |
61 | * it's empty if it's 0 | 61 | * it's empty if it's 0 |
62 | */ | 62 | */ |
63 | virtual bool isEmpty()const; | 63 | virtual bool isEmpty()const; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * toRichText summary | 66 | * toRichText summary |
67 | */ | 67 | */ |
68 | virtual QString toRichText()const = 0; | 68 | virtual QString toRichText()const = 0; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * a small one line summary | 71 | * a small one line summary |
72 | */ | 72 | */ |
73 | virtual QString toShortText()const = 0; | 73 | virtual QString toShortText()const = 0; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * the name of the Record | 76 | * the name of the Record |
77 | */ | 77 | */ |
78 | virtual QString type()const = 0; | 78 | virtual QString type()const = 0; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * matches the Records the regular expression? | 81 | * matches the Records the regular expression? |
82 | */ | 82 | */ |
83 | virtual bool match( const QString ®exp ) const | 83 | virtual bool match( const QString ®exp ) const |
84 | {setLastHitField( -1 ); | 84 | {setLastHitField( -1 ); |
85 | return Qtopia::Record::match(QRegExp(regexp));}; | 85 | return Qtopia::Record::match(QRegExp(regexp));}; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * if implemented this function returns which item has been | 88 | * if implemented this function returns which item has been |
89 | * last hit by the match() function. | 89 | * last hit by the match() function. |
90 | * or -1 if not implemented or no hit has occured | 90 | * or -1 if not implemented or no hit has occured |
91 | */ | 91 | */ |
92 | int lastHitField()const; | 92 | int lastHitField()const; |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * converts the internal structure to a map | 95 | * converts the internal structure to a map |
96 | */ | 96 | */ |
97 | virtual QMap<int, QString> toMap()const = 0; | 97 | virtual QMap<int, QString> toMap()const = 0; |
98 | // virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers) | ||
98 | 99 | ||
99 | /** | 100 | /** |
100 | * key value representation of extra items | 101 | * key value representation of extra items |
101 | */ | 102 | */ |
102 | QMap<QString, QString> toExtraMap()const; | 103 | QMap<QString, QString> toExtraMap()const; |
103 | void setExtraMap( const QMap<QString, QString>& ); | 104 | void setExtraMap( const QMap<QString, QString>& ); |
104 | 105 | ||
105 | /** | 106 | /** |
106 | * the name for a recordField | 107 | * the name for a recordField |
107 | */ | 108 | */ |
108 | virtual QString recordField(int)const = 0; | 109 | virtual QString recordField(int)const = 0; |
109 | 110 | ||
110 | /** | 111 | /** |
111 | * returns a reference of the | 112 | * returns a reference of the |
112 | * Cross Reference Manager | 113 | * Cross Reference Manager |
113 | * Partner 'One' is THIS PIM RECORD! | 114 | * Partner 'One' is THIS PIM RECORD! |
114 | * 'Two' is the Partner where we link to | 115 | * 'Two' is the Partner where we link to |
115 | */ | 116 | */ |
116 | OPimXRefManager& xrefmanager(); | 117 | OPimXRefManager& xrefmanager(); |
117 | 118 | ||
118 | /** | 119 | /** |
119 | * set the uid | 120 | * set the uid |
120 | */ | 121 | */ |
121 | virtual void setUid( int uid ); | 122 | virtual void setUid( int uid ); |
122 | 123 | ||
123 | /* | 124 | /* |
124 | * used inside the Templates for casting | 125 | * used inside the Templates for casting |
125 | * REIMPLEMENT in your .... | 126 | * REIMPLEMENT in your .... |
126 | */ | 127 | */ |
127 | static int rtti(); | 128 | static int rtti(); |
128 | 129 | ||
129 | /** | 130 | /** |
130 | * some marshalling and de marshalling code | 131 | * some marshalling and de marshalling code |
131 | * saves the OPimRecord | 132 | * saves the OPimRecord |
132 | * to and from a DataStream | 133 | * to and from a DataStream |
133 | */ | 134 | */ |
134 | virtual bool loadFromStream(QDataStream& ); | 135 | virtual bool loadFromStream(QDataStream& ); |
135 | virtual bool saveToStream( QDataStream& stream )const; | 136 | virtual bool saveToStream( QDataStream& stream )const; |
136 | 137 | ||
137 | protected: | 138 | protected: |
138 | // need to be const cause it is called from const methods | 139 | // need to be const cause it is called from const methods |
139 | mutable int m_lastHit; | 140 | mutable int m_lastHit; |
140 | void setLastHitField( int lastHit )const; | 141 | void setLastHitField( int lastHit )const; |
141 | Qtopia::UidGen &uidGen(); | 142 | Qtopia::UidGen &uidGen(); |
142 | // QString crossToString()const; | 143 | // QString crossToString()const; |
143 | 144 | ||
144 | private: | 145 | private: |
145 | class OPimRecordPrivate; | 146 | class OPimRecordPrivate; |
146 | OPimRecordPrivate *d; | 147 | OPimRecordPrivate *d; |
147 | OPimXRefManager m_xrefman; | 148 | OPimXRefManager m_xrefman; |
148 | static Qtopia::UidGen m_uidGen; | 149 | static Qtopia::UidGen m_uidGen; |
149 | 150 | ||
150 | private: | 151 | private: |
151 | void flush( const OPimXRefPartner&, QDataStream& stream )const; | 152 | void flush( const OPimXRefPartner&, QDataStream& stream )const; |
152 | OPimXRefPartner partner( QDataStream& ); | 153 | OPimXRefPartner partner( QDataStream& ); |
153 | }; | 154 | }; |
154 | 155 | ||
155 | 156 | ||
156 | 157 | ||
157 | #endif | 158 | #endif |