-rw-r--r-- | kabc/vcard/VCardv.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp index 49bfe43..1166aac 100644 --- a/kabc/vcard/VCardv.cpp +++ b/kabc/vcard/VCardv.cpp | |||
@@ -1,294 +1,294 @@ | |||
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 | #include <qstringlist.h> | 26 | #include <qstringlist.h> |
27 | #include <qstring.h> | 27 | #include <qstring.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | 29 | ||
30 | #include <VCardEntity.h> | 30 | #include <VCardEntity.h> |
31 | #include <VCardVCard.h> | 31 | #include <VCardVCard.h> |
32 | #include <VCardContentLine.h> | 32 | #include <VCardContentLine.h> |
33 | #include <VCardRToken.h> | 33 | #include <VCardRToken.h> |
34 | 34 | ||
35 | #include <VCardDefines.h> | 35 | #include <VCardDefines.h> |
36 | 36 | ||
37 | using namespace VCARD; | 37 | using namespace VCARD; |
38 | 38 | ||
39 | VCard::VCard() | 39 | VCard::VCard() |
40 | :Entity() | 40 | :Entity() |
41 | { | 41 | { |
42 | contentLineList_.setAutoDelete( TRUE ); | 42 | contentLineList_.setAutoDelete( TRUE ); |
43 | } | 43 | } |
44 | 44 | ||
45 | VCard::VCard(const VCard & x) | 45 | VCard::VCard(const VCard & x) |
46 | :Entity(x), | 46 | :Entity(x), |
47 | group_(x.group_) | 47 | group_(x.group_) |
48 | { | 48 | { |
49 | contentLineList_.setAutoDelete( TRUE ); | 49 | contentLineList_.setAutoDelete( TRUE ); |
50 | 50 | ||
51 | QPtrListIterator<ContentLine> it(x.contentLineList_); | 51 | QPtrListIterator<ContentLine> it(x.contentLineList_); |
52 | for (; it.current(); ++it) { | 52 | for (; it.current(); ++it) { |
53 | ContentLine * c = new ContentLine(*it.current()); | 53 | ContentLine * c = new ContentLine(*it.current()); |
54 | contentLineList_.append(c); | 54 | contentLineList_.append(c); |
55 | } | 55 | } |
56 | 56 | ||
57 | } | 57 | } |
58 | 58 | ||
59 | VCard::VCard(const QCString & s) | 59 | VCard::VCard(const QCString & s) |
60 | :Entity(s) | 60 | :Entity(s) |
61 | { | 61 | { |
62 | contentLineList_.setAutoDelete( TRUE ); | 62 | contentLineList_.setAutoDelete( TRUE ); |
63 | } | 63 | } |
64 | 64 | ||
65 | VCard & | 65 | VCard & |
66 | VCard::operator = (VCard & x) | 66 | VCard::operator = (VCard & x) |
67 | { | 67 | { |
68 | if (*this == x) return *this; | 68 | if (*this == x) return *this; |
69 | 69 | ||
70 | group_ = x.group(); | 70 | group_ = x.group(); |
71 | QPtrListIterator<ContentLine> it(x.contentLineList_); | 71 | QPtrListIterator<ContentLine> it(x.contentLineList_); |
72 | for (; it.current(); ++it) { | 72 | for (; it.current(); ++it) { |
73 | ContentLine * c = new ContentLine(*it.current()); | 73 | ContentLine * c = new ContentLine(*it.current()); |
74 | contentLineList_.append(c); | 74 | contentLineList_.append(c); |
75 | } | 75 | } |
76 | 76 | ||
77 | Entity::operator = (x); | 77 | Entity::operator = (x); |
78 | return *this; | 78 | return *this; |
79 | } | 79 | } |
80 | 80 | ||
81 | VCard & | 81 | VCard & |
82 | VCard::operator = (const QCString & s) | 82 | VCard::operator = (const QCString & s) |
83 | { | 83 | { |
84 | Entity::operator = (s); | 84 | Entity::operator = (s); |
85 | return *this; | 85 | return *this; |
86 | } | 86 | } |
87 | 87 | ||
88 | bool | 88 | bool |
89 | VCard::operator == (VCard & x) | 89 | VCard::operator == (VCard & x) |
90 | { | 90 | { |
91 | x.parse(); | 91 | x.parse(); |
92 | return false; | 92 | return false; |
93 | } | 93 | } |
94 | 94 | ||
95 | VCard::~VCard() | 95 | VCard::~VCard() |
96 | { | 96 | { |
97 | } | 97 | } |
98 | 98 | ||
99 | void | 99 | void |
100 | VCard::_parse() | 100 | VCard::_parse() |
101 | { | 101 | { |
102 | 102 | ||
103 | QStringList l; | 103 | QStringList l; |
104 | QStrList sl; | 104 | QStrList sl; |
105 | 105 | ||
106 | RTokenise(strRep_, "\r\n", sl); | 106 | RTokenise(strRep_, "\r\n", sl); |
107 | 107 | ||
108 | if (sl.count() < 3) { // Invalid VCARD ! | 108 | if (sl.count() < 3) { // Invalid VCARD ! |
109 | //qDebug("invalid vcard "); | 109 | //qDebug("invalid vcard "); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | l = QStringList::fromStrList( sl ); | 112 | l = QStringList::fromStrList( sl ); |
113 | // Get the first line | 113 | // Get the first line |
114 | QString beginLine = l[0].stripWhiteSpace(); | 114 | QString beginLine = l[0].stripWhiteSpace(); |
115 | 115 | ||
116 | // Remove extra blank lines | 116 | // Remove extra blank lines |
117 | while (l.last().isEmpty()) | 117 | while (l.last().isEmpty()) |
118 | l.remove(l.last()); | 118 | l.remove(l.last()); |
119 | 119 | ||
120 | // Now we know this is the last line | 120 | // Now we know this is the last line |
121 | QString endLine = l.last(); | 121 | QString endLine = l.last(); |
122 | 122 | ||
123 | // Trash the first and last lines as we have seen them. | 123 | // Trash the first and last lines as we have seen them. |
124 | l.remove(l.first()); | 124 | l.remove(l.begin()); |
125 | l.remove(l.last()); | 125 | l.remove(l.last()); |
126 | 126 | ||
127 | /////////////////////////////////////////////////////////////// | 127 | /////////////////////////////////////////////////////////////// |
128 | // FIRST LINE | 128 | // FIRST LINE |
129 | 129 | ||
130 | int split = beginLine.find(':'); | 130 | int split = beginLine.find(':'); |
131 | 131 | ||
132 | if (split == -1) { // invalid, no BEGIN | 132 | if (split == -1) { // invalid, no BEGIN |
133 | vDebug("No split"); | 133 | vDebug("No split"); |
134 | return; | 134 | return; |
135 | } | 135 | } |
136 | 136 | ||
137 | QString firstPart(beginLine.left(split)); | 137 | QString firstPart(beginLine.left(split)); |
138 | QString valuePart(beginLine.mid(split + 1)); | 138 | QString valuePart(beginLine.mid(split + 1)); |
139 | 139 | ||
140 | split = firstPart.find('.'); | 140 | split = firstPart.find('.'); |
141 | 141 | ||
142 | if (split != -1) { | 142 | if (split != -1) { |
143 | group_ = firstPart.left(split); | 143 | group_ = firstPart.left(split); |
144 | firstPart= firstPart.right(firstPart.length() - split - 1); | 144 | firstPart= firstPart.right(firstPart.length() - split - 1); |
145 | } | 145 | } |
146 | 146 | ||
147 | if (firstPart.left(5) != "BEGIN" ) { // No BEGIN ! | 147 | if (firstPart.left(5) != "BEGIN" ) { // No BEGIN ! |
148 | qDebug("no BEGIN in vcard "); | 148 | qDebug("no BEGIN in vcard "); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | 151 | ||
152 | if (valuePart.left(5) != "VCARD") { // Not a vcard ! | 152 | if (valuePart.left(5) != "VCARD") { // Not a vcard ! |
153 | qDebug("not a VCARD "); | 153 | qDebug("not a VCARD "); |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | 156 | ||
157 | /////////////////////////////////////////////////////////////// | 157 | /////////////////////////////////////////////////////////////// |
158 | // CONTENT LINES | 158 | // CONTENT LINES |
159 | // | 159 | // |
160 | vDebug("Content lines"); | 160 | vDebug("Content lines"); |
161 | 161 | ||
162 | // Handle folded lines. | 162 | // Handle folded lines. |
163 | 163 | ||
164 | QStringList refolded; | 164 | QStringList refolded; |
165 | 165 | ||
166 | 166 | ||
167 | QStringList::Iterator it = l.begin(); | 167 | QStringList::Iterator it = l.begin(); |
168 | 168 | ||
169 | QString cur; | 169 | QString cur; |
170 | 170 | ||
171 | for (; it != l.end(); ++it) { | 171 | for (; it != l.end(); ++it) { |
172 | cur = (*it); | 172 | cur = (*it); |
173 | ++it; | 173 | ++it; |
174 | while ( it!= l.end() && (*it).at(0) == ' '&& (*it).length()!= 1) { | 174 | while ( it!= l.end() && (*it).at(0) == ' '&& (*it).length()!= 1) { |
175 | cur += (*it) ; | 175 | cur += (*it) ; |
176 | ++it; | 176 | ++it; |
177 | } | 177 | } |
178 | --it; | 178 | --it; |
179 | refolded.append(cur); | 179 | refolded.append(cur); |
180 | } | 180 | } |
181 | QStringList::Iterator it2 = refolded.begin(); | 181 | QStringList::Iterator it2 = refolded.begin(); |
182 | for (; it2 != refolded.end(); ++it2) { | 182 | for (; it2 != refolded.end(); ++it2) { |
183 | ContentLine * cl = new ContentLine(QCString((*it2).latin1())); | 183 | ContentLine * cl = new ContentLine(QCString((*it2).latin1())); |
184 | cl->parse(); | 184 | cl->parse(); |
185 | if (cl->value() == 0) | 185 | if (cl->value() == 0) |
186 | { | 186 | { |
187 | qDebug("Content line could not be parsed. Discarded: %s", (*it2).latin1()); | 187 | qDebug("Content line could not be parsed. Discarded: %s", (*it2).latin1()); |
188 | delete cl; | 188 | delete cl; |
189 | } | 189 | } |
190 | else | 190 | else |
191 | contentLineList_.append(cl); | 191 | contentLineList_.append(cl); |
192 | } | 192 | } |
193 | 193 | ||
194 | /////////////////////////////////////////////////////////////// | 194 | /////////////////////////////////////////////////////////////// |
195 | // LAST LINE | 195 | // LAST LINE |
196 | 196 | ||
197 | 197 | ||
198 | // LR: sorry, but the remaining code in this method makes no sense | 198 | // LR: sorry, but the remaining code in this method makes no sense |
199 | 199 | ||
200 | #if 0 | 200 | #if 0 |
201 | split = endLine.find(':'); | 201 | split = endLine.find(':'); |
202 | 202 | ||
203 | if (split == -1) // invalid, no END | 203 | if (split == -1) // invalid, no END |
204 | return; | 204 | return; |
205 | 205 | ||
206 | firstPart = endLine.left(split); | 206 | firstPart = endLine.left(split); |
207 | valuePart = endLine.right(firstPart.length() - split - 1); | 207 | valuePart = endLine.right(firstPart.length() - split - 1); |
208 | 208 | ||
209 | split = firstPart.find('.'); | 209 | split = firstPart.find('.'); |
210 | 210 | ||
211 | if (split != -1) { | 211 | if (split != -1) { |
212 | group_ = firstPart.left(split); | 212 | group_ = firstPart.left(split); |
213 | firstPart= firstPart.right(firstPart.length() - split - 1); | 213 | firstPart= firstPart.right(firstPart.length() - split - 1); |
214 | } | 214 | } |
215 | 215 | ||
216 | if (qstricmp(firstPart, "END") != 0) // No END ! | 216 | if (qstricmp(firstPart, "END") != 0) // No END ! |
217 | return; | 217 | return; |
218 | 218 | ||
219 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! | 219 | if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! |
220 | return; | 220 | return; |
221 | #endif | 221 | #endif |
222 | } | 222 | } |
223 | 223 | ||
224 | void | 224 | void |
225 | VCard::_assemble() | 225 | VCard::_assemble() |
226 | { | 226 | { |
227 | vDebug("Assembling vcard"); | 227 | vDebug("Assembling vcard"); |
228 | strRep_ = "BEGIN:VCARD\r\n"; | 228 | strRep_ = "BEGIN:VCARD\r\n"; |
229 | strRep_ += "VERSION:3.0\r\n"; | 229 | strRep_ += "VERSION:3.0\r\n"; |
230 | 230 | ||
231 | QPtrListIterator<ContentLine> it(contentLineList_); | 231 | QPtrListIterator<ContentLine> it(contentLineList_); |
232 | 232 | ||
233 | for (; it.current(); ++it) | 233 | for (; it.current(); ++it) |
234 | strRep_ += it.current()->asString() + "\r\n"; | 234 | strRep_ += it.current()->asString() + "\r\n"; |
235 | 235 | ||
236 | strRep_ += "END:VCARD\r\n"; | 236 | strRep_ += "END:VCARD\r\n"; |
237 | } | 237 | } |
238 | 238 | ||
239 | bool | 239 | bool |
240 | VCard::has(EntityType t) | 240 | VCard::has(EntityType t) |
241 | { | 241 | { |
242 | parse(); | 242 | parse(); |
243 | return contentLine(t) == 0 ? false : true; | 243 | return contentLine(t) == 0 ? false : true; |
244 | } | 244 | } |
245 | 245 | ||
246 | bool | 246 | bool |
247 | VCard::has(const QCString & s) | 247 | VCard::has(const QCString & s) |
248 | { | 248 | { |
249 | parse(); | 249 | parse(); |
250 | return contentLine(s) == 0 ? false : true; | 250 | return contentLine(s) == 0 ? false : true; |
251 | } | 251 | } |
252 | 252 | ||
253 | void | 253 | void |
254 | VCard::add(const ContentLine & cl) | 254 | VCard::add(const ContentLine & cl) |
255 | { | 255 | { |
256 | parse(); | 256 | parse(); |
257 | ContentLine * c = new ContentLine(cl); | 257 | ContentLine * c = new ContentLine(cl); |
258 | contentLineList_.append(c); | 258 | contentLineList_.append(c); |
259 | } | 259 | } |
260 | 260 | ||
261 | void | 261 | void |
262 | VCard::add(const QCString & s) | 262 | VCard::add(const QCString & s) |
263 | { | 263 | { |
264 | parse(); | 264 | parse(); |
265 | ContentLine * c = new ContentLine(s); | 265 | ContentLine * c = new ContentLine(s); |
266 | contentLineList_.append(c); | 266 | contentLineList_.append(c); |
267 | } | 267 | } |
268 | 268 | ||
269 | ContentLine * | 269 | ContentLine * |
270 | VCard::contentLine(EntityType t) | 270 | VCard::contentLine(EntityType t) |
271 | { | 271 | { |
272 | parse(); | 272 | parse(); |
273 | QPtrListIterator<ContentLine> it(contentLineList_); | 273 | QPtrListIterator<ContentLine> it(contentLineList_); |
274 | 274 | ||
275 | for (; it.current(); ++it) | 275 | for (; it.current(); ++it) |
276 | if (it.current()->entityType() == t) | 276 | if (it.current()->entityType() == t) |
277 | return it.current(); | 277 | return it.current(); |
278 | 278 | ||
279 | return 0; | 279 | return 0; |
280 | } | 280 | } |
281 | 281 | ||
282 | ContentLine * | 282 | ContentLine * |
283 | VCard::contentLine(const QCString & s) | 283 | VCard::contentLine(const QCString & s) |
284 | { | 284 | { |
285 | parse(); | 285 | parse(); |
286 | QPtrListIterator<ContentLine> it(contentLineList_); | 286 | QPtrListIterator<ContentLine> it(contentLineList_); |
287 | 287 | ||
288 | for (; it.current(); ++it) | 288 | for (; it.current(); ++it) |
289 | if (it.current()->entityType() == EntityNameToEntityType(s)) | 289 | if (it.current()->entityType() == EntityNameToEntityType(s)) |
290 | return it.current(); | 290 | return it.current(); |
291 | 291 | ||
292 | return 0; | 292 | return 0; |
293 | } | 293 | } |
294 | 294 | ||