author | eilers <eilers> | 2004-12-20 14:14:07 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-12-20 14:14:07 (UTC) |
commit | 18e47153532d016d878f47e0ce11cb1a9716218e (patch) (unidiff) | |
tree | 52eb6c25258fda0b2f295a29809c4603f5e17b0b /libopie2/opiepim/backend/ocontactaccessbackend.cpp | |
parent | 876e48baa20213d8265041cfac3034fe92cb0590 (diff) | |
download | opie-18e47153532d016d878f47e0ce11cb1a9716218e.zip opie-18e47153532d016d878f47e0ce11cb1a9716218e.tar.gz opie-18e47153532d016d878f47e0ce11cb1a9716218e.tar.bz2 |
Recovery of the following Changes:
* Implement fast and full featured version of sorted() for addressbook
* Implement generic queryByExample for all Addressboook backends. It allows incremental search.
* Update of API Documentation
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.cpp | 205 |
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 | |||
@@ -33,17 +33,210 @@ | |||
33 | 33 | ||
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | 35 | ||
36 | #include <qdatetime.h> | ||
37 | |||
36 | namespace Opie { | 38 | namespace Opie { |
37 | OPimContactAccessBackend::OPimContactAccessBackend() {} | 39 | OPimContactAccessBackend::OPimContactAccessBackend() {} |
38 | 40 | ||
39 | UIDArray | 41 | UIDArray OPimContactAccessBackend::queryByExample( const UIDArray& uid_array, const OPimContact& query, int settings, |
40 | OPimContactAccessBackend::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 | ||
45 | UIDArray | 178 | const uint OPimContactAccessBackend::querySettings() const |
46 | OPimContactAccessBackend::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 | |||
191 | bool 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 | |||
239 | UIDArray 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 | ||