summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index f3b6d56..0ffbb67 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -1,597 +1,609 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * VCard Backend for the OPIE-Contact Database. 30 * VCard Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33 33
34#include <opie2/private/vobject_p.h> 34#include <opie2/private/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 version_major( 1 ), 52 version_major( 1 ),
53 version_minor( 0 ) 53 version_minor( 0 )
54{ 54{
55 load(); 55 load();
56} 56}
57 57
58 58
59bool OPimContactAccessBackend_VCard::load () 59bool OPimContactAccessBackend_VCard::load ()
60{ 60{
61 m_map.clear(); 61 m_map.clear();
62 m_dirty = false; 62 m_dirty = false;
63 63
64 VObject* obj = 0l; 64 VObject* obj = 0l;
65 65
66 if ( QFile::exists(m_file) ){ 66 if ( QFile::exists(m_file) ){
67 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 67 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
68 if ( !obj ) 68 if ( !obj )
69 return false; 69 return false;
70 }else{ 70 }else{
71 odebug << "File \"" << m_file << "\" not found !" << oendl; 71 odebug << "File \"" << m_file << "\" not found !" << oendl;
72 return false; 72 return false;
73 } 73 }
74 74
75 while ( obj ) { 75 while ( obj ) {
76 OPimContact con = parseVObject( obj ); 76 OPimContact con = parseVObject( obj );
77 /* 77 /*
78 * if uid is 0 assign a new one 78 * if uid is 0 assign a new one
79 * this at least happens on 79 * this at least happens on
80 * Nokia6210 80 * Nokia6210
81 */ 81 */
82 if ( con.uid() == 0 ){ 82 if ( con.uid() == 0 ){
83 con.setUid( 1 ); 83 con.setUid( 1 );
84 owarn << "assigned new uid " << con.uid() << "" << oendl; 84 owarn << "assigned new uid " << con.uid() << "" << oendl;
85 } 85 }
86 86
87 m_map.insert( con.uid(), con ); 87 m_map.insert( con.uid(), con );
88 88
89 VObject *t = obj; 89 VObject *t = obj;
90 obj = nextVObjectInList(obj); 90 obj = nextVObjectInList(obj);
91 cleanVObject( t ); 91 cleanVObject( t );
92 } 92 }
93 93
94 return true; 94 return true;
95 95
96} 96}
97bool OPimContactAccessBackend_VCard::reload() 97bool OPimContactAccessBackend_VCard::reload()
98{ 98{
99 return load(); 99 return load();
100} 100}
101bool OPimContactAccessBackend_VCard::save() 101bool OPimContactAccessBackend_VCard::save()
102{ 102{
103 if (!m_dirty ) 103 if (!m_dirty )
104 return true; 104 return true;
105 105
106 QFile file( m_file ); 106 QFile file( m_file );
107 if (!file.open(IO_WriteOnly ) ) 107 if (!file.open(IO_WriteOnly ) )
108 return false; 108 return false;
109 109
110 VObject *obj; 110 VObject *obj;
111 obj = newVObject( VCCalProp ); 111 obj = newVObject( VCCalProp );
112 addPropValue( obj, VCVersionProp, "1.0" ); 112 addPropValue( obj, VCVersionProp, "1.0" );
113 113
114 VObject *vo; 114 VObject *vo;
115 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 115 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
116 vo = createVObject( *it ); 116 vo = createVObject( *it );
117 writeVObject( file.fh, vo ); //FIXME: HACK!!! 117 writeVObject( file.fh, vo ); //FIXME: HACK!!!
118 cleanVObject( vo ); 118 cleanVObject( vo );
119 } 119 }
120 cleanStrTbl(); 120 cleanStrTbl();
121 deleteVObject( obj ); 121 deleteVObject( obj );
122 122
123 m_dirty = false; 123 m_dirty = false;
124 return true; 124 return true;
125 125
126 126
127} 127}
128void OPimContactAccessBackend_VCard::clear () 128void OPimContactAccessBackend_VCard::clear ()
129{ 129{
130 m_map.clear(); 130 m_map.clear();
131 m_dirty = true; // ??? sure ? (se) 131 m_dirty = true; // ??? sure ? (se)
132} 132}
133 133
134bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact ) 134bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact )
135{ 135{
136 m_map.insert( newcontact.uid(), newcontact ); 136 m_map.insert( newcontact.uid(), newcontact );
137 m_dirty = true; 137 m_dirty = true;
138 return true; 138 return true;
139} 139}
140 140
141bool OPimContactAccessBackend_VCard::remove ( int uid ) 141bool OPimContactAccessBackend_VCard::remove ( int uid )
142{ 142{
143 m_map.remove( uid ); 143 m_map.remove( uid );
144 m_dirty = true; 144 m_dirty = true;
145 return true; 145 return true;
146} 146}
147 147
148bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact ) 148bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact )
149{ 149{
150 m_map.replace( contact.uid(), contact ); 150 m_map.replace( contact.uid(), contact );
151 m_dirty = true; 151 m_dirty = true;
152 return true; 152 return true;
153} 153}
154 154
155OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const 155OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const
156{ 156{
157 return m_map[uid]; 157 return m_map[uid];
158} 158}
159 159
160UIDArray OPimContactAccessBackend_VCard::allRecords() const 160UIDArray OPimContactAccessBackend_VCard::allRecords() const
161{ 161{
162 UIDArray ar( m_map.count() ); 162 UIDArray ar( m_map.count() );
163 QMap<int, OPimContact>::ConstIterator it; 163 QMap<int, OPimContact>::ConstIterator it;
164 int i = 0; 164 int i = 0;
165 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 165 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
166 ar[i] = it.key(); 166 ar[i] = it.key();
167 i++; 167 i++;
168 } 168 }
169 return ar; 169 return ar;
170} 170}
171 171
172bool OPimContactAccessBackend_VCard::wasChangedExternally() 172bool OPimContactAccessBackend_VCard::wasChangedExternally()
173{ 173{
174 return false; // Don't expect concurrent access 174 return false; // Don't expect concurrent access
175} 175}
176 176
177// *** Private stuff *** 177// *** Private stuff ***
178OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) 178OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
179{ 179{
180 OPimContact c; 180 OPimContact c;
181 VObjectIterator it; 181 VObjectIterator it;
182 initPropIterator( &it, obj ); 182 initPropIterator( &it, obj );
183 while( moreIteration( &it ) ) { 183 while( moreIteration( &it ) ) {
184 VObject *o = nextVObject( &it ); 184 VObject *o = nextVObject( &it );
185 QCString name = vObjectName( o ); 185 QCString name = vObjectName( o );
186 QString value = QString::fromUtf8( vObjectStringZValue( o ) ); 186 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
187 odebug << "(1)Read: " << name << " " << QString( value ).latin1() << oendl; 187 odebug << "(1)Read: " << name << " " << QString( value ).latin1() << oendl;
188 if ( name == VCVersionProp ) { 188 if ( name == VCVersionProp ) {
189 189
190 odebug << "Version: " << value << oendl; 190 odebug << "Version: " << value << oendl;
191 QStringList version = QStringList::split( ".", value ); 191 QStringList version = QStringList::split( ".", value );
192 version_major = version[0].toUInt(); 192 version_major = version[0].toUInt();
193 version_minor = version[1].toUInt(); 193 version_minor = version[1].toUInt();
194 odebug << "Major: "<< version_major << " Minor: " << version_minor << oendl; 194 odebug << "Major: "<< version_major << " Minor: " << version_minor << oendl;
195 195
196 } 196 }
197 else if ( name == VCNameProp ) { 197 else if ( name == VCNameProp ) {
198 VObjectIterator nit; 198 VObjectIterator nit;
199 initPropIterator( &nit, o ); 199 initPropIterator( &nit, o );
200 while( moreIteration( &nit ) ) { 200 while( moreIteration( &nit ) ) {
201 VObject *o = nextVObject( &nit ); 201 VObject *o = nextVObject( &nit );
202 QCString name = vObjectTypeInfo( o ); 202 QCString name = vObjectTypeInfo( o );
203 QString value = QString::fromUtf8( vObjectStringZValue( o ) ); 203 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
204 odebug << "Nametype is: "<< name << " Value: " << value.latin1() << oendl; 204 odebug << "Nametype is: "<< name << " Value: " << value.latin1() << oendl;
205 if ( name == VCNamePrefixesProp ) 205 if ( name == VCNamePrefixesProp )
206 c.setTitle( value ); 206 c.setTitle( value );
207 else if ( name == VCNameSuffixesProp ) 207 else if ( name == VCNameSuffixesProp )
208 c.setSuffix( value ); 208 c.setSuffix( value );
209 else if ( name == VCFamilyNameProp ) 209 else if ( name == VCFamilyNameProp )
210 c.setLastName( value ); 210 c.setLastName( value );
211 else if ( name == VCGivenNameProp ) 211 else if ( name == VCGivenNameProp )
212 c.setFirstName( value ); 212 c.setFirstName( value );
213 else if ( name == VCAdditionalNamesProp ) 213 else if ( name == VCAdditionalNamesProp )
214 c.setMiddleName( value ); 214 c.setMiddleName( value );
215 } 215 }
216 } 216 }
217 else if ( name == VCAdrProp ) { 217 else if ( name == VCAdrProp ) {
218 bool work = TRUE; // default address is work address 218 bool work = TRUE; // default address is work address
219 QString street; 219 QString street;
220 QString city; 220 QString city;
221 QString region; 221 QString region;
222 QString postal; 222 QString postal;
223 QString country; 223 QString country;
224 224
225 VObjectIterator nit; 225 VObjectIterator nit;
226 initPropIterator( &nit, o ); 226 initPropIterator( &nit, o );
227 while( moreIteration( &nit ) ) { 227 while( moreIteration( &nit ) ) {
228 VObject *o = nextVObject( &nit ); 228 VObject *o = nextVObject( &nit );
229 QCString name = vObjectTypeInfo( o ); 229 QCString name = vObjectTypeInfo( o );
230 QString value = QString::fromUtf8( vObjectStringZValue( o ) ); 230 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
231 odebug << "AddressType is: "<< name << " Value: " << value.latin1() << oendl; 231 odebug << "AddressType is: "<< name << " Value: " << value.latin1() << oendl;
232 if ( name == VCHomeProp ) 232 if ( name == VCHomeProp )
233 work = FALSE; 233 work = FALSE;
234 else if ( name == VCWorkProp ) 234 else if ( name == VCWorkProp )
235 work = TRUE; 235 work = TRUE;
236 else if ( name == VCStreetAddressProp ) 236 else if ( name == VCStreetAddressProp )
237 street = value; 237 street = value;
238 else if ( name == VCCityProp ) 238 else if ( name == VCCityProp )
239 city = value; 239 city = value;
240 else if ( name == VCRegionProp ) 240 else if ( name == VCRegionProp )
241 region = value; 241 region = value;
242 else if ( name == VCPostalCodeProp ) 242 else if ( name == VCPostalCodeProp )
243 postal = value; 243 postal = value;
244 else if ( name == VCCountryNameProp ) 244 else if ( name == VCCountryNameProp )
245 country = value; 245 country = value;
246 } 246 }
247 if ( work ) { 247 if ( work ) {
248 c.setBusinessStreet( street ); 248 c.setBusinessStreet( street );
249 c.setBusinessCity( city ); 249 c.setBusinessCity( city );
250 c.setBusinessCountry( country ); 250 c.setBusinessCountry( country );
251 c.setBusinessZip( postal ); 251 c.setBusinessZip( postal );
252 c.setBusinessState( region ); 252 c.setBusinessState( region );
253 } else { 253 } else {
254 c.setHomeStreet( street ); 254 c.setHomeStreet( street );
255 c.setHomeCity( city ); 255 c.setHomeCity( city );
256 c.setHomeCountry( country ); 256 c.setHomeCountry( country );
257 c.setHomeZip( postal ); 257 c.setHomeZip( postal );
258 c.setHomeState( region ); 258 c.setHomeState( region );
259 } 259 }
260 } 260 }
261 else if ( name == VCTelephoneProp ) { 261 else if ( name == VCTelephoneProp ) {
262 enum { 262 enum {
263 HOME = 0x01, 263 HOME = 0x01,
264 WORK = 0x02, 264 WORK = 0x02,
265 VOICE = 0x04, 265 VOICE = 0x04,
266 CELL = 0x08, 266 CELL = 0x08,
267 FAX = 0x10, 267 FAX = 0x10,
268 PAGER = 0x20, 268 PAGER = 0x20,
269 UNKNOWN = 0x80 269 UNKNOWN = 0x80
270 }; 270 };
271 int type = 0; 271 int type = 0;
272 272
273 VObjectIterator nit; 273 VObjectIterator nit;
274 initPropIterator( &nit, o ); 274 initPropIterator( &nit, o );
275 while( moreIteration( &nit ) ) { 275 while( moreIteration( &nit ) ) {
276 VObject *o = nextVObject( &nit ); 276 VObject *o = nextVObject( &nit );
277 QCString name = vObjectTypeInfo( o ); 277 QCString name = vObjectTypeInfo( o );
278 odebug << "Telephonetype is: "<< name << " Value: " << value.latin1() << oendl; 278 odebug << "Telephonetype is: "<< name << " Value: " << value.latin1() << oendl;
279 if ( name == VCHomeProp ) 279 if ( name == VCHomeProp )
280 type |= HOME; 280 type |= HOME;
281 else if ( name == VCWorkProp ) 281 else if ( name == VCWorkProp )
282 type |= WORK; 282 type |= WORK;
283 else if ( name == VCVoiceProp ) 283 else if ( name == VCVoiceProp )
284 type |= VOICE; 284 type |= VOICE;
285 else if ( name == VCCellularProp ) 285 else if ( name == VCCellularProp )
286 type |= CELL; 286 type |= CELL;
287 else if ( name == VCFaxProp ) 287 else if ( name == VCFaxProp )
288 type |= FAX; 288 type |= FAX;
289 else if ( name == VCPagerProp ) 289 else if ( name == VCPagerProp )
290 type |= PAGER; 290 type |= PAGER;
291 else if ( name == VCPreferredProp ) 291 else if ( name == VCPreferredProp )
292 ; 292 ;
293 else if ( name.left( 2 ) == "X-" || name.left( 2 ) == "x-" ) 293 else if ( name.left( 2 ) == "X-" || name.left( 2 ) == "x-" )
294 ; // Ignore 294 ; // Ignore
295 else 295 else
296 type |= UNKNOWN; 296 type |= UNKNOWN;
297 } 297 }
298 if ( (type & UNKNOWN) != UNKNOWN ) { 298 if ( (type & UNKNOWN) != UNKNOWN ) {
299 if ( ( type & (HOME|WORK) ) == 0 ) // default 299 if ( ( type & (HOME|WORK) ) == 0 ) // default
300 type |= HOME; 300 type |= HOME;
301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
302 type |= VOICE; 302 type |= VOICE;
303 303
304 odebug << "value %s %d" << value.data() << type << oendl; 304 odebug << "value %s %d" << value.data() << type << oendl;
305 305
306 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) 306 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
307 c.setHomePhone( value ); 307 c.setHomePhone( value );
308 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 308 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
309 c.setHomeFax( value ); 309 c.setHomeFax( value );
310 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 310 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
311 c.setHomeMobile( value ); 311 c.setHomeMobile( value );
312 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) 312 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) )
313 c.setBusinessPhone( value ); 313 c.setBusinessPhone( value );
314 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 314 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
315 c.setBusinessFax( value ); 315 c.setBusinessFax( value );
316 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 316 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
317 c.setBusinessMobile( value ); 317 c.setBusinessMobile( value );
318 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 318 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
319 c.setBusinessPager( value ); 319 c.setBusinessPager( value );
320 } 320 }
321 } 321 }
322 else if ( name == VCEmailAddressProp ) { 322 else if ( name == VCEmailAddressProp ) {
323 QString email = QString::fromUtf8( vObjectStringZValue( o ) ); 323 QString email = QString::fromUtf8( vObjectStringZValue( o ) );
324 bool valid = TRUE; 324 bool valid = TRUE;
325 VObjectIterator nit; 325 VObjectIterator nit;
326 initPropIterator( &nit, o ); 326 initPropIterator( &nit, o );
327 while( moreIteration( &nit ) ) { 327 while( moreIteration( &nit ) ) {
328 VObject *o = nextVObject( &nit ); 328 VObject *o = nextVObject( &nit );
329 QCString name = vObjectTypeInfo( o ); 329 QCString name = vObjectTypeInfo( o );
330 odebug << "Emailtype is: "<< name << " Value: " << value.latin1() << oendl; 330 odebug << "Emailtype is: "<< name << " Value: " << value.latin1() << oendl;
331 if ( name != VCInternetProp && name != VCHomeProp && 331 if ( name != VCInternetProp && name != VCHomeProp &&
332 name != VCWorkProp && 332 name != VCWorkProp &&
333 name != VCPreferredProp && 333 name != VCPreferredProp &&
334 name.left( 2 ) != "X-" && name.left( 2 ) != "x-" ){ 334 name.left( 2 ) != "X-" && name.left( 2 ) != "x-" ){
335 // ### preffered should map to default email 335 // ### preffered should map to default email
336 valid = FALSE; 336 valid = FALSE;
337 odebug << "Email was detected as invalid!" << oendl; 337 odebug << "Email was detected as invalid!" << oendl;
338 } 338 }
339 } 339 }
340 if ( valid ) { 340 if ( valid ) {
341 c.insertEmail( email ); 341 c.insertEmail( email );
342 } 342 }
343 } 343 }
344 else if ( name == VCURLProp ) { 344 else if ( name == VCURLProp ) {
345 VObjectIterator nit; 345 VObjectIterator nit;
346 initPropIterator( &nit, o ); 346 initPropIterator( &nit, o );
347 while( moreIteration( &nit ) ) { 347 while( moreIteration( &nit ) ) {
348 VObject *o = nextVObject( &nit ); 348 VObject *o = nextVObject( &nit );
349 QCString name = vObjectTypeInfo( o ); 349 QCString name = vObjectTypeInfo( o );
350 if ( name == VCHomeProp ) 350 if ( name == VCHomeProp )
351 c.setHomeWebpage( value ); 351 c.setHomeWebpage( value );
352 else if ( name == VCWorkProp ) 352 else if ( name == VCWorkProp )
353 c.setBusinessWebpage( value ); 353 c.setBusinessWebpage( value );
354 } 354 }
355 } 355 }
356 else if ( name == VCOrgProp ) { 356 else if ( name == VCOrgProp ) {
357 VObjectIterator nit; 357 VObjectIterator nit;
358 initPropIterator( &nit, o ); 358 initPropIterator( &nit, o );
359 while( moreIteration( &nit ) ) { 359 while( moreIteration( &nit ) ) {
360 VObject *o = nextVObject( &nit ); 360 VObject *o = nextVObject( &nit );
361 QCString name = vObjectName( o ); 361 QCString name = vObjectName( o );
362 QString value = QString::fromUtf8( vObjectStringZValue( o ) ); 362 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
363 if ( name == VCOrgNameProp ) 363 if ( name == VCOrgNameProp )
364 c.setCompany( value ); 364 c.setCompany( value );
365 else if ( name == VCOrgUnitProp ) 365 else if ( name == VCOrgUnitProp )
366 c.setDepartment( value ); 366 c.setDepartment( value );
367 else if ( name == VCOrgUnit2Prop ) 367 else if ( name == VCOrgUnit2Prop )
368 c.setOffice( value ); 368 c.setOffice( value );
369 } 369 }
370 } 370 }
371 else if ( name == VCTitleProp ) { 371 else if ( name == VCTitleProp ) {
372 c.setJobTitle( value ); 372 c.setJobTitle( value );
373 } 373 }
374 else if ( name == "X-Qtopia-Profession" ) { 374 else if ( name == "X-Qtopia-Profession" ) {
375 c.setProfession( value ); 375 c.setProfession( value );
376 } 376 }
377 else if ( name == "X-Qtopia-Manager" ) { 377 else if ( name == "X-Qtopia-Manager" ) {
378 c.setManager( value ); 378 c.setManager( value );
379 } 379 }
380 else if ( name == "X-Qtopia-Assistant" ) { 380 else if ( name == "X-Qtopia-Assistant" ) {
381 c.setAssistant( value ); 381 c.setAssistant( value );
382 } 382 }
383 else if ( name == "X-Qtopia-Spouse" ) { 383 else if ( name == "X-Qtopia-Spouse" ) {
384 c.setSpouse( value ); 384 c.setSpouse( value );
385 } 385 }
386 else if ( name == "X-Qtopia-Gender" ) { 386 else if ( name == "X-Qtopia-Gender" ) {
387 c.setGender( value ); 387 c.setGender( value );
388 } 388 }
389 else if ( name == "X-Qtopia-Anniversary" ) { 389 else if ( name == "X-Qtopia-Anniversary" ) {
390 c.setAnniversary( convVCardDateToDate( value ) ); 390 c.setAnniversary( convVCardDateToDate( value ) );
391 } 391 }
392 else if ( name == "X-Qtopia-Nickname" ) { 392 else if ( name == "X-Qtopia-Nickname" ) {
393 c.setNickname( value ); 393 c.setNickname( value );
394 } 394 }
395 else if ( name == "X-Qtopia-Children" ) { 395 else if ( name == "X-Qtopia-Children" ) {
396 c.setChildren( value ); 396 c.setChildren( value );
397 } 397 }
398 else if ( name == VCBirthDateProp ) { 398 else if ( name == VCBirthDateProp ) {
399 // Reading Birthdate regarding RFC 2425 (5.8.4) 399 // Reading Birthdate regarding RFC 2425 (5.8.4)
400 c.setBirthday( convVCardDateToDate( value ) ); 400 c.setBirthday( convVCardDateToDate( value ) );
401 401
402 } 402 }
403 else if ( name == VCCommentProp ) { 403 else if ( name == VCCommentProp ) {
404 c.setNotes( value ); 404 c.setNotes( value );
405 } 405 }
406#if 0 406#if 0
407 else { 407 else {
408 printf("Name: %s, value=%s\n", name.data(), QString::fromUtf8( vObjectStringZValue( o ) ) ); 408 printf("Name: %s, value=%s\n", name.data(), QString::fromUtf8( vObjectStringZValue( o ) ) );
409 VObjectIterator nit; 409 VObjectIterator nit;
410 initPropIterator( &nit, o ); 410 initPropIterator( &nit, o );
411 while( moreIteration( &nit ) ) { 411 while( moreIteration( &nit ) ) {
412 VObject *o = nextVObject( &nit ); 412 VObject *o = nextVObject( &nit );
413 QCString name = vObjectName( o ); 413 QCString name = vObjectName( o );
414 QString value = QString::fromUtf8( vObjectStringZValue( o ) ); 414 QString value = QString::fromUtf8( vObjectStringZValue( o ) );
415 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 415 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
416 } 416 }
417 } 417 }
418 else { 418 else {
419 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 419 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
420 VObjectIterator nit; 420 VObjectIterator nit;
421 initPropIterator( &nit, o ); 421 initPropIterator( &nit, o );
422 while( moreIteration( &nit ) ) { 422 while( moreIteration( &nit ) ) {
423 VObject *o = nextVObject( &nit ); 423 VObject *o = nextVObject( &nit );
424 QCString name = vObjectName( o ); 424 QCString name = vObjectName( o );
425 QString value = vObjectStringZValue( o ); 425 QString value = vObjectStringZValue( o );
426 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 426 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
427 } 427 }
428 } 428 }
429#endif 429#endif
430 } 430 }
431 c.setFileAs(); 431 c.setFileAs();
432 return c; 432 return c;
433} 433}
434 434
435 435
436VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) 436VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
437{ 437{
438 VObject *vcard = newVObject( VCCardProp ); 438 VObject *vcard = newVObject( VCCardProp );
439 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 439 safeAddPropValue( vcard, VCVersionProp, "2.1" );
440 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 440 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
441 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 441 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
442 442
443 // full name 443 // full name
444 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 444 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
445 445
446 // name properties 446 // name properties
447 VObject *name = safeAddProp( vcard, VCNameProp ); 447 VObject *name = safeAddProp( vcard, VCNameProp );
448 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 448 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
449 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 449 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
450 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 450 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
451 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 451 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
452 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 452 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
453 453
454 // home properties 454 // home properties
455 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 455 if ( !( c.homeStreet().isEmpty()
456 safeAddProp( home_adr, VCHomeProp ); 456 && c.homeCity().isEmpty()
457 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 457 && c.homeState().isEmpty()
458 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 458 && c.homeZip().isEmpty()
459 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 459 && c.homeCountry().isEmpty() ) ){
460 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 460 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
461 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 461 safeAddProp( home_adr, VCHomeProp );
462 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
463 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
464 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
465 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
466 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
467 }
462 468
463 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 469 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
464 safeAddProp( home_phone, VCHomeProp ); 470 safeAddProp( home_phone, VCHomeProp );
465 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 471 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
466 safeAddProp( home_phone, VCHomeProp ); 472 safeAddProp( home_phone, VCHomeProp );
467 safeAddProp( home_phone, VCCellularProp ); 473 safeAddProp( home_phone, VCCellularProp );
468 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 474 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
469 safeAddProp( home_phone, VCHomeProp ); 475 safeAddProp( home_phone, VCHomeProp );
470 safeAddProp( home_phone, VCFaxProp ); 476 safeAddProp( home_phone, VCFaxProp );
471 477
472 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 478 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
473 safeAddProp( url, VCHomeProp ); 479 safeAddProp( url, VCHomeProp );
474 480
475 // work properties 481 // work properties
476 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 482 if ( !( c.businessStreet().isEmpty()
477 safeAddProp( work_adr, VCWorkProp ); 483 && c.businessCity().isEmpty()
478 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 484 && c.businessState().isEmpty()
479 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 485 && c.businessZip().isEmpty()
480 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 486 && c.businessCountry().isEmpty() ) ){
481 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 487 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
482 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 488 safeAddProp( work_adr, VCWorkProp );
489 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
490 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
491 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
492 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
493 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
494 }
483 495
484 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 496 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
485 safeAddProp( work_phone, VCWorkProp ); 497 safeAddProp( work_phone, VCWorkProp );
486 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 498 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
487 safeAddProp( work_phone, VCWorkProp ); 499 safeAddProp( work_phone, VCWorkProp );
488 safeAddProp( work_phone, VCCellularProp ); 500 safeAddProp( work_phone, VCCellularProp );
489 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 501 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
490 safeAddProp( work_phone, VCWorkProp ); 502 safeAddProp( work_phone, VCWorkProp );
491 safeAddProp( work_phone, VCFaxProp ); 503 safeAddProp( work_phone, VCFaxProp );
492 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 504 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
493 safeAddProp( work_phone, VCWorkProp ); 505 safeAddProp( work_phone, VCWorkProp );
494 safeAddProp( work_phone, VCPagerProp ); 506 safeAddProp( work_phone, VCPagerProp );
495 507
496 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 508 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
497 safeAddProp( url, VCWorkProp ); 509 safeAddProp( url, VCWorkProp );
498 510
499 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 511 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
500 safeAddProp( title, VCWorkProp ); 512 safeAddProp( title, VCWorkProp );
501 513
502 514
503 QStringList emails = c.emailList(); 515 QStringList emails = c.emailList();
504 // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 516 // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045
505 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 517 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
506 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 518 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
507 safeAddProp( email, VCInternetProp ); 519 safeAddProp( email, VCInternetProp );
508 } 520 }
509 521
510 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 522 safeAddPropValue( vcard, VCNoteProp, c.notes() );
511 523
512 // Exporting Birthday regarding RFC 2425 (5.8.4) 524 // Exporting Birthday regarding RFC 2425 (5.8.4)
513 if ( c.birthday().isValid() ){ 525 if ( c.birthday().isValid() ){
514 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); 526 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) );
515 } 527 }
516 528
517 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 529 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
518 VObject *org = safeAddProp( vcard, VCOrgProp ); 530 VObject *org = safeAddProp( vcard, VCOrgProp );
519 safeAddPropValue( org, VCOrgNameProp, c.company() ); 531 safeAddPropValue( org, VCOrgNameProp, c.company() );
520 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 532 safeAddPropValue( org, VCOrgUnitProp, c.department() );
521 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 533 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
522 } 534 }
523 535
524 // some values we have to export as custom fields 536 // some values we have to export as custom fields
525 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 537 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
526 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 538 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
527 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 539 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
528 540
529 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 541 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
530 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 542 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
531 if ( c.anniversary().isValid() ){ 543 if ( c.anniversary().isValid() ){
532 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); 544 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) );
533 } 545 }
534 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 546 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
535 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 547 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
536 548
537 return vcard; 549 return vcard;
538} 550}
539 551
540QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const 552QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const
541{ 553{
542 QString str_rfc2425 = QString("%1-%2-%3") 554 QString str_rfc2425 = QString("%1-%2-%3")
543 .arg( d.year() ) 555 .arg( d.year() )
544 .arg( d.month(), 2 ) 556 .arg( d.month(), 2 )
545 .arg( d.day(), 2 ); 557 .arg( d.day(), 2 );
546 // Now replace spaces with "0"... 558 // Now replace spaces with "0"...
547 int pos = 0; 559 int pos = 0;
548 while ( ( pos = str_rfc2425.find (' ') ) > 0 ) 560 while ( ( pos = str_rfc2425.find (' ') ) > 0 )
549 str_rfc2425.replace( pos, 1, "0" ); 561 str_rfc2425.replace( pos, 1, "0" );
550 562
551 return str_rfc2425; 563 return str_rfc2425;
552} 564}
553 565
554QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) 566QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr )
555{ 567{
556 int monthPos = datestr.find('-'); 568 int monthPos = datestr.find('-');
557 int dayPos = datestr.find('-', monthPos+1 ); 569 int dayPos = datestr.find('-', monthPos+1 );
558 int sep_ignore = 1; 570 int sep_ignore = 1;
559 if ( monthPos == -1 || dayPos == -1 ) { 571 if ( monthPos == -1 || dayPos == -1 ) {
560 odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; 572 odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
561 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 573 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
562 if ( datestr.length() == 8 ){ 574 if ( datestr.length() == 8 ){
563 monthPos = 4; 575 monthPos = 4;
564 dayPos = 6; 576 dayPos = 6;
565 sep_ignore = 0; 577 sep_ignore = 0;
566 odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; 578 odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
567 } else { 579 } else {
568 return QDate(); 580 return QDate();
569 } 581 }
570 } 582 }
571 int y = datestr.left( monthPos ).toInt(); 583 int y = datestr.left( monthPos ).toInt();
572 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 584 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
573 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 585 int d = datestr.mid( dayPos + sep_ignore ).toInt();
574 odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl; 586 odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
575 QDate date ( y,m,d ); 587 QDate date ( y,m,d );
576 return date; 588 return date;
577} 589}
578 590
579VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) 591VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value )
580{ 592{
581 VObject *ret = 0; 593 VObject *ret = 0;
582 if ( o && !value.isEmpty() ) 594 if ( o && !value.isEmpty() )
583 ret = addPropValue( o, prop, value.utf8() ); 595 ret = addPropValue( o, prop, value.utf8() );
584 return ret; 596 return ret;
585} 597}
586 598
587VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) 599VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop)
588{ 600{
589 VObject *ret = 0; 601 VObject *ret = 0;
590 if ( o ) 602 if ( o )
591 ret = addProp( o, prop ); 603 ret = addProp( o, prop );
592 return ret; 604 return ret;
593} 605}
594 606
595 607
596 608
597} 609}