author | eilers <eilers> | 2005-01-16 19:54:28 (UTC) |
---|---|---|
committer | eilers <eilers> | 2005-01-16 19:54:28 (UTC) |
commit | 37f290f048eeade1036cd1dc2239d2a98412c54b (patch) (unidiff) | |
tree | 04dea39ccf2725f4992d5b8bdbf12807e9a67ae2 /libopie2/opiepim/backend | |
parent | 07a4cf7e277aee7097c4da286a2559b717054362 (diff) | |
download | opie-37f290f048eeade1036cd1dc2239d2a98412c54b.zip opie-37f290f048eeade1036cd1dc2239d2a98412c54b.tar.gz opie-37f290f048eeade1036cd1dc2239d2a98412c54b.tar.bz2 |
Added new generic sorted for the databook backends. Needed an sortedvector
to do this job, which is now added to private classes..
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend.cpp | 58 |
3 files changed, 60 insertions, 6 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.cpp b/libopie2/opiepim/backend/ocontactaccessbackend.cpp index b4fdd46..c09427c 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend.cpp | |||
@@ -1,19 +1,20 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2004 Holger Freyther <freyther@handhelds.org> | 3 | Copyright (C) Holger Freyther <freyther@handhelds.org> |
4 | Copyright (C) Stefan Eilers <stefan@eilers-online.net> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 5 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 6 | .=l. |
6 | .>+-= | 7 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 14 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
@@ -224,33 +225,33 @@ bool OPimContactAccessBackend::hasQuerySettings (uint querySettings) const | |||
224 | ){ | 225 | ){ |
225 | case OPimContactAccess::RegExp: | 226 | case OPimContactAccess::RegExp: |
226 | return ( true ); | 227 | return ( true ); |
227 | case OPimContactAccess::WildCards: | 228 | case OPimContactAccess::WildCards: |
228 | return ( true ); | 229 | return ( true ); |
229 | case OPimContactAccess::ExactMatch: | 230 | case OPimContactAccess::ExactMatch: |
230 | return ( true ); | 231 | return ( true ); |
231 | case 0: // one of the upper removed bits were set.. | 232 | case 0: // one of the upper removed bits were set.. |
232 | return ( true ); | 233 | return ( true ); |
233 | default: | 234 | default: |
234 | return ( false ); | 235 | return ( false ); |
235 | } | 236 | } |
236 | } | 237 | } |
237 | 238 | ||
238 | 239 | ||
239 | UIDArray OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, | 240 | UIDArray OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, |
240 | int filter, const QArray<int>& categories)const { | 241 | int filter, const QArray<int>& categories )const { |
241 | odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl; | 242 | odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl; |
242 | 243 | ||
243 | Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder ); | 244 | Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder ); |
244 | 245 | ||
245 | int item = 0; | 246 | int item = 0; |
246 | uint cat_count = categories.count(); | 247 | uint cat_count = categories.count(); |
247 | uint eve_count = ar.count(); | 248 | uint eve_count = ar.count(); |
248 | bool bCat = filter & OPimContactAccess::FilterCategory ? true : false; | 249 | bool bCat = filter & OPimContactAccess::FilterCategory ? true : false; |
249 | bool catPassed = false; | 250 | bool catPassed = false; |
250 | int cat; | 251 | int cat; |
251 | 252 | ||
252 | for ( uint i = 0; i < eve_count; ++i ) { | 253 | for ( uint i = 0; i < eve_count; ++i ) { |
253 | OPimContact contact = find( ar[i], ar, i, Frontend::Forward ); | 254 | OPimContact contact = find( ar[i], ar, i, Frontend::Forward ); |
254 | if ( contact.isEmpty() ) | 255 | if ( contact.isEmpty() ) |
255 | continue; | 256 | continue; |
256 | 257 | ||
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index 27d70ab..d5c463b 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -1,19 +1,20 @@ | |||
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) Holger Freyther <freyther@handhelds.org> |
4 | Copyright (C) Stefan Eilers <stefan@eilers-online.net> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 5 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 6 | .=l. |
6 | .>+-= | 7 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 14 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp index e44912a..6da0170 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp | |||
@@ -15,35 +15,37 @@ | |||
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 | #include <qtl.h> | 29 | #include <qtl.h> |
30 | 30 | ||
31 | #include <opie2/odebug.h> | ||
31 | #include <opie2/opimrecurrence.h> | 32 | #include <opie2/opimrecurrence.h> |
32 | 33 | #include <opie2/odatebookaccess.h> | |
33 | #include <opie2/odatebookaccessbackend.h> | 34 | #include <opie2/odatebookaccessbackend.h> |
35 | #include <opie2/private/opimeventsortvector.h> | ||
34 | 36 | ||
35 | using namespace Opie; | 37 | using namespace Opie; |
36 | 38 | ||
37 | namespace { | 39 | namespace { |
38 | /* a small helper to get all NonRepeating events for a range of time */ | 40 | /* a small helper to get all NonRepeating events for a range of time */ |
39 | void events( OPimBackendOccurrence::List& tmpList, | 41 | void events( OPimBackendOccurrence::List& tmpList, |
40 | const OPimEvent::ValueList& events, | 42 | const OPimEvent::ValueList& events, |
41 | const QDate& from, const QDate& to ) { | 43 | const QDate& from, const QDate& to ) { |
42 | QDateTime dtStart, dtEnd; | 44 | QDateTime dtStart, dtEnd; |
43 | 45 | ||
44 | for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { | 46 | for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { |
45 | dtStart = (*it).startDateTime(); | 47 | dtStart = (*it).startDateTime(); |
46 | dtEnd = (*it).endDateTime(); | 48 | dtEnd = (*it).endDateTime(); |
47 | 49 | ||
48 | /* | 50 | /* |
49 | * If in range | 51 | * If in range |
@@ -131,34 +133,84 @@ const uint ODateBookAccessBackend::querySettings() const | |||
131 | } | 133 | } |
132 | 134 | ||
133 | bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const | 135 | bool ODateBookAccessBackend::hasQuerySettings (uint querySettings) const |
134 | { | 136 | { |
135 | return false; | 137 | return false; |
136 | } | 138 | } |
137 | 139 | ||
138 | 140 | ||
139 | 141 | ||
140 | UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings, | 142 | UIDArray ODateBookAccessBackend::queryByExample( const UIDArray& uidlist, const OPimEvent&, int settings, |
141 | const QDateTime& d )const | 143 | const QDateTime& d )const |
142 | { | 144 | { |
143 | qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" ); | 145 | qDebug( "Accessing ODateBookAccessBackend::queryByExample() which is not implemented!" ); |
144 | return UIDArray(); | 146 | return UIDArray(); |
145 | } | 147 | } |
146 | 148 | ||
147 | UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const { | 149 | UIDArray ODateBookAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, int filter, const QArray<int>& categories )const { |
148 | return UIDArray(); | 150 | odebug << "Using Unaccelerated ODateBookAccessBackend sorted Implementation" << oendl; |
151 | |||
152 | Internal::OPimEventSortVector vector( ar.count(), asc, sortOrder ); | ||
153 | int item = 0; | ||
154 | |||
155 | for ( uint i = 0; i < ar.count(); ++i ){ | ||
156 | OPimEvent event = find( ar[i], ar, i, Frontend::Forward ); | ||
157 | if ( event.isEmpty() ) | ||
158 | continue; | ||
159 | |||
160 | bool catPassed = true; | ||
161 | if ( filter & ODateBookAccess::FilterCategory ){ | ||
162 | catPassed = false; | ||
163 | // Filter Categories | ||
164 | for ( uint cat_idx = 0; cat_idx < categories.count(); ++cat_idx ){ | ||
165 | int cat = categories[cat_idx]; | ||
166 | if ( cat == -1 || cat == 0 ){ | ||
167 | // Unfiled. Check next category if list is not empty. | ||
168 | // Else: take it as we will not filter unfiled events.. | ||
169 | if ( !event.categories().isEmpty() ) | ||
170 | continue; | ||
171 | else | ||
172 | catPassed = true; | ||
173 | } else { | ||
174 | if ( !event.categories().contains( cat ) ) | ||
175 | continue; | ||
176 | else{ | ||
177 | catPassed = true; | ||
178 | break; | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | |||
184 | // Continue to next event if the category filter removed this item | ||
185 | if ( !catPassed ) | ||
186 | continue; | ||
187 | |||
188 | vector.insert( item++, event ); | ||
189 | } | ||
190 | |||
191 | // Now sort the vector and return the list of UID's | ||
192 | vector.resize( item ); | ||
193 | vector.sort(); | ||
194 | |||
195 | UIDArray array( vector.count() ); | ||
196 | for ( uint i= 0; i < vector.count(); i++ ) | ||
197 | array[i] = vector.uidAt( i ); | ||
198 | |||
199 | return array; | ||
200 | |||
149 | } | 201 | } |
150 | 202 | ||
151 | OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, | 203 | OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList, |
152 | const QDateTime& dt ) { | 204 | const QDateTime& dt ) { |
153 | OPimBackendOccurrence::List tmpList; | 205 | OPimBackendOccurrence::List tmpList; |
154 | OPimBackendOccurrence::List::ConstIterator it; | 206 | OPimBackendOccurrence::List::ConstIterator it; |
155 | 207 | ||
156 | for ( it = dayList.begin(); it != dayList.end(); ++it ) { | 208 | for ( it = dayList.begin(); it != dayList.end(); ++it ) { |
157 | OPimBackendOccurrence occ = *it; | 209 | OPimBackendOccurrence occ = *it; |
158 | 210 | ||
159 | /* | 211 | /* |
160 | * Let us find occurrences that are 'now'! | 212 | * Let us find occurrences that are 'now'! |
161 | * If the dt.date() is on the same day as start or end of the Occurrence | 213 | * If the dt.date() is on the same day as start or end of the Occurrence |
162 | * check how near start/end are. | 214 | * check how near start/end are. |
163 | * If it is in the middle of a multiday occurrence list it. | 215 | * If it is in the middle of a multiday occurrence list it. |
164 | * | 216 | * |