-rw-r--r-- | kabc/vcard/ContentLine.cpp | 10 | ||||
-rw-r--r-- | kabc/vcard/VCardv.cpp | 12 | ||||
-rw-r--r-- | kabc/vcard/include/VCardDefines.h | 3 | ||||
-rw-r--r-- | kabc/vcardformatimpl.cpp | 2 |
4 files changed, 20 insertions, 7 deletions
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp index 0fb5b5d..f7e04a9 100644 --- a/kabc/vcard/ContentLine.cpp +++ b/kabc/vcard/ContentLine.cpp | |||
@@ -1,314 +1,320 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1999 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1999 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qcstring.h> | 24 | #include <qcstring.h> |
25 | #include <qstrlist.h> | 25 | #include <qstrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | 27 | ||
28 | #include <kdebug.h> | 28 | #include <kdebug.h> |
29 | 29 | ||
30 | #include <VCardAdrParam.h> | 30 | #include <VCardAdrParam.h> |
31 | #include <VCardAgentParam.h> | 31 | #include <VCardAgentParam.h> |
32 | #include <VCardDateParam.h> | 32 | #include <VCardDateParam.h> |
33 | #include <VCardEmailParam.h> | 33 | #include <VCardEmailParam.h> |
34 | #include <VCardImageParam.h> | 34 | #include <VCardImageParam.h> |
35 | #include <VCardSourceParam.h> | 35 | #include <VCardSourceParam.h> |
36 | #include <VCardTelParam.h> | 36 | #include <VCardTelParam.h> |
37 | #include <VCardTextBinParam.h> | 37 | #include <VCardTextBinParam.h> |
38 | #include <VCardTextParam.h> | 38 | #include <VCardTextParam.h> |
39 | 39 | ||
40 | #include <VCardAdrValue.h> | 40 | #include <VCardAdrValue.h> |
41 | #include <VCardAgentValue.h> | 41 | #include <VCardAgentValue.h> |
42 | #include <VCardDateValue.h> | 42 | #include <VCardDateValue.h> |
43 | #include <VCardImageValue.h> | 43 | #include <VCardImageValue.h> |
44 | #include <VCardTextValue.h> | 44 | #include <VCardTextValue.h> |
45 | #include <VCardTextBinValue.h> | 45 | #include <VCardTextBinValue.h> |
46 | #include <VCardLangValue.h> | 46 | #include <VCardLangValue.h> |
47 | #include <VCardNValue.h> | 47 | #include <VCardNValue.h> |
48 | #include <VCardURIValue.h> | 48 | #include <VCardURIValue.h> |
49 | #include <VCardSoundValue.h> | 49 | #include <VCardSoundValue.h> |
50 | #include <VCardClassValue.h> | 50 | #include <VCardClassValue.h> |
51 | #include <VCardFloatValue.h> | 51 | #include <VCardFloatValue.h> |
52 | #include <VCardOrgValue.h> | 52 | #include <VCardOrgValue.h> |
53 | #include <VCardTelValue.h> | 53 | #include <VCardTelValue.h> |
54 | #include <VCardTextListValue.h> | 54 | #include <VCardTextListValue.h> |
55 | #include <VCardUTCValue.h> | 55 | #include <VCardUTCValue.h> |
56 | #include <VCardGeoValue.h> | 56 | #include <VCardGeoValue.h> |
57 | 57 | ||
58 | #include <VCardRToken.h> | 58 | #include <VCardRToken.h> |
59 | #include <VCardContentLine.h> | 59 | #include <VCardContentLine.h> |
60 | 60 | ||
61 | #include <VCardEntity.h> | 61 | #include <VCardEntity.h> |
62 | #include <VCardEnum.h> | 62 | #include <VCardEnum.h> |
63 | #include <VCardDefines.h> | 63 | #include <VCardDefines.h> |
64 | 64 | ||
65 | using namespace VCARD; | 65 | using namespace VCARD; |
66 | 66 | ||
67 | ContentLine::ContentLine() | 67 | ContentLine::ContentLine() |
68 | :Entity(), | 68 | :Entity(), |
69 | value_(0) | 69 | value_(0), |
70 | paramType_( ParamUnknown ), | ||
71 | valueType_( ValueUnknown ), | ||
72 | entityType_( EntityUnknown ) | ||
70 | { | 73 | { |
71 | paramList_.setAutoDelete( TRUE ); | 74 | paramList_.setAutoDelete( TRUE ); |
72 | } | 75 | } |
73 | 76 | ||
74 | ContentLine::ContentLine(const ContentLine & x) | 77 | ContentLine::ContentLine(const ContentLine & x) |
75 | :Entity(x), | 78 | :Entity(x), |
76 | group_ (x.group_), | 79 | group_ (x.group_), |
77 | name_ (x.name_), | 80 | name_ (x.name_), |
78 | /*US paramList_(x.paramList_),*/ | 81 | /*US paramList_(x.paramList_),*/ |
79 | value_(x.value_->clone()), | 82 | value_(x.value_->clone()), |
80 | paramType_(x.paramType_), | 83 | paramType_(x.paramType_), |
81 | valueType_(x.valueType_), | 84 | valueType_(x.valueType_), |
82 | entityType_(x.entityType_) | 85 | entityType_(x.entityType_) |
83 | { | 86 | { |
84 | paramList_.setAutoDelete( TRUE ); | 87 | paramList_.setAutoDelete( TRUE ); |
85 | 88 | ||
86 | 89 | ||
87 | ParamListIterator it(x.paramList_); | 90 | ParamListIterator it(x.paramList_); |
88 | for (; it.current(); ++it) | 91 | for (; it.current(); ++it) |
89 | { | 92 | { |
90 | Param *p = new Param; | 93 | Param *p = new Param; |
91 | p->setName( it.current()->name() ); | 94 | p->setName( it.current()->name() ); |
92 | p->setValue( it.current()->value() ); | 95 | p->setValue( it.current()->value() ); |
93 | paramList_.append(p); | 96 | paramList_.append(p); |
94 | } | 97 | } |
95 | 98 | ||
96 | } | 99 | } |
97 | 100 | ||
98 | ContentLine::ContentLine(const QCString & s) | 101 | ContentLine::ContentLine(const QCString & s) |
99 | :Entity(s), | 102 | :Entity(s), |
100 | value_(0) | 103 | value_(0), |
104 | paramType_( ParamUnknown ), | ||
105 | valueType_( ValueUnknown ), | ||
106 | entityType_( EntityUnknown ) | ||
101 | { | 107 | { |
102 | paramList_.setAutoDelete( TRUE ); | 108 | paramList_.setAutoDelete( TRUE ); |
103 | } | 109 | } |
104 | 110 | ||
105 | ContentLine & | 111 | ContentLine & |
106 | ContentLine::operator = (ContentLine & x) | 112 | ContentLine::operator = (ContentLine & x) |
107 | { | 113 | { |
108 | if (*this == x) return *this; | 114 | if (*this == x) return *this; |
109 | 115 | ||
110 | ParamListIterator it(x.paramList_); | 116 | ParamListIterator it(x.paramList_); |
111 | for (; it.current(); ++it) | 117 | for (; it.current(); ++it) |
112 | { | 118 | { |
113 | Param *p = new Param; | 119 | Param *p = new Param; |
114 | p->setName( it.current()->name() ); | 120 | p->setName( it.current()->name() ); |
115 | p->setValue( it.current()->value() ); | 121 | p->setValue( it.current()->value() ); |
116 | paramList_.append(p); | 122 | paramList_.append(p); |
117 | } | 123 | } |
118 | 124 | ||
119 | value_ = x.value_->clone(); | 125 | value_ = x.value_->clone(); |
120 | 126 | ||
121 | Entity::operator = (x); | 127 | Entity::operator = (x); |
122 | return *this; | 128 | return *this; |
123 | } | 129 | } |
124 | 130 | ||
125 | ContentLine & | 131 | ContentLine & |
126 | ContentLine::operator = (const QCString & s) | 132 | ContentLine::operator = (const QCString & s) |
127 | { | 133 | { |
128 | Entity::operator = (s); | 134 | Entity::operator = (s); |
129 | delete value_; | 135 | delete value_; |
130 | value_ = 0; | 136 | value_ = 0; |
131 | return *this; | 137 | return *this; |
132 | } | 138 | } |
133 | 139 | ||
134 | bool | 140 | bool |
135 | ContentLine::operator == (ContentLine & x) | 141 | ContentLine::operator == (ContentLine & x) |
136 | { | 142 | { |
137 | x.parse(); | 143 | x.parse(); |
138 | 144 | ||
139 | QPtrListIterator<Param> it(x.paramList()); | 145 | QPtrListIterator<Param> it(x.paramList()); |
140 | 146 | ||
141 | if (!paramList_.find(it.current())) | 147 | if (!paramList_.find(it.current())) |
142 | return false; | 148 | return false; |
143 | 149 | ||
144 | return true; | 150 | return true; |
145 | } | 151 | } |
146 | 152 | ||
147 | ContentLine::~ContentLine() | 153 | ContentLine::~ContentLine() |
148 | { | 154 | { |
149 | delete value_; | 155 | delete value_; |
150 | value_ = 0; | 156 | value_ = 0; |
151 | } | 157 | } |
152 | 158 | ||
153 | void | 159 | void |
154 | ContentLine::_parse() | 160 | ContentLine::_parse() |
155 | { | 161 | { |
156 | vDebug("parse"); | 162 | vDebug("parse"); |
157 | 163 | ||
158 | // Unqote newlines | 164 | // Unqote newlines |
159 | strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); | 165 | strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); |
160 | 166 | ||
161 | int split = strRep_.find(':'); | 167 | int split = strRep_.find(':'); |
162 | 168 | ||
163 | if (split == -1) { // invalid content line | 169 | if (split == -1) { // invalid content line |
164 | vDebug("No ':'"); | 170 | vDebug("No ':'"); |
165 | return; | 171 | return; |
166 | } | 172 | } |
167 | 173 | ||
168 | QCString firstPart(strRep_.left(split)); | 174 | QCString firstPart(strRep_.left(split)); |
169 | QCString valuePart(strRep_.mid(split + 1)); | 175 | QCString valuePart(strRep_.mid(split + 1)); |
170 | 176 | ||
171 | split = firstPart.find('.'); | 177 | split = firstPart.find('.'); |
172 | 178 | ||
173 | if (split != -1) { | 179 | if (split != -1) { |
174 | group_ = firstPart.left(split); | 180 | group_ = firstPart.left(split); |
175 | firstPart= firstPart.mid(split + 1); | 181 | firstPart= firstPart.mid(split + 1); |
176 | } | 182 | } |
177 | 183 | ||
178 | vDebug("Group == " + group_); | 184 | vDebug("Group == " + group_); |
179 | vDebug("firstPart == " + firstPart); | 185 | vDebug("firstPart == " + firstPart); |
180 | vDebug("valuePart == " + valuePart); | 186 | vDebug("valuePart == " + valuePart); |
181 | 187 | ||
182 | // Now we have the group, the name and param list together and the value. | 188 | // Now we have the group, the name and param list together and the value. |
183 | 189 | ||
184 | QStrList l; | 190 | QStrList l; |
185 | 191 | ||
186 | RTokenise(firstPart, ";", l); | 192 | RTokenise(firstPart, ";", l); |
187 | 193 | ||
188 | if (l.count() == 0) {// invalid - no name ! | 194 | if (l.count() == 0) {// invalid - no name ! |
189 | vDebug("No name for this content line !"); | 195 | vDebug("No name for this content line !"); |
190 | return; | 196 | return; |
191 | } | 197 | } |
192 | 198 | ||
193 | name_ = l.at(0); | 199 | name_ = l.at(0); |
194 | 200 | ||
195 | // Now we have the name, so the rest of 'l' is the params. | 201 | // Now we have the name, so the rest of 'l' is the params. |
196 | // Remove the name part. | 202 | // Remove the name part. |
197 | l.remove(0u); | 203 | l.remove(0u); |
198 | 204 | ||
199 | entityType_= EntityNameToEntityType(name_); | 205 | entityType_= EntityNameToEntityType(name_); |
200 | paramType_= EntityTypeToParamType(entityType_); | 206 | paramType_= EntityTypeToParamType(entityType_); |
201 | 207 | ||
202 | unsigned int i = 0; | 208 | unsigned int i = 0; |
203 | 209 | ||
204 | // For each parameter, create a new parameter of the correct type. | 210 | // For each parameter, create a new parameter of the correct type. |
205 | 211 | ||
206 | QStrListIterator it(l); | 212 | QStrListIterator it(l); |
207 | 213 | ||
208 | for (; it.current(); ++it, i++) { | 214 | for (; it.current(); ++it, i++) { |
209 | 215 | ||
210 | QCString str = *it; | 216 | QCString str = *it; |
211 | 217 | ||
212 | split = str.find("="); | 218 | split = str.find("="); |
213 | if (split < 0 ) { | 219 | if (split < 0 ) { |
214 | vDebug("No '=' in paramter."); | 220 | vDebug("No '=' in paramter."); |
215 | continue; | 221 | continue; |
216 | } | 222 | } |
217 | 223 | ||
218 | QCString paraName = str.left(split); | 224 | QCString paraName = str.left(split); |
219 | QCString paraValue = str.mid(split + 1); | 225 | QCString paraValue = str.mid(split + 1); |
220 | 226 | ||
221 | QStrList paraValues; | 227 | QStrList paraValues; |
222 | RTokenise(paraValue, ",", paraValues); | 228 | RTokenise(paraValue, ",", paraValues); |
223 | 229 | ||
224 | QStrListIterator it2( paraValues ); | 230 | QStrListIterator it2( paraValues ); |
225 | 231 | ||
226 | for(; it2.current(); ++it2) { | 232 | for(; it2.current(); ++it2) { |
227 | 233 | ||
228 | Param *p = new Param; | 234 | Param *p = new Param; |
229 | p->setName( paraName ); | 235 | p->setName( paraName ); |
230 | p->setValue( *it2 ); | 236 | p->setValue( *it2 ); |
231 | 237 | ||
232 | paramList_.append(p); | 238 | paramList_.append(p); |
233 | } | 239 | } |
234 | } | 240 | } |
235 | 241 | ||
236 | // Create a new value of the correct type. | 242 | // Create a new value of the correct type. |
237 | 243 | ||
238 | valueType_ = EntityTypeToValueType(entityType_); | 244 | valueType_ = EntityTypeToValueType(entityType_); |
239 | 245 | ||
240 | //kdDebug(5710) << "valueType: " << valueType_ << endl; | 246 | //kdDebug(5710) << "valueType: " << valueType_ << endl; |
241 | 247 | ||
242 | switch (valueType_) { | 248 | switch (valueType_) { |
243 | 249 | ||
244 | case ValueSound: value_ = new SoundValue;break; | 250 | case ValueSound: value_ = new SoundValue;break; |
245 | case ValueAgent: value_ = new AgentValue;break; | 251 | case ValueAgent: value_ = new AgentValue;break; |
246 | case ValueAddress: value_ = new AdrValue; break; | 252 | case ValueAddress: value_ = new AdrValue; break; |
247 | case ValueTel: value_ = new TelValue; break; | 253 | case ValueTel: value_ = new TelValue; break; |
248 | case ValueTextBin: value_ = new TextBinValue;break; | 254 | case ValueTextBin: value_ = new TextBinValue;break; |
249 | case ValueOrg: value_ = new OrgValue; break; | 255 | case ValueOrg: value_ = new OrgValue; break; |
250 | case ValueN: value_ = new NValue; break; | 256 | case ValueN: value_ = new NValue; break; |
251 | case ValueUTC: value_ = new UTCValue; break; | 257 | case ValueUTC: value_ = new UTCValue; break; |
252 | case ValueURI: value_ = new URIValue; break; | 258 | case ValueURI: value_ = new URIValue; break; |
253 | case ValueClass: value_ = new ClassValue;break; | 259 | case ValueClass: value_ = new ClassValue;break; |
254 | case ValueFloat: value_ = new FloatValue;break; | 260 | case ValueFloat: value_ = new FloatValue;break; |
255 | case ValueImage: value_ = new ImageValue;break; | 261 | case ValueImage: value_ = new ImageValue;break; |
256 | case ValueDate: value_ = new DateValue; break; | 262 | case ValueDate: value_ = new DateValue; break; |
257 | case ValueTextList: value_ = new TextListValue;break; | 263 | case ValueTextList: value_ = new TextListValue;break; |
258 | case ValueGeo: value_ = new GeoValue; break; | 264 | case ValueGeo: value_ = new GeoValue; break; |
259 | case ValueText: | 265 | case ValueText: |
260 | case ValueUnknown: | 266 | case ValueUnknown: |
261 | default: value_ = new TextValue; break; | 267 | default: value_ = new TextValue; break; |
262 | } | 268 | } |
263 | 269 | ||
264 | *value_ = valuePart; | 270 | *value_ = valuePart; |
265 | } | 271 | } |
266 | 272 | ||
267 | void | 273 | void |
268 | ContentLine::_assemble() | 274 | ContentLine::_assemble() |
269 | { | 275 | { |
270 | vDebug("Assemble (argl) - my name is \"" + name_ + "\""); | 276 | vDebug("Assemble (argl) - my name is \"" + name_ + "\""); |
271 | strRep_.truncate(0); | 277 | strRep_.truncate(0); |
272 | 278 | ||
273 | QCString line; | 279 | QCString line; |
274 | 280 | ||
275 | if (!group_.isEmpty()) | 281 | if (!group_.isEmpty()) |
276 | line += group_ + '.'; | 282 | line += group_ + '.'; |
277 | 283 | ||
278 | line += name_; | 284 | line += name_; |
279 | 285 | ||
280 | vDebug("Adding parameters"); | 286 | vDebug("Adding parameters"); |
281 | ParamListIterator it(paramList_); | 287 | ParamListIterator it(paramList_); |
282 | 288 | ||
283 | for (; it.current(); ++it) | 289 | for (; it.current(); ++it) |
284 | line += ";" + it.current()->asString(); | 290 | line += ";" + it.current()->asString(); |
285 | 291 | ||
286 | vDebug("Adding value"); | 292 | vDebug("Adding value"); |
287 | if (value_ != 0) | 293 | if (value_ != 0) |
288 | line += ":" + value_->asString(); | 294 | line += ":" + value_->asString(); |
289 | else | 295 | else |
290 | vDebug("No value"); | 296 | vDebug("No value"); |
291 | 297 | ||
292 | // Quote newlines | 298 | // Quote newlines |
293 | line = line.replace( QRegExp( "\n" ), "\\n" ); | 299 | line = line.replace( QRegExp( "\n" ), "\\n" ); |
294 | 300 | ||
295 | // Fold lines longer than 72 chars | 301 | // Fold lines longer than 72 chars |
296 | const int maxLen = 72; | 302 | const int maxLen = 72; |
297 | uint cursor = 0; | 303 | uint cursor = 0; |
298 | while( line.length() > ( cursor + 1 ) * maxLen ) { | 304 | while( line.length() > ( cursor + 1 ) * maxLen ) { |
299 | strRep_ += line.mid( cursor * maxLen, maxLen ); | 305 | strRep_ += line.mid( cursor * maxLen, maxLen ); |
300 | strRep_ += "\r\n "; | 306 | strRep_ += "\r\n "; |
301 | ++cursor; | 307 | ++cursor; |
302 | } | 308 | } |
303 | strRep_ += line.mid( cursor * maxLen ); | 309 | strRep_ += line.mid( cursor * maxLen ); |
304 | } | 310 | } |
305 | 311 | ||
306 | void | 312 | void |
307 | ContentLine::clear() | 313 | ContentLine::clear() |
308 | { | 314 | { |
309 | group_.truncate(0); | 315 | group_.truncate(0); |
310 | name_.truncate(0); | 316 | name_.truncate(0); |
311 | paramList_.clear(); | 317 | paramList_.clear(); |
312 | delete value_; | 318 | delete value_; |
313 | value_ = 0; | 319 | value_ = 0; |
314 | } | 320 | } |
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp index 391a69e..d19a004 100644 --- a/kabc/vcard/VCardv.cpp +++ b/kabc/vcard/VCardv.cpp | |||
@@ -1,295 +1,299 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1998 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qcstring.h> | 24 | #include <qcstring.h> |
25 | #include <qstrlist.h> | 25 | #include <qstrlist.h> |
26 | 26 | ||
27 | #include <VCardEntity.h> | 27 | #include <VCardEntity.h> |
28 | #include <VCardVCard.h> | 28 | #include <VCardVCard.h> |
29 | #include <VCardContentLine.h> | 29 | #include <VCardContentLine.h> |
30 | #include <VCardRToken.h> | 30 | #include <VCardRToken.h> |
31 | 31 | ||
32 | #include <VCardDefines.h> | 32 | #include <VCardDefines.h> |
33 | 33 | ||
34 | using namespace VCARD; | 34 | using namespace VCARD; |
35 | 35 | ||
36 | VCard::VCard() | 36 | VCard::VCard() |
37 | :Entity() | 37 | :Entity() |
38 | { | 38 | { |
39 | contentLineList_.setAutoDelete( TRUE ); | 39 | contentLineList_.setAutoDelete( TRUE ); |
40 | } | 40 | } |
41 | 41 | ||
42 | VCard::VCard(const VCard & x) | 42 | VCard::VCard(const VCard & x) |
43 | :Entity(x), | 43 | :Entity(x), |
44 | group_(x.group_) | 44 | group_(x.group_) |
45 | { | 45 | { |
46 | contentLineList_.setAutoDelete( TRUE ); | 46 | contentLineList_.setAutoDelete( TRUE ); |
47 | 47 | ||
48 | QPtrListIterator<ContentLine> it(x.contentLineList_); | 48 | QPtrListIterator<ContentLine> it(x.contentLineList_); |
49 | for (; it.current(); ++it) { | 49 | for (; it.current(); ++it) { |
50 | ContentLine * c = new ContentLine(*it.current()); | 50 | ContentLine * c = new ContentLine(*it.current()); |
51 | contentLineList_.append(c); | 51 | contentLineList_.append(c); |
52 | } | 52 | } |
53 | 53 | ||
54 | } | 54 | } |
55 | 55 | ||
56 | VCard::VCard(const QCString & s) | 56 | VCard::VCard(const QCString & s) |
57 | :Entity(s) | 57 | :Entity(s) |
58 | { | 58 | { |
59 | contentLineList_.setAutoDelete( TRUE ); | 59 | contentLineList_.setAutoDelete( TRUE ); |
60 | } | 60 | } |
61 | 61 | ||
62 | VCard & | 62 | VCard & |
63 | VCard::operator = (VCard & x) | 63 | VCard::operator = (VCard & x) |
64 | { | 64 | { |
65 | if (*this == x) return *this; | 65 | if (*this == x) return *this; |
66 | 66 | ||
67 | group_ = x.group(); | 67 | group_ = x.group(); |
68 | QPtrListIterator<ContentLine> it(x.contentLineList_); | 68 | QPtrListIterator<ContentLine> it(x.contentLineList_); |
69 | for (; it.current(); ++it) { | 69 | for (; it.current(); ++it) { |
70 | ContentLine * c = new ContentLine(*it.current()); | 70 | ContentLine * c = new ContentLine(*it.current()); |
71 | contentLineList_.append(c); | 71 | contentLineList_.append(c); |
72 | } | 72 | } |
73 | 73 | ||
74 | Entity::operator = (x); | 74 | Entity::operator = (x); |
75 | return *this; | 75 | return *this; |
76 | } | 76 | } |
77 | 77 | ||
78 | VCard & | 78 | VCard & |
79 | VCard::operator = (const QCString & s) | 79 | VCard::operator = (const QCString & s) |
80 | { | 80 | { |
81 | Entity::operator = (s); | 81 | Entity::operator = (s); |
82 | return *this; | 82 | return *this; |
83 | } | 83 | } |
84 | 84 | ||
85 | bool | 85 | bool |
86 | VCard::operator == (VCard & x) | 86 | VCard::operator == (VCard & x) |
87 | { | 87 | { |
88 | x.parse(); | 88 | x.parse(); |
89 | return false; | 89 | return false; |
90 | } | 90 | } |
91 | 91 | ||
92 | VCard::~VCard() | 92 | VCard::~VCard() |
93 | { | 93 | { |
94 | } | 94 | } |
95 | 95 | ||
96 | void | 96 | void |
97 | VCard::_parse() | 97 | VCard::_parse() |
98 | { | 98 | { |
99 | vDebug("parse() called"); | 99 | vDebug("parse() called"); |
100 | QStrList l; | 100 | QStrList l; |
101 | 101 | ||
102 | RTokenise(strRep_, "\r\n", l); | 102 | RTokenise(strRep_, "\r\n", l); |
103 | 103 | ||
104 | if (l.count() < 3) { // Invalid VCARD ! | 104 | if (l.count() < 3) { // Invalid VCARD ! |
105 | vDebug("Invalid vcard"); | 105 | vDebug("Invalid vcard"); |
106 | return; | 106 | return; |
107 | } | 107 | } |
108 | 108 | ||
109 | // Get the first line | 109 | // Get the first line |
110 | QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); | 110 | QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); |
111 | 111 | ||
112 | vDebug("Begin line == \"" + beginLine + "\""); | 112 | vDebug("Begin line == \"" + beginLine + "\""); |
113 | 113 | ||
114 | // Remove extra blank lines | 114 | // Remove extra blank lines |
115 | while (QCString(l.last()).isEmpty()) | 115 | while (QCString(l.last()).isEmpty()) |
116 | l.remove(l.last()); | 116 | l.remove(l.last()); |
117 | 117 | ||
118 | // Now we know this is the last line | 118 | // Now we know this is the last line |
119 | QCString endLine = l.last(); | 119 | QCString endLine = l.last(); |
120 | 120 | ||
121 | // Trash the first and last lines as we have seen them. | 121 | // Trash the first and last lines as we have seen them. |
122 | l.remove(0u); | 122 | l.remove(0u); |
123 | l.remove(l.last()); | 123 | l.remove(l.last()); |
124 | 124 | ||
125 | /////////////////////////////////////////////////////////////// | 125 | /////////////////////////////////////////////////////////////// |
126 | // FIRST LINE | 126 | // FIRST LINE |
127 | 127 | ||
128 | int split = beginLine.find(':'); | 128 | int split = beginLine.find(':'); |
129 | 129 | ||
130 | if (split == -1) { // invalid, no BEGIN | 130 | if (split == -1) { // invalid, no BEGIN |
131 | vDebug("No split"); | 131 | vDebug("No split"); |
132 | return; | 132 | return; |
133 | } | 133 | } |
134 | 134 | ||
135 | QCString firstPart(beginLine.left(split)); | 135 | QCString firstPart(beginLine.left(split)); |
136 | QCString valuePart(beginLine.mid(split + 1)); | 136 | QCString valuePart(beginLine.mid(split + 1)); |
137 | 137 | ||
138 | split = firstPart.find('.'); | 138 | split = firstPart.find('.'); |
139 | 139 | ||
140 | if (split != -1) { | 140 | if (split != -1) { |
141 | group_ = firstPart.left(split); | 141 | group_ = firstPart.left(split); |
142 | firstPart= firstPart.right(firstPart.length() - split - 1); | 142 | firstPart= firstPart.right(firstPart.length() - split - 1); |
143 | } | 143 | } |
144 | 144 | ||
145 | if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! | 145 | if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! |
146 | vDebug("No BEGIN"); | 146 | vDebug("No BEGIN"); |
147 | return; | 147 | return; |
148 | } | 148 | } |
149 | 149 | ||
150 | if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! | 150 | if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! |
151 | vDebug("No VCARD"); | 151 | vDebug("No VCARD"); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | 154 | ||
155 | /////////////////////////////////////////////////////////////// | 155 | /////////////////////////////////////////////////////////////// |
156 | // CONTENT LINES | 156 | // CONTENT LINES |
157 | // | 157 | // |
158 | vDebug("Content lines"); | 158 | vDebug("Content lines"); |
159 | 159 | ||
160 | // Handle folded lines. | 160 | // Handle folded lines. |
161 | 161 | ||
162 | QStrList refolded; | 162 | QStrList refolded; |
163 | 163 | ||
164 | QStrListIterator it(l); | 164 | QStrListIterator it(l); |
165 | 165 | ||
166 | QCString cur; | 166 | QCString cur; |
167 | 167 | ||
168 | for (; it.current(); ++it) { | 168 | for (; it.current(); ++it) { |
169 | 169 | ||
170 | cur = it.current(); | 170 | cur = it.current(); |
171 | 171 | ||
172 | ++it; | 172 | ++it; |
173 | 173 | ||
174 | while ( | 174 | while ( |
175 | it.current() && | 175 | it.current() && |
176 | it.current()[0] == ' '&& | 176 | it.current()[0] == ' '&& |
177 | strlen(it.current()) != 1) | 177 | strlen(it.current()) != 1) |
178 | { | 178 | { |
179 | cur += it.current() + 1; | 179 | cur += it.current() + 1; |
180 | ++it; | 180 | ++it; |
181 | } | 181 | } |
182 | 182 | ||
183 | --it; | 183 | --it; |
184 | 184 | ||
185 | refolded.append(cur); | 185 | refolded.append(cur); |
186 | } | 186 | } |
187 | 187 | ||
188 | QStrListIterator it2(refolded); | 188 | QStrListIterator it2(refolded); |
189 | 189 | ||
190 | for (; it2.current(); ++it2) { | 190 | for (; it2.current(); ++it2) { |
191 | 191 | vDebug("New contentline using \"" + QCString(it2.current()) + "\""); | |
192 | vDebug("New contentline using \"" + QCString(it2.current()) + "\""); | ||
193 | ContentLine * cl = new ContentLine(it2.current()); | 192 | ContentLine * cl = new ContentLine(it2.current()); |
194 | 193 | ||
195 | cl->parse(); | 194 | cl->parse(); |
196 | 195 | if (cl->value() == 0) | |
197 | contentLineList_.append(cl); | 196 | { |
197 | qDebug("Content line could not be parsed. Discarded: %s" + QCString(it2.current())); | ||
198 | delete cl; | ||
199 | } | ||
200 | else | ||
201 | contentLineList_.append(cl); | ||
198 | } | 202 | } |
199 | 203 | ||
200 | /////////////////////////////////////////////////////////////// | 204 | /////////////////////////////////////////////////////////////// |
201 | // LAST LINE | 205 | // LAST LINE |
202 | 206 | ||
203 | split = endLine.find(':'); | 207 | split = endLine.find(':'); |
204 | 208 | ||
205 | if (split == -1) // invalid, no END | 209 | if (split == -1) // invalid, no END |
206 | return; | 210 | return; |
207 | 211 | ||
208 | firstPart = endLine.left(split); | 212 | firstPart = endLine.left(split); |
209 | valuePart = endLine.right(firstPart.length() - split - 1); | 213 | valuePart = endLine.right(firstPart.length() - split - 1); |
210 | 214 | ||
211 | split = firstPart.find('.'); | 215 | split = firstPart.find('.'); |
212 | 216 | ||
213 | if (split != -1) { | 217 | if (split != -1) { |
214 | group_ = firstPart.left(split); | 218 | group_ = firstPart.left(split); |
215 | firstPart= firstPart.right(firstPart.length() - split - 1); | 219 | firstPart= firstPart.right(firstPart.length() - split - 1); |
216 | } | 220 | } |
217 | 221 | ||
218 | if (qstricmp(firstPart, "END") != 0) // No END ! | 222 | if (qstricmp(firstPart, "END") != 0) // No END ! |
219 | return; | 223 | return; |
220 | 224 | ||
221 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! | 225 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! |
222 | return; | 226 | return; |
223 | } | 227 | } |
224 | 228 | ||
225 | void | 229 | void |
226 | VCard::_assemble() | 230 | VCard::_assemble() |
227 | { | 231 | { |
228 | vDebug("Assembling vcard"); | 232 | vDebug("Assembling vcard"); |
229 | strRep_ = "BEGIN:VCARD\r\n"; | 233 | strRep_ = "BEGIN:VCARD\r\n"; |
230 | strRep_ += "VERSION:3.0\r\n"; | 234 | strRep_ += "VERSION:3.0\r\n"; |
231 | 235 | ||
232 | QPtrListIterator<ContentLine> it(contentLineList_); | 236 | QPtrListIterator<ContentLine> it(contentLineList_); |
233 | 237 | ||
234 | for (; it.current(); ++it) | 238 | for (; it.current(); ++it) |
235 | strRep_ += it.current()->asString() + "\r\n"; | 239 | strRep_ += it.current()->asString() + "\r\n"; |
236 | 240 | ||
237 | strRep_ += "END:VCARD\r\n"; | 241 | strRep_ += "END:VCARD\r\n"; |
238 | } | 242 | } |
239 | 243 | ||
240 | bool | 244 | bool |
241 | VCard::has(EntityType t) | 245 | VCard::has(EntityType t) |
242 | { | 246 | { |
243 | parse(); | 247 | parse(); |
244 | return contentLine(t) == 0 ? false : true; | 248 | return contentLine(t) == 0 ? false : true; |
245 | } | 249 | } |
246 | 250 | ||
247 | bool | 251 | bool |
248 | VCard::has(const QCString & s) | 252 | VCard::has(const QCString & s) |
249 | { | 253 | { |
250 | parse(); | 254 | parse(); |
251 | return contentLine(s) == 0 ? false : true; | 255 | return contentLine(s) == 0 ? false : true; |
252 | } | 256 | } |
253 | 257 | ||
254 | void | 258 | void |
255 | VCard::add(const ContentLine & cl) | 259 | VCard::add(const ContentLine & cl) |
256 | { | 260 | { |
257 | parse(); | 261 | parse(); |
258 | ContentLine * c = new ContentLine(cl); | 262 | ContentLine * c = new ContentLine(cl); |
259 | contentLineList_.append(c); | 263 | contentLineList_.append(c); |
260 | } | 264 | } |
261 | 265 | ||
262 | void | 266 | void |
263 | VCard::add(const QCString & s) | 267 | VCard::add(const QCString & s) |
264 | { | 268 | { |
265 | parse(); | 269 | parse(); |
266 | ContentLine * c = new ContentLine(s); | 270 | ContentLine * c = new ContentLine(s); |
267 | contentLineList_.append(c); | 271 | contentLineList_.append(c); |
268 | } | 272 | } |
269 | 273 | ||
270 | ContentLine * | 274 | ContentLine * |
271 | VCard::contentLine(EntityType t) | 275 | VCard::contentLine(EntityType t) |
272 | { | 276 | { |
273 | parse(); | 277 | parse(); |
274 | QPtrListIterator<ContentLine> it(contentLineList_); | 278 | QPtrListIterator<ContentLine> it(contentLineList_); |
275 | 279 | ||
276 | for (; it.current(); ++it) | 280 | for (; it.current(); ++it) |
277 | if (it.current()->entityType() == t) | 281 | if (it.current()->entityType() == t) |
278 | return it.current(); | 282 | return it.current(); |
279 | 283 | ||
280 | return 0; | 284 | return 0; |
281 | } | 285 | } |
282 | 286 | ||
283 | ContentLine * | 287 | ContentLine * |
284 | VCard::contentLine(const QCString & s) | 288 | VCard::contentLine(const QCString & s) |
285 | { | 289 | { |
286 | parse(); | 290 | parse(); |
287 | QPtrListIterator<ContentLine> it(contentLineList_); | 291 | QPtrListIterator<ContentLine> it(contentLineList_); |
288 | 292 | ||
289 | for (; it.current(); ++it) | 293 | for (; it.current(); ++it) |
290 | if (it.current()->entityType() == EntityNameToEntityType(s)) | 294 | if (it.current()->entityType() == EntityNameToEntityType(s)) |
291 | return it.current(); | 295 | return it.current(); |
292 | 296 | ||
293 | return 0; | 297 | return 0; |
294 | } | 298 | } |
295 | 299 | ||
diff --git a/kabc/vcard/include/VCardDefines.h b/kabc/vcard/include/VCardDefines.h index dd38ae2..557410f 100644 --- a/kabc/vcard/include/VCardDefines.h +++ b/kabc/vcard/include/VCardDefines.h | |||
@@ -1,52 +1,53 @@ | |||
1 | /* | 1 | /* |
2 | libvcard - vCard parsing library for vCard version 3.0 | 2 | libvcard - vCard parsing library for vCard version 3.0 |
3 | 3 | ||
4 | Copyright (C) 1998 Rik Hemsley rik@kde.org | 4 | Copyright (C) 1998 Rik Hemsley rik@kde.org |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | of this software and associated documentation files (the "Software"), to | 7 | of this software and associated documentation files (the "Software"), to |
8 | deal in the Software without restriction, including without limitation the | 8 | deal in the Software without restriction, including without limitation the |
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | sell copies of the Software, and to permit persons to whom the Software is | 10 | sell copies of the Software, and to permit persons to whom the Software is |
11 | furnished to do so, subject to the following conditions: | 11 | furnished to do so, subject to the following conditions: |
12 | 12 | ||
13 | The above copyright notice and this permission notice shall be included in | 13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. | 14 | all copies or substantial portions of the Software. |
15 | 15 | ||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef VCARD_DEFINES_H | 24 | #ifndef VCARD_DEFINES_H |
25 | #define VCARD_DEFINES_H | 25 | #define VCARD_DEFINES_H |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | 28 | ||
29 | #ifdef VCARD_DEBUG | 29 | #ifdef VCARD_DEBUG |
30 | #define vDebug(a) kdDebug(5710) << a << endl; | 30 | //US #define vDebug(a) kdDebug(5710) << a << endl; |
31 | #define vDebug(a) qDebug(a); | ||
31 | #else | 32 | #else |
32 | #define vDebug(a) | 33 | #define vDebug(a) |
33 | #endif | 34 | #endif |
34 | 35 | ||
35 | #if 0 | 36 | #if 0 |
36 | #ifndef NDEBUG | 37 | #ifndef NDEBUG |
37 | #include <qcstring.h> | 38 | #include <qcstring.h> |
38 | #include <iostream> | 39 | #include <iostream> |
39 | #ifdef __GNUG__ | 40 | #ifdef __GNUG__ |
40 | # define vDebug(a) cerr << className() << ":" << __FUNCTION__ << " (" \ | 41 | # define vDebug(a) cerr << className() << ":" << __FUNCTION__ << " (" \ |
41 | << __LINE__ << "): " << QCString((a)).data() << endl; | 42 | << __LINE__ << "): " << QCString((a)).data() << endl; |
42 | #else | 43 | #else |
43 | # define vDebug(a) cerr << className() << ": " \ | 44 | # define vDebug(a) cerr << className() << ": " \ |
44 | << QCString((a)).data() << endl; | 45 | << QCString((a)).data() << endl; |
45 | #endif | 46 | #endif |
46 | #else | 47 | #else |
47 | #define vDebug(a) | 48 | #define vDebug(a) |
48 | #endif | 49 | #endif |
49 | #endif | 50 | #endif |
50 | 51 | ||
51 | #endif // Included this file | 52 | #endif // Included this file |
52 | 53 | ||
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index 2d6eb3d..1bf2cde 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp | |||
@@ -1,1025 +1,1027 @@ | |||
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 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <qfile.h> | 28 | #include <qfile.h> |
29 | #include <qregexp.h> | 29 | #include <qregexp.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <kmdcodec.h> | 32 | #include <kmdcodec.h> |
33 | #include <kstandarddirs.h> | 33 | #include <kstandarddirs.h> |
34 | #include <ktempfile.h> | 34 | #include <ktempfile.h> |
35 | 35 | ||
36 | #include <VCard.h> | 36 | #include <VCard.h> |
37 | 37 | ||
38 | #include "addressbook.h" | 38 | #include "addressbook.h" |
39 | #include "vcardformatimpl.h" | 39 | #include "vcardformatimpl.h" |
40 | 40 | ||
41 | using namespace KABC; | 41 | using namespace KABC; |
42 | using namespace VCARD; | 42 | using namespace VCARD; |
43 | 43 | ||
44 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) | 44 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) |
45 | { | 45 | { |
46 | kdDebug(5700) << "VCardFormat::load()" << endl; | 46 | kdDebug(5700) << "VCardFormat::load()" << endl; |
47 | 47 | ||
48 | QByteArray fdata = file->readAll(); | 48 | QByteArray fdata = file->readAll(); |
49 | QCString data(fdata.data(), fdata.size()+1); | 49 | QCString data(fdata.data(), fdata.size()+1); |
50 | 50 | ||
51 | VCardEntity e( data ); | 51 | VCardEntity e( data ); |
52 | 52 | ||
53 | VCardListIterator it( e.cardList() ); | 53 | VCardListIterator it( e.cardList() ); |
54 | 54 | ||
55 | if ( it.current() ) { | 55 | if ( it.current() ) { |
56 | //US VCard v(*it.current()); | 56 | //US VCard v(*it.current()); |
57 | //US loadAddressee( addressee, v ); | 57 | //US loadAddressee( addressee, v ); |
58 | loadAddressee( addressee, it.current() ); | 58 | loadAddressee( addressee, it.current() ); |
59 | return true; | 59 | return true; |
60 | } | 60 | } |
61 | 61 | ||
62 | return false; | 62 | return false; |
63 | } | 63 | } |
64 | 64 | ||
65 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) | 65 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) |
66 | { | 66 | { |
67 | kdDebug(5700) << "VCardFormat::loadAll()" << endl; | 67 | kdDebug(5700) << "VCardFormat::loadAll()" << endl; |
68 | 68 | ||
69 | QByteArray fdata = file->readAll(); | 69 | QByteArray fdata = file->readAll(); |
70 | QCString data(fdata.data(), fdata.size()+1); | 70 | QCString data(fdata.data(), fdata.size()+1); |
71 | 71 | ||
72 | VCardEntity e( data ); | 72 | VCardEntity e( data ); |
73 | 73 | ||
74 | VCardListIterator it( e.cardList() ); | 74 | VCardListIterator it( e.cardList() ); |
75 | 75 | ||
76 | for (; it.current(); ++it) { | 76 | for (; it.current(); ++it) { |
77 | //US VCard v(*it.current()); | 77 | //US VCard v(*it.current()); |
78 | Addressee addressee; | 78 | Addressee addressee; |
79 | //US loadAddressee( addressee, v ); | 79 | //US loadAddressee( addressee, v ); |
80 | loadAddressee( addressee, it.current() ); | 80 | loadAddressee( addressee, it.current() ); |
81 | addressee.setResource( resource ); | 81 | addressee.setResource( resource ); |
82 | addressBook->insertAddressee( addressee ); | 82 | addressBook->insertAddressee( addressee ); |
83 | } | 83 | } |
84 | 84 | ||
85 | return true; | 85 | return true; |
86 | } | 86 | } |
87 | 87 | ||
88 | void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) | 88 | void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) |
89 | { | 89 | { |
90 | VCardEntity vcards; | 90 | VCardEntity vcards; |
91 | VCardList vcardlist; | 91 | VCardList vcardlist; |
92 | vcardlist.setAutoDelete( true ); | 92 | vcardlist.setAutoDelete( true ); |
93 | 93 | ||
94 | VCard *v = new VCard; | 94 | VCard *v = new VCard; |
95 | 95 | ||
96 | saveAddressee( addressee, v, false ); | 96 | saveAddressee( addressee, v, false ); |
97 | 97 | ||
98 | vcardlist.append( v ); | 98 | vcardlist.append( v ); |
99 | vcards.setCardList( vcardlist ); | 99 | vcards.setCardList( vcardlist ); |
100 | 100 | ||
101 | QCString vcardData = vcards.asString(); | 101 | QCString vcardData = vcards.asString(); |
102 | file->writeBlock( (const char*)vcardData, vcardData.length() ); | 102 | file->writeBlock( (const char*)vcardData, vcardData.length() ); |
103 | } | 103 | } |
104 | 104 | ||
105 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) | 105 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) |
106 | { | 106 | { |
107 | VCardEntity vcards; | 107 | VCardEntity vcards; |
108 | VCardList vcardlist; | 108 | VCardList vcardlist; |
109 | vcardlist.setAutoDelete( true ); | 109 | vcardlist.setAutoDelete( true ); |
110 | 110 | ||
111 | AddressBook::Iterator it; | 111 | AddressBook::Iterator it; |
112 | for ( it = ab->begin(); it != ab->end(); ++it ) { | 112 | for ( it = ab->begin(); it != ab->end(); ++it ) { |
113 | if ( (*it).resource() == resource ) { | 113 | if ( (*it).resource() == resource ) { |
114 | VCard *v = new VCard; | 114 | VCard *v = new VCard; |
115 | saveAddressee( (*it), v, false ); | 115 | saveAddressee( (*it), v, false ); |
116 | (*it).setChanged( false ); | 116 | (*it).setChanged( false ); |
117 | vcardlist.append( v ); | 117 | vcardlist.append( v ); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | vcards.setCardList( vcardlist ); | 121 | vcards.setCardList( vcardlist ); |
122 | 122 | ||
123 | QCString vcardData = vcards.asString(); | 123 | QCString vcardData = vcards.asString(); |
124 | file->writeBlock( (const char*)vcardData, vcardData.length() ); | 124 | file->writeBlock( (const char*)vcardData, vcardData.length() ); |
125 | } | 125 | } |
126 | 126 | ||
127 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) | 127 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) |
128 | { | 128 | { |
129 | QPtrList<ContentLine> contentLines = v->contentLineList(); | 129 | QPtrList<ContentLine> contentLines = v->contentLineList(); |
130 | ContentLine *cl; | 130 | ContentLine *cl; |
131 | 131 | ||
132 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 132 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
133 | QCString n = cl->name(); | 133 | QCString n = cl->name(); |
134 | if ( n.left( 2 ) == "X-" ) { | 134 | if ( n.left( 2 ) == "X-" ) { |
135 | n = n.mid( 2 ); | 135 | n = n.mid( 2 ); |
136 | int posDash = n.find( "-" ); | 136 | int posDash = n.find( "-" ); |
137 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), | 137 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), |
138 | QString::fromUtf8( n.mid( posDash + 1 ) ), | 138 | QString::fromUtf8( n.mid( posDash + 1 ) ), |
139 | QString::fromUtf8( cl->value()->asString() ) ); | 139 | QString::fromUtf8( cl->value()->asString() ) ); |
140 | continue; | 140 | continue; |
141 | } | 141 | } |
142 | 142 | ||
143 | EntityType type = cl->entityType(); | 143 | EntityType type = cl->entityType(); |
144 | switch( type ) { | 144 | switch( type ) { |
145 | 145 | ||
146 | case EntityUID: | 146 | case EntityUID: |
147 | addressee.setUid( readTextValue( cl ) ); | 147 | addressee.setUid( readTextValue( cl ) ); |
148 | break; | 148 | break; |
149 | 149 | ||
150 | case EntityEmail: | 150 | case EntityEmail: |
151 | addressee.insertEmail( readTextValue( cl ) ); | 151 | addressee.insertEmail( readTextValue( cl ) ); |
152 | break; | 152 | break; |
153 | 153 | ||
154 | case EntityName: | 154 | case EntityName: |
155 | addressee.setName( readTextValue( cl ) ); | 155 | addressee.setName( readTextValue( cl ) ); |
156 | break; | 156 | break; |
157 | 157 | ||
158 | case EntityFullName: | 158 | case EntityFullName: |
159 | addressee.setFormattedName( readTextValue( cl ) ); | 159 | addressee.setFormattedName( readTextValue( cl ) ); |
160 | break; | 160 | break; |
161 | 161 | ||
162 | case EntityURL: | 162 | case EntityURL: |
163 | addressee.setUrl( KURL( readTextValue( cl ) ) ); | 163 | addressee.setUrl( KURL( readTextValue( cl ) ) ); |
164 | break; | 164 | break; |
165 | 165 | ||
166 | case EntityNickname: | 166 | case EntityNickname: |
167 | addressee.setNickName( readTextValue( cl ) ); | 167 | addressee.setNickName( readTextValue( cl ) ); |
168 | break; | 168 | break; |
169 | 169 | ||
170 | case EntityLabel: | 170 | case EntityLabel: |
171 | // not yet supported by kabc | 171 | // not yet supported by kabc |
172 | break; | 172 | break; |
173 | 173 | ||
174 | case EntityMailer: | 174 | case EntityMailer: |
175 | addressee.setMailer( readTextValue( cl ) ); | 175 | addressee.setMailer( readTextValue( cl ) ); |
176 | break; | 176 | break; |
177 | 177 | ||
178 | case EntityTitle: | 178 | case EntityTitle: |
179 | addressee.setTitle( readTextValue( cl ) ); | 179 | addressee.setTitle( readTextValue( cl ) ); |
180 | break; | 180 | break; |
181 | 181 | ||
182 | case EntityRole: | 182 | case EntityRole: |
183 | addressee.setRole( readTextValue( cl ) ); | 183 | addressee.setRole( readTextValue( cl ) ); |
184 | break; | 184 | break; |
185 | 185 | ||
186 | case EntityOrganisation: | 186 | case EntityOrganisation: |
187 | addressee.setOrganization( readTextValue( cl ) ); | 187 | addressee.setOrganization( readTextValue( cl ) ); |
188 | break; | 188 | break; |
189 | 189 | ||
190 | case EntityNote: | 190 | case EntityNote: |
191 | addressee.setNote( readTextValue( cl ) ); | 191 | addressee.setNote( readTextValue( cl ) ); |
192 | break; | 192 | break; |
193 | 193 | ||
194 | case EntityProductID: | 194 | case EntityProductID: |
195 | addressee.setProductId( readTextValue( cl ) ); | 195 | addressee.setProductId( readTextValue( cl ) ); |
196 | break; | 196 | break; |
197 | 197 | ||
198 | case EntitySortString: | 198 | case EntitySortString: |
199 | addressee.setSortString( readTextValue( cl ) ); | 199 | addressee.setSortString( readTextValue( cl ) ); |
200 | break; | 200 | break; |
201 | 201 | ||
202 | case EntityN: | 202 | case EntityN: |
203 | readNValue( cl, addressee ); | 203 | readNValue( cl, addressee ); |
204 | break; | 204 | break; |
205 | 205 | ||
206 | case EntityAddress: | 206 | case EntityAddress: |
207 | addressee.insertAddress( readAddressValue( cl ) ); | 207 | addressee.insertAddress( readAddressValue( cl ) ); |
208 | break; | 208 | break; |
209 | 209 | ||
210 | case EntityTelephone: | 210 | case EntityTelephone: |
211 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); | 211 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); |
212 | break; | 212 | break; |
213 | 213 | ||
214 | case EntityCategories: | 214 | case EntityCategories: |
215 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); | 215 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); |
216 | break; | 216 | break; |
217 | 217 | ||
218 | case EntityBirthday: | 218 | case EntityBirthday: |
219 | addressee.setBirthday( readDateValue( cl ) ); | 219 | addressee.setBirthday( readDateValue( cl ) ); |
220 | break; | 220 | break; |
221 | 221 | ||
222 | case EntityRevision: | 222 | case EntityRevision: |
223 | addressee.setRevision( readDateTimeValue( cl ) ); | 223 | addressee.setRevision( readDateTimeValue( cl ) ); |
224 | break; | 224 | break; |
225 | 225 | ||
226 | case EntityGeo: | 226 | case EntityGeo: |
227 | addressee.setGeo( readGeoValue( cl ) ); | 227 | addressee.setGeo( readGeoValue( cl ) ); |
228 | break; | 228 | break; |
229 | 229 | ||
230 | case EntityTimeZone: | 230 | case EntityTimeZone: |
231 | addressee.setTimeZone( readUTCValue( cl ) ); | 231 | addressee.setTimeZone( readUTCValue( cl ) ); |
232 | break; | 232 | break; |
233 | 233 | ||
234 | case EntityVersion: | 234 | case EntityVersion: |
235 | break; | 235 | break; |
236 | 236 | ||
237 | case EntityClass: | 237 | case EntityClass: |
238 | addressee.setSecrecy( readClassValue( cl ) ); | 238 | addressee.setSecrecy( readClassValue( cl ) ); |
239 | break; | 239 | break; |
240 | 240 | ||
241 | case EntityKey: | 241 | case EntityKey: |
242 | addressee.insertKey( readKeyValue( cl ) ); | 242 | addressee.insertKey( readKeyValue( cl ) ); |
243 | break; | 243 | break; |
244 | 244 | ||
245 | case EntityPhoto: | 245 | case EntityPhoto: |
246 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); | 246 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); |
247 | break; | 247 | break; |
248 | 248 | ||
249 | case EntityLogo: | 249 | case EntityLogo: |
250 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); | 250 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); |
251 | break; | 251 | break; |
252 | 252 | ||
253 | case EntityAgent: | 253 | case EntityAgent: |
254 | addressee.setAgent( readAgentValue( cl ) ); | 254 | addressee.setAgent( readAgentValue( cl ) ); |
255 | break; | 255 | break; |
256 | 256 | ||
257 | case EntitySound: | 257 | case EntitySound: |
258 | addressee.setSound( readSoundValue( cl, addressee ) ); | 258 | addressee.setSound( readSoundValue( cl, addressee ) ); |
259 | break; | 259 | break; |
260 | 260 | ||
261 | default: | 261 | default: |
262 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " | 262 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " |
263 | << int( type ) << ": " << cl->asString() << endl; | 263 | << int( type ) << ": " << cl->asString() << endl; |
264 | qDebug("VCardFormat::load(): Unsupported entity: %i: %s ", int(type), (const char*)cl->asString()); | ||
264 | break; | 265 | break; |
265 | } | 266 | } |
266 | } | 267 | } |
267 | 268 | ||
268 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 269 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
269 | EntityType type = cl->entityType(); | 270 | EntityType type = cl->entityType(); |
270 | if ( type == EntityLabel ) { | 271 | if ( type == EntityLabel ) { |
271 | int type = readAddressParam( cl ); | 272 | int type = readAddressParam( cl ); |
272 | Address address = addressee.address( type ); | 273 | Address address = addressee.address( type ); |
273 | if ( address.isEmpty() ) | 274 | if ( address.isEmpty() ) |
274 | address.setType( type ); | 275 | address.setType( type ); |
275 | 276 | ||
276 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); | 277 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); |
277 | addressee.insertAddress( address ); | 278 | addressee.insertAddress( address ); |
278 | } | 279 | } |
279 | } | 280 | } |
280 | 281 | ||
281 | return true; | 282 | return true; |
282 | } | 283 | } |
283 | 284 | ||
284 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) | 285 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) |
285 | { | 286 | { |
286 | //US ContentLine cl; | 287 | //US ContentLine cl; |
287 | //US QString value; | 288 | //US QString value; |
288 | 289 | ||
289 | addTextValue( v, EntityName, addressee.name() ); | 290 | addTextValue( v, EntityName, addressee.name() ); |
290 | addTextValue( v, EntityUID, addressee.uid() ); | 291 | addTextValue( v, EntityUID, addressee.uid() ); |
291 | addTextValue( v, EntityFullName, addressee.formattedName() ); | 292 | addTextValue( v, EntityFullName, addressee.formattedName() ); |
292 | 293 | ||
293 | QStringList emails = addressee.emails(); | 294 | QStringList emails = addressee.emails(); |
294 | QStringList::ConstIterator it4; | 295 | QStringList::ConstIterator it4; |
295 | for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { | 296 | for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { |
296 | addTextValue( v, EntityEmail, *it4 ); | 297 | addTextValue( v, EntityEmail, *it4 ); |
297 | } | 298 | } |
298 | 299 | ||
299 | QStringList customs = addressee.customs(); | 300 | QStringList customs = addressee.customs(); |
300 | QStringList::ConstIterator it5; | 301 | QStringList::ConstIterator it5; |
301 | for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { | 302 | for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { |
302 | addCustomValue( v, *it5 ); | 303 | addCustomValue( v, *it5 ); |
303 | } | 304 | } |
304 | 305 | ||
305 | addTextValue( v, EntityURL, addressee.url().url() ); | 306 | addTextValue( v, EntityURL, addressee.url().url() ); |
306 | 307 | ||
307 | addNValue( v, addressee ); | 308 | addNValue( v, addressee ); |
308 | 309 | ||
309 | addTextValue( v, EntityNickname, addressee.nickName() ); | 310 | addTextValue( v, EntityNickname, addressee.nickName() ); |
310 | addTextValue( v, EntityMailer, addressee.mailer() ); | 311 | addTextValue( v, EntityMailer, addressee.mailer() ); |
311 | addTextValue( v, EntityTitle, addressee.title() ); | 312 | addTextValue( v, EntityTitle, addressee.title() ); |
312 | addTextValue( v, EntityRole, addressee.role() ); | 313 | addTextValue( v, EntityRole, addressee.role() ); |
313 | addTextValue( v, EntityOrganisation, addressee.organization() ); | 314 | addTextValue( v, EntityOrganisation, addressee.organization() ); |
314 | addTextValue( v, EntityNote, addressee.note() ); | 315 | addTextValue( v, EntityNote, addressee.note() ); |
315 | addTextValue( v, EntityProductID, addressee.productId() ); | 316 | addTextValue( v, EntityProductID, addressee.productId() ); |
316 | addTextValue( v, EntitySortString, addressee.sortString() ); | 317 | addTextValue( v, EntitySortString, addressee.sortString() ); |
317 | 318 | ||
318 | Address::List addresses = addressee.addresses(); | 319 | Address::List addresses = addressee.addresses(); |
319 | Address::List::ConstIterator it3; | 320 | Address::List::ConstIterator it3; |
320 | for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { | 321 | for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { |
321 | addAddressValue( v, *it3 ); | 322 | addAddressValue( v, *it3 ); |
322 | addLabelValue( v, *it3 ); | 323 | addLabelValue( v, *it3 ); |
323 | } | 324 | } |
324 | 325 | ||
325 | PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); | 326 | PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); |
326 | PhoneNumber::List::ConstIterator it2; | 327 | PhoneNumber::List::ConstIterator it2; |
327 | for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { | 328 | for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { |
328 | addTelephoneValue( v, *it2 ); | 329 | addTelephoneValue( v, *it2 ); |
329 | } | 330 | } |
330 | 331 | ||
331 | Key::List keys = addressee.keys(); | 332 | Key::List keys = addressee.keys(); |
332 | Key::List::ConstIterator it6; | 333 | Key::List::ConstIterator it6; |
333 | for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { | 334 | for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { |
334 | addKeyValue( v, *it6 ); | 335 | addKeyValue( v, *it6 ); |
335 | } | 336 | } |
336 | 337 | ||
337 | addTextValue( v, EntityCategories, addressee.categories().join(",") ); | 338 | addTextValue( v, EntityCategories, addressee.categories().join(",") ); |
338 | 339 | ||
339 | addDateValue( v, EntityBirthday, addressee.birthday().date() ); | 340 | addDateValue( v, EntityBirthday, addressee.birthday().date() ); |
340 | addDateTimeValue( v, EntityRevision, addressee.revision() ); | 341 | addDateTimeValue( v, EntityRevision, addressee.revision() ); |
341 | addGeoValue( v, addressee.geo() ); | 342 | addGeoValue( v, addressee.geo() ); |
342 | addUTCValue( v, addressee.timeZone() ); | 343 | addUTCValue( v, addressee.timeZone() ); |
343 | 344 | ||
344 | addClassValue( v, addressee.secrecy() ); | 345 | addClassValue( v, addressee.secrecy() ); |
345 | 346 | ||
346 | addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); | 347 | addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); |
347 | addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); | 348 | addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); |
348 | 349 | ||
349 | addAgentValue( v, addressee.agent() ); | 350 | addAgentValue( v, addressee.agent() ); |
350 | 351 | ||
351 | addSoundValue( v, addressee.sound(), addressee, intern ); | 352 | addSoundValue( v, addressee.sound(), addressee, intern ); |
352 | } | 353 | } |
353 | 354 | ||
354 | void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) | 355 | void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) |
355 | { | 356 | { |
356 | if ( txt.isEmpty() ) return; | 357 | if ( txt.isEmpty() ) return; |
357 | 358 | ||
358 | ContentLine cl; | 359 | ContentLine cl; |
359 | cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); | 360 | cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); |
360 | QString value = txt.mid( txt.find( ":" ) + 1 ); | 361 | QString value = txt.mid( txt.find( ":" ) + 1 ); |
361 | if ( value.isEmpty() ) | 362 | if ( value.isEmpty() ) |
362 | return; | 363 | return; |
363 | cl.setValue( new TextValue( value.utf8() ) ); | 364 | cl.setValue( new TextValue( value.utf8() ) ); |
364 | v->add(cl); | 365 | v->add(cl); |
365 | } | 366 | } |
366 | 367 | ||
367 | void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) | 368 | void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) |
368 | { | 369 | { |
369 | if ( txt.isEmpty() ) return; | 370 | if ( txt.isEmpty() ) return; |
370 | 371 | ||
371 | ContentLine cl; | 372 | ContentLine cl; |
372 | cl.setName( EntityTypeToParamName( type ) ); | 373 | cl.setName( EntityTypeToParamName( type ) ); |
373 | cl.setValue( new TextValue( txt.utf8() ) ); | 374 | cl.setValue( new TextValue( txt.utf8() ) ); |
374 | v->add(cl); | 375 | v->add(cl); |
375 | } | 376 | } |
376 | 377 | ||
377 | void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, | 378 | void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, |
378 | const QDate &date ) | 379 | const QDate &date ) |
379 | { | 380 | { |
380 | if ( !date.isValid() ) return; | 381 | if ( !date.isValid() ) return; |
381 | 382 | ||
382 | ContentLine cl; | 383 | ContentLine cl; |
383 | cl.setName( EntityTypeToParamName( type ) ); | 384 | cl.setName( EntityTypeToParamName( type ) ); |
384 | 385 | ||
385 | DateValue *v = new DateValue( date ); | 386 | DateValue *v = new DateValue( date ); |
386 | cl.setValue( v ); | 387 | cl.setValue( v ); |
387 | vcard->add(cl); | 388 | vcard->add(cl); |
388 | } | 389 | } |
389 | 390 | ||
390 | void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, | 391 | void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, |
391 | const QDateTime &dateTime ) | 392 | const QDateTime &dateTime ) |
392 | { | 393 | { |
393 | if ( !dateTime.isValid() ) return; | 394 | if ( !dateTime.isValid() ) return; |
394 | 395 | ||
395 | ContentLine cl; | 396 | ContentLine cl; |
396 | cl.setName( EntityTypeToParamName( type ) ); | 397 | cl.setName( EntityTypeToParamName( type ) ); |
397 | 398 | ||
398 | DateValue *v = new DateValue( dateTime ); | 399 | DateValue *v = new DateValue( dateTime ); |
399 | cl.setValue( v ); | 400 | cl.setValue( v ); |
400 | vcard->add(cl); | 401 | vcard->add(cl); |
401 | } | 402 | } |
402 | 403 | ||
403 | void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) | 404 | void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) |
404 | { | 405 | { |
405 | if ( a.isEmpty() ) | 406 | if ( a.isEmpty() ) |
406 | return; | 407 | return; |
407 | 408 | ||
408 | ContentLine cl; | 409 | ContentLine cl; |
409 | cl.setName( EntityTypeToParamName( EntityAddress ) ); | 410 | cl.setName( EntityTypeToParamName( EntityAddress ) ); |
410 | 411 | ||
411 | AdrValue *v = new AdrValue; | 412 | AdrValue *v = new AdrValue; |
412 | v->setPOBox( a.postOfficeBox().utf8() ); | 413 | v->setPOBox( a.postOfficeBox().utf8() ); |
413 | v->setExtAddress( a.extended().utf8() ); | 414 | v->setExtAddress( a.extended().utf8() ); |
414 | v->setStreet( a.street().utf8() ); | 415 | v->setStreet( a.street().utf8() ); |
415 | v->setLocality( a.locality().utf8() ); | 416 | v->setLocality( a.locality().utf8() ); |
416 | v->setRegion( a.region().utf8() ); | 417 | v->setRegion( a.region().utf8() ); |
417 | v->setPostCode( a.postalCode().utf8() ); | 418 | v->setPostCode( a.postalCode().utf8() ); |
418 | v->setCountryName( a.country().utf8() ); | 419 | v->setCountryName( a.country().utf8() ); |
419 | cl.setValue( v ); | 420 | cl.setValue( v ); |
420 | 421 | ||
421 | addAddressParam( &cl, a.type() ); | 422 | addAddressParam( &cl, a.type() ); |
422 | 423 | ||
423 | vcard->add( cl ); | 424 | vcard->add( cl ); |
424 | } | 425 | } |
425 | 426 | ||
426 | void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) | 427 | void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) |
427 | { | 428 | { |
428 | if ( a.label().isEmpty() ) return; | 429 | if ( a.label().isEmpty() ) return; |
429 | 430 | ||
430 | ContentLine cl; | 431 | ContentLine cl; |
431 | cl.setName( EntityTypeToParamName( EntityLabel ) ); | 432 | cl.setName( EntityTypeToParamName( EntityLabel ) ); |
432 | cl.setValue( new TextValue( a.label().utf8() ) ); | 433 | cl.setValue( new TextValue( a.label().utf8() ) ); |
433 | 434 | ||
434 | addAddressParam( &cl, a.type() ); | 435 | addAddressParam( &cl, a.type() ); |
435 | 436 | ||
436 | vcard->add( cl ); | 437 | vcard->add( cl ); |
437 | } | 438 | } |
438 | 439 | ||
439 | void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) | 440 | void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) |
440 | { | 441 | { |
441 | ParamList params; | 442 | ParamList params; |
442 | if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); | 443 | if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); |
443 | if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); | 444 | if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); |
444 | if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); | 445 | if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); |
445 | if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); | 446 | if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); |
446 | if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); | 447 | if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); |
447 | if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); | 448 | if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); |
448 | if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); | 449 | if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); |
449 | cl->setParamList( params ); | 450 | cl->setParamList( params ); |
450 | } | 451 | } |
451 | 452 | ||
452 | void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) | 453 | void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) |
453 | { | 454 | { |
454 | if ( !geo.isValid() ) return; | 455 | if ( !geo.isValid() ) return; |
455 | 456 | ||
456 | ContentLine cl; | 457 | ContentLine cl; |
457 | cl.setName( EntityTypeToParamName( EntityGeo ) ); | 458 | cl.setName( EntityTypeToParamName( EntityGeo ) ); |
458 | 459 | ||
459 | GeoValue *v = new GeoValue; | 460 | GeoValue *v = new GeoValue; |
460 | v->setLatitude( geo.latitude() ); | 461 | v->setLatitude( geo.latitude() ); |
461 | v->setLongitude( geo.longitude() ); | 462 | v->setLongitude( geo.longitude() ); |
462 | 463 | ||
463 | cl.setValue( v ); | 464 | cl.setValue( v ); |
464 | vcard->add(cl); | 465 | vcard->add(cl); |
465 | } | 466 | } |
466 | 467 | ||
467 | void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) | 468 | void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) |
468 | { | 469 | { |
469 | if ( !tz.isValid() ) return; | 470 | if ( !tz.isValid() ) return; |
470 | 471 | ||
471 | ContentLine cl; | 472 | ContentLine cl; |
472 | cl.setName( EntityTypeToParamName( EntityTimeZone ) ); | 473 | cl.setName( EntityTypeToParamName( EntityTimeZone ) ); |
473 | 474 | ||
474 | UTCValue *v = new UTCValue; | 475 | UTCValue *v = new UTCValue; |
475 | 476 | ||
476 | v->setPositive( tz.offset() >= 0 ); | 477 | v->setPositive( tz.offset() >= 0 ); |
477 | v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); | 478 | v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); |
478 | v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); | 479 | v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); |
479 | 480 | ||
480 | cl.setValue( v ); | 481 | cl.setValue( v ); |
481 | vcard->add(cl); | 482 | vcard->add(cl); |
482 | } | 483 | } |
483 | 484 | ||
484 | void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) | 485 | void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) |
485 | { | 486 | { |
486 | ContentLine cl; | 487 | ContentLine cl; |
487 | cl.setName( EntityTypeToParamName( EntityClass ) ); | 488 | cl.setName( EntityTypeToParamName( EntityClass ) ); |
488 | 489 | ||
489 | ClassValue *v = new ClassValue; | 490 | ClassValue *v = new ClassValue; |
490 | switch ( secrecy.type() ) { | 491 | switch ( secrecy.type() ) { |
491 | case Secrecy::Public: | 492 | case Secrecy::Public: |
492 | v->setType( (int)ClassValue::Public ); | 493 | v->setType( (int)ClassValue::Public ); |
493 | break; | 494 | break; |
494 | case Secrecy::Private: | 495 | case Secrecy::Private: |
495 | v->setType( (int)ClassValue::Private ); | 496 | v->setType( (int)ClassValue::Private ); |
496 | break; | 497 | break; |
497 | case Secrecy::Confidential: | 498 | case Secrecy::Confidential: |
498 | v->setType( (int)ClassValue::Confidential ); | 499 | v->setType( (int)ClassValue::Confidential ); |
499 | break; | 500 | break; |
500 | } | 501 | } |
501 | 502 | ||
502 | cl.setValue( v ); | 503 | cl.setValue( v ); |
503 | vcard->add(cl); | 504 | vcard->add(cl); |
504 | } | 505 | } |
505 | 506 | ||
506 | 507 | ||
507 | Address VCardFormatImpl::readAddressValue( ContentLine *cl ) | 508 | Address VCardFormatImpl::readAddressValue( ContentLine *cl ) |
508 | { | 509 | { |
509 | Address a; | 510 | Address a; |
510 | AdrValue *v = (AdrValue *)cl->value(); | 511 | AdrValue *v = (AdrValue *)cl->value(); |
511 | a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); | 512 | a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); |
512 | a.setExtended( QString::fromUtf8( v->extAddress() ) ); | 513 | a.setExtended( QString::fromUtf8( v->extAddress() ) ); |
513 | a.setStreet( QString::fromUtf8( v->street() ) ); | 514 | a.setStreet( QString::fromUtf8( v->street() ) ); |
514 | a.setLocality( QString::fromUtf8( v->locality() ) ); | 515 | a.setLocality( QString::fromUtf8( v->locality() ) ); |
515 | a.setRegion( QString::fromUtf8( v->region() ) ); | 516 | a.setRegion( QString::fromUtf8( v->region() ) ); |
516 | a.setPostalCode( QString::fromUtf8( v->postCode() ) ); | 517 | a.setPostalCode( QString::fromUtf8( v->postCode() ) ); |
517 | a.setCountry( QString::fromUtf8( v->countryName() ) ); | 518 | a.setCountry( QString::fromUtf8( v->countryName() ) ); |
518 | 519 | ||
519 | a.setType( readAddressParam( cl ) ); | 520 | a.setType( readAddressParam( cl ) ); |
520 | 521 | ||
521 | return a; | 522 | return a; |
522 | } | 523 | } |
523 | 524 | ||
524 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) | 525 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) |
525 | { | 526 | { |
526 | int type = 0; | 527 | int type = 0; |
527 | ParamList params = cl->paramList(); | 528 | ParamList params = cl->paramList(); |
528 | ParamListIterator it( params ); | 529 | ParamListIterator it( params ); |
529 | QCString tmpStr; | 530 | QCString tmpStr; |
530 | for( ; it.current(); ++it ) { | 531 | for( ; it.current(); ++it ) { |
531 | if ( (*it)->name().upper() == "TYPE" ) { | 532 | if ( (*it)->name().upper() == "TYPE" ) { |
532 | tmpStr = (*it)->value().lower(); | 533 | tmpStr = (*it)->value().lower(); |
533 | if ( tmpStr == "dom" ) type |= Address::Dom; | 534 | if ( tmpStr == "dom" ) type |= Address::Dom; |
534 | else if ( tmpStr == "intl" ) type |= Address::Intl; | 535 | else if ( tmpStr == "intl" ) type |= Address::Intl; |
535 | else if ( tmpStr == "parcel" ) type |= Address::Parcel; | 536 | else if ( tmpStr == "parcel" ) type |= Address::Parcel; |
536 | else if ( tmpStr == "postal" ) type |= Address::Postal; | 537 | else if ( tmpStr == "postal" ) type |= Address::Postal; |
537 | else if ( tmpStr == "work" ) type |= Address::Work; | 538 | else if ( tmpStr == "work" ) type |= Address::Work; |
538 | else if ( tmpStr == "home" ) type |= Address::Home; | 539 | else if ( tmpStr == "home" ) type |= Address::Home; |
539 | else if ( tmpStr == "pref" ) type |= Address::Pref; | 540 | else if ( tmpStr == "pref" ) type |= Address::Pref; |
540 | } | 541 | } |
541 | } | 542 | } |
542 | return type; | 543 | return type; |
543 | } | 544 | } |
544 | 545 | ||
545 | void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) | 546 | void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) |
546 | { | 547 | { |
547 | ContentLine cl; | 548 | ContentLine cl; |
548 | cl.setName(EntityTypeToParamName( EntityN ) ); | 549 | cl.setName(EntityTypeToParamName( EntityN ) ); |
549 | NValue *v = new NValue; | 550 | NValue *v = new NValue; |
550 | v->setFamily( a.familyName().utf8() ); | 551 | v->setFamily( a.familyName().utf8() ); |
551 | v->setGiven( a.givenName().utf8() ); | 552 | v->setGiven( a.givenName().utf8() ); |
552 | v->setMiddle( a.additionalName().utf8() ); | 553 | v->setMiddle( a.additionalName().utf8() ); |
553 | v->setPrefix( a.prefix().utf8() ); | 554 | v->setPrefix( a.prefix().utf8() ); |
554 | v->setSuffix( a.suffix().utf8() ); | 555 | v->setSuffix( a.suffix().utf8() ); |
555 | 556 | ||
556 | cl.setValue( v ); | 557 | cl.setValue( v ); |
557 | vcard->add(cl); | 558 | vcard->add(cl); |
558 | } | 559 | } |
559 | 560 | ||
560 | void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) | 561 | void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) |
561 | { | 562 | { |
562 | NValue *v = (NValue *)cl->value(); | 563 | NValue *v = (NValue *)cl->value(); |
563 | a.setFamilyName( QString::fromUtf8( v->family() ) ); | 564 | a.setFamilyName( QString::fromUtf8( v->family() ) ); |
564 | a.setGivenName( QString::fromUtf8( v->given() ) ); | 565 | a.setGivenName( QString::fromUtf8( v->given() ) ); |
565 | a.setAdditionalName( QString::fromUtf8( v->middle() ) ); | 566 | a.setAdditionalName( QString::fromUtf8( v->middle() ) ); |
566 | a.setPrefix( QString::fromUtf8( v->prefix() ) ); | 567 | a.setPrefix( QString::fromUtf8( v->prefix() ) ); |
567 | a.setSuffix( QString::fromUtf8( v->suffix() ) ); | 568 | a.setSuffix( QString::fromUtf8( v->suffix() ) ); |
568 | } | 569 | } |
569 | 570 | ||
570 | void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) | 571 | void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) |
571 | { | 572 | { |
572 | if ( p.number().isEmpty() ) | 573 | if ( p.number().isEmpty() ) |
573 | return; | 574 | return; |
574 | 575 | ||
575 | ContentLine cl; | 576 | ContentLine cl; |
576 | cl.setName(EntityTypeToParamName(EntityTelephone)); | 577 | cl.setName(EntityTypeToParamName(EntityTelephone)); |
577 | cl.setValue(new TelValue( p.number().utf8() )); | 578 | cl.setValue(new TelValue( p.number().utf8() )); |
578 | 579 | ||
579 | ParamList params; | 580 | ParamList params; |
580 | if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); | 581 | if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); |
581 | if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); | 582 | if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); |
582 | if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); | 583 | if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); |
583 | if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); | 584 | if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); |
584 | if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); | 585 | if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); |
585 | if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); | 586 | if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); |
586 | if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); | 587 | if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); |
587 | if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); | 588 | if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); |
588 | if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); | 589 | if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); |
589 | if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); | 590 | if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); |
590 | if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); | 591 | if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); |
591 | if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); | 592 | if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); |
592 | if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); | 593 | if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); |
593 | if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); | 594 | if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); |
594 | if( p.type() & PhoneNumber::Sip ) params.append( new Param( "TYPE", "sip" ) ); | 595 | if( p.type() & PhoneNumber::Sip ) params.append( new Param( "TYPE", "sip" ) ); |
595 | cl.setParamList( params ); | 596 | cl.setParamList( params ); |
596 | 597 | ||
597 | v->add(cl); | 598 | v->add(cl); |
598 | } | 599 | } |
599 | 600 | ||
600 | PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) | 601 | PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) |
601 | { | 602 | { |
602 | PhoneNumber p; | 603 | PhoneNumber p; |
603 | TelValue *value = (TelValue *)cl->value(); | 604 | TelValue *value = (TelValue *)cl->value(); |
604 | p.setNumber( QString::fromUtf8( value->asString() ) ); | 605 | p.setNumber( QString::fromUtf8( value->asString() ) ); |
605 | 606 | ||
606 | int type = 0; | 607 | int type = 0; |
607 | ParamList params = cl->paramList(); | 608 | ParamList params = cl->paramList(); |
608 | ParamListIterator it( params ); | 609 | ParamListIterator it( params ); |
609 | QCString tmpStr; | 610 | QCString tmpStr; |
610 | for( ; it.current(); ++it ) { | 611 | for( ; it.current(); ++it ) { |
611 | if ( (*it)->name() == "TYPE" ) { | 612 | if ( (*it)->name() == "TYPE" ) { |
612 | tmpStr = (*it)->value().lower(); | 613 | tmpStr = (*it)->value().lower(); |
613 | if ( tmpStr == "home" ) type |= PhoneNumber::Home; | 614 | if ( tmpStr == "home" ) type |= PhoneNumber::Home; |
614 | else if ( tmpStr == "work" ) type |= PhoneNumber::Work; | 615 | else if ( tmpStr == "work" ) type |= PhoneNumber::Work; |
615 | else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; | 616 | else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; |
616 | else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; | 617 | else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; |
617 | else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; | 618 | else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; |
618 | else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; | 619 | else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; |
619 | else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; | 620 | else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; |
620 | else if ( tmpStr == "video" ) type |= PhoneNumber::Video; | 621 | else if ( tmpStr == "video" ) type |= PhoneNumber::Video; |
621 | else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; | 622 | else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; |
622 | else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; | 623 | else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; |
623 | else if ( tmpStr == "car" ) type |= PhoneNumber::Car; | 624 | else if ( tmpStr == "car" ) type |= PhoneNumber::Car; |
624 | else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; | 625 | else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; |
625 | else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; | 626 | else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; |
626 | else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; | 627 | else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; |
627 | else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip; | 628 | else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip; |
628 | } | 629 | } |
629 | } | 630 | } |
630 | p.setType( type ); | 631 | p.setType( type ); |
631 | 632 | ||
632 | return p; | 633 | return p; |
633 | } | 634 | } |
634 | 635 | ||
635 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) | 636 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) |
636 | { | 637 | { |
637 | VCARD::Value *value = cl->value(); | 638 | VCARD::Value *value = cl->value(); |
638 | if ( value ) { | 639 | if ( value ) { |
639 | return QString::fromUtf8( value->asString() ); | 640 | return QString::fromUtf8( value->asString() ); |
640 | } else { | 641 | } else { |
641 | kdDebug(5700) << "No value: " << cl->asString() << endl; | 642 | kdDebug(5700) << "No value: " << cl->asString() << endl; |
643 | qDebug("No value: %s", (const char*)(cl->asString())); | ||
642 | return QString::null; | 644 | return QString::null; |
643 | } | 645 | } |
644 | } | 646 | } |
645 | 647 | ||
646 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) | 648 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) |
647 | { | 649 | { |
648 | DateValue *dateValue = (DateValue *)cl->value(); | 650 | DateValue *dateValue = (DateValue *)cl->value(); |
649 | if ( dateValue ) | 651 | if ( dateValue ) |
650 | return dateValue->qdate(); | 652 | return dateValue->qdate(); |
651 | else | 653 | else |
652 | return QDate(); | 654 | return QDate(); |
653 | } | 655 | } |
654 | 656 | ||
655 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) | 657 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) |
656 | { | 658 | { |
657 | DateValue *dateValue = (DateValue *)cl->value(); | 659 | DateValue *dateValue = (DateValue *)cl->value(); |
658 | if ( dateValue ) | 660 | if ( dateValue ) |
659 | return dateValue->qdt(); | 661 | return dateValue->qdt(); |
660 | else | 662 | else |
661 | return QDateTime(); | 663 | return QDateTime(); |
662 | } | 664 | } |
663 | 665 | ||
664 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) | 666 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) |
665 | { | 667 | { |
666 | GeoValue *geoValue = (GeoValue *)cl->value(); | 668 | GeoValue *geoValue = (GeoValue *)cl->value(); |
667 | if ( geoValue ) { | 669 | if ( geoValue ) { |
668 | Geo geo( geoValue->latitude(), geoValue->longitude() ); | 670 | Geo geo( geoValue->latitude(), geoValue->longitude() ); |
669 | return geo; | 671 | return geo; |
670 | } else | 672 | } else |
671 | return Geo(); | 673 | return Geo(); |
672 | } | 674 | } |
673 | 675 | ||
674 | TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) | 676 | TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) |
675 | { | 677 | { |
676 | UTCValue *utcValue = (UTCValue *)cl->value(); | 678 | UTCValue *utcValue = (UTCValue *)cl->value(); |
677 | if ( utcValue ) { | 679 | if ( utcValue ) { |
678 | TimeZone tz; | 680 | TimeZone tz; |
679 | tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); | 681 | tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); |
680 | return tz; | 682 | return tz; |
681 | } else | 683 | } else |
682 | return TimeZone(); | 684 | return TimeZone(); |
683 | } | 685 | } |
684 | 686 | ||
685 | Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) | 687 | Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) |
686 | { | 688 | { |
687 | ClassValue *classValue = (ClassValue *)cl->value(); | 689 | ClassValue *classValue = (ClassValue *)cl->value(); |
688 | if ( classValue ) { | 690 | if ( classValue ) { |
689 | Secrecy secrecy; | 691 | Secrecy secrecy; |
690 | switch ( classValue->type() ) { | 692 | switch ( classValue->type() ) { |
691 | case ClassValue::Public: | 693 | case ClassValue::Public: |
692 | secrecy.setType( Secrecy::Public ); | 694 | secrecy.setType( Secrecy::Public ); |
693 | break; | 695 | break; |
694 | case ClassValue::Private: | 696 | case ClassValue::Private: |
695 | secrecy.setType( Secrecy::Private ); | 697 | secrecy.setType( Secrecy::Private ); |
696 | break; | 698 | break; |
697 | case ClassValue::Confidential: | 699 | case ClassValue::Confidential: |
698 | secrecy.setType( Secrecy::Confidential ); | 700 | secrecy.setType( Secrecy::Confidential ); |
699 | break; | 701 | break; |
700 | } | 702 | } |
701 | 703 | ||
702 | return secrecy; | 704 | return secrecy; |
703 | } else | 705 | } else |
704 | return Secrecy(); | 706 | return Secrecy(); |
705 | } | 707 | } |
706 | 708 | ||
707 | void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) | 709 | void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) |
708 | { | 710 | { |
709 | ContentLine cl; | 711 | ContentLine cl; |
710 | cl.setName( EntityTypeToParamName( EntityKey ) ); | 712 | cl.setName( EntityTypeToParamName( EntityKey ) ); |
711 | 713 | ||
712 | ParamList params; | 714 | ParamList params; |
713 | if ( key.isBinary() ) { | 715 | if ( key.isBinary() ) { |
714 | cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); | 716 | cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); |
715 | params.append( new Param( "ENCODING", "b" ) ); | 717 | params.append( new Param( "ENCODING", "b" ) ); |
716 | } else { | 718 | } else { |
717 | cl.setValue( new TextValue( key.textData().utf8() ) ); | 719 | cl.setValue( new TextValue( key.textData().utf8() ) ); |
718 | } | 720 | } |
719 | 721 | ||
720 | switch ( key.type() ) { | 722 | switch ( key.type() ) { |
721 | case Key::X509: | 723 | case Key::X509: |
722 | params.append( new Param( "TYPE", "X509" ) ); | 724 | params.append( new Param( "TYPE", "X509" ) ); |
723 | break; | 725 | break; |
724 | case Key::PGP: | 726 | case Key::PGP: |
725 | params.append( new Param( "TYPE", "PGP" ) ); | 727 | params.append( new Param( "TYPE", "PGP" ) ); |
726 | break; | 728 | break; |
727 | case Key::Custom: | 729 | case Key::Custom: |
728 | params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); | 730 | params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); |
729 | break; | 731 | break; |
730 | } | 732 | } |
731 | 733 | ||
732 | cl.setParamList( params ); | 734 | cl.setParamList( params ); |
733 | vcard->add( cl ); | 735 | vcard->add( cl ); |
734 | } | 736 | } |
735 | 737 | ||
736 | Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) | 738 | Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) |
737 | { | 739 | { |
738 | Key key; | 740 | Key key; |
739 | bool isBinary = false; | 741 | bool isBinary = false; |
740 | TextValue *v = (TextValue *)cl->value(); | 742 | TextValue *v = (TextValue *)cl->value(); |
741 | 743 | ||
742 | ParamList params = cl->paramList(); | 744 | ParamList params = cl->paramList(); |
743 | ParamListIterator it( params ); | 745 | ParamListIterator it( params ); |
744 | for( ; it.current(); ++it ) { | 746 | for( ; it.current(); ++it ) { |
745 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 747 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
746 | isBinary = true; | 748 | isBinary = true; |
747 | if ( (*it)->name() == "TYPE" ) { | 749 | if ( (*it)->name() == "TYPE" ) { |
748 | if ( (*it)->value().isEmpty() ) | 750 | if ( (*it)->value().isEmpty() ) |
749 | continue; | 751 | continue; |
750 | if ( (*it)->value() == "X509" ) | 752 | if ( (*it)->value() == "X509" ) |
751 | key.setType( Key::X509 ); | 753 | key.setType( Key::X509 ); |
752 | else if ( (*it)->value() == "PGP" ) | 754 | else if ( (*it)->value() == "PGP" ) |
753 | key.setType( Key::PGP ); | 755 | key.setType( Key::PGP ); |
754 | else { | 756 | else { |
755 | key.setType( Key::Custom ); | 757 | key.setType( Key::Custom ); |
756 | key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); | 758 | key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); |
757 | } | 759 | } |
758 | } | 760 | } |
759 | } | 761 | } |
760 | 762 | ||
761 | 763 | ||
762 | if ( isBinary ) { | 764 | if ( isBinary ) { |
763 | QByteArray data; | 765 | QByteArray data; |
764 | KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); | 766 | KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); |
765 | key.setBinaryData( data ); | 767 | key.setBinaryData( data ); |
766 | } else { | 768 | } else { |
767 | key.setTextData( QString::fromUtf8( v->asString() ) ); | 769 | key.setTextData( QString::fromUtf8( v->asString() ) ); |
768 | } | 770 | } |
769 | 771 | ||
770 | return key; | 772 | return key; |
771 | } | 773 | } |
772 | 774 | ||
773 | 775 | ||
774 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) | 776 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) |
775 | { | 777 | { |
776 | if ( agent.isIntern() && !agent.addressee() ) | 778 | if ( agent.isIntern() && !agent.addressee() ) |
777 | return; | 779 | return; |
778 | 780 | ||
779 | if ( !agent.isIntern() && agent.url().isEmpty() ) | 781 | if ( !agent.isIntern() && agent.url().isEmpty() ) |
780 | return; | 782 | return; |
781 | 783 | ||
782 | ContentLine cl; | 784 | ContentLine cl; |
783 | cl.setName( EntityTypeToParamName( EntityAgent ) ); | 785 | cl.setName( EntityTypeToParamName( EntityAgent ) ); |
784 | 786 | ||
785 | ParamList params; | 787 | ParamList params; |
786 | if ( agent.isIntern() ) { | 788 | if ( agent.isIntern() ) { |
787 | QString vstr; | 789 | QString vstr; |
788 | Addressee *addr = agent.addressee(); | 790 | Addressee *addr = agent.addressee(); |
789 | if ( addr ) { | 791 | if ( addr ) { |
790 | writeToString( (*addr), vstr ); | 792 | writeToString( (*addr), vstr ); |
791 | 793 | ||
792 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 794 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
793 | /*US | 795 | /*US |
794 | vstr.replace( ":", "\\:" ); | 796 | vstr.replace( ":", "\\:" ); |
795 | vstr.replace( ",", "\\," ); | 797 | vstr.replace( ",", "\\," ); |
796 | vstr.replace( ";", "\\;" ); | 798 | vstr.replace( ";", "\\;" ); |
797 | vstr.replace( "\r\n", "\\n" ); | 799 | vstr.replace( "\r\n", "\\n" ); |
798 | */ | 800 | */ |
799 | vstr.replace( QRegExp(":"), "\\:" ); | 801 | vstr.replace( QRegExp(":"), "\\:" ); |
800 | vstr.replace( QRegExp(","), "\\," ); | 802 | vstr.replace( QRegExp(","), "\\," ); |
801 | vstr.replace( QRegExp(";"), "\\;" ); | 803 | vstr.replace( QRegExp(";"), "\\;" ); |
802 | vstr.replace( QRegExp("\r\n"), "\\n" ); | 804 | vstr.replace( QRegExp("\r\n"), "\\n" ); |
803 | 805 | ||
804 | cl.setValue( new TextValue( vstr.utf8() ) ); | 806 | cl.setValue( new TextValue( vstr.utf8() ) ); |
805 | } else | 807 | } else |
806 | return; | 808 | return; |
807 | } else { | 809 | } else { |
808 | cl.setValue( new TextValue( agent.url().utf8() ) ); | 810 | cl.setValue( new TextValue( agent.url().utf8() ) ); |
809 | params.append( new Param( "VALUE", "uri" ) ); | 811 | params.append( new Param( "VALUE", "uri" ) ); |
810 | } | 812 | } |
811 | 813 | ||
812 | cl.setParamList( params ); | 814 | cl.setParamList( params ); |
813 | vcard->add( cl ); | 815 | vcard->add( cl ); |
814 | } | 816 | } |
815 | 817 | ||
816 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) | 818 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) |
817 | { | 819 | { |
818 | Agent agent; | 820 | Agent agent; |
819 | bool isIntern = true; | 821 | bool isIntern = true; |
820 | TextValue *v = (TextValue *)cl->value(); | 822 | TextValue *v = (TextValue *)cl->value(); |
821 | 823 | ||
822 | ParamList params = cl->paramList(); | 824 | ParamList params = cl->paramList(); |
823 | ParamListIterator it( params ); | 825 | ParamListIterator it( params ); |
824 | for( ; it.current(); ++it ) { | 826 | for( ; it.current(); ++it ) { |
825 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) | 827 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) |
826 | isIntern = false; | 828 | isIntern = false; |
827 | } | 829 | } |
828 | 830 | ||
829 | if ( isIntern ) { | 831 | if ( isIntern ) { |
830 | QString vstr = QString::fromUtf8( v->asString() ); | 832 | QString vstr = QString::fromUtf8( v->asString() ); |
831 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 833 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
832 | /*US | 834 | /*US |
833 | vstr.replace( "\\n", "\r\n" ); | 835 | vstr.replace( "\\n", "\r\n" ); |
834 | vstr.replace( "\\:", ":" ); | 836 | vstr.replace( "\\:", ":" ); |
835 | vstr.replace( "\\,", "," ); | 837 | vstr.replace( "\\,", "," ); |
836 | vstr.replace( "\\;", ";" ); | 838 | vstr.replace( "\\;", ";" ); |
837 | */ | 839 | */ |
838 | vstr.replace( QRegExp("\\n"), "\r\n" ); | 840 | vstr.replace( QRegExp("\\n"), "\r\n" ); |
839 | vstr.replace( QRegExp("\\:"), ":" ); | 841 | vstr.replace( QRegExp("\\:"), ":" ); |
840 | vstr.replace( QRegExp("\\,"), "," ); | 842 | vstr.replace( QRegExp("\\,"), "," ); |
841 | vstr.replace( QRegExp("\\;"), ";" ); | 843 | vstr.replace( QRegExp("\\;"), ";" ); |
842 | 844 | ||
843 | Addressee *addr = new Addressee; | 845 | Addressee *addr = new Addressee; |
844 | readFromString( vstr, *addr ); | 846 | readFromString( vstr, *addr ); |
845 | agent.setAddressee( addr ); | 847 | agent.setAddressee( addr ); |
846 | } else { | 848 | } else { |
847 | agent.setUrl( QString::fromUtf8( v->asString() ) ); | 849 | agent.setUrl( QString::fromUtf8( v->asString() ) ); |
848 | } | 850 | } |
849 | 851 | ||
850 | return agent; | 852 | return agent; |
851 | } | 853 | } |
852 | 854 | ||
853 | void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) | 855 | void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) |
854 | { | 856 | { |
855 | ContentLine cl; | 857 | ContentLine cl; |
856 | cl.setName( EntityTypeToParamName( type ) ); | 858 | cl.setName( EntityTypeToParamName( type ) ); |
857 | 859 | ||
858 | if ( pic.isIntern() && pic.data().isNull() ) | 860 | if ( pic.isIntern() && pic.data().isNull() ) |
859 | return; | 861 | return; |
860 | 862 | ||
861 | if ( !pic.isIntern() && pic.url().isEmpty() ) | 863 | if ( !pic.isIntern() && pic.url().isEmpty() ) |
862 | return; | 864 | return; |
863 | 865 | ||
864 | ParamList params; | 866 | ParamList params; |
865 | if ( pic.isIntern() ) { | 867 | if ( pic.isIntern() ) { |
866 | QImage img = pic.data(); | 868 | QImage img = pic.data(); |
867 | if ( intern ) { // only for vCard export we really write the data inline | 869 | if ( intern ) { // only for vCard export we really write the data inline |
868 | QByteArray data; | 870 | QByteArray data; |
869 | QDataStream s( data, IO_WriteOnly ); | 871 | QDataStream s( data, IO_WriteOnly ); |
870 | s.setVersion( 4 ); // to produce valid png files | 872 | s.setVersion( 4 ); // to produce valid png files |
871 | s << img; | 873 | s << img; |
872 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); | 874 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); |
873 | 875 | ||
874 | } else { // save picture in cache | 876 | } else { // save picture in cache |
875 | QString dir; | 877 | QString dir; |
876 | if ( type == EntityPhoto ) | 878 | if ( type == EntityPhoto ) |
877 | dir = "photos"; | 879 | dir = "photos"; |
878 | if ( type == EntityLogo ) | 880 | if ( type == EntityLogo ) |
879 | dir = "logos"; | 881 | dir = "logos"; |
880 | 882 | ||
881 | img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); | 883 | img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); |
882 | cl.setValue( new TextValue( "<dummy>" ) ); | 884 | cl.setValue( new TextValue( "<dummy>" ) ); |
883 | } | 885 | } |
884 | params.append( new Param( "ENCODING", "b" ) ); | 886 | params.append( new Param( "ENCODING", "b" ) ); |
885 | if ( !pic.type().isEmpty() ) | 887 | if ( !pic.type().isEmpty() ) |
886 | params.append( new Param( "TYPE", pic.type().utf8() ) ); | 888 | params.append( new Param( "TYPE", pic.type().utf8() ) ); |
887 | } else { | 889 | } else { |
888 | 890 | ||
889 | cl.setValue( new TextValue( pic.url().utf8() ) ); | 891 | cl.setValue( new TextValue( pic.url().utf8() ) ); |
890 | params.append( new Param( "VALUE", "uri" ) ); | 892 | params.append( new Param( "VALUE", "uri" ) ); |
891 | } | 893 | } |
892 | 894 | ||
893 | cl.setParamList( params ); | 895 | cl.setParamList( params ); |
894 | vcard->add( cl ); | 896 | vcard->add( cl ); |
895 | } | 897 | } |
896 | 898 | ||
897 | Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) | 899 | Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) |
898 | { | 900 | { |
899 | Picture pic; | 901 | Picture pic; |
900 | bool isInline = false; | 902 | bool isInline = false; |
901 | QString picType; | 903 | QString picType; |
902 | TextValue *v = (TextValue *)cl->value(); | 904 | TextValue *v = (TextValue *)cl->value(); |
903 | 905 | ||
904 | ParamList params = cl->paramList(); | 906 | ParamList params = cl->paramList(); |
905 | ParamListIterator it( params ); | 907 | ParamListIterator it( params ); |
906 | for( ; it.current(); ++it ) { | 908 | for( ; it.current(); ++it ) { |
907 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 909 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
908 | isInline = true; | 910 | isInline = true; |
909 | if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) | 911 | if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) |
910 | picType = QString::fromUtf8( (*it)->value() ); | 912 | picType = QString::fromUtf8( (*it)->value() ); |
911 | } | 913 | } |
912 | 914 | ||
913 | if ( isInline ) { | 915 | if ( isInline ) { |
914 | QImage img; | 916 | QImage img; |
915 | if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache | 917 | if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache |
916 | QString dir; | 918 | QString dir; |
917 | if ( type == EntityPhoto ) | 919 | if ( type == EntityPhoto ) |
918 | dir = "photos"; | 920 | dir = "photos"; |
919 | if ( type == EntityLogo ) | 921 | if ( type == EntityLogo ) |
920 | dir = "logos"; | 922 | dir = "logos"; |
921 | 923 | ||
922 | img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) ); | 924 | img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) ); |
923 | } else { | 925 | } else { |
924 | QByteArray data; | 926 | QByteArray data; |
925 | KCodecs::base64Decode( v->asString(), data ); | 927 | KCodecs::base64Decode( v->asString(), data ); |
926 | img.loadFromData( data ); | 928 | img.loadFromData( data ); |
927 | } | 929 | } |
928 | pic.setData( img ); | 930 | pic.setData( img ); |
929 | pic.setType( picType ); | 931 | pic.setType( picType ); |
930 | } else { | 932 | } else { |
931 | pic.setUrl( QString::fromUtf8( v->asString() ) ); | 933 | pic.setUrl( QString::fromUtf8( v->asString() ) ); |
932 | } | 934 | } |
933 | 935 | ||
934 | return pic; | 936 | return pic; |
935 | } | 937 | } |
936 | 938 | ||
937 | void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) | 939 | void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) |
938 | { | 940 | { |
939 | ContentLine cl; | 941 | ContentLine cl; |
940 | cl.setName( EntityTypeToParamName( EntitySound ) ); | 942 | cl.setName( EntityTypeToParamName( EntitySound ) ); |
941 | 943 | ||
942 | if ( sound.isIntern() && sound.data().isNull() ) | 944 | if ( sound.isIntern() && sound.data().isNull() ) |
943 | return; | 945 | return; |
944 | 946 | ||
945 | if ( !sound.isIntern() && sound.url().isEmpty() ) | 947 | if ( !sound.isIntern() && sound.url().isEmpty() ) |
946 | return; | 948 | return; |
947 | 949 | ||
948 | ParamList params; | 950 | ParamList params; |
949 | if ( sound.isIntern() ) { | 951 | if ( sound.isIntern() ) { |
950 | QByteArray data = sound.data(); | 952 | QByteArray data = sound.data(); |
951 | if ( intern ) { // only for vCard export we really write the data inline | 953 | if ( intern ) { // only for vCard export we really write the data inline |
952 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); | 954 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); |
953 | } else { // save sound in cache | 955 | } else { // save sound in cache |
954 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); | 956 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); |
955 | if ( file.open( IO_WriteOnly ) ) { | 957 | if ( file.open( IO_WriteOnly ) ) { |
956 | file.writeBlock( data ); | 958 | file.writeBlock( data ); |
957 | } | 959 | } |
958 | cl.setValue( new TextValue( "<dummy>" ) ); | 960 | cl.setValue( new TextValue( "<dummy>" ) ); |
959 | } | 961 | } |
960 | params.append( new Param( "ENCODING", "b" ) ); | 962 | params.append( new Param( "ENCODING", "b" ) ); |
961 | } else { | 963 | } else { |
962 | cl.setValue( new TextValue( sound.url().utf8() ) ); | 964 | cl.setValue( new TextValue( sound.url().utf8() ) ); |
963 | params.append( new Param( "VALUE", "uri" ) ); | 965 | params.append( new Param( "VALUE", "uri" ) ); |
964 | } | 966 | } |
965 | 967 | ||
966 | cl.setParamList( params ); | 968 | cl.setParamList( params ); |
967 | vcard->add( cl ); | 969 | vcard->add( cl ); |
968 | } | 970 | } |
969 | 971 | ||
970 | Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) | 972 | Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) |
971 | { | 973 | { |
972 | Sound sound; | 974 | Sound sound; |
973 | bool isInline = false; | 975 | bool isInline = false; |
974 | TextValue *v = (TextValue *)cl->value(); | 976 | TextValue *v = (TextValue *)cl->value(); |
975 | 977 | ||
976 | ParamList params = cl->paramList(); | 978 | ParamList params = cl->paramList(); |
977 | ParamListIterator it( params ); | 979 | ParamListIterator it( params ); |
978 | for( ; it.current(); ++it ) { | 980 | for( ; it.current(); ++it ) { |
979 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 981 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
980 | isInline = true; | 982 | isInline = true; |
981 | } | 983 | } |
982 | 984 | ||
983 | if ( isInline ) { | 985 | if ( isInline ) { |
984 | QByteArray data; | 986 | QByteArray data; |
985 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache | 987 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache |
986 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); | 988 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); |
987 | if ( file.open( IO_ReadOnly ) ) { | 989 | if ( file.open( IO_ReadOnly ) ) { |
988 | data = file.readAll(); | 990 | data = file.readAll(); |
989 | file.close(); | 991 | file.close(); |
990 | } | 992 | } |
991 | } else { | 993 | } else { |
992 | KCodecs::base64Decode( v->asString(), data ); | 994 | KCodecs::base64Decode( v->asString(), data ); |
993 | } | 995 | } |
994 | sound.setData( data ); | 996 | sound.setData( data ); |
995 | } else { | 997 | } else { |
996 | sound.setUrl( QString::fromUtf8( v->asString() ) ); | 998 | sound.setUrl( QString::fromUtf8( v->asString() ) ); |
997 | } | 999 | } |
998 | 1000 | ||
999 | return sound; | 1001 | return sound; |
1000 | } | 1002 | } |
1001 | 1003 | ||
1002 | bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) | 1004 | bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) |
1003 | { | 1005 | { |
1004 | VCardEntity e( vcard.utf8() ); | 1006 | VCardEntity e( vcard.utf8() ); |
1005 | VCardListIterator it( e.cardList() ); | 1007 | VCardListIterator it( e.cardList() ); |
1006 | 1008 | ||
1007 | if ( it.current() ) { | 1009 | if ( it.current() ) { |
1008 | //US VCard v(*it.current()); | 1010 | //US VCard v(*it.current()); |
1009 | //US loadAddressee( addressee, v ); | 1011 | //US loadAddressee( addressee, v ); |
1010 | loadAddressee( addressee, it.current() ); | 1012 | loadAddressee( addressee, it.current() ); |
1011 | return true; | 1013 | return true; |
1012 | } | 1014 | } |
1013 | 1015 | ||
1014 | return false; | 1016 | return false; |
1015 | } | 1017 | } |
1016 | 1018 | ||
1017 | bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) | 1019 | bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) |
1018 | { | 1020 | { |
1019 | VCardEntity vcards; | 1021 | VCardEntity vcards; |
1020 | VCardList vcardlist; | 1022 | VCardList vcardlist; |
1021 | vcardlist.setAutoDelete( true ); | 1023 | vcardlist.setAutoDelete( true ); |
1022 | 1024 | ||
1023 | VCard *v = new VCard; | 1025 | VCard *v = new VCard; |
1024 | 1026 | ||
1025 | saveAddressee( addressee, v, true ); | 1027 | saveAddressee( addressee, v, true ); |