author | ulf69 <ulf69> | 2004-07-09 08:10:08 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-09 08:10:08 (UTC) |
commit | de99e22a7093e857ee3c08a67ccc389d6374099a (patch) (unidiff) | |
tree | 511c309f9df3ae71d43c194cc41f27bdb1966a05 | |
parent | d56bb523048598245ac4ffcb16689687e082f831 (diff) | |
download | kdepimpi-de99e22a7093e857ee3c08a67ccc389d6374099a.zip kdepimpi-de99e22a7093e857ee3c08a67ccc389d6374099a.tar.gz kdepimpi-de99e22a7093e857ee3c08a67ccc389d6374099a.tar.bz2 |
support of caseinsensitive phone and adress types, as required by the vcard spec
-rw-r--r-- | kabc/converter/opie/opieconverterE.pro | 2 | ||||
-rw-r--r-- | kabc/formats/vcardformatplugin2.cpp | 4 | ||||
-rw-r--r-- | kabc/vcardformatimpl.cpp | 48 | ||||
-rw-r--r-- | kabc/vcardformatplugin.cpp | 4 | ||||
-rw-r--r-- | kabc/vcardparser/vcardtool.cpp | 22 |
5 files changed, 53 insertions, 27 deletions
diff --git a/kabc/converter/opie/opieconverterE.pro b/kabc/converter/opie/opieconverterE.pro index 85ba28f..e026f2a 100644 --- a/kabc/converter/opie/opieconverterE.pro +++ b/kabc/converter/opie/opieconverterE.pro | |||
@@ -1,32 +1,32 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | INCLUDEPATH += . ../.. ../../../microkde ../../../microkde/kdecore $(QPEDIR)/include $(OPIEDIR)/include | 2 | INCLUDEPATH += . ../.. ../../../microkde ../../../microkde/kdecore $(OPIEDIR)/include $(OPEDIR)/include |
3 | #CONFIG += staticlib | 3 | #CONFIG += staticlib |
4 | OBJECTS_DIR = obj/$(PLATFORM) | 4 | OBJECTS_DIR = obj/$(PLATFORM) |
5 | MOC_DIR = moc/$(PLATFORM) | 5 | MOC_DIR = moc/$(PLATFORM) |
6 | 6 | ||
7 | #for static linkage, put it here | 7 | #for static linkage, put it here |
8 | #DESTDIR=../../lib/$(PLATFORM) | 8 | #DESTDIR=../../lib/$(PLATFORM) |
9 | 9 | ||
10 | #for dynamic linkage, put it here | 10 | #for dynamic linkage, put it here |
11 | DESTDIR=$(QPEDIR)/lib | 11 | DESTDIR=$(QPEDIR)/lib |
12 | 12 | ||
13 | LIBS += -lmicrokde | 13 | LIBS += -lmicrokde |
14 | LIBS += -lmicrokabc | 14 | LIBS += -lmicrokabc |
15 | LIBS += -L$(QPEDIR)/lib | 15 | LIBS += -L$(QPEDIR)/lib |
16 | LIBS += -L$(OPIEDIR)/lib | 16 | LIBS += -L$(OPIEDIR)/lib |
17 | LIBS += -lopie | 17 | LIBS += -lopie |
18 | LIBS += -lqpe | 18 | LIBS += -lqpe |
19 | LIBS += -lqte | 19 | LIBS += -lqte |
20 | 20 | ||
21 | 21 | ||
22 | TARGET = microkabc_opieconverter | 22 | TARGET = microkabc_opieconverter |
23 | 23 | ||
24 | # Input | 24 | # Input |
25 | 25 | ||
26 | HEADERS += \ | 26 | HEADERS += \ |
27 | opieconverter.h \ | 27 | opieconverter.h \ |
28 | 28 | ||
29 | 29 | ||
30 | SOURCES += \ | 30 | SOURCES += \ |
31 | opieconverter.cpp \ | 31 | opieconverter.cpp \ |
32 | 32 | ||
diff --git a/kabc/formats/vcardformatplugin2.cpp b/kabc/formats/vcardformatplugin2.cpp index f19e218..41b0c9a 100644 --- a/kabc/formats/vcardformatplugin2.cpp +++ b/kabc/formats/vcardformatplugin2.cpp | |||
@@ -1,120 +1,124 @@ | |||
1 | /* | 1 | /* |
2 | Enhanced Version of the file for platform independent KDE tools. | 2 | Enhanced Version of the file for platform independent KDE tools. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | $Id$ | 5 | $Id$ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "vcardformatplugin2.h" | 8 | #include "vcardformatplugin2.h" |
9 | 9 | ||
10 | #include "address.h" | 10 | #include "address.h" |
11 | #include "addressee.h" | 11 | #include "addressee.h" |
12 | #include "vcardparser/vcardtool.h" | 12 | #include "vcardparser/vcardtool.h" |
13 | 13 | ||
14 | #include <qtextstream.h> | 14 | #include <qtextstream.h> |
15 | #include <qfile.h> | 15 | #include <qfile.h> |
16 | 16 | ||
17 | using namespace KABC; | 17 | using namespace KABC; |
18 | 18 | ||
19 | extern "C" | 19 | extern "C" |
20 | { | 20 | { |
21 | FormatPlugin *format() | 21 | FormatPlugin *format() |
22 | { | 22 | { |
23 | return new VCardFormatPlugin2(); | 23 | return new VCardFormatPlugin2(); |
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | VCardFormatPlugin2::VCardFormatPlugin2() | 27 | VCardFormatPlugin2::VCardFormatPlugin2() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | VCardFormatPlugin2::~VCardFormatPlugin2() | 31 | VCardFormatPlugin2::~VCardFormatPlugin2() |
32 | { | 32 | { |
33 | } | 33 | } |
34 | 34 | ||
35 | bool VCardFormatPlugin2::load( Addressee &addressee, QFile *file ) | 35 | bool VCardFormatPlugin2::load( Addressee &addressee, QFile *file ) |
36 | { | 36 | { |
37 | qDebug("VCardFormatPlugin2::load"); | ||
37 | QString data; | 38 | QString data; |
38 | 39 | ||
39 | QTextStream t( file ); | 40 | QTextStream t( file ); |
40 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 41 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
41 | data = t.read(); | 42 | data = t.read(); |
42 | 43 | ||
43 | VCardTool tool; | 44 | VCardTool tool; |
44 | 45 | ||
45 | Addressee::List l = tool.parseVCards( data ); | 46 | Addressee::List l = tool.parseVCards( data ); |
46 | 47 | ||
47 | if ( ! l.first().isEmpty() ) { | 48 | if ( ! l.first().isEmpty() ) { |
48 | addressee = l.first(); | 49 | addressee = l.first(); |
49 | return true; | 50 | return true; |
50 | } | 51 | } |
51 | 52 | ||
52 | return false; | 53 | return false; |
53 | } | 54 | } |
54 | 55 | ||
55 | bool VCardFormatPlugin2::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) | 56 | bool VCardFormatPlugin2::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) |
56 | { | 57 | { |
58 | qDebug("VCardFormatPlugin2::loadAll"); | ||
57 | QString data; | 59 | QString data; |
58 | 60 | ||
59 | QTextStream t( file ); | 61 | QTextStream t( file ); |
60 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 62 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
61 | data = t.read(); | 63 | data = t.read(); |
62 | 64 | ||
63 | VCardTool tool; | 65 | VCardTool tool; |
64 | 66 | ||
65 | Addressee::List l = tool.parseVCards( data ); | 67 | Addressee::List l = tool.parseVCards( data ); |
66 | 68 | ||
67 | Addressee::List::Iterator itr; | 69 | Addressee::List::Iterator itr; |
68 | 70 | ||
69 | for ( itr = l.begin(); itr != l.end(); ++itr) { | 71 | for ( itr = l.begin(); itr != l.end(); ++itr) { |
70 | Addressee addressee = *itr; | 72 | Addressee addressee = *itr; |
71 | addressee.setResource( resource ); | 73 | addressee.setResource( resource ); |
72 | addressBook->insertAddressee( addressee ); | 74 | addressBook->insertAddressee( addressee ); |
73 | } | 75 | } |
74 | 76 | ||
75 | return true; | 77 | return true; |
76 | } | 78 | } |
77 | 79 | ||
78 | void VCardFormatPlugin2::save( const Addressee &addressee, QFile *file ) | 80 | void VCardFormatPlugin2::save( const Addressee &addressee, QFile *file ) |
79 | { | 81 | { |
82 | qDebug("VCardFormatPlugin2::save"); | ||
80 | VCardTool tool; | 83 | VCardTool tool; |
81 | Addressee::List vcardlist; | 84 | Addressee::List vcardlist; |
82 | 85 | ||
83 | 86 | ||
84 | vcardlist.append( addressee ); | 87 | vcardlist.append( addressee ); |
85 | 88 | ||
86 | QTextStream t( file ); | 89 | QTextStream t( file ); |
87 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 90 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
88 | t << tool.createVCards( vcardlist ); | 91 | t << tool.createVCards( vcardlist ); |
89 | } | 92 | } |
90 | 93 | ||
91 | void VCardFormatPlugin2::saveAll( AddressBook *ab, Resource *resource, QFile *file ) | 94 | void VCardFormatPlugin2::saveAll( AddressBook *ab, Resource *resource, QFile *file ) |
92 | { | 95 | { |
96 | qDebug("VCardFormatPlugin2::saveAll"); | ||
93 | VCardTool tool; | 97 | VCardTool tool; |
94 | Addressee::List vcardlist; | 98 | Addressee::List vcardlist; |
95 | 99 | ||
96 | AddressBook::Iterator it; | 100 | AddressBook::Iterator it; |
97 | for ( it = ab->begin(); it != ab->end(); ++it ) { | 101 | for ( it = ab->begin(); it != ab->end(); ++it ) { |
98 | if ( (*it).resource() == resource ) { | 102 | if ( (*it).resource() == resource ) { |
99 | (*it).setChanged( false ); | 103 | (*it).setChanged( false ); |
100 | vcardlist.append( *it ); | 104 | vcardlist.append( *it ); |
101 | } | 105 | } |
102 | } | 106 | } |
103 | 107 | ||
104 | QTextStream t( file ); | 108 | QTextStream t( file ); |
105 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 109 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
106 | t << tool.createVCards( vcardlist ); | 110 | t << tool.createVCards( vcardlist ); |
107 | } | 111 | } |
108 | 112 | ||
109 | bool VCardFormatPlugin2::checkFormat( QFile *file ) const | 113 | bool VCardFormatPlugin2::checkFormat( QFile *file ) const |
110 | { | 114 | { |
111 | QString line; | 115 | QString line; |
112 | 116 | ||
113 | file->readLine( line, 1024 ); | 117 | file->readLine( line, 1024 ); |
114 | line = line.stripWhiteSpace(); | 118 | line = line.stripWhiteSpace(); |
115 | if ( line == "BEGIN:VCARD" ) | 119 | if ( line == "BEGIN:VCARD" ) |
116 | return true; | 120 | return true; |
117 | else | 121 | else |
118 | return false; | 122 | return false; |
119 | } | 123 | } |
120 | 124 | ||
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index f90f813..3fcaf94 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp | |||
@@ -143,861 +143,865 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard &v ) | |||
143 | 143 | ||
144 | case EntityUID: | 144 | case EntityUID: |
145 | addressee.setUid( readTextValue( cl ) ); | 145 | addressee.setUid( readTextValue( cl ) ); |
146 | break; | 146 | break; |
147 | 147 | ||
148 | case EntityEmail: | 148 | case EntityEmail: |
149 | addressee.insertEmail( readTextValue( cl ) ); | 149 | addressee.insertEmail( readTextValue( cl ) ); |
150 | break; | 150 | break; |
151 | 151 | ||
152 | case EntityName: | 152 | case EntityName: |
153 | addressee.setName( readTextValue( cl ) ); | 153 | addressee.setName( readTextValue( cl ) ); |
154 | break; | 154 | break; |
155 | 155 | ||
156 | case EntityFullName: | 156 | case EntityFullName: |
157 | addressee.setFormattedName( readTextValue( cl ) ); | 157 | addressee.setFormattedName( readTextValue( cl ) ); |
158 | break; | 158 | break; |
159 | 159 | ||
160 | case EntityURL: | 160 | case EntityURL: |
161 | addressee.setUrl( KURL( readTextValue( cl ) ) ); | 161 | addressee.setUrl( KURL( readTextValue( cl ) ) ); |
162 | break; | 162 | break; |
163 | 163 | ||
164 | case EntityNickname: | 164 | case EntityNickname: |
165 | addressee.setNickName( readTextValue( cl ) ); | 165 | addressee.setNickName( readTextValue( cl ) ); |
166 | break; | 166 | break; |
167 | 167 | ||
168 | case EntityLabel: | 168 | case EntityLabel: |
169 | // not yet supported by kabc | 169 | // not yet supported by kabc |
170 | break; | 170 | break; |
171 | 171 | ||
172 | case EntityMailer: | 172 | case EntityMailer: |
173 | addressee.setMailer( readTextValue( cl ) ); | 173 | addressee.setMailer( readTextValue( cl ) ); |
174 | break; | 174 | break; |
175 | 175 | ||
176 | case EntityTitle: | 176 | case EntityTitle: |
177 | addressee.setTitle( readTextValue( cl ) ); | 177 | addressee.setTitle( readTextValue( cl ) ); |
178 | break; | 178 | break; |
179 | 179 | ||
180 | case EntityRole: | 180 | case EntityRole: |
181 | addressee.setRole( readTextValue( cl ) ); | 181 | addressee.setRole( readTextValue( cl ) ); |
182 | break; | 182 | break; |
183 | 183 | ||
184 | case EntityOrganisation: | 184 | case EntityOrganisation: |
185 | addressee.setOrganization( readTextValue( cl ) ); | 185 | addressee.setOrganization( readTextValue( cl ) ); |
186 | break; | 186 | break; |
187 | 187 | ||
188 | case EntityNote: | 188 | case EntityNote: |
189 | addressee.setNote( readTextValue( cl ) ); | 189 | addressee.setNote( readTextValue( cl ) ); |
190 | break; | 190 | break; |
191 | 191 | ||
192 | case EntityProductID: | 192 | case EntityProductID: |
193 | addressee.setProductId( readTextValue( cl ) ); | 193 | addressee.setProductId( readTextValue( cl ) ); |
194 | break; | 194 | break; |
195 | 195 | ||
196 | case EntitySortString: | 196 | case EntitySortString: |
197 | addressee.setSortString( readTextValue( cl ) ); | 197 | addressee.setSortString( readTextValue( cl ) ); |
198 | break; | 198 | break; |
199 | 199 | ||
200 | case EntityN: | 200 | case EntityN: |
201 | readNValue( cl, addressee ); | 201 | readNValue( cl, addressee ); |
202 | break; | 202 | break; |
203 | 203 | ||
204 | case EntityAddress: | 204 | case EntityAddress: |
205 | addressee.insertAddress( readAddressValue( cl ) ); | 205 | addressee.insertAddress( readAddressValue( cl ) ); |
206 | break; | 206 | break; |
207 | 207 | ||
208 | case EntityTelephone: | 208 | case EntityTelephone: |
209 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); | 209 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); |
210 | break; | 210 | break; |
211 | 211 | ||
212 | case EntityCategories: | 212 | case EntityCategories: |
213 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); | 213 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); |
214 | break; | 214 | break; |
215 | 215 | ||
216 | case EntityBirthday: | 216 | case EntityBirthday: |
217 | addressee.setBirthday( readDateValue( cl ) ); | 217 | addressee.setBirthday( readDateValue( cl ) ); |
218 | break; | 218 | break; |
219 | 219 | ||
220 | case EntityRevision: | 220 | case EntityRevision: |
221 | addressee.setRevision( readDateTimeValue( cl ) ); | 221 | addressee.setRevision( readDateTimeValue( cl ) ); |
222 | break; | 222 | break; |
223 | 223 | ||
224 | case EntityGeo: | 224 | case EntityGeo: |
225 | addressee.setGeo( readGeoValue( cl ) ); | 225 | addressee.setGeo( readGeoValue( cl ) ); |
226 | break; | 226 | break; |
227 | 227 | ||
228 | case EntityTimeZone: | 228 | case EntityTimeZone: |
229 | addressee.setTimeZone( readUTCValue( cl ) ); | 229 | addressee.setTimeZone( readUTCValue( cl ) ); |
230 | break; | 230 | break; |
231 | 231 | ||
232 | case EntityVersion: | 232 | case EntityVersion: |
233 | break; | 233 | break; |
234 | 234 | ||
235 | case EntityClass: | 235 | case EntityClass: |
236 | addressee.setSecrecy( readClassValue( cl ) ); | 236 | addressee.setSecrecy( readClassValue( cl ) ); |
237 | break; | 237 | break; |
238 | 238 | ||
239 | case EntityKey: | 239 | case EntityKey: |
240 | addressee.insertKey( readKeyValue( cl ) ); | 240 | addressee.insertKey( readKeyValue( cl ) ); |
241 | break; | 241 | break; |
242 | 242 | ||
243 | case EntityPhoto: | 243 | case EntityPhoto: |
244 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); | 244 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); |
245 | break; | 245 | break; |
246 | 246 | ||
247 | case EntityLogo: | 247 | case EntityLogo: |
248 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); | 248 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); |
249 | break; | 249 | break; |
250 | 250 | ||
251 | case EntityAgent: | 251 | case EntityAgent: |
252 | addressee.setAgent( readAgentValue( cl ) ); | 252 | addressee.setAgent( readAgentValue( cl ) ); |
253 | break; | 253 | break; |
254 | 254 | ||
255 | case EntitySound: | 255 | case EntitySound: |
256 | addressee.setSound( readSoundValue( cl, addressee ) ); | 256 | addressee.setSound( readSoundValue( cl, addressee ) ); |
257 | break; | 257 | break; |
258 | 258 | ||
259 | default: | 259 | default: |
260 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " | 260 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " |
261 | << int( type ) << ": " << cl->asString() << endl; | 261 | << int( type ) << ": " << cl->asString() << endl; |
262 | break; | 262 | break; |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 266 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
267 | EntityType type = cl->entityType(); | 267 | EntityType type = cl->entityType(); |
268 | if ( type == EntityLabel ) { | 268 | if ( type == EntityLabel ) { |
269 | int type = readAddressParam( cl ); | 269 | int type = readAddressParam( cl ); |
270 | Address address = addressee.address( type ); | 270 | Address address = addressee.address( type ); |
271 | if ( address.isEmpty() ) | 271 | if ( address.isEmpty() ) |
272 | address.setType( type ); | 272 | address.setType( type ); |
273 | 273 | ||
274 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); | 274 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); |
275 | addressee.insertAddress( address ); | 275 | addressee.insertAddress( address ); |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | return true; | 279 | return true; |
280 | } | 280 | } |
281 | 281 | ||
282 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) | 282 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) |
283 | { | 283 | { |
284 | ContentLine cl; | 284 | ContentLine cl; |
285 | QString value; | 285 | QString value; |
286 | 286 | ||
287 | addTextValue( v, EntityName, addressee.name() ); | 287 | addTextValue( v, EntityName, addressee.name() ); |
288 | addTextValue( v, EntityUID, addressee.uid() ); | 288 | addTextValue( v, EntityUID, addressee.uid() ); |
289 | addTextValue( v, EntityFullName, addressee.formattedName() ); | 289 | addTextValue( v, EntityFullName, addressee.formattedName() ); |
290 | 290 | ||
291 | QStringList emails = addressee.emails(); | 291 | QStringList emails = addressee.emails(); |
292 | QStringList::ConstIterator it4; | 292 | QStringList::ConstIterator it4; |
293 | for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { | 293 | for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { |
294 | addTextValue( v, EntityEmail, *it4 ); | 294 | addTextValue( v, EntityEmail, *it4 ); |
295 | } | 295 | } |
296 | 296 | ||
297 | QStringList customs = addressee.customs(); | 297 | QStringList customs = addressee.customs(); |
298 | QStringList::ConstIterator it5; | 298 | QStringList::ConstIterator it5; |
299 | for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { | 299 | for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { |
300 | addCustomValue( v, *it5 ); | 300 | addCustomValue( v, *it5 ); |
301 | } | 301 | } |
302 | 302 | ||
303 | addTextValue( v, EntityURL, addressee.url().url() ); | 303 | addTextValue( v, EntityURL, addressee.url().url() ); |
304 | 304 | ||
305 | addNValue( v, addressee ); | 305 | addNValue( v, addressee ); |
306 | 306 | ||
307 | addTextValue( v, EntityNickname, addressee.nickName() ); | 307 | addTextValue( v, EntityNickname, addressee.nickName() ); |
308 | addTextValue( v, EntityMailer, addressee.mailer() ); | 308 | addTextValue( v, EntityMailer, addressee.mailer() ); |
309 | addTextValue( v, EntityTitle, addressee.title() ); | 309 | addTextValue( v, EntityTitle, addressee.title() ); |
310 | addTextValue( v, EntityRole, addressee.role() ); | 310 | addTextValue( v, EntityRole, addressee.role() ); |
311 | addTextValue( v, EntityOrganisation, addressee.organization() ); | 311 | addTextValue( v, EntityOrganisation, addressee.organization() ); |
312 | addTextValue( v, EntityNote, addressee.note() ); | 312 | addTextValue( v, EntityNote, addressee.note() ); |
313 | addTextValue( v, EntityProductID, addressee.productId() ); | 313 | addTextValue( v, EntityProductID, addressee.productId() ); |
314 | addTextValue( v, EntitySortString, addressee.sortString() ); | 314 | addTextValue( v, EntitySortString, addressee.sortString() ); |
315 | 315 | ||
316 | Address::List addresses = addressee.addresses(); | 316 | Address::List addresses = addressee.addresses(); |
317 | Address::List::ConstIterator it3; | 317 | Address::List::ConstIterator it3; |
318 | for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { | 318 | for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { |
319 | addAddressValue( v, *it3 ); | 319 | addAddressValue( v, *it3 ); |
320 | addLabelValue( v, *it3 ); | 320 | addLabelValue( v, *it3 ); |
321 | } | 321 | } |
322 | 322 | ||
323 | PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); | 323 | PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); |
324 | PhoneNumber::List::ConstIterator it2; | 324 | PhoneNumber::List::ConstIterator it2; |
325 | for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { | 325 | for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { |
326 | addTelephoneValue( v, *it2 ); | 326 | addTelephoneValue( v, *it2 ); |
327 | } | 327 | } |
328 | 328 | ||
329 | Key::List keys = addressee.keys(); | 329 | Key::List keys = addressee.keys(); |
330 | Key::List::ConstIterator it6; | 330 | Key::List::ConstIterator it6; |
331 | for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { | 331 | for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { |
332 | addKeyValue( v, *it6 ); | 332 | addKeyValue( v, *it6 ); |
333 | } | 333 | } |
334 | 334 | ||
335 | addTextValue( v, EntityCategories, addressee.categories().join(",") ); | 335 | addTextValue( v, EntityCategories, addressee.categories().join(",") ); |
336 | 336 | ||
337 | addDateValue( v, EntityBirthday, addressee.birthday().date() ); | 337 | addDateValue( v, EntityBirthday, addressee.birthday().date() ); |
338 | addDateTimeValue( v, EntityRevision, addressee.revision() ); | 338 | addDateTimeValue( v, EntityRevision, addressee.revision() ); |
339 | addGeoValue( v, addressee.geo() ); | 339 | addGeoValue( v, addressee.geo() ); |
340 | addUTCValue( v, addressee.timeZone() ); | 340 | addUTCValue( v, addressee.timeZone() ); |
341 | 341 | ||
342 | addClassValue( v, addressee.secrecy() ); | 342 | addClassValue( v, addressee.secrecy() ); |
343 | 343 | ||
344 | addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); | 344 | addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); |
345 | addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); | 345 | addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); |
346 | 346 | ||
347 | addAgentValue( v, addressee.agent() ); | 347 | addAgentValue( v, addressee.agent() ); |
348 | 348 | ||
349 | addSoundValue( v, addressee.sound(), addressee, intern ); | 349 | addSoundValue( v, addressee.sound(), addressee, intern ); |
350 | } | 350 | } |
351 | 351 | ||
352 | void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) | 352 | void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) |
353 | { | 353 | { |
354 | if ( txt.isEmpty() ) return; | 354 | if ( txt.isEmpty() ) return; |
355 | 355 | ||
356 | ContentLine cl; | 356 | ContentLine cl; |
357 | cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); | 357 | cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); |
358 | QString value = txt.mid( txt.find( ":" ) + 1 ); | 358 | QString value = txt.mid( txt.find( ":" ) + 1 ); |
359 | if ( value.isEmpty() ) | 359 | if ( value.isEmpty() ) |
360 | return; | 360 | return; |
361 | cl.setValue( new TextValue( value.utf8() ) ); | 361 | cl.setValue( new TextValue( value.utf8() ) ); |
362 | v->add(cl); | 362 | v->add(cl); |
363 | } | 363 | } |
364 | 364 | ||
365 | void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) | 365 | void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) |
366 | { | 366 | { |
367 | if ( txt.isEmpty() ) return; | 367 | if ( txt.isEmpty() ) return; |
368 | 368 | ||
369 | ContentLine cl; | 369 | ContentLine cl; |
370 | cl.setName( EntityTypeToParamName( type ) ); | 370 | cl.setName( EntityTypeToParamName( type ) ); |
371 | cl.setValue( new TextValue( txt.utf8() ) ); | 371 | cl.setValue( new TextValue( txt.utf8() ) ); |
372 | v->add(cl); | 372 | v->add(cl); |
373 | } | 373 | } |
374 | 374 | ||
375 | void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, | 375 | void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, |
376 | const QDate &date ) | 376 | const QDate &date ) |
377 | { | 377 | { |
378 | if ( !date.isValid() ) return; | 378 | if ( !date.isValid() ) return; |
379 | 379 | ||
380 | ContentLine cl; | 380 | ContentLine cl; |
381 | cl.setName( EntityTypeToParamName( type ) ); | 381 | cl.setName( EntityTypeToParamName( type ) ); |
382 | 382 | ||
383 | DateValue *v = new DateValue( date ); | 383 | DateValue *v = new DateValue( date ); |
384 | cl.setValue( v ); | 384 | cl.setValue( v ); |
385 | vcard->add(cl); | 385 | vcard->add(cl); |
386 | } | 386 | } |
387 | 387 | ||
388 | void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, | 388 | void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, |
389 | const QDateTime &dateTime ) | 389 | const QDateTime &dateTime ) |
390 | { | 390 | { |
391 | if ( !dateTime.isValid() ) return; | 391 | if ( !dateTime.isValid() ) return; |
392 | 392 | ||
393 | ContentLine cl; | 393 | ContentLine cl; |
394 | cl.setName( EntityTypeToParamName( type ) ); | 394 | cl.setName( EntityTypeToParamName( type ) ); |
395 | 395 | ||
396 | DateValue *v = new DateValue( dateTime ); | 396 | DateValue *v = new DateValue( dateTime ); |
397 | cl.setValue( v ); | 397 | cl.setValue( v ); |
398 | vcard->add(cl); | 398 | vcard->add(cl); |
399 | } | 399 | } |
400 | 400 | ||
401 | void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) | 401 | void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) |
402 | { | 402 | { |
403 | if ( a.isEmpty() ) | 403 | if ( a.isEmpty() ) |
404 | return; | 404 | return; |
405 | 405 | ||
406 | ContentLine cl; | 406 | ContentLine cl; |
407 | cl.setName( EntityTypeToParamName( EntityAddress ) ); | 407 | cl.setName( EntityTypeToParamName( EntityAddress ) ); |
408 | 408 | ||
409 | AdrValue *v = new AdrValue; | 409 | AdrValue *v = new AdrValue; |
410 | v->setPOBox( a.postOfficeBox().utf8() ); | 410 | v->setPOBox( a.postOfficeBox().utf8() ); |
411 | v->setExtAddress( a.extended().utf8() ); | 411 | v->setExtAddress( a.extended().utf8() ); |
412 | v->setStreet( a.street().utf8() ); | 412 | v->setStreet( a.street().utf8() ); |
413 | v->setLocality( a.locality().utf8() ); | 413 | v->setLocality( a.locality().utf8() ); |
414 | v->setRegion( a.region().utf8() ); | 414 | v->setRegion( a.region().utf8() ); |
415 | v->setPostCode( a.postalCode().utf8() ); | 415 | v->setPostCode( a.postalCode().utf8() ); |
416 | v->setCountryName( a.country().utf8() ); | 416 | v->setCountryName( a.country().utf8() ); |
417 | cl.setValue( v ); | 417 | cl.setValue( v ); |
418 | 418 | ||
419 | addAddressParam( &cl, a.type() ); | 419 | addAddressParam( &cl, a.type() ); |
420 | 420 | ||
421 | vcard->add( cl ); | 421 | vcard->add( cl ); |
422 | } | 422 | } |
423 | 423 | ||
424 | void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) | 424 | void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) |
425 | { | 425 | { |
426 | if ( a.label().isEmpty() ) return; | 426 | if ( a.label().isEmpty() ) return; |
427 | 427 | ||
428 | ContentLine cl; | 428 | ContentLine cl; |
429 | cl.setName( EntityTypeToParamName( EntityLabel ) ); | 429 | cl.setName( EntityTypeToParamName( EntityLabel ) ); |
430 | cl.setValue( new TextValue( a.label().utf8() ) ); | 430 | cl.setValue( new TextValue( a.label().utf8() ) ); |
431 | 431 | ||
432 | addAddressParam( &cl, a.type() ); | 432 | addAddressParam( &cl, a.type() ); |
433 | 433 | ||
434 | vcard->add( cl ); | 434 | vcard->add( cl ); |
435 | } | 435 | } |
436 | 436 | ||
437 | void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) | 437 | void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) |
438 | { | 438 | { |
439 | ParamList params; | 439 | ParamList params; |
440 | if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); | 440 | if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); |
441 | if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); | 441 | if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); |
442 | if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); | 442 | if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); |
443 | if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); | 443 | if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); |
444 | if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); | 444 | if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); |
445 | if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); | 445 | if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); |
446 | if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); | 446 | if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); |
447 | cl->setParamList( params ); | 447 | cl->setParamList( params ); |
448 | } | 448 | } |
449 | 449 | ||
450 | void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) | 450 | void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) |
451 | { | 451 | { |
452 | if ( !geo.isValid() ) return; | 452 | if ( !geo.isValid() ) return; |
453 | 453 | ||
454 | ContentLine cl; | 454 | ContentLine cl; |
455 | cl.setName( EntityTypeToParamName( EntityGeo ) ); | 455 | cl.setName( EntityTypeToParamName( EntityGeo ) ); |
456 | 456 | ||
457 | GeoValue *v = new GeoValue; | 457 | GeoValue *v = new GeoValue; |
458 | v->setLatitude( geo.latitude() ); | 458 | v->setLatitude( geo.latitude() ); |
459 | v->setLongitude( geo.longitude() ); | 459 | v->setLongitude( geo.longitude() ); |
460 | 460 | ||
461 | cl.setValue( v ); | 461 | cl.setValue( v ); |
462 | vcard->add(cl); | 462 | vcard->add(cl); |
463 | } | 463 | } |
464 | 464 | ||
465 | void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) | 465 | void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) |
466 | { | 466 | { |
467 | if ( !tz.isValid() ) return; | 467 | if ( !tz.isValid() ) return; |
468 | 468 | ||
469 | ContentLine cl; | 469 | ContentLine cl; |
470 | cl.setName( EntityTypeToParamName( EntityTimeZone ) ); | 470 | cl.setName( EntityTypeToParamName( EntityTimeZone ) ); |
471 | 471 | ||
472 | UTCValue *v = new UTCValue; | 472 | UTCValue *v = new UTCValue; |
473 | 473 | ||
474 | v->setPositive( tz.offset() >= 0 ); | 474 | v->setPositive( tz.offset() >= 0 ); |
475 | v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); | 475 | v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); |
476 | v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); | 476 | v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); |
477 | 477 | ||
478 | cl.setValue( v ); | 478 | cl.setValue( v ); |
479 | vcard->add(cl); | 479 | vcard->add(cl); |
480 | } | 480 | } |
481 | 481 | ||
482 | void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) | 482 | void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) |
483 | { | 483 | { |
484 | ContentLine cl; | 484 | ContentLine cl; |
485 | cl.setName( EntityTypeToParamName( EntityClass ) ); | 485 | cl.setName( EntityTypeToParamName( EntityClass ) ); |
486 | 486 | ||
487 | ClassValue *v = new ClassValue; | 487 | ClassValue *v = new ClassValue; |
488 | switch ( secrecy.type() ) { | 488 | switch ( secrecy.type() ) { |
489 | case Secrecy::Public: | 489 | case Secrecy::Public: |
490 | v->setType( (int)ClassValue::Public ); | 490 | v->setType( (int)ClassValue::Public ); |
491 | break; | 491 | break; |
492 | case Secrecy::Private: | 492 | case Secrecy::Private: |
493 | v->setType( (int)ClassValue::Private ); | 493 | v->setType( (int)ClassValue::Private ); |
494 | break; | 494 | break; |
495 | case Secrecy::Confidential: | 495 | case Secrecy::Confidential: |
496 | v->setType( (int)ClassValue::Confidential ); | 496 | v->setType( (int)ClassValue::Confidential ); |
497 | break; | 497 | break; |
498 | } | 498 | } |
499 | 499 | ||
500 | cl.setValue( v ); | 500 | cl.setValue( v ); |
501 | vcard->add(cl); | 501 | vcard->add(cl); |
502 | } | 502 | } |
503 | 503 | ||
504 | 504 | ||
505 | Address VCardFormatImpl::readAddressValue( ContentLine *cl ) | 505 | Address VCardFormatImpl::readAddressValue( ContentLine *cl ) |
506 | { | 506 | { |
507 | Address a; | 507 | Address a; |
508 | AdrValue *v = (AdrValue *)cl->value(); | 508 | AdrValue *v = (AdrValue *)cl->value(); |
509 | a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); | 509 | a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); |
510 | a.setExtended( QString::fromUtf8( v->extAddress() ) ); | 510 | a.setExtended( QString::fromUtf8( v->extAddress() ) ); |
511 | a.setStreet( QString::fromUtf8( v->street() ) ); | 511 | a.setStreet( QString::fromUtf8( v->street() ) ); |
512 | a.setLocality( QString::fromUtf8( v->locality() ) ); | 512 | a.setLocality( QString::fromUtf8( v->locality() ) ); |
513 | a.setRegion( QString::fromUtf8( v->region() ) ); | 513 | a.setRegion( QString::fromUtf8( v->region() ) ); |
514 | a.setPostalCode( QString::fromUtf8( v->postCode() ) ); | 514 | a.setPostalCode( QString::fromUtf8( v->postCode() ) ); |
515 | a.setCountry( QString::fromUtf8( v->countryName() ) ); | 515 | a.setCountry( QString::fromUtf8( v->countryName() ) ); |
516 | 516 | ||
517 | a.setType( readAddressParam( cl ) ); | 517 | a.setType( readAddressParam( cl ) ); |
518 | 518 | ||
519 | return a; | 519 | return a; |
520 | } | 520 | } |
521 | 521 | ||
522 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) | 522 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) |
523 | { | 523 | { |
524 | int type = 0; | 524 | int type = 0; |
525 | ParamList params = cl->paramList(); | 525 | ParamList params = cl->paramList(); |
526 | ParamListIterator it( params ); | 526 | ParamListIterator it( params ); |
527 | QCString tmpStr; | ||
527 | for( ; it.current(); ++it ) { | 528 | for( ; it.current(); ++it ) { |
528 | if ( (*it)->name() == "TYPE" ) { | 529 | if ( (*it)->name().upper() == "TYPE" ) { |
529 | if ( (*it)->value() == "dom" ) type |= Address::Dom; | 530 | tmpStr = (*it)->value().lower(); |
530 | else if ( (*it)->value() == "intl" ) type |= Address::Intl; | 531 | if ( tmpStr == "dom" ) type |= Address::Dom; |
531 | else if ( (*it)->value() == "parcel" ) type |= Address::Parcel; | 532 | else if ( tmpStr == "intl" ) type |= Address::Intl; |
532 | else if ( (*it)->value() == "postal" ) type |= Address::Postal; | 533 | else if ( tmpStr == "parcel" ) type |= Address::Parcel; |
533 | else if ( (*it)->value() == "work" ) type |= Address::Work; | 534 | else if ( tmpStr == "postal" ) type |= Address::Postal; |
534 | else if ( (*it)->value() == "home" ) type |= Address::Home; | 535 | else if ( tmpStr == "work" ) type |= Address::Work; |
535 | else if ( (*it)->value() == "pref" ) type |= Address::Pref; | 536 | else if ( tmpStr == "home" ) type |= Address::Home; |
537 | else if ( tmpStr == "pref" ) type |= Address::Pref; | ||
536 | } | 538 | } |
537 | } | 539 | } |
538 | return type; | 540 | return type; |
539 | } | 541 | } |
540 | 542 | ||
541 | void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) | 543 | void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) |
542 | { | 544 | { |
543 | ContentLine cl; | 545 | ContentLine cl; |
544 | cl.setName(EntityTypeToParamName( EntityN ) ); | 546 | cl.setName(EntityTypeToParamName( EntityN ) ); |
545 | NValue *v = new NValue; | 547 | NValue *v = new NValue; |
546 | v->setFamily( a.familyName().utf8() ); | 548 | v->setFamily( a.familyName().utf8() ); |
547 | v->setGiven( a.givenName().utf8() ); | 549 | v->setGiven( a.givenName().utf8() ); |
548 | v->setMiddle( a.additionalName().utf8() ); | 550 | v->setMiddle( a.additionalName().utf8() ); |
549 | v->setPrefix( a.prefix().utf8() ); | 551 | v->setPrefix( a.prefix().utf8() ); |
550 | v->setSuffix( a.suffix().utf8() ); | 552 | v->setSuffix( a.suffix().utf8() ); |
551 | 553 | ||
552 | cl.setValue( v ); | 554 | cl.setValue( v ); |
553 | vcard->add(cl); | 555 | vcard->add(cl); |
554 | } | 556 | } |
555 | 557 | ||
556 | void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) | 558 | void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) |
557 | { | 559 | { |
558 | NValue *v = (NValue *)cl->value(); | 560 | NValue *v = (NValue *)cl->value(); |
559 | a.setFamilyName( QString::fromUtf8( v->family() ) ); | 561 | a.setFamilyName( QString::fromUtf8( v->family() ) ); |
560 | a.setGivenName( QString::fromUtf8( v->given() ) ); | 562 | a.setGivenName( QString::fromUtf8( v->given() ) ); |
561 | a.setAdditionalName( QString::fromUtf8( v->middle() ) ); | 563 | a.setAdditionalName( QString::fromUtf8( v->middle() ) ); |
562 | a.setPrefix( QString::fromUtf8( v->prefix() ) ); | 564 | a.setPrefix( QString::fromUtf8( v->prefix() ) ); |
563 | a.setSuffix( QString::fromUtf8( v->suffix() ) ); | 565 | a.setSuffix( QString::fromUtf8( v->suffix() ) ); |
564 | } | 566 | } |
565 | 567 | ||
566 | void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) | 568 | void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) |
567 | { | 569 | { |
568 | if ( p.number().isEmpty() ) | 570 | if ( p.number().isEmpty() ) |
569 | return; | 571 | return; |
570 | 572 | ||
571 | ContentLine cl; | 573 | ContentLine cl; |
572 | cl.setName(EntityTypeToParamName(EntityTelephone)); | 574 | cl.setName(EntityTypeToParamName(EntityTelephone)); |
573 | cl.setValue(new TelValue( p.number().utf8() )); | 575 | cl.setValue(new TelValue( p.number().utf8() )); |
574 | 576 | ||
575 | ParamList params; | 577 | ParamList params; |
576 | if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); | 578 | if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); |
577 | if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); | 579 | if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); |
578 | if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); | 580 | if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); |
579 | if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); | 581 | if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); |
580 | if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); | 582 | if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); |
581 | if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); | 583 | if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); |
582 | if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); | 584 | if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); |
583 | if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); | 585 | if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); |
584 | if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); | 586 | if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); |
585 | if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); | 587 | if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); |
586 | if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); | 588 | if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); |
587 | if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); | 589 | if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); |
588 | if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); | 590 | if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); |
589 | if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); | 591 | if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); |
590 | cl.setParamList( params ); | 592 | cl.setParamList( params ); |
591 | 593 | ||
592 | v->add(cl); | 594 | v->add(cl); |
593 | } | 595 | } |
594 | 596 | ||
595 | PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) | 597 | PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) |
596 | { | 598 | { |
597 | PhoneNumber p; | 599 | PhoneNumber p; |
598 | TelValue *value = (TelValue *)cl->value(); | 600 | TelValue *value = (TelValue *)cl->value(); |
599 | p.setNumber( QString::fromUtf8( value->asString() ) ); | 601 | p.setNumber( QString::fromUtf8( value->asString() ) ); |
600 | 602 | ||
601 | int type = 0; | 603 | int type = 0; |
602 | ParamList params = cl->paramList(); | 604 | ParamList params = cl->paramList(); |
603 | ParamListIterator it( params ); | 605 | ParamListIterator it( params ); |
606 | QCString tmpStr; | ||
604 | for( ; it.current(); ++it ) { | 607 | for( ; it.current(); ++it ) { |
605 | if ( (*it)->name() == "TYPE" ) { | 608 | if ( (*it)->name() == "TYPE" ) { |
606 | if ( (*it)->value() == "home" ) type |= PhoneNumber::Home; | 609 | tmpStr = (*it)->value().lower(); |
607 | else if ( (*it)->value() == "work" ) type |= PhoneNumber::Work; | 610 | if ( tmpStr == "home" ) type |= PhoneNumber::Home; |
608 | else if ( (*it)->value() == "msg" ) type |= PhoneNumber::Msg; | 611 | else if ( tmpStr == "work" ) type |= PhoneNumber::Work; |
609 | else if ( (*it)->value() == "pref" ) type |= PhoneNumber::Pref; | 612 | else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; |
610 | else if ( (*it)->value() == "voice" ) type |= PhoneNumber::Voice; | 613 | else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; |
611 | else if ( (*it)->value() == "fax" ) type |= PhoneNumber::Fax; | 614 | else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; |
612 | else if ( (*it)->value() == "cell" ) type |= PhoneNumber::Cell; | 615 | else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; |
613 | else if ( (*it)->value() == "video" ) type |= PhoneNumber::Video; | 616 | else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; |
614 | else if ( (*it)->value() == "bbs" ) type |= PhoneNumber::Bbs; | 617 | else if ( tmpStr == "video" ) type |= PhoneNumber::Video; |
615 | else if ( (*it)->value() == "modem" ) type |= PhoneNumber::Modem; | 618 | else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; |
616 | else if ( (*it)->value() == "car" ) type |= PhoneNumber::Car; | 619 | else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; |
617 | else if ( (*it)->value() == "isdn" ) type |= PhoneNumber::Isdn; | 620 | else if ( tmpStr == "car" ) type |= PhoneNumber::Car; |
618 | else if ( (*it)->value() == "pcs" ) type |= PhoneNumber::Pcs; | 621 | else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; |
619 | else if ( (*it)->value() == "pager" ) type |= PhoneNumber::Pager; | 622 | else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; |
623 | else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; | ||
620 | } | 624 | } |
621 | } | 625 | } |
622 | p.setType( type ); | 626 | p.setType( type ); |
623 | 627 | ||
624 | return p; | 628 | return p; |
625 | } | 629 | } |
626 | 630 | ||
627 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) | 631 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) |
628 | { | 632 | { |
629 | VCARD::Value *value = cl->value(); | 633 | VCARD::Value *value = cl->value(); |
630 | if ( value ) { | 634 | if ( value ) { |
631 | return QString::fromUtf8( value->asString() ); | 635 | return QString::fromUtf8( value->asString() ); |
632 | } else { | 636 | } else { |
633 | kdDebug(5700) << "No value: " << cl->asString() << endl; | 637 | kdDebug(5700) << "No value: " << cl->asString() << endl; |
634 | return QString::null; | 638 | return QString::null; |
635 | } | 639 | } |
636 | } | 640 | } |
637 | 641 | ||
638 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) | 642 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) |
639 | { | 643 | { |
640 | DateValue *dateValue = (DateValue *)cl->value(); | 644 | DateValue *dateValue = (DateValue *)cl->value(); |
641 | if ( dateValue ) | 645 | if ( dateValue ) |
642 | return dateValue->qdate(); | 646 | return dateValue->qdate(); |
643 | else | 647 | else |
644 | return QDate(); | 648 | return QDate(); |
645 | } | 649 | } |
646 | 650 | ||
647 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) | 651 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) |
648 | { | 652 | { |
649 | DateValue *dateValue = (DateValue *)cl->value(); | 653 | DateValue *dateValue = (DateValue *)cl->value(); |
650 | if ( dateValue ) | 654 | if ( dateValue ) |
651 | return dateValue->qdt(); | 655 | return dateValue->qdt(); |
652 | else | 656 | else |
653 | return QDateTime(); | 657 | return QDateTime(); |
654 | } | 658 | } |
655 | 659 | ||
656 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) | 660 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) |
657 | { | 661 | { |
658 | GeoValue *geoValue = (GeoValue *)cl->value(); | 662 | GeoValue *geoValue = (GeoValue *)cl->value(); |
659 | if ( geoValue ) { | 663 | if ( geoValue ) { |
660 | Geo geo( geoValue->latitude(), geoValue->longitude() ); | 664 | Geo geo( geoValue->latitude(), geoValue->longitude() ); |
661 | return geo; | 665 | return geo; |
662 | } else | 666 | } else |
663 | return Geo(); | 667 | return Geo(); |
664 | } | 668 | } |
665 | 669 | ||
666 | TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) | 670 | TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) |
667 | { | 671 | { |
668 | UTCValue *utcValue = (UTCValue *)cl->value(); | 672 | UTCValue *utcValue = (UTCValue *)cl->value(); |
669 | if ( utcValue ) { | 673 | if ( utcValue ) { |
670 | TimeZone tz; | 674 | TimeZone tz; |
671 | tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); | 675 | tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); |
672 | return tz; | 676 | return tz; |
673 | } else | 677 | } else |
674 | return TimeZone(); | 678 | return TimeZone(); |
675 | } | 679 | } |
676 | 680 | ||
677 | Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) | 681 | Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) |
678 | { | 682 | { |
679 | ClassValue *classValue = (ClassValue *)cl->value(); | 683 | ClassValue *classValue = (ClassValue *)cl->value(); |
680 | if ( classValue ) { | 684 | if ( classValue ) { |
681 | Secrecy secrecy; | 685 | Secrecy secrecy; |
682 | switch ( classValue->type() ) { | 686 | switch ( classValue->type() ) { |
683 | case ClassValue::Public: | 687 | case ClassValue::Public: |
684 | secrecy.setType( Secrecy::Public ); | 688 | secrecy.setType( Secrecy::Public ); |
685 | break; | 689 | break; |
686 | case ClassValue::Private: | 690 | case ClassValue::Private: |
687 | secrecy.setType( Secrecy::Private ); | 691 | secrecy.setType( Secrecy::Private ); |
688 | break; | 692 | break; |
689 | case ClassValue::Confidential: | 693 | case ClassValue::Confidential: |
690 | secrecy.setType( Secrecy::Confidential ); | 694 | secrecy.setType( Secrecy::Confidential ); |
691 | break; | 695 | break; |
692 | } | 696 | } |
693 | 697 | ||
694 | return secrecy; | 698 | return secrecy; |
695 | } else | 699 | } else |
696 | return Secrecy(); | 700 | return Secrecy(); |
697 | } | 701 | } |
698 | 702 | ||
699 | void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) | 703 | void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) |
700 | { | 704 | { |
701 | ContentLine cl; | 705 | ContentLine cl; |
702 | cl.setName( EntityTypeToParamName( EntityKey ) ); | 706 | cl.setName( EntityTypeToParamName( EntityKey ) ); |
703 | 707 | ||
704 | ParamList params; | 708 | ParamList params; |
705 | if ( key.isBinary() ) { | 709 | if ( key.isBinary() ) { |
706 | cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); | 710 | cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); |
707 | params.append( new Param( "ENCODING", "b" ) ); | 711 | params.append( new Param( "ENCODING", "b" ) ); |
708 | } else { | 712 | } else { |
709 | cl.setValue( new TextValue( key.textData().utf8() ) ); | 713 | cl.setValue( new TextValue( key.textData().utf8() ) ); |
710 | } | 714 | } |
711 | 715 | ||
712 | switch ( key.type() ) { | 716 | switch ( key.type() ) { |
713 | case Key::X509: | 717 | case Key::X509: |
714 | params.append( new Param( "TYPE", "X509" ) ); | 718 | params.append( new Param( "TYPE", "X509" ) ); |
715 | break; | 719 | break; |
716 | case Key::PGP: | 720 | case Key::PGP: |
717 | params.append( new Param( "TYPE", "PGP" ) ); | 721 | params.append( new Param( "TYPE", "PGP" ) ); |
718 | break; | 722 | break; |
719 | case Key::Custom: | 723 | case Key::Custom: |
720 | params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); | 724 | params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); |
721 | break; | 725 | break; |
722 | } | 726 | } |
723 | 727 | ||
724 | cl.setParamList( params ); | 728 | cl.setParamList( params ); |
725 | vcard->add( cl ); | 729 | vcard->add( cl ); |
726 | } | 730 | } |
727 | 731 | ||
728 | Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) | 732 | Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) |
729 | { | 733 | { |
730 | Key key; | 734 | Key key; |
731 | bool isBinary = false; | 735 | bool isBinary = false; |
732 | TextValue *v = (TextValue *)cl->value(); | 736 | TextValue *v = (TextValue *)cl->value(); |
733 | 737 | ||
734 | ParamList params = cl->paramList(); | 738 | ParamList params = cl->paramList(); |
735 | ParamListIterator it( params ); | 739 | ParamListIterator it( params ); |
736 | for( ; it.current(); ++it ) { | 740 | for( ; it.current(); ++it ) { |
737 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 741 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
738 | isBinary = true; | 742 | isBinary = true; |
739 | if ( (*it)->name() == "TYPE" ) { | 743 | if ( (*it)->name() == "TYPE" ) { |
740 | if ( (*it)->value().isEmpty() ) | 744 | if ( (*it)->value().isEmpty() ) |
741 | continue; | 745 | continue; |
742 | if ( (*it)->value() == "X509" ) | 746 | if ( (*it)->value() == "X509" ) |
743 | key.setType( Key::X509 ); | 747 | key.setType( Key::X509 ); |
744 | else if ( (*it)->value() == "PGP" ) | 748 | else if ( (*it)->value() == "PGP" ) |
745 | key.setType( Key::PGP ); | 749 | key.setType( Key::PGP ); |
746 | else { | 750 | else { |
747 | key.setType( Key::Custom ); | 751 | key.setType( Key::Custom ); |
748 | key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); | 752 | key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); |
749 | } | 753 | } |
750 | } | 754 | } |
751 | } | 755 | } |
752 | 756 | ||
753 | 757 | ||
754 | if ( isBinary ) { | 758 | if ( isBinary ) { |
755 | QByteArray data; | 759 | QByteArray data; |
756 | KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); | 760 | KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); |
757 | key.setBinaryData( data ); | 761 | key.setBinaryData( data ); |
758 | } else { | 762 | } else { |
759 | key.setTextData( QString::fromUtf8( v->asString() ) ); | 763 | key.setTextData( QString::fromUtf8( v->asString() ) ); |
760 | } | 764 | } |
761 | 765 | ||
762 | return key; | 766 | return key; |
763 | } | 767 | } |
764 | 768 | ||
765 | 769 | ||
766 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) | 770 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) |
767 | { | 771 | { |
768 | if ( agent.isIntern() && !agent.addressee() ) | 772 | if ( agent.isIntern() && !agent.addressee() ) |
769 | return; | 773 | return; |
770 | 774 | ||
771 | if ( !agent.isIntern() && agent.url().isEmpty() ) | 775 | if ( !agent.isIntern() && agent.url().isEmpty() ) |
772 | return; | 776 | return; |
773 | 777 | ||
774 | ContentLine cl; | 778 | ContentLine cl; |
775 | cl.setName( EntityTypeToParamName( EntityAgent ) ); | 779 | cl.setName( EntityTypeToParamName( EntityAgent ) ); |
776 | 780 | ||
777 | ParamList params; | 781 | ParamList params; |
778 | if ( agent.isIntern() ) { | 782 | if ( agent.isIntern() ) { |
779 | QString vstr; | 783 | QString vstr; |
780 | Addressee *addr = agent.addressee(); | 784 | Addressee *addr = agent.addressee(); |
781 | if ( addr ) { | 785 | if ( addr ) { |
782 | writeToString( (*addr), vstr ); | 786 | writeToString( (*addr), vstr ); |
783 | 787 | ||
784 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 788 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
785 | /*US | 789 | /*US |
786 | vstr.replace( ":", "\\:" ); | 790 | vstr.replace( ":", "\\:" ); |
787 | vstr.replace( ",", "\\," ); | 791 | vstr.replace( ",", "\\," ); |
788 | vstr.replace( ";", "\\;" ); | 792 | vstr.replace( ";", "\\;" ); |
789 | vstr.replace( "\r\n", "\\n" ); | 793 | vstr.replace( "\r\n", "\\n" ); |
790 | */ | 794 | */ |
791 | vstr.replace( QRegExp(":"), "\\:" ); | 795 | vstr.replace( QRegExp(":"), "\\:" ); |
792 | vstr.replace( QRegExp(","), "\\," ); | 796 | vstr.replace( QRegExp(","), "\\," ); |
793 | vstr.replace( QRegExp(";"), "\\;" ); | 797 | vstr.replace( QRegExp(";"), "\\;" ); |
794 | vstr.replace( QRegExp("\r\n"), "\\n" ); | 798 | vstr.replace( QRegExp("\r\n"), "\\n" ); |
795 | 799 | ||
796 | cl.setValue( new TextValue( vstr.utf8() ) ); | 800 | cl.setValue( new TextValue( vstr.utf8() ) ); |
797 | } else | 801 | } else |
798 | return; | 802 | return; |
799 | } else { | 803 | } else { |
800 | cl.setValue( new TextValue( agent.url().utf8() ) ); | 804 | cl.setValue( new TextValue( agent.url().utf8() ) ); |
801 | params.append( new Param( "VALUE", "uri" ) ); | 805 | params.append( new Param( "VALUE", "uri" ) ); |
802 | } | 806 | } |
803 | 807 | ||
804 | cl.setParamList( params ); | 808 | cl.setParamList( params ); |
805 | vcard->add( cl ); | 809 | vcard->add( cl ); |
806 | } | 810 | } |
807 | 811 | ||
808 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) | 812 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) |
809 | { | 813 | { |
810 | Agent agent; | 814 | Agent agent; |
811 | bool isIntern = true; | 815 | bool isIntern = true; |
812 | TextValue *v = (TextValue *)cl->value(); | 816 | TextValue *v = (TextValue *)cl->value(); |
813 | 817 | ||
814 | ParamList params = cl->paramList(); | 818 | ParamList params = cl->paramList(); |
815 | ParamListIterator it( params ); | 819 | ParamListIterator it( params ); |
816 | for( ; it.current(); ++it ) { | 820 | for( ; it.current(); ++it ) { |
817 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) | 821 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) |
818 | isIntern = false; | 822 | isIntern = false; |
819 | } | 823 | } |
820 | 824 | ||
821 | if ( isIntern ) { | 825 | if ( isIntern ) { |
822 | QString vstr = QString::fromUtf8( v->asString() ); | 826 | QString vstr = QString::fromUtf8( v->asString() ); |
823 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 827 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
824 | /*US | 828 | /*US |
825 | vstr.replace( "\\n", "\r\n" ); | 829 | vstr.replace( "\\n", "\r\n" ); |
826 | vstr.replace( "\\:", ":" ); | 830 | vstr.replace( "\\:", ":" ); |
827 | vstr.replace( "\\,", "," ); | 831 | vstr.replace( "\\,", "," ); |
828 | vstr.replace( "\\;", ";" ); | 832 | vstr.replace( "\\;", ";" ); |
829 | */ | 833 | */ |
830 | vstr.replace( QRegExp("\\n"), "\r\n" ); | 834 | vstr.replace( QRegExp("\\n"), "\r\n" ); |
831 | vstr.replace( QRegExp("\\:"), ":" ); | 835 | vstr.replace( QRegExp("\\:"), ":" ); |
832 | vstr.replace( QRegExp("\\,"), "," ); | 836 | vstr.replace( QRegExp("\\,"), "," ); |
833 | vstr.replace( QRegExp("\\;"), ";" ); | 837 | vstr.replace( QRegExp("\\;"), ";" ); |
834 | 838 | ||
835 | Addressee *addr = new Addressee; | 839 | Addressee *addr = new Addressee; |
836 | readFromString( vstr, *addr ); | 840 | readFromString( vstr, *addr ); |
837 | agent.setAddressee( addr ); | 841 | agent.setAddressee( addr ); |
838 | } else { | 842 | } else { |
839 | agent.setUrl( QString::fromUtf8( v->asString() ) ); | 843 | agent.setUrl( QString::fromUtf8( v->asString() ) ); |
840 | } | 844 | } |
841 | 845 | ||
842 | return agent; | 846 | return agent; |
843 | } | 847 | } |
844 | 848 | ||
845 | void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) | 849 | void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) |
846 | { | 850 | { |
847 | ContentLine cl; | 851 | ContentLine cl; |
848 | cl.setName( EntityTypeToParamName( type ) ); | 852 | cl.setName( EntityTypeToParamName( type ) ); |
849 | 853 | ||
850 | if ( pic.isIntern() && pic.data().isNull() ) | 854 | if ( pic.isIntern() && pic.data().isNull() ) |
851 | return; | 855 | return; |
852 | 856 | ||
853 | if ( !pic.isIntern() && pic.url().isEmpty() ) | 857 | if ( !pic.isIntern() && pic.url().isEmpty() ) |
854 | return; | 858 | return; |
855 | 859 | ||
856 | ParamList params; | 860 | ParamList params; |
857 | if ( pic.isIntern() ) { | 861 | if ( pic.isIntern() ) { |
858 | QImage img = pic.data(); | 862 | QImage img = pic.data(); |
859 | if ( intern ) { // only for vCard export we really write the data inline | 863 | if ( intern ) { // only for vCard export we really write the data inline |
860 | QByteArray data; | 864 | QByteArray data; |
861 | QDataStream s( data, IO_WriteOnly ); | 865 | QDataStream s( data, IO_WriteOnly ); |
862 | s.setVersion( 4 ); // to produce valid png files | 866 | s.setVersion( 4 ); // to produce valid png files |
863 | s << img; | 867 | s << img; |
864 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); | 868 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); |
865 | 869 | ||
866 | } else { // save picture in cache | 870 | } else { // save picture in cache |
867 | QString dir; | 871 | QString dir; |
868 | if ( type == EntityPhoto ) | 872 | if ( type == EntityPhoto ) |
869 | dir = "photos"; | 873 | dir = "photos"; |
870 | if ( type == EntityLogo ) | 874 | if ( type == EntityLogo ) |
871 | dir = "logos"; | 875 | dir = "logos"; |
872 | 876 | ||
873 | img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); | 877 | img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); |
874 | cl.setValue( new TextValue( "<dummy>" ) ); | 878 | cl.setValue( new TextValue( "<dummy>" ) ); |
875 | } | 879 | } |
876 | params.append( new Param( "ENCODING", "b" ) ); | 880 | params.append( new Param( "ENCODING", "b" ) ); |
877 | if ( !pic.type().isEmpty() ) | 881 | if ( !pic.type().isEmpty() ) |
878 | params.append( new Param( "TYPE", pic.type().utf8() ) ); | 882 | params.append( new Param( "TYPE", pic.type().utf8() ) ); |
879 | } else { | 883 | } else { |
880 | 884 | ||
881 | cl.setValue( new TextValue( pic.url().utf8() ) ); | 885 | cl.setValue( new TextValue( pic.url().utf8() ) ); |
882 | params.append( new Param( "VALUE", "uri" ) ); | 886 | params.append( new Param( "VALUE", "uri" ) ); |
883 | } | 887 | } |
884 | 888 | ||
885 | cl.setParamList( params ); | 889 | cl.setParamList( params ); |
886 | vcard->add( cl ); | 890 | vcard->add( cl ); |
887 | } | 891 | } |
888 | 892 | ||
889 | Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) | 893 | Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) |
890 | { | 894 | { |
891 | Picture pic; | 895 | Picture pic; |
892 | bool isInline = false; | 896 | bool isInline = false; |
893 | QString picType; | 897 | QString picType; |
894 | TextValue *v = (TextValue *)cl->value(); | 898 | TextValue *v = (TextValue *)cl->value(); |
895 | 899 | ||
896 | ParamList params = cl->paramList(); | 900 | ParamList params = cl->paramList(); |
897 | ParamListIterator it( params ); | 901 | ParamListIterator it( params ); |
898 | for( ; it.current(); ++it ) { | 902 | for( ; it.current(); ++it ) { |
899 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 903 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
900 | isInline = true; | 904 | isInline = true; |
901 | if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) | 905 | if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) |
902 | picType = QString::fromUtf8( (*it)->value() ); | 906 | picType = QString::fromUtf8( (*it)->value() ); |
903 | } | 907 | } |
904 | 908 | ||
905 | if ( isInline ) { | 909 | if ( isInline ) { |
906 | QImage img; | 910 | QImage img; |
907 | if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache | 911 | if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache |
908 | QString dir; | 912 | QString dir; |
909 | if ( type == EntityPhoto ) | 913 | if ( type == EntityPhoto ) |
910 | dir = "photos"; | 914 | dir = "photos"; |
911 | if ( type == EntityLogo ) | 915 | if ( type == EntityLogo ) |
912 | dir = "logos"; | 916 | dir = "logos"; |
913 | 917 | ||
914 | img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) ); | 918 | img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) ); |
915 | } else { | 919 | } else { |
916 | QByteArray data; | 920 | QByteArray data; |
917 | KCodecs::base64Decode( v->asString(), data ); | 921 | KCodecs::base64Decode( v->asString(), data ); |
918 | img.loadFromData( data ); | 922 | img.loadFromData( data ); |
919 | } | 923 | } |
920 | pic.setData( img ); | 924 | pic.setData( img ); |
921 | pic.setType( picType ); | 925 | pic.setType( picType ); |
922 | } else { | 926 | } else { |
923 | pic.setUrl( QString::fromUtf8( v->asString() ) ); | 927 | pic.setUrl( QString::fromUtf8( v->asString() ) ); |
924 | } | 928 | } |
925 | 929 | ||
926 | return pic; | 930 | return pic; |
927 | } | 931 | } |
928 | 932 | ||
929 | void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) | 933 | void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) |
930 | { | 934 | { |
931 | ContentLine cl; | 935 | ContentLine cl; |
932 | cl.setName( EntityTypeToParamName( EntitySound ) ); | 936 | cl.setName( EntityTypeToParamName( EntitySound ) ); |
933 | 937 | ||
934 | if ( sound.isIntern() && sound.data().isNull() ) | 938 | if ( sound.isIntern() && sound.data().isNull() ) |
935 | return; | 939 | return; |
936 | 940 | ||
937 | if ( !sound.isIntern() && sound.url().isEmpty() ) | 941 | if ( !sound.isIntern() && sound.url().isEmpty() ) |
938 | return; | 942 | return; |
939 | 943 | ||
940 | ParamList params; | 944 | ParamList params; |
941 | if ( sound.isIntern() ) { | 945 | if ( sound.isIntern() ) { |
942 | QByteArray data = sound.data(); | 946 | QByteArray data = sound.data(); |
943 | if ( intern ) { // only for vCard export we really write the data inline | 947 | if ( intern ) { // only for vCard export we really write the data inline |
944 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); | 948 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); |
945 | } else { // save sound in cache | 949 | } else { // save sound in cache |
946 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); | 950 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); |
947 | if ( file.open( IO_WriteOnly ) ) { | 951 | if ( file.open( IO_WriteOnly ) ) { |
948 | file.writeBlock( data ); | 952 | file.writeBlock( data ); |
949 | } | 953 | } |
950 | cl.setValue( new TextValue( "<dummy>" ) ); | 954 | cl.setValue( new TextValue( "<dummy>" ) ); |
951 | } | 955 | } |
952 | params.append( new Param( "ENCODING", "b" ) ); | 956 | params.append( new Param( "ENCODING", "b" ) ); |
953 | } else { | 957 | } else { |
954 | cl.setValue( new TextValue( sound.url().utf8() ) ); | 958 | cl.setValue( new TextValue( sound.url().utf8() ) ); |
955 | params.append( new Param( "VALUE", "uri" ) ); | 959 | params.append( new Param( "VALUE", "uri" ) ); |
956 | } | 960 | } |
957 | 961 | ||
958 | cl.setParamList( params ); | 962 | cl.setParamList( params ); |
959 | vcard->add( cl ); | 963 | vcard->add( cl ); |
960 | } | 964 | } |
961 | 965 | ||
962 | Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) | 966 | Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) |
963 | { | 967 | { |
964 | Sound sound; | 968 | Sound sound; |
965 | bool isInline = false; | 969 | bool isInline = false; |
966 | TextValue *v = (TextValue *)cl->value(); | 970 | TextValue *v = (TextValue *)cl->value(); |
967 | 971 | ||
968 | ParamList params = cl->paramList(); | 972 | ParamList params = cl->paramList(); |
969 | ParamListIterator it( params ); | 973 | ParamListIterator it( params ); |
970 | for( ; it.current(); ++it ) { | 974 | for( ; it.current(); ++it ) { |
971 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 975 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
972 | isInline = true; | 976 | isInline = true; |
973 | } | 977 | } |
974 | 978 | ||
975 | if ( isInline ) { | 979 | if ( isInline ) { |
976 | QByteArray data; | 980 | QByteArray data; |
977 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache | 981 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache |
978 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); | 982 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); |
979 | if ( file.open( IO_ReadOnly ) ) { | 983 | if ( file.open( IO_ReadOnly ) ) { |
980 | data = file.readAll(); | 984 | data = file.readAll(); |
981 | file.close(); | 985 | file.close(); |
982 | } | 986 | } |
983 | } else { | 987 | } else { |
984 | KCodecs::base64Decode( v->asString(), data ); | 988 | KCodecs::base64Decode( v->asString(), data ); |
985 | } | 989 | } |
986 | sound.setData( data ); | 990 | sound.setData( data ); |
987 | } else { | 991 | } else { |
988 | sound.setUrl( QString::fromUtf8( v->asString() ) ); | 992 | sound.setUrl( QString::fromUtf8( v->asString() ) ); |
989 | } | 993 | } |
990 | 994 | ||
991 | return sound; | 995 | return sound; |
992 | } | 996 | } |
993 | 997 | ||
994 | bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) | 998 | bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) |
995 | { | 999 | { |
996 | VCardEntity e( vcard.utf8() ); | 1000 | VCardEntity e( vcard.utf8() ); |
997 | VCardListIterator it( e.cardList() ); | 1001 | VCardListIterator it( e.cardList() ); |
998 | 1002 | ||
999 | if ( it.current() ) { | 1003 | if ( it.current() ) { |
1000 | VCard v(*it.current()); | 1004 | VCard v(*it.current()); |
1001 | loadAddressee( addressee, v ); | 1005 | loadAddressee( addressee, v ); |
1002 | return true; | 1006 | return true; |
1003 | } | 1007 | } |
diff --git a/kabc/vcardformatplugin.cpp b/kabc/vcardformatplugin.cpp index 3cba59a..bc18690 100644 --- a/kabc/vcardformatplugin.cpp +++ b/kabc/vcardformatplugin.cpp | |||
@@ -1,66 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "vcardformatplugin.h" | 21 | #include "vcardformatplugin.h" |
22 | #include "vcardformatimpl.h" | 22 | #include "vcardformatimpl.h" |
23 | 23 | ||
24 | using namespace KABC; | 24 | using namespace KABC; |
25 | 25 | ||
26 | VCardFormatPlugin::VCardFormatPlugin() | 26 | VCardFormatPlugin::VCardFormatPlugin() |
27 | { | 27 | { |
28 | mImpl = new VCardFormatImpl; | 28 | mImpl = new VCardFormatImpl; |
29 | } | 29 | } |
30 | 30 | ||
31 | VCardFormatPlugin::~VCardFormatPlugin() | 31 | VCardFormatPlugin::~VCardFormatPlugin() |
32 | { | 32 | { |
33 | delete mImpl; | 33 | delete mImpl; |
34 | } | 34 | } |
35 | 35 | ||
36 | bool VCardFormatPlugin::load( Addressee &addressee, QFile *file ) | 36 | bool VCardFormatPlugin::load( Addressee &addressee, QFile *file ) |
37 | { | 37 | { |
38 | qDebug("VCardFormatPlugin::load"); | ||
38 | return mImpl->load( addressee, file ); | 39 | return mImpl->load( addressee, file ); |
39 | } | 40 | } |
40 | 41 | ||
41 | bool VCardFormatPlugin::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) | 42 | bool VCardFormatPlugin::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) |
42 | { | 43 | { |
44 | qDebug("VCardFormatPlugin::loadAll"); | ||
43 | return mImpl->loadAll( addressBook, resource, file ); | 45 | return mImpl->loadAll( addressBook, resource, file ); |
44 | } | 46 | } |
45 | 47 | ||
46 | void VCardFormatPlugin::save( const Addressee &addressee, QFile *file ) | 48 | void VCardFormatPlugin::save( const Addressee &addressee, QFile *file ) |
47 | { | 49 | { |
50 | qDebug("VCardFormatPlugin::save"); | ||
48 | mImpl->save( addressee, file ); | 51 | mImpl->save( addressee, file ); |
49 | } | 52 | } |
50 | 53 | ||
51 | void VCardFormatPlugin::saveAll( AddressBook *addressBook, Resource *resource, QFile *file ) | 54 | void VCardFormatPlugin::saveAll( AddressBook *addressBook, Resource *resource, QFile *file ) |
52 | { | 55 | { |
56 | qDebug("VCardFormatPlugin::saveAll"); | ||
53 | mImpl->saveAll( addressBook, resource, file ); | 57 | mImpl->saveAll( addressBook, resource, file ); |
54 | } | 58 | } |
55 | 59 | ||
56 | bool VCardFormatPlugin::checkFormat( QFile *file ) const | 60 | bool VCardFormatPlugin::checkFormat( QFile *file ) const |
57 | { | 61 | { |
58 | QString line; | 62 | QString line; |
59 | 63 | ||
60 | file->readLine( line, 1024 ); | 64 | file->readLine( line, 1024 ); |
61 | line = line.stripWhiteSpace(); | 65 | line = line.stripWhiteSpace(); |
62 | if ( line == "BEGIN:VCARD" ) | 66 | if ( line == "BEGIN:VCARD" ) |
63 | return true; | 67 | return true; |
64 | else | 68 | else |
65 | return false; | 69 | return false; |
66 | } | 70 | } |
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp index 01c5b3e..71f29d7 100644 --- a/kabc/vcardparser/vcardtool.cpp +++ b/kabc/vcardparser/vcardtool.cpp | |||
@@ -1,620 +1,634 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qdatastream.h> | 21 | #include <qdatastream.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qregexp.h> | 23 | #include <qregexp.h> |
24 | #include <kmdcodec.h> | 24 | #include <kmdcodec.h> |
25 | 25 | ||
26 | #include "agent.h" | 26 | #include "agent.h" |
27 | #include "key.h" | 27 | #include "key.h" |
28 | #include "picture.h" | 28 | #include "picture.h" |
29 | #include "secrecy.h" | 29 | #include "secrecy.h" |
30 | #include "sound.h" | 30 | #include "sound.h" |
31 | 31 | ||
32 | #include "vcardtool.h" | 32 | #include "vcardtool.h" |
33 | 33 | ||
34 | using namespace KABC; | 34 | using namespace KABC; |
35 | 35 | ||
36 | VCardTool::VCardTool() | 36 | VCardTool::VCardTool() |
37 | { | 37 | { |
38 | mAddressTypeMap.insert( "dom", Address::Dom ); | 38 | mAddressTypeMap.insert( "dom", Address::Dom ); |
39 | mAddressTypeMap.insert( "intl", Address::Intl ); | 39 | mAddressTypeMap.insert( "intl", Address::Intl ); |
40 | mAddressTypeMap.insert( "postal", Address::Postal ); | 40 | mAddressTypeMap.insert( "postal", Address::Postal ); |
41 | mAddressTypeMap.insert( "parcel", Address::Parcel ); | 41 | mAddressTypeMap.insert( "parcel", Address::Parcel ); |
42 | mAddressTypeMap.insert( "home", Address::Home ); | 42 | mAddressTypeMap.insert( "home", Address::Home ); |
43 | mAddressTypeMap.insert( "work", Address::Work ); | 43 | mAddressTypeMap.insert( "work", Address::Work ); |
44 | mAddressTypeMap.insert( "pref", Address::Pref ); | 44 | mAddressTypeMap.insert( "pref", Address::Pref ); |
45 | 45 | ||
46 | mPhoneTypeMap.insert( "HOME", PhoneNumber::Home ); | 46 | mPhoneTypeMap.insert( "HOME", PhoneNumber::Home ); |
47 | mPhoneTypeMap.insert( "WORK", PhoneNumber::Work ); | 47 | mPhoneTypeMap.insert( "WORK", PhoneNumber::Work ); |
48 | mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg ); | 48 | mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg ); |
49 | mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref ); | 49 | mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref ); |
50 | mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice ); | 50 | mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice ); |
51 | mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax ); | 51 | mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax ); |
52 | mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell ); | 52 | mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell ); |
53 | mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video ); | 53 | mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video ); |
54 | mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs ); | 54 | mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs ); |
55 | mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem ); | 55 | mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem ); |
56 | mPhoneTypeMap.insert( "CAR", PhoneNumber::Car ); | 56 | mPhoneTypeMap.insert( "CAR", PhoneNumber::Car ); |
57 | mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn ); | 57 | mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn ); |
58 | mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs ); | 58 | mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs ); |
59 | mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); | 59 | mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); |
60 | } | 60 | } |
61 | 61 | ||
62 | VCardTool::~VCardTool() | 62 | VCardTool::~VCardTool() |
63 | { | 63 | { |
64 | } | 64 | } |
65 | 65 | ||
66 | QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) | 66 | QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) |
67 | { | 67 | { |
68 | VCard::List vCardList; | 68 | VCard::List vCardList; |
69 | 69 | ||
70 | Addressee::List::Iterator addrIt; | 70 | Addressee::List::Iterator addrIt; |
71 | for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) { | 71 | for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) { |
72 | VCard card; | 72 | VCard card; |
73 | QStringList::ConstIterator strIt; | 73 | QStringList::ConstIterator strIt; |
74 | 74 | ||
75 | // ADR + LABEL | 75 | // ADR + LABEL |
76 | Address::List addresses = (*addrIt).addresses(); | 76 | Address::List addresses = (*addrIt).addresses(); |
77 | for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { | 77 | for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { |
78 | QStringList address; | 78 | QStringList address; |
79 | 79 | ||
80 | /*US | 80 | /*US |
81 | address.append( (*it).postOfficeBox().replace( ';', "\\;" ) ); | 81 | address.append( (*it).postOfficeBox().replace( ';', "\\;" ) ); |
82 | address.append( (*it).extended().replace( ';', "\\;" ) ); | 82 | address.append( (*it).extended().replace( ';', "\\;" ) ); |
83 | address.append( (*it).street().replace( ';', "\\;" ) ); | 83 | address.append( (*it).street().replace( ';', "\\;" ) ); |
84 | address.append( (*it).locality().replace( ';', "\\;" ) ); | 84 | address.append( (*it).locality().replace( ';', "\\;" ) ); |
85 | address.append( (*it).region().replace( ';', "\\;" ) ); | 85 | address.append( (*it).region().replace( ';', "\\;" ) ); |
86 | address.append( (*it).postalCode().replace( ';', "\\;" ) ); | 86 | address.append( (*it).postalCode().replace( ';', "\\;" ) ); |
87 | address.append( (*it).country().replace( ';', "\\;" ) ); | 87 | address.append( (*it).country().replace( ';', "\\;" ) ); |
88 | */ | 88 | */ |
89 | //US using the old implementation instead | 89 | //US using the old implementation instead |
90 | //qDebug("VCardTool::createVCards has to be verified"); | 90 | //qDebug("VCardTool::createVCards has to be verified"); |
91 | address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) ); | 91 | address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) ); |
92 | address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) ); | 92 | address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) ); |
93 | address.append( (*it).street().replace( QRegExp(";"), "\\;" ) ); | 93 | address.append( (*it).street().replace( QRegExp(";"), "\\;" ) ); |
94 | address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) ); | 94 | address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) ); |
95 | address.append( (*it).region().replace( QRegExp(";"), "\\;" ) ); | 95 | address.append( (*it).region().replace( QRegExp(";"), "\\;" ) ); |
96 | address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) ); | 96 | address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) ); |
97 | address.append( (*it).country().replace( QRegExp(";"), "\\;" ) ); | 97 | address.append( (*it).country().replace( QRegExp(";"), "\\;" ) ); |
98 | 98 | ||
99 | VCardLine adrLine( "ADR", address.join( ";" ) ); | 99 | VCardLine adrLine( "ADR", address.join( ";" ) ); |
100 | VCardLine labelLine( "LABEL", (*it).label() ); | 100 | VCardLine labelLine( "LABEL", (*it).label() ); |
101 | 101 | ||
102 | bool hasLabel = !(*it).label().isEmpty(); | 102 | bool hasLabel = !(*it).label().isEmpty(); |
103 | QMap<QString, int>::Iterator typeIt; | 103 | QMap<QString, int>::Iterator typeIt; |
104 | for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { | 104 | for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { |
105 | if ( typeIt.data() & (*it).type() ) { | 105 | if ( typeIt.data() & (*it).type() ) { |
106 | adrLine.addParameter( "TYPE", typeIt.key() ); | 106 | if ( version == VCard::v3_0 ) { |
107 | if ( hasLabel ) | 107 | adrLine.addParameter( "TYPE", typeIt.key().lower() ); |
108 | labelLine.addParameter( "TYPE", typeIt.key() ); | 108 | } |
109 | else { | ||
110 | adrLine.addParameter( "TYPE", typeIt.key() ); | ||
111 | } | ||
112 | if ( hasLabel ) { | ||
113 | if ( version == VCard::v3_0 ) { | ||
114 | labelLine.addParameter( "TYPE", typeIt.key().lower() ); | ||
115 | } | ||
116 | else { | ||
117 | labelLine.addParameter( "TYPE", typeIt.key() ); | ||
118 | } | ||
119 | } | ||
109 | } | 120 | } |
110 | } | 121 | } |
111 | 122 | ||
112 | card.addLine( adrLine ); | 123 | card.addLine( adrLine ); |
113 | if ( hasLabel ) | 124 | if ( hasLabel ) |
114 | card.addLine( labelLine ); | 125 | card.addLine( labelLine ); |
115 | } | 126 | } |
116 | 127 | ||
117 | // AGENT | 128 | // AGENT |
118 | card.addLine( createAgent( version, (*addrIt).agent() ) ); | 129 | card.addLine( createAgent( version, (*addrIt).agent() ) ); |
119 | 130 | ||
120 | // BDAY | 131 | // BDAY |
121 | card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) ); | 132 | card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) ); |
122 | 133 | ||
123 | // CATEGORIES | 134 | // CATEGORIES |
124 | if ( version == VCard::v3_0 ) { | 135 | if ( version == VCard::v3_0 ) { |
125 | QStringList categories = (*addrIt).categories(); | 136 | QStringList categories = (*addrIt).categories(); |
126 | QStringList::Iterator catIt; | 137 | QStringList::Iterator catIt; |
127 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) | 138 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) |
128 | { | 139 | { |
129 | //US using the old implementation instead | 140 | //US using the old implementation instead |
130 | // qDebug("VCardTool::createVCards has to be verified"); | 141 | // qDebug("VCardTool::createVCards has to be verified"); |
131 | //US (*catIt).replace( ',', "\\," ); | 142 | //US (*catIt).replace( ',', "\\," ); |
132 | (*catIt).replace( QRegExp(","), "\\," ); | 143 | (*catIt).replace( QRegExp(","), "\\," ); |
133 | } | 144 | } |
134 | card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) ); | 145 | card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) ); |
135 | } | 146 | } |
136 | 147 | ||
137 | // CLASS | 148 | // CLASS |
138 | if ( version == VCard::v3_0 ) { | 149 | if ( version == VCard::v3_0 ) { |
139 | card.addLine( createSecrecy( (*addrIt).secrecy() ) ); | 150 | card.addLine( createSecrecy( (*addrIt).secrecy() ) ); |
140 | } | 151 | } |
141 | 152 | ||
142 | 153 | ||
143 | QStringList emails = (*addrIt).emails(); | 154 | QStringList emails = (*addrIt).emails(); |
144 | bool pref = true; | 155 | bool pref = true; |
145 | for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) { | 156 | for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) { |
146 | VCardLine line( "EMAIL", *strIt ); | 157 | VCardLine line( "EMAIL", *strIt ); |
147 | if ( pref == true ) { | 158 | if ( pref == true ) { |
148 | line.addParameter( "TYPE", "PREF" ); | 159 | line.addParameter( "TYPE", "PREF" ); |
149 | pref = false; | 160 | pref = false; |
150 | } | 161 | } |
151 | card.addLine( line ); | 162 | card.addLine( line ); |
152 | } | 163 | } |
153 | 164 | ||
154 | // FN | 165 | // FN |
155 | card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) ); | 166 | card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) ); |
156 | 167 | ||
157 | // GEO | 168 | // GEO |
158 | Geo geo = (*addrIt).geo(); | 169 | Geo geo = (*addrIt).geo(); |
159 | if ( geo.isValid() ) { | 170 | if ( geo.isValid() ) { |
160 | QString str; | 171 | QString str; |
161 | str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() ); | 172 | str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() ); |
162 | card.addLine( VCardLine( "GEO", str ) ); | 173 | card.addLine( VCardLine( "GEO", str ) ); |
163 | } | 174 | } |
164 | 175 | ||
165 | // KEY | 176 | // KEY |
166 | Key::List keys = (*addrIt).keys(); | 177 | Key::List keys = (*addrIt).keys(); |
167 | Key::List::ConstIterator keyIt; | 178 | Key::List::ConstIterator keyIt; |
168 | for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt ) | 179 | for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt ) |
169 | card.addLine( createKey( *keyIt ) ); | 180 | card.addLine( createKey( *keyIt ) ); |
170 | 181 | ||
171 | // LOGO | 182 | // LOGO |
172 | card.addLine( createPicture( "LOGO", (*addrIt).logo() ) ); | 183 | card.addLine( createPicture( "LOGO", (*addrIt).logo() ) ); |
173 | 184 | ||
174 | // MAILER | 185 | // MAILER |
175 | card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) ); | 186 | card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) ); |
176 | 187 | ||
177 | // N | 188 | // N |
178 | QStringList name; | 189 | QStringList name; |
179 | //US using the old implementation instead | 190 | //US using the old implementation instead |
180 | //qDebug("VCardTool::createVCards has to be verified"); | 191 | //qDebug("VCardTool::createVCards has to be verified"); |
181 | /*US | 192 | /*US |
182 | name.append( (*addrIt).familyName().replace( ';', "\\;" ) ); | 193 | name.append( (*addrIt).familyName().replace( ';', "\\;" ) ); |
183 | name.append( (*addrIt).givenName().replace( ';', "\\;" ) ); | 194 | name.append( (*addrIt).givenName().replace( ';', "\\;" ) ); |
184 | name.append( (*addrIt).additionalName().replace( ';', "\\;" ) ); | 195 | name.append( (*addrIt).additionalName().replace( ';', "\\;" ) ); |
185 | name.append( (*addrIt).prefix().replace( ';', "\\;" ) ); | 196 | name.append( (*addrIt).prefix().replace( ';', "\\;" ) ); |
186 | name.append( (*addrIt).suffix().replace( ';', "\\;" ) ); | 197 | name.append( (*addrIt).suffix().replace( ';', "\\;" ) ); |
187 | */ | 198 | */ |
188 | name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) ); | 199 | name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) ); |
189 | name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) ); | 200 | name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) ); |
190 | name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) ); | 201 | name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) ); |
191 | name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) ); | 202 | name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) ); |
192 | name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) ); | 203 | name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) ); |
193 | 204 | ||
194 | if ( !name.join( "" ).isEmpty() ) | 205 | if ( !name.join( "" ).isEmpty() ) |
195 | card.addLine( VCardLine( "N", name.join( ";" ) ) ); | 206 | card.addLine( VCardLine( "N", name.join( ";" ) ) ); |
196 | 207 | ||
197 | // NICKNAME | 208 | // NICKNAME |
198 | if ( version == VCard::v3_0 ) | 209 | if ( version == VCard::v3_0 ) |
199 | card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) ); | 210 | card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) ); |
200 | 211 | ||
201 | // NOTE | 212 | // NOTE |
202 | card.addLine( VCardLine( "NOTE", (*addrIt).note() ) ); | 213 | card.addLine( VCardLine( "NOTE", (*addrIt).note() ) ); |
203 | 214 | ||
204 | // ORG | 215 | // ORG |
205 | card.addLine( VCardLine( "ORG", (*addrIt).organization() ) ); | 216 | card.addLine( VCardLine( "ORG", (*addrIt).organization() ) ); |
206 | 217 | ||
207 | // PHOTO | 218 | // PHOTO |
208 | card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) ); | 219 | card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) ); |
209 | 220 | ||
210 | // PROID | 221 | // PROID |
211 | if ( version == VCard::v3_0 ) | 222 | if ( version == VCard::v3_0 ) |
212 | card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) ); | 223 | card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) ); |
213 | 224 | ||
214 | // REV | 225 | // REV |
215 | card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) ); | 226 | card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) ); |
216 | 227 | ||
217 | // ROLE | 228 | // ROLE |
218 | card.addLine( VCardLine( "ROLE", (*addrIt).role() ) ); | 229 | card.addLine( VCardLine( "ROLE", (*addrIt).role() ) ); |
219 | 230 | ||
220 | // SORT-STRING | 231 | // SORT-STRING |
221 | if ( version == VCard::v3_0 ) | 232 | if ( version == VCard::v3_0 ) |
222 | card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) ); | 233 | card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) ); |
223 | 234 | ||
224 | // SOUND | 235 | // SOUND |
225 | card.addLine( createSound( (*addrIt).sound() ) ); | 236 | card.addLine( createSound( (*addrIt).sound() ) ); |
226 | 237 | ||
227 | // TEL | 238 | // TEL |
228 | PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); | 239 | PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); |
229 | PhoneNumber::List::ConstIterator phoneIt; | 240 | PhoneNumber::List::ConstIterator phoneIt; |
230 | for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { | 241 | for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { |
231 | VCardLine line( "TEL", (*phoneIt).number() ); | 242 | VCardLine line( "TEL", (*phoneIt).number() ); |
232 | 243 | ||
233 | QMap<QString, int>::Iterator typeIt; | 244 | QMap<QString, int>::Iterator typeIt; |
234 | for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { | 245 | for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { |
235 | if ( typeIt.data() & (*phoneIt).type() ) | 246 | if ( typeIt.data() & (*phoneIt).type() ) |
236 | line.addParameter( "TYPE", typeIt.key() ); | 247 | if ( version == VCard::v3_0 ) |
248 | line.addParameter( "TYPE", typeIt.key().lower() ); | ||
249 | else | ||
250 | line.addParameter( "TYPE", typeIt.key() ); | ||
237 | } | 251 | } |
238 | 252 | ||
239 | card.addLine( line ); | 253 | card.addLine( line ); |
240 | } | 254 | } |
241 | 255 | ||
242 | // TITLE | 256 | // TITLE |
243 | card.addLine( VCardLine( "TITLE", (*addrIt).title() ) ); | 257 | card.addLine( VCardLine( "TITLE", (*addrIt).title() ) ); |
244 | 258 | ||
245 | // TZ | 259 | // TZ |
246 | TimeZone timeZone = (*addrIt).timeZone(); | 260 | TimeZone timeZone = (*addrIt).timeZone(); |
247 | if ( timeZone.isValid() ) { | 261 | if ( timeZone.isValid() ) { |
248 | QString str; | 262 | QString str; |
249 | 263 | ||
250 | int neg = 1; | 264 | int neg = 1; |
251 | if ( timeZone.offset() < 0 ) | 265 | if ( timeZone.offset() < 0 ) |
252 | neg = -1; | 266 | neg = -1; |
253 | 267 | ||
254 | str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ), | 268 | str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ), |
255 | ( timeZone.offset() / 60 ) * neg, | 269 | ( timeZone.offset() / 60 ) * neg, |
256 | ( timeZone.offset() % 60 ) * neg ); | 270 | ( timeZone.offset() % 60 ) * neg ); |
257 | 271 | ||
258 | card.addLine( VCardLine( "TZ", str ) ); | 272 | card.addLine( VCardLine( "TZ", str ) ); |
259 | } | 273 | } |
260 | 274 | ||
261 | // UID | 275 | // UID |
262 | card.addLine( VCardLine( "UID", (*addrIt).uid() ) ); | 276 | card.addLine( VCardLine( "UID", (*addrIt).uid() ) ); |
263 | 277 | ||
264 | // URL | 278 | // URL |
265 | card.addLine( VCardLine( "URL", (*addrIt).url().url() ) ); | 279 | card.addLine( VCardLine( "URL", (*addrIt).url().url() ) ); |
266 | 280 | ||
267 | // VERSION | 281 | // VERSION |
268 | if ( version == VCard::v2_1 ) | 282 | if ( version == VCard::v2_1 ) |
269 | card.addLine( VCardLine( "VERSION", "2.1" ) ); | 283 | card.addLine( VCardLine( "VERSION", "2.1" ) ); |
270 | if ( version == VCard::v3_0 ) | 284 | if ( version == VCard::v3_0 ) |
271 | card.addLine( VCardLine( "VERSION", "3.0" ) ); | 285 | card.addLine( VCardLine( "VERSION", "3.0" ) ); |
272 | 286 | ||
273 | // X- | 287 | // X- |
274 | QStringList customs = (*addrIt).customs(); | 288 | QStringList customs = (*addrIt).customs(); |
275 | for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { | 289 | for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { |
276 | QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) ); | 290 | QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) ); |
277 | QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 ); | 291 | QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 ); |
278 | if ( value.isEmpty() ) | 292 | if ( value.isEmpty() ) |
279 | continue; | 293 | continue; |
280 | 294 | ||
281 | card.addLine( VCardLine( identifier, value ) ); | 295 | card.addLine( VCardLine( identifier, value ) ); |
282 | } | 296 | } |
283 | 297 | ||
284 | vCardList.append( card ); | 298 | vCardList.append( card ); |
285 | } | 299 | } |
286 | 300 | ||
287 | return VCardParser::createVCards( vCardList ); | 301 | return VCardParser::createVCards( vCardList ); |
288 | } | 302 | } |
289 | 303 | ||
290 | Addressee::List VCardTool::parseVCards( const QString& vcard ) | 304 | Addressee::List VCardTool::parseVCards( const QString& vcard ) |
291 | { | 305 | { |
292 | QChar semicolonSep( ';' ); | 306 | QChar semicolonSep( ';' ); |
293 | QChar commaSep( ',' ); | 307 | QChar commaSep( ',' ); |
294 | QString identifier; | 308 | QString identifier; |
295 | 309 | ||
296 | Addressee::List addrList; | 310 | Addressee::List addrList; |
297 | VCard::List vCardList = VCardParser::parseVCards( vcard ); | 311 | VCard::List vCardList = VCardParser::parseVCards( vcard ); |
298 | VCard::List::Iterator cardIt; | 312 | VCard::List::Iterator cardIt; |
299 | for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) { | 313 | for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) { |
300 | Addressee addr; | 314 | Addressee addr; |
301 | QStringList idents = (*cardIt).identifiers(); | 315 | QStringList idents = (*cardIt).identifiers(); |
302 | QStringList::ConstIterator identIt; | 316 | QStringList::ConstIterator identIt; |
303 | for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { | 317 | for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { |
304 | VCard card = (*cardIt); | 318 | VCard card = (*cardIt); |
305 | VCardLine::List lines = card.lines( (*identIt) ); | 319 | VCardLine::List lines = card.lines( (*identIt) ); |
306 | VCardLine::List::Iterator lineIt; | 320 | VCardLine::List::Iterator lineIt; |
307 | 321 | ||
308 | // iterate over the lines | 322 | // iterate over the lines |
309 | for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { | 323 | for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { |
310 | QStringList params = (*lineIt).parameterList(); | 324 | QStringList params = (*lineIt).parameterList(); |
311 | 325 | ||
312 | identifier = (*lineIt).identifier().lower(); | 326 | identifier = (*lineIt).identifier().lower(); |
313 | // ADR | 327 | // ADR |
314 | if ( identifier == "adr" ) { | 328 | if ( identifier == "adr" ) { |
315 | Address address; | 329 | Address address; |
316 | QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); | 330 | QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); |
317 | if ( addrParts.count() > 0 ) | 331 | if ( addrParts.count() > 0 ) |
318 | address.setPostOfficeBox( addrParts[ 0 ] ); | 332 | address.setPostOfficeBox( addrParts[ 0 ] ); |
319 | if ( addrParts.count() > 1 ) | 333 | if ( addrParts.count() > 1 ) |
320 | address.setExtended( addrParts[ 1 ] ); | 334 | address.setExtended( addrParts[ 1 ] ); |
321 | if ( addrParts.count() > 2 ) | 335 | if ( addrParts.count() > 2 ) |
322 | address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") ); | 336 | address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") ); |
323 | if ( addrParts.count() > 3 ) | 337 | if ( addrParts.count() > 3 ) |
324 | address.setLocality( addrParts[ 3 ] ); | 338 | address.setLocality( addrParts[ 3 ] ); |
325 | if ( addrParts.count() > 4 ) | 339 | if ( addrParts.count() > 4 ) |
326 | address.setRegion( addrParts[ 4 ] ); | 340 | address.setRegion( addrParts[ 4 ] ); |
327 | if ( addrParts.count() > 5 ) | 341 | if ( addrParts.count() > 5 ) |
328 | address.setPostalCode( addrParts[ 5 ] ); | 342 | address.setPostalCode( addrParts[ 5 ] ); |
329 | if ( addrParts.count() > 6 ) | 343 | if ( addrParts.count() > 6 ) |
330 | address.setCountry( addrParts[ 6 ] ); | 344 | address.setCountry( addrParts[ 6 ] ); |
331 | 345 | ||
332 | int type = 0; | 346 | int type = 0; |
333 | 347 | ||
334 | QStringList types = (*lineIt).parameters( "type" ); | 348 | QStringList types = (*lineIt).parameters( "type" ); |
335 | for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) | 349 | for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) |
336 | type += mAddressTypeMap[ (*it).lower() ]; | 350 | type += mAddressTypeMap[ (*it).lower() ]; |
337 | 351 | ||
338 | if ( !type ) | 352 | if ( !type ) |
339 | type = Address::Home; // default | 353 | type = Address::Home; // default |
340 | 354 | ||
341 | address.setType( type ); | 355 | address.setType( type ); |
342 | addr.insertAddress( address ); | 356 | addr.insertAddress( address ); |
343 | } | 357 | } |
344 | 358 | ||
345 | // AGENT | 359 | // AGENT |
346 | if ( identifier == "agent" ) | 360 | if ( identifier == "agent" ) |
347 | addr.setAgent( parseAgent( *lineIt ) ); | 361 | addr.setAgent( parseAgent( *lineIt ) ); |
348 | 362 | ||
349 | // BDAY | 363 | // BDAY |
350 | if ( identifier == "bday" ) | 364 | if ( identifier == "bday" ) |
351 | addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); | 365 | addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); |
352 | 366 | ||
353 | // CATEGORIES | 367 | // CATEGORIES |
354 | if ( identifier == "categories" ) { | 368 | if ( identifier == "categories" ) { |
355 | QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); | 369 | QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); |
356 | addr.setCategories( categories ); | 370 | addr.setCategories( categories ); |
357 | } | 371 | } |
358 | 372 | ||
359 | // CLASS | 373 | // CLASS |
360 | if ( identifier == "class" ) | 374 | if ( identifier == "class" ) |
361 | addr.setSecrecy( parseSecrecy( *lineIt ) ); | 375 | addr.setSecrecy( parseSecrecy( *lineIt ) ); |
362 | 376 | ||
363 | 377 | ||
364 | if ( identifier == "email" ) { | 378 | if ( identifier == "email" ) { |
365 | QStringList types = (*lineIt).parameters( "type" ); | 379 | QStringList types = (*lineIt).parameters( "type" ); |
366 | addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) ); | 380 | addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) ); |
367 | } | 381 | } |
368 | 382 | ||
369 | // FN | 383 | // FN |
370 | if ( identifier == "fn" ) | 384 | if ( identifier == "fn" ) |
371 | addr.setFormattedName( (*lineIt).value().asString() ); | 385 | addr.setFormattedName( (*lineIt).value().asString() ); |
372 | 386 | ||
373 | // GEO | 387 | // GEO |
374 | if ( identifier == "geo" ) { | 388 | if ( identifier == "geo" ) { |
375 | Geo geo; | 389 | Geo geo; |
376 | 390 | ||
377 | QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); | 391 | QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); |
378 | geo.setLatitude( geoParts[ 0 ].toFloat() ); | 392 | geo.setLatitude( geoParts[ 0 ].toFloat() ); |
379 | geo.setLongitude( geoParts[ 1 ].toFloat() ); | 393 | geo.setLongitude( geoParts[ 1 ].toFloat() ); |
380 | 394 | ||
381 | addr.setGeo( geo ); | 395 | addr.setGeo( geo ); |
382 | } | 396 | } |
383 | 397 | ||
384 | // KEY | 398 | // KEY |
385 | if ( identifier == "key" ) | 399 | if ( identifier == "key" ) |
386 | addr.insertKey( parseKey( *lineIt ) ); | 400 | addr.insertKey( parseKey( *lineIt ) ); |
387 | 401 | ||
388 | // LABEL | 402 | // LABEL |
389 | if ( identifier == "label" ) { | 403 | if ( identifier == "label" ) { |
390 | int type = 0; | 404 | int type = 0; |
391 | 405 | ||
392 | QStringList types = (*lineIt).parameters( "type" ); | 406 | QStringList types = (*lineIt).parameters( "type" ); |
393 | for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) | 407 | for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) |
394 | type += mAddressTypeMap[ (*it).lower() ]; | 408 | type += mAddressTypeMap[ (*it).lower() ]; |
395 | 409 | ||
396 | if ( !type ) | 410 | if ( !type ) |
397 | type = Address::Home; | 411 | type = Address::Home; |
398 | 412 | ||
399 | KABC::Address::List addressList = addr.addresses(); | 413 | KABC::Address::List addressList = addr.addresses(); |
400 | KABC::Address::List::Iterator it; | 414 | KABC::Address::List::Iterator it; |
401 | for ( it = addressList.begin(); it != addressList.end(); ++it ) { | 415 | for ( it = addressList.begin(); it != addressList.end(); ++it ) { |
402 | if ( (*it).type() == type ) { | 416 | if ( (*it).type() == type ) { |
403 | (*it).setLabel( (*lineIt).value().asString() ); | 417 | (*it).setLabel( (*lineIt).value().asString() ); |
404 | addr.insertAddress( *it ); | 418 | addr.insertAddress( *it ); |
405 | } | 419 | } |
406 | } | 420 | } |
407 | } | 421 | } |
408 | 422 | ||
409 | // LOGO | 423 | // LOGO |
410 | if ( identifier == "logo" ) | 424 | if ( identifier == "logo" ) |
411 | addr.setLogo( parsePicture( *lineIt ) ); | 425 | addr.setLogo( parsePicture( *lineIt ) ); |
412 | 426 | ||
413 | // MAILER | 427 | // MAILER |
414 | if ( identifier == "mailer" ) | 428 | if ( identifier == "mailer" ) |
415 | addr.setMailer( (*lineIt).value().asString() ); | 429 | addr.setMailer( (*lineIt).value().asString() ); |
416 | 430 | ||
417 | // N | 431 | // N |
418 | if ( identifier == "n" ) { | 432 | if ( identifier == "n" ) { |
419 | QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); | 433 | QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); |
420 | if ( nameParts.count() > 0 ) | 434 | if ( nameParts.count() > 0 ) |
421 | addr.setFamilyName( nameParts[ 0 ] ); | 435 | addr.setFamilyName( nameParts[ 0 ] ); |
422 | if ( nameParts.count() > 1 ) | 436 | if ( nameParts.count() > 1 ) |
423 | addr.setGivenName( nameParts[ 1 ] ); | 437 | addr.setGivenName( nameParts[ 1 ] ); |
424 | if ( nameParts.count() > 2 ) | 438 | if ( nameParts.count() > 2 ) |
425 | addr.setAdditionalName( nameParts[ 2 ] ); | 439 | addr.setAdditionalName( nameParts[ 2 ] ); |
426 | if ( nameParts.count() > 3 ) | 440 | if ( nameParts.count() > 3 ) |
427 | addr.setPrefix( nameParts[ 3 ] ); | 441 | addr.setPrefix( nameParts[ 3 ] ); |
428 | if ( nameParts.count() > 4 ) | 442 | if ( nameParts.count() > 4 ) |
429 | addr.setSuffix( nameParts[ 4 ] ); | 443 | addr.setSuffix( nameParts[ 4 ] ); |
430 | } | 444 | } |
431 | 445 | ||
432 | // NICKNAME | 446 | // NICKNAME |
433 | if ( identifier == "nickname" ) | 447 | if ( identifier == "nickname" ) |
434 | addr.setNickName( (*lineIt).value().asString() ); | 448 | addr.setNickName( (*lineIt).value().asString() ); |
435 | 449 | ||
436 | // NOTE | 450 | // NOTE |
437 | if ( identifier == "note" ) { | 451 | if ( identifier == "note" ) { |
438 | // #ifdef DESKTOP_VERSION | 452 | // #ifdef DESKTOP_VERSION |
439 | // addr.setNote( (*lineIt).value().asString() ); | 453 | // addr.setNote( (*lineIt).value().asString() ); |
440 | // #else | 454 | // #else |
441 | QString note = (*lineIt).value().asString(); | 455 | QString note = (*lineIt).value().asString(); |
442 | if ( ! note.isEmpty() ) | 456 | if ( ! note.isEmpty() ) |
443 | addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") ); | 457 | addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") ); |
444 | else | 458 | else |
445 | addr.setNote( note ); | 459 | addr.setNote( note ); |
446 | //#endif | 460 | //#endif |
447 | } | 461 | } |
448 | 462 | ||
449 | // ORGANIZATION | 463 | // ORGANIZATION |
450 | if ( identifier == "org" ) | 464 | if ( identifier == "org" ) |
451 | addr.setOrganization( (*lineIt).value().asString() ); | 465 | addr.setOrganization( (*lineIt).value().asString() ); |
452 | 466 | ||
453 | // PHOTO | 467 | // PHOTO |
454 | if ( identifier == "photo" ) | 468 | if ( identifier == "photo" ) |
455 | addr.setPhoto( parsePicture( *lineIt ) ); | 469 | addr.setPhoto( parsePicture( *lineIt ) ); |
456 | 470 | ||
457 | // PROID | 471 | // PROID |
458 | if ( identifier == "prodid" ) | 472 | if ( identifier == "prodid" ) |
459 | addr.setProductId( (*lineIt).value().asString() ); | 473 | addr.setProductId( (*lineIt).value().asString() ); |
460 | 474 | ||
461 | // REV | 475 | // REV |
462 | if ( identifier == "rev" ) | 476 | if ( identifier == "rev" ) |
463 | addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); | 477 | addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); |
464 | 478 | ||
465 | // ROLE | 479 | // ROLE |
466 | if ( identifier == "role" ) | 480 | if ( identifier == "role" ) |
467 | addr.setRole( (*lineIt).value().asString() ); | 481 | addr.setRole( (*lineIt).value().asString() ); |
468 | 482 | ||
469 | // SORT-STRING | 483 | // SORT-STRING |
470 | if ( identifier == "sort-string" ) | 484 | if ( identifier == "sort-string" ) |
471 | addr.setSortString( (*lineIt).value().asString() ); | 485 | addr.setSortString( (*lineIt).value().asString() ); |
472 | 486 | ||
473 | // SOUND | 487 | // SOUND |
474 | if ( identifier == "sound" ) | 488 | if ( identifier == "sound" ) |
475 | addr.setSound( parseSound( *lineIt ) ); | 489 | addr.setSound( parseSound( *lineIt ) ); |
476 | 490 | ||
477 | // TEL | 491 | // TEL |
478 | if ( identifier == "tel" ) { | 492 | if ( identifier == "tel" ) { |
479 | PhoneNumber phone; | 493 | PhoneNumber phone; |
480 | phone.setNumber( (*lineIt).value().asString() ); | 494 | phone.setNumber( (*lineIt).value().asString() ); |
481 | 495 | ||
482 | int type = 0; | 496 | int type = 0; |
483 | 497 | ||
484 | QStringList types = (*lineIt).parameters( "type" ); | 498 | QStringList types = (*lineIt).parameters( "type" ); |
485 | for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) | 499 | for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) |
486 | type += mPhoneTypeMap[(*it).upper()]; | 500 | type += mPhoneTypeMap[(*it).upper()]; |
487 | 501 | ||
488 | if ( !type ) | 502 | if ( !type ) |
489 | type = PhoneNumber::Home; // default | 503 | type = PhoneNumber::Home; // default |
490 | 504 | ||
491 | phone.setType( type ); | 505 | phone.setType( type ); |
492 | 506 | ||
493 | addr.insertPhoneNumber( phone ); | 507 | addr.insertPhoneNumber( phone ); |
494 | } | 508 | } |
495 | 509 | ||
496 | // TITLE | 510 | // TITLE |
497 | if ( identifier == "title" ) | 511 | if ( identifier == "title" ) |
498 | addr.setTitle( (*lineIt).value().asString() ); | 512 | addr.setTitle( (*lineIt).value().asString() ); |
499 | 513 | ||
500 | // TZ | 514 | // TZ |
501 | if ( identifier == "tz" ) { | 515 | if ( identifier == "tz" ) { |
502 | TimeZone tz; | 516 | TimeZone tz; |
503 | QString date = (*lineIt).value().asString(); | 517 | QString date = (*lineIt).value().asString(); |
504 | 518 | ||
505 | int hours = date.mid( 1, 2).toInt(); | 519 | int hours = date.mid( 1, 2).toInt(); |
506 | int minutes = date.mid( 4, 2 ).toInt(); | 520 | int minutes = date.mid( 4, 2 ).toInt(); |
507 | int offset = ( hours * 60 ) + minutes; | 521 | int offset = ( hours * 60 ) + minutes; |
508 | offset = offset * ( date[ 0 ] == '+' ? 1 : -1 ); | 522 | offset = offset * ( date[ 0 ] == '+' ? 1 : -1 ); |
509 | 523 | ||
510 | tz.setOffset( offset ); | 524 | tz.setOffset( offset ); |
511 | addr.setTimeZone( tz ); | 525 | addr.setTimeZone( tz ); |
512 | } | 526 | } |
513 | 527 | ||
514 | // UID | 528 | // UID |
515 | if ( identifier == "uid" ) | 529 | if ( identifier == "uid" ) |
516 | addr.setUid( (*lineIt).value().asString() ); | 530 | addr.setUid( (*lineIt).value().asString() ); |
517 | 531 | ||
518 | // URL | 532 | // URL |
519 | if ( identifier == "url" ) | 533 | if ( identifier == "url" ) |
520 | addr.setUrl( (*lineIt).value().asString() ); | 534 | addr.setUrl( (*lineIt).value().asString() ); |
521 | 535 | ||
522 | // X- | 536 | // X- |
523 | if ( identifier.startsWith( "x-" ) ) { | 537 | if ( identifier.startsWith( "x-" ) ) { |
524 | QString key = (*lineIt).identifier().mid( 2 ); | 538 | QString key = (*lineIt).identifier().mid( 2 ); |
525 | int dash = key.find( "-" ); | 539 | int dash = key.find( "-" ); |
526 | addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() ); | 540 | addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() ); |
527 | } | 541 | } |
528 | } | 542 | } |
529 | } | 543 | } |
530 | 544 | ||
531 | addrList.append( addr ); | 545 | addrList.append( addr ); |
532 | } | 546 | } |
533 | 547 | ||
534 | return addrList; | 548 | return addrList; |
535 | } | 549 | } |
536 | 550 | ||
537 | QDateTime VCardTool::parseDateTime( const QString &str ) | 551 | QDateTime VCardTool::parseDateTime( const QString &str ) |
538 | { | 552 | { |
539 | QDateTime dateTime; | 553 | QDateTime dateTime; |
540 | 554 | ||
541 | if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd) | 555 | if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd) |
542 | dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), | 556 | dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), |
543 | str.mid( 6, 2 ).toInt() ) ); | 557 | str.mid( 6, 2 ).toInt() ) ); |
544 | 558 | ||
545 | if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss | 559 | if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss |
546 | dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), | 560 | dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), |
547 | str.mid( 17, 2 ).toInt() ) ); | 561 | str.mid( 17, 2 ).toInt() ) ); |
548 | 562 | ||
549 | } else { // is extended format yyyy-mm-dd | 563 | } else { // is extended format yyyy-mm-dd |
550 | dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), | 564 | dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), |
551 | str.mid( 8, 2 ).toInt() ) ); | 565 | str.mid( 8, 2 ).toInt() ) ); |
552 | 566 | ||
553 | if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss | 567 | if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss |
554 | dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), | 568 | dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), |
555 | str.mid( 17, 2 ).toInt() ) ); | 569 | str.mid( 17, 2 ).toInt() ) ); |
556 | } | 570 | } |
557 | 571 | ||
558 | return dateTime; | 572 | return dateTime; |
559 | } | 573 | } |
560 | 574 | ||
561 | QString VCardTool::createDateTime( const QDateTime &dateTime ) | 575 | QString VCardTool::createDateTime( const QDateTime &dateTime ) |
562 | { | 576 | { |
563 | QString str; | 577 | QString str; |
564 | 578 | ||
565 | if ( dateTime.date().isValid() ) { | 579 | if ( dateTime.date().isValid() ) { |
566 | str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), | 580 | str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), |
567 | dateTime.date().day() ); | 581 | dateTime.date().day() ); |
568 | if ( dateTime.time().isValid() ) { | 582 | if ( dateTime.time().isValid() ) { |
569 | QString tmp; | 583 | QString tmp; |
570 | tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), | 584 | tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), |
571 | dateTime.time().second() ); | 585 | dateTime.time().second() ); |
572 | str += tmp; | 586 | str += tmp; |
573 | } | 587 | } |
574 | } | 588 | } |
575 | 589 | ||
576 | return str; | 590 | return str; |
577 | } | 591 | } |
578 | 592 | ||
579 | Picture VCardTool::parsePicture( const VCardLine &line ) | 593 | Picture VCardTool::parsePicture( const VCardLine &line ) |
580 | { | 594 | { |
581 | Picture pic; | 595 | Picture pic; |
582 | 596 | ||
583 | QStringList params = line.parameterList(); | 597 | QStringList params = line.parameterList(); |
584 | if ( params.contains( "encoding" ) ) { | 598 | if ( params.contains( "encoding" ) ) { |
585 | QCString cs(line.value().asCString()); | 599 | QCString cs(line.value().asCString()); |
586 | QByteArray input, output; | 600 | QByteArray input, output; |
587 | input = line.value().asCString(); | 601 | input = line.value().asCString(); |
588 | if ( line.parameter( "encoding" ).lower() == "b" ) | 602 | if ( line.parameter( "encoding" ).lower() == "b" ) |
589 | KCodecs::base64Decode( input, output ); | 603 | KCodecs::base64Decode( input, output ); |
590 | else if ( line.parameter( "encoding" ).lower() == "quoted-printable" ) | 604 | else if ( line.parameter( "encoding" ).lower() == "quoted-printable" ) |
591 | KCodecs::quotedPrintableDecode( input, output ); | 605 | KCodecs::quotedPrintableDecode( input, output ); |
592 | 606 | ||
593 | qDebug("********** DECODING OKAY ************** (picture)"); | 607 | qDebug("********** DECODING OKAY ************** (picture)"); |
594 | pic.setData( QImage(output) ); | 608 | pic.setData( QImage(output) ); |
595 | 609 | ||
596 | } | 610 | } |
597 | else if ( params.contains( "value" ) ) { | 611 | else if ( params.contains( "value" ) ) { |
598 | if ( line.parameter( "value" ).lower() == "uri" ) | 612 | if ( line.parameter( "value" ).lower() == "uri" ) |
599 | pic.setUrl( line.value().asString() ); | 613 | pic.setUrl( line.value().asString() ); |
600 | } | 614 | } |
601 | 615 | ||
602 | if ( params.contains( "type" ) ) | 616 | if ( params.contains( "type" ) ) |
603 | pic.setType( line.parameter( "type" ) ); | 617 | pic.setType( line.parameter( "type" ) ); |
604 | 618 | ||
605 | return pic; | 619 | return pic; |
606 | } | 620 | } |
607 | 621 | ||
608 | VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) | 622 | VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) |
609 | { | 623 | { |
610 | // LR fixed | 624 | // LR fixed |
611 | VCardLine line( identifier ); | 625 | VCardLine line( identifier ); |
612 | 626 | ||
613 | if ( pic.isIntern() ) { | 627 | if ( pic.isIntern() ) { |
614 | if ( !pic.data().isNull() ) { | 628 | if ( !pic.data().isNull() ) { |
615 | #if 0 | 629 | #if 0 |
616 | QByteArray input; | 630 | QByteArray input; |
617 | QDataStream s( input, IO_WriteOnly ); | 631 | QDataStream s( input, IO_WriteOnly ); |
618 | s.setVersion( 4 ); | 632 | s.setVersion( 4 ); |
619 | s << pic.data(); | 633 | s << pic.data(); |
620 | line.setValue( input ); | 634 | line.setValue( input ); |