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