summaryrefslogtreecommitdiff
Side-by-side diff
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,7 +1,9 @@
SOURCES += \
+ backend/ocontactaccessbackend.cpp \
backend/ocontactaccessbackend_vcard.cpp \
backend/ocontactaccessbackend_xml.cpp \
backend/odatebookaccessbackend.cpp \
backend/odatebookaccessbackend_xml.cpp \
+ backend/opimbackendoccurrence.cpp \
backend/otodoaccessbackend.cpp \
backend/otodoaccessvcal.cpp \
@@ -15,5 +17,6 @@ HEADERS += \
backend/odatebookaccessbackend.h \
backend/odatebookaccessbackend_xml.h \
- backend/opimaccessbackend.h \
+ backend/opimaccessbackend.h \
+ backend/opimbackendoccurrence.h \
backend/otodoaccessbackend.h \
backend/otodoaccessvcal.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
@@ -63,7 +63,7 @@ using namespace Opie::Pim;
namespace Opie {
-
+
class OBackendPrivate;
-
+
/**
* This class is our factory. It will give us the default implementations
@@ -85,6 +85,6 @@ class OBackendPrivate;
{
public:
- OBackendFactory() {};
-
+ OBackendFactory() {};
+
/**
* Returns a selected backend implementation
@@ -97,14 +97,16 @@ class OBackendPrivate;
static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
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;
if ( use_database == OPimGlobal::DEFAULT ){
use_database = defaultDB( type );
}
-
+
switch ( type ){
case OPimGlobal::TODOLIST:
-
+
switch ( use_database ){
default: // Use SQL if something weird is given.
@@ -167,7 +169,7 @@ class OBackendPrivate;
return (T*) NULL;
}
-
+
}
-
+
/**
* Returns the style of the default database which is used to contact PIM data.
@@ -190,25 +192,25 @@ class OBackendPrivate;
group_name = "unknown";
}
-
+
Config config( "pimaccess" );
config.setGroup ( group_name );
QString db_String = config.readEntry( "usebackend", "xml" );
-
+
QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
dictDbTypes.setAutoDelete( TRUE );
-
+
dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
-
+
int* db_find = dictDbTypes[ db_String ];
-
+
if ( !db_find )
return OPimGlobal::UNKNOWN;
-
+
return (OPimGlobal::DatabaseStyle) *db_find;
}
-
-
+
+
/**
* Returns the default backend implementation for backendName. Which one is used, is defined
@@ -223,7 +225,7 @@ class OBackendPrivate;
private:
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
@@ -58,54 +58,48 @@ namespace Opie {
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
@@ -168,18 +168,4 @@ 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()
{
@@ -197,14 +183,5 @@ 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 )
{
@@ -321,5 +298,4 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
type |= VOICE;
- owarn << "value %s %d" << value.data() << type << oendl;
if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
c.setHomePhone( value );
@@ -526,5 +502,4 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
// Exporting Birthday regarding RFC 2425 (5.8.4)
if ( c.birthday().isValid() ){
- owarn << "Exporting birthday as: " << convDateToVCardDate( c.birthday() ) << "" << oendl;
safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) );
}
@@ -545,5 +520,4 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
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
@@ -60,10 +60,7 @@ class OPimContactAccessBackend_VCard : public OPimContactAccessBackend {
OPimContact find ( int uid ) const;
QArray<int> allRecords() const;
- QArray<int> queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() );
- QArray<int> matchRegexp( const QRegExp &r ) const;
const uint querySettings();
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
@@ -109,5 +109,4 @@ bool OPimContactAccessBackend_XML::save()
QListIterator<OPimContact> it( m_contactList );
for ( ; it.current(); ++it ) {
- // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl;
out += "<Contact ";
(*it)->save( out );
@@ -138,6 +137,4 @@ bool OPimContactAccessBackend_XML::save()
// because, I don't feel like using QDir.
if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
- owarn << "problem renaming file " << strNewFile << " to " << m_journalName
- << ", errno: " << errno << oendl;
// remove the tmp file...
QFile::remove( strNewFile );
@@ -214,7 +211,6 @@ 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() );
QListIterator<OPimContact> it( m_contactList );
@@ -279,11 +275,8 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
// the current/given date and the maximum date
// ( maximum time range ) !
- owarn << "Checking if " << checkDate->toString() << " is between " << current.toString()
- << " and " << queryDate->toString() << " ! " << oendl;
if ( current.daysTo( *queryDate ) >= 0 ){
if ( !( ( *checkDate >= current ) &&
( *checkDate <= *queryDate ) ) ){
allcorrect = false;
- owarn << " Nope!.." << oendl;
}
}
@@ -431,4 +424,5 @@ bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
}
+#if 0
// Currently only asc implemented..
QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
@@ -459,8 +453,9 @@ QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
}
+#endif
+
bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
{
- //owarn << "odefaultbackend: ACTION::ADD" << oendl;
updateJournal (newcontact, ACTION_ADD);
addContact_p( newcontact );
@@ -486,6 +481,4 @@ bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
- owarn << "Nur zur Sicherheit: " << contact.uid() << " == " << newCont->uid() << " ?" << oendl;
-
return true;
} else
@@ -592,6 +585,4 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
dict.insert( "actionrow", new int(JOURNALROW) );
- //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl;
-
XMLElement *root = XMLElement::load( filename );
if(root != 0l ){ // start parsing
@@ -600,5 +591,4 @@ 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;
@@ -606,6 +596,4 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
while( element && !isJournal ){
if( element->tagName() != QString::fromLatin1("Contacts") ){
- //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: "
- // << element->tagName() << oendl;
element = element->nextChild();
} else {
@@ -617,6 +605,4 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
while( element ){
if( element->tagName() != QString::fromLatin1("Contact") ){
- //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: "
- // << element->tagName() << oendl;
element = element->nextChild();
continue;
@@ -625,6 +611,4 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
* attributes contained
*/
- //owarn << "OPimContactDefBack::load element tagName() : "
- // << element->tagName() << oendl;
QString dummy;
foundAction = false;
@@ -635,10 +619,7 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
customMap.clear();
for( it = aMap.begin(); it != aMap.end(); ++it ){
- // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl;
-
int *find = dict[ it.key() ];
/* Unknown attributes will be stored as "Custom" elements */
if ( !find ) {
- // owarn << "Attribute " << it.key() << " not known." << oendl;
//contact.setCustomField(it.key(), it.data());
customMap.insert( it.key(), it.data() );
@@ -705,8 +686,6 @@ 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
@@ -63,6 +63,5 @@ class OPimContactAccessBackend_XML : public OPimContactAccessBackend {
OPimContact find ( int uid ) const;
- 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;
@@ -71,6 +70,4 @@ class OPimContactAccessBackend_XML : public OPimContactAccessBackend {
bool hasQuerySettings (uint querySettings) const;
- // 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
@@ -37,116 +37,48 @@ using namespace Opie;
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 );
}
}
}
+}
namespace Opie {
@@ -160,57 +92,73 @@ 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();
events( tmpList, list, from, to );
- qHeapSort( tmpList );
return tmpList;
}
-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 );
}
return tmpList;
}
-
}
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
@@ -43,6 +43,4 @@ namespace Opie {
class ODateBookAccessBackend : public OPimAccessBackend<OPimEvent> {
public:
- typedef int UID;
-
/**
* c'tor without parameter
@@ -53,15 +51,8 @@ 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
* @return list of repeating events
*/
- virtual QArray<UID> rawRepeats()const = 0;
+ virtual UIDArray rawRepeats()const = 0;
/**
@@ -70,5 +61,5 @@ public:
* @return list of nonrepeating events
*/
- virtual QArray<UID> nonRepeats() const = 0;
+ virtual UIDArray nonRepeats() const = 0;
/**
@@ -77,10 +68,10 @@ public:
* This method can return empty lists if effectiveEvents is implememted
*/
- virtual OPimEvent::ValueList directNonRepeats() = 0;
+ virtual OPimEvent::ValueList directNonRepeats()const = 0;
/**
* Same as above but return raw repeats!
*/
- virtual OPimEvent::ValueList directRawRepeats() = 0;
+ virtual OPimEvent::ValueList directRawRepeats()const = 0;
/* is implemented by default but you can reimplement it*/
@@ -90,25 +81,27 @@ public:
* yourself
*/
- virtual OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to );
+ virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const;
/**
* 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:
class 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
@@ -168,6 +168,4 @@ bool ODateBookAccessBackend_SQL::load()
qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
- owarn << "command: " << qu << "" << oendl;
-
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
@@ -289,5 +287,4 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
+ "');";
}
- owarn << "add " << qu << "" << oendl;
OSQLRawQuery raw( qu );
@@ -329,8 +326,4 @@ bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
}
-QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
-{
- return allRecords();
-}
QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
@@ -360,5 +353,5 @@ QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
}
-OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
+OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const
{
QArray<int> nonRepUids = nonRepeats();
@@ -372,5 +365,5 @@ OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
}
-OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
+OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const
{
QArray<int> rawRepUids = rawRepeats();
@@ -411,5 +404,4 @@ QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
{
- owarn << "extractUids" << oendl;
QTime t;
t.start();
@@ -417,5 +409,4 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
- owarn << " count = " << list.count() << "" << oendl;
int i = 0;
@@ -424,5 +415,4 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
i++;
}
- owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
return ints;
@@ -441,5 +431,4 @@ 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;
return 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
@@ -67,10 +67,9 @@ public:
bool replace( const OPimEvent& ev );
- QArray<UID> rawEvents()const;
QArray<UID> rawRepeats()const;
QArray<UID> nonRepeats()const;
- OPimEvent::ValueList directNonRepeats();
- OPimEvent::ValueList directRawRepeats();
+ OPimEvent::ValueList directNonRepeats()const;
+ OPimEvent::ValueList directRawRepeats()const;
private:
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
@@ -123,5 +123,4 @@ namespace {
// FIXME: Use OPimEvent::toMap() here !! (eilers)
static void save( const OPimEvent& ev, QString& buf ) {
- owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl;
buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
if (!ev.location().isEmpty() )
@@ -327,7 +326,5 @@ bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) {
return add( ev );
}
-QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
- return allRecords();
-}
+
QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
QArray<int> ints( m_rep.count() );
@@ -354,5 +351,5 @@ QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
return ints;
}
-OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
+OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats()const {
OPimEvent::ValueList list;
QMap<int, OPimEvent>::ConstIterator it;
@@ -362,5 +359,5 @@ OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
return list;
}
-OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() {
+OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats()const {
OPimEvent::ValueList list;
QMap<int, OPimEvent>::ConstIterator it;
@@ -540,5 +537,4 @@ 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 );
}
@@ -551,5 +547,4 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
}
void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) {
-// owarn << " setting " << value << "" << oendl;
switch( id ) {
case FDescription:
@@ -635,5 +630,4 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
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
@@ -64,6 +64,6 @@ public:
QArray<UID> nonRepeats()const;
- OPimEvent::ValueList directNonRepeats();
- OPimEvent::ValueList directRawRepeats();
+ OPimEvent::ValueList directNonRepeats()const;
+ OPimEvent::ValueList directRawRepeats()const;
private:
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
@@ -35,15 +35,18 @@
#include <opie2/opimtemplatebase.h>
#include <opie2/opimrecord.h>
-
+#include <opie2/opimbackendoccurrence.h>
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.
*/
template <class T = OPimRecord>
@@ -52,73 +55,44 @@ public:
typedef OTemplateBase<T> Frontend;
- /** 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 );
@@ -128,14 +102,10 @@ public:
void setReadAhead( uint count );
protected:
+ //@{
int access()const;
-
void cache( const T& t )const;
-
- /**
- * use a prime number here!
- */
void setSaneCacheSize( int );
-
uint readAhead()const;
+ //@}
private:
@@ -157,4 +127,62 @@ 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>
void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
@@ -167,5 +195,4 @@ void OPimAccessBackend<T>::cache( const T& t )const {
}
-
template <class T>
void OPimAccessBackend<T>::setSaneCacheSize( int size) {
@@ -194,3 +221,203 @@ 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
@@ -29,4 +29,8 @@
#include <opie2/otodoaccessbackend.h>
+#include <opie2/private/opimtodosortvector.h>
+#include <opie2/otodoaccess.h>
+
+#include <qintdict.h>
namespace Opie {
@@ -39,3 +43,113 @@ 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
@@ -40,13 +40,21 @@ public:
OPimTodoAccessBackend();
~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:
class Private;
@@ -54,6 +62,18 @@ 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
@@ -456,5 +456,4 @@ OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
FindQuery query( uid );
return parseResultAndCache( uid, m_driver->query(&query) );
-
}
@@ -466,18 +465,16 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
QArray<int> search( CACHE );
uint size =0;
- OPimTodo to;
// we try to cache CACHE items
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];
size++;
}
break;
- /* reverse */
- case Frontend::Reverse:
+ /* reverse */
+ case Frontend::Reverse:
for (uint i = cur; i != 0 && size < CACHE; i-- ) {
search[size] = ints[i];
@@ -491,5 +488,5 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
OSQLResult res = m_driver->query( &query );
if ( res.state() != OSQLResult::Success )
- return to;
+ return OPimTodo();
return parseResultAndCache( uid, res );
@@ -508,4 +505,5 @@ bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
if ( res.state() == OSQLResult::Failure )
return false;
+
int c = m_uids.count();
m_uids.resize( c+1 );
@@ -535,5 +533,5 @@ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
return b;
}
-QArray<int> OPimTodoAccessBackendSQL::overDue() {
+QArray<int> OPimTodoAccessBackendSQL::overDue()const {
OverDueQuery qu;
return uids( m_driver->query(&qu ) );
@@ -541,8 +539,10 @@ QArray<int> OPimTodoAccessBackendSQL::overDue() {
QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
const QDate& t,
- bool u) {
+ bool u)const {
EffQuery ef(s, t, u );
return uids (m_driver->query(&ef) );
}
+
+#if 0
/*
*
@@ -561,5 +561,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
*/
/* Category */
- if ( sortFilter & 1 ) {
+ if ( sortFilter & OPimTodoAccess::FilterCategory ) {
QString str;
if (cat != 0 ) str = QString::number( cat );
@@ -567,5 +567,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
}
/* Show only overdue */
- if ( sortFilter & 2 ) {
+ if ( sortFilter & OPimTodoAccess::OnlyOverDue ) {
QDate date = QDate::currentDate();
QString due;
@@ -578,5 +578,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
}
/* not show completed */
- if ( sortFilter & 4 ) {
+ if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
query += " completed = 0 AND";
}else{
@@ -594,22 +594,21 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
switch( 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";
break;
}
- if ( !asc ) {
- odebug << "not ascending!" << oendl;
+ if ( !asc )
query += " DESC";
- }
+
odebug << query << oendl;
@@ -617,4 +616,7 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
return uids( m_driver->query(&raw) );
}
+#endif
+
+
bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
if ( str == "0-0-0" )
@@ -630,4 +632,6 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
}
}
+
+
OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
if ( res.state() == OSQLResult::Failure ) {
@@ -640,12 +644,8 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul
OSQLResultItem::ValueList list = res.results();
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 );
if ( newTodo.uid() == uid )
@@ -654,6 +654,5 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul
return retTodo;
}
-OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
- odebug << "todo(ResultItem)" << oendl;
+OPimTodo OPimTodoAccessBackendSQL::parse( OSQLResultItem& item )const {
// Request information from addressbook table and create the OPimTodo-object.
@@ -663,6 +662,4 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
QStringList cats = QStringList::split(";", item.data("categories") );
- odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
-
OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
cats, item.data("summary"), item.data("description"),
@@ -718,34 +715,6 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
return parseResultAndCache( uid, m_driver->query(&find) );
}
-/*
- * 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
-}
/*
* need to be const so let's fool the
@@ -766,5 +735,4 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
- odebug << " count = " << list.count() << "" << oendl;
int i = 0;
@@ -778,13 +746,7 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
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";
qu += " rlike(\""+ r.pattern() + "\",\"summary\")";
@@ -792,31 +754,8 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
qu += ")";
- odebug << "query: " << qu << "" << oendl;
-
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
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;
}
@@ -832,6 +771,4 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
QArray<int> completed_uids = uids( res );
- odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
-
if ( completed_uids.size() == 0 )
return;
@@ -840,5 +777,5 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
QString query;
- for ( int i = 0; i < completed_uids.size(); i++ ){
+ for ( uint i = 0; i < completed_uids.size(); i++ ){
if ( !query.isEmpty() )
query += " OR ";
@@ -851,5 +788,5 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
query = "";
- for ( int i = 0; i < completed_uids.size(); i++ ){
+ for ( uint i = 0; i < completed_uids.size(); i++ ){
if ( !query.isEmpty() )
query += " OR ";
@@ -858,11 +795,10 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
qu += query + " );";
- 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;
- }
+
}
@@ -877,13 +813,12 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
if ( res_custom.state() == OSQLResult::Failure ) {
owarn << "OSQLResult::Failure in find query !!" << oendl;
- QMap<QString, QString> empty;
- return empty;
+ return QMap<QString, QString>();
}
OSQLResultItem::ValueList list = res_custom.results();
OSQLResultItem::ValueList::Iterator it = list.begin();
- for ( ; it != list.end(); ++it ) {
+ for ( ; it != list.end(); ++it )
customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
- }
+
return customMap;
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
@@ -52,38 +52,33 @@ public:
bool reload();
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();
-
+
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;
// QAsciiDict<int> m_dict;
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
@@ -93,5 +93,4 @@ namespace {
if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
name = vObjectStringZValue( ob );
- owarn << "Categories:" << name.data() << "" << oendl;
}
@@ -234,8 +233,5 @@ OPimTodo OPimTodoAccessVCal::find(int uid )const {
return m_map[uid];
}
-QArray<int> OPimTodoAccessVCal::sorted( bool, int, int, int ) {
- QArray<int> ar(0);
- return ar;
-}
+
QArray<int> OPimTodoAccessVCal::allRecords()const {
QArray<int> ar( m_map.count() );
@@ -248,40 +244,14 @@ QArray<int> OPimTodoAccessVCal::allRecords()const {
return ar;
}
-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);
return ar;
}
-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
@@ -44,12 +44,8 @@ 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;
void clear();
@@ -59,8 +55,6 @@ public:
void removeAllCompleted();
- virtual QBitArray supports()const;
private:
- static QBitArray sup();
bool m_dirty : 1;
QString m_file;
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
@@ -35,6 +35,9 @@
#include <opie2/opimrecurrence.h>
#include <opie2/otodoaccessxml.h>
+#include <opie2/otodoaccess.h>
#include <opie2/odebug.h>
+#include <opie2/private/opimtodosortvector.h>
+
#include <qpe/global.h>
#include <qpe/stringutil.h>
@@ -143,5 +146,4 @@ bool OPimTodoAccessXML::load() {
dict.insert("Alarms", new int(OPimTodo::Alarms) );
dict.insert("Reminders", new int(OPimTodo::Reminders) );
- dict.insert("Notifiers", new int(OPimTodo::Notifiers) );
dict.insert("Maintainer", new int(OPimTodo::Maintainer) );
dict.insert("rtype", new int(FRType) );
@@ -183,5 +185,4 @@ bool OPimTodoAccessXML::load() {
i = point -dt;
i+= strLen;
- owarn << "Found a start at " << i << " " << (point-dt) << "" << oendl;
OPimTodo ev;
@@ -239,5 +240,4 @@ bool OPimTodoAccessXML::load() {
* now add it
*/
- owarn << "End at " << i << "" << oendl;
if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
ev.setUid( 1 );
@@ -262,5 +262,4 @@ bool OPimTodoAccessXML::load() {
munmap(map_addr, attribut.st_size );
- owarn << "counts " << m_events.count() << " records loaded!" << oendl;
return true;
}
@@ -270,7 +269,5 @@ bool OPimTodoAccessXML::reload() {
}
bool OPimTodoAccessXML::save() {
-// owarn << "saving" << oendl;
if (!m_opened || !m_changed ) {
-// owarn << "not saving" << oendl;
return true;
}
@@ -313,5 +310,4 @@ bool OPimTodoAccessXML::save() {
if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
-// owarn << "error renaming" << oendl;
QFile::remove( strNewFile );
}
@@ -325,8 +321,8 @@ QArray<int> OPimTodoAccessXML::allRecords()const {
int i = 0;
- 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;
}
@@ -351,5 +347,4 @@ void OPimTodoAccessXML::clear() {
}
bool OPimTodoAccessXML::add( const OPimTodo& todo ) {
-// owarn << "add" << oendl;
m_changed = true;
m_events.insert( todo.uid(), todo );
@@ -371,19 +366,15 @@ bool OPimTodoAccessXML::replace( const OPimTodo& todo) {
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;
int i = 0;
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();
}
}
@@ -391,9 +382,9 @@ QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
return ids;
}
-QArray<int> OPimTodoAccessXML::overDue() {
+QArray<int> OPimTodoAccessXML::overDue()const {
QArray<int> ids( m_events.count() );
int i = 0;
- QMap<int, OPimTodo>::Iterator it;
+ QMap<int, OPimTodo>::ConstIterator it;
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
if ( it.data().isOverdue() ) {
@@ -410,5 +401,4 @@ QArray<int> OPimTodoAccessXML::overDue() {
void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
const QCString& attr, const QString& val) {
-// owarn << "parse to do from XMLElement" << oendl;
int *find=0;
@@ -416,5 +406,4 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
find = (*dict)[ attr.data() ];
if (!find ) {
-// owarn << "Unknown option" + it.key() << oendl;
ev.setCustomField( attr, val );
return;
@@ -469,6 +458,4 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) {
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() );
manager.add( al );
@@ -543,9 +530,7 @@ namespace {
QString customToXml(const QMap<QString, QString>& customMap )
{
- //owarn << QString("writing custom %1").arg(customMap.count()) << oendl;
QString buf(" ");
for ( QMap<QString, QString>::ConstIterator cit = customMap.begin();
cit != customMap.end(); ++cit) {
-// owarn << ".ITEM." << oendl;
buf += cit.key();
buf += "=\"";
@@ -576,5 +561,4 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
}
-// owarn << "Uid " << ev.uid() << "" << oendl;
str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
@@ -623,5 +607,4 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
}
// now write the list
- owarn << "als: " << als.join("____________") << "" << oendl;
str += "Alarms=\""+als.join(";") +"\" ";
}
@@ -649,227 +632,64 @@ 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 );
/* sort it now */
vector.sort();
/* 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() {
QMap<int, OPimTodo> events = m_events;
@@ -880,34 +700,20 @@ void OPimTodoAccessXML::removeAllCompleted() {
m_events = events;
}
-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();
}
// 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
@@ -64,11 +64,11 @@ public:
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 );
- 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& );
QString toString( const OPimTodo& )const;
@@ -82,5 +82,4 @@ private:
OPimTodoAccessXMLPrivate* d;
int m_year, m_month, m_day;
-
};