summaryrefslogtreecommitdiff
authoreilers <eilers>2004-06-27 17:34:44 (UTC)
committer eilers <eilers>2004-06-27 17:34:44 (UTC)
commit0ef75ca5409d290df36d1c0bbf0413e37bfd4124 (patch) (unidiff)
treea89d266f6ce2a6b90aff542d6c305c3fc5dde5b1
parente211aea3b9201920f442b36f6726d10c09b63154 (diff)
downloadopie-0ef75ca5409d290df36d1c0bbf0413e37bfd4124.zip
opie-0ef75ca5409d290df36d1c0bbf0413e37bfd4124.tar.gz
opie-0ef75ca5409d290df36d1c0bbf0413e37bfd4124.tar.bz2
Argh.. Sorry for making problems !
CVS committed stuff which had merging conflicts... :(
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp6
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp661
2 files changed, 228 insertions, 439 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index b9a491e..92f89cf 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -125,99 +125,99 @@ bool OSQLiteDriver::open() {
125 0, 125 0,
126 &error ); 126 &error );
127 127
128 /* failed to open */ 128 /* failed to open */
129 if (m_sqlite == 0l ) { 129 if (m_sqlite == 0l ) {
130 // FIXME set the last error 130 // FIXME set the last error
131 owarn << "OSQLiteDriver::open: " << error << "" << oendl; 131 owarn << "OSQLiteDriver::open: " << error << "" << oendl;
132 free( error ); 132 free( error );
133 return false; 133 return false;
134 } 134 }
135 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) 135 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0)
136 odebug << "Unable to create user defined function!" << oendl; 136 odebug << "Unable to create user defined function!" << oendl;
137 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) 137 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0)
138 odebug << "Unable to set rlike function result type!" << oendl; 138 odebug << "Unable to set rlike function result type!" << oendl;
139 sqreg.regex_raw = NULL; 139 sqreg.regex_raw = NULL;
140 return true; 140 return true;
141} 141}
142 142
143 143
144/* close the db 144/* close the db
145 * sqlite closes them without 145 * sqlite closes them without
146 * telling failure or success 146 * telling failure or success
147 */ 147 */
148bool OSQLiteDriver::close() { 148bool OSQLiteDriver::close() {
149 if (m_sqlite ) 149 if (m_sqlite )
150 sqlite_close( m_sqlite ), m_sqlite=0l; 150 sqlite_close( m_sqlite ), m_sqlite=0l;
151 if (sqreg.regex_raw != NULL){ 151 if (sqreg.regex_raw != NULL){
152 odebug << "Freeing regex on close" << oendl; 152 odebug << "Freeing regex on close" << oendl;
153 free(sqreg.regex_raw); 153 free(sqreg.regex_raw);
154 sqreg.regex_raw=NULL; 154 sqreg.regex_raw=NULL;
155 regfree(&sqreg.regex_c); 155 regfree(&sqreg.regex_c);
156 } 156 }
157 return true; 157 return true;
158} 158}
159 159
160 160
161/* Query */ 161/* Query */
162OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 162OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
163 if ( !m_sqlite ) { 163 if ( !m_sqlite ) {
164 // FIXME set error code 164 // FIXME set error code
165 OSQLResult result( OSQLResult::Failure ); 165 OSQLResult result( OSQLResult::Failure );
166 return result; 166 return result;
167 } 167 }
168 Query query; 168 Query query;
169 query.driver = this; 169 query.driver = this;
170 char *err; 170 char *err;
171 /* SQLITE_OK 0 if return code > 0 == failure */ 171 /* SQLITE_OK 0 if return code > 0 == failure */
172 if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { 172 if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) {
173 qWarning("OSQLiteDriver::query: Error while executing %s",err); 173 owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl;
174 free(err ); 174 free( err );
175 // FixMe Errors 175 // FixMe Errors
176 } 176 }
177 177
178 OSQLResult result(OSQLResult::Success, 178 OSQLResult result(OSQLResult::Success,
179 query.items, 179 query.items,
180 query.errors ); 180 query.errors );
181 return result; 181 return result;
182} 182}
183 183
184 184
185OSQLTable::ValueList OSQLiteDriver::tables() const { 185OSQLTable::ValueList OSQLiteDriver::tables() const {
186 186
187} 187}
188 188
189 189
190OSQLError OSQLiteDriver::lastError() { 190OSQLError OSQLiteDriver::lastError() {
191 OSQLError error; 191 OSQLError error;
192 return error; 192 return error;
193}; 193};
194 194
195 195
196/* handle a callback add the row to the global 196/* handle a callback add the row to the global
197 * OSQLResultItem 197 * OSQLResultItem
198 */ 198 */
199int OSQLiteDriver::handleCallBack( int, char**, char** ) { 199int OSQLiteDriver::handleCallBack( int, char**, char** ) {
200 return 0; 200 return 0;
201} 201}
202 202
203 203
204/* callback_handler add the values to the list*/ 204/* callback_handler add the values to the list*/
205int OSQLiteDriver::call_back( void* voi, int argc, 205int OSQLiteDriver::call_back( void* voi, int argc,
206 char** argv, char** columns) { 206 char** argv, char** columns) {
207 Query* qu = (Query*)voi; 207 Query* qu = (Query*)voi;
208 208
209 //copy them over to a OSQLResultItem 209 //copy them over to a OSQLResultItem
210 QMap<QString, QString> tableString; 210 QMap<QString, QString> tableString;
211 QMap<int, QString> tableInt; 211 QMap<int, QString> tableInt;
212 for (int i = 0; i < argc; i++ ) { 212 for (int i = 0; i < argc; i++ ) {
213 213
214 tableInt.insert( i, QString::fromUtf8( argv[i] ) ); 214 tableInt.insert( i, QString::fromUtf8( argv[i] ) );
215 tableString.insert( QString::fromUtf8( columns[i] ), 215 tableString.insert( QString::fromUtf8( columns[i] ),
216 QString::fromUtf8( argv[i] ) ); 216 QString::fromUtf8( argv[i] ) );
217 } 217 }
218 OSQLResultItem item( tableString, tableInt ); 218 OSQLResultItem item( tableString, tableInt );
219 qu->items.append( item ); 219 qu->items.append( item );
220 220
221 return ((Query*)voi)->driver->handleCallBack( argc, 221 return ((Query*)voi)->driver->handleCallBack( argc,
222 argv, 222 argv,
223 columns ); 223 columns );
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index caf3c6e..6b66814 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -21,97 +21,97 @@
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 * VCard Backend for the OPIE-Contact Database. 30 * VCard Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33 33
34#include "vobject_p.h" 34#include "vobject_p.h"
35 35
36/* OPIE */ 36/* OPIE */
37#include <opie2/ocontactaccessbackend_vcard.h> 37#include <opie2/ocontactaccessbackend_vcard.h>
38#include <opie2/odebug.h> 38#include <opie2/odebug.h>
39 39
40#include <qpe/timeconversion.h> 40#include <qpe/timeconversion.h>
41 41
42//FIXME: Hack to allow direct access to FILE* fh. Rewrite this! 42//FIXME: Hack to allow direct access to FILE* fh. Rewrite this!
43#define protected public 43#define protected public
44#include <qfile.h> 44#include <qfile.h>
45#undef protected 45#undef protected
46 46
47namespace Opie { 47namespace Opie {
48 48
49OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): 49OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ):
50 m_dirty( false ), 50 m_dirty( false ),
51 m_file( filename ) 51 m_file( filename )
52{ 52{
53 load(); 53 load();
54} 54}
55 55
56 56
57bool OPimContactAccessBackend_VCard::load () 57bool OPimContactAccessBackend_VCard::load ()
58{ 58{
59 m_map.clear(); 59 m_map.clear();
60 m_dirty = false; 60 m_dirty = false;
61 61
62 VObject* obj = 0l; 62 VObject* obj = 0l;
63 63
64 if ( QFile::exists(m_file) ){ 64 if ( QFile::exists(m_file) ){
65 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 65 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
66 if ( !obj ) 66 if ( !obj )
67 return false; 67 return false;
68 }else{ 68 }else{
69 owarn << "File \"" << m_file << "\" not found !" << oendl; 69 odebug << "File \"" << m_file << "\" not found !" << oendl;
70 return false; 70 return false;
71 } 71 }
72 72
73 while ( obj ) { 73 while ( obj ) {
74 OPimContact con = parseVObject( obj ); 74 OPimContact con = parseVObject( obj );
75 /* 75 /*
76 * if uid is 0 assign a new one 76 * if uid is 0 assign a new one
77 * this at least happens on 77 * this at least happens on
78 * Nokia6210 78 * Nokia6210
79 */ 79 */
80 if ( con.uid() == 0 ){ 80 if ( con.uid() == 0 ){
81 con.setUid( 1 ); 81 con.setUid( 1 );
82 owarn << "assigned new uid " << con.uid() << "" << oendl; 82 owarn << "assigned new uid " << con.uid() << "" << oendl;
83 } 83 }
84 84
85 m_map.insert( con.uid(), con ); 85 m_map.insert( con.uid(), con );
86 86
87 VObject *t = obj; 87 VObject *t = obj;
88 obj = nextVObjectInList(obj); 88 obj = nextVObjectInList(obj);
89 cleanVObject( t ); 89 cleanVObject( t );
90 } 90 }
91 91
92 return true; 92 return true;
93 93
94} 94}
95bool OPimContactAccessBackend_VCard::reload() 95bool OPimContactAccessBackend_VCard::reload()
96{ 96{
97 return load(); 97 return load();
98} 98}
99bool OPimContactAccessBackend_VCard::save() 99bool OPimContactAccessBackend_VCard::save()
100{ 100{
101 if (!m_dirty ) 101 if (!m_dirty )
102 return true; 102 return true;
103 103
104 QFile file( m_file ); 104 QFile file( m_file );
105 if (!file.open(IO_WriteOnly ) ) 105 if (!file.open(IO_WriteOnly ) )
106 return false; 106 return false;
107 107
108 VObject *obj; 108 VObject *obj;
109 obj = newVObject( VCCalProp ); 109 obj = newVObject( VCCalProp );
110 addPropValue( obj, VCVersionProp, "1.0" ); 110 addPropValue( obj, VCVersionProp, "1.0" );
111 111
112 VObject *vo; 112 VObject *vo;
113 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 113 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
114 vo = createVObject( *it ); 114 vo = createVObject( *it );
115 writeVObject( file.fh, vo ); //FIXME: HACK!!! 115 writeVObject( file.fh, vo ); //FIXME: HACK!!!
116 cleanVObject( vo ); 116 cleanVObject( vo );
117 } 117 }
@@ -165,537 +165,326 @@ 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=======
422 VObjectIterator it; 213 VObjectIterator it;
423 initPropIterator( &it, obj ); 214 initPropIterator( &it, obj );
424 while( moreIteration( &it ) ) { 215 while( moreIteration( &it ) ) {
425 VObject *o = nextVObject( &it ); 216 VObject *o = nextVObject( &it );
426 QCString name = vObjectName( o ); 217 QCString name = vObjectName( o );
427 QCString value = vObjectStringZValue( o ); 218 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
428 if ( name == VCNameProp ) { 219 odebug << "(1)Read: %s" << QString( value ).latin1() << oendl;
429 VObjectIterator nit; 220 if ( name == VCNameProp ) {
430 initPropIterator( &nit, o ); 221 VObjectIterator nit;
431 while( moreIteration( &nit ) ) { 222 initPropIterator( &nit, o );
432 VObject *o = nextVObject( &nit ); 223 while( moreIteration( &nit ) ) {
433 QCString name = vObjectTypeInfo( o ); 224 VObject *o = nextVObject( &nit );
434 QString value = vObjectStringZValue( o ); 225 QCString name = vObjectTypeInfo( o );
435 if ( name == VCNamePrefixesProp ) 226 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
436 c.setTitle( value ); 227 odebug << "(2)Read: %s" << value.latin1() << oendl;
437 else if ( name == VCNameSuffixesProp ) 228 if ( name == VCNamePrefixesProp )
438 c.setSuffix( value ); 229 c.setTitle( value );
439 else if ( name == VCFamilyNameProp ) 230 else if ( name == VCNameSuffixesProp )
440 c.setLastName( value ); 231 c.setSuffix( value );
441 else if ( name == VCGivenNameProp ) 232 else if ( name == VCFamilyNameProp )
442 c.setFirstName( value ); 233 c.setLastName( value );
443 else if ( name == VCAdditionalNamesProp ) 234 else if ( name == VCGivenNameProp )
444 c.setMiddleName( value ); 235 c.setFirstName( value );
445 } 236 else if ( name == VCAdditionalNamesProp )
446 } 237 c.setMiddleName( value );
447 else if ( name == VCAdrProp ) { 238 }
448 bool work = TRUE; // default address is work address 239 }
449 QString street; 240 else if ( name == VCAdrProp ) {
450 QString city; 241 bool work = TRUE; // default address is work address
451 QString region; 242 QString street;
452 QString postal; 243 QString city;
453 QString country; 244 QString region;
454 245 QString postal;
455 VObjectIterator nit; 246 QString country;
456 initPropIterator( &nit, o ); 247
457 while( moreIteration( &nit ) ) { 248 VObjectIterator nit;
458 VObject *o = nextVObject( &nit ); 249 initPropIterator( &nit, o );
459 QCString name = vObjectName( o ); 250 while( moreIteration( &nit ) ) {
460 QString value = vObjectStringZValue( o ); 251 VObject *o = nextVObject( &nit );
461 if ( name == VCHomeProp ) 252 QCString name = vObjectName( o );
462 work = FALSE; 253 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
463 else if ( name == VCWorkProp ) 254 if ( name == VCHomeProp )
464 work = TRUE; 255 work = FALSE;
465 else if ( name == VCStreetAddressProp ) 256 else if ( name == VCWorkProp )
466 street = value; 257 work = TRUE;
467 else if ( name == VCCityProp ) 258 else if ( name == VCStreetAddressProp )
468 city = value; 259 street = value;
469 else if ( name == VCRegionProp ) 260 else if ( name == VCCityProp )
470 region = value; 261 city = value;
471 else if ( name == VCPostalCodeProp ) 262 else if ( name == VCRegionProp )
472 postal = value; 263 region = value;
473 else if ( name == VCCountryNameProp ) 264 else if ( name == VCPostalCodeProp )
474 country = value; 265 postal = value;
475 } 266 else if ( name == VCCountryNameProp )
476 if ( work ) { 267 country = value;
477 c.setBusinessStreet( street ); 268 }
478 c.setBusinessCity( city ); 269 if ( work ) {
479 c.setBusinessCountry( country ); 270 c.setBusinessStreet( street );
480 c.setBusinessZip( postal ); 271 c.setBusinessCity( city );
481 c.setBusinessState( region ); 272 c.setBusinessCountry( country );
482 } else { 273 c.setBusinessZip( postal );
483 c.setHomeStreet( street ); 274 c.setBusinessState( region );
484 c.setHomeCity( city ); 275 } else {
485 c.setHomeCountry( country ); 276 c.setHomeStreet( street );
486 c.setHomeZip( postal ); 277 c.setHomeCity( city );
487 c.setHomeState( region ); 278 c.setHomeCountry( country );
488 } 279 c.setHomeZip( postal );
489 } 280 c.setHomeState( region );
490 else if ( name == VCTelephoneProp ) { 281 }
491 enum { 282 }
492 HOME = 0x01, 283 else if ( name == VCTelephoneProp ) {
493 WORK = 0x02, 284 enum {
494 VOICE = 0x04, 285 HOME = 0x01,
495 CELL = 0x08, 286 WORK = 0x02,
496 FAX = 0x10, 287 VOICE = 0x04,
497 PAGER = 0x20, 288 CELL = 0x08,
498 UNKNOWN = 0x80 289 FAX = 0x10,
499 }; 290 PAGER = 0x20,
500 int type = 0; 291 UNKNOWN = 0x80
501 292 };
502 VObjectIterator nit; 293 int type = 0;
503 initPropIterator( &nit, o ); 294
504 while( moreIteration( &nit ) ) { 295 VObjectIterator nit;
505 VObject *o = nextVObject( &nit ); 296 initPropIterator( &nit, o );
506 QCString name = vObjectTypeInfo( o ); 297 while( moreIteration( &nit ) ) {
507 if ( name == VCHomeProp ) 298 VObject *o = nextVObject( &nit );
508 type |= HOME; 299 QCString name = vObjectTypeInfo( o );
509 else if ( name == VCWorkProp ) 300 if ( name == VCHomeProp )
510 type |= WORK; 301 type |= HOME;
511 else if ( name == VCVoiceProp ) 302 else if ( name == VCWorkProp )
512 type |= VOICE; 303 type |= WORK;
513 else if ( name == VCCellularProp ) 304 else if ( name == VCVoiceProp )
514 type |= CELL; 305 type |= VOICE;
515 else if ( name == VCFaxProp ) 306 else if ( name == VCCellularProp )
516 type |= FAX; 307 type |= CELL;
517 else if ( name == VCPagerProp ) 308 else if ( name == VCFaxProp )
518 type |= PAGER; 309 type |= FAX;
519 else if ( name == VCPreferredProp ) 310 else if ( name == VCPagerProp )
520 ; 311 type |= PAGER;
521 else 312 else if ( name == VCPreferredProp )
522 type |= UNKNOWN; 313 ;
523 } 314 else
524 if ( (type & UNKNOWN) != UNKNOWN ) { 315 type |= UNKNOWN;
525 if ( ( type & (HOME|WORK) ) == 0 ) // default 316 }
526 type |= HOME; 317 if ( (type & UNKNOWN) != UNKNOWN ) {
527 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 318 if ( ( type & (HOME|WORK) ) == 0 ) // default
528 type |= VOICE; 319 type |= HOME;
529 320 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
530 owarn << "value " << value.data() << " " << type << "" << oendl; 321 type |= VOICE;
531 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) 322
532 c.setHomePhone( value ); 323 owarn << "value %s %d" << value.data() << type << oendl;
533 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 324 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
534 c.setHomeFax( value ); 325 c.setHomePhone( value );
535 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 326 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
536 c.setHomeMobile( value ); 327 c.setHomeFax( value );
537 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) 328 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
538 c.setBusinessPhone( value ); 329 c.setHomeMobile( value );
539 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 330 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) )
540 c.setBusinessFax( value ); 331 c.setBusinessPhone( value );
541 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 332 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
542 c.setBusinessMobile( value ); 333 c.setBusinessFax( value );
543 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 334 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
544 c.setBusinessPager( value ); 335 c.setBusinessMobile( value );
545 } 336 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
546 } 337 c.setBusinessPager( value );
547 else if ( name == VCEmailAddressProp ) { 338 }
548 QString email = vObjectStringZValue( o ); 339 }
549 bool valid = TRUE; 340 else if ( name == VCEmailAddressProp ) {
550 VObjectIterator nit; 341 QString email = QString::fromUtf8( vObjectStringZValue( o ) );
551 initPropIterator( &nit, o ); 342 bool valid = TRUE;
552 while( moreIteration( &nit ) ) { 343 VObjectIterator nit;
553 VObject *o = nextVObject( &nit ); 344 initPropIterator( &nit, o );
554 QCString name = vObjectTypeInfo( o ); 345 while( moreIteration( &nit ) ) {
555 if ( name != VCInternetProp && name != VCHomeProp && 346 VObject *o = nextVObject( &nit );
556 name != VCWorkProp && 347 QCString name = vObjectTypeInfo( o );
557 name != VCPreferredProp ) 348 if ( name != VCInternetProp && name != VCHomeProp &&
558 // ### preffered should map to default email 349 name != VCWorkProp &&
559 valid = FALSE; 350 name != VCPreferredProp )
560 } 351 // ### preffered should map to default email
561 if ( valid ) { 352 valid = FALSE;
562 c.insertEmail( email ); 353 }
563 } 354 if ( valid ) {
564 } 355 c.insertEmail( email );
565 else if ( name == VCURLProp ) { 356 }
566 VObjectIterator nit; 357 }
567 initPropIterator( &nit, o ); 358 else if ( name == VCURLProp ) {
568 while( moreIteration( &nit ) ) { 359 VObjectIterator nit;
569 VObject *o = nextVObject( &nit ); 360 initPropIterator( &nit, o );
570 QCString name = vObjectTypeInfo( o ); 361 while( moreIteration( &nit ) ) {
571 if ( name == VCHomeProp ) 362 VObject *o = nextVObject( &nit );
572 c.setHomeWebpage( value ); 363 QCString name = vObjectTypeInfo( o );
573 else if ( name == VCWorkProp ) 364 if ( name == VCHomeProp )
574 c.setBusinessWebpage( value ); 365 c.setHomeWebpage( value );
575 } 366 else if ( name == VCWorkProp )
576 } 367 c.setBusinessWebpage( value );
577 else if ( name == VCOrgProp ) { 368 }
578 VObjectIterator nit; 369 }
579 initPropIterator( &nit, o ); 370 else if ( name == VCOrgProp ) {
580 while( moreIteration( &nit ) ) { 371 VObjectIterator nit;
581 VObject *o = nextVObject( &nit ); 372 initPropIterator( &nit, o );
582 QCString name = vObjectName( o ); 373 while( moreIteration( &nit ) ) {
583 QString value = vObjectStringZValue( o ); 374 VObject *o = nextVObject( &nit );
584 if ( name == VCOrgNameProp ) 375 QCString name = vObjectName( o );
585 c.setCompany( value ); 376 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
586 else if ( name == VCOrgUnitProp ) 377 if ( name == VCOrgNameProp )
587 c.setDepartment( value ); 378 c.setCompany( value );
588 else if ( name == VCOrgUnit2Prop ) 379 else if ( name == VCOrgUnitProp )
589 c.setOffice( value ); 380 c.setDepartment( value );
590 } 381 else if ( name == VCOrgUnit2Prop )
591 } 382 c.setOffice( value );
592 else if ( name == VCTitleProp ) { 383 }
593 c.setJobTitle( value ); 384 }
594 } 385 else if ( name == VCTitleProp ) {
595 else if ( name == "X-Qtopia-Profession" ) { 386 c.setJobTitle( value );
596 c.setProfession( value ); 387 }
597 } 388 else if ( name == "X-Qtopia-Profession" ) {
598 else if ( name == "X-Qtopia-Manager" ) { 389 c.setProfession( value );
599 c.setManager( value ); 390 }
600 } 391 else if ( name == "X-Qtopia-Manager" ) {
601 else if ( name == "X-Qtopia-Assistant" ) { 392 c.setManager( value );
602 c.setAssistant( value ); 393 }
603 } 394 else if ( name == "X-Qtopia-Assistant" ) {
604 else if ( name == "X-Qtopia-Spouse" ) { 395 c.setAssistant( value );
605 c.setSpouse( value ); 396 }
606 } 397 else if ( name == "X-Qtopia-Spouse" ) {
607 else if ( name == "X-Qtopia-Gender" ) { 398 c.setSpouse( value );
608 c.setGender( value ); 399 }
609 } 400 else if ( name == "X-Qtopia-Gender" ) {
610 else if ( name == "X-Qtopia-Anniversary" ) { 401 c.setGender( value );
611 c.setAnniversary( convVCardDateToDate( value ) ); 402 }
612 } 403 else if ( name == "X-Qtopia-Anniversary" ) {
613 else if ( name == "X-Qtopia-Nickname" ) { 404 c.setAnniversary( convVCardDateToDate( value ) );
614 c.setNickname( value ); 405 }
615 } 406 else if ( name == "X-Qtopia-Nickname" ) {
616 else if ( name == "X-Qtopia-Children" ) { 407 c.setNickname( value );
617 c.setChildren( value ); 408 }
618 } 409 else if ( name == "X-Qtopia-Children" ) {
619 else if ( name == VCBirthDateProp ) { 410 c.setChildren( value );
620 // Reading Birthdate regarding RFC 2425 (5.8.4) 411 }
621 c.setBirthday( convVCardDateToDate( value ) ); 412 else if ( name == VCBirthDateProp ) {
622 413 // Reading Birthdate regarding RFC 2425 (5.8.4)
623 } 414 c.setBirthday( convVCardDateToDate( value ) );
624 else if ( name == VCCommentProp ) { 415
625 c.setNotes( value ); 416 }
626 } 417 else if ( name == VCCommentProp ) {
627>>>>>>> 1.15 418 c.setNotes( value );
419 }
628#if 0 420#if 0
629<<<<<<< ocontactaccessbackend_vcard.cpp 421 else {
630 else { 422 printf("Name: %s, value=%s\n", name.data(), QString::fromUtf8( vObjectStringZValue( o ) ) );
631 printf("Name: %s, value=%s\n", name.data(), QString::fromUtf8( vObjectStringZValue( o ) ) ); 423 VObjectIterator nit;
632 VObjectIterator nit; 424 initPropIterator( &nit, o );
633 initPropIterator( &nit, o ); 425 while( moreIteration( &nit ) ) {
634 while( moreIteration( &nit ) ) { 426 VObject *o = nextVObject( &nit );
635 VObject *o = nextVObject( &nit ); 427 QCString name = vObjectName( o );
636 QCString name = vObjectName( o ); 428 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
637 QString value = QString::fromUtf8( vObjectStringZValue( o ) ); 429 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
638 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 430 }
639 } 431 }
640 }
641=======
642 else { 432 else {
643 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 433 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
644 VObjectIterator nit; 434 VObjectIterator nit;
645 initPropIterator( &nit, o ); 435 initPropIterator( &nit, o );
646 while( moreIteration( &nit ) ) { 436 while( moreIteration( &nit ) ) {
647 VObject *o = nextVObject( &nit ); 437 VObject *o = nextVObject( &nit );
648 QCString name = vObjectName( o ); 438 QCString name = vObjectName( o );
649 QString value = vObjectStringZValue( o ); 439 QString value = vObjectStringZValue( o );
650 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 440 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
651 } 441 }
652 } 442 }
653>>>>>>> 1.15
654#endif 443#endif
655 } 444 }
656 c.setFileAs(); 445 c.setFileAs();
657 return c; 446 return c;
658} 447}
659 448
660 449
661VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) 450VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
662{ 451{
663 VObject *vcard = newVObject( VCCardProp ); 452 VObject *vcard = newVObject( VCCardProp );
664 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 453 safeAddPropValue( vcard, VCVersionProp, "2.1" );
665 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 454 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
666 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 455 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
667 456
668 // full name 457 // full name
669 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 458 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
670 459
671 // name properties 460 // name properties
672 VObject *name = safeAddProp( vcard, VCNameProp ); 461 VObject *name = safeAddProp( vcard, VCNameProp );
673 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 462 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
674 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 463 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
675 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 464 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
676 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 465 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
677 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 466 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
678 467
679 // home properties 468 // home properties
680 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 469 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
681 safeAddProp( home_adr, VCHomeProp ); 470 safeAddProp( home_adr, VCHomeProp );
682 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 471 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
683 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 472 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
684 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 473 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
685 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 474 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
686 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 475 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
687 476
688 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 477 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
689 safeAddProp( home_phone, VCHomeProp ); 478 safeAddProp( home_phone, VCHomeProp );
690 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 479 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
691 safeAddProp( home_phone, VCHomeProp ); 480 safeAddProp( home_phone, VCHomeProp );
692 safeAddProp( home_phone, VCCellularProp ); 481 safeAddProp( home_phone, VCCellularProp );
693 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 482 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
694 safeAddProp( home_phone, VCHomeProp ); 483 safeAddProp( home_phone, VCHomeProp );
695 safeAddProp( home_phone, VCFaxProp ); 484 safeAddProp( home_phone, VCFaxProp );
696 485
697 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 486 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
698 safeAddProp( url, VCHomeProp ); 487 safeAddProp( url, VCHomeProp );
699 488
700 // work properties 489 // work properties
701 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 490 VObject *work_adr= safeAddProp( vcard, VCAdrProp );