25 files changed, 1218 insertions, 819 deletions
diff --git a/libopie2/opiepim/backend/backends.pro b/libopie2/opiepim/backend/backends.pro index 42d807c..739f74e 100644 --- a/libopie2/opiepim/backend/backends.pro +++ b/libopie2/opiepim/backend/backends.pro @@ -1,9 +1,11 @@ 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 @@ -13,9 +15,10 @@ HEADERS += \ backend/ocontactaccessbackend_vcard.h \ backend/ocontactaccessbackend_xml.h \ backend/odatebookaccessbackend.h \ backend/odatebookaccessbackend_xml.h \ - backend/opimaccessbackend.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 @@ -61,11 +61,11 @@ using namespace Opie; using namespace Opie::Pim; namespace Opie { - + class OBackendPrivate; - + /** * This class is our factory. It will give us the default implementations * of at least Todolist, Contacts and Datebook. In the future this class will * allow users to switch the backend with ( XML->SQLite ) without the need @@ -83,10 +83,10 @@ class OBackendPrivate; template<class T> class OBackendFactory { public: - OBackendFactory() {}; - + OBackendFactory() {}; + /** * Returns a selected backend implementation * @param type the type of the backend * @param database the type of the used database @@ -95,18 +95,20 @@ class OBackendPrivate; * @see OPimGlobal() */ static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, const QString& appName, const QString& filename = QString::null ){ - owarn << "Selected backend for " << type << " is: " << database << oendl; - // If we should use the dafult database style, we have to request it + owarn << "Selected backend for " << type << " is: " << +database << oendl; + + // If we should use the dafult database style, we have to request it OPimGlobal::DatabaseStyle use_database = database; if ( use_database == OPimGlobal::DEFAULT ){ use_database = defaultDB( type ); } - + switch ( type ){ case OPimGlobal::TODOLIST: - + switch ( use_database ){ default: // Use SQL if something weird is given. // Fall through !! case OPimGlobal::SQL: @@ -165,11 +167,11 @@ class OBackendPrivate; } default: return (T*) NULL; } - + } - + /** * Returns the style of the default database which is used to contact PIM data. * @param type the type of the backend * @see OPimGlobal() @@ -188,29 +190,29 @@ class OBackendPrivate; break; default: group_name = "unknown"; } - + Config config( "pimaccess" ); config.setGroup ( group_name ); QString db_String = config.readEntry( "usebackend", "xml" ); - + QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); dictDbTypes.setAutoDelete( TRUE ); - + dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); - + int* db_find = dictDbTypes[ db_String ]; - + if ( !db_find ) return OPimGlobal::UNKNOWN; - + return (OPimGlobal::DatabaseStyle) *db_find; } - - + + /** * Returns the default backend implementation for backendName. Which one is used, is defined * by the configfile "pimaccess.conf". * @param type The type of the backend (@see OPimGlobal()) @@ -221,10 +223,10 @@ class OBackendPrivate; return create( type, OPimGlobal::DEFAULT, appName ); } private: OBackendPrivate* d; - + }; - + } #endif 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 @@ -56,58 +56,52 @@ namespace Opie { * @see OPimContactAccessBackend_XML */ class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> { public: - /** - * @todo make non line in regard to BC guide of KDE - */ - OPimContactAccessBackend() {} - /** - * @todo make non inline in regard to the BC guide of KDE - */ - virtual ~OPimContactAccessBackend() {} + OPimContactAccessBackend(); - /** - * Return if database was changed externally. - * This may just make sense on file based databases like a XML-File. - * It is used to prevent to overwrite the current database content - * if the file was already changed by something else ! - * If this happens, we have to reload before save our data. - * If we use real databases, this should be handled by the database - * management system themselve, therefore this function should always return false in - * this case. It is not our problem to handle this conflict ... - * @return <i>true</i> if the database was changed and if save without reload will - * be dangerous. <i>false</i> if the database was not changed or it is save to write - * in this situation. - */ - virtual bool wasChangedExternally() = 0; + /** + * Return if database was changed externally. + * This may just make sense on file based databases like a XML-File. + * It is used to prevent to overwrite the current database content + * if the file was already changed by something else ! + * If this happens, we have to reload before save our data. + * If we use real databases, this should be handled by the database + * management system themselve, therefore this function should always return false in + * this case. It is not our problem to handle this conflict ... + * @return <i>true</i> if the database was changed and if save without reload will + * be dangerous. <i>false</i> if the database was not changed or it is save to write + * in this situation. + */ + virtual bool wasChangedExternally() = 0; - virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; + /** + * Return all possible settings. + * @return All settings provided by the current backend + * (i.e.: query_WildCards & query_IgnoreCase) + */ + virtual const uint querySettings() = 0; - /** - * Return all possible settings. - * @return All settings provided by the current backend - * (i.e.: query_WildCards & query_IgnoreCase) - */ - virtual const uint querySettings() = 0; + /** + * Check whether settings are correct. + * @return <i>true</i> if the given settings are correct and possible. + */ + virtual bool hasQuerySettings (uint querySettings) const = 0; + + /** + * Slow and inefficent default implementation + */ +//@{ + UIDArray queryByExample( const OPimContact&, int settings, const QDateTime& d = QDateTime() )const; + UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; + OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; +//@} - /** - * Check whether settings are correct. - * @return <i>true</i> if the given settings are correct and possible. - */ - virtual bool hasQuerySettings (uint querySettings) const = 0; - /** - * FIXME!!! - * Returns a sorted list of records either ascendinf or descending for a giving criteria and category - */ - virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; - - private: - class Private; - Private *d; + class Private; + Private *d; }; } diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index af77a05..43e530a 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp @@ -166,22 +166,8 @@ 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 } @@ -195,18 +181,9 @@ 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; @@ -319,9 +296,8 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) type |= HOME; 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) ) c.setHomeFax( value ); @@ -524,9 +500,8 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) safeAddPropValue( vcard, VCNoteProp, c.notes() ); // 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() ) ); } if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { @@ -543,9 +518,8 @@ 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() ); safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 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 @@ -58,14 +58,11 @@ class OPimContactAccessBackend_VCard : public OPimContactAccessBackend { bool replace ( const OPimContact& contact ); 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: OPimContact parseVObject( VObject* obj ); 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 @@ -107,9 +107,8 @@ 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"; cstr = out.utf8(); @@ -136,10 +135,8 @@ 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 ); } @@ -212,11 +209,10 @@ OPimContact OPimContactAccessBackend_XML::find ( int uid ) const return ( foundContact ); } 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; @@ -277,15 +273,12 @@ 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; } } } } else{ @@ -429,8 +422,9 @@ bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const return ( false ); } } +#if 0 // Currently only asc implemented.. QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) { QMap<QString, int> nameToUid; @@ -457,12 +451,13 @@ 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 ); m_changed = true; @@ -484,10 +479,8 @@ bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact ) m_contactList.append ( newCont ); 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; } @@ -590,24 +583,19 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal dict.insert( "Notes", new int(Qtopia::Notes) ); 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(); break; @@ -615,32 +603,25 @@ 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; XMLElement::AttributeMap aMap = element->attributes(); XMLElement::AttributeMap::Iterator it; 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; } @@ -703,12 +684,10 @@ bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal /* Move to next element */ 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 @@ -61,18 +61,15 @@ class OPimContactAccessBackend_XML : public OPimContactAccessBackend { QArray<int> allRecords() const; 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 @@ -35,120 +35,52 @@ using namespace Opie; namespace { /* a small helper to get all NonRepeating events for a range of time */ - void events( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& events, - const QDate& from, const QDate& to ) { - QDateTime dtStart, dtEnd; - - for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { - dtStart = (*it).startDateTime(); - dtEnd = (*it).endDateTime(); - - /* - * If in range - */ - if (dtStart.date() >= from && dtEnd.date() <= to ) { - OEffectiveEvent eff; - eff.setEvent( (*it) ); - eff.setDate( dtStart.date() ); - eff.setStartTime( dtStart.time() ); - - /* if not on the same day */ - if ( dtStart.date() != dtEnd.date() ) - eff.setEndTime( QTime(23, 59, 0 ) ); - else - eff.setEndTime( dtEnd.time() ); - - tmpList.append( eff ); - } - - /* we must also check for end date information... */ - if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) { - QDateTime dt = dtStart.addDays( 1 ); - dt.setTime( QTime(0, 0, 0 ) ); - QDateTime dtStop; - if ( dtEnd > to ) - dtStop = to; - else - dtStop = dtEnd; - - while ( dt <= dtStop ) { - OEffectiveEvent eff; - eff.setEvent( (*it) ); - eff.setDate( dt.date() ); - - if ( dt >= from ) { - eff.setStartTime( QTime(0, 0, 0 ) ); - if ( dt.date() == dtEnd.date() ) - eff.setEndTime( dtEnd.time() ); - else - eff.setEndTime( QTime(23, 59, 0 ) ); - tmpList.append( eff ); - } - dt = dt.addDays( 1 ); - } - } +void events( OPimBackendOccurrence::List& tmpList, + const OPimEvent::ValueList& events, + const QDate& from, const QDate& to ) { + QDateTime dtStart, dtEnd; + + for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { + dtStart = (*it).startDateTime(); + dtEnd = (*it).endDateTime(); + + /* + * If in range + */ + if (dtStart.date() >= from && dtEnd.date() <= to ) { + OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );; + tmpList.append( eff ); } } +} - void repeat( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& list, - const QDate& from, const QDate& to ) { - QDate repeat; - for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { - int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); - QDate itDate = from.addDays(-dur ); - OPimRecurrence rec = (*it).recurrence(); - if ( !rec.hasEndDate() || rec.endDate() > to ) { - rec.setEndDate( to ); - rec.setHasEndDate( true ); - } - while (rec.nextOcurrence(itDate, repeat ) ) { - if (repeat > to ) break; - OEffectiveEvent eff; - eff.setDate( repeat ); - if ( (*it).isAllDay() ) { - eff.setStartTime( QTime(0, 0, 0 ) ); - eff.setEndTime( QTime(23, 59, 59 ) ); - }else { - /* we only occur by days, not hours/minutes/seconds. Hence - * the actual end and start times will be the same for - * every repeated event. For multi day events this is - * fixed up later if on wronge day span - */ - eff.setStartTime( (*it).startDateTime().time() ); - eff.setEndTime( (*it).endDateTime().time() ); - } - if ( dur != 0 ) { - // multi-day repeating events - QDate sub_it = QMAX( repeat, from ); - QDate startDate = repeat; - QDate endDate = startDate.addDays( dur ); - - while ( sub_it <= endDate && sub_it <= to ) { - OEffectiveEvent tmpEff = eff; - tmpEff.setEvent( (*it) ); - if ( sub_it != startDate ) - tmpEff.setStartTime( QTime(0, 0, 0 ) ); - if ( sub_it != endDate ) - tmpEff.setEndTime( QTime( 23, 59, 59 ) ); - - tmpEff.setDate( sub_it ); - tmpEff.setEffectiveDates( startDate, endDate ); - tmpList.append( tmpEff ); - - sub_it = sub_it.addDays( 1 ); - } - itDate = endDate; - }else { - eff.setEvent( (*it) ); - tmpList.append( eff ); - itDate = repeat.addDays( 1 ); - } - } +void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list, + const QDate& from, const QDate& to ) { + QDate repeat; + for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { + int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); + QDate itDate = from.addDays(-dur ); + OPimRecurrence rec = (*it).recurrence(); + if ( !rec.hasEndDate() || rec.endDate() > to ) { + rec.setEndDate( to ); + rec.setHasEndDate( true ); + } + + QDateTime start, end; + while (rec.nextOcurrence(itDate, repeat ) ) { + if (repeat > to ) break; + + OPimEvent event = *it; + start = QDateTime( repeat, event.startDateTime().time() ); + end = QDateTime( repeat.addDays(dur), event.endDateTime().time() ); + OPimBackendOccurrence eff(start, end, event.uid() ); + tmpList.append( eff ); } } } +} namespace Opie { ODateBookAccessBackend::ODateBookAccessBackend() @@ -158,59 +90,75 @@ 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; - - OEffectiveEvent::ValueList tmpList; - QDateTime dtTmp; - for ( it = day.begin(); it != day.end(); ++it ) { - dtTmp = QDateTime( (*it).date(), (*it).startTime() ); - if ( QABS(dt.secsTo(dtTmp) ) < 60 ) - tmpList.append( (*it) ); - } +OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const { + OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() ); - return tmpList; + return filterOccurrences( day, dt ); } -OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, - const QDate& to ) { - OEffectiveEvent::ValueList tmpList; +OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, + const QDate& to )const { + OPimBackendOccurrence::List tmpList; OPimEvent::ValueList list = directNonRepeats(); events( tmpList, list, from, to ); - qHeapSort( tmpList ); return tmpList; } -OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { - OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); - OEffectiveEvent::ValueList::Iterator it; +OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const { + OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); + return filterOccurrences( day,dt ); +} + + +UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings, + const QDateTime& d )const { + return UIDArray(); +} + +UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const { + return UIDArray(); +} - OEffectiveEvent::ValueList tmpList; - QDateTime dtTmp; - for ( it = day.begin(); it != day.end(); ++it ) { - dtTmp = QDateTime( (*it).date(), (*it).startTime() ); - if ( QABS(dt.secsTo(dtTmp) ) < 60 ) - tmpList.append( (*it) ); +OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, + const QDateTime& dt ) { + OPimBackendOccurrence::List tmpList; + OPimBackendOccurrence::List::ConstIterator it; + + for ( it = dayList.begin(); it != dayList.end(); ++it ) { + OPimBackendOccurrence occ = *it; + + /* + * Let us find occurrences that are 'now'! + * If the dt.date() is on the same day as start or end of the Occurrence + * check how near start/end are. + * If it is in the middle of a multiday occurrence list it. + * + * We might want to 'lose' the sixty second offset and list + * all Events which are active at that time. + */ + if ( dt.date() == occ.startDateTime().date() ) { + if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 ) + tmpList.append( occ ); + }else if ( dt.date() == occ.endDateTime().date() ) { + if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 ) + tmpList.append( occ ); + }else if ( dt.date() >= occ.startDateTime().date() && + dt.date() >= occ.endDateTime().date() ) + tmpList.append( occ ); } return tmpList; } - } diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h index a9cce6a..8927ca1 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend.h @@ -41,76 +41,69 @@ namespace Opie { * */ class ODateBookAccessBackend : public OPimAccessBackend<OPimEvent> { public: - typedef int UID; - /** * c'tor without parameter */ ODateBookAccessBackend(); ~ODateBookAccessBackend(); /** * 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*/ /** * 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 */ - 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 @@ -166,10 +166,8 @@ bool ODateBookAccessBackend_SQL::load() qu += " );"; 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 ) return false; @@ -287,9 +285,8 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) + ",'" + it.data() //.latin1() + "');"; } - owarn << "add " << qu << "" << oendl; OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); if ( res.state() != OSQLResult::Success ){ @@ -327,12 +324,8 @@ bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) remove( ev.uid() ); return add( ev ); } -QArray<int> ODateBookAccessBackend_SQL::rawEvents()const -{ - return allRecords(); -} QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const { QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; @@ -358,9 +351,9 @@ 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; @@ -370,9 +363,9 @@ 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; @@ -409,22 +402,19 @@ QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const /* ===== Private Functions ========================================== */ 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; } @@ -439,9 +429,8 @@ QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) cons FindCustomQuery query( uid ); 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 @@ -65,14 +65,13 @@ public: bool add( const OPimEvent& ev ); 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(); QString m_fileName; 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 @@ -121,9 +121,8 @@ 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() ) + "\""; @@ -325,11 +324,9 @@ bool ODateBookAccessBackend_XML::remove( int uid ) { 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; QMap<int, OPimEvent>::ConstIterator it; @@ -352,17 +349,17 @@ 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 ) list.append( it.data() ); 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 ) list.append( it.data() ); @@ -538,9 +535,8 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { OPimAlarm al( snd , dt ); ev.notifiers().add( al ); } if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { - owarn << "already contains assign uid" << oendl; ev.setUid( 1 ); } if ( ev.hasRecurrence() ) @@ -549,9 +545,8 @@ void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { m_raw.insert( ev.uid(), ev ); } void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { -// owarn << " setting " << value << "" << oendl; switch( id ) { case FDescription: e.setDescription( value ); break; @@ -633,9 +628,8 @@ void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& case FExceptions:{ 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 ); } } break; 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 @@ -62,10 +62,10 @@ public: 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 m_changed :1 ; bool m_noTimeZone : 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 @@ -33,111 +33,81 @@ #include <qdatetime.h> #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; + //@{ + virtual UIDArray allRecords()const = 0; + virtual UIDArray matchRegexp(const QRegExp &r) const; + virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const = 0; + virtual UIDArray queryByExample( const OPimRecord* rec, int, const QDateTime& d = QDateTime() )const; + virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const; + virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const; + virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const; + virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const; + //@} - /** - * queryByExample for T with the given Settings - * - */ - virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; - /** - * find the OPimRecord with uid @param uid - * returns T and T.isEmpty() if nothing was found - */ - virtual T find( int uid )const = 0; + //@{ + virtual T find(UID uid )const = 0; + virtual T find(UID uid, const QArray<UID>& items, + uint current, typename Frontend::CacheDirection )const ; + //@} - virtual T find( int uid, const QArray<int>& items, - uint current, typename Frontend::CacheDirection ) const; - /** - * clear the back end - */ - virtual void clear() = 0; - /** - * add T - */ + //@{ virtual bool add( const T& t ) = 0; + virtual bool remove( UID uid ) = 0; + virtual bool replace( const T& t ) = 0; + //@} - /** - * remove - */ - virtual bool remove( int uid ) = 0; - /** - * replace a record with T.uid() - */ - virtual bool replace( const T& t ) = 0; - /* - * setTheFrontEnd!!! - */ void setFrontend( Frontend* front ); /** * set the read ahead count */ 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; Frontend* m_front; @@ -155,8 +125,66 @@ OPimAccessBackend<T>::OPimAccessBackend(int acc) 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; } @@ -165,9 +193,8 @@ void OPimAccessBackend<T>::cache( const T& t )const { if ( m_front ) m_front->cache( t ); } - template <class T> void OPimAccessBackend<T>::setSaneCacheSize( int size) { if ( m_front ) m_front->setSaneCacheSize( size ); @@ -192,5 +219,205 @@ 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 @@ -27,8 +27,12 @@ Boston, MA 02111-1307, USA. */ #include <opie2/otodoaccessbackend.h> +#include <opie2/private/opimtodosortvector.h> +#include <opie2/otodoaccess.h> + +#include <qintdict.h> namespace Opie { OPimTodoAccessBackend::OPimTodoAccessBackend() : OPimAccessBackend<OPimTodo>() @@ -37,5 +41,115 @@ OPimTodoAccessBackend::OPimTodoAccessBackend() 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 @@ -38,22 +38,42 @@ namespace Opie { class OPimTodoAccessBackend : public OPimAccessBackend<OPimTodo> { public: OPimTodoAccessBackend(); ~OPimTodoAccessBackend(); - virtual QArray<int> effectiveToDos( const QDate& start, - const QDate& end, - bool includeNoDates ) = 0; - virtual QArray<int> overDue() = 0; - virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, - int cat ) = 0; - virtual void removeAllCompleted() = 0; - virtual QBitArray supports()const = 0; - + virtual UIDArray effectiveToDos( const QDate& start, + const QDate& end, + bool includeNoDates )const = 0; + virtual UIDArray overDue()const = 0; + virtual void removeAllCompleted() = 0; + + /** + * Common and probably inefficent implementation + * for queryByExample, matchRegexp, sorted + * and occurrences + */ + //@{ + UIDArray queryByExample( const OPimTodo&, int settings, const QDateTime& d = QDateTime() )const; + UIDArray sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const; + OPimBackendOccurrence::List occurrences( const QDate&, const QDate& )const; + //@} + private: class Private; 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 @@ -454,9 +454,8 @@ 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 ! OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, @@ -464,22 +463,20 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, uint CACHE = readAhead(); odebug << "searching for " << uid << "" << oendl; QArray<int> search( CACHE ); uint size =0; - OPimTodo to; // we try to cache CACHE items switch( dir ) { - /* forward */ + /* forward */ case Frontend::Forward: for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { - odebug << "size " << size << " " << ints[i] << "" << oendl; search[size] = ints[i]; size++; } break; - /* reverse */ - case Frontend::Reverse: + /* reverse */ + case Frontend::Reverse: for (uint i = cur; i != 0 && size < CACHE; i-- ) { search[size] = ints[i]; size++; } @@ -489,9 +486,9 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, search.resize( size ); FindQuery query( search ); OSQLResult res = m_driver->query( &query ); if ( res.state() != OSQLResult::Success ) - return to; + return OPimTodo(); return parseResultAndCache( uid, res ); } @@ -506,8 +503,9 @@ bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; + int c = m_uids.count(); m_uids.resize( c+1 ); m_uids[c] = t.uid(); @@ -533,18 +531,20 @@ bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { bool b= add(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 /* * */ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, @@ -559,15 +559,15 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, * FIXME: Replace magic numbers * */ /* 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; base = QString("DueDate <= '%1-%2-%3' AND completed = 0") @@ -576,9 +576,9 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); 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"; } @@ -592,31 +592,33 @@ 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; else{ @@ -628,8 +630,10 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ da.setYMD( year, month, day ); return true; } } + + OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{ if ( res.state() == OSQLResult::Failure ) { OPimTodo to; return to; @@ -638,33 +642,26 @@ OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResul OPimTodo retTodo; 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. bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 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, item.data("uid").toInt() ); @@ -716,38 +713,10 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 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 :( */ @@ -764,9 +733,8 @@ 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 ) { ints[i] = (*it).data("uid").toInt(); @@ -776,49 +744,20 @@ 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(){ // First we need the uids from all entries which are @@ -830,17 +769,15 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ OSQLResult res = m_driver->query( &raw ); 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] ); } @@ -849,22 +786,21 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ // Put remove of custom entries in this query to speed up.. 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; - } + } QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const @@ -875,17 +811,16 @@ QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const 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; + 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 @@ -50,42 +50,37 @@ 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 @@ -91,9 +91,8 @@ namespace { } // categories if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ name = vObjectStringZValue( ob ); - owarn << "Categories:" << name.data() << "" << oendl; } event.setUid( 1 ); return event; @@ -232,12 +231,9 @@ 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; int i = 0; @@ -246,44 +242,18 @@ QArray<int> OPimTodoAccessVCal::allRecords()const { i++; } 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 @@ -42,27 +42,21 @@ public: bool reload(); 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& ); bool remove( int uid ); 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 @@ -33,10 +33,13 @@ #include <opie2/opimtimezone.h> #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> @@ -141,9 +144,8 @@ bool OPimTodoAccessXML::load() { dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); 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) ); dict.insert("rposition", new int(FRPosition) ); @@ -181,9 +183,8 @@ bool OPimTodoAccessXML::load() { int strLen = strlen(collectionString); 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; @@ -237,9 +238,8 @@ 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; } @@ -260,19 +260,16 @@ bool OPimTodoAccessXML::load() { } munmap(map_addr, attribut.st_size ); - owarn << "counts " << m_events.count() << " records loaded!" << oendl; return true; } bool OPimTodoAccessXML::reload() { m_events.clear(); return load(); } bool OPimTodoAccessXML::save() { -// owarn << "saving" << oendl; if (!m_opened || !m_changed ) { -// owarn << "not saving" << oendl; return true; } QString strNewFile = m_file + ".new"; QFile f( strNewFile ); @@ -311,9 +308,8 @@ bool OPimTodoAccessXML::save() { /* flush before renaming */ f.close(); if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { -// owarn << "error renaming" << oendl; QFile::remove( strNewFile ); } m_changed = false; @@ -323,12 +319,12 @@ QArray<int> OPimTodoAccessXML::allRecords()const { QArray<int> ids( m_events.count() ); 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& ) { QArray<int> ids(0); @@ -349,9 +345,8 @@ void OPimTodoAccessXML::clear() { m_events.clear(); } bool OPimTodoAccessXML::add( const OPimTodo& todo ) { -// owarn << "add" << oendl; m_changed = true; m_events.insert( todo.uid(), todo ); return true; @@ -369,33 +364,29 @@ bool OPimTodoAccessXML::replace( const OPimTodo& todo) { return true; } 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(); i++; @@ -408,15 +399,13 @@ 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; } @@ -467,10 +456,8 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev, OPimNotifyManager &manager = ev.notifiers(); 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 ); } } @@ -541,13 +528,11 @@ void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev, // from PalmtopRecord... GPL ### FIXME 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()); buf += "\" "; @@ -574,9 +559,8 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const { str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; 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 /* FIXME Qtopia::Record this is currently not @@ -621,9 +605,8 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const { + ":"; } } // now write the list - owarn << "als: " << als.join("____________") << "" << oendl; str += "Alarms=\""+als.join(";") +"\" "; } /* @@ -647,268 +630,91 @@ QString OPimTodoAccessXML::toString( const OPimTodo& ev )const { 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; -}; +QArray<int> OPimTodoAccessXML::sorted( const UIDArray& events, bool asc, + int sortOrder,int sortFilter, + const QArray<int>& categories )const { + Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder ); + int item = 0; -namespace { - inline QString string( const OPimTodo& todo) { - return todo.summary().isEmpty() ? - todo.description().left(20 ) : - todo.summary(); - } - inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) { - int ret = 0; - if ( todo1.isCompleted() ) ret++; - if ( todo2.isCompleted() ) ret--; - return ret; - } - inline int priority( const OPimTodo& t1, const OPimTodo& t2) { - return ( t1.priority() - t2.priority() ); - } - inline int description( const OPimTodo& t1, const OPimTodo& t2) { - return QString::compare( string(t1), string(t2) ); - } - inline int deadline( const OPimTodo& t1, const OPimTodo& t2) { - int ret = 0; - if ( t1.hasDueDate() && - t2.hasDueDate() ) - ret = t2.dueDate().daysTo( t1.dueDate() ); - else if ( t1.hasDueDate() ) - ret = -1; - else if ( t2.hasDueDate() ) - ret = 1; - else - ret = 0; + bool bCat = sortFilter & OPimTodoAccess::FilterCategory ? true : false; + bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false; + bool comp = sortFilter & OPimTodoAccess::DoNotShowCompleted ? true : false; + bool catPassed = false; + int cat; - return ret; - } + for ( uint i = 0; i < events.count(); ++i ) { + /* Guard against creating a new item... */ + if ( !m_events.contains( events[i] ) ) + continue; -}; + OPimTodo todo = m_events[events[i]]; -/* - * Returns: - * 0 if item1 == item2 - * - * non-zero if item1 != item2 - * - * This function returns int rather than bool so that reimplementations - * can return one of three values and use it to sort by: - * - * 0 if item1 == item2 - * - * > 0 (positive integer) if item1 > item2 - * - * < 0 (negative integer) if item1 < item2 - * - */ -class OPimTodoXMLVector : public QVector<OPimTodoXMLContainer> { -public: - OPimTodoXMLVector(int size, bool asc, int sort) - : QVector<OPimTodoXMLContainer>( size ) - { - setAutoDelete( true ); - m_asc = asc; - m_sort = sort; - } - /* return the summary/description */ - QString string( const OPimTodo& todo) { - return todo.summary().isEmpty() ? - todo.description().left(20 ) : - todo.summary(); - } - /** - * we take the sortorder( switch on it ) - * - */ - int compareItems( Item d1, Item d2 ) { - bool seComp, sePrio, seDesc, seDeadline; - seComp = sePrio = seDeadline = seDesc = false; - int ret =0; - OPimTodoXMLContainer* con1 = (OPimTodoXMLContainer*)d1; - OPimTodoXMLContainer* con2 = (OPimTodoXMLContainer*)d2; - - /* same item */ - if ( con1->todo.uid() == con2->todo.uid() ) - return 0; - - switch ( m_sort ) { - /* completed */ - case 0: { - ret = completed( con1->todo, con2->todo ); - seComp = TRUE; - break; - } - /* priority */ - case 1: { - ret = priority( con1->todo, con2->todo ); - sePrio = TRUE; - break; - } - /* description */ - case 2: { - ret = description( con1->todo, con2->todo ); - seDesc = TRUE; - break; - } - /* deadline */ - case 3: { - ret = deadline( con1->todo, con2->todo ); - seDeadline = TRUE; + /* show category */ + /* -1 == unfiled */ + catPassed = false; + for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) { + cat = categories[cat_nu]; + if ( bCat && cat == -1 ) { + if(!todo.categories().isEmpty() ) + continue; + } else if ( bCat && cat != 0) + if (!todo.categories().contains( cat ) ) + continue; + catPassed = true; break; } - default: - ret = 0; - break; - }; - /* - * FIXME do better sorting if the first sort criteria - * ret equals 0 start with complete and so on... - */ - - /* twist it we're not ascending*/ - if (!m_asc) - ret = ret * -1; - if ( ret ) - return ret; - - // default did not gave difference let's try it other way around /* - * General try if already checked if not test - * and return - * 1.Completed - * 2.Priority - * 3.Description - * 4.DueDate + * If none of the Categories matched + * continue */ - if (!seComp ) { - if ( (ret = completed( con1->todo, con2->todo ) ) ) { - if (!m_asc ) ret *= -1; - return ret; - } - } - if (!sePrio ) { - if ( (ret = priority( con1->todo, con2->todo ) ) ) { - if (!m_asc ) ret *= -1; - return ret; - } - } - if (!seDesc ) { - if ( (ret = description(con1->todo, con2->todo ) ) ) { - if (!m_asc) ret *= -1; - return ret; - } - } - if (!seDeadline) { - if ( (ret = deadline( con1->todo, con2->todo ) ) ) { - if (!m_asc) ret *= -1; - return ret; - } - } - - return 0; - } - private: - bool m_asc; - int m_sort; - -}; - -QArray<int> OPimTodoAccessXML::sorted( bool asc, int sortOrder, - int sortFilter, int cat ) { - OPimTodoXMLVector vector(m_events.count(), asc,sortOrder ); - QMap<int, OPimTodo>::Iterator it; - int item = 0; - - bool bCat = sortFilter & 1 ? true : false; - bool bOnly = sortFilter & 2 ? true : false; - bool comp = sortFilter & 4 ? true : false; - for ( it = m_events.begin(); it != m_events.end(); ++it ) { - - /* show category */ - /* -1 == unfiled */ - if ( bCat && cat == -1 ) { - if(!(*it).categories().isEmpty() ) - continue; - }else if ( bCat && cat != 0) - if (!(*it).categories().contains( cat ) ) { - continue; - } - /* isOverdue but we should not show overdue - why?*/ -/* if ( (*it).isOverdue() && !bOnly ) { - owarn << "item is overdue but !bOnly" << oendl; + if ( !catPassed ) continue; - } -*/ - if ( !(*it).isOverdue() && bOnly ) { + if ( !todo.isOverdue() && bOnly ) continue; - } - - if ((*it).isCompleted() && comp ) { + if (todo.isCompleted() && comp ) continue; - } - - OPimTodoXMLContainer* con = new OPimTodoXMLContainer(); - con->todo = (*it); - vector.insert(item, con ); - item++; + vector.insert(item++, todo ); } + vector.resize( item ); /* sort it now */ vector.sort(); /* now get the uids */ - QArray<int> array( vector.count() ); - for (uint i= 0; i < vector.count(); i++ ) { - array[i] = ( vector.at(i) )->todo.uid(); - } + UIDArray array( vector.count() ); + for (uint i= 0; i < vector.count(); i++ ) + array[i] = vector.uidAt( i ); + return array; -}; +} + void OPimTodoAccessXML::removeAllCompleted() { QMap<int, OPimTodo> events = m_events; for ( QMap<int, OPimTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { if ( (*it).isCompleted() ) events.remove( it.key() ); } m_events = events; } -QBitArray OPimTodoAccessXML::supports()const { - static QBitArray ar = sup(); - return ar; -} -QBitArray OPimTodoAccessXML::sup() { - QBitArray ar( OPimTodo::CompletedDate +1 ); - ar.fill( true ); - ar[OPimTodo::CrossReference] = false; - ar[OPimTodo::State ] = false; - ar[OPimTodo::Reminders] = false; - ar[OPimTodo::Notifiers] = false; - ar[OPimTodo::Maintainer] = false; - - return ar; -} + QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const { - QArray<int> m_currentQuery( m_events.count() ); + QArray<int> currentQuery( m_events.count() ); uint arraycounter = 0; - QMap<int, OPimTodo>::ConstIterator it; - for (it = m_events.begin(); it != m_events.end(); ++it ) { + QMap<int, OPimTodo>::ConstIterator it; + for (it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().match( r ) ) - m_currentQuery[arraycounter++] = it.data().uid(); + currentQuery[arraycounter++] = it.data().uid(); } // Shrink to fit.. - m_currentQuery.resize(arraycounter); + currentQuery.resize(arraycounter); - return m_currentQuery; + return currentQuery; } } diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h index 3a51543..134a21a 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.h +++ b/libopie2/opiepim/backend/otodoaccessxml.h @@ -62,15 +62,15 @@ 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; QMap<int, OPimTodo> m_events; @@ -80,9 +80,8 @@ private: bool m_changed : 1; class OPimTodoAccessXMLPrivate; OPimTodoAccessXMLPrivate* d; int m_year, m_month, m_day; - }; }; |