2 * Copyright (C) 2007 Patrick Ohly
3 * Copyright (C) 2007 Funambol
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.
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.
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
20 #ifndef INCL_FILESYNCSOURCE
21 #define INCL_FILESYNCSOURCE
23 #include "TrackingSyncSource.h"
28 #include <boost/noncopyable.hpp>
31 * Stores each SyncML item as a separate file in a directory. The
32 * directory has to be specified via the database name, using
33 * [file://]<path> as format. The file:// prefix is optional, but the
34 * directory is only created if it is used.
35 * EvolutionSyncSource::getDatabaseID() gives us the database name.
37 * Change tracking is done via the file systems modification time
38 * stamp: editing a file treats it as modified and then sends it to
39 * the server in the next sync. Removing and adding files also works.
41 * The local unique identifier for each item is its name in the
42 * directory. New files are created using a running count which
43 * initialized based on the initial content of the directory to
44 * "highest existing number + 1" and incremented to avoid collisions.
46 * Although this sync source itself does not care about the content of
47 * each item/file, the server needs to know what each item sent to it
48 * contains and what items the source is able to receive. Therefore
49 * the "type" property for this source must contain a data format
50 * specified, including a version for it. Here are some examples:
51 * - type=file:text/vcard:3.0
52 * - type=file:text/plain:1.0
54 class FileSyncSource : public TrackingSyncSource, private boost::noncopyable
57 FileSyncSource(const EvolutionSyncSourceParams ¶ms,
58 const string &dataformat);
62 /* implementation of EvolutionSyncSource interface */
65 virtual Databases getDatabases();
66 virtual SyncItem *createItem(const string &uid);
67 virtual string fileSuffix() const;
68 virtual const char *getMimeType() const;
69 virtual const char *getMimeVersion() const;
70 virtual const char *getSupportedTypes() const;
71 virtual void logItem(const string &uid, const string &info, bool debug = false);
72 virtual void logItem(const SyncItem &item, const string &info, bool debug = false);
74 /* implementation of TrackingSyncSource interface */
75 virtual void listAllItems(RevisionMap_t &revisions);
76 virtual InsertItemResult insertItem(const string &uid, const SyncItem &item);
77 virtual void deleteItem(const string &uid);
81 * @name values obtained from the source's type property
83 * Other sync sources only support one hard-coded type and
84 * don't need such variables.
89 string m_supportedTypes;
92 /** directory selected via the database name in open(), reset in close() */
94 /** a counter which is used to name new files */
98 * get access time for file, formatted as revision string
99 * @param filename absolute path or path relative to current directory
101 string getATimeString(const string &filename);
104 * create full filename from basedir and entry name
106 string createFilename(const string &entry);
109 #endif // ENABLE_FILE
110 #endif // INCL_FILESYNCSOURCE