summaryrefslogtreecommitdiffabout
path: root/kabc/vcard/ContentLine.cpp
Unidiff
Diffstat (limited to 'kabc/vcard/ContentLine.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/ContentLine.cpp36
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
@@ -8,34 +8,34 @@
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>
@@ -85,167 +85,167 @@ ContentLine::ContentLine(const ContentLine & x)
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
101ContentLine::ContentLine(const QCString & s) 101ContentLine::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 &
112ContentLine::operator = (ContentLine & x) 112ContentLine::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 &
132ContentLine::operator = (const QCString & s) 132ContentLine::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
141ContentLine::operator == (ContentLine & x) 141ContentLine::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
153ContentLine::~ContentLine() 153ContentLine::~ContentLine()
154{ 154{
155 delete value_; 155 delete value_;
156 value_ = 0; 156 value_ = 0;
157} 157}
158 158
159 void 159 void
160ContentLine::_parse() 160ContentLine::_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;
@@ -296,33 +296,33 @@ ContentLine::_assemble()
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