summaryrefslogtreecommitdiff
authorzecke <zecke>2004-11-18 21:49:23 (UTC)
committer zecke <zecke>2004-11-18 21:49:23 (UTC)
commit1e7f8f22fc10e3ed85b6563332ddc348c95792d0 (patch) (side-by-side diff)
tree59498ba1d4a7dbff05228c09bebcf0c849e916be
parent41fa1c196965f17f9748f835d90c307b7e594883 (diff)
downloadopie-1e7f8f22fc10e3ed85b6563332ddc348c95792d0.zip
opie-1e7f8f22fc10e3ed85b6563332ddc348c95792d0.tar.gz
opie-1e7f8f22fc10e3ed85b6563332ddc348c95792d0.tar.bz2
Backend Changes:
Each Backend can: -Sort and Filter a set of Records/AllRecords (which can be filtered again) -QueryByExample by every Backend -Occurrences for a period of time and a QDateTime -More common implementation -OPimBackendOccurrence with common splitting to OPimOccurrence
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 @@
SOURCES += \
+ backend/ocontactaccessbackend.cpp \
backend/ocontactaccessbackend_vcard.cpp \
@@ -5,2 +6,3 @@ SOURCES += \
backend/odatebookaccessbackend_xml.cpp \
+ backend/opimbackendoccurrence.cpp \
backend/otodoaccessbackend.cpp \
@@ -16,3 +18,4 @@ HEADERS += \
backend/odatebookaccessbackend_xml.h \
- backend/opimaccessbackend.h \
+ backend/opimaccessbackend.h \
+ backend/opimbackendoccurrence.h \
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;
namespace Opie {
-
+
class OBackendPrivate;
-
+
/**
@@ -86,4 +86,4 @@ class OBackendPrivate;
public:
- OBackendFactory() {};
-
+ OBackendFactory() {};
+
/**
@@ -98,4 +98,6 @@ class OBackendPrivate;
const QString& appName, const QString& filename = QString::null ){
- owarn << "Selected backend for " << type << " is: " << database << oendl;
- // If we should use the dafult database style, we have to request it
+ owarn << "Selected backend for " << type << " is: " <<
+database << oendl;
+
+ // If we should use the dafult database style, we have to request it
OPimGlobal::DatabaseStyle use_database = database;
@@ -104,6 +106,6 @@ class OBackendPrivate;
}
-
+
switch ( type ){
case OPimGlobal::TODOLIST:
-
+
switch ( use_database ){
@@ -168,5 +170,5 @@ class OBackendPrivate;
}
-
+
}
-
+
/**
@@ -191,3 +193,3 @@ class OBackendPrivate;
}
-
+
Config config( "pimaccess" );
@@ -195,6 +197,6 @@ class OBackendPrivate;
QString db_String = config.readEntry( "usebackend", "xml" );
-
+
QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
dictDbTypes.setAutoDelete( TRUE );
-
+
dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
@@ -202,12 +204,12 @@ class OBackendPrivate;
dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
-
+
int* db_find = dictDbTypes[ db_String ];
-
+
if ( !db_find )
return OPimGlobal::UNKNOWN;
-
+
return (OPimGlobal::DatabaseStyle) *db_find;
}
-
-
+
+
/**
@@ -224,5 +226,5 @@ class OBackendPrivate;
OBackendPrivate* d;
-
+
};
-
+
}
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 @@
+/*
+ This file is part of the Opie Project
+ Copyright (C) 2004 Holger Freyther <freyther@handhelds.org>
+ =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
+ .=l.
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "ocontactaccessbackend.h"
+#include <opie2/private/opimcontactsortvector.h>
+#include <opie2/ocontactaccess.h>
+
+#include <opie2/odebug.h>
+
+namespace Opie {
+OPimContactAccessBackend::OPimContactAccessBackend() {}
+
+UIDArray
+OPimContactAccessBackend::queryByExample( const OPimContact&, int,
+ const QDateTime& )const {
+ return UIDArray();
+}
+
+UIDArray
+OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder,
+ int filter, const QArray<int>& categories)const {
+ odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl;
+
+ Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder );
+
+ int item = 0;
+ uint cat_count = categories.count();
+ uint eve_count = ar.count();
+ bool bCat = filter & OPimContactAccess::FilterCategory ? true : false;
+ bool catPassed = false;
+ int cat;
+
+ for ( uint i = 0; i < eve_count; ++i ) {
+ OPimContact contact = find( ar[i], ar, i, Frontend::Forward );
+ if ( contact.isEmpty() )
+ continue;
+
+ /* show category */
+ /* -1 == unfiled */
+ catPassed = false;
+ for ( uint cat_nu = 0; cat_nu < cat_count; ++cat_nu ) {
+ cat = categories[cat_nu];
+ if ( bCat && cat == -1 ) {
+ if(!contact.categories().isEmpty() )
+ continue;
+ } else if ( bCat && cat != 0)
+ if (!contact.categories().contains( cat ) )
+ continue;
+ catPassed = true;
+ break;
+ }
+
+ /*
+ * If none of the Categories matched
+ * continue
+ */
+ if ( !catPassed )
+ continue;
+
+ vector.insert(item++, contact );
+ }
+
+ vector.resize( item );
+ /* sort it now */
+ vector.sort();
+ /* now get the uids */
+ UIDArray array( vector.count() );
+ for (uint i= 0; i < vector.count(); i++ )
+ array[i] = vector.uidAt( i );
+
+ return array;
+}
+
+OPimBackendOccurrence::List OPimContactAccessBackend::occurrences( const QDate& start,
+ const QDate& end)const {
+ OPimBackendOccurrence::List lst;
+
+ UIDArray records = allRecords();
+ const uint count = records.count();
+ int uid;
+
+ for ( uint i = 0; i < count; ++i ) {
+ uid = records[i];
+ OPimContact contact = find(uid, records, i, Frontend::Forward );
+
+ QDate date = contact.anniversary();
+ date = QDate( start.year(), date.month(),date.day() );
+
+// if ( date.isValid() && date.) {
+// }
+ }
+
+ return lst;
+}
+}
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> {
public:
- /**
- * @todo make non line in regard to BC guide of KDE
- */
- OPimContactAccessBackend() {}
- /**
- * @todo make non inline in regard to the BC guide of KDE
- */
- virtual ~OPimContactAccessBackend() {}
+ OPimContactAccessBackend();
- /**
- * Return if database was changed externally.
- * This may just make sense on file based databases like a XML-File.
- * It is used to prevent to overwrite the current database content
- * if the file was already changed by something else !
- * If this happens, we have to reload before save our data.
- * If we use real databases, this should be handled by the database
- * management system themselve, therefore this function should always return false in
- * this case. It is not our problem to handle this conflict ...
- * @return <i>true</i> if the database was changed and if save without reload will
- * be dangerous. <i>false</i> if the database was not changed or it is save to write
- * in this situation.
- */
- virtual bool wasChangedExternally() = 0;
+ /**
+ * Return if database was changed externally.
+ * This may just make sense on file based databases like a XML-File.
+ * It is used to prevent to overwrite the current database content
+ * if the file was already changed by something else !
+ * If this happens, we have to reload before save our data.
+ * If we use real databases, this should be handled by the database
+ * management system themselve, therefore this function should always return false in
+ * this case. It is not our problem to handle this conflict ...
+ * @return <i>true</i> if the database was changed and if save without reload will
+ * be dangerous. <i>false</i> if the database was not changed or it is save to write
+ * in this situation.
+ */
+ virtual bool wasChangedExternally() = 0;
- virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0;
+ /**
+ * Return all possible settings.
+ * @return All settings provided by the current backend
+ * (i.e.: query_WildCards & query_IgnoreCase)
+ */
+ virtual const uint querySettings() = 0;
- /**
- * Return all possible settings.
- * @return All settings provided by the current backend
- * (i.e.: query_WildCards & query_IgnoreCase)
- */
- virtual const uint querySettings() = 0;
+ /**
+ * Check whether settings are correct.
+ * @return <i>true</i> if the given settings are correct and possible.
+ */
+ virtual bool hasQuerySettings (uint querySettings) const = 0;
+
+ /**
+ * Slow and inefficent default implementation
+ */
+//@{
+ UIDArray queryByExample( const OPimContact&, int settings, const QDateTime& d = QDateTime() )const;
+ UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
+ OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const;
+//@}
- /**
- * Check whether settings are correct.
- * @return <i>true</i> if the given settings are correct and possible.
- */
- virtual bool hasQuerySettings (uint querySettings) const = 0;
- /**
- * FIXME!!!
- * Returns a sorted list of records either ascendinf or descending for a giving criteria and category
- */
- virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0;
-
-
private:
- class Private;
- Private *d;
+ class Private;
+ Private *d;
};
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
-// Not implemented
-QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& )
-{
- QArray<int> ar(0);
- return ar;
-}
-
-// Not implemented
-QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
-{
- QArray<int> ar(0);
- return ar;
-}
-
const uint OPimContactAccessBackend_VCard::querySettings()
@@ -198,12 +184,3 @@ bool OPimContactAccessBackend_VCard::wasChangedExternally()
-// Not implemented
-QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int )
-{
- QArray<int> ar(0);
- return ar;
-}
-
// *** Private stuff ***
-
-
OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
@@ -322,3 +299,2 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
- owarn << "value %s %d" << value.data() << type << oendl;
if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
@@ -527,3 +503,2 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
if ( c.birthday().isValid() ){
- owarn << "Exporting birthday as: " << convDateToVCardDate( c.birthday() ) << "" << oendl;
safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) );
@@ -546,3 +521,2 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
if ( c.anniversary().isValid() ){
- owarn << "Exporting anniversary as: " << convDateToVCardDate( c.anniversary() ) << "" << oendl;
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 {
QArray<int> allRecords() const;
- QArray<int> queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() );
- QArray<int> matchRegexp( const QRegExp &r ) const;
@@ -66,3 +64,2 @@ class OPimContactAccessBackend_VCard : public OPimContactAccessBackend {
bool hasQuerySettings (uint querySettings) const;
- QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat );
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()
for ( ; it.current(); ++it ) {
- // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl;
out += "<Contact ";
@@ -139,4 +138,2 @@ bool OPimContactAccessBackend_XML::save()
if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
- owarn << "problem renaming file " << strNewFile << " to " << m_journalName
- << ", errno: " << errno << oendl;
// remove the tmp file...
@@ -215,5 +212,4 @@ OPimContact OPimContactAccessBackend_XML::find ( int uid ) const
QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings,
- const QDateTime& d )
+ const QDateTime& d )const
{
-
QArray<int> m_currentQuery( m_contactList.count() );
@@ -280,4 +276,2 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
// ( maximum time range ) !
- owarn << "Checking if " << checkDate->toString() << " is between " << current.toString()
- << " and " << queryDate->toString() << " ! " << oendl;
if ( current.daysTo( *queryDate ) >= 0 ){
@@ -286,3 +280,2 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
allcorrect = false;
- owarn << " Nope!.." << oendl;
}
@@ -432,2 +425,3 @@ bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
+#if 0
// Currently only asc implemented..
@@ -460,2 +454,4 @@ QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
}
+#endif
+
@@ -463,3 +459,2 @@ bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
{
- //owarn << "odefaultbackend: ACTION::ADD" << oendl;
updateJournal (newcontact, ACTION_ADD);
@@ -487,4 +482,2 @@ bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
- owarn << "Nur zur Sicherheit: " << contact.uid() << " == " << newCont->uid() << " ?" << oendl;
-
return true;
@@ -593,4 +586,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
- //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl;
-
XMLElement *root = XMLElement::load( filename );
@@ -601,3 +592,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
XMLElement *element = root->firstChild();
- //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl;
element = element ? element->firstChild() : 0;
@@ -607,4 +597,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
if( element->tagName() != QString::fromLatin1("Contacts") ){
- //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: "
- // << element->tagName() << oendl;
element = element->nextChild();
@@ -618,4 +606,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
if( element->tagName() != QString::fromLatin1("Contact") ){
- //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: "
- // << element->tagName() << oendl;
element = element->nextChild();
@@ -626,4 +612,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
*/
- //owarn << "OPimContactDefBack::load element tagName() : "
- // << element->tagName() << oendl;
QString dummy;
@@ -636,4 +620,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
for( it = aMap.begin(); it != aMap.end(); ++it ){
- // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl;
-
int *find = dict[ it.key() ];
@@ -641,3 +623,2 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
if ( !find ) {
- // owarn << "Attribute " << it.key() << " not known." << oendl;
//contact.setCustomField(it.key(), it.data());
@@ -706,6 +687,4 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
}else {
- owarn << "ODefBack::could not load" << oendl;
}
delete root;
- owarn << "returning from loading" << oendl;
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 {
- QArray<int> queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() );
-
+ QArray<int> queryByExample ( const OPimContact &query, int settings, const QDateTime& d )const;
QArray<int> matchRegexp( const QRegExp &r ) const;
@@ -72,4 +71,2 @@ class OPimContactAccessBackend_XML : public OPimContactAccessBackend {
- // Currently only asc implemented..
- QArray<int> sorted( bool asc, int , int , int );
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 {
/* a small helper to get all NonRepeating events for a range of time */
- void events( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& events,
- const QDate& from, const QDate& to ) {
- QDateTime dtStart, dtEnd;
-
- for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
- dtStart = (*it).startDateTime();
- dtEnd = (*it).endDateTime();
-
- /*
- * If in range
- */
- if (dtStart.date() >= from && dtEnd.date() <= to ) {
- OEffectiveEvent eff;
- eff.setEvent( (*it) );
- eff.setDate( dtStart.date() );
- eff.setStartTime( dtStart.time() );
-
- /* if not on the same day */
- if ( dtStart.date() != dtEnd.date() )
- eff.setEndTime( QTime(23, 59, 0 ) );
- else
- eff.setEndTime( dtEnd.time() );
-
- tmpList.append( eff );
- }
-
- /* we must also check for end date information... */
- if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) {
- QDateTime dt = dtStart.addDays( 1 );
- dt.setTime( QTime(0, 0, 0 ) );
- QDateTime dtStop;
- if ( dtEnd > to )
- dtStop = to;
- else
- dtStop = dtEnd;
-
- while ( dt <= dtStop ) {
- OEffectiveEvent eff;
- eff.setEvent( (*it) );
- eff.setDate( dt.date() );
-
- if ( dt >= from ) {
- eff.setStartTime( QTime(0, 0, 0 ) );
- if ( dt.date() == dtEnd.date() )
- eff.setEndTime( dtEnd.time() );
- else
- eff.setEndTime( QTime(23, 59, 0 ) );
- tmpList.append( eff );
- }
- dt = dt.addDays( 1 );
- }
- }
+void events( OPimBackendOccurrence::List& tmpList,
+ const OPimEvent::ValueList& events,
+ const QDate& from, const QDate& to ) {
+ QDateTime dtStart, dtEnd;
+
+ for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
+ dtStart = (*it).startDateTime();
+ dtEnd = (*it).endDateTime();
+
+ /*
+ * If in range
+ */
+ if (dtStart.date() >= from && dtEnd.date() <= to ) {
+ OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );;
+ tmpList.append( eff );
}
}
+}
- void repeat( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& list,
- const QDate& from, const QDate& to ) {
- QDate repeat;
- for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
- int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
- QDate itDate = from.addDays(-dur );
- OPimRecurrence rec = (*it).recurrence();
- if ( !rec.hasEndDate() || rec.endDate() > to ) {
- rec.setEndDate( to );
- rec.setHasEndDate( true );
- }
- while (rec.nextOcurrence(itDate, repeat ) ) {
- if (repeat > to ) break;
- OEffectiveEvent eff;
- eff.setDate( repeat );
- if ( (*it).isAllDay() ) {
- eff.setStartTime( QTime(0, 0, 0 ) );
- eff.setEndTime( QTime(23, 59, 59 ) );
- }else {
- /* we only occur by days, not hours/minutes/seconds. Hence
- * the actual end and start times will be the same for
- * every repeated event. For multi day events this is
- * fixed up later if on wronge day span
- */
- eff.setStartTime( (*it).startDateTime().time() );
- eff.setEndTime( (*it).endDateTime().time() );
- }
- if ( dur != 0 ) {
- // multi-day repeating events
- QDate sub_it = QMAX( repeat, from );
- QDate startDate = repeat;
- QDate endDate = startDate.addDays( dur );
-
- while ( sub_it <= endDate && sub_it <= to ) {
- OEffectiveEvent tmpEff = eff;
- tmpEff.setEvent( (*it) );
- if ( sub_it != startDate )
- tmpEff.setStartTime( QTime(0, 0, 0 ) );
- if ( sub_it != endDate )
- tmpEff.setEndTime( QTime( 23, 59, 59 ) );
-
- tmpEff.setDate( sub_it );
- tmpEff.setEffectiveDates( startDate, endDate );
- tmpList.append( tmpEff );
-
- sub_it = sub_it.addDays( 1 );
- }
- itDate = endDate;
- }else {
- eff.setEvent( (*it) );
- tmpList.append( eff );
- itDate = repeat.addDays( 1 );
- }
- }
+void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list,
+ const QDate& from, const QDate& to ) {
+ QDate repeat;
+ for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
+ int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
+ QDate itDate = from.addDays(-dur );
+ OPimRecurrence rec = (*it).recurrence();
+ if ( !rec.hasEndDate() || rec.endDate() > to ) {
+ rec.setEndDate( to );
+ rec.setHasEndDate( true );
+ }
+
+ QDateTime start, end;
+ while (rec.nextOcurrence(itDate, repeat ) ) {
+ if (repeat > to ) break;
+
+ OPimEvent event = *it;
+ start = QDateTime( repeat, event.startDateTime().time() );
+ end = QDateTime( repeat.addDays(dur), event.endDateTime().time() );
+ OPimBackendOccurrence eff(start, end, event.uid() );
+ tmpList.append( eff );
}
@@ -150,2 +81,3 @@ namespace {
}
+}
@@ -161,33 +93,20 @@ ODateBookAccessBackend::~ODateBookAccessBackend() {
}
-OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from,
- const QDate& to ) {
- OEffectiveEvent::ValueList tmpList;
- OPimEvent::ValueList list = directNonRepeats();
+OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from,
+ const QDate& to )const {
+ OPimBackendOccurrence::List tmpList;
- events( tmpList, list, from, to );
+ events( tmpList, directNonRepeats(), from, to );
repeat( tmpList, directRawRepeats(),from,to );
- list = directRawRepeats(); // Useless, isn't it ? (eilers)
-
- qHeapSort( tmpList );
return tmpList;
}
-OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) {
- OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() );
- OEffectiveEvent::ValueList::Iterator it;
-
- OEffectiveEvent::ValueList tmpList;
- QDateTime dtTmp;
- for ( it = day.begin(); it != day.end(); ++it ) {
- dtTmp = QDateTime( (*it).date(), (*it).startTime() );
- if ( QABS(dt.secsTo(dtTmp) ) < 60 )
- tmpList.append( (*it) );
- }
+OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const {
+ OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() );
- return tmpList;
+ return filterOccurrences( day, dt );
}
-OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
- const QDate& to ) {
- OEffectiveEvent::ValueList tmpList;
+OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
+ const QDate& to )const {
+ OPimBackendOccurrence::List tmpList;
OPimEvent::ValueList list = directNonRepeats();
@@ -196,3 +115,2 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents(
- qHeapSort( tmpList );
return tmpList;
@@ -200,12 +118,43 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents(
-OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) {
- OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
- OEffectiveEvent::ValueList::Iterator it;
+OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const {
+ OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
+ return filterOccurrences( day,dt );
+}
+
+
+UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings,
+ const QDateTime& d )const {
+ return UIDArray();
+}
+
+UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const {
+ return UIDArray();
+}
- OEffectiveEvent::ValueList tmpList;
- QDateTime dtTmp;
- for ( it = day.begin(); it != day.end(); ++it ) {
- dtTmp = QDateTime( (*it).date(), (*it).startTime() );
- if ( QABS(dt.secsTo(dtTmp) ) < 60 )
- tmpList.append( (*it) );
+OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
+ const QDateTime& dt ) {
+ OPimBackendOccurrence::List tmpList;
+ OPimBackendOccurrence::List::ConstIterator it;
+
+ for ( it = dayList.begin(); it != dayList.end(); ++it ) {
+ OPimBackendOccurrence occ = *it;
+
+ /*
+ * Let us find occurrences that are 'now'!
+ * If the dt.date() is on the same day as start or end of the Occurrence
+ * check how near start/end are.
+ * If it is in the middle of a multiday occurrence list it.
+ *
+ * We might want to 'lose' the sixty second offset and list
+ * all Events which are active at that time.
+ */
+ if ( dt.date() == occ.startDateTime().date() ) {
+ if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 )
+ tmpList.append( occ );
+ }else if ( dt.date() == occ.endDateTime().date() ) {
+ if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 )
+ tmpList.append( occ );
+ }else if ( dt.date() >= occ.startDateTime().date() &&
+ dt.date() >= occ.endDateTime().date() )
+ tmpList.append( occ );
}
@@ -214,3 +163,2 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents(
}
-
}
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> {
public:
- typedef int UID;
-
/**
@@ -54,9 +52,2 @@ public:
* This method should return a list of UIDs containing
- * all events. No filter should be applied
- * @return list of events
- */
- virtual QArray<UID> rawEvents()const = 0;
-
- /**
- * This method should return a list of UIDs containing
* all repeating events. No filter should be applied
@@ -64,3 +55,3 @@ public:
*/
- virtual QArray<UID> rawRepeats()const = 0;
+ virtual UIDArray rawRepeats()const = 0;
@@ -71,3 +62,3 @@ public:
*/
- virtual QArray<UID> nonRepeats() const = 0;
+ virtual UIDArray nonRepeats() const = 0;
@@ -78,3 +69,3 @@ public:
*/
- virtual OPimEvent::ValueList directNonRepeats() = 0;
+ virtual OPimEvent::ValueList directNonRepeats()const = 0;
@@ -83,3 +74,3 @@ public:
*/
- virtual OPimEvent::ValueList directRawRepeats() = 0;
+ virtual OPimEvent::ValueList directRawRepeats()const = 0;
@@ -91,3 +82,3 @@ public:
*/
- virtual OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to );
+ virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const;
@@ -95,19 +86,21 @@ public:
* this is an overloaded member function
- * @see effectiveEvents( const QDate& from, const QDate& to )
- */
- virtual OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start );
-
- /**
- * Effective Events are special event occuring during a time frame. This method does calcualte
- * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
- * yourself
+ * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to )
*/
- virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to );
+ virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start )const;
/**
- * this is an overloaded member function
- * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to )
+ * Common and probably inefficent implementation
+ * for queryByExample, sorted
+ * and occurrences
*/
- virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start );
-
+//@{
+ UIDArray queryByExample( const OPimEvent&, int settings, const QDateTime& d = QDateTime() )const;
+ UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
+ OPimBackendOccurrence::List occurrences( const QDate&, const QDate& end )const;
+ OPimBackendOccurrence::List occurrences( const QDateTime& )const;
+//@}
+
+protected:
+ static OPimBackendOccurrence::List filterOccurrences(const OPimBackendOccurrence::List,
+ const QDateTime& time );
private:
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()
- owarn << "command: " << qu << "" << oendl;
-
OSQLRawQuery raw( qu );
@@ -290,3 +288,2 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
}
- owarn << "add " << qu << "" << oendl;
@@ -330,6 +327,2 @@ bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
-QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
-{
- return allRecords();
-}
@@ -361,3 +354,3 @@ QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
-OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
+OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const
{
@@ -373,3 +366,3 @@ OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
}
-OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
+OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const
{
@@ -412,3 +405,2 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
{
- owarn << "extractUids" << oendl;
QTime t;
@@ -418,3 +410,2 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
QArray<int> ints(list.count() );
- owarn << " count = " << list.count() << "" << oendl;
@@ -425,3 +416,2 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
}
- owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
@@ -442,3 +432,2 @@ QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) cons
if ( res_custom.state() == OSQLResult::Failure ) {
- owarn << "OSQLResult::Failure in find query !!" << oendl;
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:
- QArray<UID> rawEvents()const;
QArray<UID> rawRepeats()const;
@@ -72,4 +71,4 @@ public:
- OPimEvent::ValueList directNonRepeats();
- OPimEvent::ValueList directRawRepeats();
+ OPimEvent::ValueList directNonRepeats()const;
+ OPimEvent::ValueList directRawRepeats()const;
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 {
static void save( const OPimEvent& ev, QString& buf ) {
- owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl;
buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
@@ -328,5 +327,3 @@ bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) {
}
-QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
- return allRecords();
-}
+
QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
@@ -355,3 +352,3 @@ QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
}
-OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
+OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats()const {
OPimEvent::ValueList list;
@@ -363,3 +360,3 @@ OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
}
-OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() {
+OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats()const {
OPimEvent::ValueList list;
@@ -541,3 +538,2 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
- owarn << "already contains assign uid" << oendl;
ev.setUid( 1 );
@@ -552,3 +548,2 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) {
-// owarn << " setting " << value << "" << oendl;
switch( id ) {
@@ -636,3 +631,2 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() );
- owarn << "adding exception " << date.toString() << "" << oendl;
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:
- OPimEvent::ValueList directNonRepeats();
- OPimEvent::ValueList directRawRepeats();
+ OPimEvent::ValueList directNonRepeats()const;
+ OPimEvent::ValueList directRawRepeats()const;
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 @@
#include <opie2/opimrecord.h>
-
+#include <opie2/opimbackendoccurrence.h>
@@ -40,9 +40,12 @@ namespace Opie {
class OPimAccessBackendPrivate;
+
/**
- * OPimAccessBackend is the base class
- * for all private backends
- * it operates on OPimRecord as the base class
- * and it's responsible for fast manipulating
- * the resource the implementation takes care
- * of
+ * OPimAccessBackend is the Backend Interface to be used
+ * by OTemplateBase based Frontends.
+ * For efficency reasons and to support delayed loading
+ * most of the Frontend functions can be implemented
+ * by this backend.
+ * This allows to utilise the best method on each backend.
+ * For example we can use SQL queries instead of self made
+ * query which is first more efficent and also uses less memory.
*/
@@ -53,71 +56,42 @@ public:
- /** The access hint from the frontend */
+ //@{
OPimAccessBackend(int access = 0);
virtual ~OPimAccessBackend();
+ //@}
- /**
- * load the resource
- */
+ //@{
virtual bool load() = 0;
-
- /**
- * reload the resource
- */
virtual bool reload() = 0;
-
- /**
- * save the resource and
- * all it's changes
- */
virtual bool save() = 0;
+ virtual void clear() = 0;
+ //@}
- /**
- * return an array of
- * all available uids
- */
- virtual QArray<int> allRecords()const = 0;
- /**
- * return a List of records
- * that match the regex
- */
- virtual QArray<int> matchRegexp(const QRegExp &r) const = 0;
+ //@{
+ virtual UIDArray allRecords()const = 0;
+ virtual UIDArray matchRegexp(const QRegExp &r) const;
+ virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const = 0;
+ virtual UIDArray queryByExample( const OPimRecord* rec, int, const QDateTime& d = QDateTime() )const;
+ virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const;
+ virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const;
+ virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const;
+ virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const;
+ //@}
- /**
- * queryByExample for T with the given Settings
- *
- */
- virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0;
- /**
- * find the OPimRecord with uid @param uid
- * returns T and T.isEmpty() if nothing was found
- */
- virtual T find( int uid )const = 0;
+ //@{
+ virtual T find(UID uid )const = 0;
+ virtual T find(UID uid, const QArray<UID>& items,
+ uint current, typename Frontend::CacheDirection )const ;
+ //@}
- virtual T find( int uid, const QArray<int>& items,
- uint current, typename Frontend::CacheDirection ) const;
- /**
- * clear the back end
- */
- virtual void clear() = 0;
- /**
- * add T
- */
+ //@{
virtual bool add( const T& t ) = 0;
+ virtual bool remove( UID uid ) = 0;
+ virtual bool replace( const T& t ) = 0;
+ //@}
- /**
- * remove
- */
- virtual bool remove( int uid ) = 0;
- /**
- * replace a record with T.uid()
- */
- virtual bool replace( const T& t ) = 0;
- /*
- * setTheFrontEnd!!!
- */
void setFrontend( Frontend* front );
@@ -129,12 +103,8 @@ public:
protected:
+ //@{
int access()const;
-
void cache( const T& t )const;
-
- /**
- * use a prime number here!
- */
void setSaneCacheSize( int );
-
uint readAhead()const;
+ //@}
@@ -158,2 +128,60 @@ OPimAccessBackend<T>::~OPimAccessBackend() {
}
+
+/*
+ * Slow but default matchRegexp Implementation
+ * Create a Big Enough QArray and then iterate
+ * over all Records and matchRegexp them.
+ * At the end we will resize the array to the actual
+ * number of items
+ */
+template <class T>
+UIDArray OPimAccessBackend<T>::matchRegexp( const QRegExp& reg )const {
+ UIDArray all_rec = allRecords();
+ UIDArray result( all_rec.count() );
+ uint used_records = 0, all_rec_count = all_rec.count();
+
+ for ( uint i = 0; i < all_rec_count; ++i )
+ if (find( all_rec[i], all_rec, i, Frontend::Forward ).match( reg ) )
+ result[used_records++] = all_rec[i];
+
+ /* shrink to fit */
+ result.resize( used_records );
+ return result;
+}
+
+template <class T>
+UIDArray OPimAccessBackend<T>::queryByExample( const OPimRecord* rec, int settings,
+ const QDateTime& datetime )const {
+ T* tmp_rec = T::safeCast( rec );
+ UIDArray ar;
+ if ( tmp_rec )
+ ar = queryByExample( *tmp_rec, settings, datetime );
+
+ return ar;
+}
+
+template <class T>
+UIDArray OPimAccessBackend<T>::sorted( const UIDArray& ids, bool,
+ int, int, const QArray<int>& ) const {
+ return ids;
+}
+
+template <class T>
+UIDArray OPimAccessBackend<T>::sorted( bool asc, int order, int filter,
+ const QArray<int>& cats )const {
+ return sorted( allRecords(), asc, order, filter, cats );
+}
+
+template<class T>
+OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDate&,
+ const QDate& )const {
+ return OPimBackendOccurrence::List();
+}
+
+template<class T>
+OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDateTime& dt )const {
+ QDate date = dt.date();
+ return occurrences( date, date );
+}
+
template <class T>
@@ -168,3 +196,2 @@ void OPimAccessBackend<T>::cache( const T& t )const {
-
template <class T>
@@ -195,2 +222,202 @@ int OPimAccessBackend<T>::access()const {
+/**
+ * \fn template <class T> OPimAccessBackend<T>::OPimAccessBackend(int hint )
+ * @param hint The access hint from the frontend
+ */
+
+/**
+ * \fn template <class T> bool OPimAccessBackend<T>::load()
+ * Opens the DataBase and does necessary
+ * initialisation of internal structures.
+ *
+ * @return true If the DataBase could be opened and
+ * Information was successfully loaded
+ */
+
+/**
+ * \fn template <class T> bool OPimAccessBackend<T>::reload()
+ * Reinitialise the DataBase and merges the external changes
+ * with your local changes.
+ *
+ * @return True if the DataBase was reloaded.
+ *
+ */
+
+/**
+ * \fn template <class T> bool OPimAccessBackend<T>::save()
+ *
+ * Save the changes to storage. In case of memory or
+ * disk shortage, return false.
+ *
+ *
+ * @return True if the DataBase could be saved to storage.
+ */
+
+/**
+ * \fn template <class T> bool OPimAccessBackend<T>::clear()
+ * Until a \sa save() changes shouldn't be comitted
+ *
+ *
+ * @return True if the DataBase could be cleared
+ * @todo Introduce a 'Commit'
+ */
+
+/**
+ * \fn template <class T> QArray<UID> OPimAccessBackend<T>::allRecords()const
+ * Return an array of all available uids in the loaded
+ * DataBase.
+ * @see load
+ */
+
+/**
+ * \fn template <class T> QArray<UID> OPimAccessBackend<T>::matchRegexp(const QRegExp& r)const
+ * Return a List of records that match the regex \par r.
+ *
+ * @param r The QRegExp to match.
+ */
+
+/**
+ * \fn template <class T> QArray<UID> OPimAccessBackend<T>::queryByExample(const T& t, int settings, const QDateTime& d = QDateTime() )
+ *
+ * Implement QueryByExample. An Example record is filled and with the
+ * settings and QDateTime it is determined how the query should be executed.
+ * Return a list of UIDs that match the Example
+ *
+ * @param t The Example record
+ * @param settings Gives
+ *
+ */
+
+/**
+ * \fn template<class T> QArray<UID> OPimAccessBackend<T>::sorted(const QArray<UID>& ids, bool asc, int sortOrder, int sortFilter, int cat)
+ * \brief Sort the List of records according to the preference
+ *
+ * Implement sorting in your backend. The default implementation is
+ * to return the list as it was passed.
+ * The default Backend Implementation should do unaccelerated filtering
+ *
+ *
+ * @param ids The Records to sort
+ * @param asc Sort ascending or descending
+ * @param sortOrder
+ * @param sortFilter Sort filter
+ * @param cat The Category to include
+ */
+
+/**
+ * \fn template <class T> T OPimAccessBackend<T>::find(UID uid)const
+ * \brief Find the Record with the UID
+ *
+ * Find the UID in the database and return the record.
+ * @param uid The uid to be searched for
+ * @return The record or an empty record (T.isEmpty())
+ *
+ */
+
+/**
+ * \fn template <class T> T OPimAccessBackend<T>::find( UID uid, const QArray<UID>& items, uint current, typename Frontend::CacheDirection d)const
+ * \brief find a Record and do a read ahead or read behind
+ *
+ * @param uid The UID to search for
+ * @param items The list of items from where your search
+ * @param current The index of \param uid
+ * @param d The direction to search for
+ *
+ * @see find
+ */
+
+
+/**
+ * \fn template<class T> bool OPimAccessBackend<T>::add(const T& t)
+ *
+ * \brief Add the record to the internal database
+ *
+ * If an record with the same t.uid() is already present internally
+ * the behaviour is undefined but the state of the database
+ * needs to be stable.
+ * For modifying a record use \sa replace.
+ *
+ *
+ * @return true if the record could be added or false if not
+ * @todo Eilers your opinion on readd/replace
+ */
+
+/**
+ * \fn template<class T> bool OPimAccessBackend<T>::remove(UID uid)
+ * \brief Remove a record by its UID
+ *
+ * Remove the records with UID from the internal Database.
+ *
+ * @return True if the record could be removed.
+ *
+ */
+
+/**
+ * \fn template<class T> bool OPimAccessBackend<T>::replace(const T& t)
+ * \brief Take this Record and replace the old version.
+ *
+ * Take \param t as the new record for t.uid(). It is not described
+ * what happens if the record is not present in the database.
+ * Normally the record is determined by the UID.
+ *
+ * @param t The record to use internally.
+ */
+
+/**
+ * \fn template<class T> void OPimAccessBackend<T>::setFrontend( Frontend* fron)
+ * \@aram fron The Frontend that uses this backend
+ *
+ * This function is called by the frontend and is used
+ */
+
+/**
+ * \fn template<class T> void OPimAccessBackend<T>::setReadAhead(uint count)
+ * \brief Set the number of items to Read-Ahead/Read-Behind
+ *
+ * @param count The number of records to read ahead
+ */
+
+/**
+ * \fn template<class T> void OPimAccessBackend<T>::cache( const T& t)const
+ * \brief Add the Record to the PIM Cache
+ *
+ * This will add the Record to the PIM cache, which is owned
+ * by the FrontEnd. If no FrontEnd is available the item will
+ * not be cached.
+ *
+ *
+ * @param t The Item to be added to the Cache
+ */
+
+/**
+ * \fn template<class T> void OPimAccessBackend<T>::setSaneCacheSize(int items)
+ * \brief Give a hint on the number of too cached items
+ *
+ * Give the Frontend a hint on the number of items to be cached. Use
+ * a prime number for best performance.
+ *
+ * @param items The number of items to be cached
+ */
+
+/**
+ * \fn template<class T> uint OPimAccessBackend<T>::readAhead()const
+ * \brief Return the number of Items to be ReadAhead
+ *
+ * @return The number of Items to read ahead/read behind
+ */
+
+/**
+ * \fn template<class T> QArray<OPimBackendOccurence> OPimAccessBackend<T>::occurrences(const QDateTime& start,const QDateTime& end)
+ * \brief Get a List of Occurrences for a period of time
+ *
+ * Return an Array of OPimBackendOccurence for a period of time. If start == end date
+ * return only occurrences for the start date. If end is smaller the start date
+ * the result is not defined. You could switch dates or return an empty list.
+ *
+ * @return Return an array of OPimBackendOccurence for the period specified by the parameters
+ * @param start The start of the period.
+ * @param end The end of the period.
+ *
+ */
+
#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 @@
+/*
+ This file is part of the Opie Project
+ Copyright (C) 2004 Holger Hans Peter Freyther <zecke@handhelds.org>
+ =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
+ .=l.
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "opimbackendoccurrence.h"
+
+namespace Opie {
+
+OPimBackendOccurrence::OPimBackendOccurrence() {}
+/**
+ * \brief The occurence is only on the specefic Day
+ *
+ * If an occurrence is only a day without any time associated
+ * use this Constructor.
+ * \sa timeAssociated() will return false.
+ *
+ * @param date The Date this Occurence takes place
+ * @param uid The \sa UID of the associated OPimRecord
+ * @param sum The optional summary
+ *
+ */
+OPimBackendOccurrence::OPimBackendOccurrence( const QDate& date,
+ const UID& uid,
+ const QString& sum )
+ : m_start( date ), m_end( date ), m_uid( uid ),
+ m_haveTime(false ), m_summary( sum )
+{}
+
+/**
+ * \brief An Occurrence with a start day and end day without time
+ *
+ * Overloaded Constructor. Use this if you've a start date and
+ * end date but no time. If you need to overwrite the summary
+ * use setSummary.
+ * \sa timeAssociated() will return false.
+ *
+ * @param date The Start Date
+ * @param end Tne End Date
+ * @param uid The UID of the associated record
+ *
+ * @see setSummary
+ */
+OPimBackendOccurrence::OPimBackendOccurrence( const QDate& date,
+ const QDate& end,
+ const UID& uid)
+ : m_start( date ), m_end( end ), m_uid( uid ), m_haveTime( false )
+{}
+
+
+/**
+ * \brief Use Start and End Date with Time
+ *
+ * Overloaded Constructor to use Dates with Time time associated
+ * to it. \sa timeAssociated() will return true.
+ *
+ * @param date The Start Date and Time of the occurrence
+ * @param end The End Date and Time of the occurrence
+ * @param uid The UID of the \sa OPimRecord.
+ */
+OPimBackendOccurrence::OPimBackendOccurrence( const QDateTime& date,
+ const QDateTime& end,
+ const UID& uid )
+ : m_start( date ), m_end( end ), m_uid( uid ), m_haveTime( true )
+{}
+
+/**
+ * \brief Return the Start Date and Time
+ *
+ * @return This method will return the start
+ * Date and Time. Time is only valid if
+ * \sa timeAssociated() is true.
+ *
+ */
+QDateTime OPimBackendOccurrence::startDateTime()const {
+ return m_start;
+}
+
+/**
+ * \brief Return the Start Date and Time
+ *
+ * @return This will return the end Date and Time. The
+ * limitation for Time is the same as in startDateTime
+ *
+ * @see startDateTime()
+ */
+QDateTime OPimBackendOccurrence::endDateTime()const {
+ return m_end;
+}
+
+/**
+ * \brief Return the UID of the Associated OPimRecord
+ *
+ * @return the associated OPimRecord
+ */
+UID OPimBackendOccurrence::uid()const {
+ return m_uid;
+}
+
+/**
+ * \brief Return if there is a time associated or not
+ *
+ * If a time is present with start and end date this method
+ * will return true. There is no direct way to manipulate
+ * that attribute. But \sa setStartDate and \sa setStartDateTime
+ * will change it.
+ *
+ * @return Return true if a time is available with the date
+ *
+ */
+bool OPimBackendOccurrence::isAllDay()const {
+ return m_haveTime;
+}
+
+/**
+ * @return The special summary that will overwrite OPimRecord::summary
+ */
+QString OPimBackendOccurrence::summary()const {
+ return m_summary;
+}
+
+QString OPimBackendOccurrence::location()const {
+ return m_location;
+}
+
+QString OPimBackendOccurrence::note()const {
+ return m_note;
+}
+
+/**
+ * \brief Set the Start Date
+ *
+ * This method will set the start date and internally will mark
+ * this occurrence to have no time associated to both start
+ * and end date.
+ * A call to timeAssociated will return false after using this
+ * method.
+ *
+ * @param start The Start Date
+ *
+ */
+void OPimBackendOccurrence::setStartDate( const QDate& start) {
+ m_start = start;
+ m_haveTime = false;
+}
+
+/**
+ * \brief Set the Start Date and Time
+ *
+ * Set the Start Date and Time. After this call
+ * \sa timeAssociated will return true.
+ *
+ * @param dt The Start Date and Time to be set
+ */
+void OPimBackendOccurrence::setStartDateTime( const QDateTime& dt ) {
+ m_start = dt;
+ m_haveTime = true;
+}
+
+/**
+ * \brief This will set the End Date.
+ *
+ * This method will set the End Date. The timeAssociated attribute
+ * will not be changed.
+ *
+ * @param end The End Date to be set
+ */
+void OPimBackendOccurrence::setEndDate( const QDate& end ) {
+ m_end = end;
+}
+
+/**
+ * \brief Set the End Date and Time of the occurrence
+ *
+ * This will set the End Date and Time but will not change
+ * the timeAssociated attribute.
+ *
+ * @param dt The End Date and Time to be set.
+ */
+void OPimBackendOccurrence::setEndDateTime( const QDateTime& dt ) {
+ m_end = dt;
+}
+
+/**
+ * \brief This method will set the UID of the Record
+ *
+ * Set the UID of the OPimRecord to be associated with
+ * this OPimRecurrence.
+ *
+ * @param uid The UID of the associated OPimRecord to be set
+ */
+void OPimBackendOccurrence::setUid( const UID& uid ) {
+ m_uid = uid;
+}
+
+
+/**
+ * \brief Set a special summary instead of \sa OPimRecord::summary()
+ *
+ * If \sa OPimRecord::summary() doesn't describe the occurrence
+ * reason you can set a custom summary for the Occurrence.
+ *
+ * @param str The to be set Summary
+ */
+void OPimBackendOccurrence::setSummary( const QString& str ) {
+ m_summary = str;
+}
+
+void OPimBackendOccurrence::setLocation( const QString& str ) {
+ m_location = str;
+}
+
+void OPimBackendOccurrence::setNote( const QString& str ) {
+ m_note = str;
+}
+
+}
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 @@
+/*
+ This file is part of the Opie Project
+ Copyright (C) 2004 Holger Hans Peter Freyther <zecke@handhelds.org>
+ =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
+ .=l.
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef OPIE_PIM_BACKEND_OCCURRENCE_H
+#define OPIE_PIM_BACKEND_OCCURRENCE_H
+
+#include <opie2/opimglobal.h>
+
+#include <qarray.h>
+#include <qdatetime.h>
+#include <qvaluelist.h>
+
+namespace Opie {
+
+/**
+ * \brief Internal representation of an Occurence
+ *
+ * This class is used by the Backends to express
+ * Occurences for the Period Based Query to
+ * the by the Backend represanted Database.
+ * In the Frontend this single representation is splitted
+ * into per day \sa OPimOccurrence 's.
+ * OPimBackendOccurrence can be understand as a hint to
+ * the Frontend and must contain the \sa UID, the Start Date
+ * and End Date of the Occurence. If you have no time associated
+ * to the datetime use the QDate constructors.
+ * If OPimRecord::summary() does not describe the Occurrence
+ * right you can call setSummary() and then the supplied
+ * summary will be used.
+ * All Dates and Times are in the local time.
+ *
+ * @version 1.0
+ * @author Holger Hans Peter Freyther zecke@handhelds.org
+ */
+class OPimBackendOccurrence {
+public:
+ typedef QValueList<OPimBackendOccurrence> List;
+
+ //@{
+ OPimBackendOccurrence();
+ OPimBackendOccurrence( const QDate& date,
+ const UID& , const QString& = QString::null );
+ OPimBackendOccurrence( const QDate& date, const QDate& end,
+ const UID& );
+ OPimBackendOccurrence( const QDateTime& start,
+ const QDateTime& end,
+ const UID& uid );
+ //@}
+
+ //@{
+ QDateTime startDateTime()const;
+ QDateTime endDateTime()const;
+ UID uid()const;
+ bool isAllDay()const;
+ QString summary()const;
+ QString location()const;
+ QString note()const;
+ //@}
+
+ //@{
+ void setStartDate( const QDate& );
+ void setStartDateTime( const QDateTime& dt );
+ void setEndDate( const QDate& );
+ void setEndDateTime( const QDateTime& dt );
+ void setUid( const UID& );
+ void setSummary( const QString& );
+ void setLocation( const QString& );
+ void setNote( const QString& );
+ //@}
+
+private:
+ QDateTime m_start, m_end;
+ UID m_uid;
+ bool m_haveTime : 1;
+ QString m_summary, m_note, m_location;
+
+ struct Private;
+ Private *d;
+};
+}
+
+#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 @@
#include <opie2/otodoaccessbackend.h>
+#include <opie2/private/opimtodosortvector.h>
+#include <opie2/otodoaccess.h>
+
+#include <qintdict.h>
@@ -40,2 +44,112 @@ OPimTodoAccessBackend::~OPimTodoAccessBackend() {
+UIDArray OPimTodoAccessBackend::queryByExample( const OPimTodo&, int settings,
+ const QDateTime& d)const {
+ return UIDArray();
+}
+
+UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc,
+ int sortOrder, int sortFilter,
+ const QArray<int>& categories )const {
+ odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl;
+ Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder );
+ int item = 0;
+
+ bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false;
+ bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false;
+ bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false;
+ bool catPassed = false;
+ int cat;
+
+ for ( uint i = 0; i < events.count(); ++i ) {
+ OPimTodo todo = find( events[i], events, i, Frontend::Forward );
+ if ( todo.isEmpty() )
+ continue;
+
+ /* show category */
+ /* -1 == unfiled */
+ catPassed = false;
+ for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
+ cat = categories[cat_nu];
+ if ( bCat && cat == -1 ) {
+ if(!todo.categories().isEmpty() )
+ continue;
+ } else if ( bCat && cat != 0)
+ if (!todo.categories().contains( cat ) )
+ continue;
+ catPassed = true;
+ break;
+ }
+
+ /*
+ * If none of the Categories matched
+ * continue
+ */
+ if ( !catPassed )
+ continue;
+ if ( !todo.isOverdue() && bOnly )
+ continue;
+ if (todo.isCompleted() && comp )
+ continue;
+
+ vector.insert(item++, todo );
+ }
+
+ vector.resize( item );
+ /* sort it now */
+ vector.sort();
+ /* now get the uids */
+ UIDArray array( vector.count() );
+ for (uint i= 0; i < vector.count(); i++ )
+ array[i] = vector.uidAt( i );
+
+ return array;
+}
+
+OPimBackendOccurrence::List OPimTodoAccessBackend::occurrences( const QDate& start,
+ const QDate& end )const {
+ OPimBackendOccurrence::List lst;
+ UIDArray effective = effectiveToDos( start, end, false );
+ UIDArray overdue = overDue();
+ uint count = effective.count();
+ int uid;
+ QIntDict<int> hash;
+ hash.setAutoDelete( true );
+ OPimTodo todo;
+
+ for ( uint i = 0; i < count; ++i ) {
+ uid = effective[i];
+ todo = find( uid, effective, i, Frontend::Forward );
+ /*
+ * If isOverdue but in the 'normal' range we will fill
+ * the hash so we won't have duplicates in OPimBackendOccurrence
+ */
+ if ( todo.isOverdue() )
+ hash.insert( uid, new int(6) );
+ OPimBackendOccurrence oc = todo.hasStartDate() ?
+ OPimBackendOccurrence( todo.startDate(),
+ todo.dueDate(), uid ) :
+ OPimBackendOccurrence( todo.dueDate(), uid, QString::null );
+ oc.setSummary( todo.summary() );
+ lst.append( oc );
+ }
+
+ /*
+ * Create the OverDue items but skip
+ * the already handled Records
+ */
+ if ( !overdue.isEmpty() ) {
+ QDate today = QDate::currentDate();
+ QDate dueDate = (start >= today && today <= end ) ? today : start;
+ count = overdue.count();
+ for ( uint i = 0; i < count; ++i ) {
+ uid = overdue[i];
+ if (!hash.find( uid ) )
+ continue;
+ todo = find( uid, overdue, i, Frontend::Forward );
+ lst.append( OPimBackendOccurrence(dueDate, uid, todo.summary() ) );
+ }
+ }
+
+ return lst;
+}
}
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:
~OPimTodoAccessBackend();
- virtual QArray<int> effectiveToDos( const QDate& start,
- const QDate& end,
- bool includeNoDates ) = 0;
- virtual QArray<int> overDue() = 0;
- virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
- int cat ) = 0;
- virtual void removeAllCompleted() = 0;
- virtual QBitArray supports()const = 0;
-
+ virtual UIDArray effectiveToDos( const QDate& start,
+ const QDate& end,
+ bool includeNoDates )const = 0;
+ virtual UIDArray overDue()const = 0;
+ virtual void removeAllCompleted() = 0;
+
+ /**
+ * Common and probably inefficent implementation
+ * for queryByExample, matchRegexp, sorted
+ * and occurrences
+ */
+ //@{
+ UIDArray queryByExample( const OPimTodo&, int settings, const QDateTime& d = QDateTime() )const;
+ UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const;
+ OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const;
+ //@}
+
private:
@@ -55,5 +63,17 @@ private:
};
-
}
+
+/**
+ * \fn Opie::OPimBackendOccurrence::List Opie::OPimTodoAccessBackend::occurrences(const QDate& start,const QDate& end)const
+ * \brief Return occurrences for a period of time
+ *
+ * This method will return the 'effective' Todos and also
+ * 'Overdue' Todos. Overdues will be shown on the 'current'
+ * day if it is in the range or on \par start. If the overdue
+ * is inside the 'Effective Todos' we will skip the
+ * special overdue handling.
+ *
+ *
+ */
#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{
return parseResultAndCache( uid, m_driver->query(&query) );
-
}
@@ -467,3 +466,2 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
uint size =0;
- OPimTodo to;
@@ -471,6 +469,5 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
switch( dir ) {
- /* forward */
+ /* forward */
case Frontend::Forward:
for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
- odebug << "size " << size << " " << ints[i] << "" << oendl;
search[size] = ints[i];
@@ -479,4 +476,4 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
break;
- /* reverse */
- case Frontend::Reverse:
+ /* reverse */
+ case Frontend::Reverse:
for (uint i = cur; i != 0 && size < CACHE; i-- ) {
@@ -492,3 +489,3 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
if ( res.state() != OSQLResult::Success )
- return to;
+ return OPimTodo();
@@ -509,2 +506,3 @@ bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
return false;
+
int c = m_uids.count();
@@ -536,3 +534,3 @@ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
}
-QArray<int> OPimTodoAccessBackendSQL::overDue() {
+QArray<int> OPimTodoAccessBackendSQL::overDue()const {
OverDueQuery qu;
@@ -542,3 +540,3 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
const QDate& t,
- bool u) {
+ bool u)const {
EffQuery ef(s, t, u );
@@ -546,2 +544,4 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
}
+
+#if 0
/*
@@ -562,3 +562,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
/* Category */
- if ( sortFilter & 1 ) {
+ if ( sortFilter & OPimTodoAccess::FilterCategory ) {
QString str;
@@ -568,3 +568,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
/* Show only overdue */
- if ( sortFilter & 2 ) {
+ if ( sortFilter & OPimTodoAccess::OnlyOverDue ) {
QDate date = QDate::currentDate();
@@ -579,3 +579,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
/* not show completed */
- if ( sortFilter & 4 ) {
+ if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
query += " completed = 0 AND";
@@ -595,12 +595,12 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
/* completed */
- case 0:
+ case OPimTodoAccess::Completed:
query += "completed";
break;
- case 1:
+ case OPimTodoAccess::Priority:
query += "priority";
break;
- case 2:
+ case OPimTodoAccess::SortSummary:
query += "summary";
break;
- case 3:
+ case OPimTodoAccess::Deadline:
query += "DueDate";
@@ -609,6 +609,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
- if ( !asc ) {
- odebug << "not ascending!" << oendl;
+ if ( !asc )
query += " DESC";
- }
+
@@ -618,2 +617,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
}
+#endif
+
+
bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
@@ -631,2 +633,4 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
}
+
+
OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
@@ -641,10 +645,6 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul
OSQLResultItem::ValueList::Iterator it = list.begin();
- odebug << "todo1" << oendl;
- OPimTodo to = todo( (*it) );
- cache( to );
- ++it;
+ OPimTodo to, tmp;
for ( ; it != list.end(); ++it ) {
- odebug << "caching" << oendl;
- OPimTodo newTodo = todo( (*it) );
+ OPimTodo newTodo = parse( (*it) );
cache( newTodo );
@@ -655,4 +655,3 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul
}
-OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
- odebug << "todo(ResultItem)" << oendl;
+OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const {
@@ -664,4 +663,2 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
- odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
-
OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
@@ -719,32 +716,4 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
}
-/*
- * update the dict
- */
-void OPimTodoAccessBackendSQL::fillDict() {
-#if 0
- /* initialize dict */
- /*
- * UPDATE dict if you change anything!!!
- * FIXME: Isn't this dict obsolete ? (eilers)
- */
- m_dict.setAutoDelete( TRUE );
- m_dict.insert("Categories" , new int(OPimTodo::Category) );
- m_dict.insert("Uid" , new int(OPimTodo::Uid) );
- m_dict.insert("HasDate" , new int(OPimTodo::HasDate) );
- m_dict.insert("Completed" , new int(OPimTodo::Completed) );
- m_dict.insert("Description" , new int(OPimTodo::Description) );
- m_dict.insert("Summary" , new int(OPimTodo::Summary) );
- m_dict.insert("Priority" , new int(OPimTodo::Priority) );
- m_dict.insert("DateDay" , new int(OPimTodo::DateDay) );
- m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
- m_dict.insert("DateYear" , new int(OPimTodo::DateYear) );
- m_dict.insert("Progress" , new int(OPimTodo::Progress) );
- m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers)
- m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
-// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
-// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
-#endif
-}
/*
@@ -767,3 +736,2 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
QArray<int> ints(list.count() );
- odebug << " count = " << list.count() << "" << oendl;
@@ -779,11 +747,5 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
{
-
-#if 0
- QArray<int> empty;
- return empty;
-
-#else
QString qu = "SELECT uid FROM todolist WHERE (";
- // Do it make sense to search other fields, too ?
+ // Does it make sense to search other fields, too ?
qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
@@ -793,4 +755,2 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
- odebug << "query: " << qu << "" << oendl;
-
OSQLRawQuery raw( qu );
@@ -799,23 +759,2 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
return uids( res );
-
-
-#endif
-
-}
-QBitArray OPimTodoAccessBackendSQL::supports()const {
-
- return sup();
-}
-
-QBitArray OPimTodoAccessBackendSQL::sup() const{
-
- QBitArray ar( OPimTodo::CompletedDate + 1 );
- ar.fill( true );
- ar[OPimTodo::CrossReference] = false;
- ar[OPimTodo::State ] = false;
- ar[OPimTodo::Reminders] = false;
- ar[OPimTodo::Notifiers] = false;
- ar[OPimTodo::Maintainer] = false;
-
- return ar;
}
@@ -833,4 +772,2 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
- odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
-
if ( completed_uids.size() == 0 )
@@ -841,3 +778,3 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
- for ( int i = 0; i < completed_uids.size(); i++ ){
+ for ( uint i = 0; i < completed_uids.size(); i++ ){
if ( !query.isEmpty() )
@@ -852,3 +789,3 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
- for ( int i = 0; i < completed_uids.size(); i++ ){
+ for ( uint i = 0; i < completed_uids.size(); i++ ){
if ( !query.isEmpty() )
@@ -859,9 +796,8 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
- odebug << "query: " << qu << "" << oendl;
-
OSQLRawQuery raw2( qu );
res = m_driver->query( &raw2 );
- if ( res.state() == OSQLResult::Failure ) {
+
+ if ( res.state() == OSQLResult::Failure )
owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl;
- }
+
}
@@ -878,4 +814,3 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
owarn << "OSQLResult::Failure in find query !!" << oendl;
- QMap<QString, QString> empty;
- return empty;
+ return QMap<QString, QString>();
}
@@ -884,5 +819,5 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
OSQLResultItem::ValueList::Iterator it = list.begin();
- for ( ; it != list.end(); ++it ) {
+ for ( ; it != list.end(); ++it )
customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
- }
+
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:
bool save();
- QArray<int> allRecords()const;
+ QArray<UID> allRecords()const;
- QArray<int> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() );
- OPimTodo find(int uid)const;
- OPimTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
+ QArray<UID> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() );
+ OPimTodo find(UID uid)const;
+ OPimTodo find(UID uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
void clear();
bool add( const OPimTodo& t );
- bool remove( int uid );
+ bool remove( UID uid );
bool replace( const OPimTodo& t );
- QArray<int> overDue();
- QArray<int> effectiveToDos( const QDate& start,
- const QDate& end, bool includeNoDates );
- QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
-
- QBitArray supports()const;
- QArray<int> matchRegexp( const QRegExp &r ) const;
+ QArray<UID> overDue()const;
+ QArray<UID> effectiveToDos( const QDate& start,
+ const QDate& end, bool includeNoDates )const;
+ QArray<UID> matchRegexp( const QRegExp &r ) const;
void removeAllCompleted();
-
+
@@ -75,10 +72,8 @@ private:
void update()const;
- void fillDict();
inline bool date( QDate& date, const QString& )const;
- inline OPimTodo parseResultAndCache( int uid, const Opie::DB::OSQLResult& )const;
- inline OPimTodo todo( Opie::DB::OSQLResultItem& )const;
- inline QArray<int> uids( const Opie::DB::OSQLResult& )const;
- OPimTodo todo( int uid )const;
- QBitArray sup() const;
- QMap<QString, QString> requestCustom( int uid ) const;
+ inline OPimTodo parseResultAndCache( UID uid, const Opie::DB::OSQLResult& )const;
+ inline OPimTodo parse( Opie::DB::OSQLResultItem& )const;
+ inline QArray<UID> uids( const Opie::DB::OSQLResult& )const;
+ OPimTodo todo( UID uid )const;
+ QMap<QString, QString> requestCustom( UID uid ) const;
@@ -86,3 +81,3 @@ private:
Opie::DB::OSQLDriver* m_driver;
- QArray<int> m_uids;
+ QArray<UID> m_uids;
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 {
name = vObjectStringZValue( ob );
- owarn << "Categories:" << name.data() << "" << oendl;
}
@@ -235,6 +234,3 @@ OPimTodo OPimTodoAccessVCal::find(int uid )const {
}
-QArray<int> OPimTodoAccessVCal::sorted( bool, int, int, int ) {
- QArray<int> ar(0);
- return ar;
-}
+
QArray<int> OPimTodoAccessVCal::allRecords()const {
@@ -249,17 +245,6 @@ QArray<int> OPimTodoAccessVCal::allRecords()const {
}
-QArray<int> OPimTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const {
- QArray<int> ar(0);
- return ar;
-}
-QArray<int> OPimTodoAccessVCal::queryByExample( const OPimTodo&, int, const QDateTime& ) {
- QArray<int> ar(0);
- return ar;
-}
+
QArray<int> OPimTodoAccessVCal::effectiveToDos( const QDate& ,
const QDate& ,
- bool ) {
- QArray<int> ar(0);
- return ar;
-}
-QArray<int> OPimTodoAccessVCal::overDue() {
+ bool )const {
QArray<int> ar(0);
@@ -267,20 +252,5 @@ QArray<int> OPimTodoAccessVCal::overDue() {
}
-QBitArray OPimTodoAccessVCal::supports()const {
- static QBitArray ar = sup();
-
- return ar;
-}
-QBitArray OPimTodoAccessVCal::sup() {
- QBitArray ar ( OPimTodo::CompletedDate +1 );
- ar.fill( true );
-
- ar[OPimTodo::CrossReference] = false;
- ar[OPimTodo::State ] = false;
- ar[OPimTodo::Reminders] = false;
- ar[OPimTodo::Notifiers] = false;
- ar[OPimTodo::Maintainer] = false;
- ar[OPimTodo::Progress] = false;
- ar[OPimTodo::Alarms ] = false;
- ar[OPimTodo::Recurrence] = false;
+QArray<int> OPimTodoAccessVCal::overDue()const {
+ QArray<int> ar(0);
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:
QArray<int> allRecords()const;
- QArray<int> matchRegexp(const QRegExp &r) const;
- QArray<int> queryByExample( const OPimTodo& t, int sort, const QDateTime& d = QDateTime() );
QArray<int> effectiveToDos( const QDate& start,
const QDate& end,
- bool includeNoDates );
- QArray<int> overDue();
- QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
- int cat );
+ bool includeNoDates )const;
+ QArray<int> overDue()const;
OPimTodo find(int uid)const;
@@ -60,6 +56,4 @@ public:
void removeAllCompleted();
- virtual QBitArray supports()const;
private:
- static QBitArray sup();
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 @@
#include <opie2/otodoaccessxml.h>
+#include <opie2/otodoaccess.h>
#include <opie2/odebug.h>
+#include <opie2/private/opimtodosortvector.h>
+
#include <qpe/global.h>
@@ -144,3 +147,2 @@ bool OPimTodoAccessXML::load() {
dict.insert("Reminders", new int(OPimTodo::Reminders) );
- dict.insert("Notifiers", new int(OPimTodo::Notifiers) );
dict.insert("Maintainer", new int(OPimTodo::Maintainer) );
@@ -184,3 +186,2 @@ bool OPimTodoAccessXML::load() {
i+= strLen;
- owarn << "Found a start at " << i << " " << (point-dt) << "" << oendl;
@@ -240,3 +241,2 @@ bool OPimTodoAccessXML::load() {
*/
- owarn << "End at " << i << "" << oendl;
if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
@@ -263,3 +263,2 @@ bool OPimTodoAccessXML::load() {
- owarn << "counts " << m_events.count() << " records loaded!" << oendl;
return true;
@@ -271,5 +270,3 @@ bool OPimTodoAccessXML::reload() {
bool OPimTodoAccessXML::save() {
-// owarn << "saving" << oendl;
if (!m_opened || !m_changed ) {
-// owarn << "not saving" << oendl;
return true;
@@ -314,3 +311,2 @@ bool OPimTodoAccessXML::save() {
if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
-// owarn << "error renaming" << oendl;
QFile::remove( strNewFile );
@@ -326,6 +322,6 @@ QArray<int> OPimTodoAccessXML::allRecords()const {
- for ( it = m_events.begin(); it != m_events.end(); ++it ) {
- ids[i] = it.key();
- i++;
- }
+ for ( it = m_events.begin(); it != m_events.end(); ++it )
+ ids[i++] = it.key();
+
+
return ids;
@@ -352,3 +348,2 @@ void OPimTodoAccessXML::clear() {
bool OPimTodoAccessXML::add( const OPimTodo& todo ) {
-// owarn << "add" << oendl;
m_changed = true;
@@ -372,5 +367,5 @@ QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
const QDate& end,
- bool includeNoDates ) {
+ bool includeNoDates )const {
QArray<int> ids( m_events.count() );
- QMap<int, OPimTodo>::Iterator it;
+ QMap<int, OPimTodo>::ConstIterator it;
@@ -378,11 +373,7 @@ QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
- if ( !it.data().hasDueDate() ) {
- if ( includeNoDates ) {
- ids[i] = it.key();
- i++;
- }
+ if ( !it.data().hasDueDate() && includeNoDates) {
+ ids[i++] = it.key();
}else if ( it.data().dueDate() >= start &&
it.data().dueDate() <= end ) {
- ids[i] = it.key();
- i++;
+ ids[i++] = it.key();
}
@@ -392,3 +383,3 @@ QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
}
-QArray<int> OPimTodoAccessXML::overDue() {
+QArray<int> OPimTodoAccessXML::overDue()const {
QArray<int> ids( m_events.count() );
@@ -396,3 +387,3 @@ QArray<int> OPimTodoAccessXML::overDue() {
- QMap<int, OPimTodo>::Iterator it;
+ QMap<int, OPimTodo>::ConstIterator it;
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
@@ -411,3 +402,2 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
const QCString& attr, const QString& val) {
-// owarn << "parse to do from XMLElement" << oendl;
@@ -417,3 +407,2 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
if (!find ) {
-// owarn << "Unknown option" + it.key() << oendl;
ev.setCustomField( attr, val );
@@ -470,4 +459,2 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty
- owarn << "alarm: " << alarm.join("___") << "" << oendl;
- owarn << "alarm[0]: " << alarm[0] << " " << OPimDateConversion::dateTimeFromString( alarm[0] ).toString() << "" << oendl;
OPimAlarm al( alarm[2].toInt(), OPimDateConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() );
@@ -544,3 +531,2 @@ QString customToXml(const QMap<QString, QString>& customMap )
{
- //owarn << QString("writing custom %1").arg(customMap.count()) << oendl;
QString buf(" ");
@@ -548,3 +534,2 @@ QString customToXml(const QMap<QString, QString>& customMap )
cit != customMap.end(); ++cit) {
-// owarn << ".ITEM." << oendl;
buf += cit.key();
@@ -577,3 +562,2 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
}
-// owarn << "Uid " << ev.uid() << "" << oendl;
str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
@@ -624,3 +608,2 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
// now write the list
- owarn << "als: " << als.join("____________") << "" << oendl;
str += "Alarms=\""+als.join(";") +"\" ";
@@ -650,215 +633,51 @@ QString OPimTodoAccessXML::toString( const QArray<int>& ints ) const {
-/* internal class for sorting
- *
- * Inspired by todoxmlio.cpp from TT
- */
-struct OPimTodoXMLContainer {
- OPimTodo todo;
-};
+QArray<int> OPimTodoAccessXML::sorted( const UIDArray& events, bool asc,
+ int sortOrder,int sortFilter,
+ const QArray<int>& categories )const {
+ Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder );
+ int item = 0;
-namespace {
- inline QString string( const OPimTodo& todo) {
- return todo.summary().isEmpty() ?
- todo.description().left(20 ) :
- todo.summary();
- }
- inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) {
- int ret = 0;
- if ( todo1.isCompleted() ) ret++;
- if ( todo2.isCompleted() ) ret--;
- return ret;
- }
- inline int priority( const OPimTodo& t1, const OPimTodo& t2) {
- return ( t1.priority() - t2.priority() );
- }
- inline int description( const OPimTodo& t1, const OPimTodo& t2) {
- return QString::compare( string(t1), string(t2) );
- }
- inline int deadline( const OPimTodo& t1, const OPimTodo& t2) {
- int ret = 0;
- if ( t1.hasDueDate() &&
- t2.hasDueDate() )
- ret = t2.dueDate().daysTo( t1.dueDate() );
- else if ( t1.hasDueDate() )
- ret = -1;
- else if ( t2.hasDueDate() )
- ret = 1;
- else
- ret = 0;
+ bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false;
+ bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false;
+ bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false;
+ bool catPassed = false;
+ int cat;
- return ret;
- }
+ for ( uint i = 0; i < events.count(); ++i ) {
+ /* Guard against creating a new item... */
+ if ( !m_events.contains( events[i] ) )
+ continue;
-};
+ OPimTodo todo = m_events[events[i]];
-/*
- * Returns:
- * 0 if item1 == item2
- *
- * non-zero if item1 != item2
- *
- * This function returns int rather than bool so that reimplementations
- * can return one of three values and use it to sort by:
- *
- * 0 if item1 == item2
- *
- * > 0 (positive integer) if item1 > item2
- *
- * < 0 (negative integer) if item1 < item2
- *
- */
-class OPimTodoXMLVector : public QVector<OPimTodoXMLContainer> {
-public:
- OPimTodoXMLVector(int size, bool asc, int sort)
- : QVector<OPimTodoXMLContainer>( size )
- {
- setAutoDelete( true );
- m_asc = asc;
- m_sort = sort;
- }
- /* return the summary/description */
- QString string( const OPimTodo& todo) {
- return todo.summary().isEmpty() ?
- todo.description().left(20 ) :
- todo.summary();
- }
- /**
- * we take the sortorder( switch on it )
- *
- */
- int compareItems( Item d1, Item d2 ) {
- bool seComp, sePrio, seDesc, seDeadline;
- seComp = sePrio = seDeadline = seDesc = false;
- int ret =0;
- OPimTodoXMLContainer* con1 = (OPimTodoXMLContainer*)d1;
- OPimTodoXMLContainer* con2 = (OPimTodoXMLContainer*)d2;
-
- /* same item */
- if ( con1->todo.uid() == con2->todo.uid() )
- return 0;
-
- switch ( m_sort ) {
- /* completed */
- case 0: {
- ret = completed( con1->todo, con2->todo );
- seComp = TRUE;
- break;
- }
- /* priority */
- case 1: {
- ret = priority( con1->todo, con2->todo );
- sePrio = TRUE;
- break;
- }
- /* description */
- case 2: {
- ret = description( con1->todo, con2->todo );
- seDesc = TRUE;
- break;
- }
- /* deadline */
- case 3: {
- ret = deadline( con1->todo, con2->todo );
- seDeadline = TRUE;
+ /* show category */
+ /* -1 == unfiled */
+ catPassed = false;
+ for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
+ cat = categories[cat_nu];
+ if ( bCat && cat == -1 ) {
+ if(!todo.categories().isEmpty() )
+ continue;
+ } else if ( bCat && cat != 0)
+ if (!todo.categories().contains( cat ) )
+ continue;
+ catPassed = true;
break;
}
- default:
- ret = 0;
- break;
- };
- /*
- * FIXME do better sorting if the first sort criteria
- * ret equals 0 start with complete and so on...
- */
-
- /* twist it we're not ascending*/
- if (!m_asc)
- ret = ret * -1;
- if ( ret )
- return ret;
-
- // default did not gave difference let's try it other way around
/*
- * General try if already checked if not test
- * and return
- * 1.Completed
- * 2.Priority
- * 3.Description
- * 4.DueDate
+ * If none of the Categories matched
+ * continue
*/
- if (!seComp ) {
- if ( (ret = completed( con1->todo, con2->todo ) ) ) {
- if (!m_asc ) ret *= -1;
- return ret;
- }
- }
- if (!sePrio ) {
- if ( (ret = priority( con1->todo, con2->todo ) ) ) {
- if (!m_asc ) ret *= -1;
- return ret;
- }
- }
- if (!seDesc ) {
- if ( (ret = description(con1->todo, con2->todo ) ) ) {
- if (!m_asc) ret *= -1;
- return ret;
- }
- }
- if (!seDeadline) {
- if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
- if (!m_asc) ret *= -1;
- return ret;
- }
- }
-
- return 0;
- }
- private:
- bool m_asc;
- int m_sort;
-
-};
-
-QArray<int> OPimTodoAccessXML::sorted( bool asc, int sortOrder,
- int sortFilter, int cat ) {
- OPimTodoXMLVector vector(m_events.count(), asc,sortOrder );
- QMap<int, OPimTodo>::Iterator it;
- int item = 0;
-
- bool bCat = sortFilter & 1 ? true : false;
- bool bOnly = sortFilter & 2 ? true : false;
- bool comp = sortFilter & 4 ? true : false;
- for ( it = m_events.begin(); it != m_events.end(); ++it ) {
-
- /* show category */
- /* -1 == unfiled */
- if ( bCat && cat == -1 ) {
- if(!(*it).categories().isEmpty() )
- continue;
- }else if ( bCat && cat != 0)
- if (!(*it).categories().contains( cat ) ) {
- continue;
- }
- /* isOverdue but we should not show overdue - why?*/
-/* if ( (*it).isOverdue() && !bOnly ) {
- owarn << "item is overdue but !bOnly" << oendl;
+ if ( !catPassed )
continue;
- }
-*/
- if ( !(*it).isOverdue() && bOnly ) {
+ if ( !todo.isOverdue() && bOnly )
continue;
- }
-
- if ((*it).isCompleted() && comp ) {
+ if (todo.isCompleted() && comp )
continue;
- }
-
- OPimTodoXMLContainer* con = new OPimTodoXMLContainer();
- con->todo = (*it);
- vector.insert(item, con );
- item++;
+ vector.insert(item++, todo );
}
+
vector.resize( item );
@@ -867,8 +686,9 @@ QArray<int> OPimTodoAccessXML::sorted( bool asc, int sortOrder,
/* now get the uids */
- QArray<int> array( vector.count() );
- for (uint i= 0; i < vector.count(); i++ ) {
- array[i] = ( vector.at(i) )->todo.uid();
- }
+ UIDArray array( vector.count() );
+ for (uint i= 0; i < vector.count(); i++ )
+ array[i] = vector.uidAt( i );
+
return array;
-};
+}
+
void OPimTodoAccessXML::removeAllCompleted() {
@@ -881,26 +701,12 @@ void OPimTodoAccessXML::removeAllCompleted() {
}
-QBitArray OPimTodoAccessXML::supports()const {
- static QBitArray ar = sup();
- return ar;
-}
-QBitArray OPimTodoAccessXML::sup() {
- QBitArray ar( OPimTodo::CompletedDate +1 );
- ar.fill( true );
- ar[OPimTodo::CrossReference] = false;
- ar[OPimTodo::State ] = false;
- ar[OPimTodo::Reminders] = false;
- ar[OPimTodo::Notifiers] = false;
- ar[OPimTodo::Maintainer] = false;
-
- return ar;
-}
+
QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const
{
- QArray<int> m_currentQuery( m_events.count() );
+ QArray<int> currentQuery( m_events.count() );
uint arraycounter = 0;
- QMap<int, OPimTodo>::ConstIterator it;
- for (it = m_events.begin(); it != m_events.end(); ++it ) {
+ QMap<int, OPimTodo>::ConstIterator it;
+ for (it = m_events.begin(); it != m_events.end(); ++it ) {
if ( it.data().match( r ) )
- m_currentQuery[arraycounter++] = it.data().uid();
+ currentQuery[arraycounter++] = it.data().uid();
@@ -908,5 +714,5 @@ QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const
// Shrink to fit..
- m_currentQuery.resize(arraycounter);
+ currentQuery.resize(arraycounter);
- return m_currentQuery;
+ return currentQuery;
}
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:
const QDate& end,
- bool includeNoDates );
- QArray<int> overDue();
- QArray<int> sorted( bool asc, int sortOrder,
- int sortFilter, int cat );
- QBitArray supports()const;
+ bool includeNoDates )const;
+ QArray<int> overDue()const;
+
+//@{
+ UIDArray sorted( const UIDArray&, bool, int, int, const QArray<int>& )const;
+//@}
private:
- static QBitArray sup();
void todo( QAsciiDict<int>*, OPimTodo&,const QCString&,const QString& );
@@ -83,3 +83,2 @@ private:
int m_year, m_month, m_day;
-
};