summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/backends.pro3
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h4
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.cpp121
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h20
-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.cpp174
-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.h34
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp129
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h35
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp40
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.h10
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp306
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h13
25 files changed, 1129 insertions, 730 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,8 +1,10 @@
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 \
backend/otodoaccessxml.cpp
@@ -15,6 +17,7 @@ HEADERS += \
backend/odatebookaccessbackend.h \
backend/odatebookaccessbackend_xml.h \
backend/opimaccessbackend.h \
+ backend/opimbackendoccurrence.h \
backend/otodoaccessbackend.h \
backend/otodoaccessvcal.h \
backend/otodoaccessxml.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
@@ -96,7 +96,9 @@ 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;
+ 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 ){
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
@@ -57,14 +57,7 @@ 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();
/**
@@ -82,8 +75,6 @@ class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> {
*/
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
@@ -98,10 +89,13 @@ class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> {
virtual bool hasQuerySettings (uint querySettings) const = 0;
/**
- * FIXME!!!
- * Returns a sorted list of records either ascendinf or descending for a giving criteria and category
+ * Slow and inefficent default implementation
*/
- virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0;
+//@{
+ 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;
+//@}
private:
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
@@ -167,20 +167,6 @@ QArray<int> OPimContactAccessBackend_VCard::allRecords() const
return ar;
}
-// 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()
{
return 0; // No search possible
@@ -196,16 +182,7 @@ bool OPimContactAccessBackend_VCard::wasChangedExternally()
return false; // Don't expect concurrent access
}
-// 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 )
{
OPimContact c;
@@ -320,7 +297,6 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
type |= VOICE;
- owarn << "value %s %d" << value.data() << type << oendl;
if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
c.setHomePhone( value );
if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
@@ -525,7 +501,6 @@ 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() ) );
}
@@ -544,7 +519,6 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
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() ) );
}
safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
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
@@ -59,12 +59,9 @@ 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();
private:
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
@@ -108,7 +108,6 @@ bool OPimContactAccessBackend_XML::save()
// Write all contacts
QListIterator<OPimContact> it( m_contactList );
for ( ; it.current(); ++it ) {
- // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl;
out += "<Contact ";
(*it)->save( out );
out += "/>\n";
@@ -137,8 +136,6 @@ bool OPimContactAccessBackend_XML::save()
// move the file over, I'm just going to use the system call
// 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 );
}
@@ -213,9 +210,8 @@ 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 );
uint arraycounter = 0;
@@ -278,13 +274,10 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
// Check whether the birthday/anniversary date is between
// 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;
}
}
}
@@ -430,6 +423,7 @@ bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
}
}
+#if 0
// Currently only asc implemented..
QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
{
@@ -458,10 +452,11 @@ QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
return m_currentQuery;
}
+#endif
+
bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
{
- //owarn << "odefaultbackend: ACTION::ADD" << oendl;
updateJournal (newcontact, ACTION_ADD);
addContact_p( newcontact );
@@ -485,8 +480,6 @@ bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
m_uidToContact.remove( QString().setNum( contact.uid() ) );
m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
- owarn << "Nur zur Sicherheit: " << contact.uid() << " == " << newCont->uid() << " ?" << oendl;
-
return true;
} else
return false;
@@ -591,22 +584,17 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
dict.insert( "action", new int(JOURNALACTION) );
dict.insert( "actionrow", new int(JOURNALROW) );
- //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl;
-
XMLElement *root = XMLElement::load( filename );
if(root != 0l ){ // start parsing
/* Parse all XML-Elements and put the data into the
* Contact-Class
*/
XMLElement *element = root->firstChild();
- //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl;
element = element ? element->firstChild() : 0;
/* Search Tag "Contacts" which is the parent of all Contacts */
while( element && !isJournal ){
if( element->tagName() != QString::fromLatin1("Contacts") ){
- //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: "
- // << element->tagName() << oendl;
element = element->nextChild();
} else {
element = element->firstChild();
@@ -616,16 +604,12 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
/* Parse all Contacts and ignore unknown tags */
while( element ){
if( element->tagName() != QString::fromLatin1("Contact") ){
- //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: "
- // << element->tagName() << oendl;
element = element->nextChild();
continue;
}
/* Found alement with tagname "contact", now parse and store all
* attributes contained
*/
- //owarn << "OPimContactDefBack::load element tagName() : "
- // << element->tagName() << oendl;
QString dummy;
foundAction = false;
@@ -634,12 +618,9 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
contactMap.clear();
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() );
continue;
@@ -704,10 +685,8 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal
element = element->nextChild();
}
}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
@@ -62,16 +62,13 @@ 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;
const uint querySettings();
bool hasQuerySettings (uint querySettings) const;
- // Currently only asc implemented..
- QArray<int> sorted( bool asc, int , int , int );
bool add ( const OPimContact &newcontact );
bool replace ( const OPimContact &contact );
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
@@ -36,7 +36,8 @@ 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,
+void events( OPimBackendOccurrence::List& tmpList,
+ const OPimEvent::ValueList& events,
const QDate& from, const QDate& to ) {
QDateTime dtStart, dtEnd;
@@ -48,50 +49,13 @@ namespace {
* 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() );
-
+ OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );;
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 repeat( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& list,
+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 ) {
@@ -102,48 +66,16 @@ namespace {
rec.setEndDate( to );
rec.setHasEndDate( true );
}
+
+ QDateTime start, end;
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) );
+
+ 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 );
- itDate = repeat.addDays( 1 );
- }
}
}
}
@@ -159,58 +91,74 @@ ODateBookAccessBackend::ODateBookAccessBackend()
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;
+OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const {
+ OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() );
- 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) );
+ return filterOccurrences( day, dt );
}
- return tmpList;
-}
-
-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 );
+}
- 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) );
+
+UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings,
+ const QDateTime& d )const {
+ return UIDArray();
}
- return tmpList;
+UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const {
+ return UIDArray();
+}
+
+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
@@ -42,8 +42,6 @@ namespace Opie {
*/
class ODateBookAccessBackend : public OPimAccessBackend<OPimEvent> {
public:
- typedef int UID;
-
/**
* c'tor without parameter
*/
@@ -52,36 +50,29 @@ 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;
/**
* This mthod should return a list of UIDs containing all non
* repeating events. No filter should be applied
* @return list of nonrepeating events
*/
- virtual QArray<UID> nonRepeats() const = 0;
+ virtual UIDArray nonRepeats() const = 0;
/**
* If you do not want to implement the effectiveEvents methods below
* you need to supply it with directNonRepeats.
* 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*/
/**
@@ -89,27 +80,29 @@ public:
* EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method
* 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;
Private *d;
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
@@ -167,8 +167,6 @@ 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 );
if ( res.state() != OSQLResult::Success )
@@ -288,7 +286,6 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
+ it.data() //.latin1()
+ "');";
}
- owarn << "add " << qu << "" << oendl;
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
@@ -328,10 +325,6 @@ bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
return add( ev );
}
-QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
-{
- return allRecords();
-}
QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
{
@@ -359,7 +352,7 @@ QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
return extractUids( res );
}
-OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
+OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const
{
QArray<int> nonRepUids = nonRepeats();
OPimEvent::ValueList list;
@@ -371,7 +364,7 @@ OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
return list;
}
-OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
+OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const
{
QArray<int> rawRepUids = rawRepeats();
OPimEvent::ValueList list;
@@ -410,20 +403,17 @@ QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
{
- owarn << "extractUids" << oendl;
QTime t;
t.start();
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
- owarn << " count = " << list.count() << "" << oendl;
int i = 0;
for (it = list.begin(); it != list.end(); ++it ) {
ints[i] = (*it).data("uid").toInt();
i++;
}
- owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
return ints;
@@ -440,7 +430,6 @@ QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) cons
OSQLResult res_custom = m_driver->query( &query );
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
@@ -66,12 +66,11 @@ public:
bool remove( int uid );
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:
bool loadFile();
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
@@ -122,7 +122,6 @@ 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() )
buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\"";
@@ -326,9 +325,7 @@ bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) {
replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers)
return add( ev );
}
-QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
- return allRecords();
-}
+
QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
QArray<int> ints( m_rep.count() );
uint i = 0;
@@ -353,7 +350,7 @@ 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;
for (it = m_raw.begin(); it != m_raw.end(); ++it )
@@ -361,7 +358,7 @@ 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;
for (it = m_rep.begin(); it != m_rep.end(); ++it )
@@ -539,7 +536,6 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
ev.notifiers().add( al );
}
if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
- owarn << "already contains assign uid" << oendl;
ev.setUid( 1 );
}
@@ -550,7 +546,6 @@ 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:
e.setDescription( value );
@@ -634,7 +629,6 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString&
QStringList list = QStringList::split(' ', value );
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
@@ -63,8 +63,8 @@ public:
QArray<UID> rawRepeats()const;
QArray<UID> nonRepeats()const;
- OPimEvent::ValueList directNonRepeats();
- OPimEvent::ValueList directRawRepeats();
+ OPimEvent::ValueList directNonRepeats()const;
+ OPimEvent::ValueList directRawRepeats()const;
private:
bool m_changed :1 ;
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
@@ -34,92 +34,66 @@
#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>
class OPimAccessBackend {
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;
- /**
- * queryByExample for T with the given Settings
- *
- */
- virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 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;
+ //@}
- /**
- * 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( int uid, const QArray<int>& items,
+ //@{
+ virtual T find(UID uid )const = 0;
+ virtual T find(UID uid, const QArray<UID>& 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 );
/**
@@ -127,16 +101,12 @@ 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:
OPimAccessBackendPrivate *d;
@@ -156,6 +126,64 @@ template <class T>
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 ) {
m_front = fr;
@@ -166,7 +194,6 @@ void OPimAccessBackend<T>::cache( const T& t )const {
m_front->cache( t );
}
-
template <class T>
void OPimAccessBackend<T>::setSaneCacheSize( int size) {
if ( m_front )
@@ -193,4 +220,204 @@ 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
@@ -28,6 +28,10 @@
*/
#include <opie2/otodoaccessbackend.h>
+#include <opie2/private/opimtodosortvector.h>
+#include <opie2/otodoaccess.h>
+
+#include <qintdict.h>
namespace Opie {
OPimTodoAccessBackend::OPimTodoAccessBackend()
@@ -38,4 +42,114 @@ 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
@@ -39,21 +39,41 @@ class OPimTodoAccessBackend : public OPimAccessBackend<OPimTodo> {
public:
OPimTodoAccessBackend();
~OPimTodoAccessBackend();
- virtual QArray<int> effectiveToDos( const QDate& start,
+ virtual UIDArray 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;
+ bool includeNoDates )const = 0;
+ virtual UIDArray overDue()const = 0;
virtual void removeAllCompleted() = 0;
- virtual QBitArray supports()const = 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;
Private *d;
};
-
}
+
+/**
+ * \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
@@ -455,7 +455,6 @@ QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, con
OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
FindQuery query( uid );
return parseResultAndCache( uid, m_driver->query(&query) );
-
}
// Remember: uid is already in the list of uids, called ints !
@@ -465,14 +464,12 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
odebug << "searching for " << uid << "" << oendl;
QArray<int> search( CACHE );
uint size =0;
- OPimTodo to;
// we try to cache CACHE items
switch( dir ) {
/* 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++;
}
@@ -490,7 +487,7 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
FindQuery query( search );
OSQLResult res = m_driver->query( &query );
if ( res.state() != OSQLResult::Success )
- return to;
+ return OPimTodo();
return parseResultAndCache( uid, res );
}
@@ -507,6 +504,7 @@ bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
if ( res.state() == OSQLResult::Failure )
return false;
+
int c = m_uids.count();
m_uids.resize( c+1 );
m_uids[c] = t.uid();
@@ -534,16 +532,18 @@ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
m_dirty = false; // we changed some stuff but the UID stayed the same
return b;
}
-QArray<int> OPimTodoAccessBackendSQL::overDue() {
+QArray<int> OPimTodoAccessBackendSQL::overDue()const {
OverDueQuery qu;
return uids( m_driver->query(&qu ) );
}
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
/*
*
*/
@@ -560,13 +560,13 @@ 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 );
query += " categories like '%" +str+"%' AND";
}
/* Show only overdue */
- if ( sortFilter & 2 ) {
+ if ( sortFilter & OPimTodoAccess::OnlyOverDue ) {
QDate date = QDate::currentDate();
QString due;
QString base;
@@ -577,7 +577,7 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
query += " " + base + " AND";
}
/* not show completed */
- if ( sortFilter & 4 ) {
+ if ( sortFilter & OPimTodoAccess::DoNotShowCompleted ) {
query += " completed = 0 AND";
}else{
query += " ( completed = 1 OR completed = 0) AND";
@@ -593,29 +593,31 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
query += "ORDER BY ";
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;
OSQLRawQuery raw(query );
return uids( m_driver->query(&raw) );
}
+#endif
+
+
bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
if ( str == "0-0-0" )
return false;
@@ -629,6 +631,8 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
return true;
}
}
+
+
OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
if ( res.state() == OSQLResult::Failure ) {
OPimTodo to;
@@ -639,22 +643,17 @@ 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 )
retTodo = newTodo;
}
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.
@@ -662,8 +661,6 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
hasDueDate = date( dueDate, item.data("DueDate") );
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"),
item.data("progress").toUShort(), hasDueDate, dueDate,
@@ -717,36 +714,8 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
FindQuery find( uid );
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
* compiler :(
@@ -765,7 +734,6 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
- odebug << " count = " << list.count() << "" << oendl;
int i = 0;
for (it = list.begin(); it != list.end(); ++it ) {
@@ -777,47 +745,18 @@ 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\")";
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;
}
void OPimTodoAccessBackendSQL::removeAllCompleted(){
@@ -831,15 +770,13 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
QArray<int> completed_uids = uids( res );
- odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
-
if ( completed_uids.size() == 0 )
return;
qu = "DELETE FROM todolist WHERE (";
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 ";
query += QString( "uid = %1" ).arg( completed_uids[i] );
@@ -850,20 +787,19 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
qu += "DELETE FORM custom_data WHERE (";
query = "";
- for ( int i = 0; i < completed_uids.size(); i++ ){
+ for ( uint i = 0; i < completed_uids.size(); i++ ){
if ( !query.isEmpty() )
query += " OR ";
query += QString( "uid = %1" ).arg( completed_uids[i] );
}
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;
- }
+
}
@@ -876,15 +812,14 @@ 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
@@ -51,40 +51,35 @@ public:
bool load();
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
@@ -92,7 +92,6 @@ namespace {
// categories
if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
name = vObjectStringZValue( ob );
- owarn << "Categories:" << name.data() << "" << oendl;
}
event.setUid( 1 );
@@ -233,10 +232,7 @@ bool OPimTodoAccessVCal::replace( const OPimTodo& to ) {
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() );
QMap<int, OPimTodo>::ConstIterator it;
@@ -247,42 +243,16 @@ 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
@@ -43,14 +43,10 @@ public:
bool save();
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();
bool add( const OPimTodo& );
@@ -58,10 +54,8 @@ public:
bool replace( const OPimTodo& );
void removeAllCompleted();
- virtual QBitArray supports()const;
private:
- static QBitArray sup();
bool m_dirty : 1;
QString m_file;
QMap<int, OPimTodo> m_map;
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
@@ -34,8 +34,11 @@
#include <opie2/opimnotifymanager.h>
#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>
#include <qpe/timeconversion.h>
@@ -142,7 +145,6 @@ bool OPimTodoAccessXML::load() {
dict.insert("State", new int(OPimTodo::State) );
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) );
dict.insert("rweekdays", new int(FRWeekdays) );
@@ -182,7 +184,6 @@ bool OPimTodoAccessXML::load() {
while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) {
i = point -dt;
i+= strLen;
- owarn << "Found a start at " << i << " " << (point-dt) << "" << oendl;
OPimTodo ev;
m_year = m_month = m_day = 0;
@@ -238,7 +239,6 @@ bool OPimTodoAccessXML::load() {
/*
* now add it
*/
- owarn << "End at " << i << "" << oendl;
if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
ev.setUid( 1 );
m_changed = true;
@@ -261,7 +261,6 @@ bool OPimTodoAccessXML::load() {
munmap(map_addr, attribut.st_size );
- owarn << "counts " << m_events.count() << " records loaded!" << oendl;
return true;
}
bool OPimTodoAccessXML::reload() {
@@ -269,9 +268,7 @@ bool OPimTodoAccessXML::reload() {
return load();
}
bool OPimTodoAccessXML::save() {
-// owarn << "saving" << oendl;
if (!m_opened || !m_changed ) {
-// owarn << "not saving" << oendl;
return true;
}
QString strNewFile = m_file + ".new";
@@ -312,7 +309,6 @@ bool OPimTodoAccessXML::save() {
f.close();
if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
-// owarn << "error renaming" << oendl;
QFile::remove( strNewFile );
}
@@ -324,10 +320,10 @@ QArray<int> OPimTodoAccessXML::allRecords()const {
QMap<int, OPimTodo>::ConstIterator it;
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;
}
QArray<int> OPimTodoAccessXML::queryByExample( const OPimTodo&, int, const QDateTime& ) {
@@ -350,7 +346,6 @@ void OPimTodoAccessXML::clear() {
m_events.clear();
}
bool OPimTodoAccessXML::add( const OPimTodo& todo ) {
-// owarn << "add" << oendl;
m_changed = true;
m_events.insert( todo.uid(), todo );
@@ -370,31 +365,27 @@ 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();
}
}
ids.resize( i );
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() ) {
ids[i] = it.key();
@@ -409,13 +400,11 @@ QArray<int> OPimTodoAccessXML::overDue() {
/* private */
void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
const QCString& attr, const QString& val) {
-// owarn << "parse to do from XMLElement" << oendl;
int *find=0;
find = (*dict)[ attr.data() ];
if (!find ) {
-// owarn << "Unknown option" + it.key() << oendl;
ev.setCustomField( attr, val );
return;
}
@@ -468,8 +457,6 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
QStringList als = QStringList::split(";", val );
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 );
}
@@ -542,11 +529,9 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
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 += "=\"";
buf += Qtopia::escapeString(cit.data());
@@ -575,7 +560,6 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
}
-// owarn << "Uid " << ev.uid() << "" << oendl;
str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
// append the extra options
@@ -622,7 +606,6 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
}
}
// now write the list
- owarn << "als: " << als.join("____________") << "" << oendl;
str += "Alarms=\""+als.join(";") +"\" ";
}
@@ -648,229 +631,66 @@ QString OPimTodoAccessXML::toString( const QArray<int>& ints ) const {
return Qtopia::Record::idsToString( ints );
}
-/* internal class for sorting
- *
- * Inspired by todoxmlio.cpp from TT
- */
-
-struct OPimTodoXMLContainer {
- OPimTodo todo;
-};
-
-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;
-
- return ret;
- }
-
-};
-
-/*
- * 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;
- 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 (!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( const UIDArray& events, bool asc,
+ int sortOrder,int sortFilter,
+ const QArray<int>& categories )const {
+ 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;
-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;
+ for ( uint i = 0; i < events.count(); ++i ) {
+ /* Guard against creating a new item... */
+ if ( !m_events.contains( events[i] ) )
+ continue;
- 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 ) {
+ OPimTodo todo = m_events[events[i]];
/* 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(!(*it).categories().isEmpty() )
+ if(!todo.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 (!todo.categories().contains( cat ) )
continue;
+ catPassed = true;
+ break;
}
+
+ /*
+ * If none of the Categories matched
+ * continue
*/
- if ( !(*it).isOverdue() && bOnly ) {
+ if ( !catPassed )
continue;
- }
-
- if ((*it).isCompleted() && comp ) {
+ if ( !todo.isOverdue() && bOnly )
+ continue;
+ 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;
for ( QMap<int, OPimTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
@@ -879,36 +699,22 @@ 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 ) {
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
@@ -63,13 +63,13 @@ public:
/* our functions */
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;
QString toString( const QArray<int>& ints ) const;
@@ -81,7 +81,6 @@ private:
class OPimTodoAccessXMLPrivate;
OPimTodoAccessXMLPrivate* d;
int m_year, m_month, m_day;
-
};
};