-rw-r--r-- | libopie/pim/odatebookaccessbackend_xml.cpp | 1 | ||||
-rw-r--r-- | libopie/pim/oevent.cpp | 2 | ||||
-rw-r--r-- | libopie/pim/otodo.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiepim/oevent.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.cpp | 2 |
6 files changed, 6 insertions, 4 deletions
diff --git a/libopie/pim/odatebookaccessbackend_xml.cpp b/libopie/pim/odatebookaccessbackend_xml.cpp index 11e19d9..a0ae7b7 100644 --- a/libopie/pim/odatebookaccessbackend_xml.cpp +++ b/libopie/pim/odatebookaccessbackend_xml.cpp | |||
@@ -123,256 +123,257 @@ namespace { | |||
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_raw.clear(); | 252 | m_raw.clear(); |
252 | m_rep.clear(); | 253 | m_rep.clear(); |
253 | } | 254 | } |
254 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
255 | if ( m_raw.contains( uid ) ) | 256 | if ( m_raw.contains( uid ) ) |
256 | return m_raw[uid]; | 257 | return m_raw[uid]; |
257 | else | 258 | else |
258 | return m_rep[uid]; | 259 | return m_rep[uid]; |
259 | } | 260 | } |
260 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
261 | m_changed = true; | 262 | m_changed = true; |
262 | if (ev.hasRecurrence() ) | 263 | if (ev.hasRecurrence() ) |
263 | m_rep.insert( ev.uid(), ev ); | 264 | m_rep.insert( ev.uid(), ev ); |
264 | else | 265 | else |
265 | m_raw.insert( ev.uid(), ev ); | 266 | m_raw.insert( ev.uid(), ev ); |
266 | 267 | ||
267 | return true; | 268 | return true; |
268 | } | 269 | } |
269 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 270 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
270 | m_changed = true; | 271 | m_changed = true; |
271 | m_rep.remove( uid ); | 272 | m_rep.remove( uid ); |
272 | m_rep.remove( uid ); | 273 | m_rep.remove( uid ); |
273 | 274 | ||
274 | return true; | 275 | return true; |
275 | } | 276 | } |
276 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
277 | replace( ev.uid() ); | 278 | replace( ev.uid() ); |
278 | return add( ev ); | 279 | return add( ev ); |
279 | } | 280 | } |
280 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
281 | return allRecords(); | 282 | return allRecords(); |
282 | } | 283 | } |
283 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
284 | QArray<int> ints( m_rep.count() ); | 285 | QArray<int> ints( m_rep.count() ); |
285 | uint i = 0; | 286 | uint i = 0; |
286 | QMap<int, OEvent>::ConstIterator it; | 287 | QMap<int, OEvent>::ConstIterator it; |
287 | 288 | ||
288 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
289 | ints[i] = it.key(); | 290 | ints[i] = it.key(); |
290 | i++; | 291 | i++; |
291 | } | 292 | } |
292 | 293 | ||
293 | return ints; | 294 | return ints; |
294 | } | 295 | } |
295 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
296 | QArray<int> ints( m_raw.count() ); | 297 | QArray<int> ints( m_raw.count() ); |
297 | uint i = 0; | 298 | uint i = 0; |
298 | QMap<int, OEvent>::ConstIterator it; | 299 | QMap<int, OEvent>::ConstIterator it; |
299 | 300 | ||
300 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
301 | ints[i] = it.key(); | 302 | ints[i] = it.key(); |
302 | i++; | 303 | i++; |
303 | } | 304 | } |
304 | 305 | ||
305 | return ints; | 306 | return ints; |
306 | } | 307 | } |
307 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
308 | OEvent::ValueList list; | 309 | OEvent::ValueList list; |
309 | QMap<int, OEvent>::ConstIterator it; | 310 | QMap<int, OEvent>::ConstIterator it; |
310 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
311 | list.append( it.data() ); | 312 | list.append( it.data() ); |
312 | 313 | ||
313 | return list; | 314 | return list; |
314 | } | 315 | } |
315 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
316 | OEvent::ValueList list; | 317 | OEvent::ValueList list; |
317 | QMap<int, OEvent>::ConstIterator it; | 318 | QMap<int, OEvent>::ConstIterator it; |
318 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
319 | list.append( it.data() ); | 320 | list.append( it.data() ); |
320 | 321 | ||
321 | return list; | 322 | return list; |
322 | } | 323 | } |
323 | bool ODateBookAccessBackend_XML::loadFile() { | 324 | bool ODateBookAccessBackend_XML::loadFile() { |
324 | m_changed = false; | 325 | m_changed = false; |
325 | 326 | ||
326 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
327 | if ( fd < 0 ) return false; | 328 | if ( fd < 0 ) return false; |
328 | 329 | ||
329 | struct stat attribute; | 330 | struct stat attribute; |
330 | if ( ::fstat(fd, &attribute ) == -1 ) { | 331 | if ( ::fstat(fd, &attribute ) == -1 ) { |
331 | ::close( fd ); | 332 | ::close( fd ); |
332 | return false; | 333 | return false; |
333 | } | 334 | } |
334 | 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 ); |
335 | if ( map_addr == ( (caddr_t)-1) ) { | 336 | if ( map_addr == ( (caddr_t)-1) ) { |
336 | ::close( fd ); | 337 | ::close( fd ); |
337 | return false; | 338 | return false; |
338 | } | 339 | } |
339 | 340 | ||
340 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
341 | ::close( fd ); | 342 | ::close( fd ); |
342 | 343 | ||
343 | QAsciiDict<int> dict(FExceptions+1); | 344 | QAsciiDict<int> dict(FExceptions+1); |
344 | dict.setAutoDelete( true ); | 345 | dict.setAutoDelete( true ); |
345 | dict.insert( "description", new int(FDescription) ); | 346 | dict.insert( "description", new int(FDescription) ); |
346 | dict.insert( "location", new int(FLocation) ); | 347 | dict.insert( "location", new int(FLocation) ); |
347 | dict.insert( "categories", new int(FCategories) ); | 348 | dict.insert( "categories", new int(FCategories) ); |
348 | dict.insert( "uid", new int(FUid) ); | 349 | dict.insert( "uid", new int(FUid) ); |
349 | dict.insert( "type", new int(FType) ); | 350 | dict.insert( "type", new int(FType) ); |
350 | dict.insert( "alarm", new int(FAlarm) ); | 351 | dict.insert( "alarm", new int(FAlarm) ); |
351 | dict.insert( "sound", new int(FSound) ); | 352 | dict.insert( "sound", new int(FSound) ); |
352 | dict.insert( "rtype", new int(FRType) ); | 353 | dict.insert( "rtype", new int(FRType) ); |
353 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 354 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
354 | dict.insert( "rposition", new int(FRPosition) ); | 355 | dict.insert( "rposition", new int(FRPosition) ); |
355 | dict.insert( "rfreq", new int(FRFreq) ); | 356 | dict.insert( "rfreq", new int(FRFreq) ); |
356 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
357 | dict.insert( "enddt", new int(FREndDate) ); | 358 | dict.insert( "enddt", new int(FREndDate) ); |
358 | dict.insert( "start", new int(FRStart) ); | 359 | dict.insert( "start", new int(FRStart) ); |
359 | dict.insert( "end", new int(FREnd) ); | 360 | dict.insert( "end", new int(FREnd) ); |
360 | dict.insert( "note", new int(FNote) ); | 361 | dict.insert( "note", new int(FNote) ); |
361 | dict.insert( "created", new int(FCreated) ); | 362 | dict.insert( "created", new int(FCreated) ); |
362 | dict.insert( "recparent", new int(FRecParent) ); | 363 | dict.insert( "recparent", new int(FRecParent) ); |
363 | dict.insert( "recchildren", new int(FRecChildren) ); | 364 | dict.insert( "recchildren", new int(FRecChildren) ); |
364 | dict.insert( "exceptions", new int(FExceptions) ); | 365 | dict.insert( "exceptions", new int(FExceptions) ); |
365 | dict.insert( "timezone", new int(FTimeZone) ); | 366 | dict.insert( "timezone", new int(FTimeZone) ); |
366 | 367 | ||
367 | char* dt = (char*)map_addr; | 368 | char* dt = (char*)map_addr; |
368 | int len = attribute.st_size; | 369 | int len = attribute.st_size; |
369 | int i = 0; | 370 | int i = 0; |
370 | char* point; | 371 | char* point; |
371 | const char* collectionString = "<event "; | 372 | const char* collectionString = "<event "; |
372 | int strLen = ::strlen(collectionString); | 373 | int strLen = ::strlen(collectionString); |
373 | int *find; | 374 | int *find; |
374 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { | 375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { |
375 | i = point -dt; | 376 | i = point -dt; |
376 | i+= strLen; | 377 | i+= strLen; |
377 | 378 | ||
378 | alarmTime = -1; | 379 | alarmTime = -1; |
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp index c3eeee2..56ea10d 100644 --- a/libopie/pim/oevent.cpp +++ b/libopie/pim/oevent.cpp | |||
@@ -1,213 +1,213 @@ | |||
1 | #include <qshared.h> | 1 | #include <qshared.h> |
2 | 2 | ||
3 | #include <qpe/palmtopuidgen.h> | 3 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/categories.h> | 4 | #include <qpe/categories.h> |
5 | 5 | ||
6 | #include "orecur.h" | 6 | #include "orecur.h" |
7 | #include "opimresolver.h" | 7 | #include "opimresolver.h" |
8 | #include "opimnotifymanager.h" | 8 | #include "opimnotifymanager.h" |
9 | 9 | ||
10 | #include "oevent.h" | 10 | #include "oevent.h" |
11 | 11 | ||
12 | int OCalendarHelper::week( const QDate& date) { | 12 | int OCalendarHelper::week( const QDate& date) { |
13 | // Calculates the week this date is in within that | 13 | // Calculates the week this date is in within that |
14 | // month. Equals the "row" is is in in the month view | 14 | // month. Equals the "row" is is in in the month view |
15 | int week = 1; | 15 | int week = 1; |
16 | QDate tmp( date.year(), date.month(), 1 ); | 16 | QDate tmp( date.year(), date.month(), 1 ); |
17 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) | 17 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) |
18 | ++week; | 18 | ++week; |
19 | 19 | ||
20 | week += ( date.day() - 1 ) / 7; | 20 | week += ( date.day() - 1 ) / 7; |
21 | 21 | ||
22 | return week; | 22 | return week; |
23 | } | 23 | } |
24 | int OCalendarHelper::ocurrence( const QDate& date) { | 24 | int OCalendarHelper::ocurrence( const QDate& date) { |
25 | // calculates the number of occurrances of this day of the | 25 | // calculates the number of occurrances of this day of the |
26 | // week till the given date (e.g 3rd Wednesday of the month) | 26 | // week till the given date (e.g 3rd Wednesday of the month) |
27 | return ( date.day() - 1 ) / 7 + 1; | 27 | return ( date.day() - 1 ) / 7 + 1; |
28 | } | 28 | } |
29 | int OCalendarHelper::dayOfWeek( char day ) { | 29 | int OCalendarHelper::dayOfWeek( char day ) { |
30 | int dayOfWeek = 1; | 30 | int dayOfWeek = 1; |
31 | char i = ORecur::MON; | 31 | char i = ORecur::MON; |
32 | while ( !( i & day ) && i <= ORecur::SUN ) { | 32 | while ( !( i & day ) && i <= ORecur::SUN ) { |
33 | i <<= 1; | 33 | i <<= 1; |
34 | ++dayOfWeek; | 34 | ++dayOfWeek; |
35 | } | 35 | } |
36 | return dayOfWeek; | 36 | return dayOfWeek; |
37 | } | 37 | } |
38 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { | 38 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { |
39 | return ( second.year() - first.year() ) * 12 + | 39 | return ( second.year() - first.year() ) * 12 + |
40 | second.month() - first.month(); | 40 | second.month() - first.month(); |
41 | } | 41 | } |
42 | 42 | ||
43 | struct OEvent::Data : public QShared { | 43 | struct OEvent::Data : public QShared { |
44 | Data() : QShared() { | 44 | Data() : QShared() { |
45 | child = 0; | 45 | child = 0; |
46 | recur = 0; | 46 | recur = 0; |
47 | manager = 0; | 47 | manager = 0; |
48 | isAllDay = false; | 48 | isAllDay = false; |
49 | parent = 0; | 49 | parent = 0; |
50 | } | 50 | } |
51 | ~Data() { | 51 | ~Data() { |
52 | delete manager; | 52 | delete manager; |
53 | delete recur; | 53 | delete recur; |
54 | } | 54 | } |
55 | QString description; | 55 | QString description; |
56 | QString location; | 56 | QString location; |
57 | OPimNotifyManager* manager; | 57 | OPimNotifyManager* manager; |
58 | ORecur* recur; | 58 | ORecur* recur; |
59 | QString note; | 59 | QString note; |
60 | QDateTime created; | 60 | QDateTime created; |
61 | QDateTime start; | 61 | QDateTime start; |
62 | QDateTime end; | 62 | QDateTime end; |
63 | bool isAllDay : 1; | 63 | bool isAllDay : 1; |
64 | QString timezone; | 64 | QString timezone; |
65 | QArray<int>* child; | 65 | QArray<int>* child; |
66 | int parent; | 66 | int parent; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | OEvent::OEvent( int uid ) | 69 | OEvent::OEvent( int uid ) |
70 | : OPimRecord( uid ) { | 70 | : OPimRecord( uid ) { |
71 | data = new Data; | 71 | data = new Data; |
72 | } | 72 | } |
73 | OEvent::OEvent( const OEvent& ev) | 73 | OEvent::OEvent( const OEvent& ev) |
74 | : OPimRecord( ev ), data( ev.data ) | 74 | : OPimRecord( ev ), data( ev.data ) |
75 | { | 75 | { |
76 | data->ref(); | 76 | data->ref(); |
77 | } | 77 | } |
78 | OEvent::~OEvent() { | 78 | OEvent::~OEvent() { |
79 | if ( data->deref() ) { | 79 | if ( data->deref() ) { |
80 | delete data; | 80 | delete data; |
81 | data = 0; | 81 | data = 0; |
82 | } | 82 | } |
83 | } | 83 | } |
84 | OEvent& OEvent::operator=( const OEvent& ev) { | 84 | OEvent& OEvent::operator=( const OEvent& ev) { |
85 | if ( *this == ev ) return *this; | 85 | if ( this == &ev ) return *this; |
86 | 86 | ||
87 | OPimRecord::operator=( ev ); | 87 | OPimRecord::operator=( ev ); |
88 | ev.data->ref(); | 88 | ev.data->ref(); |
89 | deref(); | 89 | deref(); |
90 | data = ev.data; | 90 | data = ev.data; |
91 | 91 | ||
92 | 92 | ||
93 | return *this; | 93 | return *this; |
94 | } | 94 | } |
95 | QString OEvent::description()const { | 95 | QString OEvent::description()const { |
96 | return data->description; | 96 | return data->description; |
97 | } | 97 | } |
98 | void OEvent::setDescription( const QString& description ) { | 98 | void OEvent::setDescription( const QString& description ) { |
99 | changeOrModify(); | 99 | changeOrModify(); |
100 | data->description = description; | 100 | data->description = description; |
101 | } | 101 | } |
102 | void OEvent::setLocation( const QString& loc ) { | 102 | void OEvent::setLocation( const QString& loc ) { |
103 | changeOrModify(); | 103 | changeOrModify(); |
104 | data->location = loc; | 104 | data->location = loc; |
105 | } | 105 | } |
106 | QString OEvent::location()const { | 106 | QString OEvent::location()const { |
107 | return data->location; | 107 | return data->location; |
108 | } | 108 | } |
109 | OPimNotifyManager &OEvent::notifiers()const { | 109 | OPimNotifyManager &OEvent::notifiers()const { |
110 | // I hope we can skip the changeOrModify here | 110 | // I hope we can skip the changeOrModify here |
111 | // the notifier should take care of it | 111 | // the notifier should take care of it |
112 | // and OPimNotify is shared too | 112 | // and OPimNotify is shared too |
113 | if (!data->manager ) | 113 | if (!data->manager ) |
114 | data->manager = new OPimNotifyManager; | 114 | data->manager = new OPimNotifyManager; |
115 | 115 | ||
116 | return *data->manager; | 116 | return *data->manager; |
117 | } | 117 | } |
118 | bool OEvent::hasNotifiers()const { | 118 | bool OEvent::hasNotifiers()const { |
119 | if (!data->manager ) | 119 | if (!data->manager ) |
120 | return false; | 120 | return false; |
121 | if (data->manager->reminders().isEmpty() && | 121 | if (data->manager->reminders().isEmpty() && |
122 | data->manager->alarms().isEmpty() ) | 122 | data->manager->alarms().isEmpty() ) |
123 | return false; | 123 | return false; |
124 | 124 | ||
125 | return true; | 125 | return true; |
126 | } | 126 | } |
127 | ORecur OEvent::recurrence()const { | 127 | ORecur OEvent::recurrence()const { |
128 | if (!data->recur) | 128 | if (!data->recur) |
129 | data->recur = new ORecur; | 129 | data->recur = new ORecur; |
130 | 130 | ||
131 | return *data->recur; | 131 | return *data->recur; |
132 | } | 132 | } |
133 | void OEvent::setRecurrence( const ORecur& rec) { | 133 | void OEvent::setRecurrence( const ORecur& rec) { |
134 | changeOrModify(); | 134 | changeOrModify(); |
135 | if (data->recur ) | 135 | if (data->recur ) |
136 | (*data->recur) = rec; | 136 | (*data->recur) = rec; |
137 | else | 137 | else |
138 | data->recur = new ORecur( rec ); | 138 | data->recur = new ORecur( rec ); |
139 | } | 139 | } |
140 | bool OEvent::hasRecurrence()const { | 140 | bool OEvent::hasRecurrence()const { |
141 | if (!data->recur ) return false; | 141 | if (!data->recur ) return false; |
142 | return data->recur->doesRecur(); | 142 | return data->recur->doesRecur(); |
143 | } | 143 | } |
144 | QString OEvent::note()const { | 144 | QString OEvent::note()const { |
145 | return data->note; | 145 | return data->note; |
146 | } | 146 | } |
147 | void OEvent::setNote( const QString& note ) { | 147 | void OEvent::setNote( const QString& note ) { |
148 | changeOrModify(); | 148 | changeOrModify(); |
149 | data->note = note; | 149 | data->note = note; |
150 | } | 150 | } |
151 | QDateTime OEvent::createdDateTime()const { | 151 | QDateTime OEvent::createdDateTime()const { |
152 | return data->created; | 152 | return data->created; |
153 | } | 153 | } |
154 | void OEvent::setCreatedDateTime( const QDateTime& time ) { | 154 | void OEvent::setCreatedDateTime( const QDateTime& time ) { |
155 | changeOrModify(); | 155 | changeOrModify(); |
156 | data->created = time; | 156 | data->created = time; |
157 | } | 157 | } |
158 | QDateTime OEvent::startDateTime()const { | 158 | QDateTime OEvent::startDateTime()const { |
159 | if ( data->isAllDay ) | 159 | if ( data->isAllDay ) |
160 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); | 160 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); |
161 | return data->start; | 161 | return data->start; |
162 | } | 162 | } |
163 | QDateTime OEvent::startDateTimeInZone()const { | 163 | QDateTime OEvent::startDateTimeInZone()const { |
164 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 164 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
165 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); | 165 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); |
166 | 166 | ||
167 | OTimeZone zone(data->timezone ); | 167 | OTimeZone zone(data->timezone ); |
168 | return zone.toDateTime( data->start, OTimeZone::current() ); | 168 | return zone.toDateTime( data->start, OTimeZone::current() ); |
169 | } | 169 | } |
170 | void OEvent::setStartDateTime( const QDateTime& dt ) { | 170 | void OEvent::setStartDateTime( const QDateTime& dt ) { |
171 | changeOrModify(); | 171 | changeOrModify(); |
172 | data->start = dt; | 172 | data->start = dt; |
173 | } | 173 | } |
174 | QDateTime OEvent::endDateTime()const { | 174 | QDateTime OEvent::endDateTime()const { |
175 | /* | 175 | /* |
176 | * if all Day event the end time needs | 176 | * if all Day event the end time needs |
177 | * to be on the same day as the start | 177 | * to be on the same day as the start |
178 | */ | 178 | */ |
179 | if ( data->isAllDay ) | 179 | if ( data->isAllDay ) |
180 | return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); | 180 | return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); |
181 | return data->end; | 181 | return data->end; |
182 | } | 182 | } |
183 | QDateTime OEvent::endDateTimeInZone()const { | 183 | QDateTime OEvent::endDateTimeInZone()const { |
184 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 184 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
185 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); | 185 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); |
186 | 186 | ||
187 | OTimeZone zone(data->timezone ); | 187 | OTimeZone zone(data->timezone ); |
188 | return zone.toDateTime( data->end, OTimeZone::current() ); | 188 | return zone.toDateTime( data->end, OTimeZone::current() ); |
189 | } | 189 | } |
190 | void OEvent::setEndDateTime( const QDateTime& dt ) { | 190 | void OEvent::setEndDateTime( const QDateTime& dt ) { |
191 | changeOrModify(); | 191 | changeOrModify(); |
192 | data->end = dt; | 192 | data->end = dt; |
193 | } | 193 | } |
194 | bool OEvent::isMultipleDay()const { | 194 | bool OEvent::isMultipleDay()const { |
195 | return data->end.date().day() - data->start.date().day(); | 195 | return data->end.date().day() - data->start.date().day(); |
196 | } | 196 | } |
197 | bool OEvent::isAllDay()const { | 197 | bool OEvent::isAllDay()const { |
198 | return data->isAllDay; | 198 | return data->isAllDay; |
199 | } | 199 | } |
200 | void OEvent::setAllDay( bool allDay ) { | 200 | void OEvent::setAllDay( bool allDay ) { |
201 | changeOrModify(); | 201 | changeOrModify(); |
202 | data->isAllDay = allDay; | 202 | data->isAllDay = allDay; |
203 | if (allDay ) data->timezone = "UTC"; | 203 | if (allDay ) data->timezone = "UTC"; |
204 | } | 204 | } |
205 | void OEvent::setTimeZone( const QString& tz ) { | 205 | void OEvent::setTimeZone( const QString& tz ) { |
206 | changeOrModify(); | 206 | changeOrModify(); |
207 | data->timezone = tz; | 207 | data->timezone = tz; |
208 | } | 208 | } |
209 | QString OEvent::timeZone()const { | 209 | QString OEvent::timeZone()const { |
210 | if (data->isAllDay ) return QString::fromLatin1("UTC"); | 210 | if (data->isAllDay ) return QString::fromLatin1("UTC"); |
211 | return data->timezone; | 211 | return data->timezone; |
212 | } | 212 | } |
213 | bool OEvent::match( const QRegExp& )const { | 213 | bool OEvent::match( const QRegExp& )const { |
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index 049359e..ea66d39 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp | |||
@@ -215,210 +215,210 @@ bool OTodo::isOverdue( ) | |||
215 | { | 215 | { |
216 | if( data->hasDate && !data->isCompleted) | 216 | if( data->hasDate && !data->isCompleted) |
217 | return QDate::currentDate() > data->date; | 217 | return QDate::currentDate() > data->date; |
218 | return false; | 218 | return false; |
219 | } | 219 | } |
220 | void OTodo::setProgress(ushort progress ) | 220 | void OTodo::setProgress(ushort progress ) |
221 | { | 221 | { |
222 | changeOrModify(); | 222 | changeOrModify(); |
223 | data->prog = progress; | 223 | data->prog = progress; |
224 | } | 224 | } |
225 | QString OTodo::toShortText() const { | 225 | QString OTodo::toShortText() const { |
226 | return summary(); | 226 | return summary(); |
227 | } | 227 | } |
228 | /*! | 228 | /*! |
229 | Returns a richt text string | 229 | Returns a richt text string |
230 | */ | 230 | */ |
231 | QString OTodo::toRichText() const | 231 | QString OTodo::toRichText() const |
232 | { | 232 | { |
233 | QString text; | 233 | QString text; |
234 | QStringList catlist; | 234 | QStringList catlist; |
235 | 235 | ||
236 | // Description of the todo | 236 | // Description of the todo |
237 | if ( !summary().isEmpty() ) { | 237 | if ( !summary().isEmpty() ) { |
238 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; | 238 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; |
239 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; | 239 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; |
240 | } | 240 | } |
241 | if( !description().isEmpty() ){ | 241 | if( !description().isEmpty() ){ |
242 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | 242 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; |
243 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; | 243 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; |
244 | } | 244 | } |
245 | text += "<br><br><br>"; | 245 | text += "<br><br><br>"; |
246 | 246 | ||
247 | text += "<b>" + QObject::tr( "Priority:") +" </b>" | 247 | text += "<b>" + QObject::tr( "Priority:") +" </b>" |
248 | + QString::number( priority() ) + " <br>"; | 248 | + QString::number( priority() ) + " <br>"; |
249 | text += "<b>" + QObject::tr( "Progress:") + " </b>" | 249 | text += "<b>" + QObject::tr( "Progress:") + " </b>" |
250 | + QString::number( progress() ) + " %<br>"; | 250 | + QString::number( progress() ) + " %<br>"; |
251 | if (hasDueDate() ){ | 251 | if (hasDueDate() ){ |
252 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; | 252 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; |
253 | text += dueDate().toString(); | 253 | text += dueDate().toString(); |
254 | text += "<br>"; | 254 | text += "<br>"; |
255 | } | 255 | } |
256 | 256 | ||
257 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 257 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
258 | text += categoryNames( "Todo List" ).join(", "); | 258 | text += categoryNames( "Todo List" ).join(", "); |
259 | text += "<br>"; | 259 | text += "<br>"; |
260 | 260 | ||
261 | return text; | 261 | return text; |
262 | } | 262 | } |
263 | OPimNotifyManager& OTodo::notifiers() { | 263 | OPimNotifyManager& OTodo::notifiers() { |
264 | return data->notifiers; | 264 | return data->notifiers; |
265 | } | 265 | } |
266 | 266 | ||
267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
272 | return priority() < toDoEvent.priority(); | 272 | return priority() < toDoEvent.priority(); |
273 | }else{ | 273 | }else{ |
274 | return dueDate() < toDoEvent.dueDate(); | 274 | return dueDate() < toDoEvent.dueDate(); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | return false; | 277 | return false; |
278 | } | 278 | } |
279 | bool OTodo::operator<=(const OTodo &toDoEvent )const | 279 | bool OTodo::operator<=(const OTodo &toDoEvent )const |
280 | { | 280 | { |
281 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 281 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
282 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; | 282 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; |
283 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 283 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
284 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 284 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
285 | return priority() <= toDoEvent.priority(); | 285 | return priority() <= toDoEvent.priority(); |
286 | }else{ | 286 | }else{ |
287 | return dueDate() <= toDoEvent.dueDate(); | 287 | return dueDate() <= toDoEvent.dueDate(); |
288 | } | 288 | } |
289 | } | 289 | } |
290 | return true; | 290 | return true; |
291 | } | 291 | } |
292 | bool OTodo::operator>(const OTodo &toDoEvent )const | 292 | bool OTodo::operator>(const OTodo &toDoEvent )const |
293 | { | 293 | { |
294 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; | 294 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; |
295 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 295 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
296 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 296 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
297 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 297 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
298 | return priority() > toDoEvent.priority(); | 298 | return priority() > toDoEvent.priority(); |
299 | }else{ | 299 | }else{ |
300 | return dueDate() > toDoEvent.dueDate(); | 300 | return dueDate() > toDoEvent.dueDate(); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | return false; | 303 | return false; |
304 | } | 304 | } |
305 | bool OTodo::operator>=(const OTodo &toDoEvent )const | 305 | bool OTodo::operator>=(const OTodo &toDoEvent )const |
306 | { | 306 | { |
307 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 307 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
308 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 308 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
309 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 309 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
310 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 310 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
311 | return priority() > toDoEvent.priority(); | 311 | return priority() > toDoEvent.priority(); |
312 | }else{ | 312 | }else{ |
313 | return dueDate() > toDoEvent.dueDate(); | 313 | return dueDate() > toDoEvent.dueDate(); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | return true; | 316 | return true; |
317 | } | 317 | } |
318 | bool OTodo::operator==(const OTodo &toDoEvent )const | 318 | bool OTodo::operator==(const OTodo &toDoEvent )const |
319 | { | 319 | { |
320 | if ( data->priority != toDoEvent.data->priority ) return false; | 320 | if ( data->priority != toDoEvent.data->priority ) return false; |
321 | if ( data->priority != toDoEvent.data->prog ) return false; | 321 | if ( data->priority != toDoEvent.data->prog ) return false; |
322 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 322 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
323 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 323 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
324 | if ( data->date != toDoEvent.data->date ) return false; | 324 | if ( data->date != toDoEvent.data->date ) return false; |
325 | if ( data->sum != toDoEvent.data->sum ) return false; | 325 | if ( data->sum != toDoEvent.data->sum ) return false; |
326 | if ( data->desc != toDoEvent.data->desc ) return false; | 326 | if ( data->desc != toDoEvent.data->desc ) return false; |
327 | if ( data->maintainer != toDoEvent.data->maintainer ) | 327 | if ( data->maintainer != toDoEvent.data->maintainer ) |
328 | return false; | 328 | return false; |
329 | 329 | ||
330 | return OPimRecord::operator==( toDoEvent ); | 330 | return OPimRecord::operator==( toDoEvent ); |
331 | } | 331 | } |
332 | void OTodo::deref() { | 332 | void OTodo::deref() { |
333 | 333 | ||
334 | // qWarning("deref in ToDoEvent"); | 334 | // qWarning("deref in ToDoEvent"); |
335 | if ( data->deref() ) { | 335 | if ( data->deref() ) { |
336 | // qWarning("deleting"); | 336 | // qWarning("deleting"); |
337 | delete data; | 337 | delete data; |
338 | data= 0; | 338 | data= 0; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | OTodo &OTodo::operator=(const OTodo &item ) | 341 | OTodo &OTodo::operator=(const OTodo &item ) |
342 | { | 342 | { |
343 | if ( *this == item ) return *this; | 343 | if ( this == &item ) return *this; |
344 | 344 | ||
345 | OPimRecord::operator=( item ); | 345 | OPimRecord::operator=( item ); |
346 | //qWarning("operator= ref "); | 346 | //qWarning("operator= ref "); |
347 | item.data->ref(); | 347 | item.data->ref(); |
348 | deref(); | 348 | deref(); |
349 | data = item.data; | 349 | data = item.data; |
350 | 350 | ||
351 | return *this; | 351 | return *this; |
352 | } | 352 | } |
353 | 353 | ||
354 | QMap<int, QString> OTodo::toMap() const { | 354 | QMap<int, QString> OTodo::toMap() const { |
355 | QMap<int, QString> map; | 355 | QMap<int, QString> map; |
356 | 356 | ||
357 | map.insert( Uid, QString::number( uid() ) ); | 357 | map.insert( Uid, QString::number( uid() ) ); |
358 | map.insert( Category, idsToString( categories() ) ); | 358 | map.insert( Category, idsToString( categories() ) ); |
359 | map.insert( HasDate, QString::number( data->hasDate ) ); | 359 | map.insert( HasDate, QString::number( data->hasDate ) ); |
360 | map.insert( Completed, QString::number( data->isCompleted ) ); | 360 | map.insert( Completed, QString::number( data->isCompleted ) ); |
361 | map.insert( Description, data->desc ); | 361 | map.insert( Description, data->desc ); |
362 | map.insert( Summary, data->sum ); | 362 | map.insert( Summary, data->sum ); |
363 | map.insert( Priority, QString::number( data->priority ) ); | 363 | map.insert( Priority, QString::number( data->priority ) ); |
364 | map.insert( DateDay, QString::number( data->date.day() ) ); | 364 | map.insert( DateDay, QString::number( data->date.day() ) ); |
365 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 365 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
366 | map.insert( DateYear, QString::number( data->date.year() ) ); | 366 | map.insert( DateYear, QString::number( data->date.year() ) ); |
367 | map.insert( Progress, QString::number( data->prog ) ); | 367 | map.insert( Progress, QString::number( data->prog ) ); |
368 | // map.insert( CrossReference, crossToString() ); | 368 | // map.insert( CrossReference, crossToString() ); |
369 | /* FIXME!!! map.insert( State, ); | 369 | /* FIXME!!! map.insert( State, ); |
370 | map.insert( Recurrence, ); | 370 | map.insert( Recurrence, ); |
371 | map.insert( Reminders, ); | 371 | map.insert( Reminders, ); |
372 | map. | 372 | map. |
373 | */ | 373 | */ |
374 | return map; | 374 | return map; |
375 | } | 375 | } |
376 | 376 | ||
377 | QMap<QString, QString> OTodo::toExtraMap()const { | 377 | QMap<QString, QString> OTodo::toExtraMap()const { |
378 | return data->extra; | 378 | return data->extra; |
379 | } | 379 | } |
380 | /** | 380 | /** |
381 | * change or modify looks at the ref count and either | 381 | * change or modify looks at the ref count and either |
382 | * creates a new QShared Object or it can modify it | 382 | * creates a new QShared Object or it can modify it |
383 | * right in place | 383 | * right in place |
384 | */ | 384 | */ |
385 | void OTodo::changeOrModify() { | 385 | void OTodo::changeOrModify() { |
386 | if ( data->count != 1 ) { | 386 | if ( data->count != 1 ) { |
387 | qWarning("changeOrModify"); | 387 | qWarning("changeOrModify"); |
388 | data->deref(); | 388 | data->deref(); |
389 | OTodoData* d2 = new OTodoData(); | 389 | OTodoData* d2 = new OTodoData(); |
390 | copy(data, d2 ); | 390 | copy(data, d2 ); |
391 | data = d2; | 391 | data = d2; |
392 | } | 392 | } |
393 | } | 393 | } |
394 | // WATCHOUT | 394 | // WATCHOUT |
395 | /* | 395 | /* |
396 | * if you add something to the Data struct | 396 | * if you add something to the Data struct |
397 | * be sure to copy it here | 397 | * be sure to copy it here |
398 | */ | 398 | */ |
399 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 399 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
400 | dest->date = src->date; | 400 | dest->date = src->date; |
401 | dest->isCompleted = src->isCompleted; | 401 | dest->isCompleted = src->isCompleted; |
402 | dest->hasDate = src->hasDate; | 402 | dest->hasDate = src->hasDate; |
403 | dest->priority = src->priority; | 403 | dest->priority = src->priority; |
404 | dest->desc = src->desc; | 404 | dest->desc = src->desc; |
405 | dest->sum = src->sum; | 405 | dest->sum = src->sum; |
406 | dest->extra = src->extra; | 406 | dest->extra = src->extra; |
407 | dest->prog = src->prog; | 407 | dest->prog = src->prog; |
408 | dest->state = src->state; | 408 | dest->state = src->state; |
409 | dest->recur = src->recur; | 409 | dest->recur = src->recur; |
410 | dest->maintainer = src->maintainer; | 410 | dest->maintainer = src->maintainer; |
411 | dest->start = src->start; | 411 | dest->start = src->start; |
412 | dest->completed = src->completed; | 412 | dest->completed = src->completed; |
413 | dest->notifiers = src->notifiers; | 413 | dest->notifiers = src->notifiers; |
414 | } | 414 | } |
415 | QString OTodo::type() const { | 415 | QString OTodo::type() const { |
416 | return QString::fromLatin1("OTodo"); | 416 | return QString::fromLatin1("OTodo"); |
417 | } | 417 | } |
418 | QString OTodo::recordField(int /*id*/ )const { | 418 | QString OTodo::recordField(int /*id*/ )const { |
419 | return QString::null; | 419 | return QString::null; |
420 | } | 420 | } |
421 | 421 | ||
422 | int OTodo::rtti(){ | 422 | int OTodo::rtti(){ |
423 | return OPimResolver::TodoList; | 423 | return OPimResolver::TodoList; |
424 | } | 424 | } |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp index 11e19d9..a0ae7b7 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |||
@@ -123,256 +123,257 @@ namespace { | |||
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_raw.clear(); | 252 | m_raw.clear(); |
252 | m_rep.clear(); | 253 | m_rep.clear(); |
253 | } | 254 | } |
254 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 255 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
255 | if ( m_raw.contains( uid ) ) | 256 | if ( m_raw.contains( uid ) ) |
256 | return m_raw[uid]; | 257 | return m_raw[uid]; |
257 | else | 258 | else |
258 | return m_rep[uid]; | 259 | return m_rep[uid]; |
259 | } | 260 | } |
260 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 261 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
261 | m_changed = true; | 262 | m_changed = true; |
262 | if (ev.hasRecurrence() ) | 263 | if (ev.hasRecurrence() ) |
263 | m_rep.insert( ev.uid(), ev ); | 264 | m_rep.insert( ev.uid(), ev ); |
264 | else | 265 | else |
265 | m_raw.insert( ev.uid(), ev ); | 266 | m_raw.insert( ev.uid(), ev ); |
266 | 267 | ||
267 | return true; | 268 | return true; |
268 | } | 269 | } |
269 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 270 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
270 | m_changed = true; | 271 | m_changed = true; |
271 | m_rep.remove( uid ); | 272 | m_rep.remove( uid ); |
272 | m_rep.remove( uid ); | 273 | m_rep.remove( uid ); |
273 | 274 | ||
274 | return true; | 275 | return true; |
275 | } | 276 | } |
276 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
277 | replace( ev.uid() ); | 278 | replace( ev.uid() ); |
278 | return add( ev ); | 279 | return add( ev ); |
279 | } | 280 | } |
280 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 281 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
281 | return allRecords(); | 282 | return allRecords(); |
282 | } | 283 | } |
283 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 284 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
284 | QArray<int> ints( m_rep.count() ); | 285 | QArray<int> ints( m_rep.count() ); |
285 | uint i = 0; | 286 | uint i = 0; |
286 | QMap<int, OEvent>::ConstIterator it; | 287 | QMap<int, OEvent>::ConstIterator it; |
287 | 288 | ||
288 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 289 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
289 | ints[i] = it.key(); | 290 | ints[i] = it.key(); |
290 | i++; | 291 | i++; |
291 | } | 292 | } |
292 | 293 | ||
293 | return ints; | 294 | return ints; |
294 | } | 295 | } |
295 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 296 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
296 | QArray<int> ints( m_raw.count() ); | 297 | QArray<int> ints( m_raw.count() ); |
297 | uint i = 0; | 298 | uint i = 0; |
298 | QMap<int, OEvent>::ConstIterator it; | 299 | QMap<int, OEvent>::ConstIterator it; |
299 | 300 | ||
300 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 301 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
301 | ints[i] = it.key(); | 302 | ints[i] = it.key(); |
302 | i++; | 303 | i++; |
303 | } | 304 | } |
304 | 305 | ||
305 | return ints; | 306 | return ints; |
306 | } | 307 | } |
307 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 308 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
308 | OEvent::ValueList list; | 309 | OEvent::ValueList list; |
309 | QMap<int, OEvent>::ConstIterator it; | 310 | QMap<int, OEvent>::ConstIterator it; |
310 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 311 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
311 | list.append( it.data() ); | 312 | list.append( it.data() ); |
312 | 313 | ||
313 | return list; | 314 | return list; |
314 | } | 315 | } |
315 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 316 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
316 | OEvent::ValueList list; | 317 | OEvent::ValueList list; |
317 | QMap<int, OEvent>::ConstIterator it; | 318 | QMap<int, OEvent>::ConstIterator it; |
318 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 319 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
319 | list.append( it.data() ); | 320 | list.append( it.data() ); |
320 | 321 | ||
321 | return list; | 322 | return list; |
322 | } | 323 | } |
323 | bool ODateBookAccessBackend_XML::loadFile() { | 324 | bool ODateBookAccessBackend_XML::loadFile() { |
324 | m_changed = false; | 325 | m_changed = false; |
325 | 326 | ||
326 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 327 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
327 | if ( fd < 0 ) return false; | 328 | if ( fd < 0 ) return false; |
328 | 329 | ||
329 | struct stat attribute; | 330 | struct stat attribute; |
330 | if ( ::fstat(fd, &attribute ) == -1 ) { | 331 | if ( ::fstat(fd, &attribute ) == -1 ) { |
331 | ::close( fd ); | 332 | ::close( fd ); |
332 | return false; | 333 | return false; |
333 | } | 334 | } |
334 | 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 ); |
335 | if ( map_addr == ( (caddr_t)-1) ) { | 336 | if ( map_addr == ( (caddr_t)-1) ) { |
336 | ::close( fd ); | 337 | ::close( fd ); |
337 | return false; | 338 | return false; |
338 | } | 339 | } |
339 | 340 | ||
340 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 341 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
341 | ::close( fd ); | 342 | ::close( fd ); |
342 | 343 | ||
343 | QAsciiDict<int> dict(FExceptions+1); | 344 | QAsciiDict<int> dict(FExceptions+1); |
344 | dict.setAutoDelete( true ); | 345 | dict.setAutoDelete( true ); |
345 | dict.insert( "description", new int(FDescription) ); | 346 | dict.insert( "description", new int(FDescription) ); |
346 | dict.insert( "location", new int(FLocation) ); | 347 | dict.insert( "location", new int(FLocation) ); |
347 | dict.insert( "categories", new int(FCategories) ); | 348 | dict.insert( "categories", new int(FCategories) ); |
348 | dict.insert( "uid", new int(FUid) ); | 349 | dict.insert( "uid", new int(FUid) ); |
349 | dict.insert( "type", new int(FType) ); | 350 | dict.insert( "type", new int(FType) ); |
350 | dict.insert( "alarm", new int(FAlarm) ); | 351 | dict.insert( "alarm", new int(FAlarm) ); |
351 | dict.insert( "sound", new int(FSound) ); | 352 | dict.insert( "sound", new int(FSound) ); |
352 | dict.insert( "rtype", new int(FRType) ); | 353 | dict.insert( "rtype", new int(FRType) ); |
353 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 354 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
354 | dict.insert( "rposition", new int(FRPosition) ); | 355 | dict.insert( "rposition", new int(FRPosition) ); |
355 | dict.insert( "rfreq", new int(FRFreq) ); | 356 | dict.insert( "rfreq", new int(FRFreq) ); |
356 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 357 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
357 | dict.insert( "enddt", new int(FREndDate) ); | 358 | dict.insert( "enddt", new int(FREndDate) ); |
358 | dict.insert( "start", new int(FRStart) ); | 359 | dict.insert( "start", new int(FRStart) ); |
359 | dict.insert( "end", new int(FREnd) ); | 360 | dict.insert( "end", new int(FREnd) ); |
360 | dict.insert( "note", new int(FNote) ); | 361 | dict.insert( "note", new int(FNote) ); |
361 | dict.insert( "created", new int(FCreated) ); | 362 | dict.insert( "created", new int(FCreated) ); |
362 | dict.insert( "recparent", new int(FRecParent) ); | 363 | dict.insert( "recparent", new int(FRecParent) ); |
363 | dict.insert( "recchildren", new int(FRecChildren) ); | 364 | dict.insert( "recchildren", new int(FRecChildren) ); |
364 | dict.insert( "exceptions", new int(FExceptions) ); | 365 | dict.insert( "exceptions", new int(FExceptions) ); |
365 | dict.insert( "timezone", new int(FTimeZone) ); | 366 | dict.insert( "timezone", new int(FTimeZone) ); |
366 | 367 | ||
367 | char* dt = (char*)map_addr; | 368 | char* dt = (char*)map_addr; |
368 | int len = attribute.st_size; | 369 | int len = attribute.st_size; |
369 | int i = 0; | 370 | int i = 0; |
370 | char* point; | 371 | char* point; |
371 | const char* collectionString = "<event "; | 372 | const char* collectionString = "<event "; |
372 | int strLen = ::strlen(collectionString); | 373 | int strLen = ::strlen(collectionString); |
373 | int *find; | 374 | int *find; |
374 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { | 375 | while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { |
375 | i = point -dt; | 376 | i = point -dt; |
376 | i+= strLen; | 377 | i+= strLen; |
377 | 378 | ||
378 | alarmTime = -1; | 379 | alarmTime = -1; |
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp index c3eeee2..56ea10d 100644 --- a/libopie2/opiepim/oevent.cpp +++ b/libopie2/opiepim/oevent.cpp | |||
@@ -1,213 +1,213 @@ | |||
1 | #include <qshared.h> | 1 | #include <qshared.h> |
2 | 2 | ||
3 | #include <qpe/palmtopuidgen.h> | 3 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/categories.h> | 4 | #include <qpe/categories.h> |
5 | 5 | ||
6 | #include "orecur.h" | 6 | #include "orecur.h" |
7 | #include "opimresolver.h" | 7 | #include "opimresolver.h" |
8 | #include "opimnotifymanager.h" | 8 | #include "opimnotifymanager.h" |
9 | 9 | ||
10 | #include "oevent.h" | 10 | #include "oevent.h" |
11 | 11 | ||
12 | int OCalendarHelper::week( const QDate& date) { | 12 | int OCalendarHelper::week( const QDate& date) { |
13 | // Calculates the week this date is in within that | 13 | // Calculates the week this date is in within that |
14 | // month. Equals the "row" is is in in the month view | 14 | // month. Equals the "row" is is in in the month view |
15 | int week = 1; | 15 | int week = 1; |
16 | QDate tmp( date.year(), date.month(), 1 ); | 16 | QDate tmp( date.year(), date.month(), 1 ); |
17 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) | 17 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) |
18 | ++week; | 18 | ++week; |
19 | 19 | ||
20 | week += ( date.day() - 1 ) / 7; | 20 | week += ( date.day() - 1 ) / 7; |
21 | 21 | ||
22 | return week; | 22 | return week; |
23 | } | 23 | } |
24 | int OCalendarHelper::ocurrence( const QDate& date) { | 24 | int OCalendarHelper::ocurrence( const QDate& date) { |
25 | // calculates the number of occurrances of this day of the | 25 | // calculates the number of occurrances of this day of the |
26 | // week till the given date (e.g 3rd Wednesday of the month) | 26 | // week till the given date (e.g 3rd Wednesday of the month) |
27 | return ( date.day() - 1 ) / 7 + 1; | 27 | return ( date.day() - 1 ) / 7 + 1; |
28 | } | 28 | } |
29 | int OCalendarHelper::dayOfWeek( char day ) { | 29 | int OCalendarHelper::dayOfWeek( char day ) { |
30 | int dayOfWeek = 1; | 30 | int dayOfWeek = 1; |
31 | char i = ORecur::MON; | 31 | char i = ORecur::MON; |
32 | while ( !( i & day ) && i <= ORecur::SUN ) { | 32 | while ( !( i & day ) && i <= ORecur::SUN ) { |
33 | i <<= 1; | 33 | i <<= 1; |
34 | ++dayOfWeek; | 34 | ++dayOfWeek; |
35 | } | 35 | } |
36 | return dayOfWeek; | 36 | return dayOfWeek; |
37 | } | 37 | } |
38 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { | 38 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { |
39 | return ( second.year() - first.year() ) * 12 + | 39 | return ( second.year() - first.year() ) * 12 + |
40 | second.month() - first.month(); | 40 | second.month() - first.month(); |
41 | } | 41 | } |
42 | 42 | ||
43 | struct OEvent::Data : public QShared { | 43 | struct OEvent::Data : public QShared { |
44 | Data() : QShared() { | 44 | Data() : QShared() { |
45 | child = 0; | 45 | child = 0; |
46 | recur = 0; | 46 | recur = 0; |
47 | manager = 0; | 47 | manager = 0; |
48 | isAllDay = false; | 48 | isAllDay = false; |
49 | parent = 0; | 49 | parent = 0; |
50 | } | 50 | } |
51 | ~Data() { | 51 | ~Data() { |
52 | delete manager; | 52 | delete manager; |
53 | delete recur; | 53 | delete recur; |
54 | } | 54 | } |
55 | QString description; | 55 | QString description; |
56 | QString location; | 56 | QString location; |
57 | OPimNotifyManager* manager; | 57 | OPimNotifyManager* manager; |
58 | ORecur* recur; | 58 | ORecur* recur; |
59 | QString note; | 59 | QString note; |
60 | QDateTime created; | 60 | QDateTime created; |
61 | QDateTime start; | 61 | QDateTime start; |
62 | QDateTime end; | 62 | QDateTime end; |
63 | bool isAllDay : 1; | 63 | bool isAllDay : 1; |
64 | QString timezone; | 64 | QString timezone; |
65 | QArray<int>* child; | 65 | QArray<int>* child; |
66 | int parent; | 66 | int parent; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | OEvent::OEvent( int uid ) | 69 | OEvent::OEvent( int uid ) |
70 | : OPimRecord( uid ) { | 70 | : OPimRecord( uid ) { |
71 | data = new Data; | 71 | data = new Data; |
72 | } | 72 | } |
73 | OEvent::OEvent( const OEvent& ev) | 73 | OEvent::OEvent( const OEvent& ev) |
74 | : OPimRecord( ev ), data( ev.data ) | 74 | : OPimRecord( ev ), data( ev.data ) |
75 | { | 75 | { |
76 | data->ref(); | 76 | data->ref(); |
77 | } | 77 | } |
78 | OEvent::~OEvent() { | 78 | OEvent::~OEvent() { |
79 | if ( data->deref() ) { | 79 | if ( data->deref() ) { |
80 | delete data; | 80 | delete data; |
81 | data = 0; | 81 | data = 0; |
82 | } | 82 | } |
83 | } | 83 | } |
84 | OEvent& OEvent::operator=( const OEvent& ev) { | 84 | OEvent& OEvent::operator=( const OEvent& ev) { |
85 | if ( *this == ev ) return *this; | 85 | if ( this == &ev ) return *this; |
86 | 86 | ||
87 | OPimRecord::operator=( ev ); | 87 | OPimRecord::operator=( ev ); |
88 | ev.data->ref(); | 88 | ev.data->ref(); |
89 | deref(); | 89 | deref(); |
90 | data = ev.data; | 90 | data = ev.data; |
91 | 91 | ||
92 | 92 | ||
93 | return *this; | 93 | return *this; |
94 | } | 94 | } |
95 | QString OEvent::description()const { | 95 | QString OEvent::description()const { |
96 | return data->description; | 96 | return data->description; |
97 | } | 97 | } |
98 | void OEvent::setDescription( const QString& description ) { | 98 | void OEvent::setDescription( const QString& description ) { |
99 | changeOrModify(); | 99 | changeOrModify(); |
100 | data->description = description; | 100 | data->description = description; |
101 | } | 101 | } |
102 | void OEvent::setLocation( const QString& loc ) { | 102 | void OEvent::setLocation( const QString& loc ) { |
103 | changeOrModify(); | 103 | changeOrModify(); |
104 | data->location = loc; | 104 | data->location = loc; |
105 | } | 105 | } |
106 | QString OEvent::location()const { | 106 | QString OEvent::location()const { |
107 | return data->location; | 107 | return data->location; |
108 | } | 108 | } |
109 | OPimNotifyManager &OEvent::notifiers()const { | 109 | OPimNotifyManager &OEvent::notifiers()const { |
110 | // I hope we can skip the changeOrModify here | 110 | // I hope we can skip the changeOrModify here |
111 | // the notifier should take care of it | 111 | // the notifier should take care of it |
112 | // and OPimNotify is shared too | 112 | // and OPimNotify is shared too |
113 | if (!data->manager ) | 113 | if (!data->manager ) |
114 | data->manager = new OPimNotifyManager; | 114 | data->manager = new OPimNotifyManager; |
115 | 115 | ||
116 | return *data->manager; | 116 | return *data->manager; |
117 | } | 117 | } |
118 | bool OEvent::hasNotifiers()const { | 118 | bool OEvent::hasNotifiers()const { |
119 | if (!data->manager ) | 119 | if (!data->manager ) |
120 | return false; | 120 | return false; |
121 | if (data->manager->reminders().isEmpty() && | 121 | if (data->manager->reminders().isEmpty() && |
122 | data->manager->alarms().isEmpty() ) | 122 | data->manager->alarms().isEmpty() ) |
123 | return false; | 123 | return false; |
124 | 124 | ||
125 | return true; | 125 | return true; |
126 | } | 126 | } |
127 | ORecur OEvent::recurrence()const { | 127 | ORecur OEvent::recurrence()const { |
128 | if (!data->recur) | 128 | if (!data->recur) |
129 | data->recur = new ORecur; | 129 | data->recur = new ORecur; |
130 | 130 | ||
131 | return *data->recur; | 131 | return *data->recur; |
132 | } | 132 | } |
133 | void OEvent::setRecurrence( const ORecur& rec) { | 133 | void OEvent::setRecurrence( const ORecur& rec) { |
134 | changeOrModify(); | 134 | changeOrModify(); |
135 | if (data->recur ) | 135 | if (data->recur ) |
136 | (*data->recur) = rec; | 136 | (*data->recur) = rec; |
137 | else | 137 | else |
138 | data->recur = new ORecur( rec ); | 138 | data->recur = new ORecur( rec ); |
139 | } | 139 | } |
140 | bool OEvent::hasRecurrence()const { | 140 | bool OEvent::hasRecurrence()const { |
141 | if (!data->recur ) return false; | 141 | if (!data->recur ) return false; |
142 | return data->recur->doesRecur(); | 142 | return data->recur->doesRecur(); |
143 | } | 143 | } |
144 | QString OEvent::note()const { | 144 | QString OEvent::note()const { |
145 | return data->note; | 145 | return data->note; |
146 | } | 146 | } |
147 | void OEvent::setNote( const QString& note ) { | 147 | void OEvent::setNote( const QString& note ) { |
148 | changeOrModify(); | 148 | changeOrModify(); |
149 | data->note = note; | 149 | data->note = note; |
150 | } | 150 | } |
151 | QDateTime OEvent::createdDateTime()const { | 151 | QDateTime OEvent::createdDateTime()const { |
152 | return data->created; | 152 | return data->created; |
153 | } | 153 | } |
154 | void OEvent::setCreatedDateTime( const QDateTime& time ) { | 154 | void OEvent::setCreatedDateTime( const QDateTime& time ) { |
155 | changeOrModify(); | 155 | changeOrModify(); |
156 | data->created = time; | 156 | data->created = time; |
157 | } | 157 | } |
158 | QDateTime OEvent::startDateTime()const { | 158 | QDateTime OEvent::startDateTime()const { |
159 | if ( data->isAllDay ) | 159 | if ( data->isAllDay ) |
160 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); | 160 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); |
161 | return data->start; | 161 | return data->start; |
162 | } | 162 | } |
163 | QDateTime OEvent::startDateTimeInZone()const { | 163 | QDateTime OEvent::startDateTimeInZone()const { |
164 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 164 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
165 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); | 165 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); |
166 | 166 | ||
167 | OTimeZone zone(data->timezone ); | 167 | OTimeZone zone(data->timezone ); |
168 | return zone.toDateTime( data->start, OTimeZone::current() ); | 168 | return zone.toDateTime( data->start, OTimeZone::current() ); |
169 | } | 169 | } |
170 | void OEvent::setStartDateTime( const QDateTime& dt ) { | 170 | void OEvent::setStartDateTime( const QDateTime& dt ) { |
171 | changeOrModify(); | 171 | changeOrModify(); |
172 | data->start = dt; | 172 | data->start = dt; |
173 | } | 173 | } |
174 | QDateTime OEvent::endDateTime()const { | 174 | QDateTime OEvent::endDateTime()const { |
175 | /* | 175 | /* |
176 | * if all Day event the end time needs | 176 | * if all Day event the end time needs |
177 | * to be on the same day as the start | 177 | * to be on the same day as the start |
178 | */ | 178 | */ |
179 | if ( data->isAllDay ) | 179 | if ( data->isAllDay ) |
180 | return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); | 180 | return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); |
181 | return data->end; | 181 | return data->end; |
182 | } | 182 | } |
183 | QDateTime OEvent::endDateTimeInZone()const { | 183 | QDateTime OEvent::endDateTimeInZone()const { |
184 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 184 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
185 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); | 185 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); |
186 | 186 | ||
187 | OTimeZone zone(data->timezone ); | 187 | OTimeZone zone(data->timezone ); |
188 | return zone.toDateTime( data->end, OTimeZone::current() ); | 188 | return zone.toDateTime( data->end, OTimeZone::current() ); |
189 | } | 189 | } |
190 | void OEvent::setEndDateTime( const QDateTime& dt ) { | 190 | void OEvent::setEndDateTime( const QDateTime& dt ) { |
191 | changeOrModify(); | 191 | changeOrModify(); |
192 | data->end = dt; | 192 | data->end = dt; |
193 | } | 193 | } |
194 | bool OEvent::isMultipleDay()const { | 194 | bool OEvent::isMultipleDay()const { |
195 | return data->end.date().day() - data->start.date().day(); | 195 | return data->end.date().day() - data->start.date().day(); |
196 | } | 196 | } |
197 | bool OEvent::isAllDay()const { | 197 | bool OEvent::isAllDay()const { |
198 | return data->isAllDay; | 198 | return data->isAllDay; |
199 | } | 199 | } |
200 | void OEvent::setAllDay( bool allDay ) { | 200 | void OEvent::setAllDay( bool allDay ) { |
201 | changeOrModify(); | 201 | changeOrModify(); |
202 | data->isAllDay = allDay; | 202 | data->isAllDay = allDay; |
203 | if (allDay ) data->timezone = "UTC"; | 203 | if (allDay ) data->timezone = "UTC"; |
204 | } | 204 | } |
205 | void OEvent::setTimeZone( const QString& tz ) { | 205 | void OEvent::setTimeZone( const QString& tz ) { |
206 | changeOrModify(); | 206 | changeOrModify(); |
207 | data->timezone = tz; | 207 | data->timezone = tz; |
208 | } | 208 | } |
209 | QString OEvent::timeZone()const { | 209 | QString OEvent::timeZone()const { |
210 | if (data->isAllDay ) return QString::fromLatin1("UTC"); | 210 | if (data->isAllDay ) return QString::fromLatin1("UTC"); |
211 | return data->timezone; | 211 | return data->timezone; |
212 | } | 212 | } |
213 | bool OEvent::match( const QRegExp& )const { | 213 | bool OEvent::match( const QRegExp& )const { |
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index 049359e..ea66d39 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp | |||
@@ -215,210 +215,210 @@ bool OTodo::isOverdue( ) | |||
215 | { | 215 | { |
216 | if( data->hasDate && !data->isCompleted) | 216 | if( data->hasDate && !data->isCompleted) |
217 | return QDate::currentDate() > data->date; | 217 | return QDate::currentDate() > data->date; |
218 | return false; | 218 | return false; |
219 | } | 219 | } |
220 | void OTodo::setProgress(ushort progress ) | 220 | void OTodo::setProgress(ushort progress ) |
221 | { | 221 | { |
222 | changeOrModify(); | 222 | changeOrModify(); |
223 | data->prog = progress; | 223 | data->prog = progress; |
224 | } | 224 | } |
225 | QString OTodo::toShortText() const { | 225 | QString OTodo::toShortText() const { |
226 | return summary(); | 226 | return summary(); |
227 | } | 227 | } |
228 | /*! | 228 | /*! |
229 | Returns a richt text string | 229 | Returns a richt text string |
230 | */ | 230 | */ |
231 | QString OTodo::toRichText() const | 231 | QString OTodo::toRichText() const |
232 | { | 232 | { |
233 | QString text; | 233 | QString text; |
234 | QStringList catlist; | 234 | QStringList catlist; |
235 | 235 | ||
236 | // Description of the todo | 236 | // Description of the todo |
237 | if ( !summary().isEmpty() ) { | 237 | if ( !summary().isEmpty() ) { |
238 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; | 238 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; |
239 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; | 239 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; |
240 | } | 240 | } |
241 | if( !description().isEmpty() ){ | 241 | if( !description().isEmpty() ){ |
242 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | 242 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; |
243 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; | 243 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; |
244 | } | 244 | } |
245 | text += "<br><br><br>"; | 245 | text += "<br><br><br>"; |
246 | 246 | ||
247 | text += "<b>" + QObject::tr( "Priority:") +" </b>" | 247 | text += "<b>" + QObject::tr( "Priority:") +" </b>" |
248 | + QString::number( priority() ) + " <br>"; | 248 | + QString::number( priority() ) + " <br>"; |
249 | text += "<b>" + QObject::tr( "Progress:") + " </b>" | 249 | text += "<b>" + QObject::tr( "Progress:") + " </b>" |
250 | + QString::number( progress() ) + " %<br>"; | 250 | + QString::number( progress() ) + " %<br>"; |
251 | if (hasDueDate() ){ | 251 | if (hasDueDate() ){ |
252 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; | 252 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; |
253 | text += dueDate().toString(); | 253 | text += dueDate().toString(); |
254 | text += "<br>"; | 254 | text += "<br>"; |
255 | } | 255 | } |
256 | 256 | ||
257 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 257 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
258 | text += categoryNames( "Todo List" ).join(", "); | 258 | text += categoryNames( "Todo List" ).join(", "); |
259 | text += "<br>"; | 259 | text += "<br>"; |
260 | 260 | ||
261 | return text; | 261 | return text; |
262 | } | 262 | } |
263 | OPimNotifyManager& OTodo::notifiers() { | 263 | OPimNotifyManager& OTodo::notifiers() { |
264 | return data->notifiers; | 264 | return data->notifiers; |
265 | } | 265 | } |
266 | 266 | ||
267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
272 | return priority() < toDoEvent.priority(); | 272 | return priority() < toDoEvent.priority(); |
273 | }else{ | 273 | }else{ |
274 | return dueDate() < toDoEvent.dueDate(); | 274 | return dueDate() < toDoEvent.dueDate(); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | return false; | 277 | return false; |
278 | } | 278 | } |
279 | bool OTodo::operator<=(const OTodo &toDoEvent )const | 279 | bool OTodo::operator<=(const OTodo &toDoEvent )const |
280 | { | 280 | { |
281 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 281 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
282 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; | 282 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; |
283 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 283 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
284 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 284 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
285 | return priority() <= toDoEvent.priority(); | 285 | return priority() <= toDoEvent.priority(); |
286 | }else{ | 286 | }else{ |
287 | return dueDate() <= toDoEvent.dueDate(); | 287 | return dueDate() <= toDoEvent.dueDate(); |
288 | } | 288 | } |
289 | } | 289 | } |
290 | return true; | 290 | return true; |
291 | } | 291 | } |
292 | bool OTodo::operator>(const OTodo &toDoEvent )const | 292 | bool OTodo::operator>(const OTodo &toDoEvent )const |
293 | { | 293 | { |
294 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; | 294 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; |
295 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 295 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
296 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 296 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
297 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 297 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
298 | return priority() > toDoEvent.priority(); | 298 | return priority() > toDoEvent.priority(); |
299 | }else{ | 299 | }else{ |
300 | return dueDate() > toDoEvent.dueDate(); | 300 | return dueDate() > toDoEvent.dueDate(); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | return false; | 303 | return false; |
304 | } | 304 | } |
305 | bool OTodo::operator>=(const OTodo &toDoEvent )const | 305 | bool OTodo::operator>=(const OTodo &toDoEvent )const |
306 | { | 306 | { |
307 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 307 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
308 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 308 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
309 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 309 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
310 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 310 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
311 | return priority() > toDoEvent.priority(); | 311 | return priority() > toDoEvent.priority(); |
312 | }else{ | 312 | }else{ |
313 | return dueDate() > toDoEvent.dueDate(); | 313 | return dueDate() > toDoEvent.dueDate(); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | return true; | 316 | return true; |
317 | } | 317 | } |
318 | bool OTodo::operator==(const OTodo &toDoEvent )const | 318 | bool OTodo::operator==(const OTodo &toDoEvent )const |
319 | { | 319 | { |
320 | if ( data->priority != toDoEvent.data->priority ) return false; | 320 | if ( data->priority != toDoEvent.data->priority ) return false; |
321 | if ( data->priority != toDoEvent.data->prog ) return false; | 321 | if ( data->priority != toDoEvent.data->prog ) return false; |
322 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 322 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
323 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 323 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
324 | if ( data->date != toDoEvent.data->date ) return false; | 324 | if ( data->date != toDoEvent.data->date ) return false; |
325 | if ( data->sum != toDoEvent.data->sum ) return false; | 325 | if ( data->sum != toDoEvent.data->sum ) return false; |
326 | if ( data->desc != toDoEvent.data->desc ) return false; | 326 | if ( data->desc != toDoEvent.data->desc ) return false; |
327 | if ( data->maintainer != toDoEvent.data->maintainer ) | 327 | if ( data->maintainer != toDoEvent.data->maintainer ) |
328 | return false; | 328 | return false; |
329 | 329 | ||
330 | return OPimRecord::operator==( toDoEvent ); | 330 | return OPimRecord::operator==( toDoEvent ); |
331 | } | 331 | } |
332 | void OTodo::deref() { | 332 | void OTodo::deref() { |
333 | 333 | ||
334 | // qWarning("deref in ToDoEvent"); | 334 | // qWarning("deref in ToDoEvent"); |
335 | if ( data->deref() ) { | 335 | if ( data->deref() ) { |
336 | // qWarning("deleting"); | 336 | // qWarning("deleting"); |
337 | delete data; | 337 | delete data; |
338 | data= 0; | 338 | data= 0; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | OTodo &OTodo::operator=(const OTodo &item ) | 341 | OTodo &OTodo::operator=(const OTodo &item ) |
342 | { | 342 | { |
343 | if ( *this == item ) return *this; | 343 | if ( this == &item ) return *this; |
344 | 344 | ||
345 | OPimRecord::operator=( item ); | 345 | OPimRecord::operator=( item ); |
346 | //qWarning("operator= ref "); | 346 | //qWarning("operator= ref "); |
347 | item.data->ref(); | 347 | item.data->ref(); |
348 | deref(); | 348 | deref(); |
349 | data = item.data; | 349 | data = item.data; |
350 | 350 | ||
351 | return *this; | 351 | return *this; |
352 | } | 352 | } |
353 | 353 | ||
354 | QMap<int, QString> OTodo::toMap() const { | 354 | QMap<int, QString> OTodo::toMap() const { |
355 | QMap<int, QString> map; | 355 | QMap<int, QString> map; |
356 | 356 | ||
357 | map.insert( Uid, QString::number( uid() ) ); | 357 | map.insert( Uid, QString::number( uid() ) ); |
358 | map.insert( Category, idsToString( categories() ) ); | 358 | map.insert( Category, idsToString( categories() ) ); |
359 | map.insert( HasDate, QString::number( data->hasDate ) ); | 359 | map.insert( HasDate, QString::number( data->hasDate ) ); |
360 | map.insert( Completed, QString::number( data->isCompleted ) ); | 360 | map.insert( Completed, QString::number( data->isCompleted ) ); |
361 | map.insert( Description, data->desc ); | 361 | map.insert( Description, data->desc ); |
362 | map.insert( Summary, data->sum ); | 362 | map.insert( Summary, data->sum ); |
363 | map.insert( Priority, QString::number( data->priority ) ); | 363 | map.insert( Priority, QString::number( data->priority ) ); |
364 | map.insert( DateDay, QString::number( data->date.day() ) ); | 364 | map.insert( DateDay, QString::number( data->date.day() ) ); |
365 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 365 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
366 | map.insert( DateYear, QString::number( data->date.year() ) ); | 366 | map.insert( DateYear, QString::number( data->date.year() ) ); |
367 | map.insert( Progress, QString::number( data->prog ) ); | 367 | map.insert( Progress, QString::number( data->prog ) ); |
368 | // map.insert( CrossReference, crossToString() ); | 368 | // map.insert( CrossReference, crossToString() ); |
369 | /* FIXME!!! map.insert( State, ); | 369 | /* FIXME!!! map.insert( State, ); |
370 | map.insert( Recurrence, ); | 370 | map.insert( Recurrence, ); |
371 | map.insert( Reminders, ); | 371 | map.insert( Reminders, ); |
372 | map. | 372 | map. |
373 | */ | 373 | */ |
374 | return map; | 374 | return map; |
375 | } | 375 | } |
376 | 376 | ||
377 | QMap<QString, QString> OTodo::toExtraMap()const { | 377 | QMap<QString, QString> OTodo::toExtraMap()const { |
378 | return data->extra; | 378 | return data->extra; |
379 | } | 379 | } |
380 | /** | 380 | /** |
381 | * change or modify looks at the ref count and either | 381 | * change or modify looks at the ref count and either |
382 | * creates a new QShared Object or it can modify it | 382 | * creates a new QShared Object or it can modify it |
383 | * right in place | 383 | * right in place |
384 | */ | 384 | */ |
385 | void OTodo::changeOrModify() { | 385 | void OTodo::changeOrModify() { |
386 | if ( data->count != 1 ) { | 386 | if ( data->count != 1 ) { |
387 | qWarning("changeOrModify"); | 387 | qWarning("changeOrModify"); |
388 | data->deref(); | 388 | data->deref(); |
389 | OTodoData* d2 = new OTodoData(); | 389 | OTodoData* d2 = new OTodoData(); |
390 | copy(data, d2 ); | 390 | copy(data, d2 ); |
391 | data = d2; | 391 | data = d2; |
392 | } | 392 | } |
393 | } | 393 | } |
394 | // WATCHOUT | 394 | // WATCHOUT |
395 | /* | 395 | /* |
396 | * if you add something to the Data struct | 396 | * if you add something to the Data struct |
397 | * be sure to copy it here | 397 | * be sure to copy it here |
398 | */ | 398 | */ |
399 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 399 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
400 | dest->date = src->date; | 400 | dest->date = src->date; |
401 | dest->isCompleted = src->isCompleted; | 401 | dest->isCompleted = src->isCompleted; |
402 | dest->hasDate = src->hasDate; | 402 | dest->hasDate = src->hasDate; |
403 | dest->priority = src->priority; | 403 | dest->priority = src->priority; |
404 | dest->desc = src->desc; | 404 | dest->desc = src->desc; |
405 | dest->sum = src->sum; | 405 | dest->sum = src->sum; |
406 | dest->extra = src->extra; | 406 | dest->extra = src->extra; |
407 | dest->prog = src->prog; | 407 | dest->prog = src->prog; |
408 | dest->state = src->state; | 408 | dest->state = src->state; |
409 | dest->recur = src->recur; | 409 | dest->recur = src->recur; |
410 | dest->maintainer = src->maintainer; | 410 | dest->maintainer = src->maintainer; |
411 | dest->start = src->start; | 411 | dest->start = src->start; |
412 | dest->completed = src->completed; | 412 | dest->completed = src->completed; |
413 | dest->notifiers = src->notifiers; | 413 | dest->notifiers = src->notifiers; |
414 | } | 414 | } |
415 | QString OTodo::type() const { | 415 | QString OTodo::type() const { |
416 | return QString::fromLatin1("OTodo"); | 416 | return QString::fromLatin1("OTodo"); |
417 | } | 417 | } |
418 | QString OTodo::recordField(int /*id*/ )const { | 418 | QString OTodo::recordField(int /*id*/ )const { |
419 | return QString::null; | 419 | return QString::null; |
420 | } | 420 | } |
421 | 421 | ||
422 | int OTodo::rtti(){ | 422 | int OTodo::rtti(){ |
423 | return OPimResolver::TodoList; | 423 | return OPimResolver::TodoList; |
424 | } | 424 | } |