• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
  • vcard
ContentLine.cpp
1 /*
2  libvcard - vCard parsing library for vCard version 3.0
3 
4  Copyright (C) 1999 Rik Hemsley rik@kde.org
5 
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
8  deal in the Software without restriction, including without limitation the
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
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
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,
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
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.
22 */
23 
24 #include <tqcstring.h>
25 #include <tqstrlist.h>
26 #include <tqregexp.h>
27 
28 #include <kdebug.h>
29 
30 #include <VCardAdrParam.h>
31 #include <VCardAgentParam.h>
32 #include <VCardDateParam.h>
33 #include <VCardEmailParam.h>
34 #include <VCardImageParam.h>
35 #include <VCardSourceParam.h>
36 #include <VCardTelParam.h>
37 #include <VCardTextBinParam.h>
38 #include <VCardTextParam.h>
39 
40 #include <VCardAdrValue.h>
41 #include <VCardAgentValue.h>
42 #include <VCardDateValue.h>
43 #include <VCardImageValue.h>
44 #include <VCardTextValue.h>
45 #include <VCardTextBinValue.h>
46 #include <VCardLangValue.h>
47 #include <VCardNValue.h>
48 #include <VCardURIValue.h>
49 #include <VCardSoundValue.h>
50 #include <VCardClassValue.h>
51 #include <VCardFloatValue.h>
52 #include <VCardOrgValue.h>
53 #include <VCardTelValue.h>
54 #include <VCardTextListValue.h>
55 #include <VCardUTCValue.h>
56 #include <VCardGeoValue.h>
57 
58 #include <VCardRToken.h>
59 #include <VCardContentLine.h>
60 
61 #include <VCardEntity.h>
62 #include <VCardEnum.h>
63 #include <VCardDefines.h>
64 
65 using namespace VCARD;
66 
67 ContentLine::ContentLine()
68  : Entity(),
69  value_(0),
70  paramType_( ParamUnknown ),
71  valueType_( ValueUnknown ),
72  entityType_( EntityUnknown )
73 {
74 }
75 
76 ContentLine::ContentLine(const ContentLine & x)
77  : Entity(x),
78  group_ (x.group_),
79  name_ (x.name_),
80  paramList_(x.paramList_),
81  value_(x.value_->clone()),
82  paramType_( x.paramType_ ),
83  valueType_( x.valueType_ ),
84  entityType_( x.entityType_ )
85 {
86 }
87 
88 ContentLine::ContentLine(const TQCString & s)
89  : Entity(s),
90  value_(0),
91  paramType_( ParamUnknown ),
92  valueType_( ValueUnknown ),
93  entityType_( EntityUnknown )
94 {
95 }
96 
97  ContentLine &
98 ContentLine::operator = (ContentLine & x)
99 {
100  if (*this == x) return *this;
101 
102  paramList_ = x.paramList();
103  value_ = x.value_->clone();
104 
105  Entity::operator = (x);
106  return *this;
107 }
108 
109  ContentLine &
110 ContentLine::operator = (const TQCString & s)
111 {
112  Entity::operator = (s);
113  delete value_;
114  value_ = 0;
115  return *this;
116 }
117 
118  bool
119 ContentLine::operator == (ContentLine & x)
120 {
121  x.parse();
122 
123  TQPtrListIterator<Param> it(x.paramList());
124 
125  if (!paramList_.find(it.current()))
126  return false;
127 
128  return true;
129 }
130 
131 ContentLine::~ContentLine()
132 {
133  delete value_;
134  value_ = 0;
135 }
136 
137  void
138 ContentLine::_parse()
139 {
140  vDebug("parse");
141 
142  // Unqote newlines
143  strRep_ = strRep_.replace( TQRegExp( "\\\\n" ), "\n" );
144 
145  int split = strRep_.find(':');
146 
147  if (split == -1) { // invalid content line
148  vDebug("No ':'");
149  return;
150  }
151 
152  TQCString firstPart(strRep_.left(split));
153  TQCString valuePart(strRep_.mid(split + 1));
154 
155  split = firstPart.find('.');
156 
157  if (split != -1) {
158  group_ = firstPart.left(split);
159  firstPart = firstPart.mid(split + 1);
160  }
161 
162  vDebug("Group == " + group_);
163  vDebug("firstPart == " + firstPart);
164  vDebug("valuePart == " + valuePart);
165 
166  // Now we have the group, the name and param list together and the value.
167 
168  TQStrList l;
169 
170  RTokenise(firstPart, ";", l);
171 
172  if (l.count() == 0) {// invalid - no name !
173  vDebug("No name for this content line !");
174  return;
175  }
176 
177  name_ = l.at(0);
178 
179  // Now we have the name, so the rest of 'l' is the params.
180  // Remove the name part.
181  l.remove(0u);
182 
183  entityType_ = EntityNameToEntityType(name_);
184  paramType_ = EntityTypeToParamType(entityType_);
185 
186  unsigned int i = 0;
187 
188  // For each parameter, create a new parameter of the correct type.
189 
190  TQStrListIterator it(l);
191 
192  for (; it.current(); ++it, i++) {
193 
194  TQCString str = *it;
195 
196  split = str.find("=");
197  if (split < 0 ) {
198  vDebug("No '=' in parameter.");
199  continue;
200  }
201 
202  TQCString paraName = str.left(split);
203  TQCString paraValue = str.mid(split + 1);
204 
205  TQStrList paraValues;
206  RTokenise(paraValue, ",", paraValues);
207 
208  TQStrListIterator it2( paraValues );
209 
210  for(; it2.current(); ++it2) {
211 
212  Param *p = new Param;
213  p->setName( paraName );
214  p->setValue( *it2 );
215 
216  paramList_.append(p);
217  }
218  }
219 
220  // Create a new value of the correct type.
221 
222  valueType_ = EntityTypeToValueType(entityType_);
223 
224 // kdDebug(5710) << "valueType: " << valueType_ << endl;
225 
226  switch (valueType_) {
227 
228  case ValueSound: value_ = new SoundValue; break;
229  case ValueAgent: value_ = new AgentValue; break;
230  case ValueAddress: value_ = new AdrValue; break;
231  case ValueTel: value_ = new TelValue; break;
232  case ValueTextBin: value_ = new TextBinValue; break;
233  case ValueOrg: value_ = new OrgValue; break;
234  case ValueN: value_ = new NValue; break;
235  case ValueUTC: value_ = new UTCValue; break;
236  case ValueURI: value_ = new URIValue; break;
237  case ValueClass: value_ = new ClassValue; break;
238  case ValueFloat: value_ = new FloatValue; break;
239  case ValueImage: value_ = new ImageValue; break;
240  case ValueDate: value_ = new DateValue; break;
241  case ValueTextList: value_ = new TextListValue; break;
242  case ValueGeo: value_ = new GeoValue; break;
243  case ValueText:
244  case ValueUnknown:
245  default: value_ = new TextValue; break;
246  }
247 
248  *value_ = valuePart;
249 }
250 
251  void
252 ContentLine::_assemble()
253 {
254  vDebug("Assemble (argl) - my name is \"" + name_ + "\"");
255  strRep_.truncate(0);
256 
257  TQCString line;
258 
259  if (!group_.isEmpty())
260  line += group_ + '.';
261 
262  line += name_;
263 
264  vDebug("Adding parameters");
265  ParamListIterator it(paramList_);
266 
267  for (; it.current(); ++it)
268  line += ";" + it.current()->asString();
269 
270  vDebug("Adding value");
271  if (value_ != 0)
272  line += ":" + value_->asString();
273  else {
274  vDebug("No value");
275  }
276 
277  // Quote newlines
278  line = line.replace( TQRegExp( "\n" ), "\\n" );
279 
280  // Fold lines longer than 72 chars
281  const int maxLen = 72;
282  uint cursor = 0;
283  while( line.length() > ( cursor + 1 ) * maxLen ) {
284  strRep_ += line.mid( cursor * maxLen, maxLen );
285  strRep_ += "\r\n ";
286  ++cursor;
287  }
288  strRep_ += line.mid( cursor * maxLen );
289 }
290 
291  void
292 ContentLine::clear()
293 {
294  group_.truncate(0);
295  name_.truncate(0);
296  paramList_.clear();
297  delete value_;
298  value_ = 0;
299  paramType_ = ParamUnknown;
300  valueType_ = ValueUnknown;
301  entityType_ = EntityUnknown;
302 }

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.9.1
This website is maintained by Timothy Pearson.