summaryrefslogtreecommitdiff
authoreilers <eilers>2002-11-10 15:41:53 (UTC)
committer eilers <eilers>2002-11-10 15:41:53 (UTC)
commitb0b173498acde27957f8ed9297bb2ed2346eb700 (patch) (unidiff)
tree615180f2fda640ae036450701cf7a728461e7055
parenta982df01d5755c1280c6279df6d46791bd4c9e7e (diff)
downloadopie-b0b173498acde27957f8ed9297bb2ed2346eb700.zip
opie-b0b173498acde27957f8ed9297bb2ed2346eb700.tar.gz
opie-b0b173498acde27957f8ed9297bb2ed2346eb700.tar.bz2
Bugfixes..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.cpp18
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.h5
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp18
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.h5
4 files changed, 36 insertions, 10 deletions
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp
index 903c0b7..013f3af 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.cpp
+++ b/libopie/pim/ocontactaccessbackend_vcard.cpp
@@ -1,549 +1,557 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#include "ocontactaccessbackend_vcard.h" 27#include "ocontactaccessbackend_vcard.h"
24#include "../../library/backend/vobject_p.h" 28#include "../../library/backend/vobject_p.h"
25#include "../../library/backend/qfiledirect_p.h" 29#include "../../library/backend/qfiledirect_p.h"
26 30
27#include <qpe/timeconversion.h> 31#include <qpe/timeconversion.h>
28 32
29#include <qfile.h> 33#include <qfile.h>
30 34
31OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ): 35OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ):
32 m_dirty( false ), 36 m_dirty( false ),
33 m_file( filename ) 37 m_file( filename )
34{} 38{
39 load();
40}
35 41
36 42
37bool OContactAccessBackend_VCard::load () 43bool OContactAccessBackend_VCard::load ()
38{ 44{
39 m_map.clear(); 45 m_map.clear();
40 m_dirty = false; 46 m_dirty = false;
41 47
42 VObject* obj = 0l; 48 VObject* obj = 0l;
43 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 49 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
44 if ( !obj ) 50 if ( !obj )
45 return false; 51 return false;
46 52
47 while ( obj ) { 53 while ( obj ) {
48 OContact con = parseVObject( obj ); 54 OContact con = parseVObject( obj );
49 /* 55 /*
50 * if uid is 0 assign a new one 56 * if uid is 0 assign a new one
51 * this at least happens on 57 * this at least happens on
52 * Nokia6210 58 * Nokia6210
53 */ 59 */
54 if ( con.uid() == 0 ){ 60 if ( con.uid() == 0 ){
55 con.setUid( 1 ); 61 con.setUid( 1 );
56 qWarning("assigned new uid %d",con.uid() ); 62 qWarning("assigned new uid %d",con.uid() );
57 } 63 }
58 64
59 m_map.insert( con.uid(), con ); 65 m_map.insert( con.uid(), con );
60 66
61 VObject *t = obj; 67 VObject *t = obj;
62 obj = nextVObjectInList(obj); 68 obj = nextVObjectInList(obj);
63 cleanVObject( t ); 69 cleanVObject( t );
64 } 70 }
65 71
66 return true; 72 return true;
67 73
68} 74}
69bool OContactAccessBackend_VCard::reload() 75bool OContactAccessBackend_VCard::reload()
70{ 76{
71 return load(); 77 return load();
72} 78}
73bool OContactAccessBackend_VCard::save() 79bool OContactAccessBackend_VCard::save()
74{ 80{
75 if (!m_dirty ) 81 if (!m_dirty )
76 return true; 82 return true;
77 83
78 QFileDirect file( m_file ); 84 QFileDirect file( m_file );
79 if (!file.open(IO_WriteOnly ) ) 85 if (!file.open(IO_WriteOnly ) )
80 return false; 86 return false;
81 87
82 VObject *obj; 88 VObject *obj;
83 obj = newVObject( VCCalProp ); 89 obj = newVObject( VCCalProp );
84 addPropValue( obj, VCVersionProp, "1.0" ); 90 addPropValue( obj, VCVersionProp, "1.0" );
85 91
86 VObject *vo; 92 VObject *vo;
87 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 93 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
88 vo = createVObject( *it ); 94 vo = createVObject( *it );
89 addVObjectProp( obj, vo ); 95 writeVObject( file.directHandle() , vo );
96 cleanVObject( vo );
90 } 97 }
91 writeVObject( file.directHandle() , obj );
92 cleanVObject( obj );
93
94 cleanStrTbl(); 98 cleanStrTbl();
95 99
96 m_dirty = false; 100 m_dirty = false;
97 return true; 101 return true;
98 102
99 103
100} 104}
101void OContactAccessBackend_VCard::clear () 105void OContactAccessBackend_VCard::clear ()
102{ 106{
103 m_map.clear(); 107 m_map.clear();
104 m_dirty = true; // ??? sure ? (se) 108 m_dirty = true; // ??? sure ? (se)
105} 109}
106 110
107bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) 111bool OContactAccessBackend_VCard::add ( const OContact& newcontact )
108{ 112{
109 m_map.insert( newcontact.uid(), newcontact ); 113 m_map.insert( newcontact.uid(), newcontact );
110 m_dirty = true; 114 m_dirty = true;
111 return true; 115 return true;
112} 116}
113 117
114bool OContactAccessBackend_VCard::remove ( int uid ) 118bool OContactAccessBackend_VCard::remove ( int uid )
115{ 119{
116 m_map.remove( uid ); 120 m_map.remove( uid );
117 m_dirty = true; 121 m_dirty = true;
118 return true; 122 return true;
119} 123}
120 124
121bool OContactAccessBackend_VCard::replace ( const OContact &contact ) 125bool OContactAccessBackend_VCard::replace ( const OContact &contact )
122{ 126{
123 m_map.replace( contact.uid(), contact ); 127 m_map.replace( contact.uid(), contact );
124 m_dirty = true; 128 m_dirty = true;
125 return true; 129 return true;
126} 130}
127 131
128OContact OContactAccessBackend_VCard::find ( int uid ) const 132OContact OContactAccessBackend_VCard::find ( int uid ) const
129{ 133{
130 return m_map[uid]; 134 return m_map[uid];
131} 135}
132 136
133QArray<int> OContactAccessBackend_VCard::allRecords() const 137QArray<int> OContactAccessBackend_VCard::allRecords() const
134{ 138{
135 QArray<int> ar( m_map.count() ); 139 QArray<int> ar( m_map.count() );
136 QMap<int, OContact>::ConstIterator it; 140 QMap<int, OContact>::ConstIterator it;
137 int i = 0; 141 int i = 0;
138 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 142 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
139 ar[i] = it.key(); 143 ar[i] = it.key();
140 i++; 144 i++;
141 } 145 }
142 return ar; 146 return ar;
143} 147}
144 148
145// Not implemented 149// Not implemented
146QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) 150QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int )
147{ 151{
148 QArray<int> ar(0); 152 QArray<int> ar(0);
149 return ar; 153 return ar;
150} 154}
151 155
152// Not implemented 156// Not implemented
153QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const 157QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
154{ 158{
155 QArray<int> ar(0); 159 QArray<int> ar(0);
156 return ar; 160 return ar;
157} 161}
158 162
159const uint OContactAccessBackend_VCard::querySettings() 163const uint OContactAccessBackend_VCard::querySettings()
160{ 164{
161 return 0; // No search possible 165 return 0; // No search possible
162} 166}
163 167
164bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const 168bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const
165{ 169{
166 return false; // No search possible, therefore all settings invalid ;) 170 return false; // No search possible, therefore all settings invalid ;)
167} 171}
168 172
173bool OContactAccessBackend_VCard::wasChangedExternally()
174{
175 return false; // Don't expect concurrent access
176}
169 177
170// *** Private stuff *** 178// *** Private stuff ***
171 179
172 180
173OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) 181OContact OContactAccessBackend_VCard::parseVObject( VObject *obj )
174{ 182{
175 OContact c; 183 OContact c;
176 184
177 VObjectIterator it; 185 VObjectIterator it;
178 initPropIterator( &it, obj ); 186 initPropIterator( &it, obj );
179 while( moreIteration( &it ) ) { 187 while( moreIteration( &it ) ) {
180 VObject *o = nextVObject( &it ); 188 VObject *o = nextVObject( &it );
181 QCString name = vObjectName( o ); 189 QCString name = vObjectName( o );
182 QCString value = vObjectStringZValue( o ); 190 QCString value = vObjectStringZValue( o );
183 if ( name == VCNameProp ) { 191 if ( name == VCNameProp ) {
184 VObjectIterator nit; 192 VObjectIterator nit;
185 initPropIterator( &nit, o ); 193 initPropIterator( &nit, o );
186 while( moreIteration( &nit ) ) { 194 while( moreIteration( &nit ) ) {
187 VObject *o = nextVObject( &nit ); 195 VObject *o = nextVObject( &nit );
188 QCString name = vObjectTypeInfo( o ); 196 QCString name = vObjectTypeInfo( o );
189 QString value = vObjectStringZValue( o ); 197 QString value = vObjectStringZValue( o );
190 if ( name == VCNamePrefixesProp ) 198 if ( name == VCNamePrefixesProp )
191 c.setTitle( value ); 199 c.setTitle( value );
192 else if ( name == VCNameSuffixesProp ) 200 else if ( name == VCNameSuffixesProp )
193 c.setSuffix( value ); 201 c.setSuffix( value );
194 else if ( name == VCFamilyNameProp ) 202 else if ( name == VCFamilyNameProp )
195 c.setLastName( value ); 203 c.setLastName( value );
196 else if ( name == VCGivenNameProp ) 204 else if ( name == VCGivenNameProp )
197 c.setFirstName( value ); 205 c.setFirstName( value );
198 else if ( name == VCAdditionalNamesProp ) 206 else if ( name == VCAdditionalNamesProp )
199 c.setMiddleName( value ); 207 c.setMiddleName( value );
200 } 208 }
201 } 209 }
202 else if ( name == VCAdrProp ) { 210 else if ( name == VCAdrProp ) {
203 bool work = TRUE; // default address is work address 211 bool work = TRUE; // default address is work address
204 QString street; 212 QString street;
205 QString city; 213 QString city;
206 QString region; 214 QString region;
207 QString postal; 215 QString postal;
208 QString country; 216 QString country;
209 217
210 VObjectIterator nit; 218 VObjectIterator nit;
211 initPropIterator( &nit, o ); 219 initPropIterator( &nit, o );
212 while( moreIteration( &nit ) ) { 220 while( moreIteration( &nit ) ) {
213 VObject *o = nextVObject( &nit ); 221 VObject *o = nextVObject( &nit );
214 QCString name = vObjectName( o ); 222 QCString name = vObjectName( o );
215 QString value = vObjectStringZValue( o ); 223 QString value = vObjectStringZValue( o );
216 if ( name == VCHomeProp ) 224 if ( name == VCHomeProp )
217 work = FALSE; 225 work = FALSE;
218 else if ( name == VCWorkProp ) 226 else if ( name == VCWorkProp )
219 work = TRUE; 227 work = TRUE;
220 else if ( name == VCStreetAddressProp ) 228 else if ( name == VCStreetAddressProp )
221 street = value; 229 street = value;
222 else if ( name == VCCityProp ) 230 else if ( name == VCCityProp )
223 city = value; 231 city = value;
224 else if ( name == VCRegionProp ) 232 else if ( name == VCRegionProp )
225 region = value; 233 region = value;
226 else if ( name == VCPostalCodeProp ) 234 else if ( name == VCPostalCodeProp )
227 postal = value; 235 postal = value;
228 else if ( name == VCCountryNameProp ) 236 else if ( name == VCCountryNameProp )
229 country = value; 237 country = value;
230 } 238 }
231 if ( work ) { 239 if ( work ) {
232 c.setBusinessStreet( street ); 240 c.setBusinessStreet( street );
233 c.setBusinessCity( city ); 241 c.setBusinessCity( city );
234 c.setBusinessCountry( country ); 242 c.setBusinessCountry( country );
235 c.setBusinessZip( postal ); 243 c.setBusinessZip( postal );
236 c.setBusinessState( region ); 244 c.setBusinessState( region );
237 } else { 245 } else {
238 c.setHomeStreet( street ); 246 c.setHomeStreet( street );
239 c.setHomeCity( city ); 247 c.setHomeCity( city );
240 c.setHomeCountry( country ); 248 c.setHomeCountry( country );
241 c.setHomeZip( postal ); 249 c.setHomeZip( postal );
242 c.setHomeState( region ); 250 c.setHomeState( region );
243 } 251 }
244 } 252 }
245 else if ( name == VCTelephoneProp ) { 253 else if ( name == VCTelephoneProp ) {
246 enum { 254 enum {
247 HOME = 0x01, 255 HOME = 0x01,
248 WORK = 0x02, 256 WORK = 0x02,
249 VOICE = 0x04, 257 VOICE = 0x04,
250 CELL = 0x08, 258 CELL = 0x08,
251 FAX = 0x10, 259 FAX = 0x10,
252 PAGER = 0x20, 260 PAGER = 0x20,
253 UNKNOWN = 0x80 261 UNKNOWN = 0x80
254 }; 262 };
255 int type = 0; 263 int type = 0;
256 264
257 VObjectIterator nit; 265 VObjectIterator nit;
258 initPropIterator( &nit, o ); 266 initPropIterator( &nit, o );
259 while( moreIteration( &nit ) ) { 267 while( moreIteration( &nit ) ) {
260 VObject *o = nextVObject( &nit ); 268 VObject *o = nextVObject( &nit );
261 QCString name = vObjectTypeInfo( o ); 269 QCString name = vObjectTypeInfo( o );
262 if ( name == VCHomeProp ) 270 if ( name == VCHomeProp )
263 type |= HOME; 271 type |= HOME;
264 else if ( name == VCWorkProp ) 272 else if ( name == VCWorkProp )
265 type |= WORK; 273 type |= WORK;
266 else if ( name == VCVoiceProp ) 274 else if ( name == VCVoiceProp )
267 type |= VOICE; 275 type |= VOICE;
268 else if ( name == VCCellularProp ) 276 else if ( name == VCCellularProp )
269 type |= CELL; 277 type |= CELL;
270 else if ( name == VCFaxProp ) 278 else if ( name == VCFaxProp )
271 type |= FAX; 279 type |= FAX;
272 else if ( name == VCPagerProp ) 280 else if ( name == VCPagerProp )
273 type |= PAGER; 281 type |= PAGER;
274 else if ( name == VCPreferredProp ) 282 else if ( name == VCPreferredProp )
275 ; 283 ;
276 else 284 else
277 type |= UNKNOWN; 285 type |= UNKNOWN;
278 } 286 }
279 if ( (type & UNKNOWN) != UNKNOWN ) { 287 if ( (type & UNKNOWN) != UNKNOWN ) {
280 if ( ( type & (HOME|WORK) ) == 0 ) // default 288 if ( ( type & (HOME|WORK) ) == 0 ) // default
281 type |= HOME; 289 type |= HOME;
282 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 290 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
283 type |= VOICE; 291 type |= VOICE;
284 292
285 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 293 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
286 c.setHomePhone( value ); 294 c.setHomePhone( value );
287 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 295 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
288 c.setHomeFax( value ); 296 c.setHomeFax( value );
289 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 297 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
290 c.setHomeMobile( value ); 298 c.setHomeMobile( value );
291 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 299 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
292 c.setBusinessPhone( value ); 300 c.setBusinessPhone( value );
293 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 301 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
294 c.setBusinessFax( value ); 302 c.setBusinessFax( value );
295 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 303 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
296 c.setBusinessMobile( value ); 304 c.setBusinessMobile( value );
297 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 305 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
298 c.setBusinessPager( value ); 306 c.setBusinessPager( value );
299 } 307 }
300 } 308 }
301 else if ( name == VCEmailAddressProp ) { 309 else if ( name == VCEmailAddressProp ) {
302 QString email = vObjectStringZValue( o ); 310 QString email = vObjectStringZValue( o );
303 bool valid = TRUE; 311 bool valid = TRUE;
304 VObjectIterator nit; 312 VObjectIterator nit;
305 initPropIterator( &nit, o ); 313 initPropIterator( &nit, o );
306 while( moreIteration( &nit ) ) { 314 while( moreIteration( &nit ) ) {
307 VObject *o = nextVObject( &nit ); 315 VObject *o = nextVObject( &nit );
308 QCString name = vObjectTypeInfo( o ); 316 QCString name = vObjectTypeInfo( o );
309 if ( name != VCInternetProp && name != VCHomeProp && 317 if ( name != VCInternetProp && name != VCHomeProp &&
310 name != VCWorkProp && 318 name != VCWorkProp &&
311 name != VCPreferredProp ) 319 name != VCPreferredProp )
312 // ### preffered should map to default email 320 // ### preffered should map to default email
313 valid = FALSE; 321 valid = FALSE;
314 } 322 }
315 if ( valid ) { 323 if ( valid ) {
316 c.insertEmail( email ); 324 c.insertEmail( email );
317 } 325 }
318 } 326 }
319 else if ( name == VCURLProp ) { 327 else if ( name == VCURLProp ) {
320 VObjectIterator nit; 328 VObjectIterator nit;
321 initPropIterator( &nit, o ); 329 initPropIterator( &nit, o );
322 while( moreIteration( &nit ) ) { 330 while( moreIteration( &nit ) ) {
323 VObject *o = nextVObject( &nit ); 331 VObject *o = nextVObject( &nit );
324 QCString name = vObjectTypeInfo( o ); 332 QCString name = vObjectTypeInfo( o );
325 if ( name == VCHomeProp ) 333 if ( name == VCHomeProp )
326 c.setHomeWebpage( value ); 334 c.setHomeWebpage( value );
327 else if ( name == VCWorkProp ) 335 else if ( name == VCWorkProp )
328 c.setBusinessWebpage( value ); 336 c.setBusinessWebpage( value );
329 } 337 }
330 } 338 }
331 else if ( name == VCOrgProp ) { 339 else if ( name == VCOrgProp ) {
332 VObjectIterator nit; 340 VObjectIterator nit;
333 initPropIterator( &nit, o ); 341 initPropIterator( &nit, o );
334 while( moreIteration( &nit ) ) { 342 while( moreIteration( &nit ) ) {
335 VObject *o = nextVObject( &nit ); 343 VObject *o = nextVObject( &nit );
336 QCString name = vObjectName( o ); 344 QCString name = vObjectName( o );
337 QString value = vObjectStringZValue( o ); 345 QString value = vObjectStringZValue( o );
338 if ( name == VCOrgNameProp ) 346 if ( name == VCOrgNameProp )
339 c.setCompany( value ); 347 c.setCompany( value );
340 else if ( name == VCOrgUnitProp ) 348 else if ( name == VCOrgUnitProp )
341 c.setDepartment( value ); 349 c.setDepartment( value );
342 else if ( name == VCOrgUnit2Prop ) 350 else if ( name == VCOrgUnit2Prop )
343 c.setOffice( value ); 351 c.setOffice( value );
344 } 352 }
345 } 353 }
346 else if ( name == VCTitleProp ) { 354 else if ( name == VCTitleProp ) {
347 c.setJobTitle( value ); 355 c.setJobTitle( value );
348 } 356 }
349 else if ( name == "X-Qtopia-Profession" ) { 357 else if ( name == "X-Qtopia-Profession" ) {
350 c.setProfession( value ); 358 c.setProfession( value );
351 } 359 }
352 else if ( name == "X-Qtopia-Manager" ) { 360 else if ( name == "X-Qtopia-Manager" ) {
353 c.setManager( value ); 361 c.setManager( value );
354 } 362 }
355 else if ( name == "X-Qtopia-Assistant" ) { 363 else if ( name == "X-Qtopia-Assistant" ) {
356 c.setAssistant( value ); 364 c.setAssistant( value );
357 } 365 }
358 else if ( name == "X-Qtopia-Spouse" ) { 366 else if ( name == "X-Qtopia-Spouse" ) {
359 c.setSpouse( value ); 367 c.setSpouse( value );
360 } 368 }
361 else if ( name == "X-Qtopia-Gender" ) { 369 else if ( name == "X-Qtopia-Gender" ) {
362 c.setGender( value ); 370 c.setGender( value );
363 } 371 }
364 else if ( name == "X-Qtopia-Anniversary" ) { 372 else if ( name == "X-Qtopia-Anniversary" ) {
365 c.setAnniversary( TimeConversion::fromString( value ) ); 373 c.setAnniversary( TimeConversion::fromString( value ) );
366 } 374 }
367 else if ( name == "X-Qtopia-Nickname" ) { 375 else if ( name == "X-Qtopia-Nickname" ) {
368 c.setNickname( value ); 376 c.setNickname( value );
369 } 377 }
370 else if ( name == "X-Qtopia-Children" ) { 378 else if ( name == "X-Qtopia-Children" ) {
371 c.setChildren( value ); 379 c.setChildren( value );
372 } 380 }
373 else if ( name == VCBirthDateProp ) { 381 else if ( name == VCBirthDateProp ) {
374 // Reading Birthdate regarding RFC 2425 (5.8.4) 382 // Reading Birthdate regarding RFC 2425 (5.8.4)
375 c.setBirthday( convVCardDateToDate( value ) ); 383 c.setBirthday( convVCardDateToDate( value ) );
376 384
377 } 385 }
378 386
379#if 0 387#if 0
380 else { 388 else {
381 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 389 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
382 VObjectIterator nit; 390 VObjectIterator nit;
383 initPropIterator( &nit, o ); 391 initPropIterator( &nit, o );
384 while( moreIteration( &nit ) ) { 392 while( moreIteration( &nit ) ) {
385 VObject *o = nextVObject( &nit ); 393 VObject *o = nextVObject( &nit );
386 QCString name = vObjectName( o ); 394 QCString name = vObjectName( o );
387 QString value = vObjectStringZValue( o ); 395 QString value = vObjectStringZValue( o );
388 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 396 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
389 } 397 }
390 } 398 }
391#endif 399#endif
392 } 400 }
393 c.setFileAs(); 401 c.setFileAs();
394 return c; 402 return c;
395} 403}
396 404
397 405
398VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) 406VObject* OContactAccessBackend_VCard::createVObject( const OContact &c )
399{ 407{
400 VObject *vcard = newVObject( VCCardProp ); 408 VObject *vcard = newVObject( VCCardProp );
401 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 409 safeAddPropValue( vcard, VCVersionProp, "2.1" );
402 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 410 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
403 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 411 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
404 412
405 // full name 413 // full name
406 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 414 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
407 415
408 // name properties 416 // name properties
409 VObject *name = safeAddProp( vcard, VCNameProp ); 417 VObject *name = safeAddProp( vcard, VCNameProp );
410 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 418 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
411 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 419 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
412 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 420 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
413 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 421 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
414 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 422 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
415 423
416 // home properties 424 // home properties
417 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 425 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
418 safeAddProp( home_adr, VCHomeProp ); 426 safeAddProp( home_adr, VCHomeProp );
419 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 427 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
420 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 428 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
421 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 429 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
422 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 430 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
423 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 431 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
424 432
425 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 433 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
426 safeAddProp( home_phone, VCHomeProp ); 434 safeAddProp( home_phone, VCHomeProp );
427 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 435 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
428 safeAddProp( home_phone, VCHomeProp ); 436 safeAddProp( home_phone, VCHomeProp );
429 safeAddProp( home_phone, VCCellularProp ); 437 safeAddProp( home_phone, VCCellularProp );
430 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 438 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
431 safeAddProp( home_phone, VCHomeProp ); 439 safeAddProp( home_phone, VCHomeProp );
432 safeAddProp( home_phone, VCFaxProp ); 440 safeAddProp( home_phone, VCFaxProp );
433 441
434 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 442 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
435 safeAddProp( url, VCHomeProp ); 443 safeAddProp( url, VCHomeProp );
436 444
437 // work properties 445 // work properties
438 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 446 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
439 safeAddProp( work_adr, VCWorkProp ); 447 safeAddProp( work_adr, VCWorkProp );
440 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 448 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
441 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 449 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
442 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 450 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
443 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 451 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
444 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 452 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
445 453
446 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 454 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
447 safeAddProp( work_phone, VCWorkProp ); 455 safeAddProp( work_phone, VCWorkProp );
448 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 456 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
449 safeAddProp( work_phone, VCWorkProp ); 457 safeAddProp( work_phone, VCWorkProp );
450 safeAddProp( work_phone, VCCellularProp ); 458 safeAddProp( work_phone, VCCellularProp );
451 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 459 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
452 safeAddProp( work_phone, VCWorkProp ); 460 safeAddProp( work_phone, VCWorkProp );
453 safeAddProp( work_phone, VCFaxProp ); 461 safeAddProp( work_phone, VCFaxProp );
454 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 462 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
455 safeAddProp( work_phone, VCWorkProp ); 463 safeAddProp( work_phone, VCWorkProp );
456 safeAddProp( work_phone, VCPagerProp ); 464 safeAddProp( work_phone, VCPagerProp );
457 465
458 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 466 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
459 safeAddProp( url, VCWorkProp ); 467 safeAddProp( url, VCWorkProp );
460 468
461 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 469 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
462 safeAddProp( title, VCWorkProp ); 470 safeAddProp( title, VCWorkProp );
463 471
464 472
465 QStringList emails = c.emailList(); 473 QStringList emails = c.emailList();
466 emails.prepend( c.defaultEmail() ); 474 emails.prepend( c.defaultEmail() );
467 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 475 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
468 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 476 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
469 safeAddProp( email, VCInternetProp ); 477 safeAddProp( email, VCInternetProp );
470 } 478 }
471 479
472 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 480 safeAddPropValue( vcard, VCNoteProp, c.notes() );
473 481
474 // Exporting Birthday regarding RFC 2425 (5.8.4) 482 // Exporting Birthday regarding RFC 2425 (5.8.4)
475 if ( c.birthday().isValid() ){ 483 if ( c.birthday().isValid() ){
476 QString birthd_rfc2425 = QString("%1-%2-%3") 484 QString birthd_rfc2425 = QString("%1-%2-%3")
477 .arg( c.birthday().year() ) 485 .arg( c.birthday().year() )
478 .arg( c.birthday().month(), 2 ) 486 .arg( c.birthday().month(), 2 )
479 .arg( c.birthday().day(), 2 ); 487 .arg( c.birthday().day(), 2 );
480 // Now replace spaces with "0"... 488 // Now replace spaces with "0"...
481 int pos = 0; 489 int pos = 0;
482 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) 490 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
483 birthd_rfc2425.replace( pos, 1, "0" ); 491 birthd_rfc2425.replace( pos, 1, "0" );
484 492
485 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); 493 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
486 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); 494 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
487 } 495 }
488 496
489 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 497 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
490 VObject *org = safeAddProp( vcard, VCOrgProp ); 498 VObject *org = safeAddProp( vcard, VCOrgProp );
491 safeAddPropValue( org, VCOrgNameProp, c.company() ); 499 safeAddPropValue( org, VCOrgNameProp, c.company() );
492 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 500 safeAddPropValue( org, VCOrgUnitProp, c.department() );
493 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 501 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
494 } 502 }
495 503
496 // some values we have to export as custom fields 504 // some values we have to export as custom fields
497 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 505 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
498 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 506 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
499 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 507 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
500 508
501 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 509 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
502 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 510 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
503 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); 511 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
504 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 512 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
505 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 513 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
506 514
507 return vcard; 515 return vcard;
508} 516}
509 517
510QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) 518QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr )
511{ 519{
512 int monthPos = datestr.find('-'); 520 int monthPos = datestr.find('-');
513 int dayPos = datestr.find('-', monthPos+1 ); 521 int dayPos = datestr.find('-', monthPos+1 );
514 int sep_ignore = 1; 522 int sep_ignore = 1;
515 if ( monthPos == -1 || dayPos == -1 ) { 523 if ( monthPos == -1 || dayPos == -1 ) {
516 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 524 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
517 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 525 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
518 if ( datestr.length() == 8 ){ 526 if ( datestr.length() == 8 ){
519 monthPos = 4; 527 monthPos = 4;
520 dayPos = 6; 528 dayPos = 6;
521 sep_ignore = 0; 529 sep_ignore = 0;
522 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 530 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
523 } else { 531 } else {
524 return QDate(); 532 return QDate();
525 } 533 }
526 } 534 }
527 int y = datestr.left( monthPos ).toInt(); 535 int y = datestr.left( monthPos ).toInt();
528 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 536 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
529 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 537 int d = datestr.mid( dayPos + sep_ignore ).toInt();
530 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 538 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
531 QDate date ( y,m,d ); 539 QDate date ( y,m,d );
532 return date; 540 return date;
533} 541}
534 542
535VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) 543VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value )
536{ 544{
537 VObject *ret = 0; 545 VObject *ret = 0;
538 if ( o && !value.isEmpty() ) 546 if ( o && !value.isEmpty() )
539 ret = addPropValue( o, prop, value.latin1() ); 547 ret = addPropValue( o, prop, value.latin1() );
540 return ret; 548 return ret;
541} 549}
542 550
543VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) 551VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop)
544{ 552{
545 VObject *ret = 0; 553 VObject *ret = 0;
546 if ( o ) 554 if ( o )
547 ret = addProp( o, prop ); 555 ret = addProp( o, prop );
548 return ret; 556 return ret;
549} 557}
diff --git a/libopie/pim/ocontactaccessbackend_vcard.h b/libopie/pim/ocontactaccessbackend_vcard.h
index c1422b0..177ec24 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.h
+++ b/libopie/pim/ocontactaccessbackend_vcard.h
@@ -1,65 +1,70 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#ifndef __OCONTACTACCESSBACKEND_VCARD_H_ 27#ifndef __OCONTACTACCESSBACKEND_VCARD_H_
24#define __OCONTACTACCESSBACKEND_VCARD_H_ 28#define __OCONTACTACCESSBACKEND_VCARD_H_
25 29
26#include <opie/ocontact.h> 30#include <opie/ocontact.h>
27 31
28#include "ocontactaccessbackend.h" 32#include "ocontactaccessbackend.h"
29 33
30class VObject; 34class VObject;
31 35
32class OContactAccessBackend_VCard : public OContactAccessBackend { 36class OContactAccessBackend_VCard : public OContactAccessBackend {
33 public: 37 public:
34 OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); 38 OContactAccessBackend_VCard ( QString appname, QString filename = 0l );
35 39
36 bool load (); 40 bool load ();
37 bool reload(); 41 bool reload();
38 bool save(); 42 bool save();
39 void clear (); 43 void clear ();
40 44
41 bool add ( const OContact& newcontact ); 45 bool add ( const OContact& newcontact );
42 bool remove ( int uid ); 46 bool remove ( int uid );
43 bool replace ( const OContact& contact ); 47 bool replace ( const OContact& contact );
44 48
45 OContact find ( int uid ) const; 49 OContact find ( int uid ) const;
46 QArray<int> allRecords() const; 50 QArray<int> allRecords() const;
47 QArray<int> queryByExample ( const OContact &query, int settings ); 51 QArray<int> queryByExample ( const OContact &query, int settings );
48 QArray<int> matchRegexp( const QRegExp &r ) const; 52 QArray<int> matchRegexp( const QRegExp &r ) const;
49 53
50 const uint querySettings(); 54 const uint querySettings();
51 bool hasQuerySettings (uint querySettings) const; 55 bool hasQuerySettings (uint querySettings) const;
56 bool wasChangedExternally();
52 57
53private: 58private:
54 OContact parseVObject( VObject* obj ); 59 OContact parseVObject( VObject* obj );
55 VObject* createVObject( const OContact& c ); 60 VObject* createVObject( const OContact& c );
56 QDate convVCardDateToDate( const QString& datestr ); 61 QDate convVCardDateToDate( const QString& datestr );
57 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); 62 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value );
58 VObject *safeAddProp( VObject* o, const char* prop); 63 VObject *safeAddProp( VObject* o, const char* prop);
59 64
60 bool m_dirty : 1; 65 bool m_dirty : 1;
61 QString m_file; 66 QString m_file;
62 QMap<int, OContact> m_map; 67 QMap<int, OContact> m_map;
63}; 68};
64 69
65#endif 70#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index 903c0b7..013f3af 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -1,549 +1,557 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#include "ocontactaccessbackend_vcard.h" 27#include "ocontactaccessbackend_vcard.h"
24#include "../../library/backend/vobject_p.h" 28#include "../../library/backend/vobject_p.h"
25#include "../../library/backend/qfiledirect_p.h" 29#include "../../library/backend/qfiledirect_p.h"
26 30
27#include <qpe/timeconversion.h> 31#include <qpe/timeconversion.h>
28 32
29#include <qfile.h> 33#include <qfile.h>
30 34
31OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ): 35OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename = 0l ):
32 m_dirty( false ), 36 m_dirty( false ),
33 m_file( filename ) 37 m_file( filename )
34{} 38{
39 load();
40}
35 41
36 42
37bool OContactAccessBackend_VCard::load () 43bool OContactAccessBackend_VCard::load ()
38{ 44{
39 m_map.clear(); 45 m_map.clear();
40 m_dirty = false; 46 m_dirty = false;
41 47
42 VObject* obj = 0l; 48 VObject* obj = 0l;
43 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 49 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
44 if ( !obj ) 50 if ( !obj )
45 return false; 51 return false;
46 52
47 while ( obj ) { 53 while ( obj ) {
48 OContact con = parseVObject( obj ); 54 OContact con = parseVObject( obj );
49 /* 55 /*
50 * if uid is 0 assign a new one 56 * if uid is 0 assign a new one
51 * this at least happens on 57 * this at least happens on
52 * Nokia6210 58 * Nokia6210
53 */ 59 */
54 if ( con.uid() == 0 ){ 60 if ( con.uid() == 0 ){
55 con.setUid( 1 ); 61 con.setUid( 1 );
56 qWarning("assigned new uid %d",con.uid() ); 62 qWarning("assigned new uid %d",con.uid() );
57 } 63 }
58 64
59 m_map.insert( con.uid(), con ); 65 m_map.insert( con.uid(), con );
60 66
61 VObject *t = obj; 67 VObject *t = obj;
62 obj = nextVObjectInList(obj); 68 obj = nextVObjectInList(obj);
63 cleanVObject( t ); 69 cleanVObject( t );
64 } 70 }
65 71
66 return true; 72 return true;
67 73
68} 74}
69bool OContactAccessBackend_VCard::reload() 75bool OContactAccessBackend_VCard::reload()
70{ 76{
71 return load(); 77 return load();
72} 78}
73bool OContactAccessBackend_VCard::save() 79bool OContactAccessBackend_VCard::save()
74{ 80{
75 if (!m_dirty ) 81 if (!m_dirty )
76 return true; 82 return true;
77 83
78 QFileDirect file( m_file ); 84 QFileDirect file( m_file );
79 if (!file.open(IO_WriteOnly ) ) 85 if (!file.open(IO_WriteOnly ) )
80 return false; 86 return false;
81 87
82 VObject *obj; 88 VObject *obj;
83 obj = newVObject( VCCalProp ); 89 obj = newVObject( VCCalProp );
84 addPropValue( obj, VCVersionProp, "1.0" ); 90 addPropValue( obj, VCVersionProp, "1.0" );
85 91
86 VObject *vo; 92 VObject *vo;
87 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 93 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
88 vo = createVObject( *it ); 94 vo = createVObject( *it );
89 addVObjectProp( obj, vo ); 95 writeVObject( file.directHandle() , vo );
96 cleanVObject( vo );
90 } 97 }
91 writeVObject( file.directHandle() , obj );
92 cleanVObject( obj );
93
94 cleanStrTbl(); 98 cleanStrTbl();
95 99
96 m_dirty = false; 100 m_dirty = false;
97 return true; 101 return true;
98 102
99 103
100} 104}
101void OContactAccessBackend_VCard::clear () 105void OContactAccessBackend_VCard::clear ()
102{ 106{
103 m_map.clear(); 107 m_map.clear();
104 m_dirty = true; // ??? sure ? (se) 108 m_dirty = true; // ??? sure ? (se)
105} 109}
106 110
107bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) 111bool OContactAccessBackend_VCard::add ( const OContact& newcontact )
108{ 112{
109 m_map.insert( newcontact.uid(), newcontact ); 113 m_map.insert( newcontact.uid(), newcontact );
110 m_dirty = true; 114 m_dirty = true;
111 return true; 115 return true;
112} 116}
113 117
114bool OContactAccessBackend_VCard::remove ( int uid ) 118bool OContactAccessBackend_VCard::remove ( int uid )
115{ 119{
116 m_map.remove( uid ); 120 m_map.remove( uid );
117 m_dirty = true; 121 m_dirty = true;
118 return true; 122 return true;
119} 123}
120 124
121bool OContactAccessBackend_VCard::replace ( const OContact &contact ) 125bool OContactAccessBackend_VCard::replace ( const OContact &contact )
122{ 126{
123 m_map.replace( contact.uid(), contact ); 127 m_map.replace( contact.uid(), contact );
124 m_dirty = true; 128 m_dirty = true;
125 return true; 129 return true;
126} 130}
127 131
128OContact OContactAccessBackend_VCard::find ( int uid ) const 132OContact OContactAccessBackend_VCard::find ( int uid ) const
129{ 133{
130 return m_map[uid]; 134 return m_map[uid];
131} 135}
132 136
133QArray<int> OContactAccessBackend_VCard::allRecords() const 137QArray<int> OContactAccessBackend_VCard::allRecords() const
134{ 138{
135 QArray<int> ar( m_map.count() ); 139 QArray<int> ar( m_map.count() );
136 QMap<int, OContact>::ConstIterator it; 140 QMap<int, OContact>::ConstIterator it;
137 int i = 0; 141 int i = 0;
138 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 142 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
139 ar[i] = it.key(); 143 ar[i] = it.key();
140 i++; 144 i++;
141 } 145 }
142 return ar; 146 return ar;
143} 147}
144 148
145// Not implemented 149// Not implemented
146QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) 150QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int )
147{ 151{
148 QArray<int> ar(0); 152 QArray<int> ar(0);
149 return ar; 153 return ar;
150} 154}
151 155
152// Not implemented 156// Not implemented
153QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const 157QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
154{ 158{
155 QArray<int> ar(0); 159 QArray<int> ar(0);
156 return ar; 160 return ar;
157} 161}
158 162
159const uint OContactAccessBackend_VCard::querySettings() 163const uint OContactAccessBackend_VCard::querySettings()
160{ 164{
161 return 0; // No search possible 165 return 0; // No search possible
162} 166}
163 167
164bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const 168bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const
165{ 169{
166 return false; // No search possible, therefore all settings invalid ;) 170 return false; // No search possible, therefore all settings invalid ;)
167} 171}
168 172
173bool OContactAccessBackend_VCard::wasChangedExternally()
174{
175 return false; // Don't expect concurrent access
176}
169 177
170// *** Private stuff *** 178// *** Private stuff ***
171 179
172 180
173OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) 181OContact OContactAccessBackend_VCard::parseVObject( VObject *obj )
174{ 182{
175 OContact c; 183 OContact c;
176 184
177 VObjectIterator it; 185 VObjectIterator it;
178 initPropIterator( &it, obj ); 186 initPropIterator( &it, obj );
179 while( moreIteration( &it ) ) { 187 while( moreIteration( &it ) ) {
180 VObject *o = nextVObject( &it ); 188 VObject *o = nextVObject( &it );
181 QCString name = vObjectName( o ); 189 QCString name = vObjectName( o );
182 QCString value = vObjectStringZValue( o ); 190 QCString value = vObjectStringZValue( o );
183 if ( name == VCNameProp ) { 191 if ( name == VCNameProp ) {
184 VObjectIterator nit; 192 VObjectIterator nit;
185 initPropIterator( &nit, o ); 193 initPropIterator( &nit, o );
186 while( moreIteration( &nit ) ) { 194 while( moreIteration( &nit ) ) {
187 VObject *o = nextVObject( &nit ); 195 VObject *o = nextVObject( &nit );
188 QCString name = vObjectTypeInfo( o ); 196 QCString name = vObjectTypeInfo( o );
189 QString value = vObjectStringZValue( o ); 197 QString value = vObjectStringZValue( o );
190 if ( name == VCNamePrefixesProp ) 198 if ( name == VCNamePrefixesProp )
191 c.setTitle( value ); 199 c.setTitle( value );
192 else if ( name == VCNameSuffixesProp ) 200 else if ( name == VCNameSuffixesProp )
193 c.setSuffix( value ); 201 c.setSuffix( value );
194 else if ( name == VCFamilyNameProp ) 202 else if ( name == VCFamilyNameProp )
195 c.setLastName( value ); 203 c.setLastName( value );
196 else if ( name == VCGivenNameProp ) 204 else if ( name == VCGivenNameProp )
197 c.setFirstName( value ); 205 c.setFirstName( value );
198 else if ( name == VCAdditionalNamesProp ) 206 else if ( name == VCAdditionalNamesProp )
199 c.setMiddleName( value ); 207 c.setMiddleName( value );
200 } 208 }
201 } 209 }
202 else if ( name == VCAdrProp ) { 210 else if ( name == VCAdrProp ) {
203 bool work = TRUE; // default address is work address 211 bool work = TRUE; // default address is work address
204 QString street; 212 QString street;
205 QString city; 213 QString city;
206 QString region; 214 QString region;
207 QString postal; 215 QString postal;
208 QString country; 216 QString country;
209 217
210 VObjectIterator nit; 218 VObjectIterator nit;
211 initPropIterator( &nit, o ); 219 initPropIterator( &nit, o );
212 while( moreIteration( &nit ) ) { 220 while( moreIteration( &nit ) ) {
213 VObject *o = nextVObject( &nit ); 221 VObject *o = nextVObject( &nit );
214 QCString name = vObjectName( o ); 222 QCString name = vObjectName( o );
215 QString value = vObjectStringZValue( o ); 223 QString value = vObjectStringZValue( o );
216 if ( name == VCHomeProp ) 224 if ( name == VCHomeProp )
217 work = FALSE; 225 work = FALSE;
218 else if ( name == VCWorkProp ) 226 else if ( name == VCWorkProp )
219 work = TRUE; 227 work = TRUE;
220 else if ( name == VCStreetAddressProp ) 228 else if ( name == VCStreetAddressProp )
221 street = value; 229 street = value;
222 else if ( name == VCCityProp ) 230 else if ( name == VCCityProp )
223 city = value; 231 city = value;
224 else if ( name == VCRegionProp ) 232 else if ( name == VCRegionProp )
225 region = value; 233 region = value;
226 else if ( name == VCPostalCodeProp ) 234 else if ( name == VCPostalCodeProp )
227 postal = value; 235 postal = value;
228 else if ( name == VCCountryNameProp ) 236 else if ( name == VCCountryNameProp )
229 country = value; 237 country = value;
230 } 238 }
231 if ( work ) { 239 if ( work ) {
232 c.setBusinessStreet( street ); 240 c.setBusinessStreet( street );
233 c.setBusinessCity( city ); 241 c.setBusinessCity( city );
234 c.setBusinessCountry( country ); 242 c.setBusinessCountry( country );
235 c.setBusinessZip( postal ); 243 c.setBusinessZip( postal );
236 c.setBusinessState( region ); 244 c.setBusinessState( region );
237 } else { 245 } else {
238 c.setHomeStreet( street ); 246 c.setHomeStreet( street );
239 c.setHomeCity( city ); 247 c.setHomeCity( city );
240 c.setHomeCountry( country ); 248 c.setHomeCountry( country );
241 c.setHomeZip( postal ); 249 c.setHomeZip( postal );
242 c.setHomeState( region ); 250 c.setHomeState( region );
243 } 251 }
244 } 252 }
245 else if ( name == VCTelephoneProp ) { 253 else if ( name == VCTelephoneProp ) {
246 enum { 254 enum {
247 HOME = 0x01, 255 HOME = 0x01,
248 WORK = 0x02, 256 WORK = 0x02,
249 VOICE = 0x04, 257 VOICE = 0x04,
250 CELL = 0x08, 258 CELL = 0x08,
251 FAX = 0x10, 259 FAX = 0x10,
252 PAGER = 0x20, 260 PAGER = 0x20,
253 UNKNOWN = 0x80 261 UNKNOWN = 0x80
254 }; 262 };
255 int type = 0; 263 int type = 0;
256 264
257 VObjectIterator nit; 265 VObjectIterator nit;
258 initPropIterator( &nit, o ); 266 initPropIterator( &nit, o );
259 while( moreIteration( &nit ) ) { 267 while( moreIteration( &nit ) ) {
260 VObject *o = nextVObject( &nit ); 268 VObject *o = nextVObject( &nit );
261 QCString name = vObjectTypeInfo( o ); 269 QCString name = vObjectTypeInfo( o );
262 if ( name == VCHomeProp ) 270 if ( name == VCHomeProp )
263 type |= HOME; 271 type |= HOME;
264 else if ( name == VCWorkProp ) 272 else if ( name == VCWorkProp )
265 type |= WORK; 273 type |= WORK;
266 else if ( name == VCVoiceProp ) 274 else if ( name == VCVoiceProp )
267 type |= VOICE; 275 type |= VOICE;
268 else if ( name == VCCellularProp ) 276 else if ( name == VCCellularProp )
269 type |= CELL; 277 type |= CELL;
270 else if ( name == VCFaxProp ) 278 else if ( name == VCFaxProp )
271 type |= FAX; 279 type |= FAX;
272 else if ( name == VCPagerProp ) 280 else if ( name == VCPagerProp )
273 type |= PAGER; 281 type |= PAGER;
274 else if ( name == VCPreferredProp ) 282 else if ( name == VCPreferredProp )
275 ; 283 ;
276 else 284 else
277 type |= UNKNOWN; 285 type |= UNKNOWN;
278 } 286 }
279 if ( (type & UNKNOWN) != UNKNOWN ) { 287 if ( (type & UNKNOWN) != UNKNOWN ) {
280 if ( ( type & (HOME|WORK) ) == 0 ) // default 288 if ( ( type & (HOME|WORK) ) == 0 ) // default
281 type |= HOME; 289 type |= HOME;
282 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 290 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
283 type |= VOICE; 291 type |= VOICE;
284 292
285 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 293 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
286 c.setHomePhone( value ); 294 c.setHomePhone( value );
287 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 295 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
288 c.setHomeFax( value ); 296 c.setHomeFax( value );
289 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 297 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
290 c.setHomeMobile( value ); 298 c.setHomeMobile( value );
291 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 299 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
292 c.setBusinessPhone( value ); 300 c.setBusinessPhone( value );
293 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 301 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
294 c.setBusinessFax( value ); 302 c.setBusinessFax( value );
295 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 303 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
296 c.setBusinessMobile( value ); 304 c.setBusinessMobile( value );
297 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 305 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
298 c.setBusinessPager( value ); 306 c.setBusinessPager( value );
299 } 307 }
300 } 308 }
301 else if ( name == VCEmailAddressProp ) { 309 else if ( name == VCEmailAddressProp ) {
302 QString email = vObjectStringZValue( o ); 310 QString email = vObjectStringZValue( o );
303 bool valid = TRUE; 311 bool valid = TRUE;
304 VObjectIterator nit; 312 VObjectIterator nit;
305 initPropIterator( &nit, o ); 313 initPropIterator( &nit, o );
306 while( moreIteration( &nit ) ) { 314 while( moreIteration( &nit ) ) {
307 VObject *o = nextVObject( &nit ); 315 VObject *o = nextVObject( &nit );
308 QCString name = vObjectTypeInfo( o ); 316 QCString name = vObjectTypeInfo( o );
309 if ( name != VCInternetProp && name != VCHomeProp && 317 if ( name != VCInternetProp && name != VCHomeProp &&
310 name != VCWorkProp && 318 name != VCWorkProp &&
311 name != VCPreferredProp ) 319 name != VCPreferredProp )
312 // ### preffered should map to default email 320 // ### preffered should map to default email
313 valid = FALSE; 321 valid = FALSE;
314 } 322 }
315 if ( valid ) { 323 if ( valid ) {
316 c.insertEmail( email ); 324 c.insertEmail( email );
317 } 325 }
318 } 326 }
319 else if ( name == VCURLProp ) { 327 else if ( name == VCURLProp ) {
320 VObjectIterator nit; 328 VObjectIterator nit;
321 initPropIterator( &nit, o ); 329 initPropIterator( &nit, o );
322 while( moreIteration( &nit ) ) { 330 while( moreIteration( &nit ) ) {
323 VObject *o = nextVObject( &nit ); 331 VObject *o = nextVObject( &nit );
324 QCString name = vObjectTypeInfo( o ); 332 QCString name = vObjectTypeInfo( o );
325 if ( name == VCHomeProp ) 333 if ( name == VCHomeProp )
326 c.setHomeWebpage( value ); 334 c.setHomeWebpage( value );
327 else if ( name == VCWorkProp ) 335 else if ( name == VCWorkProp )
328 c.setBusinessWebpage( value ); 336 c.setBusinessWebpage( value );
329 } 337 }
330 } 338 }
331 else if ( name == VCOrgProp ) { 339 else if ( name == VCOrgProp ) {
332 VObjectIterator nit; 340 VObjectIterator nit;
333 initPropIterator( &nit, o ); 341 initPropIterator( &nit, o );
334 while( moreIteration( &nit ) ) { 342 while( moreIteration( &nit ) ) {
335 VObject *o = nextVObject( &nit ); 343 VObject *o = nextVObject( &nit );
336 QCString name = vObjectName( o ); 344 QCString name = vObjectName( o );
337 QString value = vObjectStringZValue( o ); 345 QString value = vObjectStringZValue( o );
338 if ( name == VCOrgNameProp ) 346 if ( name == VCOrgNameProp )
339 c.setCompany( value ); 347 c.setCompany( value );
340 else if ( name == VCOrgUnitProp ) 348 else if ( name == VCOrgUnitProp )
341 c.setDepartment( value ); 349 c.setDepartment( value );
342 else if ( name == VCOrgUnit2Prop ) 350 else if ( name == VCOrgUnit2Prop )
343 c.setOffice( value ); 351 c.setOffice( value );
344 } 352 }
345 } 353 }
346 else if ( name == VCTitleProp ) { 354 else if ( name == VCTitleProp ) {
347 c.setJobTitle( value ); 355 c.setJobTitle( value );
348 } 356 }
349 else if ( name == "X-Qtopia-Profession" ) { 357 else if ( name == "X-Qtopia-Profession" ) {
350 c.setProfession( value ); 358 c.setProfession( value );
351 } 359 }
352 else if ( name == "X-Qtopia-Manager" ) { 360 else if ( name == "X-Qtopia-Manager" ) {
353 c.setManager( value ); 361 c.setManager( value );
354 } 362 }
355 else if ( name == "X-Qtopia-Assistant" ) { 363 else if ( name == "X-Qtopia-Assistant" ) {
356 c.setAssistant( value ); 364 c.setAssistant( value );
357 } 365 }
358 else if ( name == "X-Qtopia-Spouse" ) { 366 else if ( name == "X-Qtopia-Spouse" ) {
359 c.setSpouse( value ); 367 c.setSpouse( value );
360 } 368 }
361 else if ( name == "X-Qtopia-Gender" ) { 369 else if ( name == "X-Qtopia-Gender" ) {
362 c.setGender( value ); 370 c.setGender( value );
363 } 371 }
364 else if ( name == "X-Qtopia-Anniversary" ) { 372 else if ( name == "X-Qtopia-Anniversary" ) {
365 c.setAnniversary( TimeConversion::fromString( value ) ); 373 c.setAnniversary( TimeConversion::fromString( value ) );
366 } 374 }
367 else if ( name == "X-Qtopia-Nickname" ) { 375 else if ( name == "X-Qtopia-Nickname" ) {
368 c.setNickname( value ); 376 c.setNickname( value );
369 } 377 }
370 else if ( name == "X-Qtopia-Children" ) { 378 else if ( name == "X-Qtopia-Children" ) {
371 c.setChildren( value ); 379 c.setChildren( value );
372 } 380 }
373 else if ( name == VCBirthDateProp ) { 381 else if ( name == VCBirthDateProp ) {
374 // Reading Birthdate regarding RFC 2425 (5.8.4) 382 // Reading Birthdate regarding RFC 2425 (5.8.4)
375 c.setBirthday( convVCardDateToDate( value ) ); 383 c.setBirthday( convVCardDateToDate( value ) );
376 384
377 } 385 }
378 386
379#if 0 387#if 0
380 else { 388 else {
381 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 389 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
382 VObjectIterator nit; 390 VObjectIterator nit;
383 initPropIterator( &nit, o ); 391 initPropIterator( &nit, o );
384 while( moreIteration( &nit ) ) { 392 while( moreIteration( &nit ) ) {
385 VObject *o = nextVObject( &nit ); 393 VObject *o = nextVObject( &nit );
386 QCString name = vObjectName( o ); 394 QCString name = vObjectName( o );
387 QString value = vObjectStringZValue( o ); 395 QString value = vObjectStringZValue( o );
388 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 396 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
389 } 397 }
390 } 398 }
391#endif 399#endif
392 } 400 }
393 c.setFileAs(); 401 c.setFileAs();
394 return c; 402 return c;
395} 403}
396 404
397 405
398VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) 406VObject* OContactAccessBackend_VCard::createVObject( const OContact &c )
399{ 407{
400 VObject *vcard = newVObject( VCCardProp ); 408 VObject *vcard = newVObject( VCCardProp );
401 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 409 safeAddPropValue( vcard, VCVersionProp, "2.1" );
402 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 410 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
403 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 411 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
404 412
405 // full name 413 // full name
406 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 414 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
407 415
408 // name properties 416 // name properties
409 VObject *name = safeAddProp( vcard, VCNameProp ); 417 VObject *name = safeAddProp( vcard, VCNameProp );
410 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 418 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
411 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 419 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
412 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 420 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
413 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 421 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
414 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 422 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
415 423
416 // home properties 424 // home properties
417 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 425 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
418 safeAddProp( home_adr, VCHomeProp ); 426 safeAddProp( home_adr, VCHomeProp );
419 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 427 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
420 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 428 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
421 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 429 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
422 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 430 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
423 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 431 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
424 432
425 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 433 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
426 safeAddProp( home_phone, VCHomeProp ); 434 safeAddProp( home_phone, VCHomeProp );
427 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 435 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
428 safeAddProp( home_phone, VCHomeProp ); 436 safeAddProp( home_phone, VCHomeProp );
429 safeAddProp( home_phone, VCCellularProp ); 437 safeAddProp( home_phone, VCCellularProp );
430 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 438 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
431 safeAddProp( home_phone, VCHomeProp ); 439 safeAddProp( home_phone, VCHomeProp );
432 safeAddProp( home_phone, VCFaxProp ); 440 safeAddProp( home_phone, VCFaxProp );
433 441
434 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 442 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
435 safeAddProp( url, VCHomeProp ); 443 safeAddProp( url, VCHomeProp );
436 444
437 // work properties 445 // work properties
438 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 446 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
439 safeAddProp( work_adr, VCWorkProp ); 447 safeAddProp( work_adr, VCWorkProp );
440 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 448 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
441 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 449 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
442 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 450 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
443 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 451 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
444 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 452 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
445 453
446 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 454 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
447 safeAddProp( work_phone, VCWorkProp ); 455 safeAddProp( work_phone, VCWorkProp );
448 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 456 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
449 safeAddProp( work_phone, VCWorkProp ); 457 safeAddProp( work_phone, VCWorkProp );
450 safeAddProp( work_phone, VCCellularProp ); 458 safeAddProp( work_phone, VCCellularProp );
451 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 459 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
452 safeAddProp( work_phone, VCWorkProp ); 460 safeAddProp( work_phone, VCWorkProp );
453 safeAddProp( work_phone, VCFaxProp ); 461 safeAddProp( work_phone, VCFaxProp );
454 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 462 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
455 safeAddProp( work_phone, VCWorkProp ); 463 safeAddProp( work_phone, VCWorkProp );
456 safeAddProp( work_phone, VCPagerProp ); 464 safeAddProp( work_phone, VCPagerProp );
457 465
458 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 466 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
459 safeAddProp( url, VCWorkProp ); 467 safeAddProp( url, VCWorkProp );
460 468
461 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 469 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
462 safeAddProp( title, VCWorkProp ); 470 safeAddProp( title, VCWorkProp );
463 471
464 472
465 QStringList emails = c.emailList(); 473 QStringList emails = c.emailList();
466 emails.prepend( c.defaultEmail() ); 474 emails.prepend( c.defaultEmail() );
467 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 475 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
468 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 476 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
469 safeAddProp( email, VCInternetProp ); 477 safeAddProp( email, VCInternetProp );
470 } 478 }
471 479
472 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 480 safeAddPropValue( vcard, VCNoteProp, c.notes() );
473 481
474 // Exporting Birthday regarding RFC 2425 (5.8.4) 482 // Exporting Birthday regarding RFC 2425 (5.8.4)
475 if ( c.birthday().isValid() ){ 483 if ( c.birthday().isValid() ){
476 QString birthd_rfc2425 = QString("%1-%2-%3") 484 QString birthd_rfc2425 = QString("%1-%2-%3")
477 .arg( c.birthday().year() ) 485 .arg( c.birthday().year() )
478 .arg( c.birthday().month(), 2 ) 486 .arg( c.birthday().month(), 2 )
479 .arg( c.birthday().day(), 2 ); 487 .arg( c.birthday().day(), 2 );
480 // Now replace spaces with "0"... 488 // Now replace spaces with "0"...
481 int pos = 0; 489 int pos = 0;
482 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) 490 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
483 birthd_rfc2425.replace( pos, 1, "0" ); 491 birthd_rfc2425.replace( pos, 1, "0" );
484 492
485 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); 493 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
486 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); 494 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
487 } 495 }
488 496
489 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 497 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
490 VObject *org = safeAddProp( vcard, VCOrgProp ); 498 VObject *org = safeAddProp( vcard, VCOrgProp );
491 safeAddPropValue( org, VCOrgNameProp, c.company() ); 499 safeAddPropValue( org, VCOrgNameProp, c.company() );
492 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 500 safeAddPropValue( org, VCOrgUnitProp, c.department() );
493 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 501 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
494 } 502 }
495 503
496 // some values we have to export as custom fields 504 // some values we have to export as custom fields
497 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 505 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
498 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 506 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
499 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 507 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
500 508
501 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 509 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
502 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 510 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
503 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); 511 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
504 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 512 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
505 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 513 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
506 514
507 return vcard; 515 return vcard;
508} 516}
509 517
510QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) 518QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr )
511{ 519{
512 int monthPos = datestr.find('-'); 520 int monthPos = datestr.find('-');
513 int dayPos = datestr.find('-', monthPos+1 ); 521 int dayPos = datestr.find('-', monthPos+1 );
514 int sep_ignore = 1; 522 int sep_ignore = 1;
515 if ( monthPos == -1 || dayPos == -1 ) { 523 if ( monthPos == -1 || dayPos == -1 ) {
516 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 524 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
517 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 525 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
518 if ( datestr.length() == 8 ){ 526 if ( datestr.length() == 8 ){
519 monthPos = 4; 527 monthPos = 4;
520 dayPos = 6; 528 dayPos = 6;
521 sep_ignore = 0; 529 sep_ignore = 0;
522 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 530 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
523 } else { 531 } else {
524 return QDate(); 532 return QDate();
525 } 533 }
526 } 534 }
527 int y = datestr.left( monthPos ).toInt(); 535 int y = datestr.left( monthPos ).toInt();
528 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 536 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
529 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 537 int d = datestr.mid( dayPos + sep_ignore ).toInt();
530 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 538 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
531 QDate date ( y,m,d ); 539 QDate date ( y,m,d );
532 return date; 540 return date;
533} 541}
534 542
535VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) 543VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value )
536{ 544{
537 VObject *ret = 0; 545 VObject *ret = 0;
538 if ( o && !value.isEmpty() ) 546 if ( o && !value.isEmpty() )
539 ret = addPropValue( o, prop, value.latin1() ); 547 ret = addPropValue( o, prop, value.latin1() );
540 return ret; 548 return ret;
541} 549}
542 550
543VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) 551VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop)
544{ 552{
545 VObject *ret = 0; 553 VObject *ret = 0;
546 if ( o ) 554 if ( o )
547 ret = addProp( o, prop ); 555 ret = addProp( o, prop );
548 return ret; 556 return ret;
549} 557}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
index c1422b0..177ec24 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h
@@ -1,65 +1,70 @@
1/* 1/*
2 * VCard Backend for the OPIE-Contact Database. 2 * VCard Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (C) 2000 Trolltech AS. All rights reserved.
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 5 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 6 *
6 * ===================================================================== 7 * =====================================================================
7 *This program is free software; you can redistribute it and/or 8 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 9 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 12 * =====================================================================
12 * ToDo: 13 * ToDo:
13 * 14 *
14 * ===================================================================== 15 * =====================================================================
15 * Version: $Id$ 16 * Version: $Id$
16 * ===================================================================== 17 * =====================================================================
17 * History: 18 * History:
18 * $Log$ 19 * $Log$
20 * Revision 1.2 2002/11/10 15:41:53 eilers
21 * Bugfixes..
22 *
19 * Revision 1.1 2002/11/09 14:34:52 eilers 23 * Revision 1.1 2002/11/09 14:34:52 eilers
20 * Added VCard Backend. 24 * Added VCard Backend.
21 * 25 *
22 */ 26 */
23#ifndef __OCONTACTACCESSBACKEND_VCARD_H_ 27#ifndef __OCONTACTACCESSBACKEND_VCARD_H_
24#define __OCONTACTACCESSBACKEND_VCARD_H_ 28#define __OCONTACTACCESSBACKEND_VCARD_H_
25 29
26#include <opie/ocontact.h> 30#include <opie/ocontact.h>
27 31
28#include "ocontactaccessbackend.h" 32#include "ocontactaccessbackend.h"
29 33
30class VObject; 34class VObject;
31 35
32class OContactAccessBackend_VCard : public OContactAccessBackend { 36class OContactAccessBackend_VCard : public OContactAccessBackend {
33 public: 37 public:
34 OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); 38 OContactAccessBackend_VCard ( QString appname, QString filename = 0l );
35 39
36 bool load (); 40 bool load ();
37 bool reload(); 41 bool reload();
38 bool save(); 42 bool save();
39 void clear (); 43 void clear ();
40 44
41 bool add ( const OContact& newcontact ); 45 bool add ( const OContact& newcontact );
42 bool remove ( int uid ); 46 bool remove ( int uid );
43 bool replace ( const OContact& contact ); 47 bool replace ( const OContact& contact );
44 48
45 OContact find ( int uid ) const; 49 OContact find ( int uid ) const;
46 QArray<int> allRecords() const; 50 QArray<int> allRecords() const;
47 QArray<int> queryByExample ( const OContact &query, int settings ); 51 QArray<int> queryByExample ( const OContact &query, int settings );
48 QArray<int> matchRegexp( const QRegExp &r ) const; 52 QArray<int> matchRegexp( const QRegExp &r ) const;
49 53
50 const uint querySettings(); 54 const uint querySettings();
51 bool hasQuerySettings (uint querySettings) const; 55 bool hasQuerySettings (uint querySettings) const;
56 bool wasChangedExternally();
52 57
53private: 58private:
54 OContact parseVObject( VObject* obj ); 59 OContact parseVObject( VObject* obj );
55 VObject* createVObject( const OContact& c ); 60 VObject* createVObject( const OContact& c );
56 QDate convVCardDateToDate( const QString& datestr ); 61 QDate convVCardDateToDate( const QString& datestr );
57 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); 62 VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value );
58 VObject *safeAddProp( VObject* o, const char* prop); 63 VObject *safeAddProp( VObject* o, const char* prop);
59 64
60 bool m_dirty : 1; 65 bool m_dirty : 1;
61 QString m_file; 66 QString m_file;
62 QMap<int, OContact> m_map; 67 QMap<int, OContact> m_map;
63}; 68};
64 69
65#endif 70#endif