summaryrefslogtreecommitdiff
path: root/src/backends/sqlite/SQLiteContactSource.h
blob: a72de8e7a8bb20c4f6ec54ae40c60e12d28ae355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright (C) 2007-2008 Patrick Ohly
 */

#ifndef INCL_SQLITECONTACTSOURCE
#define INCL_SQLITECONTACTSOURCE

#include "TrackingSyncSource.h"
#include "SQLiteUtil.h"

#ifdef ENABLE_SQLITE

/**
 * Uses SQLiteUtil for contacts with a schema inspired by the one used
 * by Mac OS X.  That schema has hierarchical tables which is not
 * supported by SQLiteUtil, therefore SQLiteContactSource uses a
 * simplified schema where each contact consists of one row in the
 * database table.
 *
 * The handling of the "N" and "ORG" property shows how mapping
 * between one property and multiple different columns works.
 *
 * Properties which can occur more than once per contact like address,
 * email and phone numbers are not supported. They would have to be
 * stored in additional tables.
 *
 * Change tracking is done by implementing a modification date as part
 * of each contact and using that as the revision string required by
 * TrackingSyncSource, which then takes care of change tracking.
 *
 * The database file is created automatically if the database ID is
 * file:///<path>.
 */
class SQLiteContactSource : public TrackingSyncSource
{
  public:
    SQLiteContactSource(const EvolutionSyncSourceParams &params) :
        TrackingSyncSource(params)
        {}

 protected:
    /* implementation of EvolutionSyncSource interface */
    virtual void open();
    virtual void close();
    virtual Databases getDatabases();
    virtual SyncItem *createItem(const string &uid);
    virtual string fileSuffix() const { return "vcf"; }
    virtual const char *getMimeType() const { return "text/x-vcard"; }
    virtual const char *getMimeVersion() const { return "2.1"; }
    virtual const char *getSupportedTypes()const { return "text/vcard:3.0,text/x-vcard:2.1"; }
    virtual void logItem(const string &uid, const string &info, bool debug = false);
    virtual void logItem(const SyncItem &item, const string &info, bool debug = false);

    /* implementation of TrackingSyncSource interface */
    virtual void listAllItems(RevisionMap_t &revisions);
    virtual InsertItemResult insertItem(const string &uid, const SyncItem &item);
    virtual void deleteItem(const string &uid);

 private:
    /** encapsulates access to database */
    SQLiteUtil m_sqlite;
};

#endif // ENABLE_SQLITE
#endif // INCL_SQLITECONTACTSOURCE