-rw-r--r-- | kabc/vcard/ContentLine.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp index 0a2f97d..1d4886c 100644 --- a/kabc/vcard/ContentLine.cpp +++ b/kabc/vcard/ContentLine.cpp | |||
@@ -1,57 +1,57 @@ | |||
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 <q3cstring.h> |
25 | #include <qstrlist.h> | 25 | #include <q3strlist.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 | ||
@@ -69,199 +69,199 @@ ContentLine::ContentLine() | |||
69 | value_(0), | 69 | value_(0), |
70 | paramType_( ParamUnknown ), | 70 | paramType_( ParamUnknown ), |
71 | valueType_( ValueUnknown ), | 71 | valueType_( ValueUnknown ), |
72 | entityType_( EntityUnknown ) | 72 | entityType_( EntityUnknown ) |
73 | { | 73 | { |
74 | paramList_.setAutoDelete( TRUE ); | 74 | paramList_.setAutoDelete( TRUE ); |
75 | } | 75 | } |
76 | 76 | ||
77 | ContentLine::ContentLine(const ContentLine & x) | 77 | ContentLine::ContentLine(const ContentLine & x) |
78 | :Entity(x), | 78 | :Entity(x), |
79 | group_ (x.group_), | 79 | group_ (x.group_), |
80 | name_ (x.name_), | 80 | name_ (x.name_), |
81 | /*US paramList_(x.paramList_),*/ | 81 | /*US paramList_(x.paramList_),*/ |
82 | value_(x.value_->clone()), | 82 | value_(x.value_->clone()), |
83 | paramType_(x.paramType_), | 83 | paramType_(x.paramType_), |
84 | valueType_(x.valueType_), | 84 | valueType_(x.valueType_), |
85 | entityType_(x.entityType_) | 85 | entityType_(x.entityType_) |
86 | { | 86 | { |
87 | paramList_.setAutoDelete( TRUE ); | 87 | paramList_.setAutoDelete( TRUE ); |
88 | 88 | ||
89 | 89 | ||
90 | ParamListIterator it(x.paramList_); | 90 | ParamListIterator it(x.paramList_); |
91 | for (; it.current(); ++it) | 91 | for (; it.current(); ++it) |
92 | { | 92 | { |
93 | Param *p = new Param; | 93 | Param *p = new Param; |
94 | p->setName( it.current()->name() ); | 94 | p->setName( it.current()->name() ); |
95 | p->setValue( it.current()->value() ); | 95 | p->setValue( it.current()->value() ); |
96 | paramList_.append(p); | 96 | paramList_.append(p); |
97 | } | 97 | } |
98 | 98 | ||
99 | } | 99 | } |
100 | 100 | ||
101 | ContentLine::ContentLine(const QCString & s) | 101 | ContentLine::ContentLine(const Q3CString & s) |
102 | :Entity(s), | 102 | :Entity(s), |
103 | value_(0), | 103 | value_(0), |
104 | paramType_( ParamUnknown ), | 104 | paramType_( ParamUnknown ), |
105 | valueType_( ValueUnknown ), | 105 | valueType_( ValueUnknown ), |
106 | entityType_( EntityUnknown ) | 106 | entityType_( EntityUnknown ) |
107 | { | 107 | { |
108 | paramList_.setAutoDelete( TRUE ); | 108 | paramList_.setAutoDelete( TRUE ); |
109 | } | 109 | } |
110 | 110 | ||
111 | ContentLine & | 111 | ContentLine & |
112 | ContentLine::operator = (ContentLine & x) | 112 | ContentLine::operator = (ContentLine & x) |
113 | { | 113 | { |
114 | if (*this == x) return *this; | 114 | if (*this == x) return *this; |
115 | 115 | ||
116 | ParamListIterator it(x.paramList_); | 116 | ParamListIterator it(x.paramList_); |
117 | for (; it.current(); ++it) | 117 | for (; it.current(); ++it) |
118 | { | 118 | { |
119 | Param *p = new Param; | 119 | Param *p = new Param; |
120 | p->setName( it.current()->name() ); | 120 | p->setName( it.current()->name() ); |
121 | p->setValue( it.current()->value() ); | 121 | p->setValue( it.current()->value() ); |
122 | paramList_.append(p); | 122 | paramList_.append(p); |
123 | } | 123 | } |
124 | 124 | ||
125 | value_ = x.value_->clone(); | 125 | value_ = x.value_->clone(); |
126 | 126 | ||
127 | Entity::operator = (x); | 127 | Entity::operator = (x); |
128 | return *this; | 128 | return *this; |
129 | } | 129 | } |
130 | 130 | ||
131 | ContentLine & | 131 | ContentLine & |
132 | ContentLine::operator = (const QCString & s) | 132 | ContentLine::operator = (const Q3CString & s) |
133 | { | 133 | { |
134 | Entity::operator = (s); | 134 | Entity::operator = (s); |
135 | delete value_; | 135 | delete value_; |
136 | value_ = 0; | 136 | value_ = 0; |
137 | return *this; | 137 | return *this; |
138 | } | 138 | } |
139 | 139 | ||
140 | bool | 140 | bool |
141 | ContentLine::operator == (ContentLine & x) | 141 | ContentLine::operator == (ContentLine & x) |
142 | { | 142 | { |
143 | x.parse(); | 143 | x.parse(); |
144 | 144 | ||
145 | QPtrListIterator<Param> it(x.paramList()); | 145 | Q3PtrListIterator<Param> it(x.paramList()); |
146 | 146 | ||
147 | if (!paramList_.find(it.current())) | 147 | if (!paramList_.find(it.current())) |
148 | return false; | 148 | return false; |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | ContentLine::~ContentLine() | 153 | ContentLine::~ContentLine() |
154 | { | 154 | { |
155 | delete value_; | 155 | delete value_; |
156 | value_ = 0; | 156 | value_ = 0; |
157 | } | 157 | } |
158 | 158 | ||
159 | void | 159 | void |
160 | ContentLine::_parse() | 160 | ContentLine::_parse() |
161 | { | 161 | { |
162 | vDebug("parse"); | 162 | vDebug("parse"); |
163 | 163 | ||
164 | // Unfold folded lines | 164 | // Unfold folded lines |
165 | // NLR | 165 | // NLR |
166 | strRep_ = strRep_.replace( QRegExp( "\\r" ), "" ); | 166 | strRep_ = strRep_.replace( "\\r" , "" ); |
167 | // Unqote newlines | 167 | // Unqote newlines |
168 | strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); | 168 | strRep_ = strRep_.replace( "\\\\n", "\n" ); |
169 | //NLR | 169 | //NLR |
170 | strRep_ = strRep_.replace( QRegExp( "\\\\r" ), "\r" ); | 170 | strRep_ = strRep_.replace( "\\\\r" , "\r" ); |
171 | 171 | ||
172 | int split = strRep_.find(':'); | 172 | int split = strRep_.find(':'); |
173 | 173 | ||
174 | if (split == -1) { // invalid content line | 174 | if (split == -1) { // invalid content line |
175 | vDebug("No ':'"); | 175 | vDebug("No ':'"); |
176 | return; | 176 | return; |
177 | } | 177 | } |
178 | 178 | ||
179 | QCString firstPart(strRep_.left(split)); | 179 | Q3CString firstPart(strRep_.left(split)); |
180 | QCString valuePart(strRep_.mid(split + 1)); | 180 | Q3CString valuePart(strRep_.mid(split + 1)); |
181 | 181 | ||
182 | split = firstPart.find('.'); | 182 | split = firstPart.find('.'); |
183 | 183 | ||
184 | if (split != -1) { | 184 | if (split != -1) { |
185 | group_ = firstPart.left(split); | 185 | group_ = firstPart.left(split); |
186 | firstPart= firstPart.mid(split + 1); | 186 | firstPart= firstPart.mid(split + 1); |
187 | } | 187 | } |
188 | 188 | ||
189 | vDebug("Group == " + group_); | 189 | vDebug("Group == " + group_); |
190 | vDebug("firstPart == " + firstPart); | 190 | vDebug("firstPart == " + firstPart); |
191 | vDebug("valuePart == " + valuePart); | 191 | vDebug("valuePart == " + valuePart); |
192 | 192 | ||
193 | // Now we have the group, the name and param list together and the value. | 193 | // Now we have the group, the name and param list together and the value. |
194 | 194 | ||
195 | QStrList l; | 195 | Q3StrList l; |
196 | 196 | ||
197 | RTokenise(firstPart, ";", l); | 197 | RTokenise(firstPart, ";", l); |
198 | 198 | ||
199 | if (l.count() == 0) {// invalid - no name ! | 199 | if (l.count() == 0) {// invalid - no name ! |
200 | vDebug("No name for this content line !"); | 200 | vDebug("No name for this content line !"); |
201 | return; | 201 | return; |
202 | } | 202 | } |
203 | 203 | ||
204 | name_ = l.at(0); | 204 | name_ = l.at(0); |
205 | 205 | ||
206 | // Now we have the name, so the rest of 'l' is the params. | 206 | // Now we have the name, so the rest of 'l' is the params. |
207 | // Remove the name part. | 207 | // Remove the name part. |
208 | l.remove(0u); | 208 | l.remove(0u); |
209 | 209 | ||
210 | entityType_= EntityNameToEntityType(name_); | 210 | entityType_= EntityNameToEntityType(name_); |
211 | paramType_= EntityTypeToParamType(entityType_); | 211 | paramType_= EntityTypeToParamType(entityType_); |
212 | 212 | ||
213 | unsigned int i = 0; | 213 | unsigned int i = 0; |
214 | 214 | ||
215 | // For each parameter, create a new parameter of the correct type. | 215 | // For each parameter, create a new parameter of the correct type. |
216 | 216 | ||
217 | QStrListIterator it(l); | 217 | Q3StrListIterator it(l); |
218 | 218 | ||
219 | for (; it.current(); ++it, i++) { | 219 | for (; it.current(); ++it, i++) { |
220 | 220 | ||
221 | QCString str = *it; | 221 | Q3CString str = *it; |
222 | 222 | ||
223 | split = str.find("="); | 223 | split = str.find("="); |
224 | if (split < 0 ) { | 224 | if (split < 0 ) { |
225 | vDebug("No '=' in paramter."); | 225 | vDebug("No '=' in paramter."); |
226 | continue; | 226 | continue; |
227 | } | 227 | } |
228 | 228 | ||
229 | QCString paraName = str.left(split); | 229 | Q3CString paraName = str.left(split); |
230 | QCString paraValue = str.mid(split + 1); | 230 | Q3CString paraValue = str.mid(split + 1); |
231 | 231 | ||
232 | QStrList paraValues; | 232 | Q3StrList paraValues; |
233 | RTokenise(paraValue, ",", paraValues); | 233 | RTokenise(paraValue, ",", paraValues); |
234 | 234 | ||
235 | QStrListIterator it2( paraValues ); | 235 | Q3StrListIterator it2( paraValues ); |
236 | 236 | ||
237 | for(; it2.current(); ++it2) { | 237 | for(; it2.current(); ++it2) { |
238 | 238 | ||
239 | Param *p = new Param; | 239 | Param *p = new Param; |
240 | p->setName( paraName ); | 240 | p->setName( paraName ); |
241 | p->setValue( *it2 ); | 241 | p->setValue( *it2 ); |
242 | 242 | ||
243 | paramList_.append(p); | 243 | paramList_.append(p); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | // Create a new value of the correct type. | 247 | // Create a new value of the correct type. |
248 | 248 | ||
249 | valueType_ = EntityTypeToValueType(entityType_); | 249 | valueType_ = EntityTypeToValueType(entityType_); |
250 | 250 | ||
251 | //kdDebug(5710) << "valueType: " << valueType_ << endl; | 251 | //kdDebug(5710) << "valueType: " << valueType_ << endl; |
252 | 252 | ||
253 | switch (valueType_) { | 253 | switch (valueType_) { |
254 | 254 | ||
255 | case ValueSound: value_ = new SoundValue;break; | 255 | case ValueSound: value_ = new SoundValue;break; |
256 | case ValueAgent: value_ = new AgentValue;break; | 256 | case ValueAgent: value_ = new AgentValue;break; |
257 | case ValueAddress: value_ = new AdrValue; break; | 257 | case ValueAddress: value_ = new AdrValue; break; |
258 | case ValueTel: value_ = new TelValue; break; | 258 | case ValueTel: value_ = new TelValue; break; |
259 | case ValueTextBin: value_ = new TextBinValue;break; | 259 | case ValueTextBin: value_ = new TextBinValue;break; |
260 | case ValueOrg: value_ = new OrgValue; break; | 260 | case ValueOrg: value_ = new OrgValue; break; |
261 | case ValueN: value_ = new NValue; break; | 261 | case ValueN: value_ = new NValue; break; |
262 | case ValueUTC: value_ = new UTCValue; break; | 262 | case ValueUTC: value_ = new UTCValue; break; |
263 | case ValueURI: value_ = new URIValue; break; | 263 | case ValueURI: value_ = new URIValue; break; |
264 | case ValueClass: value_ = new ClassValue;break; | 264 | case ValueClass: value_ = new ClassValue;break; |
265 | case ValueFloat: value_ = new FloatValue;break; | 265 | case ValueFloat: value_ = new FloatValue;break; |
266 | case ValueImage: value_ = new ImageValue;break; | 266 | case ValueImage: value_ = new ImageValue;break; |
267 | case ValueDate: value_ = new DateValue; break; | 267 | case ValueDate: value_ = new DateValue; break; |
@@ -280,65 +280,65 @@ ContentLine::_assemble() | |||
280 | { | 280 | { |
281 | //strRep_.truncate(0); | 281 | //strRep_.truncate(0); |
282 | QString line; | 282 | QString line; |
283 | if (!group_.isEmpty()) | 283 | if (!group_.isEmpty()) |
284 | line = group_ + '.'; | 284 | line = group_ + '.'; |
285 | line += name_; | 285 | line += name_; |
286 | ParamListIterator it(paramList_); | 286 | ParamListIterator it(paramList_); |
287 | for (; it.current(); ++it) | 287 | for (; it.current(); ++it) |
288 | line += ";" + it.current()->asString(); | 288 | line += ";" + it.current()->asString(); |
289 | 289 | ||
290 | if (value_ != 0) | 290 | if (value_ != 0) |
291 | line += ":" + value_->asString(); | 291 | line += ":" + value_->asString(); |
292 | 292 | ||
293 | line = line.replace( QRegExp( "\r" ), "\\r" ); | 293 | line = line.replace( QRegExp( "\r" ), "\\r" ); |
294 | line = line.replace( QRegExp( "\n" ), "\\n" ); | 294 | line = line.replace( QRegExp( "\n" ), "\\n" ); |
295 | 295 | ||
296 | // Fold lines longer than 72 chars | 296 | // Fold lines longer than 72 chars |
297 | const int maxLen = 72; | 297 | const int maxLen = 72; |
298 | uint cursor = 0; | 298 | uint cursor = 0; |
299 | QString cut; | 299 | QString cut; |
300 | while( line.length() > ( cursor + 1 ) * maxLen ) { | 300 | while( line.length() > ( cursor + 1 ) * maxLen ) { |
301 | cut += line.mid( cursor * maxLen, maxLen ); | 301 | cut += line.mid( cursor * maxLen, maxLen ); |
302 | cut += "\r\n "; | 302 | cut += "\r\n "; |
303 | ++cursor; | 303 | ++cursor; |
304 | } | 304 | } |
305 | cut += line.mid( cursor * maxLen ); | 305 | cut += line.mid( cursor * maxLen ); |
306 | strRep_ = cut.latin1(); | 306 | strRep_ = cut.latin1(); |
307 | //qDebug("ContentLine::_assemble()\n%s*****", strRep_.data()); | 307 | //qDebug("ContentLine::_assemble()\n%s*****", strRep_.data()); |
308 | #if 0 | 308 | #if 0 |
309 | vDebug("Assemble (argl) - my name is \"" + name_ + "\""); | 309 | vDebug("Assemble (argl) - my name is \"" + name_ + "\""); |
310 | strRep_.truncate(0); | 310 | strRep_.truncate(0); |
311 | 311 | ||
312 | QCString line; | 312 | Q3CString line; |
313 | 313 | ||
314 | if (!group_.isEmpty()) | 314 | if (!group_.isEmpty()) |
315 | line += group_ + '.'; | 315 | line += group_ + '.'; |
316 | 316 | ||
317 | line += name_; | 317 | line += name_; |
318 | 318 | ||
319 | vDebug("Adding parameters"); | 319 | vDebug("Adding parameters"); |
320 | ParamListIterator it(paramList_); | 320 | ParamListIterator it(paramList_); |
321 | 321 | ||
322 | for (; it.current(); ++it) | 322 | for (; it.current(); ++it) |
323 | line += ";" + it.current()->asString(); | 323 | line += ";" + it.current()->asString(); |
324 | 324 | ||
325 | vDebug("Adding value"); | 325 | vDebug("Adding value"); |
326 | if (value_ != 0) | 326 | if (value_ != 0) |
327 | line += ":" + value_->asString(); | 327 | line += ":" + value_->asString(); |
328 | else | 328 | else |
329 | vDebug("No value"); | 329 | vDebug("No value"); |
330 | 330 | ||
331 | // Quote newlines | 331 | // Quote newlines |
332 | line = line.replace( QRegExp( "\n" ), "\\n" ); | 332 | line = line.replace( QRegExp( "\n" ), "\\n" ); |
333 | 333 | ||
334 | // Fold lines longer than 72 chars | 334 | // Fold lines longer than 72 chars |
335 | const int maxLen = 72; | 335 | const int maxLen = 72; |
336 | uint cursor = 0; | 336 | uint cursor = 0; |
337 | while( line.length() > ( cursor + 1 ) * maxLen ) { | 337 | while( line.length() > ( cursor + 1 ) * maxLen ) { |
338 | strRep_ += line.mid( cursor * maxLen, maxLen ); | 338 | strRep_ += line.mid( cursor * maxLen, maxLen ); |
339 | strRep_ += "\r\n "; | 339 | strRep_ += "\r\n "; |
340 | ++cursor; | 340 | ++cursor; |
341 | } | 341 | } |
342 | strRep_ += line.mid( cursor * maxLen ); | 342 | strRep_ += line.mid( cursor * maxLen ); |
343 | qDebug("ContentLine::_assemble()\n%s*****", strRep_.data()); | 343 | qDebug("ContentLine::_assemble()\n%s*****", strRep_.data()); |
344 | #endif | 344 | #endif |