summaryrefslogtreecommitdiffabout
path: root/kabc/vcard
Unidiff
Diffstat (limited to 'kabc/vcard') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/ContentLine.cpp30
-rw-r--r--kabc/vcard/VCardv.cpp77
2 files changed, 65 insertions, 42 deletions
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp
index c368172..2f88cde 100644
--- a/kabc/vcard/ContentLine.cpp
+++ b/kabc/vcard/ContentLine.cpp
@@ -272,8 +272,35 @@ ContentLine::_parse()
272 272
273 void 273 void
274ContentLine::_assemble() 274ContentLine::_assemble()
275{ 275{
276 //strRep_.truncate(0);
277 QString line;
278 if (!group_.isEmpty())
279 line = group_ + '.';
280 line += name_;
281 ParamListIterator it(paramList_);
282 for (; it.current(); ++it)
283 line += ";" + it.current()->asString();
284
285 if (value_ != 0)
286 line += ":" + value_->asString();
287
288 line = line.replace( QRegExp( "\n" ), "\\n" );
289
290 // Fold lines longer than 72 chars
291 const int maxLen = 72;
292 uint cursor = 0;
293 QString cut;
294 while( line.length() > ( cursor + 1 ) * maxLen ) {
295 cut += line.mid( cursor * maxLen, maxLen );
296 cut += "\r\n ";
297 ++cursor;
298 }
299 cut += line.mid( cursor * maxLen );
300 strRep_ = cut.latin1();
301 //qDebug("ContentLine::_assemble()\n%s*****", strRep_.data());
302#if 0
276 vDebug("Assemble (argl) - my name is \"" + name_ + "\""); 303 vDebug("Assemble (argl) - my name is \"" + name_ + "\"");
277 strRep_.truncate(0); 304 strRep_.truncate(0);
278 305
279 QCString line; 306 QCString line;
@@ -306,9 +333,10 @@ ContentLine::_assemble()
306 strRep_ += "\r\n "; 333 strRep_ += "\r\n ";
307 ++cursor; 334 ++cursor;
308 } 335 }
309 strRep_ += line.mid( cursor * maxLen ); 336 strRep_ += line.mid( cursor * maxLen );
310 //qDebug("ContentLine::_assemble()\n%s*****", strRep_.data()); 337 qDebug("ContentLine::_assemble()\n%s*****", strRep_.data());
338#endif
311} 339}
312 340
313 void 341 void
314ContentLine::clear() 342ContentLine::clear()
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp
index bc80707..49bfe43 100644
--- a/kabc/vcard/VCardv.cpp
+++ b/kabc/vcard/VCardv.cpp
@@ -22,8 +22,11 @@
22*/ 22*/
23 23
24#include <qcstring.h> 24#include <qcstring.h>
25#include <qstrlist.h> 25#include <qstrlist.h>
26#include <qstringlist.h>
27#include <qstring.h>
28#include <qvaluelist.h>
26 29
27#include <VCardEntity.h> 30#include <VCardEntity.h>
28#include <VCardVCard.h> 31#include <VCardVCard.h>
29#include <VCardContentLine.h> 32#include <VCardContentLine.h>
@@ -95,32 +98,31 @@ VCard::~VCard()
95 98
96 void 99 void
97VCard::_parse() 100VCard::_parse()
98{ 101{
99 vDebug("parse() called"); 102
100 QStrList l; 103 QStringList l;
104 QStrList sl;
101 105
102 RTokenise(strRep_, "\r\n", l); 106 RTokenise(strRep_, "\r\n", sl);
103 107
104 if (l.count() < 3) { // Invalid VCARD ! 108 if (sl.count() < 3) { // Invalid VCARD !
105 vDebug("Invalid vcard"); 109 //qDebug("invalid vcard ");
106 return; 110 return;
107 } 111 }
108 112 l = QStringList::fromStrList( sl );
109 // Get the first line 113 // Get the first line
110 QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); 114 QString beginLine = l[0].stripWhiteSpace();
111
112 vDebug("Begin line == \"" + beginLine + "\"");
113 115
114 // Remove extra blank lines 116 // Remove extra blank lines
115 while (QCString(l.last()).isEmpty()) 117 while (l.last().isEmpty())
116 l.remove(l.last()); 118 l.remove(l.last());
117 119
118 // Now we know this is the last line 120 // Now we know this is the last line
119 QCString endLine = l.last(); 121 QString endLine = l.last();
120 122
121 // Trash the first and last lines as we have seen them. 123 // Trash the first and last lines as we have seen them.
122 l.remove(0u); 124 l.remove(l.first());
123 l.remove(l.last()); 125 l.remove(l.last());
124 126
125 /////////////////////////////////////////////////////////////// 127 ///////////////////////////////////////////////////////////////
126 // FIRST LINE 128 // FIRST LINE
@@ -131,25 +133,25 @@ VCard::_parse()
131 vDebug("No split"); 133 vDebug("No split");
132 return; 134 return;
133 } 135 }
134 136
135 QCString firstPart(beginLine.left(split)); 137 QString firstPart(beginLine.left(split));
136 QCString valuePart(beginLine.mid(split + 1)); 138 QString valuePart(beginLine.mid(split + 1));
137 139
138 split = firstPart.find('.'); 140 split = firstPart.find('.');
139 141
140 if (split != -1) { 142 if (split != -1) {
141 group_ = firstPart.left(split); 143 group_ = firstPart.left(split);
142 firstPart= firstPart.right(firstPart.length() - split - 1); 144 firstPart= firstPart.right(firstPart.length() - split - 1);
143 } 145 }
144 146
145 if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! 147 if (firstPart.left(5) != "BEGIN" ) { // No BEGIN !
146 vDebug("No BEGIN"); 148 qDebug("no BEGIN in vcard ");
147 return; 149 return;
148 } 150 }
149 151
150 if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! 152 if (valuePart.left(5) != "VCARD") { // Not a vcard !
151 vDebug("No VCARD"); 153 qDebug("not a VCARD ");
152 return; 154 return;
153 } 155 }
154 156
155 /////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////
@@ -158,44 +160,32 @@ VCard::_parse()
158 vDebug("Content lines"); 160 vDebug("Content lines");
159 161
160 // Handle folded lines. 162 // Handle folded lines.
161 163
162 QStrList refolded; 164 QStringList refolded;
163
164 QStrListIterator it(l);
165 165
166 QCString cur;
167 166
168 for (; it.current(); ++it) { 167 QStringList::Iterator it = l.begin();
169 168
170 cur = it.current(); 169 QString cur;
171 170
171 for (; it != l.end(); ++it) {
172 cur = (*it);
172 ++it; 173 ++it;
173 174 while ( it!= l.end() && (*it).at(0) == ' '&& (*it).length()!= 1) {
174 while ( 175 cur += (*it) ;
175 it.current() &&
176 it.current()[0] == ' '&&
177 strlen(it.current()) != 1)
178 {
179 cur += it.current() + 1;
180 ++it; 176 ++it;
181 } 177 }
182
183 --it; 178 --it;
184
185 refolded.append(cur); 179 refolded.append(cur);
186 } 180 }
187 181 QStringList::Iterator it2 = refolded.begin();
188 QStrListIterator it2(refolded); 182 for (; it2 != refolded.end(); ++it2) {
189 183 ContentLine * cl = new ContentLine(QCString((*it2).latin1()));
190 for (; it2.current(); ++it2) {
191 vDebug("New contentline using \"" + QCString(it2.current()) + "\"");
192 ContentLine * cl = new ContentLine(it2.current());
193
194 cl->parse(); 184 cl->parse();
195 if (cl->value() == 0) 185 if (cl->value() == 0)
196 { 186 {
197 qDebug("Content line could not be parsed. Discarded: %s", it2.current()); 187 qDebug("Content line could not be parsed. Discarded: %s", (*it2).latin1());
198 delete cl; 188 delete cl;
199 } 189 }
200 else 190 else
201 contentLineList_.append(cl); 191 contentLineList_.append(cl);
@@ -203,8 +193,12 @@ VCard::_parse()
203 193
204 /////////////////////////////////////////////////////////////// 194 ///////////////////////////////////////////////////////////////
205 // LAST LINE 195 // LAST LINE
206 196
197
198 // LR: sorry, but the remaining code in this method makes no sense
199
200#if 0
207 split = endLine.find(':'); 201 split = endLine.find(':');
208 202
209 if (split == -1) // invalid, no END 203 if (split == -1) // invalid, no END
210 return; 204 return;
@@ -223,8 +217,9 @@ VCard::_parse()
223 return; 217 return;
224 218
225 if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! 219 if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard !
226 return; 220 return;
221#endif
227} 222}
228 223
229 void 224 void
230VCard::_assemble() 225VCard::_assemble()