Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / EvolutionContactSource.h
1 /*
2  * Copyright (C) 2005-2006 Patrick Ohly
3  * Copyright (C) 2007 Funambol
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #ifndef INCL_EVOLUTIONCONTACTSOURCE
21 #define INCL_EVOLUTIONCONTACTSOURCE
22
23 #include <config.h>
24 #include "EvolutionSyncSource.h"
25 #include "EvolutionSmartPtr.h"
26
27 #ifdef ENABLE_EBOOK
28
29 #include <libebook/e-book.h>
30 #include <libebook/e-vcard.h>
31
32 #include <set>
33
34 /**
35  * Implements access to Evolution address books.
36  */
37 class EvolutionContactSource : public EvolutionSyncSource
38 {
39   public:
40     EvolutionContactSource(const EvolutionSyncSourceParams &params,
41                            EVCardFormat vcardFormat = EVC_FORMAT_VCARD_30);
42     EvolutionContactSource(const EvolutionContactSource &other);
43     virtual ~EvolutionContactSource() { close(); }
44
45     // utility function: extract vcard from item in format suitable for Evolution
46     string preparseVCard(SyncItem& item);
47
48     //
49     // implementation of EvolutionSyncSource
50     //
51     virtual sources getSyncBackends();
52     virtual void open();
53     virtual void close(); 
54     virtual void exportData(ostream &out);
55     virtual string fileSuffix() { return "vcf"; }
56     virtual const char *getMimeType() const;
57     virtual const char *getMimeVersion() const;
58     virtual const char *getSupportedTypes() const { return "text/vcard:3.0,text/x-vcard:2.1"; }
59    
60     virtual SyncItem *createItem(const string &uid);
61     
62   protected:
63     //
64     // implementation of EvolutionSyncSource callbacks
65     //
66     virtual void beginSyncThrow(bool needAll,
67                                 bool needPartial,
68                                 bool deleteLocal);
69     virtual void endSyncThrow();
70     virtual void setItemStatusThrow(const char *key, int status);
71     virtual int addItemThrow(SyncItem& item);
72     virtual int updateItemThrow(SyncItem& item);
73     virtual int deleteItemThrow(SyncItem& item);
74     virtual void logItem(const string &uid, const string &info, bool debug = false);
75     virtual void logItem(const SyncItem &item, const string &info, bool debug = false);
76
77   private:
78     /** valid after open(): the address book that this source references */
79     eptr<EBook, GObject> m_addressbook;
80
81     /** the format of vcards that new items are expected to have */
82     const EVCardFormat m_vcardFormat;
83
84     /**
85      * a list of Evolution vcard properties which have to be encoded
86      * as X-SYNCEVOLUTION-* when sending to server in 2.1 and decoded
87      * back when receiving.
88      */
89     static const class extensions : public set<string> {
90       public:
91         extensions() : prefix("X-SYNCEVOLUTION-") {
92             this->insert("FBURL");
93             this->insert("CALURI");
94         }
95
96         const string prefix;
97     } m_vcardExtensions;
98
99     /**
100      * a list of properties which SyncEvolution (in contrast to
101      * the server) will only store once in each contact
102      */
103     static const class unique : public set<string> {
104       public:
105         unique () {
106             insert("X-AIM");
107             insert("X-GROUPWISE");
108             insert("X-ICQ");
109             insert("X-YAHOO");
110             insert("X-EVOLUTION-ANNIVERSARY");
111             insert("X-EVOLUTION-ASSISTANT");
112             insert("X-EVOLUTION-BLOG-URL");
113             insert("X-EVOLUTION-FILE-AS");
114             insert("X-EVOLUTION-MANAGER");
115             insert("X-EVOLUTION-SPOUSE");
116             insert("X-EVOLUTION-VIDEO-URL");
117             insert("X-MOZILLA-HTML");
118             insert("FBURL");
119             insert("CALURI");
120         }
121     } m_uniqueProperties;
122 };
123
124 #endif // ENABLE_EBOOK
125
126 #endif // INCL_EVOLUTIONCONTACTSOURCE