-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 127 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.h | 54 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 2 |
4 files changed, 184 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 8c2ea3a..761d7d8 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -296,245 +296,245 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | |||
296 | 296 | ||
297 | // we try to cache CACHE items | 297 | // we try to cache CACHE items |
298 | switch( dir ) { | 298 | switch( dir ) { |
299 | /* forward */ | 299 | /* forward */ |
300 | case 0: | 300 | case 0: |
301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
302 | qWarning("size %d %d", size, ints[i] ); | 302 | qWarning("size %d %d", size, ints[i] ); |
303 | search[size] = ints[i]; | 303 | search[size] = ints[i]; |
304 | size++; | 304 | size++; |
305 | } | 305 | } |
306 | break; | 306 | break; |
307 | /* reverse */ | 307 | /* reverse */ |
308 | case 1: | 308 | case 1: |
309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
310 | search[size] = ints[i]; | 310 | search[size] = ints[i]; |
311 | size++; | 311 | size++; |
312 | } | 312 | } |
313 | break; | 313 | break; |
314 | } | 314 | } |
315 | search.resize( size ); | 315 | search.resize( size ); |
316 | FindQuery query( search ); | 316 | FindQuery query( search ); |
317 | OSQLResult res = m_driver->query( &query ); | 317 | OSQLResult res = m_driver->query( &query ); |
318 | if ( res.state() != OSQLResult::Success ) | 318 | if ( res.state() != OSQLResult::Success ) |
319 | return to; | 319 | return to; |
320 | 320 | ||
321 | return todo( res ); | 321 | return todo( res ); |
322 | } | 322 | } |
323 | void OTodoAccessBackendSQL::clear() { | 323 | void OTodoAccessBackendSQL::clear() { |
324 | ClearQuery cle; | 324 | ClearQuery cle; |
325 | OSQLResult res = m_driver->query( &cle ); | 325 | OSQLResult res = m_driver->query( &cle ); |
326 | CreateQuery qu; | 326 | CreateQuery qu; |
327 | res = m_driver->query(&qu); | 327 | res = m_driver->query(&qu); |
328 | } | 328 | } |
329 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 329 | bool OTodoAccessBackendSQL::add( const OTodo& t) { |
330 | InsertQuery ins( t ); | 330 | InsertQuery ins( t ); |
331 | OSQLResult res = m_driver->query( &ins ); | 331 | OSQLResult res = m_driver->query( &ins ); |
332 | 332 | ||
333 | if ( res.state() == OSQLResult::Failure ) | 333 | if ( res.state() == OSQLResult::Failure ) |
334 | return false; | 334 | return false; |
335 | int c = m_uids.count(); | 335 | int c = m_uids.count(); |
336 | m_uids.resize( c+1 ); | 336 | m_uids.resize( c+1 ); |
337 | m_uids[c] = t.uid(); | 337 | m_uids[c] = t.uid(); |
338 | 338 | ||
339 | return true; | 339 | return true; |
340 | } | 340 | } |
341 | bool OTodoAccessBackendSQL::remove( int uid ) { | 341 | bool OTodoAccessBackendSQL::remove( int uid ) { |
342 | RemoveQuery rem( uid ); | 342 | RemoveQuery rem( uid ); |
343 | OSQLResult res = m_driver->query(&rem ); | 343 | OSQLResult res = m_driver->query(&rem ); |
344 | 344 | ||
345 | if ( res.state() == OSQLResult::Failure ) | 345 | if ( res.state() == OSQLResult::Failure ) |
346 | return false; | 346 | return false; |
347 | 347 | ||
348 | m_dirty = true; | 348 | m_dirty = true; |
349 | return true; | 349 | return true; |
350 | } | 350 | } |
351 | /* | 351 | /* |
352 | * FIXME better set query | 352 | * FIXME better set query |
353 | * but we need the cache for that | 353 | * but we need the cache for that |
354 | * now we remove | 354 | * now we remove |
355 | */ | 355 | */ |
356 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 356 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
357 | remove( t.uid() ); | 357 | remove( t.uid() ); |
358 | bool b= add(t); | 358 | bool b= add(t); |
359 | m_dirty = false; // we changed some stuff but the UID stayed the same | 359 | m_dirty = false; // we changed some stuff but the UID stayed the same |
360 | return b; | 360 | return b; |
361 | } | 361 | } |
362 | QArray<int> OTodoAccessBackendSQL::overDue() { | 362 | QArray<int> OTodoAccessBackendSQL::overDue() { |
363 | OverDueQuery qu; | 363 | OverDueQuery qu; |
364 | return uids( m_driver->query(&qu ) ); | 364 | return uids( m_driver->query(&qu ) ); |
365 | } | 365 | } |
366 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 366 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
367 | const QDate& t, | 367 | const QDate& t, |
368 | bool u) { | 368 | bool u) { |
369 | EffQuery ef(s, t, u ); | 369 | EffQuery ef(s, t, u ); |
370 | return uids (m_driver->query(&ef) ); | 370 | return uids (m_driver->query(&ef) ); |
371 | } | 371 | } |
372 | /* | 372 | /* |
373 | * | 373 | * |
374 | */ | 374 | */ |
375 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 375 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
376 | int sortFilter, int cat ) { | 376 | int sortFilter, int cat ) { |
377 | qWarning("sorted %d, %d", asc, sortOrder ); | 377 | qWarning("sorted %d, %d", asc, sortOrder ); |
378 | QString query; | 378 | QString query; |
379 | query = "select uid from todolist WHERE "; | 379 | query = "select uid from todolist WHERE "; |
380 | 380 | ||
381 | /* | 381 | /* |
382 | * Sort Filter stuff | 382 | * Sort Filter stuff |
383 | * not that straight forward | 383 | * not that straight forward |
384 | * | 384 | * |
385 | */ | 385 | */ |
386 | /* Category */ | 386 | /* Category */ |
387 | if ( sortFilter & 1 ) { | 387 | if ( sortFilter & 1 ) { |
388 | QString str; | 388 | QString str; |
389 | if (cat != 0 ) str = QString::number( cat ); | 389 | if (cat != 0 ) str = QString::number( cat ); |
390 | query += " categories like '%" +str+"%' AND"; | 390 | query += " categories like '%" +str+"%' AND"; |
391 | } | 391 | } |
392 | /* Show only overdue */ | 392 | /* Show only overdue */ |
393 | if ( sortFilter & 2 ) { | 393 | if ( sortFilter & 2 ) { |
394 | QDate date = QDate::currentDate(); | 394 | QDate date = QDate::currentDate(); |
395 | QString due; | 395 | QString due; |
396 | QString base; | 396 | QString base; |
397 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | 397 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); |
398 | query += " " + base + " AND"; | 398 | query += " " + base + " AND"; |
399 | } | 399 | } |
400 | /* not show completed */ | 400 | /* not show completed */ |
401 | if ( sortFilter & 4 ) { | 401 | if ( sortFilter & 4 ) { |
402 | query += " completed = 0 AND"; | 402 | query += " completed = 0 AND"; |
403 | }else{ | 403 | }else{ |
404 | query += " ( completed = 1 OR completed = 0) AND"; | 404 | query += " ( completed = 1 OR completed = 0) AND"; |
405 | } | 405 | } |
406 | /* srtip the end */ | 406 | /* srtip the end */ |
407 | query = query.remove( query.length()-3, 3 ); | 407 | query = query.remove( query.length()-3, 3 ); |
408 | 408 | ||
409 | 409 | ||
410 | /* | 410 | /* |
411 | * sort order stuff | 411 | * sort order stuff |
412 | * quite straight forward | 412 | * quite straight forward |
413 | */ | 413 | */ |
414 | query += "ORDER BY "; | 414 | query += "ORDER BY "; |
415 | switch( sortOrder ) { | 415 | switch( sortOrder ) { |
416 | /* completed */ | 416 | /* completed */ |
417 | case 0: | 417 | case 0: |
418 | query += "completed"; | 418 | query += "completed"; |
419 | break; | 419 | break; |
420 | case 1: | 420 | case 1: |
421 | query += "priority"; | 421 | query += "priority"; |
422 | break; | 422 | break; |
423 | case 2: | 423 | case 2: |
424 | query += "description"; | 424 | query += "summary"; |
425 | break; | 425 | break; |
426 | case 3: | 426 | case 3: |
427 | query += "DueDate"; | 427 | query += "DueDate"; |
428 | break; | 428 | break; |
429 | } | 429 | } |
430 | 430 | ||
431 | if ( !asc ) { | 431 | if ( !asc ) { |
432 | qWarning("not ascending!"); | 432 | qWarning("not ascending!"); |
433 | query += " DESC"; | 433 | query += " DESC"; |
434 | } | 434 | } |
435 | 435 | ||
436 | qWarning( query ); | 436 | qWarning( query ); |
437 | OSQLRawQuery raw(query ); | 437 | OSQLRawQuery raw(query ); |
438 | return uids( m_driver->query(&raw) ); | 438 | return uids( m_driver->query(&raw) ); |
439 | } | 439 | } |
440 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 440 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
441 | if ( str == "0-0-0" ) | 441 | if ( str == "0-0-0" ) |
442 | return false; | 442 | return false; |
443 | else{ | 443 | else{ |
444 | int day, year, month; | 444 | int day, year, month; |
445 | QStringList list = QStringList::split("-", str ); | 445 | QStringList list = QStringList::split("-", str ); |
446 | year = list[0].toInt(); | 446 | year = list[0].toInt(); |
447 | month = list[1].toInt(); | 447 | month = list[1].toInt(); |
448 | day = list[2].toInt(); | 448 | day = list[2].toInt(); |
449 | da.setYMD( year, month, day ); | 449 | da.setYMD( year, month, day ); |
450 | return true; | 450 | return true; |
451 | } | 451 | } |
452 | } | 452 | } |
453 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 453 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
454 | if ( res.state() == OSQLResult::Failure ) { | 454 | if ( res.state() == OSQLResult::Failure ) { |
455 | OTodo to; | 455 | OTodo to; |
456 | return to; | 456 | return to; |
457 | } | 457 | } |
458 | 458 | ||
459 | OSQLResultItem::ValueList list = res.results(); | 459 | OSQLResultItem::ValueList list = res.results(); |
460 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 460 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
461 | qWarning("todo1"); | 461 | qWarning("todo1"); |
462 | OTodo to = todo( (*it) ); | 462 | OTodo to = todo( (*it) ); |
463 | cache( to ); | 463 | cache( to ); |
464 | ++it; | 464 | ++it; |
465 | 465 | ||
466 | for ( ; it != list.end(); ++it ) { | 466 | for ( ; it != list.end(); ++it ) { |
467 | qWarning("caching"); | 467 | qWarning("caching"); |
468 | cache( todo( (*it) ) ); | 468 | cache( todo( (*it) ) ); |
469 | } | 469 | } |
470 | return to; | 470 | return to; |
471 | } | 471 | } |
472 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 472 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
473 | qWarning("todo"); | 473 | qWarning("todo"); |
474 | bool has = false; QDate da = QDate::currentDate(); | 474 | bool has = false; QDate da = QDate::currentDate(); |
475 | has = date( da, item.data("DueDate") ); | 475 | has = date( da, item.data("DueDate") ); |
476 | QStringList cats = QStringList::split(";", item.data("categories") ); | 476 | QStringList cats = QStringList::split(";", item.data("categories") ); |
477 | 477 | ||
478 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 478 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
479 | cats, item.data("summary"), item.data("description"), | 479 | cats, item.data("summary"), item.data("description"), |
480 | item.data("progress").toUShort(), has, da, | 480 | item.data("progress").toUShort(), has, da, |
481 | item.data("uid").toInt() ); | 481 | item.data("uid").toInt() ); |
482 | return to; | 482 | return to; |
483 | } | 483 | } |
484 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 484 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
485 | FindQuery find( uid ); | 485 | FindQuery find( uid ); |
486 | return todo( m_driver->query(&find) ); | 486 | return todo( m_driver->query(&find) ); |
487 | } | 487 | } |
488 | /* | 488 | /* |
489 | * update the dict | 489 | * update the dict |
490 | */ | 490 | */ |
491 | void OTodoAccessBackendSQL::fillDict() { | 491 | void OTodoAccessBackendSQL::fillDict() { |
492 | /* initialize dict */ | 492 | /* initialize dict */ |
493 | /* | 493 | /* |
494 | * UPDATE dict if you change anything!!! | 494 | * UPDATE dict if you change anything!!! |
495 | */ | 495 | */ |
496 | m_dict.setAutoDelete( TRUE ); | 496 | m_dict.setAutoDelete( TRUE ); |
497 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 497 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
498 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 498 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
499 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 499 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
500 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 500 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
501 | m_dict.insert("Description" , new int(OTodo::Description) ); | 501 | m_dict.insert("Description" , new int(OTodo::Description) ); |
502 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 502 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
503 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 503 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
504 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 504 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
505 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 505 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
506 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 506 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
507 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 507 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
508 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 508 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
509 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 509 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
510 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 510 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
511 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 511 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
512 | } | 512 | } |
513 | /* | 513 | /* |
514 | * need to be const so let's fool the | 514 | * need to be const so let's fool the |
515 | * compiler :( | 515 | * compiler :( |
516 | */ | 516 | */ |
517 | void OTodoAccessBackendSQL::update()const { | 517 | void OTodoAccessBackendSQL::update()const { |
518 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | 518 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; |
519 | LoadQuery lo; | 519 | LoadQuery lo; |
520 | OSQLResult res = m_driver->query(&lo); | 520 | OSQLResult res = m_driver->query(&lo); |
521 | if ( res.state() != OSQLResult::Success ) | 521 | if ( res.state() != OSQLResult::Success ) |
522 | return; | 522 | return; |
523 | 523 | ||
524 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); | 524 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
525 | } | 525 | } |
526 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 526 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
527 | 527 | ||
528 | OSQLResultItem::ValueList list = res.results(); | 528 | OSQLResultItem::ValueList list = res.results(); |
529 | OSQLResultItem::ValueList::Iterator it; | 529 | OSQLResultItem::ValueList::Iterator it; |
530 | QArray<int> ints(list.count() ); | 530 | QArray<int> ints(list.count() ); |
531 | qWarning(" count = %d", list.count() ); | 531 | qWarning(" count = %d", list.count() ); |
532 | 532 | ||
533 | int i = 0; | 533 | int i = 0; |
534 | for (it = list.begin(); it != list.end(); ++it ) { | 534 | for (it = list.begin(); it != list.end(); ++it ) { |
535 | ints[i] = (*it).data("uid").toInt(); | 535 | ints[i] = (*it).data("uid").toInt(); |
536 | i++; | 536 | i++; |
537 | } | 537 | } |
538 | return ints; | 538 | return ints; |
539 | } | 539 | } |
540 | 540 | ||
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp new file mode 100644 index 0000000..6c81f8f --- a/dev/null +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -0,0 +1,127 @@ | |||
1 | #include <qshared.h> | ||
2 | |||
3 | #include <qtopia/timeconversion.h> | ||
4 | |||
5 | #include "orecur.h" | ||
6 | |||
7 | struct ORecur::Data : public QShared { | ||
8 | Data() : QShared() { | ||
9 | type = ORecur::NoRepeat; | ||
10 | freq = -1; | ||
11 | days = 0; | ||
12 | pos = 0; | ||
13 | create = -1; | ||
14 | hasEnd = FALSE; | ||
15 | end = 0; | ||
16 | } | ||
17 | char days; // Q_UINT8 for 8 seven days;) | ||
18 | ORecur::RepeatType type; | ||
19 | int freq; | ||
20 | int pos; | ||
21 | bool hasEnd : 1; | ||
22 | time_t end; | ||
23 | time_t create; | ||
24 | }; | ||
25 | |||
26 | |||
27 | ORecur::ORecur() { | ||
28 | data = new Data; | ||
29 | } | ||
30 | ORecur::ORecur( const ORecur& rec) | ||
31 | : data( rec.data ) | ||
32 | { | ||
33 | data->ref(); | ||
34 | } | ||
35 | ORecur::~ORecur() { | ||
36 | if ( data->deref() ) { | ||
37 | delete data; | ||
38 | data = 0l; | ||
39 | } | ||
40 | } | ||
41 | void ORecur::deref() { | ||
42 | if ( data->deref() ) { | ||
43 | delete data; | ||
44 | data = 0l; | ||
45 | } | ||
46 | } | ||
47 | bool ORecur::operator==( const ORecur& )const { | ||
48 | return false; | ||
49 | } | ||
50 | ORecur &ORecur::operator=( const ORecur& re) { | ||
51 | re.data->ref(); | ||
52 | deref(); | ||
53 | data = re.data; | ||
54 | |||
55 | return *this; | ||
56 | } | ||
57 | ORecur::RepeatType ORecur::type()const{ | ||
58 | return data->type; | ||
59 | } | ||
60 | int ORecur::frequency()const { | ||
61 | return data->freq; | ||
62 | } | ||
63 | int ORecur::position()const { | ||
64 | return data->pos; | ||
65 | } | ||
66 | char ORecur::days() const{ | ||
67 | return data->days; | ||
68 | } | ||
69 | bool ORecur::hasEndDate()const { | ||
70 | return data->hasEnd; | ||
71 | } | ||
72 | QDate ORecur::endDate()const { | ||
73 | return TimeConversion::fromUTC( data->end ).date(); | ||
74 | } | ||
75 | time_t ORecur::endDateUTC()const { | ||
76 | return data->end; | ||
77 | } | ||
78 | time_t ORecur::createTime()const { | ||
79 | return data->create; | ||
80 | } | ||
81 | void ORecur::setType( const RepeatType& z) { | ||
82 | checkOrModify(); | ||
83 | data->type = z; | ||
84 | } | ||
85 | void ORecur::setFrequency( int freq ) { | ||
86 | checkOrModify(); | ||
87 | data->freq = freq; | ||
88 | } | ||
89 | void ORecur::setPosition( int pos ) { | ||
90 | checkOrModify(); | ||
91 | data->pos = pos; | ||
92 | } | ||
93 | void ORecur::setDays( char c ) { | ||
94 | checkOrModify(); | ||
95 | data->days = c; | ||
96 | } | ||
97 | void ORecur::setEndDate( const QDate& dt) { | ||
98 | checkOrModify(); | ||
99 | data->end = TimeConversion::toUTC( dt ); | ||
100 | } | ||
101 | void ORecur::setEndDateUTC( time_t t) { | ||
102 | checkOrModify(); | ||
103 | data->end = t; | ||
104 | } | ||
105 | void ORecur::setCreateTime( time_t t) { | ||
106 | checkOrModify(); | ||
107 | data->create = t; | ||
108 | } | ||
109 | void ORecur::setHasEndDate( bool b) { | ||
110 | checkOrModify(); | ||
111 | data->hasEnd = b; | ||
112 | } | ||
113 | void ORecur::checkOrModify() { | ||
114 | if ( data->count != 1 ) { | ||
115 | data->deref(); | ||
116 | Data* d2 = new Data; | ||
117 | d2->days = data->days; | ||
118 | d2->type = data->type; | ||
119 | d2->freq = data->freq; | ||
120 | d2->pos = data->pos; | ||
121 | d2->hasEnd = data->hasEnd; | ||
122 | d2->end = data->end; | ||
123 | d2->create = data->create; | ||
124 | data = d2; | ||
125 | } | ||
126 | } | ||
127 | |||
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h new file mode 100644 index 0000000..89258f8 --- a/dev/null +++ b/libopie2/opiepim/core/orecur.h | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * GPL from TT | ||
3 | */ | ||
4 | |||
5 | #ifndef OPIE_RECUR_H | ||
6 | #define OPIE_RECUR_H | ||
7 | |||
8 | #include <sys/types.h> | ||
9 | |||
10 | #include <qdatetime.h> | ||
11 | |||
12 | |||
13 | |||
14 | class ORecur { | ||
15 | public: | ||
16 | enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, | ||
17 | MonthlyDate, Yearly }; | ||
18 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, | ||
19 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; | ||
20 | ORecur(); | ||
21 | ORecur( const ORecur& ); | ||
22 | ~ORecur(); | ||
23 | |||
24 | ORecur &operator=( const ORecur& ); | ||
25 | bool operator==(const ORecur& )const; | ||
26 | RepeatType type()const; | ||
27 | int frequency()const; | ||
28 | int position()const; | ||
29 | char days()const; | ||
30 | bool hasEndDate()const; | ||
31 | QDate endDate()const; | ||
32 | time_t endDateUTC()const; | ||
33 | time_t createTime()const; | ||
34 | |||
35 | void setType( const RepeatType& ); | ||
36 | void setFrequency( int freq ); | ||
37 | void setPosition( int pos ); | ||
38 | void setDays( char c); | ||
39 | void setEndDate( const QDate& dt ); | ||
40 | void setEndDateUTC( time_t ); | ||
41 | void setCreateTime( time_t ); | ||
42 | void setHasEndDate( bool b ); | ||
43 | private: | ||
44 | void deref(); | ||
45 | inline void checkOrModify(); | ||
46 | |||
47 | |||
48 | class Data; | ||
49 | Data* data; | ||
50 | class ORecurPrivate; | ||
51 | ORecurPrivate *d; | ||
52 | }; | ||
53 | |||
54 | #endif | ||
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 5404910..e377447 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -135,136 +135,138 @@ ORecordListIterator<T>::~ORecordListIterator() { | |||
135 | /* nothing to delete */ | 135 | /* nothing to delete */ |
136 | } | 136 | } |
137 | 137 | ||
138 | template <class T> | 138 | template <class T> |
139 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 139 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
140 | // qWarning("ORecordListIterator copy c'tor"); | 140 | // qWarning("ORecordListIterator copy c'tor"); |
141 | m_uids = it.m_uids; | 141 | m_uids = it.m_uids; |
142 | m_current = it.m_current; | 142 | m_current = it.m_current; |
143 | m_temp = it.m_temp; | 143 | m_temp = it.m_temp; |
144 | m_end = it.m_end; | 144 | m_end = it.m_end; |
145 | m_record = it.m_record; | 145 | m_record = it.m_record; |
146 | m_direction = it.m_direction; | 146 | m_direction = it.m_direction; |
147 | } | 147 | } |
148 | 148 | ||
149 | template <class T> | 149 | template <class T> |
150 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 150 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
151 | m_uids = it.m_uids; | 151 | m_uids = it.m_uids; |
152 | m_current = it.m_current; | 152 | m_current = it.m_current; |
153 | m_temp = it.m_temp; | 153 | m_temp = it.m_temp; |
154 | m_end = it.m_end; | 154 | m_end = it.m_end; |
155 | m_record = it.m_record; | 155 | m_record = it.m_record; |
156 | 156 | ||
157 | return *this; | 157 | return *this; |
158 | } | 158 | } |
159 | 159 | ||
160 | template <class T> | 160 | template <class T> |
161 | T ORecordListIterator<T>::operator*() { | 161 | T ORecordListIterator<T>::operator*() { |
162 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 162 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
163 | if (!m_end ) | 163 | if (!m_end ) |
164 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 164 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
165 | m_direction ? Base::Forward : | 165 | m_direction ? Base::Forward : |
166 | Base::Reverse ); | 166 | Base::Reverse ); |
167 | else | 167 | else |
168 | m_record = T(); | 168 | m_record = T(); |
169 | 169 | ||
170 | return m_record; | 170 | return m_record; |
171 | } | 171 | } |
172 | 172 | ||
173 | template <class T> | 173 | template <class T> |
174 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 174 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
175 | m_direction = true; | 175 | m_direction = true; |
176 | if (m_current < m_uids.count() ) { | 176 | if (m_current < m_uids.count() ) { |
177 | m_end = false; | 177 | m_end = false; |
178 | ++m_current; | 178 | ++m_current; |
179 | }else | 179 | }else |
180 | m_end = true; | 180 | m_end = true; |
181 | 181 | ||
182 | return *this; | 182 | return *this; |
183 | } | 183 | } |
184 | template <class T> | 184 | template <class T> |
185 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 185 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
186 | m_direction = false; | 186 | m_direction = false; |
187 | if ( m_current > 0 ) { | 187 | if ( m_current > 0 ) { |
188 | --m_current; | 188 | --m_current; |
189 | m_end = false; | 189 | m_end = false; |
190 | } else | 190 | } else |
191 | m_end = true; | 191 | m_end = true; |
192 | 192 | ||
193 | return *this; | 193 | return *this; |
194 | } | 194 | } |
195 | 195 | ||
196 | template <class T> | 196 | template <class T> |
197 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 197 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
198 | 198 | ||
199 | /* if both are at we're the same.... */ | 199 | /* if both are at we're the same.... */ |
200 | if ( m_end == it.m_end ) return true; | 200 | if ( m_end == it.m_end ) return true; |
201 | 201 | ||
202 | if ( m_uids != it.m_uids ) return false; | 202 | if ( m_uids != it.m_uids ) return false; |
203 | if ( m_current != it.m_current ) return false; | 203 | if ( m_current != it.m_current ) return false; |
204 | if ( m_temp != it.m_temp ) return false; | 204 | if ( m_temp != it.m_temp ) return false; |
205 | 205 | ||
206 | return true; | 206 | return true; |
207 | } | 207 | } |
208 | template <class T> | 208 | template <class T> |
209 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 209 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
210 | return !(*this == it ); | 210 | return !(*this == it ); |
211 | } | 211 | } |
212 | template <class T> | 212 | template <class T> |
213 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 213 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
214 | const Base* t ) | 214 | const Base* t ) |
215 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 215 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
216 | m_direction( false ) | 216 | m_direction( false ) |
217 | { | 217 | { |
218 | } | 218 | } |
219 | template <class T> | 219 | template <class T> |
220 | uint ORecordListIterator<T>::current()const { | 220 | uint ORecordListIterator<T>::current()const { |
221 | return m_current; | 221 | return m_current; |
222 | } | 222 | } |
223 | template <class T> | 223 | template <class T> |
224 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 224 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
225 | if( cur < m_uids.count() ) { | 225 | if( cur < m_uids.count() ) { |
226 | m_end = false; | 226 | m_end = false; |
227 | m_current= cur; | 227 | m_current= cur; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | template <class T> | 230 | template <class T> |
231 | uint ORecordListIterator<T>::count()const { | 231 | uint ORecordListIterator<T>::count()const { |
232 | return m_uids.count(); | 232 | return m_uids.count(); |
233 | } | 233 | } |
234 | template <class T> | 234 | template <class T> |
235 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 235 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
236 | const Base* acc ) | 236 | const Base* acc ) |
237 | : m_ids( ids ), m_acc( acc ) | 237 | : m_ids( ids ), m_acc( acc ) |
238 | { | 238 | { |
239 | } | 239 | } |
240 | template <class T> | 240 | template <class T> |
241 | ORecordList<T>::~ORecordList() { | 241 | ORecordList<T>::~ORecordList() { |
242 | /* nothing to do here */ | 242 | /* nothing to do here */ |
243 | } | 243 | } |
244 | template <class T> | 244 | template <class T> |
245 | ORecordList<T>::Iterator ORecordList<T>::begin() { | 245 | ORecordList<T>::Iterator ORecordList<T>::begin() { |
246 | Iterator it( m_ids, m_acc ); | 246 | Iterator it( m_ids, m_acc ); |
247 | return it; | 247 | return it; |
248 | } | 248 | } |
249 | template <class T> | 249 | template <class T> |
250 | ORecordList<T>::Iterator ORecordList<T>::end() { | 250 | ORecordList<T>::Iterator ORecordList<T>::end() { |
251 | Iterator it( m_ids, m_acc ); | 251 | Iterator it( m_ids, m_acc ); |
252 | it.m_end = true; | 252 | it.m_end = true; |
253 | it.m_current = m_ids.count(); | 253 | it.m_current = m_ids.count(); |
254 | 254 | ||
255 | return it; | 255 | return it; |
256 | } | 256 | } |
257 | template <class T> | 257 | template <class T> |
258 | uint ORecordList<T>::count()const { | 258 | uint ORecordList<T>::count()const { |
259 | return m_ids.count(); | 259 | return m_ids.count(); |
260 | } | 260 | } |
261 | template <class T> | 261 | template <class T> |
262 | T ORecordList<T>::operator[]( uint i ) { | 262 | T ORecordList<T>::operator[]( uint i ) { |
263 | if ( i < 0 || (i+1) > m_ids.count() ) | ||
264 | return T(); | ||
263 | /* forward */ | 265 | /* forward */ |
264 | return m_acc->find( m_ids[i], m_ids, i ); | 266 | return m_acc->find( m_ids[i], m_ids, i ); |
265 | } | 267 | } |
266 | template <class T> | 268 | template <class T> |
267 | int ORecordList<T>::uidAt( uint i ) { | 269 | int ORecordList<T>::uidAt( uint i ) { |
268 | return m_ids[i]; | 270 | return m_ids[i]; |
269 | } | 271 | } |
270 | #endif | 272 | #endif |