summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ChangeLog4
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h4
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp29
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.h2
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp27
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.h15
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h6
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.cpp32
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.h15
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp34
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h2
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp5
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h1
13 files changed, 134 insertions, 42 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog
index 564e92a..2007744 100644
--- a/libopie2/opiepim/ChangeLog
+++ b/libopie2/opiepim/ChangeLog
@@ -1,21 +1,23 @@
2004-12-28 Stefan Eilers <stefan@eilers-online.net>
* Make improved query by example accessable via frontend
- * Some API improvement
+ * 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/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h
index ee6dbc2..27d70ab 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.h
@@ -59,53 +59,53 @@ class OPimContactAccessBackend: public OPimAccessBackend<OPimContact> {
public:
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 all possible settings.
* @return All settings provided by the current backend
* (i.e.: query_WildCards & query_IgnoreCase)
*/
- virtual const uint querySettings() const;
+ const uint querySettings() const;
/**
* Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
- virtual bool hasQuerySettings (uint querySettings) const;
+ bool hasQuerySettings (uint querySettings) const;
/**
* Advanced search mechanism.
*/
UIDArray queryByExample( const UIDArray& uidlist, const OPimContact&, int settings, const QDateTime &d = QDateTime() ) const;
/**
* Slow and inefficent default implementation
*/
//@{
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;
};
}
#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index 9375f43..2368865 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -258,75 +258,77 @@ namespace {
id = 0;
QMap<QString, QString> customMap = m_contact.toExtraMap();
for( QMap<QString, QString>::Iterator it = customMap.begin();
it != customMap.end(); ++it ){
qu += "insert into custom_data VALUES("
+ QString::number( m_contact.uid() )
+ ","
+ QString::number( id++ )
+ ",'"
+ it.key()
+ "',"
+ "0" // Priority for future enhancements
+ ",'"
+ it.data()
+ "');";
}
// qu += "commit;";
odebug << "add " << qu << "" << oendl;
return qu;
}
RemoveQuery::RemoveQuery(int uid )
: OSQLQuery(), m_uid( uid ) {}
+
RemoveQuery::~RemoveQuery() {}
+
QString RemoveQuery::query()const {
QString qu = "DELETE from addressbook where uid = "
+ QString::number(m_uid) + ";";
qu += "DELETE from custom_data where uid = "
+ QString::number(m_uid) + ";";
return qu;
}
-
-
FindQuery::FindQuery(int uid)
: OSQLQuery(), m_uid( uid ) {
}
FindQuery::FindQuery(const UIDArray& ints)
: OSQLQuery(), m_uids( ints ){
}
FindQuery::~FindQuery() {
}
QString FindQuery::query()const{
- if ( m_uids.count() == 0 )
- return single();
- else
- return multi();
+ if ( m_uids.count() == 0 )
+ return single();
+ else
+ return multi();
}
+
+
QString FindQuery::multi()const {
QString qu = "select * from addressbook where";
for (uint i = 0; i < m_uids.count(); i++ ) {
qu += " uid = " + QString::number( m_uids[i] ) + " OR";
}
qu.remove( qu.length()-2, 2 ); // Hmmmm..
odebug << "find query: " << qu << "" << oendl;
return qu;
}
QString FindQuery::single()const{
QString qu = "select *";
qu += " from addressbook where uid = " + QString::number(m_uid);
// owarn << "find query: " << qu << "" << oendl;
return qu;
}
FindCustomQuery::FindCustomQuery(int uid)
: OSQLQuery(), m_uid( uid ) {
}
FindCustomQuery::FindCustomQuery(const UIDArray& ints)
@@ -507,52 +509,65 @@ OPimContact OPimContactAccessBackend_SQL::find( int uid, const UIDArray& queryUi
for ( uint i = current; i < queryUids.count() && size < numReadAhead; i++ ) {
searchList[size] = queryUids[i];
size++;
}
break;
/* reverse */
case Frontend::Reverse:
for ( uint i = current; i != 0 && size < numReadAhead; i-- ) {
searchList[size] = queryUids[i];
size++;
}
break;
}
//Shrink to real size..
searchList.resize( size );
OPimContact retContact( requestContactsAndCache( uid, searchList ) );
odebug << "OPimContactAccessBackend_SQL::find( ..multi.. ) needed: " << t.elapsed() << " ms" << oendl;
return retContact;
}
-UIDArray OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings,
+UIDArray OPimContactAccessBackend_SQL::queryByExample ( const UIDArray& uidlist, const OPimContact &query, int settings,
const QDateTime& qd ) const
{
QString qu = "SELECT uid FROM addressbook WHERE";
+
+ // Just add uid's selection if we really try to search in a subset of all uids! Otherwise this would
+ // just take time and memory!
+ if ( uidlist.count() != m_uids.count() ) {
+ qu += " (";
+
+ for ( uint i = 0; i < uidlist.count(); i++ ) {
+ qu += " uid = " + QString::number( uidlist[i] ) + " OR";
+ }
+ qu.remove( qu.length()-2, 2 ); // Hmmmm..
+ qu += " ) AND ";
+ }
+
QString searchQuery ="";
QDate startDate;
if ( qd.isValid() )
startDate = qd.date();
else
startDate = QDate::currentDate();
QMap<int, QString> queryFields = query.toMap();
QStringList fieldList = OPimContactFields::untrfields( false );
QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
// Convert every filled field to a SQL-Query
// bool isAnyFieldSelected = false;
for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
int id = translate[*it];
QString queryStr = queryFields[id];
QDate* endDate = 0l;
if ( !queryStr.isEmpty() ){
// If something is alredy stored in the query, add an "AND"
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
index 299c175..1cf1185 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
@@ -54,49 +54,49 @@ namespace Opie {
/**
* This class is the SQL implementation of a Contact backend
* it does implement everything available for OPimContact.
* @see OPimAccessBackend for more information of available methods
*/
class OPimContactAccessBackend_SQL : public OPimContactAccessBackend {
public:
OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null );
~OPimContactAccessBackend_SQL ();
bool save();
bool load ();
void clear ();
bool wasChangedExternally();
UIDArray allRecords() const;
OPimContact find( int uid ) const;
OPimContact find( int uid, const UIDArray& items, uint cur, Frontend::CacheDirection ) const;
- UIDArray queryByExample ( const OPimContact &query, int settings,
+ UIDArray queryByExample ( const UIDArray& uidlist, const OPimContact &query, int settings,
const QDateTime& d ) const;
UIDArray matchRegexp( const QRegExp &r ) const;
const uint querySettings() const;
bool hasQuerySettings (uint querySettings) const;
UIDArray sorted( const UIDArray& ar, bool asc, int sortOrder,
int filter, const QArray<int>& categories)const;
bool add ( const OPimContact &newcontact );
bool replace ( const OPimContact &contact );
bool remove ( int uid );
bool reload();
private:
UIDArray extractUids( Opie::DB::OSQLResult& res ) const;
QMap<int, QString> requestNonCustom( int uid ) const;
QMap<QString, QString> requestCustom( int uid ) const;
QMap<int, QString> fillNonCustomMap( const Opie::DB::OSQLResultItem& resultItem ) const;
OPimContact requestContactsAndCache( int uid, const QArray<int>& cachelist ) const;
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
index 73c7059..e44912a 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -79,72 +79,89 @@ void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& l
}
}
}
}
namespace Opie {
ODateBookAccessBackend::ODateBookAccessBackend()
: OPimAccessBackend<OPimEvent>()
{
}
ODateBookAccessBackend::~ODateBookAccessBackend() {
}
OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from,
const QDate& to )const {
OPimBackendOccurrence::List tmpList;
events( tmpList, directNonRepeats(), from, to );
repeat( tmpList, directRawRepeats(),from,to );
return tmpList;
}
-OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const {
+
+OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const
+{
OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() );
return filterOccurrences( day, dt );
}
OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
- const QDate& to )const {
+ const QDate& to )const
+{
OPimBackendOccurrence::List tmpList;
OPimEvent::ValueList list = directNonRepeats();
events( tmpList, list, from, to );
return tmpList;
}
-OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const {
+OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const
+{
OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
return filterOccurrences( day,dt );
}
+const uint ODateBookAccessBackend::querySettings() const
+{
+ return 0;
+}
+
+bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const
+{
+ return false;
+}
+
+
-UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings,
- const QDateTime& d )const {
+UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings,
+ const QDateTime& d )const
+{
+ qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" );
return UIDArray();
}
UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const {
return UIDArray();
}
OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
const QDateTime& dt ) {
OPimBackendOccurrence::List tmpList;
OPimBackendOccurrence::List::ConstIterator it;
for ( it = dayList.begin(); it != dayList.end(); ++it ) {
OPimBackendOccurrence occ = *it;
/*
* Let us find occurrences that are 'now'!
* If the dt.date() is on the same day as start or end of the Occurrence
* check how near start/end are.
* If it is in the middle of a multiday occurrence list it.
*
* We might want to 'lose' the sixty second offset and list
* all Events which are active at that time.
*/
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h
index 8927ca1..91f63aa 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.h
@@ -73,42 +73,55 @@ public:
* Same as above but return raw repeats!
*/
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 OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to )const;
/**
* this is an overloaded member function
* @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to )
*/
virtual OPimBackendOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start )const;
/**
* Common and probably inefficent implementation
* for queryByExample, sorted
* and occurrences
*/
//@{
- UIDArray queryByExample( const OPimEvent&, int settings, const QDateTime& d = QDateTime() )const;
+ /**
+ * 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 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;
};
}
#endif
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 7321758..6666fd6 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -54,64 +54,64 @@ class OPimAccessBackend {
public:
typedef OTemplateBase<T> Frontend;
//@{
OPimAccessBackend(int access = 0);
virtual ~OPimAccessBackend();
//@}
//@{
virtual bool load() = 0;
virtual bool reload() = 0;
virtual bool save() = 0;
virtual void clear() = 0;
//@}
//@{
// FIXME: Uncommented some of the abstract functions below. This should be removed as they are implemented in
// all typespecifc backenends (eilers)
/**
* Return all possible settings for queryByExample()
* @return All settings provided by the current backend
* (i.e.: query_WildCards & query_IgnoreCase)
* See implementation in the specific backends for contacts, todo and dates.
*/
- virtual const uint querySettings() const { return 0; } /* FIXME: Make Abstrakt !! = 0; */
+ virtual const uint querySettings() const = 0;
/**
* Check whether settings are correct for queryByExample()
* See implementation in the specific backends for OPimContactAccess, OPimTodoAccess and ODateBookAccess.
* @return <i>true</i> if the given settings are correct and possible.
*/
- virtual bool hasQuerySettings (uint querySettings) const { return false; } /* FIXME: Make Abstrakt !! = 0; */
+ virtual bool hasQuerySettings (uint querySettings) const = 0;
//@}
//@{
virtual UIDArray allRecords()const = 0;
virtual UIDArray matchRegexp(const QRegExp &r) const;
virtual UIDArray queryByExample( const UIDArray&, const T& t,
- int settings, const QDateTime& d = QDateTime() )const { return UIDArray(); } /* FIXME: Make Abstrakt !! = 0; */
+ int settings, const QDateTime& d = QDateTime() )const = 0;
virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const;
virtual UIDArray queryByExample( const OPimRecord* rec, int settings, const QDateTime& d = QDateTime() )const;
virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const = 0;
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;
//@}
//@{
virtual T find(UID uid )const = 0;
virtual T find(UID uid, const QArray<UID>& items,
uint current, typename Frontend::CacheDirection )const ;
//@}
//@{
virtual bool add( const T& t ) = 0;
virtual bool remove( UID uid ) = 0;
virtual bool replace( const T& t ) = 0;
//@}
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.cpp b/libopie2/opiepim/backend/otodoaccessbackend.cpp
index 5f86be9..f979976 100644
--- a/libopie2/opiepim/backend/otodoaccessbackend.cpp
+++ b/libopie2/opiepim/backend/otodoaccessbackend.cpp
@@ -21,51 +21,77 @@
: = ...= . :.=-
-. .:....=;==+<; 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() {
}
-UIDArray OPimTodoAccessBackend::queryByExample( const OPimTodo&, int settings,
- const QDateTime& d)const {
- return UIDArray();
+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
+{
+ 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 ) {
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h
index 66297bb..870ee57 100644
--- a/libopie2/opiepim/backend/otodoaccessbackend.h
+++ b/libopie2/opiepim/backend/otodoaccessbackend.h
@@ -30,49 +30,62 @@
#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
*/
//@{
- UIDArray queryByExample( const OPimTodo&, int settings, const QDateTime& d = QDateTime() )const;
+ /**
+ * 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 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.
*
*
*/
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 2bcab29..70e40e4 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -280,71 +280,81 @@ namespace {
id = 0;
QMap<QString, QString> customMap = m_todo.toExtraMap();
for( QMap<QString, QString>::Iterator it = customMap.begin();
it != customMap.end(); ++it ){
qu += "insert into custom_data VALUES("
+ QString::number( m_todo.uid() )
+ ","
+ QString::number( id++ )
+ ",'"
+ it.key()
+ "',"
+ "0" // Priority for future enhancements
+ ",'"
+ it.data()
+ "');";
}
odebug << "add " << qu << "" << oendl;
return qu;
}
RemoveQuery::RemoveQuery(int uid )
: OSQLQuery(), m_uid( uid ) {}
+
RemoveQuery::~RemoveQuery() {}
+
QString RemoveQuery::query()const {
QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
- qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
+ qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
return qu;
}
ClearQuery::ClearQuery()
: OSQLQuery() {}
ClearQuery::~ClearQuery() {}
- QString ClearQuery::query()const {
- QString qu = "drop table todolist";
- return qu;
+ QString ClearQuery::query()const
+ {
+ QString qu = "drop table todolist";
+ return qu;
}
+
FindQuery::FindQuery(int uid)
- : OSQLQuery(), m_uid(uid ) {
+ : OSQLQuery(), m_uid(uid )
+ {
}
+
FindQuery::FindQuery(const QArray<int>& ints)
- : OSQLQuery(), m_uids(ints){
+ : OSQLQuery(), m_uids(ints)
+ {
}
- FindQuery::~FindQuery() {
+
+ FindQuery::~FindQuery()
+ {
}
+
QString FindQuery::query()const{
if (m_uids.count() == 0 )
return single();
else
return multi();
}
QString FindQuery::single()const{
QString qu = "select * from todolist where uid = " + QString::number(m_uid);
return qu;
}
QString FindQuery::multi()const {
QString qu = "select * from todolist where ";
for (uint i = 0; i < m_uids.count(); i++ ) {
qu += " UID = " + QString::number( m_uids[i] ) + " OR";
}
qu.remove( qu.length()-2, 2 );
return qu;
}
OverDueQuery::OverDueQuery(): OSQLQuery() {}
OverDueQuery::~OverDueQuery() {}
QString OverDueQuery::query()const {
QDate date = QDate::currentDate();
QString str;
@@ -427,52 +437,52 @@ OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){
bool OPimTodoAccessBackendSQL::load(){
if (!m_driver->open() )
return false;
CreateQuery creat;
OSQLResult res = m_driver->query(&creat );
m_dirty = true;
return true;
}
bool OPimTodoAccessBackendSQL::reload(){
return load();
}
bool OPimTodoAccessBackendSQL::save(){
return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
}
QArray<int> OPimTodoAccessBackendSQL::allRecords()const {
if (m_dirty )
update();
return m_uids;
}
-QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){
- QArray<int> ints(0);
- return ints;
-}
+// QArray<int> OPimTodoAccessBackendSQL::queryByExample( const UIDArray& uidlist, const OPimTodo& , int, const QDateTime& ){
+// QArray<int> ints(0);
+// return ints;
+// }
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,
uint cur, Frontend::CacheDirection dir ) const{
uint CACHE = readAhead();
odebug << "searching for " << uid << "" << oendl;
QArray<int> search( CACHE );
uint size =0;
// we try to cache CACHE items
switch( dir ) {
/* forward */
case Frontend::Forward:
for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
search[size] = ints[i];
size++;
}
break;
/* reverse */
case Frontend::Reverse:
@@ -598,49 +608,49 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
break;
case OPimTodoAccess::Priority:
query += "priority";
break;
case OPimTodoAccess::SortSummary:
query += "summary";
break;
case OPimTodoAccess::Deadline:
query += "DueDate";
break;
}
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" )
+ if ( str == "0000-00-00" )
return false;
else{
int day, year, month;
QStringList list = QStringList::split("-", str );
year = list[0].toInt();
month = list[1].toInt();
day = list[2].toInt();
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;
}
OPimTodo retTodo;
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it = list.begin();
OPimTodo to, tmp;
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 0ba8f3a..ac3476a 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -32,49 +32,49 @@
/* #include <qasciidict.h> */
#include <opie2/otodoaccessbackend.h>
namespace Opie {
namespace DB {
class OSQLDriver;
class OSQLResult;
class OSQLResultItem;
}
}
namespace Opie {
class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend {
public:
OPimTodoAccessBackendSQL( const QString& file );
~OPimTodoAccessBackendSQL();
bool load();
bool reload();
bool save();
QArray<UID> allRecords()const;
- QArray<UID> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() );
+/* QArray<UID> queryByExample( const UIDArray& uidlist, 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( UID uid );
bool replace( const OPimTodo& t );
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;
inline bool date( QDate& date, const QString& )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;
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 273f91a..ab50604 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -305,52 +305,49 @@ bool OPimTodoAccessXML::save() {
QFile::remove( strNewFile );
return false;
}
/* flush before renaming */
f.close();
if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
QFile::remove( strNewFile );
}
m_changed = false;
return true;
}
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();
return ids;
}
-QArray<int> OPimTodoAccessXML::queryByExample( const OPimTodo&, int, const QDateTime& ) {
- QArray<int> ids(0);
- return ids;
-}
+
OPimTodo OPimTodoAccessXML::find( int uid )const {
OPimTodo todo;
todo.setUid( 0 ); // isEmpty()
QMap<int, OPimTodo>::ConstIterator it = m_events.find( uid );
if ( it != m_events.end() )
todo = it.data();
return todo;
}
void OPimTodoAccessXML::clear() {
if (m_opened )
m_changed = true;
m_events.clear();
}
bool OPimTodoAccessXML::add( const OPimTodo& todo ) {
m_changed = true;
m_events.insert( todo.uid(), todo );
return true;
}
bool OPimTodoAccessXML::remove( int uid ) {
m_changed = true;
m_events.remove( uid );
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h
index 134a21a..8a71bb7 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.h
+++ b/libopie2/opiepim/backend/otodoaccessxml.h
@@ -31,49 +31,48 @@
#include <qasciidict.h>
#include <qmap.h>
#include <opie2/otodoaccessbackend.h>
namespace Opie {
class XMLElement;
class OPimTodoAccessXML : public OPimTodoAccessBackend {
public:
/**
* fileName if Empty we will use the default path
*/
OPimTodoAccessXML( const QString& appName,
const QString& fileName = QString::null );
~OPimTodoAccessXML();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
QArray<int> matchRegexp(const QRegExp &r) const;
- QArray<int> queryByExample( const OPimTodo&, int querysettings, const QDateTime& d = QDateTime() );
OPimTodo find( int uid )const;
void clear();
bool add( const OPimTodo& );
bool remove( int uid );
void removeAllCompleted();
bool replace( const OPimTodo& );
/* our functions */
QArray<int> effectiveToDos( const QDate& start,
const QDate& end,
bool includeNoDates )const;
QArray<int> overDue()const;
//@{
UIDArray sorted( const UIDArray&, bool, int, int, const QArray<int>& )const;
//@}
private:
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;
QString m_file;
QString m_app;
bool m_opened : 1;