gloox  0.9.9.12
vcard.h
1 /*
2  Copyright (c) 2006-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef VCARD_H__
15 #define VCARD_H__
16 
17 #include "gloox.h"
18 
19 namespace gloox
20 {
21 
22  class Tag;
23 
33  class GLOOX_API VCard
34  {
35  public:
45  {
46  AddrTypeHome = 1,
47  AddrTypeWork = 2,
48  AddrTypePref = 4,
49  AddrTypeX400 = 8,
50  AddrTypeInet = 16,
51  AddrTypeParcel = 32,
52  AddrTypePostal = 64,
53  AddrTypeDom = 128,
54  AddrTypeIntl = 256,
55  AddrTypeVoice = 512,
56  AddrTypeFax = 1024,
57  AddrTypePager = 2048,
58  AddrTypeMsg = 4096,
59  AddrTypeCell = 8192,
60  AddrTypeVideo = 16384,
61  AddrTypeBbs = 32768,
62  AddrTypeModem = 65536,
63  AddrTypeIsdn = 131072,
64  AddrTypePcs = 262144
65  };
66 
70  struct Name
71  {
72  std::string family;
73  std::string given;
74  std::string middle;
75  std::string prefix;
76  std::string suffix;
77  };
78 
83  {
84  ClassNone = 0,
85  ClassPublic = 1,
86  ClassPrivate = 2,
87  ClassConfidential = 4
88  };
89 
93  struct Email
94  {
95  std::string userid;
96  bool home;
97  bool work;
98  bool internet;
99  bool pref;
100  bool x400;
101  };
102 
106  typedef std::list<Email> EmailList;
107 
111  struct Telephone
112  {
113  std::string number;
114  bool home;
115  bool work;
116  bool voice;
117  bool fax;
118  bool pager;
119  bool msg;
120  bool cell;
121  bool video;
122  bool bbs;
123  bool modem;
124  bool isdn;
125  bool pcs;
126  bool pref;
127  };
128 
132  typedef std::list<Telephone> TelephoneList;
133 
137  struct Address
138  {
139  std::string pobox;
140  std::string extadd;
141  std::string street;
142  std::string locality;
143  std::string region;
144  std::string pcode;
145  std::string ctry;
146  bool home;
147  bool work;
148  bool postal;
149  bool parcel;
150  bool pref;
151  bool dom;
152  bool intl;
153  };
154 
158  struct Label
159  {
161  bool home;
162  bool work;
163  bool postal;
164  bool parcel;
165  bool pref;
166  bool dom;
167  bool intl;
168  };
169 
173  struct Geo
174  {
175  std::string latitude;
176  std::string longitude;
177  };
178 
182  struct Org
183  {
184  std::string name;
185  StringList units;
187  };
188 
192  struct Photo
193  {
194  std::string extval;
196  std::string binval;
197  std::string type;
198  };
199 
203  typedef std::list<Address> AddressList;
204 
208  typedef std::list<Label> LabelList;
209 
213  VCard();
214 
219  VCard( Tag* vcard );
220 
224  virtual ~VCard() {}
225 
230  Tag* tag() const;
231 
236  void setFormattedname( const std::string& name ) { m_formattedname = name; }
237 
242  const std::string& formattedname() const { return m_formattedname; }
243 
252  void setName( const std::string& family, const std::string& given, const std::string& middle = "",
253  const std::string& prefix = "", const std::string& suffix = "" );
254 
259  const Name& name() const { return m_name; }
260 
265  void setNickname( const std::string& nickname ) { m_nickname = nickname; }
266 
271  const std::string& nickname() const { return m_nickname; }
272 
277  void setUrl( const std::string& url ) { m_url = url; }
278 
283  const std::string& url() const { return m_url; }
284 
289  void setBday( const std::string& bday ) { m_bday = bday; }
290 
295  const std::string& bday() const { return m_bday; }
296 
301  void setJabberid( const std::string& jabberid ) { m_jabberid = jabberid; }
302 
307  const std::string& jabberid() const { return m_jabberid; }
308 
313  void setTitle( const std::string& title ) { m_title = title; }
314 
319  const std::string& title() const { return m_title; }
320 
325  void setRole( const std::string& role ) { m_role = role; }
326 
331  const std::string& role() const { return m_role; }
332 
337  void setNote( const std::string& note ) { m_note = note; }
338 
343  const std::string& note() const { return m_note; }
344 
349  void setDesc( const std::string& desc ) { m_desc = desc; }
350 
355  const std::string& desc() const { return m_desc; }
356 
361  void setMailer( const std::string& mailer ) { m_mailer = mailer; }
362 
367  const std::string& mailer() const { return m_mailer; }
368 
373  void setRev( const std::string& rev ) { m_rev = rev; }
374 
379  const std::string& rev() const { return m_rev; }
380 
385  void setUid( const std::string& uid ) { m_uid = uid; }
386 
391  const std::string& uid() const { return m_uid; }
392 
398  void setTz( const std::string& tz ) { m_tz = tz; }
399 
404  const std::string& tz() const { return m_tz; }
405 
410  void setProdid( const std::string& prodid ) { m_prodid = prodid; }
411 
416  const std::string& prodid() const { return m_prodid; }
417 
422  void setSortstring( const std::string& sortstring ) { m_sortstring = sortstring; }
423 
428  const std::string& sortstring() const { return m_sortstring; }
429 
434  void setPhoto( const std::string& extval );
435 
441  void setPhoto( const std::string& type, const std::string& binval );
442 
447  const Photo& photo() const { return m_photo; }
448 
453  void setLogo( const std::string& extval );
454 
460  void setLogo( const std::string& type, const std::string& binval );
461 
466  const Photo& logo() const { return m_logo; }
467 
473  void addEmail( const std::string& userid, int type );
474 
479  EmailList& emailAddresses() { return m_emailList; }
480 
492  void addAddress( const std::string& pobox, const std::string& extadd,
493  const std::string& street, const std::string& locality,
494  const std::string& region, const std::string& pcode,
495  const std::string& ctry, int type );
496 
502  void addLabel( const StringList& lines, int type );
503 
508  AddressList& addresses() { return m_addressList; }
509 
514  LabelList& labels() { return m_labelList; }
515 
521  void addTelephone( const std::string& number, int type );
522 
527  TelephoneList& telephone() { return m_telephoneList; }
528 
535  void setGeo( const std::string& lat, const std::string& lon );
536 
541  const Geo& geo() const { return m_geo; }
542 
548  void setOrganization( const std::string& orgname, const StringList& orgunits );
549 
554  const Org& org() const { return m_org; }
555 
560  void setClass( VCardClassification vclass ) { m_class = vclass; }
561 
566  VCardClassification classification() const { return m_class; }
567 
568 
569  private:
570  void checkField( Tag *vcard, const std::string& field, std::string& var );
571  void insertField( Tag *vcard, const std::string& field, const std::string& var ) const;
572  void insertField( Tag *vcard, const std::string& field, bool var ) const;
573 
574 
575  EmailList m_emailList;
576  TelephoneList m_telephoneList;
577  AddressList m_addressList;
578  LabelList m_labelList;
579 
580  Name m_name;
581  Geo m_geo;
582  Org m_org;
583  Photo m_photo;
584  Photo m_logo;
585 
586  VCardClassification m_class;
587 
588  std::string m_formattedname;
589  std::string m_nickname;
590  std::string m_url;
591  std::string m_bday;
592  std::string m_jabberid;
593  std::string m_title;
594  std::string m_role;
595  std::string m_note;
596  std::string m_desc;
597  std::string m_mailer;
598  std::string m_tz;
599  std::string m_prodid;
600  std::string m_rev;
601  std::string m_sortstring;
602  std::string m_uid;
603 
604  bool m_N;
605  bool m_PHOTO;
606  bool m_LOGO;
607  };
608 
609 }
610 
611 #endif // VCARD_H__