Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | 205 |
1 files changed, 6 insertions, 199 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index 5df7253..f96f1bf 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -180,15 +180,15 @@ bool OPimContactAccessBackend_XML::wasChangedExternally() | |||
180 | 180 | ||
181 | QDateTime lastmod = fi.lastModified (); | 181 | QDateTime lastmod = fi.lastModified (); |
182 | 182 | ||
183 | return (lastmod != m_readtime); | 183 | return (lastmod != m_readtime); |
184 | } | 184 | } |
185 | 185 | ||
186 | QArray<int> OPimContactAccessBackend_XML::allRecords() const | 186 | UIDArray OPimContactAccessBackend_XML::allRecords() const |
187 | { | 187 | { |
188 | QArray<int> uid_list( m_contactList.count() ); | 188 | UIDArray uid_list( m_contactList.count() ); |
189 | 189 | ||
190 | uint counter = 0; | 190 | uint counter = 0; |
191 | QListIterator<OPimContact> it( m_contactList ); | 191 | QListIterator<OPimContact> it( m_contactList ); |
192 | for( ; it.current(); ++it ){ | 192 | for( ; it.current(); ++it ){ |
193 | uid_list[counter++] = (*it)->uid(); | 193 | uid_list[counter++] = (*it)->uid(); |
194 | } | 194 | } |
@@ -206,151 +206,16 @@ OPimContact OPimContactAccessBackend_XML::find ( int uid ) const | |||
206 | foundContact = *found; | 206 | foundContact = *found; |
207 | } | 207 | } |
208 | 208 | ||
209 | return ( foundContact ); | 209 | return ( foundContact ); |
210 | } | 210 | } |
211 | 211 | ||
212 | QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, | ||
213 | const QDateTime& d )const | ||
214 | { | ||
215 | QArray<int> m_currentQuery( m_contactList.count() ); | ||
216 | QListIterator<OPimContact> it( m_contactList ); | ||
217 | uint arraycounter = 0; | ||
218 | |||
219 | for( ; it.current(); ++it ){ | ||
220 | /* Search all fields and compare them with query object. Store them into list | ||
221 | * if all fields matches. | ||
222 | */ | ||
223 | QDate* queryDate = 0l; | ||
224 | QDate* checkDate = 0l; | ||
225 | bool allcorrect = true; | ||
226 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | ||
227 | // Birthday and anniversary are special nonstring fields and should | ||
228 | // be handled specially | ||
229 | switch ( i ){ | ||
230 | case Qtopia::Birthday: | ||
231 | queryDate = new QDate( query.birthday() ); | ||
232 | checkDate = new QDate( (*it)->birthday() ); | ||
233 | // fall through | ||
234 | case Qtopia::Anniversary: | ||
235 | if ( queryDate == 0l ){ | ||
236 | queryDate = new QDate( query.anniversary() ); | ||
237 | checkDate = new QDate( (*it)->anniversary() ); | ||
238 | } | ||
239 | |||
240 | if ( queryDate->isValid() ){ | ||
241 | if( checkDate->isValid() ){ | ||
242 | if ( settings & OPimContactAccess::DateYear ){ | ||
243 | if ( queryDate->year() != checkDate->year() ) | ||
244 | allcorrect = false; | ||
245 | } | ||
246 | if ( settings & OPimContactAccess::DateMonth ){ | ||
247 | if ( queryDate->month() != checkDate->month() ) | ||
248 | allcorrect = false; | ||
249 | } | ||
250 | if ( settings & OPimContactAccess::DateDay ){ | ||
251 | if ( queryDate->day() != checkDate->day() ) | ||
252 | allcorrect = false; | ||
253 | } | ||
254 | if ( settings & OPimContactAccess::DateDiff ) { | ||
255 | QDate current; | ||
256 | // If we get an additional date, we | ||
257 | // will take this date instead of | ||
258 | // the current one.. | ||
259 | if ( !d.date().isValid() ) | ||
260 | current = QDate::currentDate(); | ||
261 | else | ||
262 | current = d.date(); | ||
263 | |||
264 | // We have to equalize the year, otherwise | ||
265 | // the search will fail.. | ||
266 | checkDate->setYMD( current.year(), | ||
267 | checkDate->month(), | ||
268 | checkDate->day() ); | ||
269 | if ( *checkDate < current ) | ||
270 | checkDate->setYMD( current.year()+1, | ||
271 | checkDate->month(), | ||
272 | checkDate->day() ); | ||
273 | |||
274 | // Check whether the birthday/anniversary date is between | ||
275 | // the current/given date and the maximum date | ||
276 | // ( maximum time range ) ! | ||
277 | if ( current.daysTo( *queryDate ) >= 0 ){ | ||
278 | if ( !( ( *checkDate >= current ) && | ||
279 | ( *checkDate <= *queryDate ) ) ){ | ||
280 | allcorrect = false; | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | } else{ | ||
285 | // checkDate is invalid. Therefore this entry is always rejected | ||
286 | allcorrect = false; | ||
287 | } | ||
288 | } | ||
289 | 212 | ||
290 | delete queryDate; | 213 | UIDArray OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
291 | queryDate = 0l; | ||
292 | delete checkDate; | ||
293 | checkDate = 0l; | ||
294 | break; | ||
295 | default: | ||
296 | /* Just compare fields which are not empty in the query object */ | ||
297 | if ( !query.field(i).isEmpty() ){ | ||
298 | switch ( settings & ~( OPimContactAccess::IgnoreCase | ||
299 | | OPimContactAccess::DateDiff | ||
300 | | OPimContactAccess::DateYear | ||
301 | | OPimContactAccess::DateMonth | ||
302 | | OPimContactAccess::DateDay | ||
303 | | OPimContactAccess::MatchOne | ||
304 | ) ){ | ||
305 | |||
306 | case OPimContactAccess::RegExp:{ | ||
307 | QRegExp expr ( query.field(i), | ||
308 | !(settings & OPimContactAccess::IgnoreCase), | ||
309 | false ); | ||
310 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | ||
311 | allcorrect = false; | ||
312 | } | ||
313 | break; | ||
314 | case OPimContactAccess::WildCards:{ | ||
315 | QRegExp expr ( query.field(i), | ||
316 | !(settings & OPimContactAccess::IgnoreCase), | ||
317 | true ); | ||
318 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | ||
319 | allcorrect = false; | ||
320 | } | ||
321 | break; | ||
322 | case OPimContactAccess::ExactMatch:{ | ||
323 | if (settings & OPimContactAccess::IgnoreCase){ | ||
324 | if ( query.field(i).upper() != | ||
325 | (*it)->field(i).upper() ) | ||
326 | allcorrect = false; | ||
327 | }else{ | ||
328 | if ( query.field(i) != (*it)->field(i) ) | ||
329 | allcorrect = false; | ||
330 | } | ||
331 | } | ||
332 | break; | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | } | ||
337 | if ( allcorrect ){ | ||
338 | m_currentQuery[arraycounter++] = (*it)->uid(); | ||
339 | } | ||
340 | } | ||
341 | |||
342 | // Shrink to fit.. | ||
343 | m_currentQuery.resize(arraycounter); | ||
344 | |||
345 | return m_currentQuery; | ||
346 | } | ||
347 | |||
348 | QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | ||
349 | { | 214 | { |
350 | QArray<int> m_currentQuery( m_contactList.count() ); | 215 | UIDArray m_currentQuery( m_contactList.count() ); |
351 | QListIterator<OPimContact> it( m_contactList ); | 216 | QListIterator<OPimContact> it( m_contactList ); |
352 | uint arraycounter = 0; | 217 | uint arraycounter = 0; |
353 | 218 | ||
354 | for( ; it.current(); ++it ){ | 219 | for( ; it.current(); ++it ){ |
355 | if ( (*it)->match( r ) ){ | 220 | if ( (*it)->match( r ) ){ |
356 | m_currentQuery[arraycounter++] = (*it)->uid(); | 221 | m_currentQuery[arraycounter++] = (*it)->uid(); |
@@ -360,79 +225,21 @@ QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | |||
360 | // Shrink to fit.. | 225 | // Shrink to fit.. |
361 | m_currentQuery.resize(arraycounter); | 226 | m_currentQuery.resize(arraycounter); |
362 | 227 | ||
363 | return m_currentQuery; | 228 | return m_currentQuery; |
364 | } | 229 | } |
365 | 230 | ||
366 | const uint OPimContactAccessBackend_XML::querySettings() | ||
367 | { | ||
368 | return ( OPimContactAccess::WildCards | ||
369 | | OPimContactAccess::IgnoreCase | ||
370 | | OPimContactAccess::RegExp | ||
371 | | OPimContactAccess::ExactMatch | ||
372 | | OPimContactAccess::DateDiff | ||
373 | | OPimContactAccess::DateYear | ||
374 | | OPimContactAccess::DateMonth | ||
375 | | OPimContactAccess::DateDay | ||
376 | ); | ||
377 | } | ||
378 | 231 | ||
379 | bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | ||
380 | { | ||
381 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | ||
382 | * may be added with any of the other settings. IgnoreCase should never used alone. | ||
383 | * Wildcards, RegExp, ExactMatch should never used at the same time... | ||
384 | */ | ||
385 | |||
386 | // Step 1: Check whether the given settings are supported by this backend | ||
387 | if ( ( querySettings & ( | ||
388 | OPimContactAccess::IgnoreCase | ||
389 | | OPimContactAccess::WildCards | ||
390 | | OPimContactAccess::DateDiff | ||
391 | | OPimContactAccess::DateYear | ||
392 | | OPimContactAccess::DateMonth | ||
393 | | OPimContactAccess::DateDay | ||
394 | | OPimContactAccess::RegExp | ||
395 | | OPimContactAccess::ExactMatch | ||
396 | ) ) != querySettings ) | ||
397 | return false; | ||
398 | |||
399 | // Step 2: Check whether the given combinations are ok.. | ||
400 | |||
401 | // IngoreCase alone is invalid | ||
402 | if ( querySettings == OPimContactAccess::IgnoreCase ) | ||
403 | return false; | ||
404 | |||
405 | // WildCards, RegExp and ExactMatch should never used at the same time | ||
406 | switch ( querySettings & ~( OPimContactAccess::IgnoreCase | ||
407 | | OPimContactAccess::DateDiff | ||
408 | | OPimContactAccess::DateYear | ||
409 | | OPimContactAccess::DateMonth | ||
410 | | OPimContactAccess::DateDay | ||
411 | ) | ||
412 | ){ | ||
413 | case OPimContactAccess::RegExp: | ||
414 | return ( true ); | ||
415 | case OPimContactAccess::WildCards: | ||
416 | return ( true ); | ||
417 | case OPimContactAccess::ExactMatch: | ||
418 | return ( true ); | ||
419 | case 0: // one of the upper removed bits were set.. | ||
420 | return ( true ); | ||
421 | default: | ||
422 | return ( false ); | ||
423 | } | ||
424 | } | ||
425 | 232 | ||
426 | #if 0 | 233 | #if 0 |
427 | // Currently only asc implemented.. | 234 | // Currently only asc implemented.. |
428 | QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 235 | UIDArray OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
429 | { | 236 | { |
430 | QMap<QString, int> nameToUid; | 237 | QMap<QString, int> nameToUid; |
431 | QStringList names; | 238 | QStringList names; |
432 | QArray<int> m_currentQuery( m_contactList.count() ); | 239 | UIDArray m_currentQuery( m_contactList.count() ); |
433 | 240 | ||
434 | // First fill map and StringList with all Names | 241 | // First fill map and StringList with all Names |
435 | // Afterwards sort namelist and use map to fill array to return.. | 242 | // Afterwards sort namelist and use map to fill array to return.. |
436 | QListIterator<OPimContact> it( m_contactList ); | 243 | QListIterator<OPimContact> it( m_contactList ); |
437 | for( ; it.current(); ++it ){ | 244 | for( ; it.current(); ++it ){ |
438 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); | 245 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); |