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

tdeabc

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

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.8.8
This website is maintained by Timothy Pearson.