gloox  1.0.16
vcard.h
1 /*
2  Copyright (c) 2006-2015 by Jakob Schröter <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 #include "stanzaextension.h"
19 
20 namespace gloox
21 {
22 
23  class Tag;
24 
34  class GLOOX_API VCard : public StanzaExtension
35  {
36  public:
46  {
47  AddrTypeHome = 1,
48  AddrTypeWork = 2,
49  AddrTypePref = 4,
50  AddrTypeX400 = 8,
51  AddrTypeInet = 16,
52  AddrTypeParcel = 32,
53  AddrTypePostal = 64,
54  AddrTypeDom = 128,
55  AddrTypeIntl = 256,
56  AddrTypeVoice = 512,
57  AddrTypeFax = 1024,
58  AddrTypePager = 2048,
59  AddrTypeMsg = 4096,
60  AddrTypeCell = 8192,
61  AddrTypeVideo = 16384,
62  AddrTypeBbs = 32768,
63  AddrTypeModem = 65536,
64  AddrTypeIsdn = 131072,
65  AddrTypePcs = 262144
66  };
67 
71  struct Name
72  {
73  std::string family;
74  std::string given;
75  std::string middle;
76  std::string prefix;
77  std::string suffix;
78  };
79 
84  {
85  ClassNone = 0,
86  ClassPublic = 1,
87  ClassPrivate = 2,
88  ClassConfidential = 4
89  };
90 
94  struct Email
95  {
96  std::string userid;
97  bool home;
98  bool work;
99  bool internet;
100  bool pref;
101  bool x400;
102  };
103 
107  typedef std::list<Email> EmailList;
108 
112  struct Telephone
113  {
114  std::string number;
115  bool home;
116  bool work;
117  bool voice;
118  bool fax;
119  bool pager;
120  bool msg;
121  bool cell;
122  bool video;
123  bool bbs;
124  bool modem;
125  bool isdn;
126  bool pcs;
127  bool pref;
128  };
129 
133  typedef std::list<Telephone> TelephoneList;
134 
138  struct Address
139  {
140  std::string pobox;
141  std::string extadd;
142  std::string street;
143  std::string locality;
144  std::string region;
145  std::string pcode;
146  std::string ctry;
147  bool home;
148  bool work;
149  bool postal;
150  bool parcel;
151  bool pref;
152  bool dom;
153  bool intl;
154  };
155 
159  struct Label
160  {
162  bool home;
163  bool work;
164  bool postal;
165  bool parcel;
166  bool pref;
167  bool dom;
168  bool intl;
169  };
170 
174  struct Geo
175  {
176  std::string latitude;
177  std::string longitude;
178  };
179 
183  struct Org
184  {
185  std::string name;
188  };
189 
193  struct Photo
194  {
195  std::string extval;
197  std::string binval;
198  std::string type;
199  };
200 
204  typedef std::list<Address> AddressList;
205 
209  typedef std::list<Label> LabelList;
210 
214  VCard();
215 
220  VCard( const Tag* vcard );
221 
225  virtual ~VCard() {}
226 
231  void setFormattedname( const std::string& name ) { m_formattedname = name; }
232 
237  const std::string& formattedname() const { return m_formattedname; }
238 
247  void setName( const std::string& family, const std::string& given,
248  const std::string& middle = EmptyString,
249  const std::string& prefix = EmptyString,
250  const std::string& suffix = EmptyString );
251 
256  const Name& name() const { return m_name; }
257 
262  void setNickname( const std::string& nickname ) { m_nickname = nickname; }
263 
268  const std::string& nickname() const { return m_nickname; }
269 
274  void setUrl( const std::string& url ) { m_url = url; }
275 
280  const std::string& url() const { return m_url; }
281 
286  void setBday( const std::string& bday ) { m_bday = bday; }
287 
292  const std::string& bday() const { return m_bday; }
293 
298  void setJabberid( const std::string& jabberid ) { m_jabberid = jabberid; }
299 
304  const std::string& jabberid() const { return m_jabberid; }
305 
310  void setTitle( const std::string& title ) { m_title = title; }
311 
316  const std::string& title() const { return m_title; }
317 
322  void setRole( const std::string& role ) { m_role = role; }
323 
328  const std::string& role() const { return m_role; }
329 
334  void setNote( const std::string& note ) { m_note = note; }
335 
340  const std::string& note() const { return m_note; }
341 
346  void setDesc( const std::string& desc ) { m_desc = desc; }
347 
352  const std::string& desc() const { return m_desc; }
353 
358  void setMailer( const std::string& mailer ) { m_mailer = mailer; }
359 
364  const std::string& mailer() const { return m_mailer; }
365 
370  void setRev( const std::string& rev ) { m_rev = rev; }
371 
376  const std::string& rev() const { return m_rev; }
377 
382  void setUid( const std::string& uid ) { m_uid = uid; }
383 
388  const std::string& uid() const { return m_uid; }
389 
395  void setTz( const std::string& tz ) { m_tz = tz; }
396 
401  const std::string& tz() const { return m_tz; }
402 
407  void setProdid( const std::string& prodid ) { m_prodid = prodid; }
408 
413  const std::string& prodid() const { return m_prodid; }
414 
419  void setSortstring( const std::string& sortstring ) { m_sortstring = sortstring; }
420 
425  const std::string& sortstring() const { return m_sortstring; }
426 
431  void setPhotoUri( const std::string& extval );
432 
439  void setPhoto( const std::string& type = EmptyString, const std::string& binval = EmptyString );
440 
445  const Photo& photo() const { return m_photo; }
446 
451  void setLogo( const std::string& extval );
452 
459  void setLogo( const std::string& type = EmptyString, const std::string& binval = EmptyString );
460 
465  const Photo& logo() const { return m_logo; }
466 
472  void addEmail( const std::string& userid, int type );
473 
478  const EmailList& emailAddresses() const { return m_emailList; }
479 
491  void addAddress( const std::string& pobox, const std::string& extadd,
492  const std::string& street, const std::string& locality,
493  const std::string& region, const std::string& pcode,
494  const std::string& ctry, int type );
495 
501  void addLabel( const StringList& lines, int type );
502 
507  const AddressList& addresses() const { return m_addressList; }
508 
513  const LabelList& labels() const { return m_labelList; }
514 
520  void addTelephone( const std::string& number, int type );
521 
526  const TelephoneList& telephone() const { return m_telephoneList; }
527 
534  void setGeo( const std::string& lat, const std::string& lon );
535 
540  const Geo& geo() const { return m_geo; }
541 
547  void setOrganization( const std::string& orgname, const StringList& orgunits );
548 
553  const Org& org() const { return m_org; }
554 
559  void setClass( VCardClassification vclass ) { m_class = vclass; }
560 
565  const VCardClassification& classification() const { return m_class; }
566 
567  // reimplemented from StanzaExtension
568  virtual const std::string& filterString() const;
569 
570  // reimplemented from StanzaExtension
571  virtual StanzaExtension* newInstance( const Tag* tag ) const
572  {
573  return new VCard( tag );
574  }
575 
576  // reimplemented from StanzaExtension
577  virtual Tag* tag() const;
578 
579  // reimplemented from StanzaExtension
580  virtual StanzaExtension* clone() const
581  {
582  return new VCard( *this );
583  }
584 
585  private:
586 
587  static void insertField( Tag* vcard, const char* field, const std::string& var );
588  static void insertField( Tag* vcard, const char* field, bool var );
589  static void checkField ( const Tag* vcard, const char* field, std::string& var );
590 
591  EmailList m_emailList;
592  TelephoneList m_telephoneList;
593  AddressList m_addressList;
594  LabelList m_labelList;
595 
596  Name m_name;
597  Geo m_geo;
598  Org m_org;
599  Photo m_photo;
600  Photo m_logo;
601 
602  VCardClassification m_class;
603 
604  std::string m_formattedname;
605  std::string m_nickname;
606  std::string m_url;
607  std::string m_bday;
608  std::string m_jabberid;
609  std::string m_title;
610  std::string m_role;
611  std::string m_note;
612  std::string m_desc;
613  std::string m_mailer;
614  std::string m_tz;
615  std::string m_prodid;
616  std::string m_rev;
617  std::string m_sortstring;
618  std::string m_uid;
619 
620  bool m_N;
621  bool m_PHOTO;
622  bool m_LOGO;
623  };
624 
625 }
626 
627 #endif // VCARD_H__
void setTz(const std::string &tz)
Definition: vcard.h:395
void setNote(const std::string &note)
Definition: vcard.h:334
const EmailList & emailAddresses() const
Definition: vcard.h:478
void setRev(const std::string &rev)
Definition: vcard.h:370
std::string pcode
Definition: vcard.h:145
std::list< std::string > StringList
Definition: gloox.h:1244
virtual StanzaExtension * clone() const
Definition: vcard.h:580
std::string binval
Definition: vcard.h:197
std::string street
Definition: vcard.h:142
std::string latitude
Definition: vcard.h:176
void setDesc(const std::string &desc)
Definition: vcard.h:346
std::string suffix
Definition: vcard.h:77
std::string family
Definition: vcard.h:73
std::list< Label > LabelList
Definition: vcard.h:209
const Geo & geo() const
Definition: vcard.h:540
const std::string & formattedname() const
Definition: vcard.h:237
StringList units
Definition: vcard.h:186
void setNickname(const std::string &nickname)
Definition: vcard.h:262
const std::string & bday() const
Definition: vcard.h:292
const std::string & sortstring() const
Definition: vcard.h:425
void setBday(const std::string &bday)
Definition: vcard.h:286
std::string longitude
Definition: vcard.h:177
std::string name
Definition: vcard.h:185
void setClass(VCardClassification vclass)
Definition: vcard.h:559
void setTitle(const std::string &title)
Definition: vcard.h:310
void setMailer(const std::string &mailer)
Definition: vcard.h:358
std::string region
Definition: vcard.h:144
std::string prefix
Definition: vcard.h:76
const std::string & prodid() const
Definition: vcard.h:413
void setUrl(const std::string &url)
Definition: vcard.h:274
const std::string & mailer() const
Definition: vcard.h:364
const std::string & note() const
Definition: vcard.h:340
std::string pobox
Definition: vcard.h:140
void setProdid(const std::string &prodid)
Definition: vcard.h:407
const TelephoneList & telephone() const
Definition: vcard.h:526
std::string number
Definition: vcard.h:114
const Photo & photo() const
Definition: vcard.h:445
VCardClassification
Definition: vcard.h:83
void setRole(const std::string &role)
Definition: vcard.h:322
const std::string & uid() const
Definition: vcard.h:388
virtual ~VCard()
Definition: vcard.h:225
const std::string & role() const
Definition: vcard.h:328
void setSortstring(const std::string &sortstring)
Definition: vcard.h:419
void setJabberid(const std::string &jabberid)
Definition: vcard.h:298
const AddressList & addresses() const
Definition: vcard.h:507
std::string middle
Definition: vcard.h:75
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an element in a specific namespace...
const std::string & jabberid() const
Definition: vcard.h:304
const std::string & tz() const
Definition: vcard.h:401
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition: vcard.h:571
std::string ctry
Definition: vcard.h:146
const LabelList & labels() const
Definition: vcard.h:513
std::list< Email > EmailList
Definition: vcard.h:107
std::string userid
Definition: vcard.h:96
std::string locality
Definition: vcard.h:143
std::string extval
Definition: vcard.h:195
std::string given
Definition: vcard.h:74
std::string type
Definition: vcard.h:198
std::list< Address > AddressList
Definition: vcard.h:204
StringList lines
Definition: vcard.h:161
std::string extadd
Definition: vcard.h:141
const Photo & logo() const
Definition: vcard.h:465
const Name & name() const
Definition: vcard.h:256
A VCard abstraction.
Definition: vcard.h:34
void setFormattedname(const std::string &name)
Definition: vcard.h:231
const VCardClassification & classification() const
Definition: vcard.h:565
const Org & org() const
Definition: vcard.h:553
const std::string & rev() const
Definition: vcard.h:376
void setUid(const std::string &uid)
Definition: vcard.h:382
const std::string & desc() const
Definition: vcard.h:352
std::list< Telephone > TelephoneList
Definition: vcard.h:133
const std::string & title() const
Definition: vcard.h:316
const std::string EmptyString
Definition: gloox.cpp:123
const std::string & nickname() const
Definition: vcard.h:268
This is an abstraction of an XML element.
Definition: tag.h:46
const std::string & url() const
Definition: vcard.h:280