summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp24
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp232
2 files changed, 235 insertions, 21 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index 69eddfe..b9a491e 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -1,92 +1,88 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 =. 4 =.
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#include "osqlquery.h" 31#include "osqlquery.h"
32#include "osqlitedriver.h" 32#include "osqlitedriver.h"
33 33
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35 35
36#include <stdlib.h> 36#include <stdlib.h>
37#include <stdio.h> 37#include <stdio.h>
38 38
39// fromLocal8Bit() does not work as expected. Thus it 39namespace Opie {
40// is replaced by fromLatin1() (eilers) 40namespace DB {
41#define __BUGGY_LOCAL8BIT_
42
43namespace Opie {
44namespace DB {
45namespace Internal { 41namespace Internal {
46 42
47namespace { 43namespace {
48 struct Query { 44 struct Query {
49 OSQLError::ValueList errors; 45 OSQLError::ValueList errors;
50 OSQLResultItem::ValueList items; 46 OSQLResultItem::ValueList items;
51 OSQLiteDriver *driver; 47 OSQLiteDriver *driver;
52 }; 48 };
53} 49}
54 50
55 51
56OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) 52OSQLiteDriver::OSQLiteDriver( QLibrary *lib )
57 : OSQLDriver( lib ) 53 : OSQLDriver( lib )
58{ 54{
59 m_sqlite = 0l; 55 m_sqlite = 0l;
60} 56}
61 57
62 58
63OSQLiteDriver::~OSQLiteDriver() { 59OSQLiteDriver::~OSQLiteDriver() {
64 close(); 60 close();
65} 61}
66 62
67 63
68QString OSQLiteDriver::id()const { 64QString OSQLiteDriver::id()const {
69 return QString::fromLatin1("SQLite"); 65 return QString::fromLatin1("SQLite");
70} 66}
71 67
72void OSQLiteDriver::setUserName( const QString& ) {} 68void OSQLiteDriver::setUserName( const QString& ) {}
73 69
74 70
75void OSQLiteDriver::setPassword( const QString& ) {} 71void OSQLiteDriver::setPassword( const QString& ) {}
76 72
77 73
78void OSQLiteDriver::setUrl( const QString& url ) { 74void OSQLiteDriver::setUrl( const QString& url ) {
79 m_url = url; 75 m_url = url;
80} 76}
81 77
82 78
83void OSQLiteDriver::setOptions( const QStringList& ) { 79void OSQLiteDriver::setOptions( const QStringList& ) {
84} 80}
85 81
86/* 82/*
87 * Functions to patch a regex search into sqlite 83 * Functions to patch a regex search into sqlite
88 */ 84 */
89int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ 85int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){
90 int res; 86 int res;
91 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ 87 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){
92 if (reg->regex_raw != NULL) { 88 if (reg->regex_raw != NULL) {
@@ -128,111 +124,105 @@ bool OSQLiteDriver::open() {
128 m_sqlite = sqlite_open(m_url.local8Bit(), 124 m_sqlite = sqlite_open(m_url.local8Bit(),
129 0, 125 0,
130 &error ); 126 &error );
131 127
132 /* failed to open */ 128 /* failed to open */
133 if (m_sqlite == 0l ) { 129 if (m_sqlite == 0l ) {
134 // FIXME set the last error 130 // FIXME set the last error
135 owarn << "OSQLiteDriver::open: " << error << "" << oendl; 131 owarn << "OSQLiteDriver::open: " << error << "" << oendl;
136 free( error ); 132 free( error );
137 return false; 133 return false;
138 } 134 }
139 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) 135 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0)
140 odebug << "Unable to create user defined function!" << oendl; 136 odebug << "Unable to create user defined function!" << oendl;
141 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) 137 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0)
142 odebug << "Unable to set rlike function result type!" << oendl; 138 odebug << "Unable to set rlike function result type!" << oendl;
143 sqreg.regex_raw = NULL; 139 sqreg.regex_raw = NULL;
144 return true; 140 return true;
145} 141}
146 142
147 143
148/* close the db 144/* close the db
149 * sqlite closes them without 145 * sqlite closes them without
150 * telling failure or success 146 * telling failure or success
151 */ 147 */
152bool OSQLiteDriver::close() { 148bool OSQLiteDriver::close() {
153 if (m_sqlite ) 149 if (m_sqlite )
154 sqlite_close( m_sqlite ), m_sqlite=0l; 150 sqlite_close( m_sqlite ), m_sqlite=0l;
155 if (sqreg.regex_raw != NULL){ 151 if (sqreg.regex_raw != NULL){
156 odebug << "Freeing regex on close" << oendl; 152 odebug << "Freeing regex on close" << oendl;
157 free(sqreg.regex_raw); 153 free(sqreg.regex_raw);
158 sqreg.regex_raw=NULL; 154 sqreg.regex_raw=NULL;
159 regfree(&sqreg.regex_c); 155 regfree(&sqreg.regex_c);
160 } 156 }
161 return true; 157 return true;
162} 158}
163 159
164 160
165/* Query */ 161/* Query */
166OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 162OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
167 if ( !m_sqlite ) { 163 if ( !m_sqlite ) {
168 // FIXME set error code 164 // FIXME set error code
169 OSQLResult result( OSQLResult::Failure ); 165 OSQLResult result( OSQLResult::Failure );
170 return result; 166 return result;
171 } 167 }
172 Query query; 168 Query query;
173 query.driver = this; 169 query.driver = this;
174 char *err; 170 char *err;
175 /* SQLITE_OK 0 if return code > 0 == failure */ 171 /* SQLITE_OK 0 if return code > 0 == failure */
176 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { 172 if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) {
177 owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; 173 qWarning("OSQLiteDriver::query: Error while executing %s",err);
178 free(err ); 174 free(err );
179 // FixMe Errors 175 // FixMe Errors
180 } 176 }
181 177
182 OSQLResult result(OSQLResult::Success, 178 OSQLResult result(OSQLResult::Success,
183 query.items, 179 query.items,
184 query.errors ); 180 query.errors );
185 return result; 181 return result;
186} 182}
187 183
188 184
189OSQLTable::ValueList OSQLiteDriver::tables() const { 185OSQLTable::ValueList OSQLiteDriver::tables() const {
190 186
191} 187}
192 188
193 189
194OSQLError OSQLiteDriver::lastError() { 190OSQLError OSQLiteDriver::lastError() {
195 OSQLError error; 191 OSQLError error;
196 return error; 192 return error;
197}; 193};
198 194
199 195
200/* handle a callback add the row to the global 196/* handle a callback add the row to the global
201 * OSQLResultItem 197 * OSQLResultItem
202 */ 198 */
203int OSQLiteDriver::handleCallBack( int, char**, char** ) { 199int OSQLiteDriver::handleCallBack( int, char**, char** ) {
204 return 0; 200 return 0;
205} 201}
206 202
207 203
208/* callback_handler add the values to the list*/ 204/* callback_handler add the values to the list*/
209int OSQLiteDriver::call_back( void* voi, int argc, 205int OSQLiteDriver::call_back( void* voi, int argc,
210 char** argv, char** columns) { 206 char** argv, char** columns) {
211 Query* qu = (Query*)voi; 207 Query* qu = (Query*)voi;
212 208
213 //copy them over to a OSQLResultItem 209 //copy them over to a OSQLResultItem
214 QMap<QString, QString> tableString; 210 QMap<QString, QString> tableString;
215 QMap<int, QString> tableInt; 211 QMap<int, QString> tableInt;
216 for (int i = 0; i < argc; i++ ) { 212 for (int i = 0; i < argc; i++ ) {
217 213
218#ifdef __BUGGY_LOCAL8BIT_ 214 tableInt.insert( i, QString::fromUtf8( argv[i] ) );
219 tableInt.insert( i, QString::fromLatin1( argv[i] ) ); 215 tableString.insert( QString::fromUtf8( columns[i] ),
220 tableString.insert( QString::fromLatin1( columns[i] ), 216 QString::fromUtf8( argv[i] ) );
221 QString::fromLatin1( argv[i] ) );
222#else
223 tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) );
224 tableString.insert( QString::fromLocal8Bit( columns[i] ),
225 QString::fromLocal8Bit( argv[i] ) );
226#endif
227 } 217 }
228 OSQLResultItem item( tableString, tableInt ); 218 OSQLResultItem item( tableString, tableInt );
229 qu->items.append( item ); 219 qu->items.append( item );
230 220
231 return ((Query*)voi)->driver->handleCallBack( argc, 221 return ((Query*)voi)->driver->handleCallBack( argc,
232 argv, 222 argv,
233 columns ); 223 columns );
234 224
235 225
236} 226}
237 227
238}}} // namespace OPIE::DB::Internal 228}}} // namespace OPIE::DB::Internal
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index b6ea461..caf3c6e 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -165,96 +165,305 @@ QArray<int> OPimContactAccessBackend_VCard::allRecords() const
165 i++; 165 i++;
166 } 166 }
167 return ar; 167 return ar;
168} 168}
169 169
170// Not implemented 170// Not implemented
171QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& ) 171QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& )
172{ 172{
173 QArray<int> ar(0); 173 QArray<int> ar(0);
174 return ar; 174 return ar;
175} 175}
176 176
177// Not implemented 177// Not implemented
178QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const 178QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
179{ 179{
180 QArray<int> ar(0); 180 QArray<int> ar(0);
181 return ar; 181 return ar;
182} 182}
183 183
184const uint OPimContactAccessBackend_VCard::querySettings() 184const uint OPimContactAccessBackend_VCard::querySettings()
185{ 185{
186 return 0; // No search possible 186 return 0; // No search possible
187} 187}
188 188
189bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const 189bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const
190{ 190{
191 return false; // No search possible, therefore all settings invalid ;) 191 return false; // No search possible, therefore all settings invalid ;)
192} 192}
193 193
194bool OPimContactAccessBackend_VCard::wasChangedExternally() 194bool OPimContactAccessBackend_VCard::wasChangedExternally()
195{ 195{
196 return false; // Don't expect concurrent access 196 return false; // Don't expect concurrent access
197} 197}
198 198
199// Not implemented 199// Not implemented
200QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int ) 200QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int )
201{ 201{
202 QArray<int> ar(0); 202 QArray<int> ar(0);
203 return ar; 203 return ar;
204} 204}
205 205
206// *** Private stuff *** 206// *** Private stuff ***
207 207
208 208
209OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) 209OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
210{ 210{
211 OPimContact c; 211 OPimContact c;
212 212
213<<<<<<< ocontactaccessbackend_vcard.cpp
214 VObjectIterator it;
215 initPropIterator( &it, obj );
216 while( moreIteration( &it ) ) {
217 VObject *o = nextVObject( &it );
218 QCString name = vObjectName( o );
219 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
220 qDebug( "(1)Read: %s", QString( value ).latin1() );
221 if ( name == VCNameProp ) {
222 VObjectIterator nit;
223 initPropIterator( &nit, o );
224 while( moreIteration( &nit ) ) {
225 VObject *o = nextVObject( &nit );
226 QCString name = vObjectTypeInfo( o );
227 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
228 qDebug( "(2)Read: %s", value.latin1() );
229 if ( name == VCNamePrefixesProp )
230 c.setTitle( value );
231 else if ( name == VCNameSuffixesProp )
232 c.setSuffix( value );
233 else if ( name == VCFamilyNameProp )
234 c.setLastName( value );
235 else if ( name == VCGivenNameProp )
236 c.setFirstName( value );
237 else if ( name == VCAdditionalNamesProp )
238 c.setMiddleName( value );
239 }
240 }
241 else if ( name == VCAdrProp ) {
242 bool work = TRUE; // default address is work address
243 QString street;
244 QString city;
245 QString region;
246 QString postal;
247 QString country;
248
249 VObjectIterator nit;
250 initPropIterator( &nit, o );
251 while( moreIteration( &nit ) ) {
252 VObject *o = nextVObject( &nit );
253 QCString name = vObjectName( o );
254 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
255 if ( name == VCHomeProp )
256 work = FALSE;
257 else if ( name == VCWorkProp )
258 work = TRUE;
259 else if ( name == VCStreetAddressProp )
260 street = value;
261 else if ( name == VCCityProp )
262 city = value;
263 else if ( name == VCRegionProp )
264 region = value;
265 else if ( name == VCPostalCodeProp )
266 postal = value;
267 else if ( name == VCCountryNameProp )
268 country = value;
269 }
270 if ( work ) {
271 c.setBusinessStreet( street );
272 c.setBusinessCity( city );
273 c.setBusinessCountry( country );
274 c.setBusinessZip( postal );
275 c.setBusinessState( region );
276 } else {
277 c.setHomeStreet( street );
278 c.setHomeCity( city );
279 c.setHomeCountry( country );
280 c.setHomeZip( postal );
281 c.setHomeState( region );
282 }
283 }
284 else if ( name == VCTelephoneProp ) {
285 enum {
286 HOME = 0x01,
287 WORK = 0x02,
288 VOICE = 0x04,
289 CELL = 0x08,
290 FAX = 0x10,
291 PAGER = 0x20,
292 UNKNOWN = 0x80
293 };
294 int type = 0;
295
296 VObjectIterator nit;
297 initPropIterator( &nit, o );
298 while( moreIteration( &nit ) ) {
299 VObject *o = nextVObject( &nit );
300 QCString name = vObjectTypeInfo( o );
301 if ( name == VCHomeProp )
302 type |= HOME;
303 else if ( name == VCWorkProp )
304 type |= WORK;
305 else if ( name == VCVoiceProp )
306 type |= VOICE;
307 else if ( name == VCCellularProp )
308 type |= CELL;
309 else if ( name == VCFaxProp )
310 type |= FAX;
311 else if ( name == VCPagerProp )
312 type |= PAGER;
313 else if ( name == VCPreferredProp )
314 ;
315 else
316 type |= UNKNOWN;
317 }
318 if ( (type & UNKNOWN) != UNKNOWN ) {
319 if ( ( type & (HOME|WORK) ) == 0 ) // default
320 type |= HOME;
321 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
322 type |= VOICE;
323
324 qWarning("value %s %d", value.data(), type );
325 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
326 c.setHomePhone( value );
327 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
328 c.setHomeFax( value );
329 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
330 c.setHomeMobile( value );
331 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) )
332 c.setBusinessPhone( value );
333 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
334 c.setBusinessFax( value );
335 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
336 c.setBusinessMobile( value );
337 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
338 c.setBusinessPager( value );
339 }
340 }
341 else if ( name == VCEmailAddressProp ) {
342 QString email = QString::fromUtf8( vObjectStringZValue( o ) );
343 bool valid = TRUE;
344 VObjectIterator nit;
345 initPropIterator( &nit, o );
346 while( moreIteration( &nit ) ) {
347 VObject *o = nextVObject( &nit );
348 QCString name = vObjectTypeInfo( o );
349 if ( name != VCInternetProp && name != VCHomeProp &&
350 name != VCWorkProp &&
351 name != VCPreferredProp )
352 // ### preffered should map to default email
353 valid = FALSE;
354 }
355 if ( valid ) {
356 c.insertEmail( email );
357 }
358 }
359 else if ( name == VCURLProp ) {
360 VObjectIterator nit;
361 initPropIterator( &nit, o );
362 while( moreIteration( &nit ) ) {
363 VObject *o = nextVObject( &nit );
364 QCString name = vObjectTypeInfo( o );
365 if ( name == VCHomeProp )
366 c.setHomeWebpage( value );
367 else if ( name == VCWorkProp )
368 c.setBusinessWebpage( value );
369 }
370 }
371 else if ( name == VCOrgProp ) {
372 VObjectIterator nit;
373 initPropIterator( &nit, o );
374 while( moreIteration( &nit ) ) {
375 VObject *o = nextVObject( &nit );
376 QCString name = vObjectName( o );
377 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
378 if ( name == VCOrgNameProp )
379 c.setCompany( value );
380 else if ( name == VCOrgUnitProp )
381 c.setDepartment( value );
382 else if ( name == VCOrgUnit2Prop )
383 c.setOffice( value );
384 }
385 }
386 else if ( name == VCTitleProp ) {
387 c.setJobTitle( value );
388 }
389 else if ( name == "X-Qtopia-Profession" ) {
390 c.setProfession( value );
391 }
392 else if ( name == "X-Qtopia-Manager" ) {
393 c.setManager( value );
394 }
395 else if ( name == "X-Qtopia-Assistant" ) {
396 c.setAssistant( value );
397 }
398 else if ( name == "X-Qtopia-Spouse" ) {
399 c.setSpouse( value );
400 }
401 else if ( name == "X-Qtopia-Gender" ) {
402 c.setGender( value );
403 }
404 else if ( name == "X-Qtopia-Anniversary" ) {
405 c.setAnniversary( convVCardDateToDate( value ) );
406 }
407 else if ( name == "X-Qtopia-Nickname" ) {
408 c.setNickname( value );
409 }
410 else if ( name == "X-Qtopia-Children" ) {
411 c.setChildren( value );
412 }
413 else if ( name == VCBirthDateProp ) {
414 // Reading Birthdate regarding RFC 2425 (5.8.4)
415 c.setBirthday( convVCardDateToDate( value ) );
416
417 }
418 else if ( name == VCCommentProp ) {
419 c.setNotes( value );
420 }
421=======
213 VObjectIterator it; 422 VObjectIterator it;
214 initPropIterator( &it, obj ); 423 initPropIterator( &it, obj );
215 while( moreIteration( &it ) ) { 424 while( moreIteration( &it ) ) {
216 VObject *o = nextVObject( &it ); 425 VObject *o = nextVObject( &it );
217 QCString name = vObjectName( o ); 426 QCString name = vObjectName( o );
218 QCString value = vObjectStringZValue( o ); 427 QCString value = vObjectStringZValue( o );
219 if ( name == VCNameProp ) { 428 if ( name == VCNameProp ) {
220 VObjectIterator nit; 429 VObjectIterator nit;
221 initPropIterator( &nit, o ); 430 initPropIterator( &nit, o );
222 while( moreIteration( &nit ) ) { 431 while( moreIteration( &nit ) ) {
223 VObject *o = nextVObject( &nit ); 432 VObject *o = nextVObject( &nit );
224 QCString name = vObjectTypeInfo( o ); 433 QCString name = vObjectTypeInfo( o );
225 QString value = vObjectStringZValue( o ); 434 QString value = vObjectStringZValue( o );
226 if ( name == VCNamePrefixesProp ) 435 if ( name == VCNamePrefixesProp )
227 c.setTitle( value ); 436 c.setTitle( value );
228 else if ( name == VCNameSuffixesProp ) 437 else if ( name == VCNameSuffixesProp )
229 c.setSuffix( value ); 438 c.setSuffix( value );
230 else if ( name == VCFamilyNameProp ) 439 else if ( name == VCFamilyNameProp )
231 c.setLastName( value ); 440 c.setLastName( value );
232 else if ( name == VCGivenNameProp ) 441 else if ( name == VCGivenNameProp )
233 c.setFirstName( value ); 442 c.setFirstName( value );
234 else if ( name == VCAdditionalNamesProp ) 443 else if ( name == VCAdditionalNamesProp )
235 c.setMiddleName( value ); 444 c.setMiddleName( value );
236 } 445 }
237 } 446 }
238 else if ( name == VCAdrProp ) { 447 else if ( name == VCAdrProp ) {
239 bool work = TRUE; // default address is work address 448 bool work = TRUE; // default address is work address
240 QString street; 449 QString street;
241 QString city; 450 QString city;
242 QString region; 451 QString region;
243 QString postal; 452 QString postal;
244 QString country; 453 QString country;
245 454
246 VObjectIterator nit; 455 VObjectIterator nit;
247 initPropIterator( &nit, o ); 456 initPropIterator( &nit, o );
248 while( moreIteration( &nit ) ) { 457 while( moreIteration( &nit ) ) {
249 VObject *o = nextVObject( &nit ); 458 VObject *o = nextVObject( &nit );
250 QCString name = vObjectName( o ); 459 QCString name = vObjectName( o );
251 QString value = vObjectStringZValue( o ); 460 QString value = vObjectStringZValue( o );
252 if ( name == VCHomeProp ) 461 if ( name == VCHomeProp )
253 work = FALSE; 462 work = FALSE;
254 else if ( name == VCWorkProp ) 463 else if ( name == VCWorkProp )
255 work = TRUE; 464 work = TRUE;
256 else if ( name == VCStreetAddressProp ) 465 else if ( name == VCStreetAddressProp )
257 street = value; 466 street = value;
258 else if ( name == VCCityProp ) 467 else if ( name == VCCityProp )
259 city = value; 468 city = value;
260 else if ( name == VCRegionProp ) 469 else if ( name == VCRegionProp )
@@ -370,108 +579,123 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
370 initPropIterator( &nit, o ); 579 initPropIterator( &nit, o );
371 while( moreIteration( &nit ) ) { 580 while( moreIteration( &nit ) ) {
372 VObject *o = nextVObject( &nit ); 581 VObject *o = nextVObject( &nit );
373 QCString name = vObjectName( o ); 582 QCString name = vObjectName( o );
374 QString value = vObjectStringZValue( o ); 583 QString value = vObjectStringZValue( o );
375 if ( name == VCOrgNameProp ) 584 if ( name == VCOrgNameProp )
376 c.setCompany( value ); 585 c.setCompany( value );
377 else if ( name == VCOrgUnitProp ) 586 else if ( name == VCOrgUnitProp )
378 c.setDepartment( value ); 587 c.setDepartment( value );
379 else if ( name == VCOrgUnit2Prop ) 588 else if ( name == VCOrgUnit2Prop )
380 c.setOffice( value ); 589 c.setOffice( value );
381 } 590 }
382 } 591 }
383 else if ( name == VCTitleProp ) { 592 else if ( name == VCTitleProp ) {
384 c.setJobTitle( value ); 593 c.setJobTitle( value );
385 } 594 }
386 else if ( name == "X-Qtopia-Profession" ) { 595 else if ( name == "X-Qtopia-Profession" ) {
387 c.setProfession( value ); 596 c.setProfession( value );
388 } 597 }
389 else if ( name == "X-Qtopia-Manager" ) { 598 else if ( name == "X-Qtopia-Manager" ) {
390 c.setManager( value ); 599 c.setManager( value );
391 } 600 }
392 else if ( name == "X-Qtopia-Assistant" ) { 601 else if ( name == "X-Qtopia-Assistant" ) {
393 c.setAssistant( value ); 602 c.setAssistant( value );
394 } 603 }
395 else if ( name == "X-Qtopia-Spouse" ) { 604 else if ( name == "X-Qtopia-Spouse" ) {
396 c.setSpouse( value ); 605 c.setSpouse( value );
397 } 606 }
398 else if ( name == "X-Qtopia-Gender" ) { 607 else if ( name == "X-Qtopia-Gender" ) {
399 c.setGender( value ); 608 c.setGender( value );
400 } 609 }
401 else if ( name == "X-Qtopia-Anniversary" ) { 610 else if ( name == "X-Qtopia-Anniversary" ) {
402 c.setAnniversary( convVCardDateToDate( value ) ); 611 c.setAnniversary( convVCardDateToDate( value ) );
403 } 612 }
404 else if ( name == "X-Qtopia-Nickname" ) { 613 else if ( name == "X-Qtopia-Nickname" ) {
405 c.setNickname( value ); 614 c.setNickname( value );
406 } 615 }
407 else if ( name == "X-Qtopia-Children" ) { 616 else if ( name == "X-Qtopia-Children" ) {
408 c.setChildren( value ); 617 c.setChildren( value );
409 } 618 }
410 else if ( name == VCBirthDateProp ) { 619 else if ( name == VCBirthDateProp ) {
411 // Reading Birthdate regarding RFC 2425 (5.8.4) 620 // Reading Birthdate regarding RFC 2425 (5.8.4)
412 c.setBirthday( convVCardDateToDate( value ) ); 621 c.setBirthday( convVCardDateToDate( value ) );
413 622
414 } 623 }
415 else if ( name == VCCommentProp ) { 624 else if ( name == VCCommentProp ) {
416 c.setNotes( value ); 625 c.setNotes( value );
417 } 626 }
627>>>>>>> 1.15
418#if 0 628#if 0
629<<<<<<< ocontactaccessbackend_vcard.cpp
630 else {
631 printf("Name: %s, value=%s\n", name.data(), QString::fromUtf8( vObjectStringZValue( o ) ) );
632 VObjectIterator nit;
633 initPropIterator( &nit, o );
634 while( moreIteration( &nit ) ) {
635 VObject *o = nextVObject( &nit );
636 QCString name = vObjectName( o );
637 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
638 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
639 }
640 }
641=======
419 else { 642 else {
420 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 643 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
421 VObjectIterator nit; 644 VObjectIterator nit;
422 initPropIterator( &nit, o ); 645 initPropIterator( &nit, o );
423 while( moreIteration( &nit ) ) { 646 while( moreIteration( &nit ) ) {
424 VObject *o = nextVObject( &nit ); 647 VObject *o = nextVObject( &nit );
425 QCString name = vObjectName( o ); 648 QCString name = vObjectName( o );
426 QString value = vObjectStringZValue( o ); 649 QString value = vObjectStringZValue( o );
427 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 650 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
428 } 651 }
429 } 652 }
653>>>>>>> 1.15
430#endif 654#endif
431 } 655 }
432 c.setFileAs(); 656 c.setFileAs();
433 return c; 657 return c;
434} 658}
435 659
436 660
437VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) 661VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
438{ 662{
439 VObject *vcard = newVObject( VCCardProp ); 663 VObject *vcard = newVObject( VCCardProp );
440 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 664 safeAddPropValue( vcard, VCVersionProp, "2.1" );
441 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 665 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
442 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 666 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
443 667
444 // full name 668 // full name
445 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 669 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
446 670
447 // name properties 671 // name properties
448 VObject *name = safeAddProp( vcard, VCNameProp ); 672 VObject *name = safeAddProp( vcard, VCNameProp );
449 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 673 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
450 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 674 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
451 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 675 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
452 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 676 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
453 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 677 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
454 678
455 // home properties 679 // home properties
456 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 680 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
457 safeAddProp( home_adr, VCHomeProp ); 681 safeAddProp( home_adr, VCHomeProp );
458 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 682 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
459 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 683 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
460 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 684 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
461 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 685 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
462 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 686 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
463 687
464 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 688 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
465 safeAddProp( home_phone, VCHomeProp ); 689 safeAddProp( home_phone, VCHomeProp );
466 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 690 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
467 safeAddProp( home_phone, VCHomeProp ); 691 safeAddProp( home_phone, VCHomeProp );
468 safeAddProp( home_phone, VCCellularProp ); 692 safeAddProp( home_phone, VCCellularProp );
469 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 693 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
470 safeAddProp( home_phone, VCHomeProp ); 694 safeAddProp( home_phone, VCHomeProp );
471 safeAddProp( home_phone, VCFaxProp ); 695 safeAddProp( home_phone, VCFaxProp );
472 696
473 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 697 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
474 safeAddProp( url, VCHomeProp ); 698 safeAddProp( url, VCHomeProp );
475 699
476 // work properties 700 // work properties
477 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 701 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
@@ -536,63 +760,63 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
536 } 760 }
537 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 761 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
538 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 762 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
539 763
540 return vcard; 764 return vcard;
541} 765}
542 766
543QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const 767QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const
544{ 768{
545 QString str_rfc2425 = QString("%1-%2-%3") 769 QString str_rfc2425 = QString("%1-%2-%3")
546 .arg( d.year() ) 770 .arg( d.year() )
547 .arg( d.month(), 2 ) 771 .arg( d.month(), 2 )
548 .arg( d.day(), 2 ); 772 .arg( d.day(), 2 );
549 // Now replace spaces with "0"... 773 // Now replace spaces with "0"...
550 int pos = 0; 774 int pos = 0;
551 while ( ( pos = str_rfc2425.find (' ') ) > 0 ) 775 while ( ( pos = str_rfc2425.find (' ') ) > 0 )
552 str_rfc2425.replace( pos, 1, "0" ); 776 str_rfc2425.replace( pos, 1, "0" );
553 777
554 return str_rfc2425; 778 return str_rfc2425;
555} 779}
556 780
557QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) 781QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr )
558{ 782{
559 int monthPos = datestr.find('-'); 783 int monthPos = datestr.find('-');
560 int dayPos = datestr.find('-', monthPos+1 ); 784 int dayPos = datestr.find('-', monthPos+1 );
561 int sep_ignore = 1; 785 int sep_ignore = 1;
562 if ( monthPos == -1 || dayPos == -1 ) { 786 if ( monthPos == -1 || dayPos == -1 ) {
563 odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; 787 odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
564 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 788 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
565 if ( datestr.length() == 8 ){ 789 if ( datestr.length() == 8 ){
566 monthPos = 4; 790 monthPos = 4;
567 dayPos = 6; 791 dayPos = 6;
568 sep_ignore = 0; 792 sep_ignore = 0;
569 odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; 793 odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
570 } else { 794 } else {
571 return QDate(); 795 return QDate();
572 } 796 }
573 } 797 }
574 int y = datestr.left( monthPos ).toInt(); 798 int y = datestr.left( monthPos ).toInt();
575 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 799 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
576 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 800 int d = datestr.mid( dayPos + sep_ignore ).toInt();
577 odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; 801 odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
578 QDate date ( y,m,d ); 802 QDate date ( y,m,d );
579 return date; 803 return date;
580} 804}
581 805
582VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) 806VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value )
583{ 807{
584 VObject *ret = 0; 808 VObject *ret = 0;
585 if ( o && !value.isEmpty() ) 809 if ( o && !value.isEmpty() )
586 ret = addPropValue( o, prop, value.latin1() ); 810 ret = addPropValue( o, prop, value.utf8() );
587 return ret; 811 return ret;
588} 812}
589 813
590VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) 814VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop)
591{ 815{
592 VObject *ret = 0; 816 VObject *ret = 0;
593 if ( o ) 817 if ( o )
594 ret = addProp( o, prop ); 818 ret = addProp( o, prop );
595 return ret; 819 return ret;
596} 820}
597 821
598} 822}