summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/backends.pro5
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h42
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.cpp121
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h80
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp26
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.h3
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp29
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h5
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp228
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.h47
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp15
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.h5
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp12
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.h4
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h361
-rw-r--r--libopie2/opiepim/backend/opimbackendoccurrence.cpp241
-rw-r--r--libopie2/opiepim/backend/opimbackendoccurrence.h108
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.cpp114
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.h40
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp135
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h37
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp40
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.h10
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp316
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h13
25 files changed, 1218 insertions, 819 deletions
diff --git a/libopie2/opiepim/backend/backends.pro b/libopie2/opiepim/backend/backends.pro
index 42d807c..739f74e 100644
--- a/libopie2/opiepim/backend/backends.pro
+++ b/libopie2/opiepim/backend/backends.pro
@@ -1,2 +1,3 @@
1SOURCES += \ 1SOURCES += \
2 backend/ocontactaccessbackend.cpp \
2 backend/ocontactaccessbackend_vcard.cpp \ 3 backend/ocontactaccessbackend_vcard.cpp \
@@ -5,2 +6,3 @@ SOURCES += \
5 backend/odatebookaccessbackend_xml.cpp \ 6 backend/odatebookaccessbackend_xml.cpp \
7 backend/opimbackendoccurrence.cpp \
6 backend/otodoaccessbackend.cpp \ 8 backend/otodoaccessbackend.cpp \
@@ -16,3 +18,4 @@ HEADERS += \
16 backend/odatebookaccessbackend_xml.h \ 18 backend/odatebookaccessbackend_xml.h \
17 backend/opimaccessbackend.h \ 19 backend/opimaccessbackend.h \
20 backend/opimbackendoccurrence.h \
18 backend/otodoaccessbackend.h \ 21 backend/otodoaccessbackend.h \
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 9f3a823..25e247b 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -64,5 +64,5 @@ using namespace Opie::Pim;
64namespace Opie { 64namespace Opie {
65 65
66class OBackendPrivate; 66class OBackendPrivate;
67 67
68/** 68/**
@@ -86,4 +86,4 @@ class OBackendPrivate;
86 public: 86 public:
87 OBackendFactory() {}; 87 OBackendFactory() {};
88 88
89 /** 89 /**
@@ -98,4 +98,6 @@ class OBackendPrivate;
98 const QString& appName, const QString& filename = QString::null ){ 98 const QString& appName, const QString& filename = QString::null ){
99 owarn << "Selected backend for " << type << " is: " << database << oendl; 99 owarn << "Selected backend for " << type << " is: " <<
100 // If we should use the dafult database style, we have to request it 100database << oendl;
101
102 // If we should use the dafult database style, we have to request it
101 OPimGlobal::DatabaseStyle use_database = database; 103 OPimGlobal::DatabaseStyle use_database = database;
@@ -104,6 +106,6 @@ class OBackendPrivate;
104 } 106 }
105 107
106 switch ( type ){ 108 switch ( type ){
107 case OPimGlobal::TODOLIST: 109 case OPimGlobal::TODOLIST:
108 110
109 switch ( use_database ){ 111 switch ( use_database ){
@@ -168,5 +170,5 @@ class OBackendPrivate;
168 } 170 }
169 171
170 } 172 }
171 173
172 /** 174 /**
@@ -191,3 +193,3 @@ class OBackendPrivate;
191 } 193 }
192 194
193 Config config( "pimaccess" ); 195 Config config( "pimaccess" );
@@ -195,6 +197,6 @@ class OBackendPrivate;
195 QString db_String = config.readEntry( "usebackend", "xml" ); 197 QString db_String = config.readEntry( "usebackend", "xml" );
196 198
197 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); 199 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
198 dictDbTypes.setAutoDelete( TRUE ); 200 dictDbTypes.setAutoDelete( TRUE );
199 201
200 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); 202 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
@@ -202,12 +204,12 @@ class OBackendPrivate;
202 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); 204 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
203 205
204 int* db_find = dictDbTypes[ db_String ]; 206 int* db_find = dictDbTypes[ db_String ];
205 207
206 if ( !db_find ) 208 if ( !db_find )
207 return OPimGlobal::UNKNOWN; 209 return OPimGlobal::UNKNOWN;
208 210
209 return (OPimGlobal::DatabaseStyle) *db_find; 211 return (OPimGlobal::DatabaseStyle) *db_find;
210 } 212 }
211 213
212 214
213 /** 215 /**
@@ -224,5 +226,5 @@ class OBackendPrivate;
224 OBackendPrivate* d; 226 OBackendPrivate* d;
225 227
226 }; 228 };
227 229
228} 230}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.cpp b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
new file mode 100644
index 0000000..6ef60eb
--- a/dev/null
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
@@ -0,0 +1,121 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Freyther <freyther@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "ocontactaccessbackend.h"
31#include <opie2/private/opimcontactsortvector.h>
32#include <opie2/ocontactaccess.h>
33
34#include <opie2/odebug.h>
35
36namespace Opie {
37OPimContactAccessBackend::OPimContactAccessBackend() {}
38
39UIDArray
40OPimContactAccessBackend::queryByExample( const OPimContact&, int,
41 const QDateTime& )const {
42 return UIDArray();
43}
44
45UIDArray
46OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder,
47 int filter, const QArray<int>& categories)const {
48 odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl;
49
50 Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder );
51
52 int item = 0;
53 uint cat_count = categories.count();
54 uint eve_count = ar.count();
55 bool bCat = filter & OPimContactAccess::FilterCategory ? true : false;
56 bool catPassed = false;
57 int cat;
58
59 for ( uint i = 0; i < eve_count; ++i ) {
60 OPimContact contact = find( ar[i], ar, i, Frontend::Forward );
61 if ( contact.isEmpty() )
62 continue;
63
64 /* show category */
65 /* -1 == unfiled */
66 catPassed = false;
67 for ( uint cat_nu = 0; cat_nu < cat_count; ++cat_nu ) {
68 cat = categories[cat_nu];
69 if ( bCat && cat == -1 ) {
70 if(!contact.categories().isEmpty() )
71 continue;
72 } else if ( bCat && cat != 0)
73 if (!contact.categories().contains( cat ) )
74 continue;
75 catPassed = true;
76 break;
77 }
78
79 /*
80 * If none of the Categories matched
81 * continue
82 */
83 if ( !catPassed )
84 continue;
85
86 vector.insert(item++, contact );
87 }
88
89 vector.resize( item );
90 /* sort it now */
91 vector.sort();
92 /* now get the uids */
93 UIDArray array( vector.count() );
94 for (uint i= 0; i < vector.count(); i++ )
95 array[i] = vector.uidAt( i );
96
97 return array;
98}
99
100OPimBackendOccurrence::List OPimContactAccessBackend::occurrences( const QDate& start,
101 const QDate& end)const {
102 OPimBackendOccurrence::List lst;
103
104 UIDArray records = allRecords();
105 const uint count = records.count();
106 int uid;
107
108 for ( uint i = 0; i < count; ++i ) {
109 uid = records[i];
110 OPimContact contact = find(uid, records, i, Frontend::Forward );
111
112 QDate date = contact.anniversary();
113 date = QDate( start.year(), date.month(),date.day() );
114
115// if ( date.isValid() && date.) {
116// }
117 }
118
119 return lst;
120}
121}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h
index 8436adc..efb04c7 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.h
@@ -59,52 +59,46 @@ class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> {
59 public: 59 public:
60 /** 60 OPimContactAccessBackend();
61 * @todo make non line in regard to BC guide of KDE
62 */
63 OPimContactAccessBackend() {}
64 /**
65 * @todo make non inline in regard to the BC guide of KDE
66 */
67 virtual ~OPimContactAccessBackend() {}
68 61
69 62
70 /** 63 /**
71 * Return if database was changed externally. 64 * Return if database was changed externally.
72 * 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.
73 * It is used to prevent to overwrite the current database content 66 * It is used to prevent to overwrite the current database content
74 * if the file was already changed by something else ! 67 * if the file was already changed by something else !
75 * If this happens, we have to reload before save our data. 68 * If this happens, we have to reload before save our data.
76 * 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
77 * management system themselve, therefore this function should always return false in 70 * management system themselve, therefore this function should always return false in
78 * this case. It is not our problem to handle this conflict ... 71 * this case. It is not our problem to handle this conflict ...
79 * @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
80 * 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
81 * in this situation. 74 * in this situation.
82 */ 75 */
83 virtual bool wasChangedExternally() = 0; 76 virtual bool wasChangedExternally() = 0;
84 77
85 virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; 78 /**
79 * Return all possible settings.
80 * @return All settings provided by the current backend
81 * (i.e.: query_WildCards & query_IgnoreCase)
82 */
83 virtual const uint querySettings() = 0;
86 84
87 /** 85 /**
88 * Return all possible settings. 86 * Check whether settings are correct.
89 * @return All settings provided by the current backend 87 * @return <i>true</i> if the given settings are correct and possible.
90 * (i.e.: query_WildCards & query_IgnoreCase) 88 */
91 */ 89 virtual bool hasQuerySettings (uint querySettings) const = 0;
92 virtual const uint querySettings() = 0; 90
91 /**
92 * Slow and inefficent default implementation
93 */
94//@{
95 UIDArray queryByExample( const OPimContact&, int settings, const QDateTime& d = QDateTime() )const;
96 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
97 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const;
98//@}
93 99
94 /**
95 * Check whether settings are correct.
96 * @return <i>true</i> if the given settings are correct and possible.
97 */
98 virtual bool hasQuerySettings (uint querySettings) const = 0;
99 100
100 /**
101 * FIXME!!!
102 * Returns a sorted list of records either ascendinf or descending for a giving criteria and category
103 */
104 virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0;
105
106
107private: 101private:
108 class Private; 102 class Private;
109 Private *d; 103 Private *d;
110}; 104};
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index af77a05..43e530a 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -169,16 +169,2 @@ QArray<int> OPimContactAccessBackend_VCard::allRecords() const
169 169
170// Not implemented
171QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& )
172{
173 QArray<int> ar(0);
174 return ar;
175}
176
177// Not implemented
178QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
179{
180 QArray<int> ar(0);
181 return ar;
182}
183
184const uint OPimContactAccessBackend_VCard::querySettings() 170const uint OPimContactAccessBackend_VCard::querySettings()
@@ -198,12 +184,3 @@ bool OPimContactAccessBackend_VCard::wasChangedExternally()
198 184
199// Not implemented
200QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int )
201{
202 QArray<int> ar(0);
203 return ar;
204}
205
206// *** Private stuff *** 185// *** Private stuff ***
207
208
209OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) 186OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
@@ -322,3 +299,2 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
322 299
323 owarn << "value %s %d" << value.data() << type << oendl;
324 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) 300 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
@@ -527,3 +503,2 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
527 if ( c.birthday().isValid() ){ 503 if ( c.birthday().isValid() ){
528 owarn << "Exporting birthday as: " << convDateToVCardDate( c.birthday() ) << "" << oendl;
529 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); 504 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) );
@@ -546,3 +521,2 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
546 if ( c.anniversary().isValid() ){ 521 if ( c.anniversary().isValid() ){
547 owarn << "Exporting anniversary as: " << convDateToVCardDate( c.anniversary() ) << "" << oendl;
548 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); 522 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) );
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
index 2a786af..1faf747 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
@@ -61,4 +61,2 @@ class OPimContactAccessBackend_VCard : public OPimContactAccessBackend {
61 QArray<int> allRecords() const; 61 QArray<int> allRecords() const;
62 QArray<int> queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() );
63 QArray<int> matchRegexp( const QRegExp &r ) const;
64 62
@@ -66,3 +64,2 @@ class OPimContactAccessBackend_VCard : public OPimContactAccessBackend {
66 bool hasQuerySettings (uint querySettings) const; 64 bool hasQuerySettings (uint querySettings) const;
67 QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat );
68 bool wasChangedExternally(); 65 bool wasChangedExternally();
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 18113c2..5df7253 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -110,3 +110,2 @@ bool OPimContactAccessBackend_XML::save()
110 for ( ; it.current(); ++it ) { 110 for ( ; it.current(); ++it ) {
111 // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl;
112 out += "<Contact "; 111 out += "<Contact ";
@@ -139,4 +138,2 @@ bool OPimContactAccessBackend_XML::save()
139 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 138 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
140 owarn << "problem renaming file " << strNewFile << " to " << m_journalName
141 << ", errno: " << errno << oendl;
142 // remove the tmp file... 139 // remove the tmp file...
@@ -215,5 +212,4 @@ OPimContact OPimContactAccessBackend_XML::find ( int uid ) const
215QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, 212QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings,
216 const QDateTime& d ) 213 const QDateTime& d )const
217{ 214{
218
219 QArray<int> m_currentQuery( m_contactList.count() ); 215 QArray<int> m_currentQuery( m_contactList.count() );
@@ -280,4 +276,2 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
280 // ( maximum time range ) ! 276 // ( maximum time range ) !
281 owarn << "Checking if " << checkDate->toString() << " is between " << current.toString()
282 << " and " << queryDate->toString() << " ! " << oendl;
283 if ( current.daysTo( *queryDate ) >= 0 ){ 277 if ( current.daysTo( *queryDate ) >= 0 ){
@@ -286,3 +280,2 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
286 allcorrect = false; 280 allcorrect = false;
287 owarn << " Nope!.." << oendl;
288 } 281 }
@@ -432,2 +425,3 @@ bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
432 425
426#if 0
433// Currently only asc implemented.. 427// Currently only asc implemented..
@@ -460,2 +454,4 @@ QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
460} 454}
455#endif
456
461 457
@@ -463,3 +459,2 @@ bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
463{ 459{
464 //owarn << "odefaultbackend: ACTION::ADD" << oendl;
465 updateJournal (newcontact, ACTION_ADD); 460 updateJournal (newcontact, ACTION_ADD);
@@ -487,4 +482,2 @@ bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
487 482
488 owarn << "Nur zur Sicherheit: " << contact.uid() << " == " << newCont->uid() << " ?" << oendl;
489
490 return true; 483 return true;
@@ -593,4 +586,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
593 586
594 //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl;
595
596 XMLElement *root = XMLElement::load( filename ); 587 XMLElement *root = XMLElement::load( filename );
@@ -601,3 +592,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
601 XMLElement *element = root->firstChild(); 592 XMLElement *element = root->firstChild();
602 //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl;
603 element = element ? element->firstChild() : 0; 593 element = element ? element->firstChild() : 0;
@@ -607,4 +597,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
607 if( element->tagName() != QString::fromLatin1("Contacts") ){ 597 if( element->tagName() != QString::fromLatin1("Contacts") ){
608 //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: "
609 // << element->tagName() << oendl;
610 element = element->nextChild(); 598 element = element->nextChild();
@@ -618,4 +606,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
618 if( element->tagName() != QString::fromLatin1("Contact") ){ 606 if( element->tagName() != QString::fromLatin1("Contact") ){
619 //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: "
620 // << element->tagName() << oendl;
621 element = element->nextChild(); 607 element = element->nextChild();
@@ -626,4 +612,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
626 */ 612 */
627 //owarn << "OPimContactDefBack::load element tagName() : "
628 // << element->tagName() << oendl;
629 QString dummy; 613 QString dummy;
@@ -636,4 +620,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
636 for( it = aMap.begin(); it != aMap.end(); ++it ){ 620 for( it = aMap.begin(); it != aMap.end(); ++it ){
637 // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl;
638
639 int *find = dict[ it.key() ]; 621 int *find = dict[ it.key() ];
@@ -641,3 +623,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
641 if ( !find ) { 623 if ( !find ) {
642 // owarn << "Attribute " << it.key() << " not known." << oendl;
643 //contact.setCustomField(it.key(), it.data()); 624 //contact.setCustomField(it.key(), it.data());
@@ -706,6 +687,4 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
706 }else { 687 }else {
707 owarn << "ODefBack::could not load" << oendl;
708 } 688 }
709 delete root; 689 delete root;
710 owarn << "returning from loading" << oendl;
711 return true; 690 return true;
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
index eaea352..3e4f1e1 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h
@@ -64,4 +64,3 @@ class OPimContactAccessBackend_XML : public OPimContactAccessBackend {
64 64
65 QArray<int> queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() ); 65 QArray<int> queryByExample ( const OPimContact &query, int settings, const QDateTime& d )const;
66
67 QArray<int> matchRegexp( const QRegExp &r ) const; 66 QArray<int> matchRegexp( const QRegExp &r ) const;
@@ -72,4 +71,2 @@ class OPimContactAccessBackend_XML : public OPimContactAccessBackend {
72 71
73 // Currently only asc implemented..
74 QArray<int> sorted( bool asc, int , int , int );
75 bool add ( const OPimContact &newcontact ); 72 bool add ( const OPimContact &newcontact );
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
index f3b7b5f..73c7059 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -38,111 +38,42 @@ namespace {
38/* a small helper to get all NonRepeating events for a range of time */ 38/* a small helper to get all NonRepeating events for a range of time */
39 void events( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& events, 39void events( OPimBackendOccurrence::List& tmpList,
40 const QDate& from, const QDate& to ) { 40 const OPimEvent::ValueList& events,
41 QDateTime dtStart, dtEnd; 41 const QDate& from, const QDate& to ) {
42 42 QDateTime dtStart, dtEnd;
43 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { 43
44 dtStart = (*it).startDateTime(); 44 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
45 dtEnd = (*it).endDateTime(); 45 dtStart = (*it).startDateTime();
46 46 dtEnd = (*it).endDateTime();
47 /* 47
48 * If in range 48 /*
49 */ 49 * If in range
50 if (dtStart.date() >= from && dtEnd.date() <= to ) { 50 */
51 OEffectiveEvent eff; 51 if (dtStart.date() >= from && dtEnd.date() <= to ) {
52 eff.setEvent( (*it) ); 52 OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );;
53 eff.setDate( dtStart.date() ); 53 tmpList.append( eff );
54 eff.setStartTime( dtStart.time() );
55
56 /* if not on the same day */
57 if ( dtStart.date() != dtEnd.date() )
58 eff.setEndTime( QTime(23, 59, 0 ) );
59 else
60 eff.setEndTime( dtEnd.time() );
61
62 tmpList.append( eff );
63 }
64
65 /* we must also check for end date information... */
66 if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) {
67 QDateTime dt = dtStart.addDays( 1 );
68 dt.setTime( QTime(0, 0, 0 ) );
69 QDateTime dtStop;
70 if ( dtEnd > to )
71 dtStop = to;
72 else
73 dtStop = dtEnd;
74
75 while ( dt <= dtStop ) {
76 OEffectiveEvent eff;
77 eff.setEvent( (*it) );
78 eff.setDate( dt.date() );
79
80 if ( dt >= from ) {
81 eff.setStartTime( QTime(0, 0, 0 ) );
82 if ( dt.date() == dtEnd.date() )
83 eff.setEndTime( dtEnd.time() );
84 else
85 eff.setEndTime( QTime(23, 59, 0 ) );
86 tmpList.append( eff );
87 }
88 dt = dt.addDays( 1 );
89 }
90 }
91 } 54 }
92 } 55 }
56}
93 57
94 void repeat( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& list, 58void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list,
95 const QDate& from, const QDate& to ) { 59 const QDate& from, const QDate& to ) {
96 QDate repeat; 60 QDate repeat;
97 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { 61 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
98 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); 62 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
99 QDate itDate = from.addDays(-dur ); 63 QDate itDate = from.addDays(-dur );
100 OPimRecurrence rec = (*it).recurrence(); 64 OPimRecurrence rec = (*it).recurrence();
101 if ( !rec.hasEndDate() || rec.endDate() > to ) { 65 if ( !rec.hasEndDate() || rec.endDate() > to ) {
102 rec.setEndDate( to ); 66 rec.setEndDate( to );
103 rec.setHasEndDate( true ); 67 rec.setHasEndDate( true );
104 } 68 }
105 while (rec.nextOcurrence(itDate, repeat ) ) { 69
106 if (repeat > to ) break; 70 QDateTime start, end;
107 OEffectiveEvent eff; 71 while (rec.nextOcurrence(itDate, repeat ) ) {
108 eff.setDate( repeat ); 72 if (repeat > to ) break;
109 if ( (*it).isAllDay() ) { 73
110 eff.setStartTime( QTime(0, 0, 0 ) ); 74 OPimEvent event = *it;
111 eff.setEndTime( QTime(23, 59, 59 ) ); 75 start = QDateTime( repeat, event.startDateTime().time() );
112 }else { 76 end = QDateTime( repeat.addDays(dur), event.endDateTime().time() );
113 /* we only occur by days, not hours/minutes/seconds. Hence 77 OPimBackendOccurrence eff(start, end, event.uid() );
114 * the actual end and start times will be the same for 78 tmpList.append( eff );
115 * every repeated event. For multi day events this is
116 * fixed up later if on wronge day span
117 */
118 eff.setStartTime( (*it).startDateTime().time() );
119 eff.setEndTime( (*it).endDateTime().time() );
120 }
121 if ( dur != 0 ) {
122 // multi-day repeating events
123 QDate sub_it = QMAX( repeat, from );
124 QDate startDate = repeat;
125 QDate endDate = startDate.addDays( dur );
126
127 while ( sub_it <= endDate && sub_it <= to ) {
128 OEffectiveEvent tmpEff = eff;
129 tmpEff.setEvent( (*it) );
130 if ( sub_it != startDate )
131 tmpEff.setStartTime( QTime(0, 0, 0 ) );
132 if ( sub_it != endDate )
133 tmpEff.setEndTime( QTime( 23, 59, 59 ) );
134
135 tmpEff.setDate( sub_it );
136 tmpEff.setEffectiveDates( startDate, endDate );
137 tmpList.append( tmpEff );
138
139 sub_it = sub_it.addDays( 1 );
140 }
141 itDate = endDate;
142 }else {
143 eff.setEvent( (*it) );
144 tmpList.append( eff );
145 itDate = repeat.addDays( 1 );
146 }
147 }
148 } 79 }
@@ -150,2 +81,3 @@ namespace {
150} 81}
82}
151 83
@@ -161,33 +93,20 @@ ODateBookAccessBackend::~ODateBookAccessBackend() {
161} 93}
162OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from, 94OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from,
163 const QDate& to ) { 95 const QDate& to )const {
164 OEffectiveEvent::ValueList tmpList; 96 OPimBackendOccurrence::List tmpList;
165 OPimEvent::ValueList list = directNonRepeats();
166 97
167 events( tmpList, list, from, to ); 98 events( tmpList, directNonRepeats(), from, to );
168 repeat( tmpList, directRawRepeats(),from,to ); 99 repeat( tmpList, directRawRepeats(),from,to );
169 100
170 list = directRawRepeats(); // Useless, isn't it ? (eilers)
171
172 qHeapSort( tmpList );
173 return tmpList; 101 return tmpList;
174} 102}
175OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) { 103OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const {
176 OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() ); 104 OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() );
177 OEffectiveEvent::ValueList::Iterator it;
178
179 OEffectiveEvent::ValueList tmpList;
180 QDateTime dtTmp;
181 for ( it = day.begin(); it != day.end(); ++it ) {
182 dtTmp = QDateTime( (*it).date(), (*it).startTime() );
183 if ( QABS(dt.secsTo(dtTmp) ) < 60 )
184 tmpList.append( (*it) );
185 }
186 105
187 return tmpList; 106 return filterOccurrences( day, dt );
188} 107}
189 108
190OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, 109OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
191 const QDate& to ) { 110 const QDate& to )const {
192 OEffectiveEvent::ValueList tmpList; 111 OPimBackendOccurrence::List tmpList;
193 OPimEvent::ValueList list = directNonRepeats(); 112 OPimEvent::ValueList list = directNonRepeats();
@@ -196,3 +115,2 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents(
196 115
197 qHeapSort( tmpList );
198 return tmpList; 116 return tmpList;
@@ -200,12 +118,43 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents(
200 118
201OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { 119OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const {
202 OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); 120 OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
203 OEffectiveEvent::ValueList::Iterator it; 121 return filterOccurrences( day,dt );
122}
123
124
125UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings,
126 const QDateTime& d )const {
127 return UIDArray();
128}
129
130UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const {
131 return UIDArray();
132}
204 133
205 OEffectiveEvent::ValueList tmpList; 134OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
206 QDateTime dtTmp; 135 const QDateTime& dt ) {
207 for ( it = day.begin(); it != day.end(); ++it ) { 136 OPimBackendOccurrence::List tmpList;
208 dtTmp = QDateTime( (*it).date(), (*it).startTime() ); 137 OPimBackendOccurrence::List::ConstIterator it;
209 if ( QABS(dt.secsTo(dtTmp) ) < 60 ) 138
210 tmpList.append( (*it) ); 139 for ( it = dayList.begin(); it != dayList.end(); ++it ) {
140 OPimBackendOccurrence occ = *it;
141
142 /*
143 * Let us find occurrences that are 'now'!
144 * If the dt.date() is on the same day as start or end of the Occurrence
145 * check how near start/end are.
146 * If it is in the middle of a multiday occurrence list it.
147 *
148 * We might want to 'lose' the sixty second offset and list
149 * all Events which are active at that time.
150 */
151 if ( dt.date() == occ.startDateTime().date() ) {
152 if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 )
153 tmpList.append( occ );
154 }else if ( dt.date() == occ.endDateTime().date() ) {
155 if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 )
156 tmpList.append( occ );
157 }else if ( dt.date() >= occ.startDateTime().date() &&
158 dt.date() >= occ.endDateTime().date() )
159 tmpList.append( occ );
211 } 160 }
@@ -214,3 +163,2 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents(
214} 163}
215
216} 164}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h
index a9cce6a..8927ca1 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.h
@@ -44,4 +44,2 @@ class ODateBookAccessBackend : public OPimAccessBackend<OPimEvent> {
44public: 44public:
45 typedef int UID;
46
47 /** 45 /**
@@ -54,9 +52,2 @@ public:
54 * This method should return a list of UIDs containing 52 * This method should return a list of UIDs containing
55 * all events. No filter should be applied
56 * @return list of events
57 */
58 virtual QArray<UID> rawEvents()const = 0;
59
60 /**
61 * This method should return a list of UIDs containing
62 * all repeating events. No filter should be applied 53 * all repeating events. No filter should be applied
@@ -64,3 +55,3 @@ public:
64 */ 55 */
65 virtual QArray<UID> rawRepeats()const = 0; 56 virtual UIDArray rawRepeats()const = 0;
66 57
@@ -71,3 +62,3 @@ public:
71 */ 62 */
72 virtual QArray<UID> nonRepeats() const = 0; 63 virtual UIDArray nonRepeats() const = 0;
73 64
@@ -78,3 +69,3 @@ public:
78 */ 69 */
79 virtual OPimEvent::ValueList directNonRepeats() = 0; 70 virtual OPimEvent::ValueList directNonRepeats()const = 0;
80 71
@@ -83,3 +74,3 @@ public:
83 */ 74 */
84 virtual OPimEvent::ValueList directRawRepeats() = 0; 75 virtual OPimEvent::ValueList directRawRepeats()const = 0;
85 76
@@ -91,3 +82,3 @@ public:
91 */ 82 */
92 virtual OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); 83 virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const;
93 84
@@ -95,19 +86,21 @@ public:
95 * this is an overloaded member function 86 * this is an overloaded member function
96 * @see effectiveEvents( const QDate& from, const QDate& to ) 87 * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to )
97 */
98 virtual OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start );
99
100 /**
101 * Effective Events are special event occuring during a time frame. This method does calcualte
102 * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
103 * yourself
104 */ 88 */
105 virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ); 89 virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start )const;
106 90
107 /** 91 /**
108 * this is an overloaded member function 92 * Common and probably inefficent implementation
109 * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) 93 * for queryByExample, sorted
94 * and occurrences
110 */ 95 */
111 virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ); 96//@{
112 97 UIDArray queryByExample( const OPimEvent&, int settings, const QDateTime& d = QDateTime() )const;
98 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
99 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& end )const;
100 OPimBackendOccurrence::List occurrences( const QDateTime& )const;
101//@}
102
103protected:
104 static OPimBackendOccurrence::List filterOccurrences(const OPimBackendOccurrence::List,
105 const QDateTime& time );
113private: 106private:
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index 105c106..41b714e 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -169,4 +169,2 @@ bool ODateBookAccessBackend_SQL::load()
169 169
170 owarn << "command: " << qu << "" << oendl;
171
172 OSQLRawQuery raw( qu ); 170 OSQLRawQuery raw( qu );
@@ -290,3 +288,2 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
290 } 288 }
291 owarn << "add " << qu << "" << oendl;
292 289
@@ -330,6 +327,2 @@ bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
330 327
331QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
332{
333 return allRecords();
334}
335 328
@@ -361,3 +354,3 @@ QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
361 354
362OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() 355OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const
363{ 356{
@@ -373,3 +366,3 @@ OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
373} 366}
374OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() 367OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const
375{ 368{
@@ -412,3 +405,2 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
412{ 405{
413 owarn << "extractUids" << oendl;
414 QTime t; 406 QTime t;
@@ -418,3 +410,2 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
418 QArray<int> ints(list.count() ); 410 QArray<int> ints(list.count() );
419 owarn << " count = " << list.count() << "" << oendl;
420 411
@@ -425,3 +416,2 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
425 } 416 }
426 owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
427 417
@@ -442,3 +432,2 @@ QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) cons
442 if ( res_custom.state() == OSQLResult::Failure ) { 432 if ( res_custom.state() == OSQLResult::Failure ) {
443 owarn << "OSQLResult::Failure in find query !!" << oendl;
444 QMap<QString, QString> empty; 433 QMap<QString, QString> empty;
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
index b624159..a649d25 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
@@ -68,3 +68,2 @@ public:
68 68
69 QArray<UID> rawEvents()const;
70 QArray<UID> rawRepeats()const; 69 QArray<UID> rawRepeats()const;
@@ -72,4 +71,4 @@ public:
72 71
73 OPimEvent::ValueList directNonRepeats(); 72 OPimEvent::ValueList directNonRepeats()const;
74 OPimEvent::ValueList directRawRepeats(); 73 OPimEvent::ValueList directRawRepeats()const;
75 74
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index 0f99d50..55e47e2 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -124,3 +124,2 @@ namespace {
124 static void save( const OPimEvent& ev, QString& buf ) { 124 static void save( const OPimEvent& ev, QString& buf ) {
125 owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl;
126 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; 125 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
@@ -328,5 +327,3 @@ bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) {
328} 327}
329QArray<int> ODateBookAccessBackend_XML::rawEvents()const { 328
330 return allRecords();
331}
332QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { 329QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
@@ -355,3 +352,3 @@ QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
355} 352}
356OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { 353OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats()const {
357 OPimEvent::ValueList list; 354 OPimEvent::ValueList list;
@@ -363,3 +360,3 @@ OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
363} 360}
364OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { 361OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats()const {
365 OPimEvent::ValueList list; 362 OPimEvent::ValueList list;
@@ -541,3 +538,2 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
541 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { 538 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
542 owarn << "already contains assign uid" << oendl;
543 ev.setUid( 1 ); 539 ev.setUid( 1 );
@@ -552,3 +548,2 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
552void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { 548void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) {
553// owarn << " setting " << value << "" << oendl;
554 switch( id ) { 549 switch( id ) {
@@ -636,3 +631,2 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
636 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); 631 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() );
637 owarn << "adding exception " << date.toString() << "" << oendl;
638 recur()->exceptions().append( date ); 632 recur()->exceptions().append( date );
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
index af5b114..cb19f76 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
@@ -65,4 +65,4 @@ public:
65 65
66 OPimEvent::ValueList directNonRepeats(); 66 OPimEvent::ValueList directNonRepeats()const;
67 OPimEvent::ValueList directRawRepeats(); 67 OPimEvent::ValueList directRawRepeats()const;
68 68
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 26af762..0d112c9 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -36,3 +36,3 @@
36#include <opie2/opimrecord.h> 36#include <opie2/opimrecord.h>
37 37#include <opie2/opimbackendoccurrence.h>
38 38
@@ -40,9 +40,12 @@ namespace Opie {
40class OPimAccessBackendPrivate; 40class OPimAccessBackendPrivate;
41
41/** 42/**
42 * OPimAccessBackend is the base class 43 * OPimAccessBackend is the Backend Interface to be used
43 * for all private backends 44 * by OTemplateBase based Frontends.
44 * it operates on OPimRecord as the base class 45 * For efficency reasons and to support delayed loading
45 * and it's responsible for fast manipulating 46 * most of the Frontend functions can be implemented
46 * the resource the implementation takes care 47 * by this backend.
47 * of 48 * This allows to utilise the best method on each backend.
49 * For example we can use SQL queries instead of self made
50 * query which is first more efficent and also uses less memory.
48 */ 51 */
@@ -53,71 +56,42 @@ public:
53 56
54 /** The access hint from the frontend */ 57 //@{
55 OPimAccessBackend(int access = 0); 58 OPimAccessBackend(int access = 0);
56 virtual ~OPimAccessBackend(); 59 virtual ~OPimAccessBackend();
60 //@}
57 61
58 /** 62 //@{
59 * load the resource
60 */
61 virtual bool load() = 0; 63 virtual bool load() = 0;
62
63 /**
64 * reload the resource
65 */
66 virtual bool reload() = 0; 64 virtual bool reload() = 0;
67
68 /**
69 * save the resource and
70 * all it's changes
71 */
72 virtual bool save() = 0; 65 virtual bool save() = 0;
66 virtual void clear() = 0;
67 //@}
73 68
74 /**
75 * return an array of
76 * all available uids
77 */
78 virtual QArray<int> allRecords()const = 0;
79 69
80 /** 70 //@{
81 * return a List of records 71 virtual UIDArray allRecords()const = 0;
82 * that match the regex 72 virtual UIDArray matchRegexp(const QRegExp &r) const;
83 */ 73 virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const = 0;
84 virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; 74 virtual UIDArray queryByExample( const OPimRecord* rec, int, const QDateTime& d = QDateTime() )const;
75 virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const;
76 virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const;
77 virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const;
78 virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const;
79 //@}
85 80
86 /**
87 * queryByExample for T with the given Settings
88 *
89 */
90 virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0;
91 81
92 /** 82 //@{
93 * find the OPimRecord with uid @param uid 83 virtual T find(UID uid )const = 0;
94 * returns T and T.isEmpty() if nothing was found 84 virtual T find(UID uid, const QArray<UID>& items,
95 */ 85 uint current, typename Frontend::CacheDirection )const ;
96 virtual T find( int uid )const = 0; 86 //@}
97 87
98 virtual T find( int uid, const QArray<int>& items,
99 uint current, typename Frontend::CacheDirection ) const;
100 /**
101 * clear the back end
102 */
103 virtual void clear() = 0;
104 88
105 /** 89 //@{
106 * add T
107 */
108 virtual bool add( const T& t ) = 0; 90 virtual bool add( const T& t ) = 0;
91 virtual bool remove( UID uid ) = 0;
92 virtual bool replace( const T& t ) = 0;
93 //@}
109 94
110 /**
111 * remove
112 */
113 virtual bool remove( int uid ) = 0;
114 95
115 /**
116 * replace a record with T.uid()
117 */
118 virtual bool replace( const T& t ) = 0;
119 96
120 /*
121 * setTheFrontEnd!!!
122 */
123 void setFrontend( Frontend* front ); 97 void setFrontend( Frontend* front );
@@ -129,12 +103,8 @@ public:
129protected: 103protected:
104 //@{
130 int access()const; 105 int access()const;
131
132 void cache( const T& t )const; 106 void cache( const T& t )const;
133
134 /**
135 * use a prime number here!
136 */
137 void setSaneCacheSize( int ); 107 void setSaneCacheSize( int );
138
139 uint readAhead()const; 108 uint readAhead()const;
109 //@}
140 110
@@ -158,2 +128,60 @@ OPimAccessBackend<T>::~OPimAccessBackend() {
158} 128}
129
130/*
131 * Slow but default matchRegexp Implementation
132 * Create a Big Enough QArray and then iterate
133 * over all Records and matchRegexp them.
134 * At the end we will resize the array to the actual
135 * number of items
136 */
137template <class T>
138UIDArray OPimAccessBackend<T>::matchRegexp( const QRegExp& reg )const {
139 UIDArray all_rec = allRecords();
140 UIDArray result( all_rec.count() );
141 uint used_records = 0, all_rec_count = all_rec.count();
142
143 for ( uint i = 0; i < all_rec_count; ++i )
144 if (find( all_rec[i], all_rec, i, Frontend::Forward ).match( reg ) )
145 result[used_records++] = all_rec[i];
146
147 /* shrink to fit */
148 result.resize( used_records );
149 return result;
150}
151
152template <class T>
153UIDArray OPimAccessBackend<T>::queryByExample( const OPimRecord* rec, int settings,
154 const QDateTime& datetime )const {
155 T* tmp_rec = T::safeCast( rec );
156 UIDArray ar;
157 if ( tmp_rec )
158 ar = queryByExample( *tmp_rec, settings, datetime );
159
160 return ar;
161}
162
163template <class T>
164UIDArray OPimAccessBackend<T>::sorted( const UIDArray& ids, bool,
165 int, int, const QArray<int>& ) const {
166 return ids;
167}
168
169template <class T>
170UIDArray OPimAccessBackend<T>::sorted( bool asc, int order, int filter,
171 const QArray<int>& cats )const {
172 return sorted( allRecords(), asc, order, filter, cats );
173}
174
175template<class T>
176OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDate&,
177 const QDate& )const {
178 return OPimBackendOccurrence::List();
179}
180
181template<class T>
182OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDateTime& dt )const {
183 QDate date = dt.date();
184 return occurrences( date, date );
185}
186
159template <class T> 187template <class T>
@@ -168,3 +196,2 @@ void OPimAccessBackend<T>::cache( const T& t )const {
168 196
169
170template <class T> 197template <class T>
@@ -195,2 +222,202 @@ int OPimAccessBackend<T>::access()const {
195 222
223/**
224 * \fn template <class T> OPimAccessBackend<T>::OPimAccessBackend(int hint )
225 * @param hint The access hint from the frontend
226 */
227
228/**
229 * \fn template <class T> bool OPimAccessBackend<T>::load()
230 * Opens the DataBase and does necessary
231 * initialisation of internal structures.
232 *
233 * @return true If the DataBase could be opened and
234 * Information was successfully loaded
235 */
236
237/**
238 * \fn template <class T> bool OPimAccessBackend<T>::reload()
239 * Reinitialise the DataBase and merges the external changes
240 * with your local changes.
241 *
242 * @return True if the DataBase was reloaded.
243 *
244 */
245
246/**
247 * \fn template <class T> bool OPimAccessBackend<T>::save()
248 *
249 * Save the changes to storage. In case of memory or
250 * disk shortage, return false.
251 *
252 *
253 * @return True if the DataBase could be saved to storage.
254 */
255
256/**
257 * \fn template <class T> bool OPimAccessBackend<T>::clear()
258 * Until a \sa save() changes shouldn't be comitted
259 *
260 *
261 * @return True if the DataBase could be cleared
262 * @todo Introduce a 'Commit'
263 */
264
265/**
266 * \fn template <class T> QArray<UID> OPimAccessBackend<T>::allRecords()const
267 * Return an array of all available uids in the loaded
268 * DataBase.
269 * @see load
270 */
271
272/**
273 * \fn template <class T> QArray<UID> OPimAccessBackend<T>::matchRegexp(const QRegExp& r)const
274 * Return a List of records that match the regex \par r.
275 *
276 * @param r The QRegExp to match.
277 */
278
279/**
280 * \fn template <class T> QArray<UID> OPimAccessBackend<T>::queryByExample(const T& t, int settings, const QDateTime& d = QDateTime() )
281 *
282 * Implement QueryByExample. An Example record is filled and with the
283 * settings and QDateTime it is determined how the query should be executed.
284 * Return a list of UIDs that match the Example
285 *
286 * @param t The Example record
287 * @param settings Gives
288 *
289 */
290
291/**
292 * \fn template<class T> QArray<UID> OPimAccessBackend<T>::sorted(const QArray<UID>& ids, bool asc, int sortOrder, int sortFilter, int cat)
293 * \brief Sort the List of records according to the preference
294 *
295 * Implement sorting in your backend. The default implementation is
296 * to return the list as it was passed.
297 * The default Backend Implementation should do unaccelerated filtering
298 *
299 *
300 * @param ids The Records to sort
301 * @param asc Sort ascending or descending
302 * @param sortOrder
303 * @param sortFilter Sort filter
304 * @param cat The Category to include
305 */
306
307/**
308 * \fn template <class T> T OPimAccessBackend<T>::find(UID uid)const
309 * \brief Find the Record with the UID
310 *
311 * Find the UID in the database and return the record.
312 * @param uid The uid to be searched for
313 * @return The record or an empty record (T.isEmpty())
314 *
315 */
316
317/**
318 * \fn template <class T> T OPimAccessBackend<T>::find( UID uid, const QArray<UID>& items, uint current, typename Frontend::CacheDirection d)const
319 * \brief find a Record and do a read ahead or read behind
320 *
321 * @param uid The UID to search for
322 * @param items The list of items from where your search
323 * @param current The index of \param uid
324 * @param d The direction to search for
325 *
326 * @see find
327 */
328
329
330/**
331 * \fn template<class T> bool OPimAccessBackend<T>::add(const T& t)
332 *
333 * \brief Add the record to the internal database
334 *
335 * If an record with the same t.uid() is already present internally
336 * the behaviour is undefined but the state of the database
337 * needs to be stable.
338 * For modifying a record use \sa replace.
339 *
340 *
341 * @return true if the record could be added or false if not
342 * @todo Eilers your opinion on readd/replace
343 */
344
345/**
346 * \fn template<class T> bool OPimAccessBackend<T>::remove(UID uid)
347 * \brief Remove a record by its UID
348 *
349 * Remove the records with UID from the internal Database.
350 *
351 * @return True if the record could be removed.
352 *
353 */
354
355/**
356 * \fn template<class T> bool OPimAccessBackend<T>::replace(const T& t)
357 * \brief Take this Record and replace the old version.
358 *
359 * Take \param t as the new record for t.uid(). It is not described
360 * what happens if the record is not present in the database.
361 * Normally the record is determined by the UID.
362 *
363 * @param t The record to use internally.
364 */
365
366/**
367 * \fn template<class T> void OPimAccessBackend<T>::setFrontend( Frontend* fron)
368 * \@aram fron The Frontend that uses this backend
369 *
370 * This function is called by the frontend and is used
371 */
372
373/**
374 * \fn template<class T> void OPimAccessBackend<T>::setReadAhead(uint count)
375 * \brief Set the number of items to Read-Ahead/Read-Behind
376 *
377 * @param count The number of records to read ahead
378 */
379
380/**
381 * \fn template<class T> void OPimAccessBackend<T>::cache( const T& t)const
382 * \brief Add the Record to the PIM Cache
383 *
384 * This will add the Record to the PIM cache, which is owned
385 * by the FrontEnd. If no FrontEnd is available the item will
386 * not be cached.
387 *
388 *
389 * @param t The Item to be added to the Cache
390 */
391
392/**
393 * \fn template<class T> void OPimAccessBackend<T>::setSaneCacheSize(int items)
394 * \brief Give a hint on the number of too cached items
395 *
396 * Give the Frontend a hint on the number of items to be cached. Use
397 * a prime number for best performance.
398 *
399 * @param items The number of items to be cached
400 */
401
402/**
403 * \fn template<class T> uint OPimAccessBackend<T>::readAhead()const
404 * \brief Return the number of Items to be ReadAhead
405 *
406 * @return The number of Items to read ahead/read behind
407 */
408
409/**
410 * \fn template<class T> QArray<OPimBackendOccurence> OPimAccessBackend<T>::occurrences(const QDateTime& start,const QDateTime& end)
411 * \brief Get a List of Occurrences for a period of time
412 *
413 * Return an Array of OPimBackendOccurence for a period of time. If start == end date
414 * return only occurrences for the start date. If end is smaller the start date
415 * the result is not defined. You could switch dates or return an empty list.
416 *
417 * @return Return an array of OPimBackendOccurence for the period specified by the parameters
418 * @param start The start of the period.
419 * @param end The end of the period.
420 *
421 */
422
196#endif 423#endif
diff --git a/libopie2/opiepim/backend/opimbackendoccurrence.cpp b/libopie2/opiepim/backend/opimbackendoccurrence.cpp
new file mode 100644
index 0000000..8af930d
--- a/dev/null
+++ b/libopie2/opiepim/backend/opimbackendoccurrence.cpp
@@ -0,0 +1,241 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Hans Peter Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimbackendoccurrence.h"
31
32namespace Opie {
33
34OPimBackendOccurrence::OPimBackendOccurrence() {}
35/**
36 * \brief The occurence is only on the specefic Day
37 *
38 * If an occurrence is only a day without any time associated
39 * use this Constructor.
40 * \sa timeAssociated() will return false.
41 *
42 * @param date The Date this Occurence takes place
43 * @param uid The \sa UID of the associated OPimRecord
44 * @param sum The optional summary
45 *
46 */
47OPimBackendOccurrence::OPimBackendOccurrence( const QDate& date,
48 const UID& uid,
49 const QString& sum )
50 : m_start( date ), m_end( date ), m_uid( uid ),
51 m_haveTime(false ), m_summary( sum )
52{}
53
54/**
55 * \brief An Occurrence with a start day and end day without time
56 *
57 * Overloaded Constructor. Use this if you've a start date and
58 * end date but no time. If you need to overwrite the summary
59 * use setSummary.
60 * \sa timeAssociated() will return false.
61 *
62 * @param date The Start Date
63 * @param end Tne End Date
64 * @param uid The UID of the associated record
65 *
66 * @see setSummary
67 */
68OPimBackendOccurrence::OPimBackendOccurrence( const QDate& date,
69 const QDate& end,
70 const UID& uid)
71 : m_start( date ), m_end( end ), m_uid( uid ), m_haveTime( false )
72{}
73
74
75/**
76 * \brief Use Start and End Date with Time
77 *
78 * Overloaded Constructor to use Dates with Time time associated
79 * to it. \sa timeAssociated() will return true.
80 *
81 * @param date The Start Date and Time of the occurrence
82 * @param end The End Date and Time of the occurrence
83 * @param uid The UID of the \sa OPimRecord.
84 */
85OPimBackendOccurrence::OPimBackendOccurrence( const QDateTime& date,
86 const QDateTime& end,
87 const UID& uid )
88 : m_start( date ), m_end( end ), m_uid( uid ), m_haveTime( true )
89{}
90
91/**
92 * \brief Return the Start Date and Time
93 *
94 * @return This method will return the start
95 * Date and Time. Time is only valid if
96 * \sa timeAssociated() is true.
97 *
98 */
99QDateTime OPimBackendOccurrence::startDateTime()const {
100 return m_start;
101}
102
103/**
104 * \brief Return the Start Date and Time
105 *
106 * @return This will return the end Date and Time. The
107 * limitation for Time is the same as in startDateTime
108 *
109 * @see startDateTime()
110 */
111QDateTime OPimBackendOccurrence::endDateTime()const {
112 return m_end;
113}
114
115/**
116 * \brief Return the UID of the Associated OPimRecord
117 *
118 * @return the associated OPimRecord
119 */
120UID OPimBackendOccurrence::uid()const {
121 return m_uid;
122}
123
124/**
125 * \brief Return if there is a time associated or not
126 *
127 * If a time is present with start and end date this method
128 * will return true. There is no direct way to manipulate
129 * that attribute. But \sa setStartDate and \sa setStartDateTime
130 * will change it.
131 *
132 * @return Return true if a time is available with the date
133 *
134 */
135bool OPimBackendOccurrence::isAllDay()const {
136 return m_haveTime;
137}
138
139/**
140 * @return The special summary that will overwrite OPimRecord::summary
141 */
142QString OPimBackendOccurrence::summary()const {
143 return m_summary;
144}
145
146QString OPimBackendOccurrence::location()const {
147 return m_location;
148}
149
150QString OPimBackendOccurrence::note()const {
151 return m_note;
152}
153
154/**
155 * \brief Set the Start Date
156 *
157 * This method will set the start date and internally will mark
158 * this occurrence to have no time associated to both start
159 * and end date.
160 * A call to timeAssociated will return false after using this
161 * method.
162 *
163 * @param start The Start Date
164 *
165 */
166void OPimBackendOccurrence::setStartDate( const QDate& start) {
167 m_start = start;
168 m_haveTime = false;
169}
170
171/**
172 * \brief Set the Start Date and Time
173 *
174 * Set the Start Date and Time. After this call
175 * \sa timeAssociated will return true.
176 *
177 * @param dt The Start Date and Time to be set
178 */
179void OPimBackendOccurrence::setStartDateTime( const QDateTime& dt ) {
180 m_start = dt;
181 m_haveTime = true;
182}
183
184/**
185 * \brief This will set the End Date.
186 *
187 * This method will set the End Date. The timeAssociated attribute
188 * will not be changed.
189 *
190 * @param end The End Date to be set
191 */
192void OPimBackendOccurrence::setEndDate( const QDate& end ) {
193 m_end = end;
194}
195
196/**
197 * \brief Set the End Date and Time of the occurrence
198 *
199 * This will set the End Date and Time but will not change
200 * the timeAssociated attribute.
201 *
202 * @param dt The End Date and Time to be set.
203 */
204void OPimBackendOccurrence::setEndDateTime( const QDateTime& dt ) {
205 m_end = dt;
206}
207
208/**
209 * \brief This method will set the UID of the Record
210 *
211 * Set the UID of the OPimRecord to be associated with
212 * this OPimRecurrence.
213 *
214 * @param uid The UID of the associated OPimRecord to be set
215 */
216void OPimBackendOccurrence::setUid( const UID& uid ) {
217 m_uid = uid;
218}
219
220
221/**
222 * \brief Set a special summary instead of \sa OPimRecord::summary()
223 *
224 * If \sa OPimRecord::summary() doesn't describe the occurrence
225 * reason you can set a custom summary for the Occurrence.
226 *
227 * @param str The to be set Summary
228 */
229void OPimBackendOccurrence::setSummary( const QString& str ) {
230 m_summary = str;
231}
232
233void OPimBackendOccurrence::setLocation( const QString& str ) {
234 m_location = str;
235}
236
237void OPimBackendOccurrence::setNote( const QString& str ) {
238 m_note = str;
239}
240
241}
diff --git a/libopie2/opiepim/backend/opimbackendoccurrence.h b/libopie2/opiepim/backend/opimbackendoccurrence.h
new file mode 100644
index 0000000..08c3cdf
--- a/dev/null
+++ b/libopie2/opiepim/backend/opimbackendoccurrence.h
@@ -0,0 +1,108 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Hans Peter Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OPIE_PIM_BACKEND_OCCURRENCE_H
31#define OPIE_PIM_BACKEND_OCCURRENCE_H
32
33#include <opie2/opimglobal.h>
34
35#include <qarray.h>
36#include <qdatetime.h>
37#include <qvaluelist.h>
38
39namespace Opie {
40
41/**
42 * \brief Internal representation of an Occurence
43 *
44 * This class is used by the Backends to express
45 * Occurences for the Period Based Query to
46 * the by the Backend represanted Database.
47 * In the Frontend this single representation is splitted
48 * into per day \sa OPimOccurrence 's.
49 * OPimBackendOccurrence can be understand as a hint to
50 * the Frontend and must contain the \sa UID, the Start Date
51 * and End Date of the Occurence. If you have no time associated
52 * to the datetime use the QDate constructors.
53 * If OPimRecord::summary() does not describe the Occurrence
54 * right you can call setSummary() and then the supplied
55 * summary will be used.
56 * All Dates and Times are in the local time.
57 *
58 * @version 1.0
59 * @author Holger Hans Peter Freyther zecke@handhelds.org
60 */
61class OPimBackendOccurrence {
62public:
63 typedef QValueList<OPimBackendOccurrence> List;
64
65 //@{
66 OPimBackendOccurrence();
67 OPimBackendOccurrence( const QDate& date,
68 const UID& , const QString& = QString::null );
69 OPimBackendOccurrence( const QDate& date, const QDate& end,
70 const UID& );
71 OPimBackendOccurrence( const QDateTime& start,
72 const QDateTime& end,
73 const UID& uid );
74 //@}
75
76 //@{
77 QDateTime startDateTime()const;
78 QDateTime endDateTime()const;
79 UID uid()const;
80 bool isAllDay()const;
81 QString summary()const;
82 QString location()const;
83 QString note()const;
84 //@}
85
86 //@{
87 void setStartDate( const QDate& );
88 void setStartDateTime( const QDateTime& dt );
89 void setEndDate( const QDate& );
90 void setEndDateTime( const QDateTime& dt );
91 void setUid( const UID& );
92 void setSummary( const QString& );
93 void setLocation( const QString& );
94 void setNote( const QString& );
95 //@}
96
97private:
98 QDateTime m_start, m_end;
99 UID m_uid;
100 bool m_haveTime : 1;
101 QString m_summary, m_note, m_location;
102
103 struct Private;
104 Private *d;
105};
106}
107
108#endif
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.cpp b/libopie2/opiepim/backend/otodoaccessbackend.cpp
index 790a764..5f86be9 100644
--- a/libopie2/opiepim/backend/otodoaccessbackend.cpp
+++ b/libopie2/opiepim/backend/otodoaccessbackend.cpp
@@ -30,2 +30,6 @@
30#include <opie2/otodoaccessbackend.h> 30#include <opie2/otodoaccessbackend.h>
31#include <opie2/private/opimtodosortvector.h>
32#include <opie2/otodoaccess.h>
33
34#include <qintdict.h>
31 35
@@ -40,2 +44,112 @@ OPimTodoAccessBackend::~OPimTodoAccessBackend() {
40 44
45UIDArray OPimTodoAccessBackend::queryByExample( const OPimTodo&, int settings,
46 const QDateTime& d)const {
47 return UIDArray();
48}
49
50UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc,
51 int sortOrder, int sortFilter,
52 const QArray<int>& categories )const {
53 odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl;
54 Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder );
55 int item = 0;
56
57 bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false;
58 bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false;
59 bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false;
60 bool catPassed = false;
61 int cat;
62
63 for ( uint i = 0; i < events.count(); ++i ) {
64 OPimTodo todo = find( events[i], events, i, Frontend::Forward );
65 if ( todo.isEmpty() )
66 continue;
67
68 /* show category */
69 /* -1 == unfiled */
70 catPassed = false;
71 for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
72 cat = categories[cat_nu];
73 if ( bCat && cat == -1 ) {
74 if(!todo.categories().isEmpty() )
75 continue;
76 } else if ( bCat && cat != 0)
77 if (!todo.categories().contains( cat ) )
78 continue;
79 catPassed = true;
80 break;
81 }
82
83 /*
84 * If none of the Categories matched
85 * continue
86 */
87 if ( !catPassed )
88 continue;
89 if ( !todo.isOverdue() && bOnly )
90 continue;
91 if (todo.isCompleted() && comp )
92 continue;
93
94 vector.insert(item++, todo );
95 }
96
97 vector.resize( item );
98 /* sort it now */
99 vector.sort();
100 /* now get the uids */
101 UIDArray array( vector.count() );
102 for (uint i= 0; i < vector.count(); i++ )
103 array[i] = vector.uidAt( i );
104
105 return array;
106}
107
108OPimBackendOccurrence::List OPimTodoAccessBackend::occurrences( const QDate& start,
109 const QDate& end )const {
110 OPimBackendOccurrence::List lst;
111 UIDArray effective = effectiveToDos( start, end, false );
112 UIDArray overdue = overDue();
113 uint count = effective.count();
114 int uid;
115 QIntDict<int> hash;
116 hash.setAutoDelete( true );
117 OPimTodo todo;
118
119 for ( uint i = 0; i < count; ++i ) {
120 uid = effective[i];
121 todo = find( uid, effective, i, Frontend::Forward );
122 /*
123 * If isOverdue but in the 'normal' range we will fill
124 * the hash so we won't have duplicates in OPimBackendOccurrence
125 */
126 if ( todo.isOverdue() )
127 hash.insert( uid, new int(6) );
128 OPimBackendOccurrence oc = todo.hasStartDate() ?
129 OPimBackendOccurrence( todo.startDate(),
130 todo.dueDate(), uid ) :
131 OPimBackendOccurrence( todo.dueDate(), uid, QString::null );
132 oc.setSummary( todo.summary() );
133 lst.append( oc );
134 }
135
136 /*
137 * Create the OverDue items but skip
138 * the already handled Records
139 */
140 if ( !overdue.isEmpty() ) {
141 QDate today = QDate::currentDate();
142 QDate dueDate = (start >= today && today <= end ) ? today : start;
143 count = overdue.count();
144 for ( uint i = 0; i < count; ++i ) {
145 uid = overdue[i];
146 if (!hash.find( uid ) )
147 continue;
148 todo = find( uid, overdue, i, Frontend::Forward );
149 lst.append( OPimBackendOccurrence(dueDate, uid, todo.summary() ) );
150 }
151 }
152
153 return lst;
154}
41} 155}
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h
index 9dfda45..66297bb 100644
--- a/libopie2/opiepim/backend/otodoaccessbackend.h
+++ b/libopie2/opiepim/backend/otodoaccessbackend.h
@@ -41,11 +41,19 @@ public:
41 ~OPimTodoAccessBackend(); 41 ~OPimTodoAccessBackend();
42 virtual QArray<int> effectiveToDos( const QDate& start, 42 virtual UIDArray effectiveToDos( const QDate& start,
43 const QDate& end, 43 const QDate& end,
44 bool includeNoDates ) = 0; 44 bool includeNoDates )const = 0;
45 virtual QArray<int> overDue() = 0; 45 virtual UIDArray overDue()const = 0;
46 virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, 46 virtual void removeAllCompleted() = 0;
47 int cat ) = 0; 47
48 virtual void removeAllCompleted() = 0; 48 /**
49 virtual QBitArray supports()const = 0; 49 * Common and probably inefficent implementation
50 50 * for queryByExample, matchRegexp, sorted
51 * and occurrences
52 */
53 //@{
54 UIDArray queryByExample( const OPimTodo&, int settings, const QDateTime& d = QDateTime() )const;
55 UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
56 OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const;
57 //@}
58
51private: 59private:
@@ -55,5 +63,17 @@ private:
55}; 63};
56
57} 64}
58 65
66
67/**
68 * \fn Opie::OPimBackendOccurrence::List Opie::OPimTodoAccessBackend::occurrences(const QDate& start,const QDate& end)const
69 * \brief Return occurrences for a period of time
70 *
71 * This method will return the 'effective' Todos and also
72 * 'Overdue' Todos. Overdues will be shown on the 'current'
73 * day if it is in the range or on \par start. If the overdue
74 * is inside the 'Effective Todos' we will skip the
75 * special overdue handling.
76 *
77 *
78 */
59#endif 79#endif
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 4e3e47b..2bcab29 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -457,3 +457,2 @@ OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
457 return parseResultAndCache( uid, m_driver->query(&query) ); 457 return parseResultAndCache( uid, m_driver->query(&query) );
458
459} 458}
@@ -467,3 +466,2 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
467 uint size =0; 466 uint size =0;
468 OPimTodo to;
469 467
@@ -471,6 +469,5 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
471 switch( dir ) { 469 switch( dir ) {
472 /* forward */ 470 /* forward */
473 case Frontend::Forward: 471 case Frontend::Forward:
474 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 472 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
475 odebug << "size " << size << " " << ints[i] << "" << oendl;
476 search[size] = ints[i]; 473 search[size] = ints[i];
@@ -479,4 +476,4 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
479 break; 476 break;
480 /* reverse */ 477 /* reverse */
481 case Frontend::Reverse: 478 case Frontend::Reverse:
482 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 479 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
@@ -492,3 +489,3 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
492 if ( res.state() != OSQLResult::Success ) 489 if ( res.state() != OSQLResult::Success )
493 return to; 490 return OPimTodo();
494 491
@@ -509,2 +506,3 @@ bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
509 return false; 506 return false;
507
510 int c = m_uids.count(); 508 int c = m_uids.count();
@@ -536,3 +534,3 @@ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
536} 534}
537QArray<int> OPimTodoAccessBackendSQL::overDue() { 535QArray<int> OPimTodoAccessBackendSQL::overDue()const {
538 OverDueQuery qu; 536 OverDueQuery qu;
@@ -542,3 +540,3 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
542 const QDate& t, 540 const QDate& t,
543 bool u) { 541 bool u)const {
544 EffQuery ef(s, t, u ); 542 EffQuery ef(s, t, u );
@@ -546,2 +544,4 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
546} 544}
545
546#if 0
547/* 547/*
@@ -562,3 +562,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
562 /* Category */ 562 /* Category */
563 if ( sortFilter & 1 ) { 563 if ( sortFilter & OPimTodoAccess::FilterCategory ) {
564 QString str; 564 QString str;
@@ -568,3 +568,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
568 /* Show only overdue */ 568 /* Show only overdue */
569 if ( sortFilter & 2 ) { 569 if ( sortFilter & OPimTodoAccess::OnlyOverDue ) {
570 QDate date = QDate::currentDate(); 570 QDate date = QDate::currentDate();
@@ -579,3 +579,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
579 /* not show completed */ 579 /* not show completed */
580 if ( sortFilter & 4 ) { 580 if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
581 query += " completed = 0 AND"; 581 query += " completed = 0 AND";
@@ -595,12 +595,12 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
595 /* completed */ 595 /* completed */
596 case 0: 596 case OPimTodoAccess::Completed:
597 query += "completed"; 597 query += "completed";
598 break; 598 break;
599 case 1: 599 case OPimTodoAccess::Priority:
600 query += "priority"; 600 query += "priority";
601 break; 601 break;
602 case 2: 602 case OPimTodoAccess::SortSummary:
603 query += "summary"; 603 query += "summary";
604 break; 604 break;
605 case 3: 605 case OPimTodoAccess::Deadline:
606 query += "DueDate"; 606 query += "DueDate";
@@ -609,6 +609,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
609 609
610 if ( !asc ) { 610 if ( !asc )
611 odebug << "not ascending!" << oendl;
612 query += " DESC"; 611 query += " DESC";
613 } 612
614 613
@@ -618,2 +617,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
618} 617}
618#endif
619
620
619bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 621bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
@@ -631,2 +633,4 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
631} 633}
634
635
632OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ 636OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
@@ -641,10 +645,6 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul
641 OSQLResultItem::ValueList::Iterator it = list.begin(); 645 OSQLResultItem::ValueList::Iterator it = list.begin();
642 odebug << "todo1" << oendl; 646 OPimTodo to, tmp;
643 OPimTodo to = todo( (*it) );
644 cache( to );
645 ++it;
646 647
647 for ( ; it != list.end(); ++it ) { 648 for ( ; it != list.end(); ++it ) {
648 odebug << "caching" << oendl; 649 OPimTodo newTodo = parse( (*it) );
649 OPimTodo newTodo = todo( (*it) );
650 cache( newTodo ); 650 cache( newTodo );
@@ -655,4 +655,3 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul
655} 655}
656OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 656OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const {
657 odebug << "todo(ResultItem)" << oendl;
658 657
@@ -664,4 +663,2 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
664 663
665 odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
666
667 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 664 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
@@ -719,32 +716,4 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
719} 716}
720/*
721 * update the dict
722 */
723void OPimTodoAccessBackendSQL::fillDict() {
724 717
725#if 0
726 /* initialize dict */
727 /*
728 * UPDATE dict if you change anything!!!
729 * FIXME: Isn't this dict obsolete ? (eilers)
730 */
731 m_dict.setAutoDelete( TRUE );
732 m_dict.insert("Categories" , new int(OPimTodo::Category) );
733 m_dict.insert("Uid" , new int(OPimTodo::Uid) );
734 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) );
735 m_dict.insert("Completed" , new int(OPimTodo::Completed) );
736 m_dict.insert("Description" , new int(OPimTodo::Description) );
737 m_dict.insert("Summary" , new int(OPimTodo::Summary) );
738 m_dict.insert("Priority" , new int(OPimTodo::Priority) );
739 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) );
740 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
741 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) );
742 m_dict.insert("Progress" , new int(OPimTodo::Progress) );
743 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers)
744 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
745// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
746// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
747 718
748#endif
749}
750/* 719/*
@@ -767,3 +736,2 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
767 QArray<int> ints(list.count() ); 736 QArray<int> ints(list.count() );
768 odebug << " count = " << list.count() << "" << oendl;
769 737
@@ -779,11 +747,5 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
779{ 747{
780
781#if 0
782 QArray<int> empty;
783 return empty;
784
785#else
786 QString qu = "SELECT uid FROM todolist WHERE ("; 748 QString qu = "SELECT uid FROM todolist WHERE (";
787 749
788 // Do it make sense to search other fields, too ? 750 // Does it make sense to search other fields, too ?
789 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; 751 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
@@ -793,4 +755,2 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
793 755
794 odebug << "query: " << qu << "" << oendl;
795
796 OSQLRawQuery raw( qu ); 756 OSQLRawQuery raw( qu );
@@ -799,23 +759,2 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
799 return uids( res ); 759 return uids( res );
800
801
802#endif
803
804}
805QBitArray OPimTodoAccessBackendSQL::supports()const {
806
807 return sup();
808}
809
810QBitArray OPimTodoAccessBackendSQL::sup() const{
811
812 QBitArray ar( OPimTodo::CompletedDate + 1 );
813 ar.fill( true );
814 ar[OPimTodo::CrossReference] = false;
815 ar[OPimTodo::State ] = false;
816 ar[OPimTodo::Reminders] = false;
817 ar[OPimTodo::Notifiers] = false;
818 ar[OPimTodo::Maintainer] = false;
819
820 return ar;
821} 760}
@@ -833,4 +772,2 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
833 772
834 odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
835
836 if ( completed_uids.size() == 0 ) 773 if ( completed_uids.size() == 0 )
@@ -841,3 +778,3 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
841 778
842 for ( int i = 0; i < completed_uids.size(); i++ ){ 779 for ( uint i = 0; i < completed_uids.size(); i++ ){
843 if ( !query.isEmpty() ) 780 if ( !query.isEmpty() )
@@ -852,3 +789,3 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
852 789
853 for ( int i = 0; i < completed_uids.size(); i++ ){ 790 for ( uint i = 0; i < completed_uids.size(); i++ ){
854 if ( !query.isEmpty() ) 791 if ( !query.isEmpty() )
@@ -859,9 +796,8 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
859 796
860 odebug << "query: " << qu << "" << oendl;
861
862 OSQLRawQuery raw2( qu ); 797 OSQLRawQuery raw2( qu );
863 res = m_driver->query( &raw2 ); 798 res = m_driver->query( &raw2 );
864 if ( res.state() == OSQLResult::Failure ) { 799
800 if ( res.state() == OSQLResult::Failure )
865 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; 801 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl;
866 } 802
867} 803}
@@ -878,4 +814,3 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
878 owarn << "OSQLResult::Failure in find query !!" << oendl; 814 owarn << "OSQLResult::Failure in find query !!" << oendl;
879 QMap<QString, QString> empty; 815 return QMap<QString, QString>();
880 return empty;
881 } 816 }
@@ -884,5 +819,5 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
884 OSQLResultItem::ValueList::Iterator it = list.begin(); 819 OSQLResultItem::ValueList::Iterator it = list.begin();
885 for ( ; it != list.end(); ++it ) { 820 for ( ; it != list.end(); ++it )
886 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 821 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
887 } 822
888 823
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 415f791..0ba8f3a 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -53,21 +53,18 @@ public:
53 bool save(); 53 bool save();
54 QArray<int> allRecords()const; 54 QArray<UID> allRecords()const;
55 55
56 QArray<int> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() ); 56 QArray<UID> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() );
57 OPimTodo find(int uid)const; 57 OPimTodo find(UID uid)const;
58 OPimTodo find(int 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( int uid ); 61 bool remove( UID uid );
62 bool replace( const OPimTodo& t ); 62 bool replace( const OPimTodo& t );
63 63
64 QArray<int> overDue(); 64 QArray<UID> overDue()const;
65 QArray<int> effectiveToDos( const QDate& start, 65 QArray<UID> effectiveToDos( const QDate& start,
66 const QDate& end, bool includeNoDates ); 66 const QDate& end, bool includeNoDates )const;
67 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); 67 QArray<UID> matchRegexp( const QRegExp &r ) const;
68
69 QBitArray supports()const;
70 QArray<int> matchRegexp( const QRegExp &r ) const;
71 void removeAllCompleted(); 68 void removeAllCompleted();
72 69
73 70
@@ -75,10 +72,8 @@ private:
75 void update()const; 72 void update()const;
76 void fillDict();
77 inline bool date( QDate& date, const QString& )const; 73 inline bool date( QDate& date, const QString& )const;
78 inline OPimTodo parseResultAndCache( int uid, const Opie::DB::OSQLResult& )const; 74 inline OPimTodo parseResultAndCache( UID uid, const Opie::DB::OSQLResult& )const;
79 inline OPimTodo todo( Opie::DB::OSQLResultItem& )const; 75 inline OPimTodo parse( Opie::DB::OSQLResultItem& )const;
80 inline QArray<int> uids( const Opie::DB::OSQLResult& )const; 76 inline QArray<UID> uids( const Opie::DB::OSQLResult& )const;
81 OPimTodo todo( int uid )const; 77 OPimTodo todo( UID uid )const;
82 QBitArray sup() const; 78 QMap<QString, QString> requestCustom( UID uid ) const;
83 QMap<QString, QString> requestCustom( int uid ) const;
84 79
@@ -86,3 +81,3 @@ private:
86 Opie::DB::OSQLDriver* m_driver; 81 Opie::DB::OSQLDriver* m_driver;
87 QArray<int> m_uids; 82 QArray<UID> m_uids;
88 bool m_dirty : 1; 83 bool m_dirty : 1;
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp
index 7d58a40..aa8a7eb 100644
--- a/libopie2/opiepim/backend/otodoaccessvcal.cpp
+++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp
@@ -94,3 +94,2 @@ namespace {
94 name = vObjectStringZValue( ob ); 94 name = vObjectStringZValue( ob );
95 owarn << "Categories:" << name.data() << "" << oendl;
96 } 95 }
@@ -235,6 +234,3 @@ OPimTodo OPimTodoAccessVCal::find(int uid )const {
235} 234}
236QArray<int> OPimTodoAccessVCal::sorted( bool, int, int, int ) { 235
237 QArray<int> ar(0);
238 return ar;
239}
240QArray<int> OPimTodoAccessVCal::allRecords()const { 236QArray<int> OPimTodoAccessVCal::allRecords()const {
@@ -249,17 +245,6 @@ QArray<int> OPimTodoAccessVCal::allRecords()const {
249} 245}
250QArray<int> OPimTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { 246
251 QArray<int> ar(0);
252 return ar;
253}
254QArray<int> OPimTodoAccessVCal::queryByExample( const OPimTodo&, int, const QDateTime& ) {
255 QArray<int> ar(0);
256 return ar;
257}
258QArray<int> OPimTodoAccessVCal::effectiveToDos( const QDate& , 247QArray<int> OPimTodoAccessVCal::effectiveToDos( const QDate& ,
259 const QDate& , 248 const QDate& ,
260 bool ) { 249 bool )const {
261 QArray<int> ar(0);
262 return ar;
263}
264QArray<int> OPimTodoAccessVCal::overDue() {
265 QArray<int> ar(0); 250 QArray<int> ar(0);
@@ -267,20 +252,5 @@ QArray<int> OPimTodoAccessVCal::overDue() {
267} 252}
268QBitArray OPimTodoAccessVCal::supports()const {
269 static QBitArray ar = sup();
270
271 return ar;
272}
273QBitArray OPimTodoAccessVCal::sup() {
274 QBitArray ar ( OPimTodo::CompletedDate +1 );
275 ar.fill( true );
276
277 ar[OPimTodo::CrossReference] = false;
278 ar[OPimTodo::State ] = false;
279 ar[OPimTodo::Reminders] = false;
280 ar[OPimTodo::Notifiers] = false;
281 ar[OPimTodo::Maintainer] = false;
282 ar[OPimTodo::Progress] = false;
283 ar[OPimTodo::Alarms ] = false;
284 ar[OPimTodo::Recurrence] = false;
285 253
254QArray<int> OPimTodoAccessVCal::overDue()const {
255 QArray<int> ar(0);
286 return ar; 256 return ar;
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.h b/libopie2/opiepim/backend/otodoaccessvcal.h
index 1e106d3..05dd76b 100644
--- a/libopie2/opiepim/backend/otodoaccessvcal.h
+++ b/libopie2/opiepim/backend/otodoaccessvcal.h
@@ -45,10 +45,6 @@ public:
45 QArray<int> allRecords()const; 45 QArray<int> allRecords()const;
46 QArray<int> matchRegexp(const QRegExp &r) const;
47 QArray<int> queryByExample( const OPimTodo& t, int sort, const QDateTime& d = QDateTime() );
48 QArray<int> effectiveToDos( const QDate& start, 46 QArray<int> effectiveToDos( const QDate& start,
49 const QDate& end, 47 const QDate& end,
50 bool includeNoDates ); 48 bool includeNoDates )const;
51 QArray<int> overDue(); 49 QArray<int> overDue()const;
52 QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
53 int cat );
54 OPimTodo find(int uid)const; 50 OPimTodo find(int uid)const;
@@ -60,6 +56,4 @@ public:
60 void removeAllCompleted(); 56 void removeAllCompleted();
61 virtual QBitArray supports()const;
62 57
63private: 58private:
64 static QBitArray sup();
65 bool m_dirty : 1; 59 bool m_dirty : 1;
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 3e06d88..273f91a 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -36,4 +36,7 @@
36#include <opie2/otodoaccessxml.h> 36#include <opie2/otodoaccessxml.h>
37#include <opie2/otodoaccess.h>
37#include <opie2/odebug.h> 38#include <opie2/odebug.h>
38 39
40#include <opie2/private/opimtodosortvector.h>
41
39#include <qpe/global.h> 42#include <qpe/global.h>
@@ -144,3 +147,2 @@ bool OPimTodoAccessXML::load() {
144 dict.insert("Reminders", new int(OPimTodo::Reminders) ); 147 dict.insert("Reminders", new int(OPimTodo::Reminders) );
145 dict.insert("Notifiers", new int(OPimTodo::Notifiers) );
146 dict.insert("Maintainer", new int(OPimTodo::Maintainer) ); 148 dict.insert("Maintainer", new int(OPimTodo::Maintainer) );
@@ -184,3 +186,2 @@ bool OPimTodoAccessXML::load() {
184 i+= strLen; 186 i+= strLen;
185 owarn << "Found a start at " << i << " " << (point-dt) << "" << oendl;
186 187
@@ -240,3 +241,2 @@ bool OPimTodoAccessXML::load() {
240 */ 241 */
241 owarn << "End at " << i << "" << oendl;
242 if (m_events.contains( ev.uid() ) || ev.uid() == 0) { 242 if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
@@ -263,3 +263,2 @@ bool OPimTodoAccessXML::load() {
263 263
264 owarn << "counts " << m_events.count() << " records loaded!" << oendl;
265 return true; 264 return true;
@@ -271,5 +270,3 @@ bool OPimTodoAccessXML::reload() {
271bool OPimTodoAccessXML::save() { 270bool OPimTodoAccessXML::save() {
272// owarn << "saving" << oendl;
273 if (!m_opened || !m_changed ) { 271 if (!m_opened || !m_changed ) {
274// owarn << "not saving" << oendl;
275 return true; 272 return true;
@@ -314,3 +311,2 @@ bool OPimTodoAccessXML::save() {
314 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 311 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
315// owarn << "error renaming" << oendl;
316 QFile::remove( strNewFile ); 312 QFile::remove( strNewFile );
@@ -326,6 +322,6 @@ QArray<int> OPimTodoAccessXML::allRecords()const {
326 322
327 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 323 for ( it = m_events.begin(); it != m_events.end(); ++it )
328 ids[i] = it.key(); 324 ids[i++] = it.key();
329 i++; 325
330 } 326
331 return ids; 327 return ids;
@@ -352,3 +348,2 @@ void OPimTodoAccessXML::clear() {
352bool OPimTodoAccessXML::add( const OPimTodo& todo ) { 348bool OPimTodoAccessXML::add( const OPimTodo& todo ) {
353// owarn << "add" << oendl;
354 m_changed = true; 349 m_changed = true;
@@ -372,5 +367,5 @@ QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
372 const QDate& end, 367 const QDate& end,
373 bool includeNoDates ) { 368 bool includeNoDates )const {
374 QArray<int> ids( m_events.count() ); 369 QArray<int> ids( m_events.count() );
375 QMap<int, OPimTodo>::Iterator it; 370 QMap<int, OPimTodo>::ConstIterator it;
376 371
@@ -378,11 +373,7 @@ QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
378 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 373 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
379 if ( !it.data().hasDueDate() ) { 374 if ( !it.data().hasDueDate() && includeNoDates) {
380 if ( includeNoDates ) { 375 ids[i++] = it.key();
381 ids[i] = it.key();
382 i++;
383 }
384 }else if ( it.data().dueDate() >= start && 376 }else if ( it.data().dueDate() >= start &&
385 it.data().dueDate() <= end ) { 377 it.data().dueDate() <= end ) {
386 ids[i] = it.key(); 378 ids[i++] = it.key();
387 i++;
388 } 379 }
@@ -392,3 +383,3 @@ QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
392} 383}
393QArray<int> OPimTodoAccessXML::overDue() { 384QArray<int> OPimTodoAccessXML::overDue()const {
394 QArray<int> ids( m_events.count() ); 385 QArray<int> ids( m_events.count() );
@@ -396,3 +387,3 @@ QArray<int> OPimTodoAccessXML::overDue() {
396 387
397 QMap<int, OPimTodo>::Iterator it; 388 QMap<int, OPimTodo>::ConstIterator it;
398 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 389 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
@@ -411,3 +402,2 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
411 const QCString& attr, const QString& val) { 402 const QCString& attr, const QString& val) {
412// owarn << "parse to do from XMLElement" << oendl;
413 403
@@ -417,3 +407,2 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
417 if (!find ) { 407 if (!find ) {
418// owarn << "Unknown option" + it.key() << oendl;
419 ev.setCustomField( attr, val ); 408 ev.setCustomField( attr, val );
@@ -470,4 +459,2 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
470 QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty 459 QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty
471 owarn << "alarm: " << alarm.join("___") << "" << oendl;
472 owarn << "alarm[0]: " << alarm[0] << " " << OPimDateConversion::dateTimeFromString( alarm[0] ).toString() << "" << oendl;
473 OPimAlarm al( alarm[2].toInt(), OPimDateConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); 460 OPimAlarm al( alarm[2].toInt(), OPimDateConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() );
@@ -544,3 +531,2 @@ QString customToXml(const QMap<QString, QString>& customMap )
544{ 531{
545 //owarn << QString("writing custom %1").arg(customMap.count()) << oendl;
546 QString buf(" "); 532 QString buf(" ");
@@ -548,3 +534,2 @@ QString customToXml(const QMap<QString, QString>& customMap )
548 cit != customMap.end(); ++cit) { 534 cit != customMap.end(); ++cit) {
549// owarn << ".ITEM." << oendl;
550 buf += cit.key(); 535 buf += cit.key();
@@ -577,3 +562,2 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
577 } 562 }
578// owarn << "Uid " << ev.uid() << "" << oendl;
579 str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; 563 str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
@@ -624,3 +608,2 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
624 // now write the list 608 // now write the list
625 owarn << "als: " << als.join("____________") << "" << oendl;
626 str += "Alarms=\""+als.join(";") +"\" "; 609 str += "Alarms=\""+als.join(";") +"\" ";
@@ -650,215 +633,51 @@ QString OPimTodoAccessXML::toString( const QArray<int>& ints ) const {
650 633
651/* internal class for sorting
652 *
653 * Inspired by todoxmlio.cpp from TT
654 */
655 634
656struct OPimTodoXMLContainer { 635QArray<int> OPimTodoAccessXML::sorted( const UIDArray& events, bool asc,
657 OPimTodo todo; 636 int sortOrder,int sortFilter,
658}; 637 const QArray<int>& categories )const {
638 Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder );
639 int item = 0;
659 640
660namespace { 641 bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false;
661 inline QString string( const OPimTodo& todo) { 642 bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false;
662 return todo.summary().isEmpty() ? 643 bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false;
663 todo.description().left(20 ) : 644 bool catPassed = false;
664 todo.summary(); 645 int cat;
665 }
666 inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) {
667 int ret = 0;
668 if ( todo1.isCompleted() ) ret++;
669 if ( todo2.isCompleted() ) ret--;
670 return ret;
671 }
672 inline int priority( const OPimTodo& t1, const OPimTodo& t2) {
673 return ( t1.priority() - t2.priority() );
674 }
675 inline int description( const OPimTodo& t1, const OPimTodo& t2) {
676 return QString::compare( string(t1), string(t2) );
677 }
678 inline int deadline( const OPimTodo& t1, const OPimTodo& t2) {
679 int ret = 0;
680 if ( t1.hasDueDate() &&
681 t2.hasDueDate() )
682 ret = t2.dueDate().daysTo( t1.dueDate() );
683 else if ( t1.hasDueDate() )
684 ret = -1;
685 else if ( t2.hasDueDate() )
686 ret = 1;
687 else
688 ret = 0;
689 646
690 return ret; 647 for ( uint i = 0; i < events.count(); ++i ) {
691 } 648 /* Guard against creating a new item... */
649 if ( !m_events.contains( events[i] ) )
650 continue;
692 651
693}; 652 OPimTodo todo = m_events[events[i]];
694 653
695/* 654 /* show category */
696 * Returns: 655 /* -1 == unfiled */
697 * 0 if item1 == item2 656 catPassed = false;
698 * 657 for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
699 * non-zero if item1 != item2 658 cat = categories[cat_nu];
700 * 659 if ( bCat && cat == -1 ) {
701 * This function returns int rather than bool so that reimplementations 660 if(!todo.categories().isEmpty() )
702 * can return one of three values and use it to sort by: 661 continue;
703 * 662 } else if ( bCat && cat != 0)
704 * 0 if item1 == item2 663 if (!todo.categories().contains( cat ) )
705 * 664 continue;
706 * > 0 (positive integer) if item1 > item2 665 catPassed = true;
707 *
708 * < 0 (negative integer) if item1 < item2
709 *
710 */
711class OPimTodoXMLVector : public QVector<OPimTodoXMLContainer> {
712public:
713 OPimTodoXMLVector(int size, bool asc, int sort)
714 : QVector<OPimTodoXMLContainer>( size )
715 {
716 setAutoDelete( true );
717 m_asc = asc;
718 m_sort = sort;
719 }
720 /* return the summary/description */
721 QString string( const OPimTodo& todo) {
722 return todo.summary().isEmpty() ?
723 todo.description().left(20 ) :
724 todo.summary();
725 }
726 /**
727 * we take the sortorder( switch on it )
728 *
729 */
730 int compareItems( Item d1, Item d2 ) {
731 bool seComp, sePrio, seDesc, seDeadline;
732 seComp = sePrio = seDeadline = seDesc = false;
733 int ret =0;
734 OPimTodoXMLContainer* con1 = (OPimTodoXMLContainer*)d1;
735 OPimTodoXMLContainer* con2 = (OPimTodoXMLContainer*)d2;
736
737 /* same item */
738 if ( con1->todo.uid() == con2->todo.uid() )
739 return 0;
740
741 switch ( m_sort ) {
742 /* completed */
743 case 0: {
744 ret = completed( con1->todo, con2->todo );
745 seComp = TRUE;
746 break;
747 }
748 /* priority */
749 case 1: {
750 ret = priority( con1->todo, con2->todo );
751 sePrio = TRUE;
752 break;
753 }
754 /* description */
755 case 2: {
756 ret = description( con1->todo, con2->todo );
757 seDesc = TRUE;
758 break;
759 }
760 /* deadline */
761 case 3: {
762 ret = deadline( con1->todo, con2->todo );
763 seDeadline = TRUE;
764 break; 666 break;
765 } 667 }
766 default:
767 ret = 0;
768 break;
769 };
770 /*
771 * FIXME do better sorting if the first sort criteria
772 * ret equals 0 start with complete and so on...
773 */
774
775 /* twist it we're not ascending*/
776 if (!m_asc)
777 ret = ret * -1;
778 668
779 if ( ret )
780 return ret;
781
782 // default did not gave difference let's try it other way around
783 /* 669 /*
784 * General try if already checked if not test 670 * If none of the Categories matched
785 * and return 671 * continue
786 * 1.Completed
787 * 2.Priority
788 * 3.Description
789 * 4.DueDate
790 */ 672 */
791 if (!seComp ) { 673 if ( !catPassed )
792 if ( (ret = completed( con1->todo, con2->todo ) ) ) {
793 if (!m_asc ) ret *= -1;
794 return ret;
795 }
796 }
797 if (!sePrio ) {
798 if ( (ret = priority( con1->todo, con2->todo ) ) ) {
799 if (!m_asc ) ret *= -1;
800 return ret;
801 }
802 }
803 if (!seDesc ) {
804 if ( (ret = description(con1->todo, con2->todo ) ) ) {
805 if (!m_asc) ret *= -1;
806 return ret;
807 }
808 }
809 if (!seDeadline) {
810 if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
811 if (!m_asc) ret *= -1;
812 return ret;
813 }
814 }
815
816 return 0;
817 }
818 private:
819 bool m_asc;
820 int m_sort;
821
822};
823
824QArray<int> OPimTodoAccessXML::sorted( bool asc, int sortOrder,
825 int sortFilter, int cat ) {
826 OPimTodoXMLVector vector(m_events.count(), asc,sortOrder );
827 QMap<int, OPimTodo>::Iterator it;
828 int item = 0;
829
830 bool bCat = sortFilter & 1 ? true : false;
831 bool bOnly = sortFilter & 2 ? true : false;
832 bool comp = sortFilter & 4 ? true : false;
833 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
834
835 /* show category */
836 /* -1 == unfiled */
837 if ( bCat && cat == -1 ) {
838 if(!(*it).categories().isEmpty() )
839 continue;
840 }else if ( bCat && cat != 0)
841 if (!(*it).categories().contains( cat ) ) {
842 continue;
843 }
844 /* isOverdue but we should not show overdue - why?*/
845/* if ( (*it).isOverdue() && !bOnly ) {
846 owarn << "item is overdue but !bOnly" << oendl;
847 continue; 674 continue;
848 } 675 if ( !todo.isOverdue() && bOnly )
849*/
850 if ( !(*it).isOverdue() && bOnly ) {
851 continue; 676 continue;
852 } 677 if (todo.isCompleted() && comp )
853
854 if ((*it).isCompleted() && comp ) {
855 continue; 678 continue;
856 }
857 679
858 680 vector.insert(item++, todo );
859 OPimTodoXMLContainer* con = new OPimTodoXMLContainer();
860 con->todo = (*it);
861 vector.insert(item, con );
862 item++;
863 } 681 }
682
864 vector.resize( item ); 683 vector.resize( item );
@@ -867,8 +686,9 @@ QArray<int> OPimTodoAccessXML::sorted( bool asc, int sortOrder,
867 /* now get the uids */ 686 /* now get the uids */
868 QArray<int> array( vector.count() ); 687 UIDArray array( vector.count() );
869 for (uint i= 0; i < vector.count(); i++ ) { 688 for (uint i= 0; i < vector.count(); i++ )
870 array[i] = ( vector.at(i) )->todo.uid(); 689 array[i] = vector.uidAt( i );
871 } 690
872 return array; 691 return array;
873}; 692}
693
874void OPimTodoAccessXML::removeAllCompleted() { 694void OPimTodoAccessXML::removeAllCompleted() {
@@ -881,26 +701,12 @@ void OPimTodoAccessXML::removeAllCompleted() {
881} 701}
882QBitArray OPimTodoAccessXML::supports()const { 702
883 static QBitArray ar = sup();
884 return ar;
885}
886QBitArray OPimTodoAccessXML::sup() {
887 QBitArray ar( OPimTodo::CompletedDate +1 );
888 ar.fill( true );
889 ar[OPimTodo::CrossReference] = false;
890 ar[OPimTodo::State ] = false;
891 ar[OPimTodo::Reminders] = false;
892 ar[OPimTodo::Notifiers] = false;
893 ar[OPimTodo::Maintainer] = false;
894
895 return ar;
896}
897QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const 703QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const
898{ 704{
899 QArray<int> m_currentQuery( m_events.count() ); 705 QArray<int> currentQuery( m_events.count() );
900 uint arraycounter = 0; 706 uint arraycounter = 0;
901 707
902 QMap<int, OPimTodo>::ConstIterator it; 708 QMap<int, OPimTodo>::ConstIterator it;
903 for (it = m_events.begin(); it != m_events.end(); ++it ) { 709 for (it = m_events.begin(); it != m_events.end(); ++it ) {
904 if ( it.data().match( r ) ) 710 if ( it.data().match( r ) )
905 m_currentQuery[arraycounter++] = it.data().uid(); 711 currentQuery[arraycounter++] = it.data().uid();
906 712
@@ -908,5 +714,5 @@ QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const
908 // Shrink to fit.. 714 // Shrink to fit..
909 m_currentQuery.resize(arraycounter); 715 currentQuery.resize(arraycounter);
910 716
911 return m_currentQuery; 717 return currentQuery;
912} 718}
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h
index 3a51543..134a21a 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.h
+++ b/libopie2/opiepim/backend/otodoaccessxml.h
@@ -65,9 +65,9 @@ public:
65 const QDate& end, 65 const QDate& end,
66 bool includeNoDates ); 66 bool includeNoDates )const;
67 QArray<int> overDue(); 67 QArray<int> overDue()const;
68 QArray<int> sorted( bool asc, int sortOrder, 68
69 int sortFilter, int cat ); 69//@{
70 QBitArray supports()const; 70 UIDArray sorted( const UIDArray&, bool, int, int, const QArray<int>& )const;
71//@}
71private: 72private:
72 static QBitArray sup();
73 void todo( QAsciiDict<int>*, OPimTodo&,const QCString&,const QString& ); 73 void todo( QAsciiDict<int>*, OPimTodo&,const QCString&,const QString& );
@@ -83,3 +83,2 @@ private:
83 int m_year, m_month, m_day; 83 int m_year, m_month, m_day;
84
85}; 84};