[evolution/account-mgmt: 7/50] Adapt libeshell to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/account-mgmt: 7/50] Adapt libeshell to the new ESource API.
- Date: Sat, 1 Oct 2011 15:48:01 +0000 (UTC)
commit d0cd91f0c9ed47686f1108e9a44c00941e95195e
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Mar 4 15:46:33 2011 -0500
Adapt libeshell to the new ESource API.
shell/e-shell-migrate.c | 110 -----------------------------------------------
shell/e-shell-view.c | 69 +++++++++++++++++++++++++++++
shell/e-shell-view.h | 6 +++
shell/e-shell.c | 38 ++++++++++++++++-
shell/e-shell.h | 3 +
5 files changed, 115 insertions(+), 111 deletions(-)
---
diff --git a/shell/e-shell-migrate.c b/shell/e-shell-migrate.c
index 89f94b0..3bfa2fb 100644
--- a/shell/e-shell-migrate.c
+++ b/shell/e-shell-migrate.c
@@ -797,109 +797,6 @@ fix_folder_permissions (const gchar *data_dir)
change_dir_modes (data_dir);
}
-static void
-merge_duplicate_local_sources (GConfClient *client,
- const gchar *gconf_key)
-{
- ESourceList *source_list;
- GSList *iter, *to_remove = NULL;
- ESourceGroup *first_local = NULL;
-
- g_return_if_fail (client != NULL);
- g_return_if_fail (gconf_key != NULL);
-
- source_list = e_source_list_new_for_gconf (client, gconf_key);
-
- for (iter = e_source_list_peek_groups (source_list); iter; iter = iter->next) {
- GSList *sources;
- ESourceGroup *group = iter->data;
-
- if (!group || !e_source_group_peek_base_uri (group) ||
- g_ascii_strncasecmp (
- e_source_group_peek_base_uri (group), "local:", 6) != 0)
- continue;
-
- if (!first_local) {
- first_local = group;
- continue;
- }
-
- /* merging respective sources */
- for (sources = e_source_group_peek_sources (group);
- sources != NULL; sources = sources->next) {
- GSList *liter;
- ESource *dupe_source = sources->data;
-
- if (!dupe_source)
- continue;
-
- for (liter = e_source_group_peek_sources (first_local);
- liter != NULL; liter = liter->next) {
- ESource *my_source = liter->data;
- const gchar *val1, *val2;
-
- if (!my_source)
- continue;
-
- /* pretty unlikely, but just in case */
- val1 = e_source_peek_uid (dupe_source);
- val2 = e_source_peek_uid (my_source);
- if (g_strcmp0 (val1, val2) == 0)
- break;
-
- /* relative uri should not be empty
- * (but adressbook can have it empty) */
- val1 = e_source_peek_relative_uri (dupe_source);
- val2 = e_source_peek_relative_uri (my_source);
- if (g_strcmp0 (val1, val2) == 0 && val1 && *val1)
- break;
- }
-
- /* didn't find matching source, thus add its copy */
- if (liter == NULL) {
- ESource *copy;
-
- copy = e_source_copy (dupe_source);
- e_source_group_add_source (first_local, copy, -1);
- g_object_unref (copy);
- }
- }
-
- to_remove = g_slist_prepend (to_remove, group);
- }
-
- if (first_local) {
- GSList *sources;
-
- for (sources = e_source_group_peek_sources (first_local);
- sources != NULL; sources = sources->next) {
- ESource *source = sources->data;
- const gchar *relative_uri;
-
- if (!source)
- continue;
-
- relative_uri = e_source_peek_relative_uri (source);
- if (!relative_uri || !*relative_uri)
- e_source_set_relative_uri (source, e_source_peek_uid (source));
- }
- }
-
- if (!to_remove) {
- g_object_unref (source_list);
- return;
- }
-
- for (iter = to_remove; iter; iter = iter->next) {
- e_source_list_remove_group (source_list, iter->data);
- }
-
- e_source_list_sync (source_list, NULL);
-
- g_object_unref (source_list);
- g_slist_free (to_remove);
-}
-
gboolean
e_shell_migrate_attempt (EShell *shell)
{
@@ -938,13 +835,6 @@ e_shell_migrate_attempt (EShell *shell)
if (!shell_migrate_attempt (shell, major, minor, micro))
_exit (EXIT_SUCCESS);
- /* The 2.32.x (except of 2.32.2) lefts duplicate On This Computer/Personal sources,
- * thus clean the mess up */
- merge_duplicate_local_sources (client, "/apps/evolution/addressbook/sources");
- merge_duplicate_local_sources (client, "/apps/evolution/calendar/sources");
- merge_duplicate_local_sources (client, "/apps/evolution/tasks/sources");
- merge_duplicate_local_sources (client, "/apps/evolution/memos/sources");
-
/* Record a successful migration. */
string = g_strdup_printf (
"%d.%d.%d", curr_major, curr_minor, curr_micro);
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index 370aa90..4d24279 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -37,6 +37,7 @@
#include "e-util/e-file-utils.h"
#include "e-util/e-plugin-ui.h"
+#include "e-util/e-source-util.h"
#include "e-util/e-ui-manager.h"
#include "e-util/e-util-private.h"
#include "e-util/e-util.h"
@@ -1840,3 +1841,71 @@ e_shell_view_new_view_instance (EShellView *shell_view,
return view_instance;
}
+
+/**
+ * e_shell_view_submit_source:
+ * @shell_view: an #EShellView
+ * @source: an #ESource
+ *
+ * Submits the current contents of @source to the D-Bus service to be saved
+ * to disk and broadcast to other clients.
+ *
+ * This function does not block: @shell_view will dispatch the operation
+ * asynchronously and handle any errors.
+ **/
+void
+e_shell_view_submit_source (EShellView *shell_view,
+ ESource *source)
+{
+ EActivity *activity;
+ EAlertSink *alert_sink;
+ EShellBackend *shell_backend;
+ EShellContent *shell_content;
+
+ g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+ g_return_if_fail (E_IS_SOURCE (source));
+
+ shell_backend = e_shell_view_get_shell_backend (shell_view);
+ shell_content = e_shell_view_get_shell_content (shell_view);
+
+ alert_sink = E_ALERT_SINK (shell_content);
+ activity = e_source_util_submit_data (source, alert_sink);
+ e_shell_backend_add_activity (shell_backend, activity);
+}
+
+/**
+ * e_shell_view_remove_source:
+ * @shell_view: an #EShellView
+ * @source: the #ESource to be removed
+ *
+ * Requests the D-Bus service to delete the key files for @source and all of
+ * its descendants and broadcast their removal to all clients.
+ *
+ * This function does not block: @shell_view will dispatch the operation
+ * asynchronously and handle any errors.
+ **/
+void
+e_shell_view_remove_source (EShellView *shell_view,
+ ESource *source)
+{
+ EShell *shell;
+ EActivity *activity;
+ EAlertSink *alert_sink;
+ ESourceRegistry *registry;
+ EShellBackend *shell_backend;
+ EShellContent *shell_content;
+
+ g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+ g_return_if_fail (E_IS_SOURCE (source));
+
+ shell_backend = e_shell_view_get_shell_backend (shell_view);
+ shell_content = e_shell_view_get_shell_content (shell_view);
+
+ shell = e_shell_backend_get_shell (shell_backend);
+ registry = e_shell_get_registry (shell);
+
+ alert_sink = E_ALERT_SINK (shell_content);
+ activity = e_source_util_remove_source (registry, source, alert_sink);
+ e_shell_backend_add_activity (shell_backend, activity);
+}
+
diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h
index 4387082..a1adfe4 100644
--- a/shell/e-shell-view.h
+++ b/shell/e-shell-view.h
@@ -22,6 +22,8 @@
#ifndef E_SHELL_VIEW_H
#define E_SHELL_VIEW_H
+#include <libedataserver/e-source.h>
+
#include <shell/e-shell-common.h>
#include <shell/e-shell-backend.h>
#include <shell/e-shell-content.h>
@@ -225,6 +227,10 @@ GtkWidget * e_shell_view_show_popup_menu (EShellView *shell_view,
GalViewInstance *
e_shell_view_new_view_instance (EShellView *shell_view,
const gchar *instance_id);
+void e_shell_view_submit_source (EShellView *shell_view,
+ ESource *source);
+void e_shell_view_remove_source (EShellView *shell_view,
+ ESource *source);
G_END_DECLS
diff --git a/shell/e-shell.c b/shell/e-shell.c
index dce7b21..52e3401 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -55,6 +55,7 @@ struct _EShellPrivate {
GList *watched_windows;
EShellSettings *settings;
GConfClient *gconf_client;
+ ESourceRegistry *registry;
GActionGroup *action_group;
GtkWidget *preferences_window;
@@ -766,6 +767,11 @@ shell_dispose (GObject *object)
priv->gconf_client = NULL;
}
+ if (priv->registry != NULL) {
+ g_object_unref (priv->registry);
+ priv->registry = NULL;
+ }
+
if (priv->action_group != NULL) {
g_object_unref (priv->action_group);
priv->action_group = NULL;
@@ -882,10 +888,20 @@ shell_initable_init (GInitable *initable,
GError **error)
{
GApplication *application = G_APPLICATION (initable);
+ EShellPrivate *priv;
+
+ priv = E_SHELL_GET_PRIVATE (initable);
shell_add_actions (application);
- return g_application_register (application, cancellable, error);
+ priv->registry = e_source_registry_new_sync (cancellable, error);
+ if (priv->registry == NULL)
+ return FALSE;
+
+ if (!g_application_register (application, cancellable, error))
+ return FALSE;
+
+ return TRUE;
}
static void
@@ -1474,6 +1490,26 @@ e_shell_get_gconf_client (EShell *shell)
}
/**
+ * e_shell_get_registry:
+ * @shell: an #EShell
+ *
+ * Returns the default #ESourceRegistry.
+ *
+ * This is equivalent to e_source_registry_get_default(), but this
+ * function is preferred so that all singleton objects come from the
+ * same place.
+ *
+ * Returns: the default #ESourceRegistry
+ **/
+ESourceRegistry *
+e_shell_get_registry (EShell *shell)
+{
+ g_return_val_if_fail (E_IS_SHELL (shell), NULL);
+
+ return shell->priv->registry;
+}
+
+/**
* e_shell_create_shell_window:
* @shell: an #EShell
* @view_name: name of the initial shell view, or %NULL
diff --git a/shell/e-shell.h b/shell/e-shell.h
index ede071e..d9bf7ab 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -23,6 +23,7 @@
#define E_SHELL_H
#include <gconf/gconf-client.h>
+#include <libedataserver/e-source-registry.h>
#include <e-util/e-activity.h>
#include <e-util/e-alert.h>
@@ -123,6 +124,8 @@ EShellBackend * e_shell_get_backend_by_scheme (EShell *shell,
const gchar *scheme);
EShellSettings *e_shell_get_shell_settings (EShell *shell);
GConfClient * e_shell_get_gconf_client (EShell *shell);
+ESourceRegistry *
+ e_shell_get_registry (EShell *shell);
GtkWidget * e_shell_create_shell_window (EShell *shell,
const gchar *view_name);
guint e_shell_handle_uris (EShell *shell,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]