summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ChangeLog4
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h4
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp29
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.h2
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp27
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.h15
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h6
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.cpp32
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.h15
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp34
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h2
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp5
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h1
13 files changed, 134 insertions, 42 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog
index 564e92a..2007744 100644
--- a/libopie2/opiepim/ChangeLog
+++ b/libopie2/opiepim/ChangeLog
@@ -1,21 +1,23 @@
12004-12-28 Stefan Eilers <stefan@eilers-online.net> 12004-12-28 Stefan Eilers <stefan@eilers-online.net>
2 * Make improved query by example accessable via frontend 2 * Make improved query by example accessable via frontend
3 * Some API improvement 3 * Some API documentation improvement
4 * Cleanup of backend api..
5 * Fixing bug #1501
42004-11-23 Stefan Eilers <stefan@eilers-online.net> 62004-11-23 Stefan Eilers <stefan@eilers-online.net>
5 * Implement fast and full featured version of sorted() for addressbook 7 * Implement fast and full featured version of sorted() for addressbook
6 * Implement generic queryByExample for all Addressboook backends. It allows incremental search. 8 * Implement generic queryByExample for all Addressboook backends. It allows incremental search.
7 * Update of API Documentation 9 * Update of API Documentation
82004-11-18 Holger Freyther <freyther@handhelds.org> 102004-11-18 Holger Freyther <freyther@handhelds.org>
9 * Every Access can give a set of Occurrences for a period or a datetime 11 * Every Access can give a set of Occurrences for a period or a datetime
10 * QueryByExample, Find, Sort can be generically accessed by OPimBase 12 * QueryByExample, Find, Sort can be generically accessed by OPimBase
11 pointer interface 13 pointer interface
12 * OPimBackendOccurrence gets split up to OPimOccurrences by 14 * OPimBackendOccurrence gets split up to OPimOccurrences by
13 OPimTemplateBase 15 OPimTemplateBase
14 * Add safeCast to various OPimRecords 16 * Add safeCast to various OPimRecords
15 * Kill memleak in OPimTodo 17 * Kill memleak in OPimTodo
16 * Add SortVector implementations for OPimTodo and OPimContact 18 * Add SortVector implementations for OPimTodo and OPimContact
17 19
18 2004-??-??The Opie Team <opie@handhelds.org> 20 2004-??-??The Opie Team <opie@handhelds.org>
19 * Implemented some important modifications to allow to use OPimRecords as it is, without 21 * Implemented some important modifications to allow to use OPimRecords as it is, without
20 have to cast them. This makes it possible to write applications which handling pim 22 have to cast them. This makes it possible to write applications which handling pim
21 data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file 23 data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h
index ee6dbc2..27d70ab 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.h
@@ -35,77 +35,77 @@
35 * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) 35 * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
36 * 36 *
37 */ 37 */
38 38
39#ifndef _OCONTACTACCESSBACKEND_H_ 39#ifndef _OCONTACTACCESSBACKEND_H_
40#define _OCONTACTACCESSBACKEND_H_ 40#define _OCONTACTACCESSBACKEND_H_
41 41
42#include <opie2/opimcontact.h> 42#include <opie2/opimcontact.h>
43#include <opie2/opimaccessbackend.h> 43#include <opie2/opimaccessbackend.h>
44 44
45#include <qregexp.h> 45#include <qregexp.h>
46 46
47namespace Opie { 47namespace Opie {
48/** 48/**
49 * This class represents the interface of all Contact Backends. 49 * This class represents the interface of all Contact Backends.
50 * Derivates of this class will be used to access the contacts. 50 * Derivates of this class will be used to access the contacts.
51 * As implementation currently XML and vCard exist. This class needs to be implemented 51 * As implementation currently XML and vCard exist. This class needs to be implemented
52 * if you want to provide your own storage. 52 * if you want to provide your own storage.
53 * In all queries a list of uids is passed on instead of loading the actual record! 53 * In all queries a list of uids is passed on instead of loading the actual record!
54 * 54 *
55 * @see OPimContactAccessBackend_VCard 55 * @see OPimContactAccessBackend_VCard
56 * @see OPimContactAccessBackend_XML 56 * @see OPimContactAccessBackend_XML
57 */ 57 */
58class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> { 58class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> {
59 public: 59 public:
60 OPimContactAccessBackend(); 60 OPimContactAccessBackend();
61 61
62 62
63 /** 63 /**
64 * Return if database was changed externally. 64 * Return if database was changed externally.
65 * This may just make sense on file based databases like a XML-File. 65 * This may just make sense on file based databases like a XML-File.
66 * It is used to prevent to overwrite the current database content 66 * It is used to prevent to overwrite the current database content
67 * if the file was already changed by something else ! 67 * if the file was already changed by something else !
68 * If this happens, we have to reload before save our data. 68 * If this happens, we have to reload before save our data.
69 * If we use real databases, this should be handled by the database 69 * If we use real databases, this should be handled by the database
70 * management system themselve, therefore this function should always return false in 70 * management system themselve, therefore this function should always return false in
71 * this case. It is not our problem to handle this conflict ... 71 * this case. It is not our problem to handle this conflict ...
72 * @return <i>true</i> if the database was changed and if save without reload will 72 * @return <i>true</i> if the database was changed and if save without reload will
73 * be dangerous. <i>false</i> if the database was not changed or it is save to write 73 * be dangerous. <i>false</i> if the database was not changed or it is save to write
74 * in this situation. 74 * in this situation.
75 */ 75 */
76 virtual bool wasChangedExternally() = 0; 76 virtual bool wasChangedExternally() = 0;
77 77
78 /** 78 /**
79 * Return all possible settings. 79 * Return all possible settings.
80 * @return All settings provided by the current backend 80 * @return All settings provided by the current backend
81 * (i.e.: query_WildCards & query_IgnoreCase) 81 * (i.e.: query_WildCards & query_IgnoreCase)
82 */ 82 */
83 virtual const uint querySettings() const; 83 const uint querySettings() const;
84 84
85 /** 85 /**
86 * Check whether settings are correct. 86 * Check whether settings are correct.
87 * @return <i>true</i> if the given settings are correct and possible. 87 * @return <i>true</i> if the given settings are correct and possible.
88 */ 88 */
89 virtual bool hasQuerySettings (uint querySettings) const; 89 bool hasQuerySettings (uint querySettings) const;
90 90
91 /** 91 /**
92 * Advanced search mechanism. 92 * Advanced search mechanism.
93 */ 93 */
94 UIDArray queryByExample( const UIDArray& uidlist, const OPimContact&, int settings, const QDateTime &d = QDateTime() ) const; 94 UIDArray queryByExample( const UIDArray& uidlist, const OPimContact&, int settings, const QDateTime &d = QDateTime() ) const;
95 /** 95 /**
96 * Slow and inefficent default implementation 96 * Slow and inefficent default implementation
97 */ 97 */
98//@{ 98//@{
99 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; 99 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
100 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; 100 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const;
101//@} 101//@}
102 102
103 103
104private: 104private:
105 class Private; 105 class Private;
106 Private *d; 106 Private *d;
107}; 107};
108 108
109} 109}
110 110
111#endif 111#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index 9375f43..2368865 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -234,123 +234,125 @@ namespace {
234 } else { 234 } else {
235 day = m_contact.anniversary(); 235 day = m_contact.anniversary();
236 } 236 }
237 // These entries should stored in a special format 237 // These entries should stored in a special format
238 // year-month-day 238 // year-month-day
239 if ( day.isValid() ){ 239 if ( day.isValid() ){
240 qu += QString(",\"%1-%2-%3\"") 240 qu += QString(",\"%1-%2-%3\"")
241 .arg( QString::number( day.year() ).rightJustify( 4, '0' ) ) 241 .arg( QString::number( day.year() ).rightJustify( 4, '0' ) )
242 .arg( QString::number( day.month() ).rightJustify( 2, '0' ) ) 242 .arg( QString::number( day.month() ).rightJustify( 2, '0' ) )
243 .arg( QString::number( day.day() ).rightJustify( 2, '0' ) ); 243 .arg( QString::number( day.day() ).rightJustify( 2, '0' ) );
244 } else { 244 } else {
245 qu += ",\"\""; 245 qu += ",\"\"";
246 } 246 }
247 } 247 }
248 break; 248 break;
249 default: 249 default:
250 qu += QString( ",\"%1\"" ).arg( contactMap[id] ); 250 qu += QString( ",\"%1\"" ).arg( contactMap[id] );
251 } 251 }
252 } 252 }
253 qu += " );"; 253 qu += " );";
254 254
255 255
256 // Now add custom data.. 256 // Now add custom data..
257 int id = 0; 257 int id = 0;
258 id = 0; 258 id = 0;
259 QMap<QString, QString> customMap = m_contact.toExtraMap(); 259 QMap<QString, QString> customMap = m_contact.toExtraMap();
260 for( QMap<QString, QString>::Iterator it = customMap.begin(); 260 for( QMap<QString, QString>::Iterator it = customMap.begin();
261 it != customMap.end(); ++it ){ 261 it != customMap.end(); ++it ){
262 qu += "insert into custom_data VALUES(" 262 qu += "insert into custom_data VALUES("
263 + QString::number( m_contact.uid() ) 263 + QString::number( m_contact.uid() )
264 + "," 264 + ","
265 + QString::number( id++ ) 265 + QString::number( id++ )
266 + ",'" 266 + ",'"
267 + it.key() 267 + it.key()
268 + "'," 268 + "',"
269 + "0" // Priority for future enhancements 269 + "0" // Priority for future enhancements
270 + ",'" 270 + ",'"
271 + it.data() 271 + it.data()
272 + "');"; 272 + "');";
273 } 273 }
274 // qu += "commit;"; 274 // qu += "commit;";
275 odebug << "add " << qu << "" << oendl; 275 odebug << "add " << qu << "" << oendl;
276 return qu; 276 return qu;
277 } 277 }
278 278
279 279
280 RemoveQuery::RemoveQuery(int uid ) 280 RemoveQuery::RemoveQuery(int uid )
281 : OSQLQuery(), m_uid( uid ) {} 281 : OSQLQuery(), m_uid( uid ) {}
282
282 RemoveQuery::~RemoveQuery() {} 283 RemoveQuery::~RemoveQuery() {}
284
283 QString RemoveQuery::query()const { 285 QString RemoveQuery::query()const {
284 QString qu = "DELETE from addressbook where uid = " 286 QString qu = "DELETE from addressbook where uid = "
285 + QString::number(m_uid) + ";"; 287 + QString::number(m_uid) + ";";
286 qu += "DELETE from custom_data where uid = " 288 qu += "DELETE from custom_data where uid = "
287 + QString::number(m_uid) + ";"; 289 + QString::number(m_uid) + ";";
288 return qu; 290 return qu;
289 } 291 }
290 292
291 293
292
293
294 FindQuery::FindQuery(int uid) 294 FindQuery::FindQuery(int uid)
295 : OSQLQuery(), m_uid( uid ) { 295 : OSQLQuery(), m_uid( uid ) {
296 } 296 }
297 FindQuery::FindQuery(const UIDArray& ints) 297 FindQuery::FindQuery(const UIDArray& ints)
298 : OSQLQuery(), m_uids( ints ){ 298 : OSQLQuery(), m_uids( ints ){
299 } 299 }
300 FindQuery::~FindQuery() { 300 FindQuery::~FindQuery() {
301 } 301 }
302 QString FindQuery::query()const{ 302 QString FindQuery::query()const{
303 if ( m_uids.count() == 0 ) 303 if ( m_uids.count() == 0 )
304 return single(); 304 return single();
305 else 305 else
306 return multi(); 306 return multi();
307 } 307 }
308 308
309
310
309 QString FindQuery::multi()const { 311 QString FindQuery::multi()const {
310 QString qu = "select * from addressbook where"; 312 QString qu = "select * from addressbook where";
311 for (uint i = 0; i < m_uids.count(); i++ ) { 313 for (uint i = 0; i < m_uids.count(); i++ ) {
312 qu += " uid = " + QString::number( m_uids[i] ) + " OR"; 314 qu += " uid = " + QString::number( m_uids[i] ) + " OR";
313 } 315 }
314 qu.remove( qu.length()-2, 2 ); // Hmmmm.. 316 qu.remove( qu.length()-2, 2 ); // Hmmmm..
315 317
316 odebug << "find query: " << qu << "" << oendl; 318 odebug << "find query: " << qu << "" << oendl;
317 return qu; 319 return qu;
318 } 320 }
319 321
320 QString FindQuery::single()const{ 322 QString FindQuery::single()const{
321 QString qu = "select *"; 323 QString qu = "select *";
322 qu += " from addressbook where uid = " + QString::number(m_uid); 324 qu += " from addressbook where uid = " + QString::number(m_uid);
323 325
324 // owarn << "find query: " << qu << "" << oendl; 326 // owarn << "find query: " << qu << "" << oendl;
325 return qu; 327 return qu;
326 } 328 }
327 329
328 330
329 FindCustomQuery::FindCustomQuery(int uid) 331 FindCustomQuery::FindCustomQuery(int uid)
330 : OSQLQuery(), m_uid( uid ) { 332 : OSQLQuery(), m_uid( uid ) {
331 } 333 }
332 FindCustomQuery::FindCustomQuery(const UIDArray& ints) 334 FindCustomQuery::FindCustomQuery(const UIDArray& ints)
333 : OSQLQuery(), m_uids( ints ){ 335 : OSQLQuery(), m_uids( ints ){
334 } 336 }
335 FindCustomQuery::~FindCustomQuery() { 337 FindCustomQuery::~FindCustomQuery() {
336 } 338 }
337 QString FindCustomQuery::query()const{ 339 QString FindCustomQuery::query()const{
338// if ( m_uids.count() == 0 ) 340// if ( m_uids.count() == 0 )
339 return single(); 341 return single();
340 } 342 }
341 QString FindCustomQuery::single()const{ 343 QString FindCustomQuery::single()const{
342 QString qu = "select uid, type, value from custom_data where uid = "; 344 QString qu = "select uid, type, value from custom_data where uid = ";
343 qu += QString::number(m_uid); 345 qu += QString::number(m_uid);
344 return qu; 346 return qu;
345 } 347 }
346 348
347}; 349};
348 350
349 351
350/* --------------------------------------------------------------------------- */ 352/* --------------------------------------------------------------------------- */
351 353
352namespace Opie { 354namespace Opie {
353 355
354OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, 356OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */,
355 const QString& filename ): 357 const QString& filename ):
356 OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) 358 OPimContactAccessBackend(), m_changed(false), m_driver( NULL )
@@ -483,100 +485,113 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
483 485
484 odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl; 486 odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl;
485 return retContact; 487 return retContact;
486} 488}
487 489
488OPimContact OPimContactAccessBackend_SQL::find( int uid, const UIDArray& queryUids, uint current, Frontend::CacheDirection direction ) const 490OPimContact OPimContactAccessBackend_SQL::find( int uid, const UIDArray& queryUids, uint current, Frontend::CacheDirection direction ) const
489{ 491{
490 odebug << "OPimContactAccessBackend_SQL::find( ..multi.. )" << oendl; 492 odebug << "OPimContactAccessBackend_SQL::find( ..multi.. )" << oendl;
491 odebug << "searching for " << uid << "" << oendl; 493 odebug << "searching for " << uid << "" << oendl;
492 494
493 QTime t; 495 QTime t;
494 t.start(); 496 t.start();
495 497
496 uint numReadAhead = readAhead(); 498 uint numReadAhead = readAhead();
497 QArray<int> searchList( numReadAhead ); 499 QArray<int> searchList( numReadAhead );
498 500
499 uint size =0; 501 uint size =0;
500 502
501 // Build an array with all elements which should be requested and cached 503 // Build an array with all elements which should be requested and cached
502 // We will just request "numReadAhead" elements, starting from "current" position in 504 // We will just request "numReadAhead" elements, starting from "current" position in
503 // the list of many uids ! 505 // the list of many uids !
504 switch( direction ) { 506 switch( direction ) {
505 /* forward */ 507 /* forward */
506 case Frontend::Forward: 508 case Frontend::Forward:
507 for ( uint i = current; i < queryUids.count() && size < numReadAhead; i++ ) { 509 for ( uint i = current; i < queryUids.count() && size < numReadAhead; i++ ) {
508 searchList[size] = queryUids[i]; 510 searchList[size] = queryUids[i];
509 size++; 511 size++;
510 } 512 }
511 break; 513 break;
512 /* reverse */ 514 /* reverse */
513 case Frontend::Reverse: 515 case Frontend::Reverse:
514 for ( uint i = current; i != 0 && size < numReadAhead; i-- ) { 516 for ( uint i = current; i != 0 && size < numReadAhead; i-- ) {
515 searchList[size] = queryUids[i]; 517 searchList[size] = queryUids[i];
516 size++; 518 size++;
517 } 519 }
518 break; 520 break;
519 } 521 }
520 522
521 //Shrink to real size.. 523 //Shrink to real size..
522 searchList.resize( size ); 524 searchList.resize( size );
523 525
524 OPimContact retContact( requestContactsAndCache( uid, searchList ) ); 526 OPimContact retContact( requestContactsAndCache( uid, searchList ) );
525 527
526 odebug << "OPimContactAccessBackend_SQL::find( ..multi.. ) needed: " << t.elapsed() << " ms" << oendl; 528 odebug << "OPimContactAccessBackend_SQL::find( ..multi.. ) needed: " << t.elapsed() << " ms" << oendl;
527 return retContact; 529 return retContact;
528} 530}
529 531
530 532
531UIDArray OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, 533UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, const OPimContact &query, int settings,
532 const QDateTime& qd ) const 534 const QDateTime& qd ) const
533{ 535{
534 QString qu = "SELECT uid FROM addressbook WHERE"; 536 QString qu = "SELECT uid FROM addressbook WHERE";
537
538 // Just add uid's selection if we really try to search in a subset of all uids! Otherwise this would
539 // just take time and memory!
540 if ( uidlist.count() != m_uids.count() ) {
541 qu += " (";
542
543 for ( uint i = 0; i < uidlist.count(); i++ ) {
544 qu += " uid = " + QString::number( uidlist[i] ) + " OR";
545 }
546 qu.remove( qu.length()-2, 2 ); // Hmmmm..
547 qu += " ) AND ";
548 }
549
535 QString searchQuery =""; 550 QString searchQuery ="";
536 551
537 QDate startDate; 552 QDate startDate;
538 553
539 if ( qd.isValid() ) 554 if ( qd.isValid() )
540 startDate = qd.date(); 555 startDate = qd.date();
541 else 556 else
542 startDate = QDate::currentDate(); 557 startDate = QDate::currentDate();
543 558
544 559
545 QMap<int, QString> queryFields = query.toMap(); 560 QMap<int, QString> queryFields = query.toMap();
546 QStringList fieldList = OPimContactFields::untrfields( false ); 561 QStringList fieldList = OPimContactFields::untrfields( false );
547 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 562 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
548 563
549 // Convert every filled field to a SQL-Query 564 // Convert every filled field to a SQL-Query
550// bool isAnyFieldSelected = false; 565// bool isAnyFieldSelected = false;
551 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 566 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
552 567
553 int id = translate[*it]; 568 int id = translate[*it];
554 QString queryStr = queryFields[id]; 569 QString queryStr = queryFields[id];
555 QDate* endDate = 0l; 570 QDate* endDate = 0l;
556 571
557 if ( !queryStr.isEmpty() ){ 572 if ( !queryStr.isEmpty() ){
558 // If something is alredy stored in the query, add an "AND" 573 // If something is alredy stored in the query, add an "AND"
559 // to the end of the string to prepare for the next .. 574 // to the end of the string to prepare for the next ..
560 if ( !searchQuery.isEmpty() ) 575 if ( !searchQuery.isEmpty() )
561 searchQuery += " AND"; 576 searchQuery += " AND";
562 577
563// isAnyFieldSelected = true; 578// isAnyFieldSelected = true;
564 switch( id ){ 579 switch( id ){
565 case Qtopia::Birthday: 580 case Qtopia::Birthday:
566 endDate = new QDate( query.birthday() ); 581 endDate = new QDate( query.birthday() );
567 // Fall through ! 582 // Fall through !
568 case Qtopia::Anniversary: 583 case Qtopia::Anniversary:
569 if ( endDate == 0l ) 584 if ( endDate == 0l )
570 endDate = new QDate( query.anniversary() ); 585 endDate = new QDate( query.anniversary() );
571 586
572 if ( settings & OPimContactAccess::DateDiff ) { 587 if ( settings & OPimContactAccess::DateDiff ) {
573 searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) 588 searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" )
574 .arg( *it ) 589 .arg( *it )
575 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) 590 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) )
576 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) 591 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) )
577 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) 592 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) )
578 .arg( *it ) 593 .arg( *it )
579 .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) 594 .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) )
580 .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) 595 .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) )
581 .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; 596 .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ;
582 } 597 }
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
index 299c175..1cf1185 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
@@ -30,86 +30,86 @@
30 * SQL Backend for the OPIE-Contact Database. 30 * SQL Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33#ifndef _OPimContactAccessBackend_SQL_ 33#ifndef _OPimContactAccessBackend_SQL_
34#define _OPimContactAccessBackend_SQL_ 34#define _OPimContactAccessBackend_SQL_
35 35
36#include <opie2/ocontactaccessbackend.h> 36#include <opie2/ocontactaccessbackend.h>
37#include <opie2/ocontactaccess.h> 37#include <opie2/ocontactaccess.h>
38 38
39#include <qlist.h> 39#include <qlist.h>
40#include <qdict.h> 40#include <qdict.h>
41 41
42/* aren't in namespace Opie yet - alwin */ 42/* aren't in namespace Opie yet - alwin */
43namespace Opie { 43namespace Opie {
44namespace DB { 44namespace DB {
45class OSQLDriver; 45class OSQLDriver;
46class OSQLResult; 46class OSQLResult;
47class OSQLResultItem; 47class OSQLResultItem;
48} 48}
49} 49}
50 50
51namespace Opie { 51namespace Opie {
52 52
53/* the default xml implementation */ 53/* the default xml implementation */
54/** 54/**
55 * This class is the SQL implementation of a Contact backend 55 * This class is the SQL implementation of a Contact backend
56 * it does implement everything available for OPimContact. 56 * it does implement everything available for OPimContact.
57 * @see OPimAccessBackend for more information of available methods 57 * @see OPimAccessBackend for more information of available methods
58 */ 58 */
59class OPimContactAccessBackend_SQL : public OPimContactAccessBackend { 59class OPimContactAccessBackend_SQL : public OPimContactAccessBackend {
60 public: 60 public:
61 OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null ); 61 OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null );
62 62
63 ~OPimContactAccessBackend_SQL (); 63 ~OPimContactAccessBackend_SQL ();
64 64
65 bool save(); 65 bool save();
66 66
67 bool load (); 67 bool load ();
68 68
69 void clear (); 69 void clear ();
70 70
71 bool wasChangedExternally(); 71 bool wasChangedExternally();
72 72
73 UIDArray allRecords() const; 73 UIDArray allRecords() const;
74 74
75 OPimContact find( int uid ) const; 75 OPimContact find( int uid ) const;
76 OPimContact find( int uid, const UIDArray& items, uint cur, Frontend::CacheDirection ) const; 76 OPimContact find( int uid, const UIDArray& items, uint cur, Frontend::CacheDirection ) const;
77 77
78 UIDArray queryByExample ( const OPimContact &query, int settings, 78 UIDArray queryByExample ( const UIDArray& uidlist, const OPimContact &query, int settings,
79 const QDateTime& d ) const; 79 const QDateTime& d ) const;
80 80
81 UIDArray matchRegexp( const QRegExp &r ) const; 81 UIDArray matchRegexp( const QRegExp &r ) const;
82 82
83 const uint querySettings() const; 83 const uint querySettings() const;
84 84
85 bool hasQuerySettings (uint querySettings) const; 85 bool hasQuerySettings (uint querySettings) const;
86 86
87 UIDArray sorted( const UIDArray& ar, bool asc, int sortOrder, 87 UIDArray sorted( const UIDArray& ar, bool asc, int sortOrder,
88 int filter, const QArray<int>& categories)const; 88 int filter, const QArray<int>& categories)const;
89 89
90 bool add ( const OPimContact &newcontact ); 90 bool add ( const OPimContact &newcontact );
91 91
92 bool replace ( const OPimContact &contact ); 92 bool replace ( const OPimContact &contact );
93 93
94 bool remove ( int uid ); 94 bool remove ( int uid );
95 bool reload(); 95 bool reload();
96 96
97 private: 97 private:
98 UIDArray extractUids( Opie::DB::OSQLResult& res ) const; 98 UIDArray extractUids( Opie::DB::OSQLResult& res ) const;
99 QMap<int, QString> requestNonCustom( int uid ) const; 99 QMap<int, QString> requestNonCustom( int uid ) const;
100 QMap<QString, QString> requestCustom( int uid ) const; 100 QMap<QString, QString> requestCustom( int uid ) const;
101 QMap<int, QString> fillNonCustomMap( const Opie::DB::OSQLResultItem& resultItem ) const; 101 QMap<int, QString> fillNonCustomMap( const Opie::DB::OSQLResultItem& resultItem ) const;
102 OPimContact requestContactsAndCache( int uid, const QArray<int>& cachelist ) const; 102 OPimContact requestContactsAndCache( int uid, const QArray<int>& cachelist ) const;
103 void update(); 103 void update();
104 104
105 protected: 105 protected:
106 bool m_changed; 106 bool m_changed;
107 QString m_fileName; 107 QString m_fileName;
108 UIDArray m_uids; 108 UIDArray m_uids;
109 109
110 Opie::DB::OSQLDriver* m_driver; 110 Opie::DB::OSQLDriver* m_driver;
111}; 111};
112 112
113} 113}
114 114
115#endif 115#endif
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
index 73c7059..e44912a 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -55,110 +55,127 @@ void events( OPimBackendOccurrence::List& tmpList,
55 } 55 }
56} 56}
57 57
58void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list, 58void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list,
59 const QDate& from, const QDate& to ) { 59 const QDate& from, const QDate& to ) {
60 QDate repeat; 60 QDate repeat;
61 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { 61 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
62 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); 62 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
63 QDate itDate = from.addDays(-dur ); 63 QDate itDate = from.addDays(-dur );
64 OPimRecurrence rec = (*it).recurrence(); 64 OPimRecurrence rec = (*it).recurrence();
65 if ( !rec.hasEndDate() || rec.endDate() > to ) { 65 if ( !rec.hasEndDate() || rec.endDate() > to ) {
66 rec.setEndDate( to ); 66 rec.setEndDate( to );
67 rec.setHasEndDate( true ); 67 rec.setHasEndDate( true );
68 } 68 }
69 69
70 QDateTime start, end; 70 QDateTime start, end;
71 while (rec.nextOcurrence(itDate, repeat ) ) { 71 while (rec.nextOcurrence(itDate, repeat ) ) {
72 if (repeat > to ) break; 72 if (repeat > to ) break;
73 73
74 OPimEvent event = *it; 74 OPimEvent event = *it;
75 start = QDateTime( repeat, event.startDateTime().time() ); 75 start = QDateTime( repeat, event.startDateTime().time() );
76 end = QDateTime( repeat.addDays(dur), event.endDateTime().time() ); 76 end = QDateTime( repeat.addDays(dur), event.endDateTime().time() );
77 OPimBackendOccurrence eff(start, end, event.uid() ); 77 OPimBackendOccurrence eff(start, end, event.uid() );
78 tmpList.append( eff ); 78 tmpList.append( eff );
79 } 79 }
80 } 80 }
81} 81}
82} 82}
83 83
84namespace Opie { 84namespace Opie {
85 85
86ODateBookAccessBackend::ODateBookAccessBackend() 86ODateBookAccessBackend::ODateBookAccessBackend()
87 : OPimAccessBackend<OPimEvent>() 87 : OPimAccessBackend<OPimEvent>()
88{ 88{
89 89
90} 90}
91ODateBookAccessBackend::~ODateBookAccessBackend() { 91ODateBookAccessBackend::~ODateBookAccessBackend() {
92 92
93} 93}
94OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from, 94OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from,
95 const QDate& to )const { 95 const QDate& to )const {
96 OPimBackendOccurrence::List tmpList; 96 OPimBackendOccurrence::List tmpList;
97 97
98 events( tmpList, directNonRepeats(), from, to ); 98 events( tmpList, directNonRepeats(), from, to );
99 repeat( tmpList, directRawRepeats(),from,to ); 99 repeat( tmpList, directRawRepeats(),from,to );
100 100
101 return tmpList; 101 return tmpList;
102} 102}
103OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const { 103
104OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const
105{
104 OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() ); 106 OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() );
105 107
106 return filterOccurrences( day, dt ); 108 return filterOccurrences( day, dt );
107} 109}
108 110
109OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, 111OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
110 const QDate& to )const { 112 const QDate& to )const
113{
111 OPimBackendOccurrence::List tmpList; 114 OPimBackendOccurrence::List tmpList;
112 OPimEvent::ValueList list = directNonRepeats(); 115 OPimEvent::ValueList list = directNonRepeats();
113 116
114 events( tmpList, list, from, to ); 117 events( tmpList, list, from, to );
115 118
116 return tmpList; 119 return tmpList;
117} 120}
118 121
119OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const { 122OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const
123{
120 OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); 124 OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
121 return filterOccurrences( day,dt ); 125 return filterOccurrences( day,dt );
122} 126}
123 127
128const uint ODateBookAccessBackend::querySettings() const
129{
130 return 0;
131}
132
133bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const
134{
135 return false;
136}
137
138
124 139
125UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings, 140UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings,
126 const QDateTime& d )const { 141 const QDateTime& d )const
142{
143 qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" );
127 return UIDArray(); 144 return UIDArray();
128} 145}
129 146
130UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const { 147UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const {
131 return UIDArray(); 148 return UIDArray();
132} 149}
133 150
134OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, 151OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
135 const QDateTime& dt ) { 152 const QDateTime& dt ) {
136 OPimBackendOccurrence::List tmpList; 153 OPimBackendOccurrence::List tmpList;
137 OPimBackendOccurrence::List::ConstIterator it; 154 OPimBackendOccurrence::List::ConstIterator it;
138 155
139 for ( it = dayList.begin(); it != dayList.end(); ++it ) { 156 for ( it = dayList.begin(); it != dayList.end(); ++it ) {
140 OPimBackendOccurrence occ = *it; 157 OPimBackendOccurrence occ = *it;
141 158
142 /* 159 /*
143 * Let us find occurrences that are 'now'! 160 * Let us find occurrences that are 'now'!
144 * If the dt.date() is on the same day as start or end of the Occurrence 161 * If the dt.date() is on the same day as start or end of the Occurrence
145 * check how near start/end are. 162 * check how near start/end are.
146 * If it is in the middle of a multiday occurrence list it. 163 * If it is in the middle of a multiday occurrence list it.
147 * 164 *
148 * We might want to 'lose' the sixty second offset and list 165 * We might want to 'lose' the sixty second offset and list
149 * all Events which are active at that time. 166 * all Events which are active at that time.
150 */ 167 */
151 if ( dt.date() == occ.startDateTime().date() ) { 168 if ( dt.date() == occ.startDateTime().date() ) {
152 if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 ) 169 if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 )
153 tmpList.append( occ ); 170 tmpList.append( occ );
154 }else if ( dt.date() == occ.endDateTime().date() ) { 171 }else if ( dt.date() == occ.endDateTime().date() ) {
155 if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 ) 172 if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 )
156 tmpList.append( occ ); 173 tmpList.append( occ );
157 }else if ( dt.date() >= occ.startDateTime().date() && 174 }else if ( dt.date() >= occ.startDateTime().date() &&
158 dt.date() >= occ.endDateTime().date() ) 175 dt.date() >= occ.endDateTime().date() )
159 tmpList.append( occ ); 176 tmpList.append( occ );
160 } 177 }
161 178
162 return tmpList; 179 return tmpList;
163} 180}
164} 181}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h
index 8927ca1..91f63aa 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.h
@@ -49,66 +49,79 @@ public:
49 ~ODateBookAccessBackend(); 49 ~ODateBookAccessBackend();
50 50
51 /** 51 /**
52 * This method should return a list of UIDs containing 52 * This method should return a list of UIDs containing
53 * all repeating events. No filter should be applied 53 * all repeating events. No filter should be applied
54 * @return list of repeating events 54 * @return list of repeating events
55 */ 55 */
56 virtual UIDArray rawRepeats()const = 0; 56 virtual UIDArray rawRepeats()const = 0;
57 57
58 /** 58 /**
59 * This mthod should return a list of UIDs containing all non 59 * This mthod should return a list of UIDs containing all non
60 * repeating events. No filter should be applied 60 * repeating events. No filter should be applied
61 * @return list of nonrepeating events 61 * @return list of nonrepeating events
62 */ 62 */
63 virtual UIDArray nonRepeats() const = 0; 63 virtual UIDArray nonRepeats() const = 0;
64 64
65 /** 65 /**
66 * If you do not want to implement the effectiveEvents methods below 66 * If you do not want to implement the effectiveEvents methods below
67 * you need to supply it with directNonRepeats. 67 * you need to supply it with directNonRepeats.
68 * This method can return empty lists if effectiveEvents is implememted 68 * This method can return empty lists if effectiveEvents is implememted
69 */ 69 */
70 virtual OPimEvent::ValueList directNonRepeats()const = 0; 70 virtual OPimEvent::ValueList directNonRepeats()const = 0;
71 71
72 /** 72 /**
73 * Same as above but return raw repeats! 73 * Same as above but return raw repeats!
74 */ 74 */
75 virtual OPimEvent::ValueList directRawRepeats()const = 0; 75 virtual OPimEvent::ValueList directRawRepeats()const = 0;
76 76
77 /* is implemented by default but you can reimplement it*/ 77 /* is implemented by default but you can reimplement it*/
78 /** 78 /**
79 * Effective Events are special event occuring during a time frame. This method does calcualte 79 * Effective Events are special event occuring during a time frame. This method does calcualte
80 * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method 80 * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
81 * yourself 81 * yourself
82 */ 82 */
83 virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const; 83 virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const;
84 84
85 /** 85 /**
86 * this is an overloaded member function 86 * this is an overloaded member function
87 * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) 87 * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to )
88 */ 88 */
89 virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start )const; 89 virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start )const;
90 90
91 /** 91 /**
92 * Common and probably inefficent implementation 92 * Common and probably inefficent implementation
93 * for queryByExample, sorted 93 * for queryByExample, sorted
94 * and occurrences 94 * and occurrences
95 */ 95 */
96//@{ 96//@{
97 UIDArray queryByExample( const OPimEvent&, int settings, const QDateTime& d = QDateTime() )const; 97 /**
98 * Return all possible settings.
99 * @return All settings provided by the current backend
100 * (i.e.: query_WildCards & query_IgnoreCase)
101 */
102 const uint querySettings() const;
103
104 /**
105 * Check whether settings are correct.
106 * @return <i>true</i> if the given settings are correct and possible.
107 */
108 bool hasQuerySettings (uint querySettings) const;
109
110 UIDArray queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings, const QDateTime& d = QDateTime() )const;
98 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; 111 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
99 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& end )const; 112 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& end )const;
100 OPimBackendOccurrence::List occurrences( const QDateTime& )const; 113 OPimBackendOccurrence::List occurrences( const QDateTime& )const;
101//@} 114//@}
102 115
103protected: 116protected:
104 static OPimBackendOccurrence::List filterOccurrences(const OPimBackendOccurrence::List, 117 static OPimBackendOccurrence::List filterOccurrences(const OPimBackendOccurrence::List,
105 const QDateTime& time ); 118 const QDateTime& time );
106private: 119private:
107 class Private; 120 class Private;
108 Private *d; 121 Private *d;
109 122
110}; 123};
111 124
112} 125}
113 126
114#endif 127#endif
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 7321758..6666fd6 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -30,112 +30,112 @@
30#define OPIE_PIM_ACCESS_BACKEND 30#define OPIE_PIM_ACCESS_BACKEND
31 31
32#include <qarray.h> 32#include <qarray.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34 34
35#include <opie2/opimtemplatebase.h> 35#include <opie2/opimtemplatebase.h>
36#include <opie2/opimrecord.h> 36#include <opie2/opimrecord.h>
37#include <opie2/opimbackendoccurrence.h> 37#include <opie2/opimbackendoccurrence.h>
38 38
39namespace Opie { 39namespace Opie {
40class OPimAccessBackendPrivate; 40class OPimAccessBackendPrivate;
41 41
42/** 42/**
43 * OPimAccessBackend is the Backend Interface to be used 43 * OPimAccessBackend is the Backend Interface to be used
44 * by OTemplateBase based Frontends. 44 * by OTemplateBase based Frontends.
45 * For efficency reasons and to support delayed loading 45 * For efficency reasons and to support delayed loading
46 * most of the Frontend functions can be implemented 46 * most of the Frontend functions can be implemented
47 * by this backend. 47 * by this backend.
48 * This allows to utilise the best method on each backend. 48 * This allows to utilise the best method on each backend.
49 * For example we can use SQL queries instead of self made 49 * For example we can use SQL queries instead of self made
50 * query which is first more efficent and also uses less memory. 50 * query which is first more efficent and also uses less memory.
51 */ 51 */
52template <class T = OPimRecord> 52template <class T = OPimRecord>
53class OPimAccessBackend { 53class OPimAccessBackend {
54public: 54public:
55 typedef OTemplateBase<T> Frontend; 55 typedef OTemplateBase<T> Frontend;
56 56
57 //@{ 57 //@{
58 OPimAccessBackend(int access = 0); 58 OPimAccessBackend(int access = 0);
59 virtual ~OPimAccessBackend(); 59 virtual ~OPimAccessBackend();
60 //@} 60 //@}
61 61
62 //@{ 62 //@{
63 virtual bool load() = 0; 63 virtual bool load() = 0;
64 virtual bool reload() = 0; 64 virtual bool reload() = 0;
65 virtual bool save() = 0; 65 virtual bool save() = 0;
66 virtual void clear() = 0; 66 virtual void clear() = 0;
67 //@} 67 //@}
68 68
69 //@{ 69 //@{
70 // FIXME: Uncommented some of the abstract functions below. This should be removed as they are implemented in 70 // FIXME: Uncommented some of the abstract functions below. This should be removed as they are implemented in
71 // all typespecifc backenends (eilers) 71 // all typespecifc backenends (eilers)
72 /** 72 /**
73 * Return all possible settings for queryByExample() 73 * Return all possible settings for queryByExample()
74 * @return All settings provided by the current backend 74 * @return All settings provided by the current backend
75 * (i.e.: query_WildCards & query_IgnoreCase) 75 * (i.e.: query_WildCards & query_IgnoreCase)
76 * See implementation in the specific backends for contacts, todo and dates. 76 * See implementation in the specific backends for contacts, todo and dates.
77 */ 77 */
78 virtual const uint querySettings() const { return 0; } /* FIXME: Make Abstrakt !! = 0; */ 78 virtual const uint querySettings() const = 0;
79 79
80 /** 80 /**
81 * Check whether settings are correct for queryByExample() 81 * Check whether settings are correct for queryByExample()
82 * See implementation in the specific backends for OPimContactAccess, OPimTodoAccess and ODateBookAccess. 82 * See implementation in the specific backends for OPimContactAccess, OPimTodoAccess and ODateBookAccess.
83 * @return <i>true</i> if the given settings are correct and possible. 83 * @return <i>true</i> if the given settings are correct and possible.
84 */ 84 */
85 virtual bool hasQuerySettings (uint querySettings) const { return false; } /* FIXME: Make Abstrakt !! = 0; */ 85 virtual bool hasQuerySettings (uint querySettings) const = 0;
86 //@} 86 //@}
87 87
88 88
89 //@{ 89 //@{
90 virtual UIDArray allRecords()const = 0; 90 virtual UIDArray allRecords()const = 0;
91 virtual UIDArray matchRegexp(const QRegExp &r) const; 91 virtual UIDArray matchRegexp(const QRegExp &r) const;
92 virtual UIDArray queryByExample( const UIDArray&, const T& t, 92 virtual UIDArray queryByExample( const UIDArray&, const T& t,
93 int settings, const QDateTime& d = QDateTime() )const { return UIDArray(); } /* FIXME: Make Abstrakt !! = 0; */ 93 int settings, const QDateTime& d = QDateTime() )const = 0;
94 virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const; 94 virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const;
95 virtual UIDArray queryByExample( const OPimRecord* rec, int settings, const QDateTime& d = QDateTime() )const; 95 virtual UIDArray queryByExample( const OPimRecord* rec, int settings, const QDateTime& d = QDateTime() )const;
96 virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const = 0; 96 virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const = 0;
97 virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const; 97 virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const;
98 virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const; 98 virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const;
99 virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const; 99 virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const;
100 //@} 100 //@}
101 101
102 102
103 //@{ 103 //@{
104 virtual T find(UID uid )const = 0; 104 virtual T find(UID uid )const = 0;
105 virtual T find(UID uid, const QArray<UID>& items, 105 virtual T find(UID uid, const QArray<UID>& items,
106 uint current, typename Frontend::CacheDirection )const ; 106 uint current, typename Frontend::CacheDirection )const ;
107 //@} 107 //@}
108 108
109 109
110 //@{ 110 //@{
111 virtual bool add( const T& t ) = 0; 111 virtual bool add( const T& t ) = 0;
112 virtual bool remove( UID uid ) = 0; 112 virtual bool remove( UID uid ) = 0;
113 virtual bool replace( const T& t ) = 0; 113 virtual bool replace( const T& t ) = 0;
114 //@} 114 //@}
115 115
116 116
117 117
118 void setFrontend( Frontend* front ); 118 void setFrontend( Frontend* front );
119 119
120 /** 120 /**
121 * set the read ahead count 121 * set the read ahead count
122 */ 122 */
123 void setReadAhead( uint count ); 123 void setReadAhead( uint count );
124protected: 124protected:
125 //@{ 125 //@{
126 int access()const; 126 int access()const;
127 void cache( const T& t )const; 127 void cache( const T& t )const;
128 void setSaneCacheSize( int ); 128 void setSaneCacheSize( int );
129 uint readAhead()const; 129 uint readAhead()const;
130 //@} 130 //@}
131 131
132private: 132private:
133 OPimAccessBackendPrivate *d; 133 OPimAccessBackendPrivate *d;
134 Frontend* m_front; 134 Frontend* m_front;
135 uint m_read; 135 uint m_read;
136 int m_acc; 136 int m_acc;
137 137
138}; 138};
139 139
140template <class T> 140template <class T>
141OPimAccessBackend<T>::OPimAccessBackend(int acc) 141OPimAccessBackend<T>::OPimAccessBackend(int acc)
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.cpp b/libopie2/opiepim/backend/otodoaccessbackend.cpp
index 5f86be9..f979976 100644
--- a/libopie2/opiepim/backend/otodoaccessbackend.cpp
+++ b/libopie2/opiepim/backend/otodoaccessbackend.cpp
@@ -1,95 +1,121 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include <opie2/otodoaccessbackend.h> 30#include <opie2/otodoaccessbackend.h>
31#include <opie2/private/opimtodosortvector.h> 31#include <opie2/private/opimtodosortvector.h>
32#include <opie2/otodoaccess.h> 32#include <opie2/otodoaccess.h>
33 33
34#include <qintdict.h> 34#include <qintdict.h>
35 35
36namespace Opie { 36namespace Opie {
37OPimTodoAccessBackend::OPimTodoAccessBackend() 37OPimTodoAccessBackend::OPimTodoAccessBackend()
38 : OPimAccessBackend<OPimTodo>() 38 : OPimAccessBackend<OPimTodo>()
39{ 39{
40} 40}
41OPimTodoAccessBackend::~OPimTodoAccessBackend() { 41OPimTodoAccessBackend::~OPimTodoAccessBackend() {
42 42
43} 43}
44 44
45UIDArray OPimTodoAccessBackend::queryByExample( const OPimTodo&, int settings, 45const uint OPimTodoAccessBackend::querySettings() const
46 const QDateTime& d)const { 46{
47 return UIDArray(); 47 return 0;
48}
49
50bool OPimTodoAccessBackend::hasQuerySettings (uint querySettings) const
51{
52 return false;
53}
54
55
56UIDArray OPimTodoAccessBackend::queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings,
57 const QDateTime& endperiod )const
58{
59 qDebug( "Accessing OPimTodoAccessBackend::queryByExample() which is not implemented!" );
60 return UIDArray();
61
62// odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl;
63
64// UIDArray m_currentQuery( uid_array.count() );
65// uint arraycounter = 0;
66
67// for( uint it = 0; it < uid_array.count(); ++it ){
68 // /* Search all fields and compare them with query object. Store them into list
69 // * if all fields matches.
70 // */
71// }
72
73
48} 74}
49 75
50UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc, 76UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc,
51 int sortOrder, int sortFilter, 77 int sortOrder, int sortFilter,
52 const QArray<int>& categories )const { 78 const QArray<int>& categories )const {
53 odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl; 79 odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl;
54 Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder ); 80 Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder );
55 int item = 0; 81 int item = 0;
56 82
57 bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false; 83 bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false;
58 bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false; 84 bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false;
59 bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false; 85 bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false;
60 bool catPassed = false; 86 bool catPassed = false;
61 int cat; 87 int cat;
62 88
63 for ( uint i = 0; i < events.count(); ++i ) { 89 for ( uint i = 0; i < events.count(); ++i ) {
64 OPimTodo todo = find( events[i], events, i, Frontend::Forward ); 90 OPimTodo todo = find( events[i], events, i, Frontend::Forward );
65 if ( todo.isEmpty() ) 91 if ( todo.isEmpty() )
66 continue; 92 continue;
67 93
68 /* show category */ 94 /* show category */
69 /* -1 == unfiled */ 95 /* -1 == unfiled */
70 catPassed = false; 96 catPassed = false;
71 for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) { 97 for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
72 cat = categories[cat_nu]; 98 cat = categories[cat_nu];
73 if ( bCat && cat == -1 ) { 99 if ( bCat && cat == -1 ) {
74 if(!todo.categories().isEmpty() ) 100 if(!todo.categories().isEmpty() )
75 continue; 101 continue;
76 } else if ( bCat && cat != 0) 102 } else if ( bCat && cat != 0)
77 if (!todo.categories().contains( cat ) ) 103 if (!todo.categories().contains( cat ) )
78 continue; 104 continue;
79 catPassed = true; 105 catPassed = true;
80 break; 106 break;
81 } 107 }
82 108
83 /* 109 /*
84 * If none of the Categories matched 110 * If none of the Categories matched
85 * continue 111 * continue
86 */ 112 */
87 if ( !catPassed ) 113 if ( !catPassed )
88 continue; 114 continue;
89 if ( !todo.isOverdue() && bOnly ) 115 if ( !todo.isOverdue() && bOnly )
90 continue; 116 continue;
91 if (todo.isCompleted() && comp ) 117 if (todo.isCompleted() && comp )
92 continue; 118 continue;
93 119
94 vector.insert(item++, todo ); 120 vector.insert(item++, todo );
95 } 121 }
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h
index 66297bb..870ee57 100644
--- a/libopie2/opiepim/backend/otodoaccessbackend.h
+++ b/libopie2/opiepim/backend/otodoaccessbackend.h
@@ -6,74 +6,87 @@
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_TODO_ACCESS_BACKEND_H 29#ifndef OPIE_TODO_ACCESS_BACKEND_H
30#define OPIE_TODO_ACCESS_BACKEND_H 30#define OPIE_TODO_ACCESS_BACKEND_H
31 31
32#include <qbitarray.h> 32#include <qbitarray.h>
33 33
34#include <opie2/opimtodo.h> 34#include <opie2/opimtodo.h>
35#include <opie2/opimaccessbackend.h> 35#include <opie2/opimaccessbackend.h>
36 36
37namespace Opie { 37namespace Opie {
38class OPimTodoAccessBackend : public OPimAccessBackend<OPimTodo> { 38class OPimTodoAccessBackend : public OPimAccessBackend<OPimTodo> {
39public: 39public:
40 OPimTodoAccessBackend(); 40 OPimTodoAccessBackend();
41 ~OPimTodoAccessBackend(); 41 ~OPimTodoAccessBackend();
42 virtual UIDArray effectiveToDos( const QDate& start, 42 virtual UIDArray effectiveToDos( const QDate& start,
43 const QDate& end, 43 const QDate& end,
44 bool includeNoDates )const = 0; 44 bool includeNoDates )const = 0;
45 virtual UIDArray overDue()const = 0; 45 virtual UIDArray overDue()const = 0;
46 virtual void removeAllCompleted() = 0; 46 virtual void removeAllCompleted() = 0;
47 47
48 /** 48 /**
49 * Common and probably inefficent implementation 49 * Common and probably inefficent implementation
50 * for queryByExample, matchRegexp, sorted 50 * for queryByExample, matchRegexp, sorted
51 * and occurrences 51 * and occurrences
52 */ 52 */
53 //@{ 53 //@{
54 UIDArray queryByExample( const OPimTodo&, int settings, const QDateTime& d = QDateTime() )const; 54 /**
55 * Return all possible settings.
56 * @return All settings provided by the current backend
57 * (i.e.: query_WildCards & query_IgnoreCase)
58 */
59 const uint querySettings() const;
60
61 /**
62 * Check whether settings are correct.
63 * @return <i>true</i> if the given settings are correct and possible.
64 */
65 bool hasQuerySettings (uint querySettings) const;
66
67 UIDArray queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings, const QDateTime& endperiod = QDateTime() )const;
55 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; 68 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
56 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; 69 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const;
57 //@} 70 //@}
58 71
59private: 72private:
60 class Private; 73 class Private;
61 Private *d; 74 Private *d;
62 75
63}; 76};
64} 77}
65 78
66 79
67/** 80/**
68 * \fn Opie::OPimBackendOccurrence::List Opie::OPimTodoAccessBackend::occurrences(const QDate& start,const QDate& end)const 81 * \fn Opie::OPimBackendOccurrence::List Opie::OPimTodoAccessBackend::occurrences(const QDate& start,const QDate& end)const
69 * \brief Return occurrences for a period of time 82 * \brief Return occurrences for a period of time
70 * 83 *
71 * This method will return the 'effective' Todos and also 84 * This method will return the 'effective' Todos and also
72 * 'Overdue' Todos. Overdues will be shown on the 'current' 85 * 'Overdue' Todos. Overdues will be shown on the 'current'
73 * day if it is in the range or on \par start. If the overdue 86 * day if it is in the range or on \par start. If the overdue
74 * is inside the 'Effective Todos' we will skip the 87 * is inside the 'Effective Todos' we will skip the
75 * special overdue handling. 88 * special overdue handling.
76 * 89 *
77 * 90 *
78 */ 91 */
79#endif 92#endif
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 2bcab29..70e40e4 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -256,119 +256,129 @@ namespace {
256 + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," 256 + "'" + recMap[ OPimRecurrence::Created ] + "'" + ","
257 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; 257 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ",";
258 258
259 if ( m_todo.hasNotifiers() ) { 259 if ( m_todo.hasNotifiers() ) {
260 OPimNotifyManager manager = m_todo.notifiers(); 260 OPimNotifyManager manager = m_todo.notifiers();
261 qu += "'" + manager.remindersToString() + "'" + "," 261 qu += "'" + manager.remindersToString() + "'" + ","
262 + "'" + manager.alarmsToString() + "'" + ","; 262 + "'" + manager.alarmsToString() + "'" + ",";
263 } 263 }
264 else{ 264 else{
265 qu += QString( "''" ) + "," 265 qu += QString( "''" ) + ","
266 + "''" + ","; 266 + "''" + ",";
267 } 267 }
268 268
269 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 269 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
270 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" 270 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
271 + QString::number(sMonth).rightJustify( 2, '0' ) 271 + QString::number(sMonth).rightJustify( 2, '0' )
272 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," 272 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + ","
273 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" 273 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-"
274 + QString::number(eMonth).rightJustify( 2, '0' ) 274 + QString::number(eMonth).rightJustify( 2, '0' )
275 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" 275 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'"
276 + "); "; 276 + "); ";
277 277
278 // Save custom Entries: 278 // Save custom Entries:
279 int id = 0; 279 int id = 0;
280 id = 0; 280 id = 0;
281 QMap<QString, QString> customMap = m_todo.toExtraMap(); 281 QMap<QString, QString> customMap = m_todo.toExtraMap();
282 for( QMap<QString, QString>::Iterator it = customMap.begin(); 282 for( QMap<QString, QString>::Iterator it = customMap.begin();
283 it != customMap.end(); ++it ){ 283 it != customMap.end(); ++it ){
284 qu += "insert into custom_data VALUES(" 284 qu += "insert into custom_data VALUES("
285 + QString::number( m_todo.uid() ) 285 + QString::number( m_todo.uid() )
286 + "," 286 + ","
287 + QString::number( id++ ) 287 + QString::number( id++ )
288 + ",'" 288 + ",'"
289 + it.key() 289 + it.key()
290 + "'," 290 + "',"
291 + "0" // Priority for future enhancements 291 + "0" // Priority for future enhancements
292 + ",'" 292 + ",'"
293 + it.data() 293 + it.data()
294 + "');"; 294 + "');";
295 } 295 }
296 296
297 297
298 odebug << "add " << qu << "" << oendl; 298 odebug << "add " << qu << "" << oendl;
299 return qu; 299 return qu;
300 } 300 }
301 301
302 RemoveQuery::RemoveQuery(int uid ) 302 RemoveQuery::RemoveQuery(int uid )
303 : OSQLQuery(), m_uid( uid ) {} 303 : OSQLQuery(), m_uid( uid ) {}
304
304 RemoveQuery::~RemoveQuery() {} 305 RemoveQuery::~RemoveQuery() {}
306
305 QString RemoveQuery::query()const { 307 QString RemoveQuery::query()const {
306 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; 308 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
307 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); 309 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
308 return qu; 310 return qu;
309 } 311 }
310 312
311 313
312 ClearQuery::ClearQuery() 314 ClearQuery::ClearQuery()
313 : OSQLQuery() {} 315 : OSQLQuery() {}
314 ClearQuery::~ClearQuery() {} 316 ClearQuery::~ClearQuery() {}
315 QString ClearQuery::query()const { 317 QString ClearQuery::query()const
316 QString qu = "drop table todolist"; 318 {
317 return qu; 319 QString qu = "drop table todolist";
320 return qu;
318 } 321 }
322
319 FindQuery::FindQuery(int uid) 323 FindQuery::FindQuery(int uid)
320 : OSQLQuery(), m_uid(uid ) { 324 : OSQLQuery(), m_uid(uid )
325 {
321 } 326 }
327
322 FindQuery::FindQuery(const QArray<int>& ints) 328 FindQuery::FindQuery(const QArray<int>& ints)
323 : OSQLQuery(), m_uids(ints){ 329 : OSQLQuery(), m_uids(ints)
330 {
324 } 331 }
325 FindQuery::~FindQuery() { 332
333 FindQuery::~FindQuery()
334 {
326 } 335 }
336
327 QString FindQuery::query()const{ 337 QString FindQuery::query()const{
328 if (m_uids.count() == 0 ) 338 if (m_uids.count() == 0 )
329 return single(); 339 return single();
330 else 340 else
331 return multi(); 341 return multi();
332 } 342 }
333 QString FindQuery::single()const{ 343 QString FindQuery::single()const{
334 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 344 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
335 return qu; 345 return qu;
336 } 346 }
337 QString FindQuery::multi()const { 347 QString FindQuery::multi()const {
338 QString qu = "select * from todolist where "; 348 QString qu = "select * from todolist where ";
339 for (uint i = 0; i < m_uids.count(); i++ ) { 349 for (uint i = 0; i < m_uids.count(); i++ ) {
340 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 350 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
341 } 351 }
342 qu.remove( qu.length()-2, 2 ); 352 qu.remove( qu.length()-2, 2 );
343 return qu; 353 return qu;
344 } 354 }
345 355
346 OverDueQuery::OverDueQuery(): OSQLQuery() {} 356 OverDueQuery::OverDueQuery(): OSQLQuery() {}
347 OverDueQuery::~OverDueQuery() {} 357 OverDueQuery::~OverDueQuery() {}
348 QString OverDueQuery::query()const { 358 QString OverDueQuery::query()const {
349 QDate date = QDate::currentDate(); 359 QDate date = QDate::currentDate();
350 QString str; 360 QString str;
351 str = QString("select uid from todolist where DueDate ='%1-%2-%3'") 361 str = QString("select uid from todolist where DueDate ='%1-%2-%3'")
352 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 362 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
353 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 363 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
354 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); 364 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) );
355 365
356 return str; 366 return str;
357 } 367 }
358 368
359 369
360 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 370 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
361 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 371 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
362 EffQuery::~EffQuery() {} 372 EffQuery::~EffQuery() {}
363 QString EffQuery::query()const { 373 QString EffQuery::query()const {
364 return m_inc ? with() : out(); 374 return m_inc ? with() : out();
365 } 375 }
366 QString EffQuery::with()const { 376 QString EffQuery::with()const {
367 QString str; 377 QString str;
368 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 378 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
369 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 379 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
370 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 380 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
371 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 381 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
372 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) 382 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
373 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) 383 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
374 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); 384 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
@@ -403,100 +413,100 @@ namespace {
403 qu += QString::number(m_uid); 413 qu += QString::number(m_uid);
404 return qu; 414 return qu;
405 } 415 }
406 416
407}; 417};
408 418
409 419
410namespace Opie { 420namespace Opie {
411OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) 421OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file )
412 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) 422 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true)
413{ 423{
414 QString fi = file; 424 QString fi = file;
415 if ( fi.isEmpty() ) 425 if ( fi.isEmpty() )
416 fi = Global::applicationFileName( "todolist", "todolist.db" ); 426 fi = Global::applicationFileName( "todolist", "todolist.db" );
417 OSQLManager man; 427 OSQLManager man;
418 m_driver = man.standard(); 428 m_driver = man.standard();
419 m_driver->setUrl(fi); 429 m_driver->setUrl(fi);
420 // fillDict(); 430 // fillDict();
421} 431}
422 432
423OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ 433OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){
424 if( m_driver ) 434 if( m_driver )
425 delete m_driver; 435 delete m_driver;
426} 436}
427 437
428bool OPimTodoAccessBackendSQL::load(){ 438bool OPimTodoAccessBackendSQL::load(){
429 if (!m_driver->open() ) 439 if (!m_driver->open() )
430 return false; 440 return false;
431 441
432 CreateQuery creat; 442 CreateQuery creat;
433 OSQLResult res = m_driver->query(&creat ); 443 OSQLResult res = m_driver->query(&creat );
434 444
435 m_dirty = true; 445 m_dirty = true;
436 return true; 446 return true;
437} 447}
438bool OPimTodoAccessBackendSQL::reload(){ 448bool OPimTodoAccessBackendSQL::reload(){
439 return load(); 449 return load();
440} 450}
441 451
442bool OPimTodoAccessBackendSQL::save(){ 452bool OPimTodoAccessBackendSQL::save(){
443 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 453 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
444} 454}
445QArray<int> OPimTodoAccessBackendSQL::allRecords()const { 455QArray<int> OPimTodoAccessBackendSQL::allRecords()const {
446 if (m_dirty ) 456 if (m_dirty )
447 update(); 457 update();
448 458
449 return m_uids; 459 return m_uids;
450} 460}
451QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ 461// QArray<int> OPimTodoAccessBackendSQL::queryByExample( const UIDArray& uidlist, const OPimTodo& , int, const QDateTime& ){
452 QArray<int> ints(0); 462// QArray<int> ints(0);
453 return ints; 463// return ints;
454} 464// }
455OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ 465OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
456 FindQuery query( uid ); 466 FindQuery query( uid );
457 return parseResultAndCache( uid, m_driver->query(&query) ); 467 return parseResultAndCache( uid, m_driver->query(&query) );
458} 468}
459 469
460// Remember: uid is already in the list of uids, called ints ! 470// Remember: uid is already in the list of uids, called ints !
461OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 471OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
462 uint cur, Frontend::CacheDirection dir ) const{ 472 uint cur, Frontend::CacheDirection dir ) const{
463 uint CACHE = readAhead(); 473 uint CACHE = readAhead();
464 odebug << "searching for " << uid << "" << oendl; 474 odebug << "searching for " << uid << "" << oendl;
465 QArray<int> search( CACHE ); 475 QArray<int> search( CACHE );
466 uint size =0; 476 uint size =0;
467 477
468 // we try to cache CACHE items 478 // we try to cache CACHE items
469 switch( dir ) { 479 switch( dir ) {
470 /* forward */ 480 /* forward */
471 case Frontend::Forward: 481 case Frontend::Forward:
472 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 482 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
473 search[size] = ints[i]; 483 search[size] = ints[i];
474 size++; 484 size++;
475 } 485 }
476 break; 486 break;
477 /* reverse */ 487 /* reverse */
478 case Frontend::Reverse: 488 case Frontend::Reverse:
479 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 489 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
480 search[size] = ints[i]; 490 search[size] = ints[i];
481 size++; 491 size++;
482 } 492 }
483 break; 493 break;
484 } 494 }
485 495
486 search.resize( size ); 496 search.resize( size );
487 FindQuery query( search ); 497 FindQuery query( search );
488 OSQLResult res = m_driver->query( &query ); 498 OSQLResult res = m_driver->query( &query );
489 if ( res.state() != OSQLResult::Success ) 499 if ( res.state() != OSQLResult::Success )
490 return OPimTodo(); 500 return OPimTodo();
491 501
492 return parseResultAndCache( uid, res ); 502 return parseResultAndCache( uid, res );
493} 503}
494 504
495void OPimTodoAccessBackendSQL::clear() { 505void OPimTodoAccessBackendSQL::clear() {
496 ClearQuery cle; 506 ClearQuery cle;
497 OSQLResult res = m_driver->query( &cle ); 507 OSQLResult res = m_driver->query( &cle );
498 CreateQuery qu; 508 CreateQuery qu;
499 res = m_driver->query(&qu); 509 res = m_driver->query(&qu);
500} 510}
501bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { 511bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
502 InsertQuery ins( t ); 512 InsertQuery ins( t );
@@ -574,97 +584,97 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
574 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 584 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
575 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 585 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
576 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); 586 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
577 query += " " + base + " AND"; 587 query += " " + base + " AND";
578 } 588 }
579 /* not show completed */ 589 /* not show completed */
580 if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) { 590 if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
581 query += " completed = 0 AND"; 591 query += " completed = 0 AND";
582 }else{ 592 }else{
583 query += " ( completed = 1 OR completed = 0) AND"; 593 query += " ( completed = 1 OR completed = 0) AND";
584 } 594 }
585 /* strip the end */ 595 /* strip the end */
586 query = query.remove( query.length()-3, 3 ); 596 query = query.remove( query.length()-3, 3 );
587 597
588 598
589 /* 599 /*
590 * sort order stuff 600 * sort order stuff
591 * quite straight forward 601 * quite straight forward
592 */ 602 */
593 query += "ORDER BY "; 603 query += "ORDER BY ";
594 switch( sortOrder ) { 604 switch( sortOrder ) {
595 /* completed */ 605 /* completed */
596 case OPimTodoAccess::Completed: 606 case OPimTodoAccess::Completed:
597 query += "completed"; 607 query += "completed";
598 break; 608 break;
599 case OPimTodoAccess::Priority: 609 case OPimTodoAccess::Priority:
600 query += "priority"; 610 query += "priority";
601 break; 611 break;
602 case OPimTodoAccess::SortSummary: 612 case OPimTodoAccess::SortSummary:
603 query += "summary"; 613 query += "summary";
604 break; 614 break;
605 case OPimTodoAccess::Deadline: 615 case OPimTodoAccess::Deadline:
606 query += "DueDate"; 616 query += "DueDate";
607 break; 617 break;
608 } 618 }
609 619
610 if ( !asc ) 620 if ( !asc )
611 query += " DESC"; 621 query += " DESC";
612 622
613 623
614 odebug << query << oendl; 624 odebug << query << oendl;
615 OSQLRawQuery raw(query ); 625 OSQLRawQuery raw(query );
616 return uids( m_driver->query(&raw) ); 626 return uids( m_driver->query(&raw) );
617} 627}
618#endif 628#endif
619 629
620 630
621bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 631bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
622 if ( str == "0-0-0" ) 632 if ( str == "0000-00-00" )
623 return false; 633 return false;
624 else{ 634 else{
625 int day, year, month; 635 int day, year, month;
626 QStringList list = QStringList::split("-", str ); 636 QStringList list = QStringList::split("-", str );
627 year = list[0].toInt(); 637 year = list[0].toInt();
628 month = list[1].toInt(); 638 month = list[1].toInt();
629 day = list[2].toInt(); 639 day = list[2].toInt();
630 da.setYMD( year, month, day ); 640 da.setYMD( year, month, day );
631 return true; 641 return true;
632 } 642 }
633} 643}
634 644
635 645
636OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ 646OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
637 if ( res.state() == OSQLResult::Failure ) { 647 if ( res.state() == OSQLResult::Failure ) {
638 OPimTodo to; 648 OPimTodo to;
639 return to; 649 return to;
640 } 650 }
641 651
642 OPimTodo retTodo; 652 OPimTodo retTodo;
643 653
644 OSQLResultItem::ValueList list = res.results(); 654 OSQLResultItem::ValueList list = res.results();
645 OSQLResultItem::ValueList::Iterator it = list.begin(); 655 OSQLResultItem::ValueList::Iterator it = list.begin();
646 OPimTodo to, tmp; 656 OPimTodo to, tmp;
647 657
648 for ( ; it != list.end(); ++it ) { 658 for ( ; it != list.end(); ++it ) {
649 OPimTodo newTodo = parse( (*it) ); 659 OPimTodo newTodo = parse( (*it) );
650 cache( newTodo ); 660 cache( newTodo );
651 if ( newTodo.uid() == uid ) 661 if ( newTodo.uid() == uid )
652 retTodo = newTodo; 662 retTodo = newTodo;
653 } 663 }
654 return retTodo; 664 return retTodo;
655} 665}
656OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const { 666OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const {
657 667
658 // Request information from addressbook table and create the OPimTodo-object. 668 // Request information from addressbook table and create the OPimTodo-object.
659 669
660 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 670 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
661 hasDueDate = date( dueDate, item.data("DueDate") ); 671 hasDueDate = date( dueDate, item.data("DueDate") );
662 QStringList cats = QStringList::split(";", item.data("categories") ); 672 QStringList cats = QStringList::split(";", item.data("categories") );
663 673
664 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 674 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
665 cats, item.data("summary"), item.data("description"), 675 cats, item.data("summary"), item.data("description"),
666 item.data("progress").toUShort(), hasDueDate, dueDate, 676 item.data("progress").toUShort(), hasDueDate, dueDate,
667 item.data("uid").toInt() ); 677 item.data("uid").toInt() );
668 678
669 bool isOk; 679 bool isOk;
670 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 680 int prioInt = QString( item.data("priority") ).toInt( &isOk );
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 0ba8f3a..ac3476a 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -8,81 +8,81 @@
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_PIM_ACCESS_SQL_H 29#ifndef OPIE_PIM_ACCESS_SQL_H
30#define OPIE_PIM_ACCESS_SQL_H 30#define OPIE_PIM_ACCESS_SQL_H
31 31
32/* #include <qasciidict.h> */ 32/* #include <qasciidict.h> */
33 33
34#include <opie2/otodoaccessbackend.h> 34#include <opie2/otodoaccessbackend.h>
35 35
36namespace Opie { 36namespace Opie {
37namespace DB { 37namespace DB {
38class OSQLDriver; 38class OSQLDriver;
39class OSQLResult; 39class OSQLResult;
40class OSQLResultItem; 40class OSQLResultItem;
41} 41}
42} 42}
43 43
44namespace Opie { 44namespace Opie {
45 45
46class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend { 46class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend {
47public: 47public:
48 OPimTodoAccessBackendSQL( const QString& file ); 48 OPimTodoAccessBackendSQL( const QString& file );
49 ~OPimTodoAccessBackendSQL(); 49 ~OPimTodoAccessBackendSQL();
50 50
51 bool load(); 51 bool load();
52 bool reload(); 52 bool reload();
53 bool save(); 53 bool save();
54 QArray<UID> allRecords()const; 54 QArray<UID> allRecords()const;
55 55
56 QArray<UID> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() ); 56/* QArray<UID> queryByExample( const UIDArray& uidlist, const OPimTodo& t, int settings, const QDateTime& d = QDateTime() ); */
57 OPimTodo find(UID uid)const; 57 OPimTodo find(UID uid)const;
58 OPimTodo find(UID uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; 58 OPimTodo find(UID uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
59 void clear(); 59 void clear();
60 bool add( const OPimTodo& t ); 60 bool add( const OPimTodo& t );
61 bool remove( UID uid ); 61 bool remove( UID uid );
62 bool replace( const OPimTodo& t ); 62 bool replace( const OPimTodo& t );
63 63
64 QArray<UID> overDue()const; 64 QArray<UID> overDue()const;
65 QArray<UID> effectiveToDos( const QDate& start, 65 QArray<UID> effectiveToDos( const QDate& start,
66 const QDate& end, bool includeNoDates )const; 66 const QDate& end, bool includeNoDates )const;
67 QArray<UID> matchRegexp( const QRegExp &r ) const; 67 QArray<UID> matchRegexp( const QRegExp &r ) const;
68 void removeAllCompleted(); 68 void removeAllCompleted();
69 69
70 70
71private: 71private:
72 void update()const; 72 void update()const;
73 inline bool date( QDate& date, const QString& )const; 73 inline bool date( QDate& date, const QString& )const;
74 inline OPimTodo parseResultAndCache( UID uid, const Opie::DB::OSQLResult& )const; 74 inline OPimTodo parseResultAndCache( UID uid, const Opie::DB::OSQLResult& )const;
75 inline OPimTodo parse( Opie::DB::OSQLResultItem& )const; 75 inline OPimTodo parse( Opie::DB::OSQLResultItem& )const;
76 inline QArray<UID> uids( const Opie::DB::OSQLResult& )const; 76 inline QArray<UID> uids( const Opie::DB::OSQLResult& )const;
77 OPimTodo todo( UID uid )const; 77 OPimTodo todo( UID uid )const;
78 QMap<QString, QString> requestCustom( UID uid ) const; 78 QMap<QString, QString> requestCustom( UID uid ) const;
79 79
80 // QAsciiDict<int> m_dict; 80 // QAsciiDict<int> m_dict;
81 Opie::DB::OSQLDriver* m_driver; 81 Opie::DB::OSQLDriver* m_driver;
82 QArray<UID> m_uids; 82 QArray<UID> m_uids;
83 bool m_dirty : 1; 83 bool m_dirty : 1;
84}; 84};
85 85
86} 86}
87 87
88#endif 88#endif
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 273f91a..ab50604 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -281,100 +281,97 @@ bool OPimTodoAccessXML::save() {
281 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 281 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
282 282
283 // for all todos 283 // for all todos
284 QMap<int, OPimTodo>::Iterator it; 284 QMap<int, OPimTodo>::Iterator it;
285 for (it = m_events.begin(); it != m_events.end(); ++it ) { 285 for (it = m_events.begin(); it != m_events.end(); ++it ) {
286 out+= "<Task " + toString( (*it) ) + " />\n"; 286 out+= "<Task " + toString( (*it) ) + " />\n";
287 QCString cstr = out.utf8(); 287 QCString cstr = out.utf8();
288 written = f.writeBlock( cstr.data(), cstr.length() ); 288 written = f.writeBlock( cstr.data(), cstr.length() );
289 289
290 /* less written then we wanted */ 290 /* less written then we wanted */
291 if ( written != (int)cstr.length() ) { 291 if ( written != (int)cstr.length() ) {
292 f.close(); 292 f.close();
293 QFile::remove( strNewFile ); 293 QFile::remove( strNewFile );
294 return false; 294 return false;
295 } 295 }
296 out = QString::null; 296 out = QString::null;
297 } 297 }
298 298
299 out += "</Tasks>"; 299 out += "</Tasks>";
300 QCString cstr = out.utf8(); 300 QCString cstr = out.utf8();
301 written = f.writeBlock( cstr.data(), cstr.length() ); 301 written = f.writeBlock( cstr.data(), cstr.length() );
302 302
303 if ( written != (int)cstr.length() ) { 303 if ( written != (int)cstr.length() ) {
304 f.close(); 304 f.close();
305 QFile::remove( strNewFile ); 305 QFile::remove( strNewFile );
306 return false; 306 return false;
307 } 307 }
308 /* flush before renaming */ 308 /* flush before renaming */
309 f.close(); 309 f.close();
310 310
311 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 311 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
312 QFile::remove( strNewFile ); 312 QFile::remove( strNewFile );
313 } 313 }
314 314
315 m_changed = false; 315 m_changed = false;
316 return true; 316 return true;
317} 317}
318QArray<int> OPimTodoAccessXML::allRecords()const { 318QArray<int> OPimTodoAccessXML::allRecords()const {
319 QArray<int> ids( m_events.count() ); 319 QArray<int> ids( m_events.count() );
320 QMap<int, OPimTodo>::ConstIterator it; 320 QMap<int, OPimTodo>::ConstIterator it;
321 int i = 0; 321 int i = 0;
322 322
323 for ( it = m_events.begin(); it != m_events.end(); ++it ) 323 for ( it = m_events.begin(); it != m_events.end(); ++it )
324 ids[i++] = it.key(); 324 ids[i++] = it.key();
325 325
326 326
327 return ids; 327 return ids;
328} 328}
329QArray<int> OPimTodoAccessXML::queryByExample( const OPimTodo&, int, const QDateTime& ) { 329
330 QArray<int> ids(0);
331 return ids;
332}
333OPimTodo OPimTodoAccessXML::find( int uid )const { 330OPimTodo OPimTodoAccessXML::find( int uid )const {
334 OPimTodo todo; 331 OPimTodo todo;
335 todo.setUid( 0 ); // isEmpty() 332 todo.setUid( 0 ); // isEmpty()
336 QMap<int, OPimTodo>::ConstIterator it = m_events.find( uid ); 333 QMap<int, OPimTodo>::ConstIterator it = m_events.find( uid );
337 if ( it != m_events.end() ) 334 if ( it != m_events.end() )
338 todo = it.data(); 335 todo = it.data();
339 336
340 return todo; 337 return todo;
341} 338}
342void OPimTodoAccessXML::clear() { 339void OPimTodoAccessXML::clear() {
343 if (m_opened ) 340 if (m_opened )
344 m_changed = true; 341 m_changed = true;
345 342
346 m_events.clear(); 343 m_events.clear();
347} 344}
348bool OPimTodoAccessXML::add( const OPimTodo& todo ) { 345bool OPimTodoAccessXML::add( const OPimTodo& todo ) {
349 m_changed = true; 346 m_changed = true;
350 m_events.insert( todo.uid(), todo ); 347 m_events.insert( todo.uid(), todo );
351 348
352 return true; 349 return true;
353} 350}
354bool OPimTodoAccessXML::remove( int uid ) { 351bool OPimTodoAccessXML::remove( int uid ) {
355 m_changed = true; 352 m_changed = true;
356 m_events.remove( uid ); 353 m_events.remove( uid );
357 354
358 return true; 355 return true;
359} 356}
360bool OPimTodoAccessXML::replace( const OPimTodo& todo) { 357bool OPimTodoAccessXML::replace( const OPimTodo& todo) {
361 m_changed = true; 358 m_changed = true;
362 m_events.replace( todo.uid(), todo ); 359 m_events.replace( todo.uid(), todo );
363 360
364 return true; 361 return true;
365} 362}
366QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start, 363QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
367 const QDate& end, 364 const QDate& end,
368 bool includeNoDates )const { 365 bool includeNoDates )const {
369 QArray<int> ids( m_events.count() ); 366 QArray<int> ids( m_events.count() );
370 QMap<int, OPimTodo>::ConstIterator it; 367 QMap<int, OPimTodo>::ConstIterator it;
371 368
372 int i = 0; 369 int i = 0;
373 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 370 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
374 if ( !it.data().hasDueDate() && includeNoDates) { 371 if ( !it.data().hasDueDate() && includeNoDates) {
375 ids[i++] = it.key(); 372 ids[i++] = it.key();
376 }else if ( it.data().dueDate() >= start && 373 }else if ( it.data().dueDate() >= start &&
377 it.data().dueDate() <= end ) { 374 it.data().dueDate() <= end ) {
378 ids[i++] = it.key(); 375 ids[i++] = it.key();
379 } 376 }
380 } 377 }
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h
index 134a21a..8a71bb7 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.h
+++ b/libopie2/opiepim/backend/otodoaccessxml.h
@@ -7,82 +7,81 @@
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_TODO_ACCESS_XML_H 29#ifndef OPIE_TODO_ACCESS_XML_H
30#define OPIE_TODO_ACCESS_XML_H 30#define OPIE_TODO_ACCESS_XML_H
31 31
32#include <qasciidict.h> 32#include <qasciidict.h>
33#include <qmap.h> 33#include <qmap.h>
34 34
35#include <opie2/otodoaccessbackend.h> 35#include <opie2/otodoaccessbackend.h>
36 36
37namespace Opie { 37namespace Opie {
38 class XMLElement; 38 class XMLElement;
39 39
40class OPimTodoAccessXML : public OPimTodoAccessBackend { 40class OPimTodoAccessXML : public OPimTodoAccessBackend {
41public: 41public:
42 /** 42 /**
43 * fileName if Empty we will use the default path 43 * fileName if Empty we will use the default path
44 */ 44 */
45 OPimTodoAccessXML( const QString& appName, 45 OPimTodoAccessXML( const QString& appName,
46 const QString& fileName = QString::null ); 46 const QString& fileName = QString::null );
47 ~OPimTodoAccessXML(); 47 ~OPimTodoAccessXML();
48 48
49 bool load(); 49 bool load();
50 bool reload(); 50 bool reload();
51 bool save(); 51 bool save();
52 52
53 QArray<int> allRecords()const; 53 QArray<int> allRecords()const;
54 QArray<int> matchRegexp(const QRegExp &r) const; 54 QArray<int> matchRegexp(const QRegExp &r) const;
55 QArray<int> queryByExample( const OPimTodo&, int querysettings, const QDateTime& d = QDateTime() );
56 OPimTodo find( int uid )const; 55 OPimTodo find( int uid )const;
57 void clear(); 56 void clear();
58 bool add( const OPimTodo& ); 57 bool add( const OPimTodo& );
59 bool remove( int uid ); 58 bool remove( int uid );
60 void removeAllCompleted(); 59 void removeAllCompleted();
61 bool replace( const OPimTodo& ); 60 bool replace( const OPimTodo& );
62 61
63 /* our functions */ 62 /* our functions */
64 QArray<int> effectiveToDos( const QDate& start, 63 QArray<int> effectiveToDos( const QDate& start,
65 const QDate& end, 64 const QDate& end,
66 bool includeNoDates )const; 65 bool includeNoDates )const;
67 QArray<int> overDue()const; 66 QArray<int> overDue()const;
68 67
69//@{ 68//@{
70 UIDArray sorted( const UIDArray&, bool, int, int, const QArray<int>& )const; 69 UIDArray sorted( const UIDArray&, bool, int, int, const QArray<int>& )const;
71//@} 70//@}
72private: 71private:
73 void todo( QAsciiDict<int>*, OPimTodo&,const QCString&,const QString& ); 72 void todo( QAsciiDict<int>*, OPimTodo&,const QCString&,const QString& );
74 QString toString( const OPimTodo& )const; 73 QString toString( const OPimTodo& )const;
75 QString toString( const QArray<int>& ints ) const; 74 QString toString( const QArray<int>& ints ) const;
76 QMap<int, OPimTodo> m_events; 75 QMap<int, OPimTodo> m_events;
77 QString m_file; 76 QString m_file;
78 QString m_app; 77 QString m_app;
79 bool m_opened : 1; 78 bool m_opened : 1;
80 bool m_changed : 1; 79 bool m_changed : 1;
81 class OPimTodoAccessXMLPrivate; 80 class OPimTodoAccessXMLPrivate;
82 OPimTodoAccessXMLPrivate* d; 81 OPimTodoAccessXMLPrivate* d;
83 int m_year, m_month, m_day; 82 int m_year, m_month, m_day;
84}; 83};
85 84
86}; 85};
87 86
88#endif 87#endif