00001 /* 00002 * Copyright (C) 2007-2008 Patrick Ohly 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 #ifndef INCL_SQLITECONTACTSOURCE 00020 #define INCL_SQLITECONTACTSOURCE 00021 00022 #include "TrackingSyncSource.h" 00023 #include "SQLiteUtil.h" 00024 00025 #ifdef ENABLE_SQLITE 00026 00027 /** 00028 * Uses SQLiteUtil for contacts with a schema inspired by the one used 00029 * by Mac OS X. That schema has hierarchical tables which is not 00030 * supported by SQLiteUtil, therefore SQLiteContactSource uses a 00031 * simplified schema where each contact consists of one row in the 00032 * database table. 00033 * 00034 * The handling of the "N" and "ORG" property shows how mapping 00035 * between one property and multiple different columns works. 00036 * 00037 * Properties which can occur more than once per contact like address, 00038 * email and phone numbers are not supported. They would have to be 00039 * stored in additional tables. 00040 * 00041 * Change tracking is done by implementing a modification date as part 00042 * of each contact and using that as the revision string required by 00043 * TrackingSyncSource, which then takes care of change tracking. 00044 * 00045 * The database file is created automatically if the database ID is 00046 * file:///<path>. 00047 */ 00048 class SQLiteContactSource : public TrackingSyncSource 00049 { 00050 public: 00051 SQLiteContactSource(const EvolutionSyncSourceParams ¶ms) : 00052 TrackingSyncSource(params) 00053 {} 00054 00055 protected: 00056 /* implementation of EvolutionSyncSource interface */ 00057 virtual void open(); 00058 virtual void close(); 00059 virtual Databases getDatabases(); 00060 virtual SyncItem *createItem(const string &uid); 00061 virtual string fileSuffix() const { return "vcf"; } 00062 virtual const char *getMimeType() const { return "text/x-vcard"; } 00063 virtual const char *getMimeVersion() const { return "2.1"; } 00064 virtual const char *getSupportedTypes()const { return "text/vcard:3.0,text/x-vcard:2.1"; } 00065 virtual void logItem(const string &uid, const string &info, bool debug = false); 00066 virtual void logItem(const SyncItem &item, const string &info, bool debug = false); 00067 00068 /* implementation of TrackingSyncSource interface */ 00069 virtual void listAllItems(RevisionMap_t &revisions); 00070 virtual InsertItemResult insertItem(const string &uid, const SyncItem &item); 00071 virtual void deleteItem(const string &uid); 00072 00073 private: 00074 /** encapsulates access to database */ 00075 SQLiteUtil m_sqlite; 00076 }; 00077 00078 #endif // ENABLE_SQLITE 00079 #endif // INCL_SQLITECONTACTSOURCE