[evolution/account-mgmt: 41/51] Adapt bbdb plugin to new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/account-mgmt: 41/51] Adapt bbdb plugin to new ESource API.
- Date: Fri, 6 Apr 2012 03:02:17 +0000 (UTC)
commit 4541475d7603942adcdc2e31ea5c37d3c511a097
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Mar 28 10:44:52 2011 -0400
Adapt bbdb plugin to new ESource API.
plugins/bbdb/Makefile.am | 1 +
plugins/bbdb/bbdb.c | 157 ++++++++++++++++++--------------------------
plugins/bbdb/gaimbuddies.c | 1 +
3 files changed, 65 insertions(+), 94 deletions(-)
---
diff --git a/plugins/bbdb/Makefile.am b/plugins/bbdb/Makefile.am
index e2efb70..d3e006e 100644
--- a/plugins/bbdb/Makefile.am
+++ b/plugins/bbdb/Makefile.am
@@ -26,6 +26,7 @@ liborg_gnome_evolution_bbdb_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED)
liborg_gnome_evolution_bbdb_la_LIBADD = \
$(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/shell/libeshell.la \
$(top_builddir)/composer/libcomposer.la \
$(top_builddir)/addressbook/gui/contact-editor/libecontacteditor.la \
$(top_builddir)/addressbook/gui/contact-list-editor/libecontactlisteditor.la \
diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c
index 1fa392b..461a089 100644
--- a/plugins/bbdb/bbdb.c
+++ b/plugins/bbdb/bbdb.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <libebook/e-book-client.h>
+#include <libedataserver/e-source-address-book.h>
#include <libedataserverui/e-source-combo-box.h>
#include <libedataserverui/e-client-utils.h>
@@ -49,7 +50,6 @@ GtkWidget *bbdb_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data
/* For internal use */
struct bbdb_stuff {
EABConfigTargetPrefs *target;
- ESourceList *source_list;
GtkWidget *combo_box;
GtkWidget *gaim_combo_box;
@@ -66,46 +66,6 @@ static void source_changed_cb (ESourceComboBox *source_combo_box, struct bbdb_st
static GtkWidget *create_addressbook_combo_box (struct bbdb_stuff *stuff, gint type);
static void cleanup_cb (GObject *o, gpointer data);
-static ESource *
-find_esource_by_uri (ESourceList *source_list,
- const gchar *target_uri)
-{
- GSList *groups;
-
- /* XXX This would be unnecessary if the plugin had stored
- * the addressbook's UID instead of the URI in GConf.
- * Too late to change it now, I suppose. */
-
- if (source_list == NULL || target_uri == NULL)
- return NULL;
-
- groups = e_source_list_peek_groups (source_list);
-
- while (groups != NULL) {
- GSList *sources;
-
- sources = e_source_group_peek_sources (groups->data);
-
- while (sources != NULL) {
- gchar *uri;
- gboolean match;
-
- uri = e_source_get_uri (sources->data);
- match = (strcmp (uri, target_uri) == 0);
- g_free (uri);
-
- if (match)
- return sources->data;
-
- sources = g_slist_next (sources);
- }
-
- groups = g_slist_next (groups);
- }
-
- return NULL;
-}
-
/* How often check, in minutes. Read only on plugin enable. Use <= 0 to disable polling. */
static gint
get_check_interval (void)
@@ -408,12 +368,14 @@ bbdb_do_it (EBookClient *client,
EBookClient *
bbdb_create_book_client (gint type)
{
- GSettings *settings;
- gchar *uri;
- EBookClient *client = NULL;
-
- GError *error = NULL;
- gboolean enable = TRUE;
+ EShell *shell;
+ ESource *source;
+ ESourceRegistry *registry;
+ EBookClient *client = NULL;
+ GSettings *settings;
+ gboolean enable = TRUE;
+ gchar *uid;
+ GError *error = NULL;
settings = g_settings_new (CONF_SCHEMA);
@@ -427,25 +389,35 @@ bbdb_create_book_client (gint type)
/* Open the appropriate addresbook. */
if (type == GAIM_ADDRESSBOOK)
- uri = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM);
+ uid = g_settings_get_string (
+ settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM);
else
- uri = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK);
+ uid = g_settings_get_string (
+ settings, CONF_KEY_WHICH_ADDRESSBOOK);
g_object_unref (G_OBJECT (settings));
- if (uri == NULL)
- client = e_book_client_new_system (&error);
- else {
- client = e_book_client_new_from_uri (uri, &error);
- g_free (uri);
- }
+ if (uid == NULL)
+ uid = g_strdup (E_SOURCE_BUILTIN_ADDRESS_BOOK_UID);
- if (client == NULL) {
- g_warning ("bbdb: failed to get addressbook: %s", error ? error->message : "Unknown error");
- if (error)
- g_error_free (error);
- return NULL;
+ shell = e_shell_get_default ();
+ registry = e_shell_get_registry (shell);
+ source = e_source_registry_lookup_by_uid (registry, uid);
+
+ if (source != NULL)
+ client = e_book_client_new (source, &error);
+
+ if (source == NULL)
+ g_warning ("bbdb: Source UID '%s' not found", uid);
+
+ else if (client == NULL) {
+ g_warning (
+ "bbdb: Failed to get addressbook: %s\n",
+ error->message);
+ g_error_free (error);
}
+ g_free (uid);
+
return client;
}
@@ -457,9 +429,6 @@ bbdb_open_book_client (EBookClient *client)
if (!client)
return FALSE;
- g_signal_connect (
- client, "authenticate",
- G_CALLBACK (e_client_utils_authenticate_handler), NULL);
if (!e_client_open_sync (E_CLIENT (client), FALSE, NULL, &error)) {
g_warning ("bbdb: failed to open addressbook: %s", error ? error->message : "Unknown error");
if (error)
@@ -518,14 +487,15 @@ enable_toggled_cb (GtkWidget *widget,
addressbook = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK);
if (active && !addressbook) {
- const gchar *uri = NULL;
+ const gchar *uid = "";
selected_source = e_source_combo_box_get_active (
E_SOURCE_COMBO_BOX (stuff->combo_box));
if (selected_source != NULL)
- uri = e_source_get_uri (selected_source);
+ uid = e_source_get_uid (selected_source);
- g_settings_set_string (settings, CONF_KEY_WHICH_ADDRESSBOOK, uri ? uri : "");
+ g_settings_set_string (
+ settings, CONF_KEY_WHICH_ADDRESSBOOK, uid);
}
g_free (addressbook);
@@ -547,12 +517,15 @@ enable_gaim_toggled_cb (GtkWidget *widget,
/* Save the new setting to GSettings */
g_settings_set_boolean (settings, CONF_KEY_ENABLE_GAIM, active);
- addressbook_gaim = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM);
+ addressbook_gaim = g_settings_get_string (
+ settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM);
gtk_widget_set_sensitive (stuff->gaim_combo_box, active);
if (active && !addressbook_gaim) {
selected_source = e_source_combo_box_get_active (
E_SOURCE_COMBO_BOX (stuff->gaim_combo_box));
- g_settings_set_string (settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM, e_source_get_uri (selected_source));
+ g_settings_set_string (
+ settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM,
+ e_source_get_uid (selected_source));
}
g_free (addressbook_gaim);
@@ -571,13 +544,12 @@ source_changed_cb (ESourceComboBox *source_combo_box,
{
ESource *source;
GSettings *settings = g_settings_new (CONF_SCHEMA);
+ const gchar *uid;
source = e_source_combo_box_get_active (source_combo_box);
+ uid = (source != NULL) ? e_source_get_uid (source) : "";
- g_settings_set_string (
- settings,
- CONF_KEY_WHICH_ADDRESSBOOK,
- source ? e_source_get_uri (source) : "");
+ g_settings_set_string (settings, CONF_KEY_WHICH_ADDRESSBOOK, uid);
g_object_unref (settings);
}
@@ -588,13 +560,12 @@ gaim_source_changed_cb (ESourceComboBox *source_combo_box,
{
ESource *source;
GSettings *settings = g_settings_new (CONF_SCHEMA);
+ const gchar *uid;
source = e_source_combo_box_get_active (source_combo_box);
+ uid = (source != NULL) ? e_source_get_uid (source) : "";
- g_settings_set_string (
- settings,
- CONF_KEY_WHICH_ADDRESSBOOK_GAIM,
- source ? e_source_get_uri (source) : "");
+ g_settings_set_string (settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM, uid);
g_object_unref (settings);
}
@@ -603,33 +574,32 @@ static GtkWidget *
create_addressbook_combo_box (struct bbdb_stuff *stuff,
gint type)
{
- GtkWidget *combo_box;
- ESourceList *source_list;
- ESource *selected_source;
- gchar *selected_source_uri;
- GConfClient *gconf;
+ EShell *shell;
+ ESource *source;
+ ESourceRegistry *registry;
+ GtkWidget *combo_box;
+ const gchar *extension_name;
+ gchar *uid;
GSettings *settings = g_settings_new (CONF_SCHEMA);
- gconf = gconf_client_get_default ();
- source_list = e_source_list_new_for_gconf (gconf, "/apps/evolution/addressbook/sources");
- combo_box = e_source_combo_box_new (source_list);
+ shell = e_shell_get_default ();
+ registry = e_shell_get_registry (shell);
+ extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+ combo_box = e_source_combo_box_new (registry, extension_name);
if (type == GAIM_ADDRESSBOOK)
- selected_source_uri = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM);
+ uid = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM);
else
- selected_source_uri = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK);
- selected_source = find_esource_by_uri (
- source_list, selected_source_uri);
- g_free (selected_source_uri);
+ uid = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK);
+ source = e_source_registry_lookup_by_uid (registry, uid);
+ g_free (uid);
- if (selected_source != NULL)
+ if (source != NULL)
e_source_combo_box_set_active (
- E_SOURCE_COMBO_BOX (combo_box), selected_source);
+ E_SOURCE_COMBO_BOX (combo_box), source);
gtk_widget_show (combo_box);
- stuff->source_list = source_list;
-
g_object_unref (settings);
return combo_box;
@@ -774,6 +744,5 @@ cleanup_cb (GObject *o,
{
struct bbdb_stuff *stuff = data;
- g_object_unref (stuff->source_list);
g_free (stuff);
}
diff --git a/plugins/bbdb/gaimbuddies.c b/plugins/bbdb/gaimbuddies.c
index 2f304cb..03d3a41 100644
--- a/plugins/bbdb/gaimbuddies.c
+++ b/plugins/bbdb/gaimbuddies.c
@@ -40,6 +40,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
+#include <gconf/gconf-client.h>
#include <string.h>
#include <libebook/e-book-client.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]