author | zecke <zecke> | 2003-04-13 16:55:34 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-04-13 16:55:34 (UTC) |
commit | 1537ccb435ca725c793db6e94e0b9e83484b57e7 (patch) (unidiff) | |
tree | f1aa77e10de202c058259ece02216957d8d520e3 /libopie | |
parent | 3bd592876c43c11ed44b2f3725d4c7425ebceb09 (diff) | |
download | opie-1537ccb435ca725c793db6e94e0b9e83484b57e7.zip opie-1537ccb435ca725c793db6e94e0b9e83484b57e7.tar.gz opie-1537ccb435ca725c793db6e94e0b9e83484b57e7.tar.bz2 |
OEvent/OTodo compare by address and not by value..
ODatebookAccess: clear does change it too
-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 |
3 files changed, 3 insertions, 2 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 | |||
@@ -203,96 +203,97 @@ bool ODateBookAccessBackend_XML::save() { | |||
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; |
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 | |||
@@ -37,97 +37,97 @@ int OCalendarHelper::dayOfWeek( char day ) { | |||
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) { |
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 | |||
@@ -295,97 +295,97 @@ bool OTodo::operator>(const OTodo &toDoEvent )const | |||
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; |