summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.cpp205
1 files changed, 199 insertions, 6 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.cpp b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
index 6ef60eb..b4fdd46 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend.cpp
@@ -30,23 +30,216 @@
30#include "ocontactaccessbackend.h" 30#include "ocontactaccessbackend.h"
31#include <opie2/private/opimcontactsortvector.h> 31#include <opie2/private/opimcontactsortvector.h>
32#include <opie2/ocontactaccess.h> 32#include <opie2/ocontactaccess.h>
33 33
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35 35
36#include <qdatetime.h>
37
36namespace Opie { 38namespace Opie {
37OPimContactAccessBackend::OPimContactAccessBackend() {} 39OPimContactAccessBackend::OPimContactAccessBackend() {}
38 40
39UIDArray 41UIDArray OPimContactAccessBackend::queryByExample( const UIDArray& uid_array, const OPimContact& query, int settings,
40OPimContactAccessBackend::queryByExample( const OPimContact&, int, 42 const QDateTime& d )const {
41 const QDateTime& )const { 43 odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl;
42 return UIDArray(); 44
45 UIDArray m_currentQuery( uid_array.count() );
46 uint arraycounter = 0;
47
48 for( uint it = 0; it < uid_array.count(); ++it ){
49 /* Search all fields and compare them with query object. Store them into list
50 * if all fields matches.
51 */
52 QDate* queryDate = 0l;
53 QDate* checkDate = 0l;
54 bool allcorrect = true;
55 for ( int i = 0; i < Qtopia::Groups; i++ ) {
56 // Birthday and anniversary are special nonstring fields and should
57 // be handled specially
58 switch ( i ){
59 case Qtopia::Birthday:
60 queryDate = new QDate( query.birthday() );
61 checkDate = new QDate( find( uid_array[it] ).birthday() );
62 // fall through
63 case Qtopia::Anniversary:
64 if ( queryDate == 0l ){
65 queryDate = new QDate( query.anniversary() );
66 checkDate = new QDate( find( uid_array[it] ).anniversary() );
67 }
68
69 if ( queryDate->isValid() ){
70 if( checkDate->isValid() ){
71 if ( settings & OPimContactAccess::DateYear ){
72 if ( queryDate->year() != checkDate->year() )
73 allcorrect = false;
74 }
75 if ( settings & OPimContactAccess::DateMonth ){
76 if ( queryDate->month() != checkDate->month() )
77 allcorrect = false;
78 }
79 if ( settings & OPimContactAccess::DateDay ){
80 if ( queryDate->day() != checkDate->day() )
81 allcorrect = false;
82 }
83 if ( settings & OPimContactAccess::DateDiff ) {
84 QDate current;
85 // If we get an additional date, we
86 // will take this date instead of
87 // the current one..
88 if ( !d.date().isValid() )
89 current = QDate::currentDate();
90 else
91 current = d.date();
92
93 // We have to equalize the year, otherwise
94 // the search will fail..
95 checkDate->setYMD( current.year(),
96 checkDate->month(),
97 checkDate->day() );
98 if ( *checkDate < current )
99 checkDate->setYMD( current.year()+1,
100 checkDate->month(),
101 checkDate->day() );
102
103 // Check whether the birthday/anniversary date is between
104 // the current/given date and the maximum date
105 // ( maximum time range ) !
106 if ( current.daysTo( *queryDate ) >= 0 ){
107 if ( !( ( *checkDate >= current ) &&
108 ( *checkDate <= *queryDate ) ) ){
109 allcorrect = false;
110 }
111 }
112 }
113 } else{
114 // checkDate is invalid. Therefore this entry is always rejected
115 allcorrect = false;
116 }
117 }
118
119 delete queryDate;
120 queryDate = 0l;
121 delete checkDate;
122 checkDate = 0l;
123 break;
124 default:
125 /* Just compare fields which are not empty in the query object */
126 if ( !query.field(i).isEmpty() ){
127 switch ( settings & ~( OPimContactAccess::IgnoreCase
128 | OPimContactAccess::DateDiff
129 | OPimContactAccess::DateYear
130 | OPimContactAccess::DateMonth
131 | OPimContactAccess::DateDay
132 | OPimContactAccess::MatchOne
133 ) ){
134
135 case OPimContactAccess::RegExp:{
136 QRegExp expr ( query.field(i),
137 !(settings & OPimContactAccess::IgnoreCase),
138 false );
139 if ( expr.find ( find( uid_array[it] ).field(i), 0 ) == -1 )
140 allcorrect = false;
141 }
142 break;
143 case OPimContactAccess::WildCards:{
144 QRegExp expr ( query.field(i),
145 !(settings & OPimContactAccess::IgnoreCase),
146 true );
147 if ( expr.find ( find( uid_array[it] ).field(i), 0 ) == -1 )
148 allcorrect = false;
149 }
150 break;
151 case OPimContactAccess::ExactMatch:{
152 if (settings & OPimContactAccess::IgnoreCase){
153 if ( query.field(i).upper() !=
154 find( uid_array[it] ).field(i).upper() )
155 allcorrect = false;
156 }else{
157 if ( query.field(i) != find( uid_array[it] ).field(i) )
158 allcorrect = false;
159 }
160 }
161 break;
162 }
163 }
164 }
165 }
166 if ( allcorrect ){
167 m_currentQuery[arraycounter++] = uid_array[it];
168 }
169 }
170
171 // Shrink to fit..
172 m_currentQuery.resize(arraycounter);
173
174 return m_currentQuery;
175
43} 176}
44 177
45UIDArray 178const uint OPimContactAccessBackend::querySettings() const
46OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, 179{
180 return ( OPimContactAccess::WildCards
181 | OPimContactAccess::IgnoreCase
182 | OPimContactAccess::RegExp
183 | OPimContactAccess::ExactMatch
184 | OPimContactAccess::DateDiff
185 | OPimContactAccess::DateYear
186 | OPimContactAccess::DateMonth
187 | OPimContactAccess::DateDay
188 );
189}
190
191bool OPimContactAccessBackend::hasQuerySettings (uint querySettings) const
192{
193 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
194 * may be added with any of the other settings. IgnoreCase should never used alone.
195 * Wildcards, RegExp, ExactMatch should never used at the same time...
196 */
197
198 // Step 1: Check whether the given settings are supported by this backend
199 if ( ( querySettings & (
200 OPimContactAccess::IgnoreCase
201 | OPimContactAccess::WildCards
202 | OPimContactAccess::DateDiff
203 | OPimContactAccess::DateYear
204 | OPimContactAccess::DateMonth
205 | OPimContactAccess::DateDay
206 | OPimContactAccess::RegExp
207 | OPimContactAccess::ExactMatch
208 ) ) != querySettings )
209 return false;
210
211 // Step 2: Check whether the given combinations are ok..
212
213 // IngoreCase alone is invalid
214 if ( querySettings == OPimContactAccess::IgnoreCase )
215 return false;
216
217 // WildCards, RegExp and ExactMatch should never used at the same time
218 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
219 | OPimContactAccess::DateDiff
220 | OPimContactAccess::DateYear
221 | OPimContactAccess::DateMonth
222 | OPimContactAccess::DateDay
223 )
224 ){
225 case OPimContactAccess::RegExp:
226 return ( true );
227 case OPimContactAccess::WildCards:
228 return ( true );
229 case OPimContactAccess::ExactMatch:
230 return ( true );
231 case 0: // one of the upper removed bits were set..
232 return ( true );
233 default:
234 return ( false );
235 }
236}
237
238
239UIDArray OPimContactAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder,
47 int filter, const QArray<int>& categories)const { 240 int filter, const QArray<int>& categories)const {
48 odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl; 241 odebug << "Using Unaccelerated OPimContactAccessBackend sorted Implementation" << oendl;
49 242
50 Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder ); 243 Internal::OPimContactSortVector vector(ar.count(), asc, sortOrder );
51 244
52 int item = 0; 245 int item = 0;