author | eilers <eilers> | 2005-01-03 16:44:42 (UTC) |
---|---|---|
committer | eilers <eilers> | 2005-01-03 16:44:42 (UTC) |
commit | 310c7dce0c9043f66725bc79449fe958a12ad459 (patch) (side-by-side diff) | |
tree | 9d789c21b1fb88bdd8a1ad7470867b91c70276b2 | |
parent | 0b3bbec6703c021a188c865e822f536bfa3045fc (diff) | |
download | opie-310c7dce0c9043f66725bc79449fe958a12ad459.zip opie-310c7dce0c9043f66725bc79449fe958a12ad459.tar.gz opie-310c7dce0c9043f66725bc79449fe958a12ad459.tar.bz2 |
Fixing stupid API documentation error.
Moving hasQuerySettings() and querySettings up to OPimAccessTemplate to
be available for all frontends..
-rw-r--r-- | libopie2/opiepim/ChangeLog | 3 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessbackend.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessbackend.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 9 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 15 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 43 |
7 files changed, 40 insertions, 35 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog index 2007744..320b189 100644 --- a/libopie2/opiepim/ChangeLog +++ b/libopie2/opiepim/ChangeLog @@ -1,23 +1,26 @@ +2005-01-03 Stefan Eilers <stefan@eilers-online.net> + * Fixing bug in API documentation + * Moving hasQuerySettings() and querySettings() to OPimAccessTemplate to be available for all frontends 2004-12-28 Stefan Eilers <stefan@eilers-online.net> * Make improved query by example accessable via frontend * Some API documentation improvement * Cleanup of backend api.. * Fixing bug #1501 2004-11-23 Stefan Eilers <stefan@eilers-online.net> * Implement fast and full featured version of sorted() for addressbook * Implement generic queryByExample for all Addressboook backends. It allows incremental search. * Update of API Documentation 2004-11-18 Holger Freyther <freyther@handhelds.org> * Every Access can give a set of Occurrences for a period or a datetime * QueryByExample, Find, Sort can be generically accessed by OPimBase pointer interface * OPimBackendOccurrence gets split up to OPimOccurrences by OPimTemplateBase * Add safeCast to various OPimRecords * Kill memleak in OPimTodo * Add SortVector implementations for OPimTodo and OPimContact 2004-??-?? The Opie Team <opie@handhelds.org> * Implemented some important modifications to allow to use OPimRecords as it is, without have to cast them. This makes it possible to write applications which handling pim data in a generic manner (see opimconvertion tool) (eilers)
\ No newline at end of file diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 41b714e..629e4da 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp @@ -115,192 +115,193 @@ ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { } void ODateBookAccessBackend_SQL::initFields() { // This map contains the translation of the fieldtype id's to // the names of the table columns m_fieldMap.insert( OPimEvent::FUid, "uid" ); m_fieldMap.insert( OPimEvent::FCategories, "Categories" ); m_fieldMap.insert( OPimEvent::FDescription, "Description" ); m_fieldMap.insert( OPimEvent::FLocation, "Location" ); m_fieldMap.insert( OPimEvent::FType, "Type" ); m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" ); m_fieldMap.insert( OPimEvent::FSound, "Sound" ); m_fieldMap.insert( OPimEvent::FRType, "RType" ); m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" ); m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" ); m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" ); m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" ); m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" ); m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" ); m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" ); m_fieldMap.insert( OPimEvent::FStart, "Start" ); m_fieldMap.insert( OPimEvent::FEnd, "End" ); m_fieldMap.insert( OPimEvent::FNote, "Note" ); m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" ); m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" ); m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" ); // Create a map that maps the column name to the id QMapConstIterator<int, QString> it; for ( it = m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ m_reverseFieldMap.insert( it.data(), it.key() ); } } bool ODateBookAccessBackend_SQL::load() { if (!m_driver->open() ) return false; // Don't expect that the database exists. // It is save here to create the table, even if it // do exist. ( Is that correct for all databases ?? ) QString qu = "create table datebook( uid INTEGER PRIMARY KEY "; QMap<int, QString>::Iterator it; for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); } qu += " );"; qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); if ( res.state() != OSQLResult::Success ) return false; update(); return true; } void ODateBookAccessBackend_SQL::update() { QString qu = "select uid from datebook"; OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); if ( res.state() != OSQLResult::Success ){ // m_uids.clear(); return; } m_uids = extractUids( res ); } bool ODateBookAccessBackend_SQL::reload() { return load(); } bool ODateBookAccessBackend_SQL::save() { return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) } QArray<int> ODateBookAccessBackend_SQL::allRecords()const { return m_uids; } QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) { + qDebug( "Accessing ODateBookAccessBackend_SQL::queryByExample() which is not implemented!" ); return QArray<int>(); } void ODateBookAccessBackend_SQL::clear() { QString qu = "drop table datebook;"; qu += "drop table custom_data;"; OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); reload(); } OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ odebug << "ODateBookAccessBackend_SQL::find( " << uid << " )" << oendl; QString qu = "select *"; qu += "from datebook where uid = " + QString::number(uid); odebug << "Query: " << qu << "" << oendl; OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); OSQLResultItem resItem = res.first(); // Create Map for date event and insert UID QMap<int,QString> dateEventMap; dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); // Now insert the data out of the columns into the map. QMapConstIterator<int, QString> it; for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); } // Last step: Put map into date event, add custom map and return it OPimEvent retDate( dateEventMap ); retDate.setExtraMap( requestCustom( uid ) ); odebug << "ODateBookAccessBackend_SQL::find( " << uid << " ) end" << oendl; return retDate; } // FIXME: Speed up update of uid's.. bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) { QMap<int,QString> eventMap = ev.toMap(); QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); QMap<int, QString>::Iterator it; for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ if ( !eventMap[it.key()].isEmpty() ) qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); else qu += QString( ",\"\"" ); } qu += " );"; // Add custom entries int id = 0; QMap<QString, QString> customMap = ev.toExtraMap(); for( QMap<QString, QString>::Iterator it = customMap.begin(); it != customMap.end(); ++it ){ qu += "insert into custom_data VALUES(" + QString::number( ev.uid() ) + "," + QString::number( id++ ) + ",'" + it.key() //.latin1() + "'," + "0" // Priority for future enhancements + ",'" + it.data() //.latin1() + "');"; } OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); if ( res.state() != OSQLResult::Success ){ return false; } // Update list of uid's update(); return true; } // FIXME: Speed up update of uid's.. bool ODateBookAccessBackend_SQL::remove( int uid ) { QString qu = "DELETE from datebook where uid = " + QString::number( uid ) + ";"; diff --git a/libopie2/opiepim/backend/otodoaccessbackend.cpp b/libopie2/opiepim/backend/otodoaccessbackend.cpp index f979976..c7ce123 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.cpp +++ b/libopie2/opiepim/backend/otodoaccessbackend.cpp @@ -1,153 +1,153 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.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 <opie2/otodoaccessbackend.h> #include <opie2/private/opimtodosortvector.h> #include <opie2/otodoaccess.h> #include <qintdict.h> namespace Opie { OPimTodoAccessBackend::OPimTodoAccessBackend() : OPimAccessBackend<OPimTodo>() { } OPimTodoAccessBackend::~OPimTodoAccessBackend() { } const uint OPimTodoAccessBackend::querySettings() const { return 0; } bool OPimTodoAccessBackend::hasQuerySettings (uint querySettings) const { return false; } UIDArray OPimTodoAccessBackend::queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings, - const QDateTime& endperiod )const + const QDateTime& startperiod )const { qDebug( "Accessing OPimTodoAccessBackend::queryByExample() which is not implemented!" ); return UIDArray(); // odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl; // UIDArray m_currentQuery( uid_array.count() ); // uint arraycounter = 0; // for( uint it = 0; it < uid_array.count(); ++it ){ // /* Search all fields and compare them with query object. Store them into list // * if all fields matches. // */ // } } 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) ); diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h index 870ee57..06cece3 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.h +++ b/libopie2/opiepim/backend/otodoaccessbackend.h @@ -1,92 +1,92 @@ /* This file is part of the Opie Project Copyright (C) The Main Author <main-author@whereever.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_TODO_ACCESS_BACKEND_H #define OPIE_TODO_ACCESS_BACKEND_H #include <qbitarray.h> #include <opie2/opimtodo.h> #include <opie2/opimaccessbackend.h> namespace Opie { class OPimTodoAccessBackend : public OPimAccessBackend<OPimTodo> { public: OPimTodoAccessBackend(); ~OPimTodoAccessBackend(); 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 */ //@{ /** * Return all possible settings. * @return All settings provided by the current backend * (i.e.: query_WildCards & query_IgnoreCase) */ const uint querySettings() const; /** * Check whether settings are correct. * @return <i>true</i> if the given settings are correct and possible. */ bool hasQuerySettings (uint querySettings) const; - UIDArray queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings, const QDateTime& endperiod = QDateTime() )const; + UIDArray queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings, const QDateTime& startperiod = 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/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 9bbc820..9d18d47 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp @@ -25,139 +25,130 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * ===================================================================== * ToDo: XML-Backend: Automatic reload if something was changed... * * */ #include <opie2/ocontactaccess.h> #include <opie2/obackendfactory.h> /* OPIE */ #include <opie2/ocontactaccessbackend_xml.h> #include <opie2/opimresolver.h> #include <opie2/opimglobal.h> #include <opie2/odebug.h> //#include <qpe/qcopenvelope_qws.h> #include <qpe/global.h> /* QT */ #include <qasciidict.h> #include <qdatetime.h> #include <qfile.h> #include <qregexp.h> #include <qlist.h> #include <qcopchannel_qws.h> /* STD */ #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> namespace Opie { OPimContactAccess::OPimContactAccess ( const QString appname, const QString , OPimContactAccessBackend* end, bool autosync ): OPimAccessTemplate<OPimContact>( end ) { /* take care of the backend. If there is no one defined, we * will use the XML-Backend as default (until we have a cute SQL-Backend..). */ if( end == 0 ) { end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); } // Set backend locally and in template m_backEnd = end; OPimAccessTemplate<OPimContact>::setBackEnd (end); /* Connect signal of external db change to function */ QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(copMessage(const QCString&,const QByteArray&)) ); if ( autosync ){ QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(copMessage(const QCString&,const QByteArray&)) ); } } OPimContactAccess::~OPimContactAccess () { /* The user may forget to save the changed database, therefore try to * do it for him.. */ save(); // delete m_backEnd; is done by template.. } bool OPimContactAccess::save () { /* If the database was changed externally, we could not save the * Data. This will remove added items which is unacceptable ! * Therefore: Reload database and merge the data... */ if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) reload(); bool status = OPimAccessTemplate<OPimContact>::save(); if ( !status ) return false; /* Now tell everyone that new data is available. */ QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); return true; } -const uint OPimContactAccess::querySettings() -{ - return ( m_backEnd->querySettings() ); -} - -bool OPimContactAccess::hasQuerySettings ( int querySettings ) const -{ - return ( m_backEnd->hasQuerySettings ( querySettings ) ); -} #if 0 OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const { QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); return ( OPimRecordList<OPimContact>(matchingContacts, this) ); } #endif bool OPimContactAccess::wasChangedExternally()const { return ( m_backEnd->wasChangedExternally() ); } void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) { if ( msg == "addressbookUpdated()" ){ emit signalChanged ( this ); } else if ( msg == "flush()" ) { save (); } else if ( msg == "reload()" ) { reload (); emit signalChanged ( this ); } } int OPimContactAccess::rtti() const { return OPimResolver::AddressBook; } } diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index 5051321..9a2ecaf 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h @@ -23,155 +23,140 @@ -_. . . )=. = 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. */ /* * ===================================================================== * ToDo: Define enum for query settings * ===================================================================== */ #ifndef _OCONTACTACCESS_H #define _OCONTACTACCESS_H #include <qobject.h> #include <qpe/qcopenvelope_qws.h> #include <qvaluelist.h> #include <qfileinfo.h> #include <opie2/opimcontact.h> #include <opie2/ocontactaccessbackend.h> #include <opie2/opimaccesstemplate.h> namespace Opie { /** * Class to access the contacts database. * This is just a frontend for the real database handling which is * done by the backend. * This class is used to access the Contacts on a system. This class as any OPIE PIM * class is backend independent. * @author Stefan Eilers, Holger Freyther * @see OPimAccessTemplate */ class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> { Q_OBJECT public: /** * Filter for sorted() * @see SortFilterBase in OPimBase */ enum SortFilter { /** Don't return entries who don't have children */ DoNotShowWithoutChildren = FilterCustom<<1, /** Don't return entries who don't have an anniversary */ DoNotShowWithoutAnniversary = FilterCustom<<2, /** Don't return entries who don't have a birthday */ DoNotShowWithoutBirthday = FilterCustom<<3, /** Don't return entries who don't have a home address */ DoNotShowWithoutHomeAddress = FilterCustom<<4, /** Don't return entries who don't have a business address */ DoNotShowWithoutBusinessAddress = FilterCustom<<5, /** Don't return entries which hava any category */ DoNotShowWithCategory = FilterCustom << 6 }; /** * Sort order for sorted() * @see SortOrderBase in OPimBase */ enum SortOrder { SortTitle = SortCustom, SortFirstName, SortMiddleName, SortLastName, SortSuffix, SortEmail, SortNickname, SortFileAsName, SortAnniversary, SortBirthday, SortGender }; /** * Create Database with contacts (addressbook). * @param appname Name of application which wants access to the database * (i.e. "todolist") * @param filename The name of the database file. If not set, the default one * is used. * @param backend Pointer to an alternative Backend. If not set, we will use * the default backend. * @param handlesync If <b>true</b> the database stores the current state * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> * which are used before and after synchronisation. If the application wants * to react itself, it should be disabled by setting it to <b>false</b> * @see OPimContactAccessBackend */ OPimContactAccess (const QString appname, const QString filename = 0l, OPimContactAccessBackend* backend = 0l, bool handlesync = true); ~OPimContactAccess (); - /** - * Return all possible settings for queryByExample(). - * @return All settings provided by the current backend - * (i.e.: WildCards & IgnoreCase) - * @see QuerySettings in OPimBase for details of the parameter, queryByExample() - */ - const uint querySettings(); - - /** - * Check whether settings are correct for queryByExample(). - * @return <i>true</i> if the given settings are correct and possible. - * @see QuerySettings in OPimBase for details of the parameter - */ - bool hasQuerySettings ( int querySettings ) const; - /** * if the resource was changed externally. * You should use the signal instead of polling possible changes ! */ bool wasChangedExternally()const; /** Save contacts database. * Save is more a "commit". After calling this function, all changes are public available. * @return true if successful */ bool save(); /** * Return identification of used records */ int rtti() const; signals: /* Signal is emitted if the database was changed. Therefore * we may need to reload to stay consistent. * @param which Pointer to the database who created this event. This pointer * is useful if an application has to handle multiple databases at the same time. * @see reload() */ void signalChanged ( const OPimContactAccess *which ); private: OPimContactAccessBackend *m_backEnd; bool m_loading:1; private slots: void copMessage( const QCString &msg, const QByteArray &data ); private: class Private; Private *d; }; } #endif diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 3875f09..823f03d 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -1,406 +1,431 @@ /* This file is part of the Opie Project Copyright (C) Holger Freyther <zecke@handhelds.org> Copyright (C) Stefan Eilers <eilers.stefan@epost.de> =. 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_ACCESS_TEMPLATE_H #define OPIE_PIM_ACCESS_TEMPLATE_H /* OPIE */ #include <opie2/opimrecord.h> #include <opie2/opimaccessbackend.h> #include <opie2/opimrecordlist.h> #include <opie2/opimtemplatebase.h> #include <opie2/odebug.h> /* QT */ #include <qarray.h> #include <qdatetime.h> namespace Opie { class OPimAccessTemplatePrivate; /** * Thats the frontend to our OPIE PIM * Library. Either you want to use it's * interface or you want to implement * your own Access lib * Just create a OPimRecord and inherit from * the templates */ template <class T = OPimRecord > class OPimAccessTemplate : public OTemplateBase<T> { public: /** * */ enum Access { Random = 0, SortedAccess }; typedef OPimRecordList<T> List; typedef OPimAccessBackend<T> BackEnd; typedef OPimCache<T> Cache; //@{ OPimAccessTemplate( BackEnd* end); virtual ~OPimAccessTemplate(); //@} //@{ bool load(); virtual bool reload(); bool save(); void clear() ; //@} bool wasChangedExternally()const; //@{ virtual List allRecords()const; virtual List matchRegexp( const QRegExp &r ) const; + /** + * Return all possible settings for queryByExample(). + * @return All settings provided by the current backend + * (i.e.: WildCards & IgnoreCase) + * @see QuerySettings in OPimBase for details of the parameter, queryByExample() + */ + const uint querySettings(); + + /** + * Check whether settings are correct for queryByExample(). + * @return <i>true</i> if the given settings are correct and possible. + * @see QuerySettings in OPimBase for details of the parameter + */ + bool hasQuerySettings ( int querySettings ) const; + /** * Query by example search interface. * "Query by Example" provides a very powerful search engine. Use the query object * (this may be a contact, a todo or databook event) * as a search mask which is converted into a query regarding the querySettings. If a time period is needed - * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the endperiod (the last parameter). + * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the startperiod (the last parameter). * @see QuerySettings in class OPimBase * @param query The object which contains the query set * @param querySettings This parameter defines what should be searched and how the query should be interpreted - * @param endperiod Defines the end of a period for some special queries. + * @param startperiod Defines the start of a period for some special queries. */ - virtual List queryByExample( const T& query, int querySettings, const QDateTime& endperiod = QDateTime() ); + virtual List queryByExample( const T& query, int querySettings, const QDateTime& startperiod = QDateTime() ); /** * Generic query by example search interface. This is a special version which handles generic OPimRecord types. They are converted * automatically into the right datatype. * "Query by Example" provides a very powerful search engine. Use the query object (this may be a contact, a todo or databook event) * as a search mask which is converted into a query regarding the querySettings. If a time period is needed - * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the endperiod (the last parameter). + * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the startperiod (the last parameter). * @see QuerySettings in class OPimBase * @param query The object which contains the query set * @param querySettings This parameter defines what should be searched and how the query should be interpreted - * @param endperiod Defines the end of a period for some special queries. + * @param startperiod Defines the start of a period for some special queries. */ - virtual List queryByExample( const OPimRecord* query, int querySettings, const QDateTime& endperiod = QDateTime() ); + virtual List queryByExample( const OPimRecord* query, int querySettings, const QDateTime& startperiod = QDateTime() ); /** * Incremental query by example search interface. Providing incremental search, this one provides the feature * to search in a list of records which may be returned by an other search. * "Query by Example" provides a very powerful search engine. Use the query object (this may be a contact, a todo or databook event) * as a search mask which is converted into a query regarding the querySettings. If a time period is needed - * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the endperiod (the last parameter). + * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the startperiod (the last parameter). * @see QuerySettings in class OPimBase * @param uidlist List of uid's which should be incorporated into the next search * @param query The object which contains the query set * @param querySettings This parameter defines what should be searched and how the query should be interpreted - * @param endperiod Defines the end of a period for some special queries. + * @param startperiod Defines the start of a period for some special queries. */ virtual List queryByExample( const OPimAccessTemplate::List& uidlist, const T& query, int querySettings, - const QDateTime& endperiod = QDateTime() ); + const QDateTime& startperiod = QDateTime() ); virtual T find( UID uid )const; virtual T find( UID uid, const QArray<int>&, uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; //@} /** * Get sorted lists.. * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: * @param list of UID's received by allRecords() or others... * @param sortOrder Setting the sort order defined by enum SortOrder * @param ascending Sort in ascending order if true, otherwise descending * @param sortFilter Setting the sort filter defined by enum SortFilter * @param cat number of category. */ virtual List sorted( const List& list, bool ascending, int sortOrder, int sortFilter, int cat )const; /** * Get sorted lists.. * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: * @param list of UID's received by allRecords() or others... * @param sortOrder Setting the sort order defined by enum SortOrder * @param ascending Sort in ascending order if true, otherwise descending * @param sortFilter Setting the sort filter defined by enum SortFilter * @param cats List of categories. */ virtual List sorted( const List& list, bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const; /** * Get sorted lists.. * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: * @param ascending Sort in ascending order if true, otherwise descending * @param sortOrder Setting the sort order defined by enum SortOrder * @param sortFilter Setting the sort filter defined by enum SortFilter * @param cat number of category. */ virtual List sorted( bool ascending, int sortOrder, int sortFilter, int cat )const; /** * Get sorted lists.. * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: * @param ascending Sort in ascending order if true, otherwise descending * @param sortOrder Setting the sort order defined by enum SortOrder * @param sortFilter Setting the sort filter defined by enum SortFilter * @param cats List of categories. */ virtual List sorted( bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const; /** * (Re)Implementation */ //@{ UIDArray matchRegexpSimple( const QRegExp& r )const; UIDArray queryByExampleSimple( const OPimRecord*, int, const QDateTime& )const; UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder, int sortFilter, int cat )const; UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& )const; UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, int cat )const; UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, const QArray<int>& )const; OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const; OPimOccurrence::List occurrences( const QDateTime& dt )const; //@} //@{ virtual bool add( const T& t ) ; bool add( const OPimRecord& ); bool add( const OPimRecord* ); virtual bool remove( const T& t ); bool remove( UID uid ); bool remove( const OPimRecord& ); virtual bool replace( const T& t) ; //@} void setReadAhead( uint count ); void cache( const T& )const; void setSaneCacheSize( int ); QArray<UID> records()const; protected: /** * invalidate the cache */ void invalidateCache(); void setBackEnd( BackEnd* end ); /** * returns the backend */ BackEnd* backEnd(); BackEnd* m_backEnd; Cache m_cache; private: OPimAccessTemplatePrivate *d; }; /** * c'tor BackEnd * enum Access a small hint on how to handle the backend */ template <class T> OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) : OTemplateBase<T>(), m_backEnd( end ) { if (end ) end->setFrontend( this ); } template <class T> OPimAccessTemplate<T>::~OPimAccessTemplate() { delete m_backEnd; } /** * load from the backend */ template <class T> bool OPimAccessTemplate<T>::load() { invalidateCache(); return m_backEnd->load(); } /** Reload database. * You should execute this function if the external database * was changed. * This function will load the external database and afterwards * rejoin the local changes. Therefore the local database will be set consistent. */ template <class T> bool OPimAccessTemplate<T>::reload() { invalidateCache(); return m_backEnd->reload(); } /** * Save contacts database. * Save is more a "commit". After calling this function, all changes are public available. * @return true if successful */ template <class T> bool OPimAccessTemplate<T>::save() { return m_backEnd->save(); } /** * return a List of records * you can iterate over them */ template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { QArray<int> ints = m_backEnd->allRecords(); List lis(ints, this ); return lis; } /** * return a List of records * that match the regex */ template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { QArray<int> ints = m_backEnd->matchRegexp( r ); List lis(ints, this ); return lis; } /** * find the OPimRecord uid */ template <class T> QArray<int> OPimAccessTemplate<T>::records()const { return m_backEnd->allRecords(); } +template <class T> +const uint OPimAccessTemplate<T>::querySettings(){ + return m_backEnd->querySettings(); +} + +template <class T> +bool OPimAccessTemplate<T>::hasQuerySettings ( int querySettings ) const { + return m_backEnd->hasQuerySettings( querySettings ); +} + template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); List list(ints, this ); return list; } template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::queryByExample( const OPimRecord* t, int settings, const QDateTime& d ) { T tempInstance; if ( t->rtti() == tempInstance.rtti() ) { QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); List list( ints, this ); return list; } else { owarn << "Query not possible: Objecttype mismatch" << oendl; } return List(); } template <class T> typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::queryByExample( const OPimAccessTemplate::List& uidlist, const T& t, int settings, const QDateTime& d ) { QArray<int> ints = m_backEnd->queryByExample( uidlist.uids(), t, settings, d ); List list( ints, this ); return list; } template <class T> T OPimAccessTemplate<T>::find( UID uid ) const{ // First search in cache.. if ( m_cache.contains( uid ) ) return m_cache.find( uid ); T t = m_backEnd->find( uid ); cache( t ); return t; } /** * read ahead cache find method ;) */ template <class T> T OPimAccessTemplate<T>::find( UID uid, const QArray<int>& ar, uint current, typename OTemplateBase<T>::CacheDirection dir )const { /* * better do T.isEmpty() * after a find this way we would * avoid two finds in QCache... */ if (m_cache.contains( uid ) ) return m_cache.find( uid ); T t = m_backEnd->find( uid, ar, current, dir ); cache( t ); return t; } /** * clears the backend and invalidates the backend */ template <class T> void OPimAccessTemplate<T>::clear() { invalidateCache(); m_backEnd->clear(); } /** * add T to the backend * @param t The item to add. * @return <i>true</i> if added successfully. */ template <class T> bool OPimAccessTemplate<T>::add( const T& t ) { cache( t ); return m_backEnd->add( t ); } template <class T> bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { /* same type */ T tempInstance; if ( rec.rtti() == tempInstance.rtti() ) { const T& t = static_cast<const T&>(rec); |