summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ChangeLog3
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h2
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h76
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h2
4 files changed, 74 insertions, 9 deletions
diff --git a/libopie2/opiepim/ChangeLog b/libopie2/opiepim/ChangeLog
index dd57259..564e92a 100644
--- a/libopie2/opiepim/ChangeLog
+++ b/libopie2/opiepim/ChangeLog
@@ -1,18 +1,21 @@
12004-12-28 Stefan Eilers <stefan@eilers-online.net>
2 * Make improved query by example accessable via frontend
3 * Some API improvement
12004-11-23 Stefan Eilers <stefan@eilers-online.net> 42004-11-23 Stefan Eilers <stefan@eilers-online.net>
2 * Implement fast and full featured version of sorted() for addressbook 5 * Implement fast and full featured version of sorted() for addressbook
3 * Implement generic queryByExample for all Addressboook backends. It allows incremental search. 6 * Implement generic queryByExample for all Addressboook backends. It allows incremental search.
4 * Update of API Documentation 7 * Update of API Documentation
52004-11-18 Holger Freyther <freyther@handhelds.org> 82004-11-18 Holger Freyther <freyther@handhelds.org>
6 * Every Access can give a set of Occurrences for a period or a datetime 9 * Every Access can give a set of Occurrences for a period or a datetime
7 * QueryByExample, Find, Sort can be generically accessed by OPimBase 10 * QueryByExample, Find, Sort can be generically accessed by OPimBase
8 pointer interface 11 pointer interface
9 * OPimBackendOccurrence gets split up to OPimOccurrences by 12 * OPimBackendOccurrence gets split up to OPimOccurrences by
10 OPimTemplateBase 13 OPimTemplateBase
11 * Add safeCast to various OPimRecords 14 * Add safeCast to various OPimRecords
12 * Kill memleak in OPimTodo 15 * Kill memleak in OPimTodo
13 * Add SortVector implementations for OPimTodo and OPimContact 16 * Add SortVector implementations for OPimTodo and OPimContact
14 17
15 2004-??-??The Opie Team <opie@handhelds.org> 18 2004-??-??The Opie Team <opie@handhelds.org>
16 * Implemented some important modifications to allow to use OPimRecords as it is, without 19 * Implemented some important modifications to allow to use OPimRecords as it is, without
17 have to cast them. This makes it possible to write applications which handling pim 20 have to cast them. This makes it possible to write applications which handling pim
18 data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file 21 data in a generic manner (see opimconvertion tool) (eilers) \ No newline at end of file
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index bd85b4e..5051321 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -1,177 +1,177 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: Define enum for query settings 31 * ToDo: Define enum for query settings
32 * ===================================================================== 32 * =====================================================================
33 */ 33 */
34#ifndef _OCONTACTACCESS_H 34#ifndef _OCONTACTACCESS_H
35#define _OCONTACTACCESS_H 35#define _OCONTACTACCESS_H
36 36
37#include <qobject.h> 37#include <qobject.h>
38 38
39#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
40 40
41#include <qvaluelist.h> 41#include <qvaluelist.h>
42#include <qfileinfo.h> 42#include <qfileinfo.h>
43 43
44#include <opie2/opimcontact.h> 44#include <opie2/opimcontact.h>
45#include <opie2/ocontactaccessbackend.h> 45#include <opie2/ocontactaccessbackend.h>
46#include <opie2/opimaccesstemplate.h> 46#include <opie2/opimaccesstemplate.h>
47 47
48namespace Opie { 48namespace Opie {
49/** 49/**
50 * Class to access the contacts database. 50 * Class to access the contacts database.
51 * This is just a frontend for the real database handling which is 51 * This is just a frontend for the real database handling which is
52 * done by the backend. 52 * done by the backend.
53 * This class is used to access the Contacts on a system. This class as any OPIE PIM 53 * This class is used to access the Contacts on a system. This class as any OPIE PIM
54 * class is backend independent. 54 * class is backend independent.
55 * @author Stefan Eilers, Holger Freyther 55 * @author Stefan Eilers, Holger Freyther
56 * @see OPimAccessTemplate 56 * @see OPimAccessTemplate
57 */ 57 */
58class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> 58class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
59{ 59{
60 Q_OBJECT 60 Q_OBJECT
61 61
62 public: 62 public:
63 /** 63 /**
64 * Filter for sorted() 64 * Filter for sorted()
65 * @see SortFilterBase in OPimBase 65 * @see SortFilterBase in OPimBase
66 */ 66 */
67 enum SortFilter { 67 enum SortFilter {
68 /** Don't return entries who don't have children */ 68 /** Don't return entries who don't have children */
69 DoNotShowWithoutChildren = FilterCustom<<1, 69 DoNotShowWithoutChildren = FilterCustom<<1,
70 /** Don't return entries who don't have an anniversary */ 70 /** Don't return entries who don't have an anniversary */
71 DoNotShowWithoutAnniversary = FilterCustom<<2, 71 DoNotShowWithoutAnniversary = FilterCustom<<2,
72 /** Don't return entries who don't have a birthday */ 72 /** Don't return entries who don't have a birthday */
73 DoNotShowWithoutBirthday = FilterCustom<<3, 73 DoNotShowWithoutBirthday = FilterCustom<<3,
74 /** Don't return entries who don't have a home address */ 74 /** Don't return entries who don't have a home address */
75 DoNotShowWithoutHomeAddress = FilterCustom<<4, 75 DoNotShowWithoutHomeAddress = FilterCustom<<4,
76 /** Don't return entries who don't have a business address */ 76 /** Don't return entries who don't have a business address */
77 DoNotShowWithoutBusinessAddress = FilterCustom<<5, 77 DoNotShowWithoutBusinessAddress = FilterCustom<<5,
78 /** Don't return entries which hava any category */ 78 /** Don't return entries which hava any category */
79 DoNotShowWithCategory = FilterCustom << 6 79 DoNotShowWithCategory = FilterCustom << 6
80 }; 80 };
81 81
82 /** 82 /**
83 * Sort order for sorted() 83 * Sort order for sorted()
84 * @see SortOrderBase in OPimBase 84 * @see SortOrderBase in OPimBase
85 */ 85 */
86 enum SortOrder { 86 enum SortOrder {
87 SortTitle = SortCustom, 87 SortTitle = SortCustom,
88 SortFirstName, 88 SortFirstName,
89 SortMiddleName, 89 SortMiddleName,
90 SortLastName, 90 SortLastName,
91 SortSuffix, 91 SortSuffix,
92 SortEmail, 92 SortEmail,
93 SortNickname, 93 SortNickname,
94 SortFileAsName, 94 SortFileAsName,
95 SortAnniversary, 95 SortAnniversary,
96 SortBirthday, 96 SortBirthday,
97 SortGender 97 SortGender
98 }; 98 };
99 99
100 /** 100 /**
101 * Create Database with contacts (addressbook). 101 * Create Database with contacts (addressbook).
102 * @param appname Name of application which wants access to the database 102 * @param appname Name of application which wants access to the database
103 * (i.e. "todolist") 103 * (i.e. "todolist")
104 * @param filename The name of the database file. If not set, the default one 104 * @param filename The name of the database file. If not set, the default one
105 * is used. 105 * is used.
106 * @param backend Pointer to an alternative Backend. If not set, we will use 106 * @param backend Pointer to an alternative Backend. If not set, we will use
107 * the default backend. 107 * the default backend.
108 * @param handlesync If <b>true</b> the database stores the current state 108 * @param handlesync If <b>true</b> the database stores the current state
109 * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> 109 * automatically if it receives the signals <i>flush()</i> and <i>reload()</i>
110 * which are used before and after synchronisation. If the application wants 110 * which are used before and after synchronisation. If the application wants
111 * to react itself, it should be disabled by setting it to <b>false</b> 111 * to react itself, it should be disabled by setting it to <b>false</b>
112 * @see OPimContactAccessBackend 112 * @see OPimContactAccessBackend
113 */ 113 */
114 OPimContactAccess (const QString appname, const QString filename = 0l, 114 OPimContactAccess (const QString appname, const QString filename = 0l,
115 OPimContactAccessBackend* backend = 0l, bool handlesync = true); 115 OPimContactAccessBackend* backend = 0l, bool handlesync = true);
116 ~OPimContactAccess (); 116 ~OPimContactAccess ();
117 117
118 118
119 /** 119 /**
120 * Return all possible settings for queryByExample(). 120 * Return all possible settings for queryByExample().
121 * @return All settings provided by the current backend 121 * @return All settings provided by the current backend
122 * (i.e.: WildCards & IgnoreCase) 122 * (i.e.: WildCards & IgnoreCase)
123 * @see QuerySettings in OPimBase for details of the parameter 123 * @see QuerySettings in OPimBase for details of the parameter, queryByExample()
124 */ 124 */
125 const uint querySettings(); 125 const uint querySettings();
126 126
127 /** 127 /**
128 * Check whether settings are correct for queryByExample(). 128 * Check whether settings are correct for queryByExample().
129 * @return <i>true</i> if the given settings are correct and possible. 129 * @return <i>true</i> if the given settings are correct and possible.
130 * @see QuerySettings in OPimBase for details of the parameter 130 * @see QuerySettings in OPimBase for details of the parameter
131 */ 131 */
132 bool hasQuerySettings ( int querySettings ) const; 132 bool hasQuerySettings ( int querySettings ) const;
133 133
134 /** 134 /**
135 * if the resource was changed externally. 135 * if the resource was changed externally.
136 * You should use the signal instead of polling possible changes ! 136 * You should use the signal instead of polling possible changes !
137 */ 137 */
138 bool wasChangedExternally()const; 138 bool wasChangedExternally()const;
139 139
140 140
141 /** Save contacts database. 141 /** Save contacts database.
142 * Save is more a "commit". After calling this function, all changes are public available. 142 * Save is more a "commit". After calling this function, all changes are public available.
143 * @return true if successful 143 * @return true if successful
144 */ 144 */
145 bool save(); 145 bool save();
146 146
147 /** 147 /**
148 * Return identification of used records 148 * Return identification of used records
149 */ 149 */
150 int rtti() const; 150 int rtti() const;
151 151
152 signals: 152 signals:
153 /* Signal is emitted if the database was changed. Therefore 153 /* Signal is emitted if the database was changed. Therefore
154 * we may need to reload to stay consistent. 154 * we may need to reload to stay consistent.
155 * @param which Pointer to the database who created this event. This pointer 155 * @param which Pointer to the database who created this event. This pointer
156 * is useful if an application has to handle multiple databases at the same time. 156 * is useful if an application has to handle multiple databases at the same time.
157 * @see reload() 157 * @see reload()
158 */ 158 */
159 void signalChanged ( const OPimContactAccess *which ); 159 void signalChanged ( const OPimContactAccess *which );
160 160
161 161
162 private: 162 private:
163 OPimContactAccessBackend *m_backEnd; 163 OPimContactAccessBackend *m_backEnd;
164 bool m_loading:1; 164 bool m_loading:1;
165 165
166 private slots: 166 private slots:
167 void copMessage( const QCString &msg, const QByteArray &data ); 167 void copMessage( const QCString &msg, const QByteArray &data );
168 168
169 private: 169 private:
170 class Private; 170 class Private;
171 Private *d; 171 Private *d;
172 172
173}; 173};
174 174
175} 175}
176 176
177#endif 177#endif
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 073d5f9..3875f09 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,553 +1,615 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Holger Freyther <zecke@handhelds.org> 3 Copyright (C) Holger Freyther <zecke@handhelds.org>
4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
6 .=l. 6 .=l.
7 .>+-= 7 .>+-=
8 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
9.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
11.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
12 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
13 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
14 .%`+i> _;_. 14 .%`+i> _;_.
15 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
17 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
21++= -. .` .: details. 21++= -. .` .: details.
22 : = ...= . :.=- 22 : = ...= . :.=-
23 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
24 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
25 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
31#define OPIE_PIM_ACCESS_TEMPLATE_H 31#define OPIE_PIM_ACCESS_TEMPLATE_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimrecord.h> 34#include <opie2/opimrecord.h>
35#include <opie2/opimaccessbackend.h> 35#include <opie2/opimaccessbackend.h>
36#include <opie2/opimrecordlist.h> 36#include <opie2/opimrecordlist.h>
37 37
38#include <opie2/opimtemplatebase.h> 38#include <opie2/opimtemplatebase.h>
39#include <opie2/odebug.h> 39#include <opie2/odebug.h>
40 40
41/* QT */ 41/* QT */
42#include <qarray.h> 42#include <qarray.h>
43#include <qdatetime.h> 43#include <qdatetime.h>
44 44
45namespace Opie { 45namespace Opie {
46 46
47class OPimAccessTemplatePrivate; 47class OPimAccessTemplatePrivate;
48/** 48/**
49 * Thats the frontend to our OPIE PIM 49 * Thats the frontend to our OPIE PIM
50 * Library. Either you want to use it's 50 * Library. Either you want to use it's
51 * interface or you want to implement 51 * interface or you want to implement
52 * your own Access lib 52 * your own Access lib
53 * Just create a OPimRecord and inherit from 53 * Just create a OPimRecord and inherit from
54 * the templates 54 * the templates
55 */ 55 */
56 56
57template <class T = OPimRecord > 57template <class T = OPimRecord >
58class OPimAccessTemplate : public OTemplateBase<T> { 58class OPimAccessTemplate : public OTemplateBase<T> {
59public: 59public:
60 /** 60 /**
61 * 61 *
62 */ 62 */
63 enum Access { 63 enum Access {
64 Random = 0, 64 Random = 0,
65 SortedAccess 65 SortedAccess
66 }; 66 };
67 typedef OPimRecordList<T> List; 67 typedef OPimRecordList<T> List;
68 typedef OPimAccessBackend<T> BackEnd; 68 typedef OPimAccessBackend<T> BackEnd;
69 typedef OPimCache<T> Cache; 69 typedef OPimCache<T> Cache;
70 70
71 //@{ 71 //@{
72 OPimAccessTemplate( BackEnd* end); 72 OPimAccessTemplate( BackEnd* end);
73 virtual ~OPimAccessTemplate(); 73 virtual ~OPimAccessTemplate();
74 //@} 74 //@}
75 75
76 //@{ 76 //@{
77 bool load(); 77 bool load();
78 virtual bool reload(); 78 virtual bool reload();
79 bool save(); 79 bool save();
80 void clear() ; 80 void clear() ;
81 //@} 81 //@}
82 82
83 83
84 bool wasChangedExternally()const; 84 bool wasChangedExternally()const;
85 85
86 //@{ 86 //@{
87 virtual List allRecords()const; 87 virtual List allRecords()const;
88 virtual List matchRegexp( const QRegExp &r ) const; 88 virtual List matchRegexp( const QRegExp &r ) const;
89 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); 89
90 /**
91 * Query by example search interface.
92 * "Query by Example" provides a very powerful search engine. Use the query object
93 * (this may be a contact, a todo or databook event)
94 * as a search mask which is converted into a query regarding the querySettings. If a time period is needed
95 * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the endperiod (the last parameter).
96 * @see QuerySettings in class OPimBase
97 * @param query The object which contains the query set
98 * @param querySettings This parameter defines what should be searched and how the query should be interpreted
99 * @param endperiod Defines the end of a period for some special queries.
100 */
101 virtual List queryByExample( const T& query, int querySettings, const QDateTime& endperiod = QDateTime() );
102
103 /**
104 * Generic query by example search interface. This is a special version which handles generic OPimRecord types. They are converted
105 * automatically into the right datatype.
106 * "Query by Example" provides a very powerful search engine. Use the query object (this may be a contact, a todo or databook event)
107 * as a search mask which is converted into a query regarding the querySettings. If a time period is needed
108 * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the endperiod (the last parameter).
109 * @see QuerySettings in class OPimBase
110 * @param query The object which contains the query set
111 * @param querySettings This parameter defines what should be searched and how the query should be interpreted
112 * @param endperiod Defines the end of a period for some special queries.
113 */
114 virtual List queryByExample( const OPimRecord* query, int querySettings, const QDateTime& endperiod = QDateTime() );
115 /**
116 * Incremental query by example search interface. Providing incremental search, this one provides the feature
117 * to search in a list of records which may be returned by an other search.
118 * "Query by Example" provides a very powerful search engine. Use the query object (this may be a contact, a todo or databook event)
119 * as a search mask which is converted into a query regarding the querySettings. If a time period is needed
120 * (as for OpimBase::DateDiff), you have to use the date/time in the query object and the endperiod (the last parameter).
121 * @see QuerySettings in class OPimBase
122 * @param uidlist List of uid's which should be incorporated into the next search
123 * @param query The object which contains the query set
124 * @param querySettings This parameter defines what should be searched and how the query should be interpreted
125 * @param endperiod Defines the end of a period for some special queries.
126 */
127 virtual List queryByExample( const OPimAccessTemplate::List& uidlist, const T& query, int querySettings,
128 const QDateTime& endperiod = QDateTime() );
129
90 virtual T find( UID uid )const; 130 virtual T find( UID uid )const;
91 virtual T find( UID uid, const QArray<int>&, 131 virtual T find( UID uid, const QArray<int>&,
92 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 132 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
93 //@} 133 //@}
94 134
95 /** 135 /**
96 * Get sorted lists.. 136 * Get sorted lists..
97 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: 137 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params:
98 * @param list of UID's received by allRecords() or others... 138 * @param list of UID's received by allRecords() or others...
99 * @param sortOrder Setting the sort order defined by enum SortOrder 139 * @param sortOrder Setting the sort order defined by enum SortOrder
100 * @param ascending Sort in ascending order if true, otherwise descending 140 * @param ascending Sort in ascending order if true, otherwise descending
101 * @param sortFilter Setting the sort filter defined by enum SortFilter 141 * @param sortFilter Setting the sort filter defined by enum SortFilter
102 * @param cat number of category. 142 * @param cat number of category.
103 */ 143 */
104 virtual List sorted( const List& list, bool ascending, int sortOrder, 144 virtual List sorted( const List& list, bool ascending, int sortOrder,
105 int sortFilter, int cat )const; 145 int sortFilter, int cat )const;
106 146
107 /** 147 /**
108 * Get sorted lists.. 148 * Get sorted lists..
109 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: 149 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params:
110 * @param list of UID's received by allRecords() or others... 150 * @param list of UID's received by allRecords() or others...
111 * @param sortOrder Setting the sort order defined by enum SortOrder 151 * @param sortOrder Setting the sort order defined by enum SortOrder
112 * @param ascending Sort in ascending order if true, otherwise descending 152 * @param ascending Sort in ascending order if true, otherwise descending
113 * @param sortFilter Setting the sort filter defined by enum SortFilter 153 * @param sortFilter Setting the sort filter defined by enum SortFilter
114 * @param cats List of categories. 154 * @param cats List of categories.
115 */ 155 */
116 virtual List sorted( const List& list, bool ascending, int sortOrder, 156 virtual List sorted( const List& list, bool ascending, int sortOrder,
117 int sortFilter, const QArray<UID>& cats )const; 157 int sortFilter, const QArray<UID>& cats )const;
118 158
119 /** 159 /**
120 * Get sorted lists.. 160 * Get sorted lists..
121 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: 161 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params:
122 * @param ascending Sort in ascending order if true, otherwise descending 162 * @param ascending Sort in ascending order if true, otherwise descending
123 * @param sortOrder Setting the sort order defined by enum SortOrder 163 * @param sortOrder Setting the sort order defined by enum SortOrder
124 * @param sortFilter Setting the sort filter defined by enum SortFilter 164 * @param sortFilter Setting the sort filter defined by enum SortFilter
125 * @param cat number of category. 165 * @param cat number of category.
126 */ 166 */
127 virtual List sorted( bool ascending, int sortOrder, int sortFilter, int cat )const; 167 virtual List sorted( bool ascending, int sortOrder, int sortFilter, int cat )const;
128 168
129 /** 169 /**
130 * Get sorted lists.. 170 * Get sorted lists..
131 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params: 171 * @see OPimContactAccess, OPimTodoAccess and ODateBookAccess regarding more info for the following params:
132 * @param ascending Sort in ascending order if true, otherwise descending 172 * @param ascending Sort in ascending order if true, otherwise descending
133 * @param sortOrder Setting the sort order defined by enum SortOrder 173 * @param sortOrder Setting the sort order defined by enum SortOrder
134 * @param sortFilter Setting the sort filter defined by enum SortFilter 174 * @param sortFilter Setting the sort filter defined by enum SortFilter
135 * @param cats List of categories. 175 * @param cats List of categories.
136 */ 176 */
137 virtual List sorted( bool ascending, int sortOrder, int sortFilter, 177 virtual List sorted( bool ascending, int sortOrder, int sortFilter,
138 const QArray<UID>& cats )const; 178 const QArray<UID>& cats )const;
139 /** 179 /**
140 * (Re)Implementation 180 * (Re)Implementation
141 */ 181 */
142 //@{ 182 //@{
143 UIDArray matchRegexpSimple( const QRegExp& r )const; 183 UIDArray matchRegexpSimple( const QRegExp& r )const;
144 UIDArray queryByExampleSimple( const OPimRecord*, int, const QDateTime& )const; 184 UIDArray queryByExampleSimple( const OPimRecord*, int, const QDateTime& )const;
145 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder, 185 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
146 int sortFilter, int cat )const; 186 int sortFilter, int cat )const;
147 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder, 187 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
148 int sortFilter, const QArray<int>& )const; 188 int sortFilter, const QArray<int>& )const;
149 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, 189 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
150 int cat )const; 190 int cat )const;
151 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, 191 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
152 const QArray<int>& )const; 192 const QArray<int>& )const;
153 OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const; 193 OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const;
154 OPimOccurrence::List occurrences( const QDateTime& dt )const; 194 OPimOccurrence::List occurrences( const QDateTime& dt )const;
155 //@} 195 //@}
156 196
157 //@{ 197 //@{
158 virtual bool add( const T& t ) ; 198 virtual bool add( const T& t ) ;
159 bool add( const OPimRecord& ); 199 bool add( const OPimRecord& );
160 bool add( const OPimRecord* ); 200 bool add( const OPimRecord* );
161 virtual bool remove( const T& t ); 201 virtual bool remove( const T& t );
162 bool remove( UID uid ); 202 bool remove( UID uid );
163 bool remove( const OPimRecord& ); 203 bool remove( const OPimRecord& );
164 virtual bool replace( const T& t) ; 204 virtual bool replace( const T& t) ;
165 205
166 //@} 206 //@}
167 207
168 void setReadAhead( uint count ); 208 void setReadAhead( uint count );
169 void cache( const T& )const; 209 void cache( const T& )const;
170 void setSaneCacheSize( int ); 210 void setSaneCacheSize( int );
171 211
172 QArray<UID> records()const; 212 QArray<UID> records()const;
173protected: 213protected:
174 /** 214 /**
175 * invalidate the cache 215 * invalidate the cache
176 */ 216 */
177 void invalidateCache(); 217 void invalidateCache();
178 218
179 void setBackEnd( BackEnd* end ); 219 void setBackEnd( BackEnd* end );
180 /** 220 /**
181 * returns the backend 221 * returns the backend
182 */ 222 */
183 BackEnd* backEnd(); 223 BackEnd* backEnd();
184 BackEnd* m_backEnd; 224 BackEnd* m_backEnd;
185 225
186 Cache m_cache; 226 Cache m_cache;
187 227
188private: 228private:
189 OPimAccessTemplatePrivate *d; 229 OPimAccessTemplatePrivate *d;
190 230
191}; 231};
192 232
193/** 233/**
194 * c'tor BackEnd 234 * c'tor BackEnd
195 * enum Access a small hint on how to handle the backend 235 * enum Access a small hint on how to handle the backend
196 */ 236 */
197template <class T> 237template <class T>
198OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 238OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
199 : OTemplateBase<T>(), m_backEnd( end ) 239 : OTemplateBase<T>(), m_backEnd( end )
200{ 240{
201 if (end ) 241 if (end )
202 end->setFrontend( this ); 242 end->setFrontend( this );
203} 243}
204template <class T> 244template <class T>
205OPimAccessTemplate<T>::~OPimAccessTemplate() { 245OPimAccessTemplate<T>::~OPimAccessTemplate() {
206 delete m_backEnd; 246 delete m_backEnd;
207} 247}
208 248
209/** 249/**
210 * load from the backend 250 * load from the backend
211 */ 251 */
212template <class T> 252template <class T>
213bool OPimAccessTemplate<T>::load() { 253bool OPimAccessTemplate<T>::load() {
214 invalidateCache(); 254 invalidateCache();
215 return m_backEnd->load(); 255 return m_backEnd->load();
216} 256}
217 257
218/** Reload database. 258/** Reload database.
219 * You should execute this function if the external database 259 * You should execute this function if the external database
220 * was changed. 260 * was changed.
221 * This function will load the external database and afterwards 261 * This function will load the external database and afterwards
222 * rejoin the local changes. Therefore the local database will be set consistent. 262 * rejoin the local changes. Therefore the local database will be set consistent.
223 */ 263 */
224template <class T> 264template <class T>
225bool OPimAccessTemplate<T>::reload() { 265bool OPimAccessTemplate<T>::reload() {
226 invalidateCache(); 266 invalidateCache();
227 return m_backEnd->reload(); 267 return m_backEnd->reload();
228} 268}
229 269
230/** 270/**
231 * Save contacts database. 271 * Save contacts database.
232 * Save is more a "commit". After calling this function, all changes are public available. 272 * Save is more a "commit". After calling this function, all changes are public available.
233 * @return true if successful 273 * @return true if successful
234 */ 274 */
235template <class T> 275template <class T>
236bool OPimAccessTemplate<T>::save() { 276bool OPimAccessTemplate<T>::save() {
237 return m_backEnd->save(); 277 return m_backEnd->save();
238} 278}
239 279
240 280
241/** 281/**
242 * return a List of records 282 * return a List of records
243 * you can iterate over them 283 * you can iterate over them
244 */ 284 */
245template <class T> 285template <class T>
246typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 286typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
247 QArray<int> ints = m_backEnd->allRecords(); 287 QArray<int> ints = m_backEnd->allRecords();
248 List lis(ints, this ); 288 List lis(ints, this );
249 return lis; 289 return lis;
250} 290}
251 291
252/** 292/**
253 * return a List of records 293 * return a List of records
254 * that match the regex 294 * that match the regex
255 */ 295 */
256template <class T> 296template <class T>
257typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { 297typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
258 QArray<int> ints = m_backEnd->matchRegexp( r ); 298 QArray<int> ints = m_backEnd->matchRegexp( r );
259 List lis(ints, this ); 299 List lis(ints, this );
260 return lis; 300 return lis;
261} 301}
262 302
263/** 303/**
264 * find the OPimRecord uid 304 * find the OPimRecord uid
265 */ 305 */
266template <class T> 306template <class T>
267QArray<int> OPimAccessTemplate<T>::records()const { 307QArray<int> OPimAccessTemplate<T>::records()const {
268 return m_backEnd->allRecords(); 308 return m_backEnd->allRecords();
269} 309}
270 310
271 311
272/**
273 * queryByExample.
274 * @see otodoaccess, ocontactaccess
275 */
276template <class T> 312template <class T>
277typename OPimAccessTemplate<T>::List 313typename OPimAccessTemplate<T>::List
278OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 314OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
279 QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); 315 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
280 316
281 List lis(ints, this ); 317 List list(ints, this );
282 return lis; 318 return list;
283} 319}
284 320
285template <class T> 321template <class T>
322typename OPimAccessTemplate<T>::List
323OPimAccessTemplate<T>::queryByExample( const OPimRecord* t, int settings, const QDateTime& d ) {
324 T tempInstance;
325
326 if ( t->rtti() == tempInstance.rtti() ) {
327 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
328 List list( ints, this );
329 return list;
330 } else {
331 owarn << "Query not possible: Objecttype mismatch" << oendl;
332 }
333
334 return List();
335}
336
337template <class T>
338typename OPimAccessTemplate<T>::List
339OPimAccessTemplate<T>::queryByExample( const OPimAccessTemplate::List& uidlist, const T& t, int settings, const QDateTime& d ) {
340 QArray<int> ints = m_backEnd->queryByExample( uidlist.uids(), t, settings, d );
341
342 List list( ints, this );
343 return list;
344}
345
346
347template <class T>
286T OPimAccessTemplate<T>::find( UID uid ) const{ 348T OPimAccessTemplate<T>::find( UID uid ) const{
287 // First search in cache.. 349 // First search in cache..
288 if ( m_cache.contains( uid ) ) 350 if ( m_cache.contains( uid ) )
289 return m_cache.find( uid ); 351 return m_cache.find( uid );
290 352
291 T t = m_backEnd->find( uid ); 353 T t = m_backEnd->find( uid );
292 cache( t ); 354 cache( t );
293 355
294 return t; 356 return t;
295} 357}
296 358
297 359
298/** 360/**
299 * read ahead cache find method ;) 361 * read ahead cache find method ;)
300 */ 362 */
301template <class T> 363template <class T>
302T OPimAccessTemplate<T>::find( UID uid, const QArray<int>& ar, 364T OPimAccessTemplate<T>::find( UID uid, const QArray<int>& ar,
303 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 365 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
304 /* 366 /*
305 * better do T.isEmpty() 367 * better do T.isEmpty()
306 * after a find this way we would 368 * after a find this way we would
307 * avoid two finds in QCache... 369 * avoid two finds in QCache...
308 */ 370 */
309 if (m_cache.contains( uid ) ) 371 if (m_cache.contains( uid ) )
310 return m_cache.find( uid ); 372 return m_cache.find( uid );
311 373
312 374
313 T t = m_backEnd->find( uid, ar, current, dir ); 375 T t = m_backEnd->find( uid, ar, current, dir );
314 cache( t ); 376 cache( t );
315 return t; 377 return t;
316} 378}
317 379
318/** 380/**
319 * clears the backend and invalidates the backend 381 * clears the backend and invalidates the backend
320 */ 382 */
321template <class T> 383template <class T>
322void OPimAccessTemplate<T>::clear() { 384void OPimAccessTemplate<T>::clear() {
323 invalidateCache(); 385 invalidateCache();
324 m_backEnd->clear(); 386 m_backEnd->clear();
325} 387}
326 388
327 389
328/** 390/**
329 * add T to the backend 391 * add T to the backend
330 * @param t The item to add. 392 * @param t The item to add.
331 * @return <i>true</i> if added successfully. 393 * @return <i>true</i> if added successfully.
332 */ 394 */
333template <class T> 395template <class T>
334bool OPimAccessTemplate<T>::add( const T& t ) { 396bool OPimAccessTemplate<T>::add( const T& t ) {
335 cache( t ); 397 cache( t );
336 return m_backEnd->add( t ); 398 return m_backEnd->add( t );
337} 399}
338 400
339template <class T> 401template <class T>
340bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { 402bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) {
341 /* same type */ 403 /* same type */
342 T tempInstance; 404 T tempInstance;
343 if ( rec.rtti() == tempInstance.rtti() ) { 405 if ( rec.rtti() == tempInstance.rtti() ) {
344 const T& t = static_cast<const T&>(rec); 406 const T& t = static_cast<const T&>(rec);
345 return add(t); 407 return add(t);
346 } else { 408 } else {
347 owarn << "Adding not possible: Objecttype mismatch" << oendl; 409 owarn << "Adding not possible: Objecttype mismatch" << oendl;
348 } 410 }
349 return false; 411 return false;
350} 412}
351 413
352/** 414/**
353 * Add an Opie PimRecord. 415 * Add an Opie PimRecord.
354 * Info: Take this if you are working with OPimRecords and you need to add it into any database. 416 * Info: Take this if you are working with OPimRecords and you need to add it into any database.
355 * But take care that the accessing database is compatible to the real type of OPimRecord !! 417 * But take care that the accessing database is compatible to the real type of OPimRecord !!
356 * Otherwise this access will be rejected ! 418 * Otherwise this access will be rejected !
357 */ 419 */
358template <class T> 420template <class T>
359bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { 421bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
360 /* same type, but pointer */ 422 /* same type, but pointer */
361 T tempInstance; 423 T tempInstance;
362 if ( rec -> rtti() == tempInstance.rtti() ) { 424 if ( rec -> rtti() == tempInstance.rtti() ) {
363 const T* t = static_cast<const T*>(rec); 425 const T* t = static_cast<const T*>(rec);
364 return add( *t ); 426 return add( *t );
365 } else { 427 } else {
366 owarn << "Adding not possible: Objecttype mismatch" << oendl; 428 owarn << "Adding not possible: Objecttype mismatch" << oendl;
367 } 429 }
368 return false; 430 return false;
369} 431}
370 432
371/** 433/**
372 * remove T from the backend 434 * remove T from the backend
373 * @param t The item to remove 435 * @param t The item to remove
374 * @return <i>true</i> if successful. 436 * @return <i>true</i> if successful.
375 */ 437 */
376template <class T> 438template <class T>
377bool OPimAccessTemplate<T>::remove( const T& t ) { 439bool OPimAccessTemplate<T>::remove( const T& t ) {
378 return remove( t.uid() ); 440 return remove( t.uid() );
379} 441}
380 442
381/** 443/**
382 * remove the OPimRecord with uid 444 * remove the OPimRecord with uid
383 * @param uid The ID of the item to remove 445 * @param uid The ID of the item to remove
384 * @return <i>true</i> if successful. 446 * @return <i>true</i> if successful.
385 */ 447 */
386template <class T> 448template <class T>
387bool OPimAccessTemplate<T>::remove( UID uid ) { 449bool OPimAccessTemplate<T>::remove( UID uid ) {
388 m_cache.remove( uid ); 450 m_cache.remove( uid );
389 return m_backEnd->remove( uid ); 451 return m_backEnd->remove( uid );
390} 452}
391template <class T> 453template <class T>
392bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 454bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
393 return remove( rec.uid() ); 455 return remove( rec.uid() );
394} 456}
395 457
396/** 458/**
397 * replace T from backend 459 * replace T from backend
398 * @param t The item to replace 460 * @param t The item to replace
399 * @return <i>true</i> if successful. 461 * @return <i>true</i> if successful.
400 */ 462 */
401template <class T> 463template <class T>
402bool OPimAccessTemplate<T>::replace( const T& t ) { 464bool OPimAccessTemplate<T>::replace( const T& t ) {
403 m_cache.replace( t ); 465 m_cache.replace( t );
404 return m_backEnd->replace( t ); 466 return m_backEnd->replace( t );
405} 467}
406 468
407/** 469/**
408 * @internal 470 * @internal
409 */ 471 */
410template <class T> 472template <class T>
411void OPimAccessTemplate<T>::invalidateCache() { 473void OPimAccessTemplate<T>::invalidateCache() {
412 m_cache.invalidate(); 474 m_cache.invalidate();
413} 475}
414template <class T> 476template <class T>
415typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 477typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
416 return m_backEnd; 478 return m_backEnd;
417} 479}
418 480
419/** 481/**
420 * if the resource was changed externally 482 * if the resource was changed externally
421 * You should use the signal handling instead of polling possible changes ! 483 * You should use the signal handling instead of polling possible changes !
422 * zecke: Do you implement a signal for otodoaccess ? 484 * zecke: Do you implement a signal for otodoaccess ?
423 */ 485 */
424template <class T> 486template <class T>
425bool OPimAccessTemplate<T>::wasChangedExternally()const { 487bool OPimAccessTemplate<T>::wasChangedExternally()const {
426 return false; 488 return false;
427} 489}
428template <class T> 490template <class T>
429void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 491void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
430 m_backEnd = end; 492 m_backEnd = end;
431 if (m_backEnd ) 493 if (m_backEnd )
432 m_backEnd->setFrontend( this ); 494 m_backEnd->setFrontend( this );
433} 495}
434template <class T> 496template <class T>
435void OPimAccessTemplate<T>::cache( const T& t ) const{ 497void OPimAccessTemplate<T>::cache( const T& t ) const{
436 /* hacky we need to work around the const*/ 498 /* hacky we need to work around the const*/
437 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 499 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
438} 500}
439template <class T> 501template <class T>
440void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 502void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
441 m_cache.setSize( size ); 503 m_cache.setSize( size );
442} 504}
443template <class T> 505template <class T>
444void OPimAccessTemplate<T>::setReadAhead( uint count ) { 506void OPimAccessTemplate<T>::setReadAhead( uint count ) {
445 m_backEnd->setReadAhead( count ); 507 m_backEnd->setReadAhead( count );
446} 508}
447 509
448 510
449template <class T> 511template <class T>
450typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst, 512typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
451 bool ascending, int sortOrder, 513 bool ascending, int sortOrder,
452 int sortFilter, int cat )const { 514 int sortFilter, int cat )const {
453 QArray<int> cats( 1 ); 515 QArray<int> cats( 1 );
454 cats[0] = cat; 516 cats[0] = cat;
455 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder, 517 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
456 sortFilter, cats ); 518 sortFilter, cats );
457 return List(ints, this); 519 return List(ints, this);
458} 520}
459 521
460template<class T> 522template<class T>
461typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst, 523typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
462 bool ascending, int sortOrder, 524 bool ascending, int sortOrder,
463 int sortFilter, const QArray<UID>& cats )const { 525 int sortFilter, const QArray<UID>& cats )const {
464 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder, 526 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
465 sortFilter, cats ); 527 sortFilter, cats );
466 return List(ints, this); 528 return List(ints, this);
467} 529}
468 530
469template<class T> 531template<class T>
470typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder, 532typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
471 int sortFilter, int cat )const { 533 int sortFilter, int cat )const {
472 QArray<int> cats( 1 ); 534 QArray<int> cats( 1 );
473 cats[0] = cat; 535 cats[0] = cat;
474 UIDArray ints = m_backEnd->sorted( ascending, sortOrder, 536 UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
475 sortFilter, cats ); 537 sortFilter, cats );
476 return List(ints, this); 538 return List(ints, this);
477} 539}
478 540
479template<class T> 541template<class T>
480typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder, 542typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
481 int sortFilter, const QArray<UID>& cats )const { 543 int sortFilter, const QArray<UID>& cats )const {
482 UIDArray ints = m_backEnd->sorted( ascending, sortOrder, 544 UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
483 sortFilter, cats ); 545 sortFilter, cats );
484 return List(ints, this); 546 return List(ints, this);
485} 547}
486 548
487template <class T> 549template <class T>
488OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDate& start, 550OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDate& start,
489 const QDate& end ) const { 551 const QDate& end ) const {
490 /* 552 /*
491 * Some magic involved to go from single OPimBackendOccurrence 553 * Some magic involved to go from single OPimBackendOccurrence
492 * to multiple OPimOccurrence's 554 * to multiple OPimOccurrence's
493 */ 555 */
494 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( start, end ) ); 556 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( start, end ) );
495} 557}
496 558
497template<class T> 559template<class T>
498OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDateTime& dt )const { 560OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDateTime& dt )const {
499 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( dt ) ); 561 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( dt ) );
500} 562}
501 563
502/* 564/*
503 *Implementations!! 565 *Implementations!!
504 */ 566 */
505template <class T> 567template <class T>
506UIDArray OPimAccessTemplate<T>::matchRegexpSimple( const QRegExp &r )const { 568UIDArray OPimAccessTemplate<T>::matchRegexpSimple( const QRegExp &r )const {
507 return m_backEnd->matchRegexp( r ); 569 return m_backEnd->matchRegexp( r );
508} 570}
509 571
510template <class T> 572template <class T>
511UIDArray OPimAccessTemplate<T>::queryByExampleSimple( const OPimRecord* rec, 573UIDArray OPimAccessTemplate<T>::queryByExampleSimple( const OPimRecord* rec,
512 int settings, 574 int settings,
513 const QDateTime& d )const { 575 const QDateTime& d )const {
514 return m_backEnd->queryByExample( rec, settings, d ); 576 return m_backEnd->queryByExample( rec, settings, d );
515} 577}
516 578
517template <class T> 579template <class T>
518UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst, 580UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
519 bool ascending, 581 bool ascending,
520 int sortOrder, int sortFilter, 582 int sortOrder, int sortFilter,
521 int cat ) const{ 583 int cat ) const{
522 QArray<int> cats( 1 ); 584 QArray<int> cats( 1 );
523 cats[0] = cat; 585 cats[0] = cat;
524 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats ); 586 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
525} 587}
526 588
527template <class T> 589template <class T>
528UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst, 590UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
529 bool ascending, 591 bool ascending,
530 int sortOrder, int sortFilter, 592 int sortOrder, int sortFilter,
531 const QArray<int>& cats ) const{ 593 const QArray<int>& cats ) const{
532 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats ); 594 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
533} 595}
534 596
535template <class T> 597template <class T>
536UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending, 598UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
537 int sortOrder, int sortFilter, 599 int sortOrder, int sortFilter,
538 int cat ) const{ 600 int cat ) const{
539 QArray<int> cats( 1 ); 601 QArray<int> cats( 1 );
540 cats[0] = cat; 602 cats[0] = cat;
541 603
542 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats ); 604 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
543} 605}
544 606
545template <class T> 607template <class T>
546UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending, 608UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
547 int sortOrder, int sortFilter, 609 int sortOrder, int sortFilter,
548 const QArray<int>& cats ) const{ 610 const QArray<int>& cats ) const{
549 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats ); 611 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
550} 612}
551} 613}
552 614
553#endif 615#endif
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
index c8abab4..075e573 100644
--- a/libopie2/opiepim/core/opimtemplatebase.h
+++ b/libopie2/opiepim/core/opimtemplatebase.h
@@ -1,242 +1,242 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Holger Freyther <zecke@handhelds.org> 3 Copyright (C) Holger Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OTEMPLATEBASE_H 29#ifndef OTEMPLATEBASE_H
30#define OTEMPLATEBASE_H 30#define OTEMPLATEBASE_H
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimrecord.h> 33#include <opie2/opimrecord.h>
34#include <opie2/opimcache.h> 34#include <opie2/opimcache.h>
35#include <opie2/opimoccurrence.h> 35#include <opie2/opimoccurrence.h>
36#include <opie2/opimbackendoccurrence.h> 36#include <opie2/opimbackendoccurrence.h>
37 37
38/* QT */ 38/* QT */
39#include <qarray.h> 39#include <qarray.h>
40#include <qdatetime.h> 40#include <qdatetime.h>
41 41
42namespace Opie { 42namespace Opie {
43 43
44class OPimBasePrivate; 44class OPimBasePrivate;
45 45
46/** 46/**
47 * This is the base class for all our Interfaces to the 47 * This is the base class for all our Interfaces to the
48 * PIM Records. It is pointer based and can be used 48 * PIM Records. It is pointer based and can be used
49 * generically for all types of Records. 49 * generically for all types of Records.
50 * 50 *
51 */ 51 */
52struct OPimBase { 52struct OPimBase {
53 //@{ 53 //@{
54 OPimBase(); 54 OPimBase();
55 virtual ~OPimBase(); 55 virtual ~OPimBase();
56 //@} 56 //@}
57 57
58 //@{ 58 //@{
59 /** 59 /**
60 * return the rtti 60 * return the rtti
61 */ 61 */
62 virtual int rtti() const = 0; 62 virtual int rtti() const = 0;
63 virtual OPimRecord* record()const = 0; 63 virtual OPimRecord* record()const = 0;
64 virtual OPimRecord* record(int uid)const = 0; 64 virtual OPimRecord* record(int uid)const = 0;
65 //@} 65 //@}
66 66
67 //@{ 67 //@{
68 virtual bool add( const OPimRecord& ) = 0; 68 virtual bool add( const OPimRecord& ) = 0;
69 virtual bool add( const OPimRecord* ) = 0; 69 virtual bool add( const OPimRecord* ) = 0;
70 70
71 virtual bool remove( int uid ) = 0; 71 virtual bool remove( int uid ) = 0;
72 virtual bool remove( const OPimRecord& ) = 0; 72 virtual bool remove( const OPimRecord& ) = 0;
73 //@} 73 //@}
74 74
75 //@{ 75 //@{
76 virtual void clear() = 0; 76 virtual void clear() = 0;
77 virtual bool load() = 0; 77 virtual bool load() = 0;
78 virtual bool save() = 0; 78 virtual bool save() = 0;
79 //@} 79 //@}
80 80
81 //@{ 81 //@{
82 virtual QArray<UID> records()const = 0; 82 virtual QArray<UID> records()const = 0;
83 //@} 83 //@}
84 84
85 /** Constants for query. 85 /** Constants for query.
86 * Use this constants to set the query parameters. 86 * Use this constants to set the query parameters.
87 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! 87 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
88 * @see queryByExample() 88 * @see queryByExample()
89 */ 89 */
90 enum QuerySettings { 90 enum QuerySettings {
91 /** Use Wildcards */ 91 /** Use Wildcards */
92 WildCards = 0x0001, 92 WildCards = 0x0001,
93 /** Ignore the Case */ 93 /** Ignore the Case */
94 IgnoreCase = 0x0002, 94 IgnoreCase = 0x0002,
95 /** Do a Regular Expression match */ 95 /** Do a Regular Expression match */
96 RegExp = 0x0004, 96 RegExp = 0x0004,
97 /** It needs to exactly match */ 97 /** It needs to exactly match */
98 ExactMatch = 0x0008, 98 ExactMatch = 0x0008,
99 /** Only one Entry must match */ 99 /** Only one Entry must match */
100 MatchOne = 0x0010, 100 MatchOne = 0x0010,
101 /** Find all entries from today until given date */ 101 /** Find all entries from today until given date */
102 DateDiff = 0x0020, 102 DateDiff = 0x0020,
103 /** The year matches */ 103 /** The year matches */
104 DateYear = 0x0040, 104 DateYear = 0x0040,
105 /** The month matches */ 105 /** The month matches */
106 DateMonth = 0x0080, 106 DateMonth = 0x0080,
107 /** The day matches */ 107 /** The day matches */
108 DateDay = 0x0100, 108 DateDay = 0x0100,
109 /** The last possible name matches */ 109 /** The last possible name matches */
110 LastItem = 0xffff 110 LastItem = 0xffff
111 }; 111 };
112 112
113 /** 113 /**
114 * Common Attributes for the Sort Order 114 * Common Attributes for the Sort Order
115 */ 115 */
116 enum SortOrderBase { 116 enum SortOrderBase {
117 /** Sort by a Summary of the records */ 117 /** Sort by a Summary of the records */
118 SortSummary = 0, 118 SortSummary = 0,
119 /** Sort by Category */ 119 /** Sort by Category */
120 SortByCategory = 1, 120 SortByCategory = 1,
121 /** Sort by Date */ 121 /** Sort by Date */
122 SortByDate = 2, 122 SortByDate = 2,
123 /** The First available sort number for the OPimAccessTemplates */ 123 /** The First available sort number for the OPimAccessTemplates */
124 SortCustom = 10, 124 SortCustom = 10,
125 /** make this enum 16bit large */ 125 /** make this enum 16bit large */
126 LastSortOrderBase = 0xffff 126 LastSortOrderBase = 0xffff
127 }; 127 };
128 128
129 /** 129 /**
130 * Sort a list of Items with the help of the sorted() function. 130 * Sort a list of Items with the help of the sorted() function.
131 * The Item you provide in SortOrder will be used 131 * The Item you provide in SortOrder will be used
132 * for sorting. 132 * for sorting.
133 * 133 *
134 * @see OPimAccessTemplate<>::sorted() 134 * @see OPimAccessTemplate<>::sorted()
135 */ 135 */
136 enum SortFilterBase { 136 enum SortFilterBase {
137 /** Do not filter anything. */ 137 /** Do not filter anything. */
138 FilterOff = 0, 138 FilterOff = 0,
139 /** Use given Categories for filter */ 139 /** Use given Categories for filter */
140 FilterCategory = 1, 140 FilterCategory = 1,
141 /** The first available custom filter defined in the specialized frontends */ 141 /** The first available custom filter defined in the specialized frontends */
142 FilterCustom = 1024, 142 FilterCustom = 1024,
143 LastSortFilterBase = 0xffffffff 143 LastSortFilterBase = 0xffffffff
144 }; 144 };
145 145
146 virtual UIDArray matchRegexpSimple( const QRegExp& r )const = 0; 146 virtual UIDArray matchRegexpSimple( const QRegExp& r )const = 0;
147 virtual UIDArray queryByExampleSimple( const OPimRecord*, int settings, 147 virtual UIDArray queryByExampleSimple( const OPimRecord*, int settings,
148 const QDateTime& d = QDateTime() )const = 0; 148 const QDateTime& d = QDateTime() )const = 0;
149 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending, 149 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
150 int sortOrder, int sortFilter, int cat)const = 0; 150 int sortOrder, int sortFilter, int cat)const = 0;
151 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending, 151 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
152 int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0; 152 int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
153 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, int cat)const = 0; 153 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, int cat)const = 0;
154 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0; 154 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
155 virtual OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const = 0; 155 virtual OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const = 0;
156 virtual OPimOccurrence::List occurrences( const QDateTime& dt )const = 0; 156 virtual OPimOccurrence::List occurrences( const QDateTime& dt )const = 0;
157 //@} 157 //@}
158 158
159 159
160protected: 160protected:
161 OPimOccurrence::List convertOccurrenceFromBackend( const OPimBackendOccurrence::List& )const; 161 OPimOccurrence::List convertOccurrenceFromBackend( const OPimBackendOccurrence::List& )const;
162 162
163private: 163private:
164 OPimBasePrivate* d; 164 OPimBasePrivate* d;
165}; 165};
166 166
167 167
168/** 168/**
169 * internal template base 169 * internal template base
170 * Attention: T needs to implement the copy c'tor!!! 170 * Attention: T needs to implement the copy c'tor!!!
171 */ 171 */
172class OTemplateBasePrivate; 172class OTemplateBasePrivate;
173template <class T = OPimRecord> 173template <class T = OPimRecord>
174class OTemplateBase : public OPimBase { 174class OTemplateBase : public OPimBase {
175public: 175public:
176 /** 176 /**
177 * The Direction for ReadAhead/ReadBehind which will 177 * The Direction for ReadAhead/ReadBehind which will
178 * be used by the backends to Cache Items in 178 * be used by the backends to Cache Items in
179 * advance. 179 * advance.
180 * For example if you know that you will access the 180 * For example if you know that you will access the
181 * next ten items you can give the backend a hint 181 * next ten items you can give the backend a hint
182 * to read ahead or read before. 182 * to read ahead or read before.
183 */ 183 */
184 enum CacheDirection { 184 enum CacheDirection {
185 Forward=0, /** Go forward when caching (++ to the index) */ 185 Forward=0, /** Go forward when caching (++ to the index) */
186 Reverse /** Go backward when caching (-- to the index) */ 186 Reverse /** Go backward when caching (-- to the index) */
187 }; 187 };
188 188
189 189
190 //@{ 190 //@{
191 OTemplateBase() {}; 191 OTemplateBase() {};
192 virtual ~OTemplateBase() {} 192 virtual ~OTemplateBase() {}
193 //@} 193 //@}
194 194
195 195
196 //@{ 196 //@{
197 virtual T find( int uid )const = 0; 197 virtual T find( int uid )const = 0;
198 198
199 /** 199 /**
200 * read ahead find 200 * read ahead find
201 */ 201 */
202 virtual T find( int uid, const QArray<int>& items, 202 virtual T find( int uid, const QArray<int>& items,
203 uint current, CacheDirection dir = Forward )const = 0; 203 uint current, CacheDirection dir = Forward )const = 0;
204 //@} 204 //@}
205 205
206 //@{ 206 //@{
207 /** 207 /**
208 * Put element into Cache 208 * Put element into Cache
209 */ 209 */
210 virtual void cache( const T& )const = 0; 210 virtual void cache( const T& )const = 0;
211 virtual void setSaneCacheSize( int ) = 0; 211 virtual void setSaneCacheSize( int ) = 0;
212 212
213 OPimRecord* record()const; 213 OPimRecord* record()const;
214 OPimRecord* record(int uid )const; 214 OPimRecord* record(int uid )const;
215 static T* rec(); 215 static T* rec();
216 //@} 216 //@}
217 217
218private: 218private:
219 OTemplateBasePrivate *d; 219 OTemplateBasePrivate *d;
220}; 220};
221 221
222 222
223template <class T> 223template <class T>
224OPimRecord* OTemplateBase<T>::record()const { 224OPimRecord* OTemplateBase<T>::record()const {
225 T* t = new T; 225 T* t = new T;
226 return t; 226 return t;
227} 227}
228template <class T> 228template <class T>
229OPimRecord* OTemplateBase<T>::record(int uid )const { 229OPimRecord* OTemplateBase<T>::record(int uid )const {
230 T t2 = find(uid ); 230 T t2 = find(uid );
231 T* t1 = new T(t2); 231 T* t1 = new T(t2);
232 232
233 return t1; 233 return t1;
234} 234}
235 235
236template <class T> 236template <class T>
237T* OTemplateBase<T>::rec() { 237T* OTemplateBase<T>::rec() {
238 return new T; 238 return new T;
239} 239}
240} 240}
241 241
242#endif 242#endif