-rw-r--r-- | libopie/pim/odatebookaccessbackend_xml.cpp | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | 4 |
2 files changed, 2 insertions, 6 deletions
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp index 5239d84..bc51996 100644 --- a/libopie/pim/odatebookaccessbackend_xml.cpp +++ b/libopie/pim/odatebookaccessbackend_xml.cpp | |||
@@ -1,557 +1,555 @@ | |||
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 | time_t start, end, created, rp_end; | 26 | time_t start, end, created, rp_end; |
27 | ORecur* rec; | 27 | ORecur* rec; |
28 | ORecur* recur() { | 28 | ORecur* recur() { |
29 | if (!rec) | 29 | if (!rec) |
30 | rec = new ORecur; | 30 | rec = new ORecur; |
31 | 31 | ||
32 | return rec; | 32 | return rec; |
33 | } | 33 | } |
34 | int alarmTime; | 34 | int alarmTime; |
35 | int snd; | 35 | int snd; |
36 | enum Attribute{ | 36 | enum Attribute{ |
37 | FDescription = 0, | 37 | FDescription = 0, |
38 | FLocation, | 38 | FLocation, |
39 | FCategories, | 39 | FCategories, |
40 | FUid, | 40 | FUid, |
41 | FType, | 41 | FType, |
42 | FAlarm, | 42 | FAlarm, |
43 | FSound, | 43 | FSound, |
44 | FRType, | 44 | FRType, |
45 | FRWeekdays, | 45 | FRWeekdays, |
46 | FRPosition, | 46 | FRPosition, |
47 | FRFreq, | 47 | FRFreq, |
48 | FRHasEndDate, | 48 | FRHasEndDate, |
49 | FREndDate, | 49 | FREndDate, |
50 | FRStart, | 50 | FRStart, |
51 | FREnd, | 51 | FREnd, |
52 | FNote, | 52 | FNote, |
53 | FCreated, | 53 | FCreated, |
54 | FTimeZone, | 54 | FTimeZone, |
55 | FRecParent, | 55 | FRecParent, |
56 | FRecChildren, | 56 | FRecChildren, |
57 | FExceptions | 57 | FExceptions |
58 | }; | 58 | }; |
59 | inline void save( const OEvent& ev, QString& buf ) { | 59 | inline void save( const OEvent& ev, QString& buf ) { |
60 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; | 60 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; |
61 | if (!ev.location().isEmpty() ) | 61 | if (!ev.location().isEmpty() ) |
62 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; | 62 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; |
63 | 63 | ||
64 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 64 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
65 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 65 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
66 | 66 | ||
67 | if (ev.isAllDay() ) | 67 | if (ev.isAllDay() ) |
68 | buf += " type=\"AllDay\""; | 68 | buf += " type=\"AllDay\""; |
69 | 69 | ||
70 | if (ev.hasNotifiers() ) { | 70 | if (ev.hasNotifiers() ) { |
71 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 71 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
72 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 72 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
73 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 73 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
74 | if ( alarm.sound() == OPimAlarm::Loud ) | 74 | if ( alarm.sound() == OPimAlarm::Loud ) |
75 | buf += "loud"; | 75 | buf += "loud"; |
76 | else | 76 | else |
77 | buf += "silent"; | 77 | buf += "silent"; |
78 | buf += "\""; | 78 | buf += "\""; |
79 | } | 79 | } |
80 | if ( ev.hasRecurrence() ) { | 80 | if ( ev.hasRecurrence() ) { |
81 | buf += ev.recurrence().toString(); | 81 | buf += ev.recurrence().toString(); |
82 | } | 82 | } |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * fscking timezones :) well, we'll first convert | 85 | * fscking timezones :) well, we'll first convert |
86 | * the QDateTime to a QDateTime in UTC time | 86 | * the QDateTime to a QDateTime in UTC time |
87 | * and then we'll create a nice time_t | 87 | * and then we'll create a nice time_t |
88 | */ | 88 | */ |
89 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 89 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
90 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; | 90 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; |
91 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; | 91 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; |
92 | if (!ev.note().isEmpty() ) { | 92 | if (!ev.note().isEmpty() ) { |
93 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 93 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
94 | } | 94 | } |
95 | 95 | ||
96 | buf += " timezone=\""; | 96 | buf += " timezone=\""; |
97 | if ( ev.timeZone().isEmpty() ) | 97 | if ( ev.timeZone().isEmpty() ) |
98 | buf += "None"; | 98 | buf += "None"; |
99 | else | 99 | else |
100 | buf += ev.timeZone(); | 100 | buf += ev.timeZone(); |
101 | 101 | ||
102 | if (ev.parent() != 0 ) { | 102 | if (ev.parent() != 0 ) { |
103 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 103 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
104 | } | 104 | } |
105 | 105 | ||
106 | if (ev.children().count() != 0 ) { | 106 | if (ev.children().count() != 0 ) { |
107 | QArray<int> children = ev.children(); | 107 | QArray<int> children = ev.children(); |
108 | buf += " recchildren=\""; | 108 | buf += " recchildren=\""; |
109 | for ( uint i = 0; i < children.count(); i++ ) { | 109 | for ( uint i = 0; i < children.count(); i++ ) { |
110 | if ( i != 0 ) buf += " "; | 110 | if ( i != 0 ) buf += " "; |
111 | buf += QString::number( children[i] ); | 111 | buf += QString::number( children[i] ); |
112 | } | 112 | } |
113 | buf+= "\""; | 113 | buf+= "\""; |
114 | } | 114 | } |
115 | 115 | ||
116 | // skip custom writing | 116 | // skip custom writing |
117 | } | 117 | } |
118 | 118 | ||
119 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { | 119 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { |
120 | QMap<int, OEvent>::ConstIterator it; | 120 | QMap<int, OEvent>::ConstIterator it; |
121 | QString buf; | 121 | QString buf; |
122 | QCString str; | 122 | QCString str; |
123 | int total_written; | 123 | int total_written; |
124 | for ( it = list.begin(); it != list.end(); ++it ) { | 124 | for ( it = list.begin(); it != list.end(); ++it ) { |
125 | buf = "<event"; | 125 | buf = "<event"; |
126 | save( it.data(), buf ); | 126 | save( it.data(), buf ); |
127 | buf += " />\n"; | 127 | buf += " />\n"; |
128 | str = buf.utf8(); | 128 | str = buf.utf8(); |
129 | 129 | ||
130 | total_written = file.writeBlock(str.data(), str.length() ); | 130 | total_written = file.writeBlock(str.data(), str.length() ); |
131 | if ( total_written != int(str.length() ) ) | 131 | if ( total_written != int(str.length() ) ) |
132 | return false; | 132 | return false; |
133 | } | 133 | } |
134 | return true; | 134 | return true; |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 138 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
139 | const QString& fileName ) | 139 | const QString& fileName ) |
140 | : ODateBookAccessBackend() { | 140 | : ODateBookAccessBackend() { |
141 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 141 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
142 | m_changed = false; | 142 | m_changed = false; |
143 | } | 143 | } |
144 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 144 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
145 | } | 145 | } |
146 | bool ODateBookAccessBackend_XML::load() { | 146 | bool ODateBookAccessBackend_XML::load() { |
147 | return loadFile(); | 147 | return loadFile(); |
148 | } | 148 | } |
149 | bool ODateBookAccessBackend_XML::reload() { | 149 | bool ODateBookAccessBackend_XML::reload() { |
150 | clear(); | 150 | clear(); |
151 | return load(); | 151 | return load(); |
152 | } | 152 | } |
153 | bool ODateBookAccessBackend_XML::save() { | 153 | bool ODateBookAccessBackend_XML::save() { |
154 | qWarning("going to save now"); | 154 | if (!m_changed) return true; |
155 | // if (!m_changed) return true; | ||
156 | 155 | ||
157 | int total_written; | 156 | int total_written; |
158 | QString strFileNew = m_name + ".new"; | 157 | QString strFileNew = m_name + ".new"; |
159 | 158 | ||
160 | QFile f( strFileNew ); | 159 | QFile f( strFileNew ); |
161 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 160 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
162 | 161 | ||
163 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 162 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
164 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 163 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
165 | buf += "<events>\n"; | 164 | buf += "<events>\n"; |
166 | QCString str = buf.utf8(); | 165 | QCString str = buf.utf8(); |
167 | total_written = f.writeBlock( str.data(), str.length() ); | 166 | total_written = f.writeBlock( str.data(), str.length() ); |
168 | if ( total_written != int(str.length() ) ) { | 167 | if ( total_written != int(str.length() ) ) { |
169 | f.close(); | 168 | f.close(); |
170 | QFile::remove( strFileNew ); | 169 | QFile::remove( strFileNew ); |
171 | return false; | 170 | return false; |
172 | } | 171 | } |
173 | 172 | ||
174 | if (!forAll( m_raw, f ) ) { | 173 | if (!forAll( m_raw, f ) ) { |
175 | f.close(); | 174 | f.close(); |
176 | QFile::remove( strFileNew ); | 175 | QFile::remove( strFileNew ); |
177 | return false; | 176 | return false; |
178 | } | 177 | } |
179 | if (!forAll( m_rep, f ) ) { | 178 | if (!forAll( m_rep, f ) ) { |
180 | f.close(); | 179 | f.close(); |
181 | QFile::remove( strFileNew ); | 180 | QFile::remove( strFileNew ); |
182 | return false; | 181 | return false; |
183 | } | 182 | } |
184 | 183 | ||
185 | buf = "</events>\n</DATEBOOK>\n"; | 184 | buf = "</events>\n</DATEBOOK>\n"; |
186 | str = buf.utf8(); | 185 | str = buf.utf8(); |
187 | total_written = f.writeBlock( str.data(), str.length() ); | 186 | total_written = f.writeBlock( str.data(), str.length() ); |
188 | if ( total_written != int(str.length() ) ) { | 187 | if ( total_written != int(str.length() ) ) { |
189 | f.close(); | 188 | f.close(); |
190 | QFile::remove( strFileNew ); | 189 | QFile::remove( strFileNew ); |
191 | return false; | 190 | return false; |
192 | } | 191 | } |
193 | f.close(); | 192 | f.close(); |
194 | 193 | ||
195 | exit(0); | ||
196 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 194 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
197 | QFile::remove( strFileNew ); | 195 | QFile::remove( strFileNew ); |
198 | return false; | 196 | return false; |
199 | } | 197 | } |
200 | 198 | ||
201 | m_changed = false; | 199 | m_changed = false; |
202 | return true; | 200 | return true; |
203 | } | 201 | } |
204 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 202 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
205 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 203 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
206 | uint i = 0; | 204 | uint i = 0; |
207 | QMap<int, OEvent>::ConstIterator it; | 205 | QMap<int, OEvent>::ConstIterator it; |
208 | 206 | ||
209 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 207 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
210 | ints[i] = it.key(); | 208 | ints[i] = it.key(); |
211 | i++; | 209 | i++; |
212 | } | 210 | } |
213 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 211 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
214 | ints[i] = it.key(); | 212 | ints[i] = it.key(); |
215 | i++; | 213 | i++; |
216 | } | 214 | } |
217 | 215 | ||
218 | return ints; | 216 | return ints; |
219 | } | 217 | } |
220 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int ) { | 218 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int ) { |
221 | return QArray<int>(); | 219 | return QArray<int>(); |
222 | } | 220 | } |
223 | void ODateBookAccessBackend_XML::clear() { | 221 | void ODateBookAccessBackend_XML::clear() { |
224 | m_raw.clear(); | 222 | m_raw.clear(); |
225 | m_rep.clear(); | 223 | m_rep.clear(); |
226 | } | 224 | } |
227 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 225 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
228 | if ( m_raw.contains( uid ) ) | 226 | if ( m_raw.contains( uid ) ) |
229 | return m_raw[uid]; | 227 | return m_raw[uid]; |
230 | else | 228 | else |
231 | return m_rep[uid]; | 229 | return m_rep[uid]; |
232 | } | 230 | } |
233 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 231 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
234 | m_changed = true; | 232 | m_changed = true; |
235 | if (ev.hasRecurrence() ) | 233 | if (ev.hasRecurrence() ) |
236 | m_rep.insert( ev.uid(), ev ); | 234 | m_rep.insert( ev.uid(), ev ); |
237 | else | 235 | else |
238 | m_raw.insert( ev.uid(), ev ); | 236 | m_raw.insert( ev.uid(), ev ); |
239 | 237 | ||
240 | return true; | 238 | return true; |
241 | } | 239 | } |
242 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 240 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
243 | m_changed = true; | 241 | m_changed = true; |
244 | m_rep.remove( uid ); | 242 | m_rep.remove( uid ); |
245 | m_rep.remove( uid ); | 243 | m_rep.remove( uid ); |
246 | 244 | ||
247 | return true; | 245 | return true; |
248 | } | 246 | } |
249 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 247 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
250 | replace( ev.uid() ); | 248 | replace( ev.uid() ); |
251 | return add( ev ); | 249 | return add( ev ); |
252 | } | 250 | } |
253 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 251 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
254 | return allRecords(); | 252 | return allRecords(); |
255 | } | 253 | } |
256 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 254 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
257 | QArray<int> ints( m_rep.count() ); | 255 | QArray<int> ints( m_rep.count() ); |
258 | uint i = 0; | 256 | uint i = 0; |
259 | QMap<int, OEvent>::ConstIterator it; | 257 | QMap<int, OEvent>::ConstIterator it; |
260 | 258 | ||
261 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 259 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
262 | ints[i] = it.key(); | 260 | ints[i] = it.key(); |
263 | i++; | 261 | i++; |
264 | } | 262 | } |
265 | 263 | ||
266 | return ints; | 264 | return ints; |
267 | } | 265 | } |
268 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 266 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
269 | QArray<int> ints( m_raw.count() ); | 267 | QArray<int> ints( m_raw.count() ); |
270 | uint i = 0; | 268 | uint i = 0; |
271 | QMap<int, OEvent>::ConstIterator it; | 269 | QMap<int, OEvent>::ConstIterator it; |
272 | 270 | ||
273 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 271 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
274 | ints[i] = it.key(); | 272 | ints[i] = it.key(); |
275 | i++; | 273 | i++; |
276 | } | 274 | } |
277 | 275 | ||
278 | return ints; | 276 | return ints; |
279 | } | 277 | } |
280 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 278 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
281 | OEvent::ValueList list; | 279 | OEvent::ValueList list; |
282 | QMap<int, OEvent>::ConstIterator it; | 280 | QMap<int, OEvent>::ConstIterator it; |
283 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 281 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
284 | list.append( it.data() ); | 282 | list.append( it.data() ); |
285 | 283 | ||
286 | return list; | 284 | return list; |
287 | } | 285 | } |
288 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 286 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
289 | OEvent::ValueList list; | 287 | OEvent::ValueList list; |
290 | QMap<int, OEvent>::ConstIterator it; | 288 | QMap<int, OEvent>::ConstIterator it; |
291 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 289 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
292 | list.append( it.data() ); | 290 | list.append( it.data() ); |
293 | 291 | ||
294 | return list; | 292 | return list; |
295 | } | 293 | } |
296 | bool ODateBookAccessBackend_XML::loadFile() { | 294 | bool ODateBookAccessBackend_XML::loadFile() { |
297 | m_changed = false; | 295 | m_changed = false; |
298 | 296 | ||
299 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 297 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
300 | if ( fd < 0 ) return false; | 298 | if ( fd < 0 ) return false; |
301 | 299 | ||
302 | struct stat attribute; | 300 | struct stat attribute; |
303 | if ( ::fstat(fd, &attribute ) == -1 ) { | 301 | if ( ::fstat(fd, &attribute ) == -1 ) { |
304 | ::close( fd ); | 302 | ::close( fd ); |
305 | return false; | 303 | return false; |
306 | } | 304 | } |
307 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 305 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
308 | if ( map_addr == ( (caddr_t)-1) ) { | 306 | if ( map_addr == ( (caddr_t)-1) ) { |
309 | ::close( fd ); | 307 | ::close( fd ); |
310 | return false; | 308 | return false; |
311 | } | 309 | } |
312 | 310 | ||
313 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 311 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
314 | ::close( fd ); | 312 | ::close( fd ); |
315 | 313 | ||
316 | QAsciiDict<int> dict(FExceptions+1); | 314 | QAsciiDict<int> dict(FExceptions+1); |
317 | dict.setAutoDelete( true ); | 315 | dict.setAutoDelete( true ); |
318 | dict.insert( "description", new int(FDescription) ); | 316 | dict.insert( "description", new int(FDescription) ); |
319 | dict.insert( "location", new int(FLocation) ); | 317 | dict.insert( "location", new int(FLocation) ); |
320 | dict.insert( "categories", new int(FCategories) ); | 318 | dict.insert( "categories", new int(FCategories) ); |
321 | dict.insert( "uid", new int(FUid) ); | 319 | dict.insert( "uid", new int(FUid) ); |
322 | dict.insert( "type", new int(FType) ); | 320 | dict.insert( "type", new int(FType) ); |
323 | dict.insert( "alarm", new int(FAlarm) ); | 321 | dict.insert( "alarm", new int(FAlarm) ); |
324 | dict.insert( "sound", new int(FSound) ); | 322 | dict.insert( "sound", new int(FSound) ); |
325 | dict.insert( "rtype", new int(FRType) ); | 323 | dict.insert( "rtype", new int(FRType) ); |
326 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 324 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
327 | dict.insert( "rposition", new int(FRPosition) ); | 325 | dict.insert( "rposition", new int(FRPosition) ); |
328 | dict.insert( "rfreq", new int(FRFreq) ); | 326 | dict.insert( "rfreq", new int(FRFreq) ); |
329 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 327 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
330 | dict.insert( "enddt", new int(FREndDate) ); | 328 | dict.insert( "enddt", new int(FREndDate) ); |
331 | dict.insert( "start", new int(FRStart) ); | 329 | dict.insert( "start", new int(FRStart) ); |
332 | dict.insert( "end", new int(FREnd) ); | 330 | dict.insert( "end", new int(FREnd) ); |
333 | dict.insert( "note", new int(FNote) ); | 331 | dict.insert( "note", new int(FNote) ); |
334 | dict.insert( "created", new int(FCreated) ); | 332 | dict.insert( "created", new int(FCreated) ); |
335 | dict.insert( "recparent", new int(FRecParent) ); | 333 | dict.insert( "recparent", new int(FRecParent) ); |
336 | dict.insert( "recchildren", new int(FRecChildren) ); | 334 | dict.insert( "recchildren", new int(FRecChildren) ); |
337 | dict.insert( "exceptions", new int(FExceptions) ); | 335 | dict.insert( "exceptions", new int(FExceptions) ); |
338 | dict.insert( "timezone", new int(FTimeZone) ); | 336 | dict.insert( "timezone", new int(FTimeZone) ); |
339 | 337 | ||
340 | char* dt = (char*)map_addr; | 338 | char* dt = (char*)map_addr; |
341 | int len = attribute.st_size; | 339 | int len = attribute.st_size; |
342 | int i = 0; | 340 | int i = 0; |
343 | char* point; | 341 | char* point; |
344 | const char* collectionString = "<event "; | 342 | const char* collectionString = "<event "; |
345 | int strLen = ::strlen(collectionString); | 343 | int strLen = ::strlen(collectionString); |
346 | int *find; | 344 | int *find; |
347 | while ( dt + 1 != 0 && (( point = ::strstr( dt+i, collectionString ) ) != 0 ) ) { | 345 | while ( dt + 1 != 0 && (( point = ::strstr( dt+i, collectionString ) ) != 0 ) ) { |
348 | i = point -dt; | 346 | i = point -dt; |
349 | i+= strLen; | 347 | i+= strLen; |
350 | 348 | ||
351 | alarmTime = -1; | 349 | alarmTime = -1; |
352 | snd = 0; // silent | 350 | snd = 0; // silent |
353 | 351 | ||
354 | OEvent ev; | 352 | OEvent ev; |
355 | rec = 0; | 353 | rec = 0; |
356 | 354 | ||
357 | while ( TRUE ) { | 355 | while ( TRUE ) { |
358 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 356 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
359 | ++i; | 357 | ++i; |
360 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 358 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
361 | break; | 359 | break; |
362 | 360 | ||
363 | 361 | ||
364 | // we have another attribute, read it. | 362 | // we have another attribute, read it. |
365 | int j = i; | 363 | int j = i; |
366 | while ( j < len && dt[j] != '=' ) | 364 | while ( j < len && dt[j] != '=' ) |
367 | ++j; | 365 | ++j; |
368 | QCString attr( dt+i, j-i+1); | 366 | QCString attr( dt+i, j-i+1); |
369 | 367 | ||
370 | i = ++j; // skip = | 368 | i = ++j; // skip = |
371 | 369 | ||
372 | // find the start of quotes | 370 | // find the start of quotes |
373 | while ( i < len && dt[i] != '"' ) | 371 | while ( i < len && dt[i] != '"' ) |
374 | ++i; | 372 | ++i; |
375 | j = ++i; | 373 | j = ++i; |
376 | 374 | ||
377 | bool haveUtf = FALSE; | 375 | bool haveUtf = FALSE; |
378 | bool haveEnt = FALSE; | 376 | bool haveEnt = FALSE; |
379 | while ( j < len && dt[j] != '"' ) { | 377 | while ( j < len && dt[j] != '"' ) { |
380 | if ( ((unsigned char)dt[j]) > 0x7f ) | 378 | if ( ((unsigned char)dt[j]) > 0x7f ) |
381 | haveUtf = TRUE; | 379 | haveUtf = TRUE; |
382 | if ( dt[j] == '&' ) | 380 | if ( dt[j] == '&' ) |
383 | haveEnt = TRUE; | 381 | haveEnt = TRUE; |
384 | ++j; | 382 | ++j; |
385 | } | 383 | } |
386 | if ( i == j ) { | 384 | if ( i == j ) { |
387 | // empty value | 385 | // empty value |
388 | i = j + 1; | 386 | i = j + 1; |
389 | continue; | 387 | continue; |
390 | } | 388 | } |
391 | 389 | ||
392 | QCString value( dt+i, j-i+1 ); | 390 | QCString value( dt+i, j-i+1 ); |
393 | i = j + 1; | 391 | i = j + 1; |
394 | 392 | ||
395 | QString str = (haveUtf ? QString::fromUtf8( value ) | 393 | QString str = (haveUtf ? QString::fromUtf8( value ) |
396 | : QString::fromLatin1( value ) ); | 394 | : QString::fromLatin1( value ) ); |
397 | if ( haveEnt ) | 395 | if ( haveEnt ) |
398 | str = Qtopia::plainString( str ); | 396 | str = Qtopia::plainString( str ); |
399 | 397 | ||
400 | /* | 398 | /* |
401 | * add key + value | 399 | * add key + value |
402 | */ | 400 | */ |
403 | find = dict[attr.data()]; | 401 | find = dict[attr.data()]; |
404 | if (!find) | 402 | if (!find) |
405 | ev.setCustomField( attr, value ); | 403 | ev.setCustomField( attr, value ); |
406 | else { | 404 | else { |
407 | setField( ev, *find, value ); | 405 | setField( ev, *find, value ); |
408 | } | 406 | } |
409 | } | 407 | } |
410 | /* time to finalize */ | 408 | /* time to finalize */ |
411 | finalizeRecord( ev ); | 409 | finalizeRecord( ev ); |
412 | add( ev ); | 410 | add( ev ); |
413 | delete rec; | 411 | delete rec; |
414 | } | 412 | } |
415 | ::munmap(map_addr, attribute.st_size ); | 413 | ::munmap(map_addr, attribute.st_size ); |
416 | m_changed = false; // changed during add | 414 | m_changed = false; // changed during add |
417 | 415 | ||
418 | return true; | 416 | return true; |
419 | } | 417 | } |
420 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 418 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
421 | /* AllDay is alway in UTC */ | 419 | /* AllDay is alway in UTC */ |
422 | if ( ev.isAllDay() ) { | 420 | if ( ev.isAllDay() ) { |
423 | OTimeZone utc = OTimeZone::utc(); | 421 | OTimeZone utc = OTimeZone::utc(); |
424 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 422 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
425 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 423 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
426 | ev.setTimeZone( "UTC"); // make sure it is really utc | 424 | ev.setTimeZone( "UTC"); // make sure it is really utc |
427 | }else { | 425 | }else { |
428 | /* to current date time */ | 426 | /* to current date time */ |
429 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 427 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
430 | QDateTime date = zone.toDateTime( start ); | 428 | QDateTime date = zone.toDateTime( start ); |
431 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | 429 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); |
432 | 430 | ||
433 | date = zone.toDateTime( end ); | 431 | date = zone.toDateTime( end ); |
434 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | 432 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); |
435 | } | 433 | } |
436 | if ( rec && rec->doesRecur() ) { | 434 | if ( rec && rec->doesRecur() ) { |
437 | OTimeZone utc = OTimeZone::utc(); | 435 | OTimeZone utc = OTimeZone::utc(); |
438 | ORecur recu( *rec ); // call copy c'tor; | 436 | ORecur recu( *rec ); // call copy c'tor; |
439 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 437 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
440 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 438 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
441 | recu.setStart( ev.startDateTime().date() ); | 439 | recu.setStart( ev.startDateTime().date() ); |
442 | ev.setRecurrence( recu ); | 440 | ev.setRecurrence( recu ); |
443 | } | 441 | } |
444 | 442 | ||
445 | if (alarmTime != -1 ) { | 443 | if (alarmTime != -1 ) { |
446 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 444 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
447 | OPimAlarm al( snd , dt ); | 445 | OPimAlarm al( snd , dt ); |
448 | ev.notifiers().add( al ); | 446 | ev.notifiers().add( al ); |
449 | } | 447 | } |
450 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { | 448 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { |
451 | ev.setUid( 1 ); | 449 | ev.setUid( 1 ); |
452 | } | 450 | } |
453 | if ( ev.hasRecurrence() ) | 451 | if ( ev.hasRecurrence() ) |
454 | m_rep.insert( ev.uid(), ev ); | 452 | m_rep.insert( ev.uid(), ev ); |
455 | else | 453 | else |
456 | m_raw.insert( ev.uid(), ev ); | 454 | m_raw.insert( ev.uid(), ev ); |
457 | 455 | ||
458 | } | 456 | } |
459 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { | 457 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { |
460 | // qWarning(" setting %s", value.latin1() ); | 458 | // qWarning(" setting %s", value.latin1() ); |
461 | switch( id ) { | 459 | switch( id ) { |
462 | case FDescription: | 460 | case FDescription: |
463 | e.setDescription( value ); | 461 | e.setDescription( value ); |
464 | break; | 462 | break; |
465 | case FLocation: | 463 | case FLocation: |
466 | e.setLocation( value ); | 464 | e.setLocation( value ); |
467 | break; | 465 | break; |
468 | case FCategories: | 466 | case FCategories: |
469 | e.setCategories( e.idsFromString( value ) ); | 467 | e.setCategories( e.idsFromString( value ) ); |
470 | break; | 468 | break; |
471 | case FUid: | 469 | case FUid: |
472 | e.setUid( value.toInt() ); | 470 | e.setUid( value.toInt() ); |
473 | break; | 471 | break; |
474 | case FType: | 472 | case FType: |
475 | if ( value == "AllDay" ) { | 473 | if ( value == "AllDay" ) { |
476 | e.setAllDay( true ); | 474 | e.setAllDay( true ); |
477 | e.setTimeZone( "UTC" ); | 475 | e.setTimeZone( "UTC" ); |
478 | } | 476 | } |
479 | break; | 477 | break; |
480 | case FAlarm: | 478 | case FAlarm: |
481 | alarmTime = value.toInt(); | 479 | alarmTime = value.toInt(); |
482 | break; | 480 | break; |
483 | case FSound: | 481 | case FSound: |
484 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; | 482 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; |
485 | break; | 483 | break; |
486 | // recurrence stuff | 484 | // recurrence stuff |
487 | case FRType: | 485 | case FRType: |
488 | if ( value == "Daily" ) | 486 | if ( value == "Daily" ) |
489 | recur()->setType( ORecur::Daily ); | 487 | recur()->setType( ORecur::Daily ); |
490 | else if ( value == "Weekly" ) | 488 | else if ( value == "Weekly" ) |
491 | recur()->setType( ORecur::Weekly); | 489 | recur()->setType( ORecur::Weekly); |
492 | else if ( value == "MonthlyDay" ) | 490 | else if ( value == "MonthlyDay" ) |
493 | recur()->setType( ORecur::MonthlyDay ); | 491 | recur()->setType( ORecur::MonthlyDay ); |
494 | else if ( value == "MonthlyDate" ) | 492 | else if ( value == "MonthlyDate" ) |
495 | recur()->setType( ORecur::MonthlyDate ); | 493 | recur()->setType( ORecur::MonthlyDate ); |
496 | else if ( value == "Yearly" ) | 494 | else if ( value == "Yearly" ) |
497 | recur()->setType( ORecur::Yearly ); | 495 | recur()->setType( ORecur::Yearly ); |
498 | else | 496 | else |
499 | recur()->setType( ORecur::NoRepeat ); | 497 | recur()->setType( ORecur::NoRepeat ); |
500 | break; | 498 | break; |
501 | case FRWeekdays: | 499 | case FRWeekdays: |
502 | recur()->setDays( value.toInt() ); | 500 | recur()->setDays( value.toInt() ); |
503 | break; | 501 | break; |
504 | case FRPosition: | 502 | case FRPosition: |
505 | recur()->setPosition( value.toInt() ); | 503 | recur()->setPosition( value.toInt() ); |
506 | break; | 504 | break; |
507 | case FRFreq: | 505 | case FRFreq: |
508 | recur()->setFrequency( value.toInt() ); | 506 | recur()->setFrequency( value.toInt() ); |
509 | break; | 507 | break; |
510 | case FRHasEndDate: | 508 | case FRHasEndDate: |
511 | recur()->setHasEndDate( value.toInt() ); | 509 | recur()->setHasEndDate( value.toInt() ); |
512 | break; | 510 | break; |
513 | case FREndDate: { | 511 | case FREndDate: { |
514 | rp_end = (time_t) value.toLong(); | 512 | rp_end = (time_t) value.toLong(); |
515 | break; | 513 | break; |
516 | } | 514 | } |
517 | case FRStart: { | 515 | case FRStart: { |
518 | start = (time_t) value.toLong(); | 516 | start = (time_t) value.toLong(); |
519 | break; | 517 | break; |
520 | } | 518 | } |
521 | case FREnd: { | 519 | case FREnd: { |
522 | end = ( (time_t) value.toLong() ); | 520 | end = ( (time_t) value.toLong() ); |
523 | break; | 521 | break; |
524 | } | 522 | } |
525 | case FNote: | 523 | case FNote: |
526 | e.setNote( value ); | 524 | e.setNote( value ); |
527 | break; | 525 | break; |
528 | case FCreated: | 526 | case FCreated: |
529 | created = value.toInt(); | 527 | created = value.toInt(); |
530 | break; | 528 | break; |
531 | case FRecParent: | 529 | case FRecParent: |
532 | e.setParent( value.toInt() ); | 530 | e.setParent( value.toInt() ); |
533 | break; | 531 | break; |
534 | case FRecChildren:{ | 532 | case FRecChildren:{ |
535 | QStringList list = QStringList::split(' ', value ); | 533 | QStringList list = QStringList::split(' ', value ); |
536 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 534 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
537 | e.addChild( (*it).toInt() ); | 535 | e.addChild( (*it).toInt() ); |
538 | } | 536 | } |
539 | } | 537 | } |
540 | break; | 538 | break; |
541 | case FExceptions:{ | 539 | case FExceptions:{ |
542 | QStringList list = QStringList::split(' ', value ); | 540 | QStringList list = QStringList::split(' ', value ); |
543 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 541 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
544 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); | 542 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); |
545 | qWarning("adding exception %s", date.toString().latin1() ); | 543 | qWarning("adding exception %s", date.toString().latin1() ); |
546 | recur()->exceptions().append( date ); | 544 | recur()->exceptions().append( date ); |
547 | } | 545 | } |
548 | } | 546 | } |
549 | break; | 547 | break; |
550 | case FTimeZone: | 548 | case FTimeZone: |
551 | if ( value != "None" ) | 549 | if ( value != "None" ) |
552 | e.setTimeZone( value ); | 550 | e.setTimeZone( value ); |
553 | break; | 551 | break; |
554 | default: | 552 | default: |
555 | break; | 553 | break; |
556 | } | 554 | } |
557 | } | 555 | } |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp index 5239d84..bc51996 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |||
@@ -1,557 +1,555 @@ | |||
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 | time_t start, end, created, rp_end; | 26 | time_t start, end, created, rp_end; |
27 | ORecur* rec; | 27 | ORecur* rec; |
28 | ORecur* recur() { | 28 | ORecur* recur() { |
29 | if (!rec) | 29 | if (!rec) |
30 | rec = new ORecur; | 30 | rec = new ORecur; |
31 | 31 | ||
32 | return rec; | 32 | return rec; |
33 | } | 33 | } |
34 | int alarmTime; | 34 | int alarmTime; |
35 | int snd; | 35 | int snd; |
36 | enum Attribute{ | 36 | enum Attribute{ |
37 | FDescription = 0, | 37 | FDescription = 0, |
38 | FLocation, | 38 | FLocation, |
39 | FCategories, | 39 | FCategories, |
40 | FUid, | 40 | FUid, |
41 | FType, | 41 | FType, |
42 | FAlarm, | 42 | FAlarm, |
43 | FSound, | 43 | FSound, |
44 | FRType, | 44 | FRType, |
45 | FRWeekdays, | 45 | FRWeekdays, |
46 | FRPosition, | 46 | FRPosition, |
47 | FRFreq, | 47 | FRFreq, |
48 | FRHasEndDate, | 48 | FRHasEndDate, |
49 | FREndDate, | 49 | FREndDate, |
50 | FRStart, | 50 | FRStart, |
51 | FREnd, | 51 | FREnd, |
52 | FNote, | 52 | FNote, |
53 | FCreated, | 53 | FCreated, |
54 | FTimeZone, | 54 | FTimeZone, |
55 | FRecParent, | 55 | FRecParent, |
56 | FRecChildren, | 56 | FRecChildren, |
57 | FExceptions | 57 | FExceptions |
58 | }; | 58 | }; |
59 | inline void save( const OEvent& ev, QString& buf ) { | 59 | inline void save( const OEvent& ev, QString& buf ) { |
60 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; | 60 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; |
61 | if (!ev.location().isEmpty() ) | 61 | if (!ev.location().isEmpty() ) |
62 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; | 62 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; |
63 | 63 | ||
64 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 64 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
65 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 65 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
66 | 66 | ||
67 | if (ev.isAllDay() ) | 67 | if (ev.isAllDay() ) |
68 | buf += " type=\"AllDay\""; | 68 | buf += " type=\"AllDay\""; |
69 | 69 | ||
70 | if (ev.hasNotifiers() ) { | 70 | if (ev.hasNotifiers() ) { |
71 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 71 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
72 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 72 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
73 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 73 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
74 | if ( alarm.sound() == OPimAlarm::Loud ) | 74 | if ( alarm.sound() == OPimAlarm::Loud ) |
75 | buf += "loud"; | 75 | buf += "loud"; |
76 | else | 76 | else |
77 | buf += "silent"; | 77 | buf += "silent"; |
78 | buf += "\""; | 78 | buf += "\""; |
79 | } | 79 | } |
80 | if ( ev.hasRecurrence() ) { | 80 | if ( ev.hasRecurrence() ) { |
81 | buf += ev.recurrence().toString(); | 81 | buf += ev.recurrence().toString(); |
82 | } | 82 | } |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * fscking timezones :) well, we'll first convert | 85 | * fscking timezones :) well, we'll first convert |
86 | * the QDateTime to a QDateTime in UTC time | 86 | * the QDateTime to a QDateTime in UTC time |
87 | * and then we'll create a nice time_t | 87 | * and then we'll create a nice time_t |
88 | */ | 88 | */ |
89 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 89 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
90 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; | 90 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; |
91 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; | 91 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; |
92 | if (!ev.note().isEmpty() ) { | 92 | if (!ev.note().isEmpty() ) { |
93 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 93 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
94 | } | 94 | } |
95 | 95 | ||
96 | buf += " timezone=\""; | 96 | buf += " timezone=\""; |
97 | if ( ev.timeZone().isEmpty() ) | 97 | if ( ev.timeZone().isEmpty() ) |
98 | buf += "None"; | 98 | buf += "None"; |
99 | else | 99 | else |
100 | buf += ev.timeZone(); | 100 | buf += ev.timeZone(); |
101 | 101 | ||
102 | if (ev.parent() != 0 ) { | 102 | if (ev.parent() != 0 ) { |
103 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 103 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
104 | } | 104 | } |
105 | 105 | ||
106 | if (ev.children().count() != 0 ) { | 106 | if (ev.children().count() != 0 ) { |
107 | QArray<int> children = ev.children(); | 107 | QArray<int> children = ev.children(); |
108 | buf += " recchildren=\""; | 108 | buf += " recchildren=\""; |
109 | for ( uint i = 0; i < children.count(); i++ ) { | 109 | for ( uint i = 0; i < children.count(); i++ ) { |
110 | if ( i != 0 ) buf += " "; | 110 | if ( i != 0 ) buf += " "; |
111 | buf += QString::number( children[i] ); | 111 | buf += QString::number( children[i] ); |
112 | } | 112 | } |
113 | buf+= "\""; | 113 | buf+= "\""; |
114 | } | 114 | } |
115 | 115 | ||
116 | // skip custom writing | 116 | // skip custom writing |
117 | } | 117 | } |
118 | 118 | ||
119 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { | 119 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { |
120 | QMap<int, OEvent>::ConstIterator it; | 120 | QMap<int, OEvent>::ConstIterator it; |
121 | QString buf; | 121 | QString buf; |
122 | QCString str; | 122 | QCString str; |
123 | int total_written; | 123 | int total_written; |
124 | for ( it = list.begin(); it != list.end(); ++it ) { | 124 | for ( it = list.begin(); it != list.end(); ++it ) { |
125 | buf = "<event"; | 125 | buf = "<event"; |
126 | save( it.data(), buf ); | 126 | save( it.data(), buf ); |
127 | buf += " />\n"; | 127 | buf += " />\n"; |
128 | str = buf.utf8(); | 128 | str = buf.utf8(); |
129 | 129 | ||
130 | total_written = file.writeBlock(str.data(), str.length() ); | 130 | total_written = file.writeBlock(str.data(), str.length() ); |
131 | if ( total_written != int(str.length() ) ) | 131 | if ( total_written != int(str.length() ) ) |
132 | return false; | 132 | return false; |
133 | } | 133 | } |
134 | return true; | 134 | return true; |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 138 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
139 | const QString& fileName ) | 139 | const QString& fileName ) |
140 | : ODateBookAccessBackend() { | 140 | : ODateBookAccessBackend() { |
141 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 141 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
142 | m_changed = false; | 142 | m_changed = false; |
143 | } | 143 | } |
144 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 144 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
145 | } | 145 | } |
146 | bool ODateBookAccessBackend_XML::load() { | 146 | bool ODateBookAccessBackend_XML::load() { |
147 | return loadFile(); | 147 | return loadFile(); |
148 | } | 148 | } |
149 | bool ODateBookAccessBackend_XML::reload() { | 149 | bool ODateBookAccessBackend_XML::reload() { |
150 | clear(); | 150 | clear(); |
151 | return load(); | 151 | return load(); |
152 | } | 152 | } |
153 | bool ODateBookAccessBackend_XML::save() { | 153 | bool ODateBookAccessBackend_XML::save() { |
154 | qWarning("going to save now"); | 154 | if (!m_changed) return true; |
155 | // if (!m_changed) return true; | ||
156 | 155 | ||
157 | int total_written; | 156 | int total_written; |
158 | QString strFileNew = m_name + ".new"; | 157 | QString strFileNew = m_name + ".new"; |
159 | 158 | ||
160 | QFile f( strFileNew ); | 159 | QFile f( strFileNew ); |
161 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 160 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
162 | 161 | ||
163 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 162 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
164 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 163 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
165 | buf += "<events>\n"; | 164 | buf += "<events>\n"; |
166 | QCString str = buf.utf8(); | 165 | QCString str = buf.utf8(); |
167 | total_written = f.writeBlock( str.data(), str.length() ); | 166 | total_written = f.writeBlock( str.data(), str.length() ); |
168 | if ( total_written != int(str.length() ) ) { | 167 | if ( total_written != int(str.length() ) ) { |
169 | f.close(); | 168 | f.close(); |
170 | QFile::remove( strFileNew ); | 169 | QFile::remove( strFileNew ); |
171 | return false; | 170 | return false; |
172 | } | 171 | } |
173 | 172 | ||
174 | if (!forAll( m_raw, f ) ) { | 173 | if (!forAll( m_raw, f ) ) { |
175 | f.close(); | 174 | f.close(); |
176 | QFile::remove( strFileNew ); | 175 | QFile::remove( strFileNew ); |
177 | return false; | 176 | return false; |
178 | } | 177 | } |
179 | if (!forAll( m_rep, f ) ) { | 178 | if (!forAll( m_rep, f ) ) { |
180 | f.close(); | 179 | f.close(); |
181 | QFile::remove( strFileNew ); | 180 | QFile::remove( strFileNew ); |
182 | return false; | 181 | return false; |
183 | } | 182 | } |
184 | 183 | ||
185 | buf = "</events>\n</DATEBOOK>\n"; | 184 | buf = "</events>\n</DATEBOOK>\n"; |
186 | str = buf.utf8(); | 185 | str = buf.utf8(); |
187 | total_written = f.writeBlock( str.data(), str.length() ); | 186 | total_written = f.writeBlock( str.data(), str.length() ); |
188 | if ( total_written != int(str.length() ) ) { | 187 | if ( total_written != int(str.length() ) ) { |
189 | f.close(); | 188 | f.close(); |
190 | QFile::remove( strFileNew ); | 189 | QFile::remove( strFileNew ); |
191 | return false; | 190 | return false; |
192 | } | 191 | } |
193 | f.close(); | 192 | f.close(); |
194 | 193 | ||
195 | exit(0); | ||
196 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 194 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
197 | QFile::remove( strFileNew ); | 195 | QFile::remove( strFileNew ); |
198 | return false; | 196 | return false; |
199 | } | 197 | } |
200 | 198 | ||
201 | m_changed = false; | 199 | m_changed = false; |
202 | return true; | 200 | return true; |
203 | } | 201 | } |
204 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 202 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
205 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 203 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
206 | uint i = 0; | 204 | uint i = 0; |
207 | QMap<int, OEvent>::ConstIterator it; | 205 | QMap<int, OEvent>::ConstIterator it; |
208 | 206 | ||
209 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 207 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
210 | ints[i] = it.key(); | 208 | ints[i] = it.key(); |
211 | i++; | 209 | i++; |
212 | } | 210 | } |
213 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 211 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
214 | ints[i] = it.key(); | 212 | ints[i] = it.key(); |
215 | i++; | 213 | i++; |
216 | } | 214 | } |
217 | 215 | ||
218 | return ints; | 216 | return ints; |
219 | } | 217 | } |
220 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int ) { | 218 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int ) { |
221 | return QArray<int>(); | 219 | return QArray<int>(); |
222 | } | 220 | } |
223 | void ODateBookAccessBackend_XML::clear() { | 221 | void ODateBookAccessBackend_XML::clear() { |
224 | m_raw.clear(); | 222 | m_raw.clear(); |
225 | m_rep.clear(); | 223 | m_rep.clear(); |
226 | } | 224 | } |
227 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 225 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
228 | if ( m_raw.contains( uid ) ) | 226 | if ( m_raw.contains( uid ) ) |
229 | return m_raw[uid]; | 227 | return m_raw[uid]; |
230 | else | 228 | else |
231 | return m_rep[uid]; | 229 | return m_rep[uid]; |
232 | } | 230 | } |
233 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 231 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
234 | m_changed = true; | 232 | m_changed = true; |
235 | if (ev.hasRecurrence() ) | 233 | if (ev.hasRecurrence() ) |
236 | m_rep.insert( ev.uid(), ev ); | 234 | m_rep.insert( ev.uid(), ev ); |
237 | else | 235 | else |
238 | m_raw.insert( ev.uid(), ev ); | 236 | m_raw.insert( ev.uid(), ev ); |
239 | 237 | ||
240 | return true; | 238 | return true; |
241 | } | 239 | } |
242 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 240 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
243 | m_changed = true; | 241 | m_changed = true; |
244 | m_rep.remove( uid ); | 242 | m_rep.remove( uid ); |
245 | m_rep.remove( uid ); | 243 | m_rep.remove( uid ); |
246 | 244 | ||
247 | return true; | 245 | return true; |
248 | } | 246 | } |
249 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 247 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
250 | replace( ev.uid() ); | 248 | replace( ev.uid() ); |
251 | return add( ev ); | 249 | return add( ev ); |
252 | } | 250 | } |
253 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 251 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
254 | return allRecords(); | 252 | return allRecords(); |
255 | } | 253 | } |
256 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 254 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
257 | QArray<int> ints( m_rep.count() ); | 255 | QArray<int> ints( m_rep.count() ); |
258 | uint i = 0; | 256 | uint i = 0; |
259 | QMap<int, OEvent>::ConstIterator it; | 257 | QMap<int, OEvent>::ConstIterator it; |
260 | 258 | ||
261 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 259 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
262 | ints[i] = it.key(); | 260 | ints[i] = it.key(); |
263 | i++; | 261 | i++; |
264 | } | 262 | } |
265 | 263 | ||
266 | return ints; | 264 | return ints; |
267 | } | 265 | } |
268 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 266 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
269 | QArray<int> ints( m_raw.count() ); | 267 | QArray<int> ints( m_raw.count() ); |
270 | uint i = 0; | 268 | uint i = 0; |
271 | QMap<int, OEvent>::ConstIterator it; | 269 | QMap<int, OEvent>::ConstIterator it; |
272 | 270 | ||
273 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 271 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
274 | ints[i] = it.key(); | 272 | ints[i] = it.key(); |
275 | i++; | 273 | i++; |
276 | } | 274 | } |
277 | 275 | ||
278 | return ints; | 276 | return ints; |
279 | } | 277 | } |
280 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 278 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
281 | OEvent::ValueList list; | 279 | OEvent::ValueList list; |
282 | QMap<int, OEvent>::ConstIterator it; | 280 | QMap<int, OEvent>::ConstIterator it; |
283 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 281 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
284 | list.append( it.data() ); | 282 | list.append( it.data() ); |
285 | 283 | ||
286 | return list; | 284 | return list; |
287 | } | 285 | } |
288 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 286 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
289 | OEvent::ValueList list; | 287 | OEvent::ValueList list; |
290 | QMap<int, OEvent>::ConstIterator it; | 288 | QMap<int, OEvent>::ConstIterator it; |
291 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 289 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
292 | list.append( it.data() ); | 290 | list.append( it.data() ); |
293 | 291 | ||
294 | return list; | 292 | return list; |
295 | } | 293 | } |
296 | bool ODateBookAccessBackend_XML::loadFile() { | 294 | bool ODateBookAccessBackend_XML::loadFile() { |
297 | m_changed = false; | 295 | m_changed = false; |
298 | 296 | ||
299 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 297 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
300 | if ( fd < 0 ) return false; | 298 | if ( fd < 0 ) return false; |
301 | 299 | ||
302 | struct stat attribute; | 300 | struct stat attribute; |
303 | if ( ::fstat(fd, &attribute ) == -1 ) { | 301 | if ( ::fstat(fd, &attribute ) == -1 ) { |
304 | ::close( fd ); | 302 | ::close( fd ); |
305 | return false; | 303 | return false; |
306 | } | 304 | } |
307 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 305 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
308 | if ( map_addr == ( (caddr_t)-1) ) { | 306 | if ( map_addr == ( (caddr_t)-1) ) { |
309 | ::close( fd ); | 307 | ::close( fd ); |
310 | return false; | 308 | return false; |
311 | } | 309 | } |
312 | 310 | ||
313 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 311 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
314 | ::close( fd ); | 312 | ::close( fd ); |
315 | 313 | ||
316 | QAsciiDict<int> dict(FExceptions+1); | 314 | QAsciiDict<int> dict(FExceptions+1); |
317 | dict.setAutoDelete( true ); | 315 | dict.setAutoDelete( true ); |
318 | dict.insert( "description", new int(FDescription) ); | 316 | dict.insert( "description", new int(FDescription) ); |
319 | dict.insert( "location", new int(FLocation) ); | 317 | dict.insert( "location", new int(FLocation) ); |
320 | dict.insert( "categories", new int(FCategories) ); | 318 | dict.insert( "categories", new int(FCategories) ); |
321 | dict.insert( "uid", new int(FUid) ); | 319 | dict.insert( "uid", new int(FUid) ); |
322 | dict.insert( "type", new int(FType) ); | 320 | dict.insert( "type", new int(FType) ); |
323 | dict.insert( "alarm", new int(FAlarm) ); | 321 | dict.insert( "alarm", new int(FAlarm) ); |
324 | dict.insert( "sound", new int(FSound) ); | 322 | dict.insert( "sound", new int(FSound) ); |
325 | dict.insert( "rtype", new int(FRType) ); | 323 | dict.insert( "rtype", new int(FRType) ); |
326 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 324 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
327 | dict.insert( "rposition", new int(FRPosition) ); | 325 | dict.insert( "rposition", new int(FRPosition) ); |
328 | dict.insert( "rfreq", new int(FRFreq) ); | 326 | dict.insert( "rfreq", new int(FRFreq) ); |
329 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 327 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
330 | dict.insert( "enddt", new int(FREndDate) ); | 328 | dict.insert( "enddt", new int(FREndDate) ); |
331 | dict.insert( "start", new int(FRStart) ); | 329 | dict.insert( "start", new int(FRStart) ); |
332 | dict.insert( "end", new int(FREnd) ); | 330 | dict.insert( "end", new int(FREnd) ); |
333 | dict.insert( "note", new int(FNote) ); | 331 | dict.insert( "note", new int(FNote) ); |
334 | dict.insert( "created", new int(FCreated) ); | 332 | dict.insert( "created", new int(FCreated) ); |
335 | dict.insert( "recparent", new int(FRecParent) ); | 333 | dict.insert( "recparent", new int(FRecParent) ); |
336 | dict.insert( "recchildren", new int(FRecChildren) ); | 334 | dict.insert( "recchildren", new int(FRecChildren) ); |
337 | dict.insert( "exceptions", new int(FExceptions) ); | 335 | dict.insert( "exceptions", new int(FExceptions) ); |
338 | dict.insert( "timezone", new int(FTimeZone) ); | 336 | dict.insert( "timezone", new int(FTimeZone) ); |
339 | 337 | ||
340 | char* dt = (char*)map_addr; | 338 | char* dt = (char*)map_addr; |
341 | int len = attribute.st_size; | 339 | int len = attribute.st_size; |
342 | int i = 0; | 340 | int i = 0; |
343 | char* point; | 341 | char* point; |
344 | const char* collectionString = "<event "; | 342 | const char* collectionString = "<event "; |
345 | int strLen = ::strlen(collectionString); | 343 | int strLen = ::strlen(collectionString); |
346 | int *find; | 344 | int *find; |
347 | while ( dt + 1 != 0 && (( point = ::strstr( dt+i, collectionString ) ) != 0 ) ) { | 345 | while ( dt + 1 != 0 && (( point = ::strstr( dt+i, collectionString ) ) != 0 ) ) { |
348 | i = point -dt; | 346 | i = point -dt; |
349 | i+= strLen; | 347 | i+= strLen; |
350 | 348 | ||
351 | alarmTime = -1; | 349 | alarmTime = -1; |
352 | snd = 0; // silent | 350 | snd = 0; // silent |
353 | 351 | ||
354 | OEvent ev; | 352 | OEvent ev; |
355 | rec = 0; | 353 | rec = 0; |
356 | 354 | ||
357 | while ( TRUE ) { | 355 | while ( TRUE ) { |
358 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 356 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
359 | ++i; | 357 | ++i; |
360 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 358 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
361 | break; | 359 | break; |
362 | 360 | ||
363 | 361 | ||
364 | // we have another attribute, read it. | 362 | // we have another attribute, read it. |
365 | int j = i; | 363 | int j = i; |
366 | while ( j < len && dt[j] != '=' ) | 364 | while ( j < len && dt[j] != '=' ) |
367 | ++j; | 365 | ++j; |
368 | QCString attr( dt+i, j-i+1); | 366 | QCString attr( dt+i, j-i+1); |
369 | 367 | ||
370 | i = ++j; // skip = | 368 | i = ++j; // skip = |
371 | 369 | ||
372 | // find the start of quotes | 370 | // find the start of quotes |
373 | while ( i < len && dt[i] != '"' ) | 371 | while ( i < len && dt[i] != '"' ) |
374 | ++i; | 372 | ++i; |
375 | j = ++i; | 373 | j = ++i; |
376 | 374 | ||
377 | bool haveUtf = FALSE; | 375 | bool haveUtf = FALSE; |
378 | bool haveEnt = FALSE; | 376 | bool haveEnt = FALSE; |
379 | while ( j < len && dt[j] != '"' ) { | 377 | while ( j < len && dt[j] != '"' ) { |
380 | if ( ((unsigned char)dt[j]) > 0x7f ) | 378 | if ( ((unsigned char)dt[j]) > 0x7f ) |
381 | haveUtf = TRUE; | 379 | haveUtf = TRUE; |
382 | if ( dt[j] == '&' ) | 380 | if ( dt[j] == '&' ) |
383 | haveEnt = TRUE; | 381 | haveEnt = TRUE; |
384 | ++j; | 382 | ++j; |
385 | } | 383 | } |
386 | if ( i == j ) { | 384 | if ( i == j ) { |
387 | // empty value | 385 | // empty value |
388 | i = j + 1; | 386 | i = j + 1; |
389 | continue; | 387 | continue; |
390 | } | 388 | } |
391 | 389 | ||
392 | QCString value( dt+i, j-i+1 ); | 390 | QCString value( dt+i, j-i+1 ); |
393 | i = j + 1; | 391 | i = j + 1; |
394 | 392 | ||
395 | QString str = (haveUtf ? QString::fromUtf8( value ) | 393 | QString str = (haveUtf ? QString::fromUtf8( value ) |
396 | : QString::fromLatin1( value ) ); | 394 | : QString::fromLatin1( value ) ); |
397 | if ( haveEnt ) | 395 | if ( haveEnt ) |
398 | str = Qtopia::plainString( str ); | 396 | str = Qtopia::plainString( str ); |
399 | 397 | ||
400 | /* | 398 | /* |
401 | * add key + value | 399 | * add key + value |
402 | */ | 400 | */ |
403 | find = dict[attr.data()]; | 401 | find = dict[attr.data()]; |
404 | if (!find) | 402 | if (!find) |
405 | ev.setCustomField( attr, value ); | 403 | ev.setCustomField( attr, value ); |
406 | else { | 404 | else { |
407 | setField( ev, *find, value ); | 405 | setField( ev, *find, value ); |
408 | } | 406 | } |
409 | } | 407 | } |
410 | /* time to finalize */ | 408 | /* time to finalize */ |
411 | finalizeRecord( ev ); | 409 | finalizeRecord( ev ); |
412 | add( ev ); | 410 | add( ev ); |
413 | delete rec; | 411 | delete rec; |
414 | } | 412 | } |
415 | ::munmap(map_addr, attribute.st_size ); | 413 | ::munmap(map_addr, attribute.st_size ); |
416 | m_changed = false; // changed during add | 414 | m_changed = false; // changed during add |
417 | 415 | ||
418 | return true; | 416 | return true; |
419 | } | 417 | } |
420 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 418 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
421 | /* AllDay is alway in UTC */ | 419 | /* AllDay is alway in UTC */ |
422 | if ( ev.isAllDay() ) { | 420 | if ( ev.isAllDay() ) { |
423 | OTimeZone utc = OTimeZone::utc(); | 421 | OTimeZone utc = OTimeZone::utc(); |
424 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 422 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
425 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 423 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
426 | ev.setTimeZone( "UTC"); // make sure it is really utc | 424 | ev.setTimeZone( "UTC"); // make sure it is really utc |
427 | }else { | 425 | }else { |
428 | /* to current date time */ | 426 | /* to current date time */ |
429 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 427 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
430 | QDateTime date = zone.toDateTime( start ); | 428 | QDateTime date = zone.toDateTime( start ); |
431 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | 429 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); |
432 | 430 | ||
433 | date = zone.toDateTime( end ); | 431 | date = zone.toDateTime( end ); |
434 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | 432 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); |
435 | } | 433 | } |
436 | if ( rec && rec->doesRecur() ) { | 434 | if ( rec && rec->doesRecur() ) { |
437 | OTimeZone utc = OTimeZone::utc(); | 435 | OTimeZone utc = OTimeZone::utc(); |
438 | ORecur recu( *rec ); // call copy c'tor; | 436 | ORecur recu( *rec ); // call copy c'tor; |
439 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 437 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
440 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 438 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
441 | recu.setStart( ev.startDateTime().date() ); | 439 | recu.setStart( ev.startDateTime().date() ); |
442 | ev.setRecurrence( recu ); | 440 | ev.setRecurrence( recu ); |
443 | } | 441 | } |
444 | 442 | ||
445 | if (alarmTime != -1 ) { | 443 | if (alarmTime != -1 ) { |
446 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 444 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
447 | OPimAlarm al( snd , dt ); | 445 | OPimAlarm al( snd , dt ); |
448 | ev.notifiers().add( al ); | 446 | ev.notifiers().add( al ); |
449 | } | 447 | } |
450 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { | 448 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { |
451 | ev.setUid( 1 ); | 449 | ev.setUid( 1 ); |
452 | } | 450 | } |
453 | if ( ev.hasRecurrence() ) | 451 | if ( ev.hasRecurrence() ) |
454 | m_rep.insert( ev.uid(), ev ); | 452 | m_rep.insert( ev.uid(), ev ); |
455 | else | 453 | else |
456 | m_raw.insert( ev.uid(), ev ); | 454 | m_raw.insert( ev.uid(), ev ); |
457 | 455 | ||
458 | } | 456 | } |
459 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { | 457 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { |
460 | // qWarning(" setting %s", value.latin1() ); | 458 | // qWarning(" setting %s", value.latin1() ); |
461 | switch( id ) { | 459 | switch( id ) { |
462 | case FDescription: | 460 | case FDescription: |
463 | e.setDescription( value ); | 461 | e.setDescription( value ); |
464 | break; | 462 | break; |
465 | case FLocation: | 463 | case FLocation: |
466 | e.setLocation( value ); | 464 | e.setLocation( value ); |
467 | break; | 465 | break; |
468 | case FCategories: | 466 | case FCategories: |
469 | e.setCategories( e.idsFromString( value ) ); | 467 | e.setCategories( e.idsFromString( value ) ); |
470 | break; | 468 | break; |
471 | case FUid: | 469 | case FUid: |
472 | e.setUid( value.toInt() ); | 470 | e.setUid( value.toInt() ); |
473 | break; | 471 | break; |
474 | case FType: | 472 | case FType: |
475 | if ( value == "AllDay" ) { | 473 | if ( value == "AllDay" ) { |
476 | e.setAllDay( true ); | 474 | e.setAllDay( true ); |
477 | e.setTimeZone( "UTC" ); | 475 | e.setTimeZone( "UTC" ); |
478 | } | 476 | } |
479 | break; | 477 | break; |
480 | case FAlarm: | 478 | case FAlarm: |
481 | alarmTime = value.toInt(); | 479 | alarmTime = value.toInt(); |
482 | break; | 480 | break; |
483 | case FSound: | 481 | case FSound: |
484 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; | 482 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; |
485 | break; | 483 | break; |
486 | // recurrence stuff | 484 | // recurrence stuff |
487 | case FRType: | 485 | case FRType: |
488 | if ( value == "Daily" ) | 486 | if ( value == "Daily" ) |
489 | recur()->setType( ORecur::Daily ); | 487 | recur()->setType( ORecur::Daily ); |
490 | else if ( value == "Weekly" ) | 488 | else if ( value == "Weekly" ) |
491 | recur()->setType( ORecur::Weekly); | 489 | recur()->setType( ORecur::Weekly); |
492 | else if ( value == "MonthlyDay" ) | 490 | else if ( value == "MonthlyDay" ) |
493 | recur()->setType( ORecur::MonthlyDay ); | 491 | recur()->setType( ORecur::MonthlyDay ); |
494 | else if ( value == "MonthlyDate" ) | 492 | else if ( value == "MonthlyDate" ) |
495 | recur()->setType( ORecur::MonthlyDate ); | 493 | recur()->setType( ORecur::MonthlyDate ); |
496 | else if ( value == "Yearly" ) | 494 | else if ( value == "Yearly" ) |
497 | recur()->setType( ORecur::Yearly ); | 495 | recur()->setType( ORecur::Yearly ); |
498 | else | 496 | else |
499 | recur()->setType( ORecur::NoRepeat ); | 497 | recur()->setType( ORecur::NoRepeat ); |
500 | break; | 498 | break; |
501 | case FRWeekdays: | 499 | case FRWeekdays: |
502 | recur()->setDays( value.toInt() ); | 500 | recur()->setDays( value.toInt() ); |
503 | break; | 501 | break; |
504 | case FRPosition: | 502 | case FRPosition: |
505 | recur()->setPosition( value.toInt() ); | 503 | recur()->setPosition( value.toInt() ); |
506 | break; | 504 | break; |
507 | case FRFreq: | 505 | case FRFreq: |
508 | recur()->setFrequency( value.toInt() ); | 506 | recur()->setFrequency( value.toInt() ); |
509 | break; | 507 | break; |
510 | case FRHasEndDate: | 508 | case FRHasEndDate: |
511 | recur()->setHasEndDate( value.toInt() ); | 509 | recur()->setHasEndDate( value.toInt() ); |
512 | break; | 510 | break; |
513 | case FREndDate: { | 511 | case FREndDate: { |
514 | rp_end = (time_t) value.toLong(); | 512 | rp_end = (time_t) value.toLong(); |
515 | break; | 513 | break; |
516 | } | 514 | } |
517 | case FRStart: { | 515 | case FRStart: { |
518 | start = (time_t) value.toLong(); | 516 | start = (time_t) value.toLong(); |
519 | break; | 517 | break; |
520 | } | 518 | } |
521 | case FREnd: { | 519 | case FREnd: { |
522 | end = ( (time_t) value.toLong() ); | 520 | end = ( (time_t) value.toLong() ); |
523 | break; | 521 | break; |
524 | } | 522 | } |
525 | case FNote: | 523 | case FNote: |
526 | e.setNote( value ); | 524 | e.setNote( value ); |
527 | break; | 525 | break; |
528 | case FCreated: | 526 | case FCreated: |
529 | created = value.toInt(); | 527 | created = value.toInt(); |
530 | break; | 528 | break; |
531 | case FRecParent: | 529 | case FRecParent: |
532 | e.setParent( value.toInt() ); | 530 | e.setParent( value.toInt() ); |
533 | break; | 531 | break; |
534 | case FRecChildren:{ | 532 | case FRecChildren:{ |
535 | QStringList list = QStringList::split(' ', value ); | 533 | QStringList list = QStringList::split(' ', value ); |
536 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 534 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
537 | e.addChild( (*it).toInt() ); | 535 | e.addChild( (*it).toInt() ); |
538 | } | 536 | } |
539 | } | 537 | } |
540 | break; | 538 | break; |
541 | case FExceptions:{ | 539 | case FExceptions:{ |
542 | QStringList list = QStringList::split(' ', value ); | 540 | QStringList list = QStringList::split(' ', value ); |
543 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 541 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
544 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); | 542 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); |
545 | qWarning("adding exception %s", date.toString().latin1() ); | 543 | qWarning("adding exception %s", date.toString().latin1() ); |
546 | recur()->exceptions().append( date ); | 544 | recur()->exceptions().append( date ); |
547 | } | 545 | } |
548 | } | 546 | } |
549 | break; | 547 | break; |
550 | case FTimeZone: | 548 | case FTimeZone: |
551 | if ( value != "None" ) | 549 | if ( value != "None" ) |
552 | e.setTimeZone( value ); | 550 | e.setTimeZone( value ); |
553 | break; | 551 | break; |
554 | default: | 552 | default: |
555 | break; | 553 | break; |
556 | } | 554 | } |
557 | } | 555 | } |