summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2012-09-13 17:57:28 +0200
committerPatrick Ohly <patrick.ohly@intel.com>2012-10-25 16:43:46 +0200
commita4cc410b317c17b3c2060f8e487e3b65a5c506a4 (patch)
tree647ebfb1264478bd5658936c9b25382734760345
parentf1bbe9802a9851e5323bebaae4c519ac539236c0 (diff)
EDS Client: implement creating and deleting databases
Depends on the EDS 3.6 ESourceRegistry API. Needs the very latest EDS with the following commit. There's no configure check yet because EDS 3.6 is not released yet. commit 6df76009318eac9dbe3dd49165394d389102764e Author: Matthew Barnes <mbarnes@redhat.com> Date: Tue Sep 11 22:56:08 2012 -0400 Bug 683785 - Add e_source_new_with_uid() Variation of e_source_new() which allows a predetermined UID to be specified for a scratch source. This changes the "uid" property from read-only to read/write + construct-only, and eliminates the need for EServerSideSource to override the property.
-rw-r--r--src/backends/evolution/EvolutionCalendarSource.h2
-rw-r--r--src/backends/evolution/EvolutionContactSource.h4
-rw-r--r--src/backends/evolution/EvolutionSyncSource.cpp59
-rw-r--r--src/backends/evolution/EvolutionSyncSource.h9
4 files changed, 73 insertions, 1 deletions
diff --git a/src/backends/evolution/EvolutionCalendarSource.h b/src/backends/evolution/EvolutionCalendarSource.h
index fed3e74f..8107b002 100644
--- a/src/backends/evolution/EvolutionCalendarSource.h
+++ b/src/backends/evolution/EvolutionCalendarSource.h
@@ -170,7 +170,7 @@ class EvolutionCalendarSource : public EvolutionSyncSource,
ECalClientSourceType sourceType() const {
return (ECalClientSourceType)m_type;
}
- const char *sourceExtension() const {
+ virtual const char *sourceExtension() const {
return
m_type == EVOLUTION_CAL_SOURCE_TYPE_EVENTS ? E_SOURCE_EXTENSION_CALENDAR :
m_type == EVOLUTION_CAL_SOURCE_TYPE_TASKS ? E_SOURCE_EXTENSION_TASK_LIST :
diff --git a/src/backends/evolution/EvolutionContactSource.h b/src/backends/evolution/EvolutionContactSource.h
index a0ef0b5c..9ba700a9 100644
--- a/src/backends/evolution/EvolutionContactSource.h
+++ b/src/backends/evolution/EvolutionContactSource.h
@@ -86,6 +86,10 @@ class EvolutionContactSource : public EvolutionSyncSource,
info.m_afterReadScript = "$VCARD_AFTERREAD_SCRIPT_EVOLUTION;";
}
+#ifdef USE_EDS_CLIENT
+ virtual const char *sourceExtension() const { return E_SOURCE_EXTENSION_ADDRESS_BOOK; }
+#endif
+
private:
/** extract REV string for contact, throw error if not found */
std::string getRevision(const std::string &uid);
diff --git a/src/backends/evolution/EvolutionSyncSource.cpp b/src/backends/evolution/EvolutionSyncSource.cpp
index 5a90df2e..c9850ca4 100644
--- a/src/backends/evolution/EvolutionSyncSource.cpp
+++ b/src/backends/evolution/EvolutionSyncSource.cpp
@@ -140,9 +140,68 @@ EClientCXX EvolutionSyncSource::openESource(const char *extension,
}
}
+ // record result for SyncSource::getDatabase()
+ source = e_client_get_source(client);
+ if (source) {
+ Database database(e_source_get_display_name(source),
+ e_source_get_uid(source));
+ setDatabase(database);
+ }
+
return client;
}
+SyncSource::Database EvolutionSyncSource::createDatabase(const Database &database)
+{
+ GErrorCXX gerror;
+ ESourceCXX source(e_source_new_with_uid(database.m_uri.empty() ? NULL : database.m_uri.c_str(),
+ NULL, gerror), false);
+ if (!source) {
+ gerror.throwError("e_source_new()");
+ }
+ e_source_set_enabled(source, true);
+ e_source_set_display_name(source, database.m_name.c_str());
+ e_source_set_parent(source, "local-stub");
+
+
+ // create extension of the right type and set "local" as backend
+ ESourceBackend *backend = static_cast<ESourceBackend *>(e_source_get_extension(source, sourceExtension()));
+ e_source_backend_set_backend_name(backend, "local");
+
+ ESourceRegistryCXX registry = getSourceRegistry();
+ ESourceListCXX sources;
+ sources.push_back(source.ref()); // ESourceListCXX unrefs sources it points to
+ if (!e_source_registry_create_sources_sync(registry,
+ sources,
+ NULL,
+ gerror)) {
+ gerror.throwError(StringPrintf("creating EDS database of type %s with name '%s'%s%s",
+ sourceExtension(),
+ database.m_name.c_str(),
+ database.m_uri.empty() ? "" : " and URI ",
+ database.m_uri.c_str()));
+ }
+ const gchar *name = e_source_get_display_name(source);
+ const gchar *uid = e_source_get_uid(source);
+ return Database(name, uid);
+}
+
+void EvolutionSyncSource::deleteDatabase(const std::string &uri)
+{
+ ESourceRegistryCXX registry = getSourceRegistry();
+ ESourceCXX source(e_source_registry_ref_source(registry, uri.c_str()), false);
+ if (!source) {
+ throwError(StringPrintf("EDS database with URI '%s' cannot be deleted, does not exist",
+ uri.c_str()));
+ }
+ GErrorCXX gerror;
+ if (!e_source_remove_sync(source, NULL, gerror)) {
+ throwError(StringPrintf("deleting EDS database with URI '%s'", uri.c_str()),
+ gerror);
+ }
+}
+
+
#endif // USE_EDS_CLIENT
ESource *EvolutionSyncSource::findSource(const ESourceListCXX &list, const string &id )
diff --git a/src/backends/evolution/EvolutionSyncSource.h b/src/backends/evolution/EvolutionSyncSource.h
index 3ac68ac5..e5c8d281 100644
--- a/src/backends/evolution/EvolutionSyncSource.h
+++ b/src/backends/evolution/EvolutionSyncSource.h
@@ -76,7 +76,16 @@ class EvolutionSyncSource : public TrackingSyncSource
ESource *(*refBuiltin)(ESourceRegistry *),
const boost::function<EClient *(ESource *, GError **gerror)> &newClient);
ESourceRegistryCXX getSourceRegistry();
+
+ // Implementation of SyncSource calls which only works when using EDS Client API
+ // and EDS > 3.4. Older EDS has no way of creating sources easily (or at all).
+ virtual Database createDatabase(const Database &database);
+ virtual void deleteDatabase(const std::string &uri);
+
+ /** E_SOURCE_EXTENSION_ADDRESS_BOOK, etc. */
+ virtual const char *sourceExtension() const = 0;
#endif
+
/**
* searches the list for a source with the given uri or name
*