vcard.h

Go to the documentation of this file.
00001 ///
00002 /// \file       vcard.h
00003 ///             Conversion routines for vcards
00004 ///
00005 
00006 /*
00007     Copyright (C) 2006-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_SYNC_VCARD_H__
00023 #define __BARRY_SYNC_VCARD_H__
00024 
00025 #include "dll.h"
00026 #include "vbase.h"
00027 #include "r_contact.h"
00028 #include <stdint.h>
00029 #include <string>
00030 
00031 namespace Barry { namespace Sync {
00032 
00033 //
00034 // vCard
00035 //
00036 /// Class for converting between RFC 2425/2426 vCard data format,
00037 /// and the Barry::Contact class.
00038 ///
00039 class BXEXPORT vCard : public vBase
00040 {
00041         // data to pass to external requests
00042         char *m_gCardData;      // dynamic memory returned by vformat()... can
00043                                 // be used directly by the plugin, without
00044                                 // overmuch allocation and freeing (see Extract())
00045         std::string m_vCardData;// copy of m_gCardData, for C++ use
00046         Barry::Contact m_BarryContact;
00047 
00048 protected:
00049         void AddAddress(const char *rfc_type, const Barry::PostalAddress &addr);
00050         void AddPhoneCond(const std::string &phone);
00051         void AddPhoneCond(const char *rfc_type, const std::string &phone);
00052 
00053         void ParseAddress(vAttr &adr, Barry::PostalAddress &address);
00054         void ParseCategories(vAttr &cat, Barry::CategoryList &cats);
00055 
00056 public:
00057         vCard();
00058         ~vCard();
00059 
00060         const std::string&      ToVCard(const Barry::Contact &con);
00061         const Barry::Contact&   ToBarry(const char *vcal, uint32_t RecordId);
00062 
00063         const std::string&      GetVCard() const { return m_vCardData; }
00064         const Barry::Contact&   GetBarryContact() const { return m_BarryContact; }
00065 
00066         char* ExtractVCard();
00067 
00068         void Clear();
00069 
00070         // This is the v-name of the innermost BEGIN/END block
00071         static const char* GetVName() { return "VCARD"; }
00072 };
00073 
00074 }} // namespace Barry::Sync
00075 
00076 #endif
00077