[evolution/account-mgmt: 12/33] Adapt addressbook/gui/widgets to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/account-mgmt: 12/33] Adapt addressbook/gui/widgets to the new ESource API.
- Date: Fri, 18 Mar 2011 01:53:01 +0000 (UTC)
commit e109b6fd936393b80ebec8471a41e82b59300a0c
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Dec 8 00:16:09 2010 -0500
Adapt addressbook/gui/widgets to the new ESource API.
.../gui/contact-editor/e-contact-quick-add.c | 3 +-
addressbook/gui/widgets/e-addressbook-model.c | 37 +++++++++---
addressbook/gui/widgets/e-addressbook-selector.c | 42 ++++++-------
addressbook/gui/widgets/e-addressbook-selector.h | 3 +-
addressbook/gui/widgets/e-addressbook-view.c | 18 +++---
addressbook/gui/widgets/ea-minicard-view.c | 10 ++--
addressbook/gui/widgets/eab-gui-util.c | 64 ++++++++++----------
7 files changed, 97 insertions(+), 80 deletions(-)
---
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c
index fd84aa8..73a9a91 100644
--- a/addressbook/gui/contact-editor/e-contact-quick-add.c
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.c
@@ -136,7 +136,8 @@ merge_cb (ESource *source,
e_alert_run_dialog_for_args (
e_shell_get_active_window (NULL),
"addressbook:error-read-only",
- e_source_get_name (e_book_get_source (book)),
+ e_source_get_display_name (
+ e_book_get_source (book)),
NULL);
if (qa->cb)
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index 6f679a4..c0f0585 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.c
@@ -374,6 +374,27 @@ book_view_loaded (EBook *book,
e_book_view_start (model->priv->book_view);
}
+static guint32
+get_ldap_download_limit (ESource *source)
+{
+ GObject *extension;
+ const gchar *extension_name;
+ guint limit;
+
+ /* FIXME This absolutely does not belong here. We don't have
+ * access to the LDAP ESource extension from here, so we
+ * have to fetch the download limit by its property name.
+ * This suggests we need to make the design more flexible
+ * so this logic can live in the LDAP backend where it
+ * belongs. */
+
+ extension_name = "LDAP Backend";
+ extension = e_source_get_extension (source, extension_name);
+ g_object_get (extension, "limit", &limit, NULL);
+
+ return limit;
+}
+
static gboolean
addressbook_model_idle_cb (EAddressbookModel *model)
{
@@ -381,14 +402,14 @@ addressbook_model_idle_cb (EAddressbookModel *model)
if (model->priv->book && model->priv->query) {
ESource *source;
- const gchar *limit_str;
+ const gchar *backend_name;
gint limit = -1;
source = e_book_get_source (model->priv->book);
+ backend_name = e_source_get_backend_name (source);
- limit_str = e_source_get_property (source, "limit");
- if (limit_str && *limit_str)
- limit = atoi (limit_str);
+ if (g_strcmp0 (backend_name, "ldap") == 0)
+ limit = get_ldap_download_limit (source);
remove_book_view (model);
@@ -402,10 +423,10 @@ addressbook_model_idle_cb (EAddressbookModel *model)
} else {
free_data (model);
- g_signal_emit (model,
- signals[MODEL_CHANGED], 0);
- g_signal_emit (model,
- signals[STOP_STATE_CHANGED], 0);
+ g_signal_emit (
+ model, signals[MODEL_CHANGED], 0);
+ g_signal_emit (
+ model, signals[STOP_STATE_CHANGED], 0);
}
} else
e_book_get_book_view_async (
diff --git a/addressbook/gui/widgets/e-addressbook-selector.c b/addressbook/gui/widgets/e-addressbook-selector.c
index a39750c..cffc545 100644
--- a/addressbook/gui/widgets/e-addressbook-selector.c
+++ b/addressbook/gui/widgets/e-addressbook-selector.c
@@ -20,6 +20,8 @@
#include "e-addressbook-selector.h"
+#include <libebook/e-source-address-book.h>
+
#include <e-util/e-selection.h>
#include <eab-book-util.h>
@@ -149,26 +151,13 @@ addressbook_selector_merge_next_cb (EBook *book,
static void
addressbook_selector_load_primary_source (ESourceSelector *selector)
{
- ESourceList *source_list;
- ESource *source = NULL;
- GSList *groups;
-
- source_list = e_source_selector_get_source_list (selector);
-
- /* Dig up the first source in the source list.
- * XXX libedataserver should provide API for this. */
- groups = e_source_list_peek_groups (source_list);
- while (groups != NULL) {
- ESourceGroup *source_group = groups->data;
- GSList *sources;
-
- sources = e_source_group_peek_sources (source_group);
- if (sources != NULL) {
- source = sources->data;
- break;
- }
-
- groups = g_slist_next (groups);
+ ESource *source;
+
+ source = e_source_selector_get_default_source (selector);
+ if (source == NULL) {
+ ESourceRegistry *registry;
+ registry = e_source_selector_get_registry (selector);
+ source = e_source_registry_lookup_by_uid (registry, "system");
}
if (source != NULL)
@@ -324,6 +313,12 @@ addressbook_selector_init (EAddressbookSelector *selector)
selector, E_TYPE_ADDRESSBOOK_SELECTOR,
EAddressbookSelectorPrivate);
+ e_source_selector_set_show_colors (
+ E_SOURCE_SELECTOR (selector), FALSE);
+
+ e_source_selector_set_show_toggles (
+ E_SOURCE_SELECTOR (selector), FALSE);
+
gtk_drag_dest_set (
GTK_WIDGET (selector), GTK_DEST_DEFAULT_ALL,
drag_types, G_N_ELEMENTS (drag_types),
@@ -360,13 +355,14 @@ e_addressbook_selector_get_type (void)
}
GtkWidget *
-e_addressbook_selector_new (ESourceList *source_list)
+e_addressbook_selector_new (ESourceRegistry *registry)
{
- g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), NULL);
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
return g_object_new (
E_TYPE_ADDRESSBOOK_SELECTOR,
- "source-list", source_list, NULL);
+ "extension-name", E_SOURCE_EXTENSION_ADDRESS_BOOK,
+ "registry", registry, NULL);
}
EAddressbookView *
diff --git a/addressbook/gui/widgets/e-addressbook-selector.h b/addressbook/gui/widgets/e-addressbook-selector.h
index c0102cb..d4d6ad8 100644
--- a/addressbook/gui/widgets/e-addressbook-selector.h
+++ b/addressbook/gui/widgets/e-addressbook-selector.h
@@ -21,7 +21,6 @@
#ifndef E_ADDRESSBOOK_SELECTOR_H
#define E_ADDRESSBOOK_SELECTOR_H
-#include <libedataserver/e-source-list.h>
#include <libedataserverui/e-source-selector.h>
#include "e-addressbook-view.h"
@@ -60,7 +59,7 @@ struct _EAddressbookSelectorClass {
};
GType e_addressbook_selector_get_type (void);
-GtkWidget * e_addressbook_selector_new (ESourceList *source_list);
+GtkWidget * e_addressbook_selector_new (ESourceRegistry *registry);
EAddressbookView *
e_addressbook_selector_get_current_view
(EAddressbookSelector *selector);
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index 804fa10..ff3ca99 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -562,13 +562,13 @@ addressbook_view_constructed (GObject *object)
GalViewInstance *view_instance;
EShellView *shell_view;
ESource *source;
- gchar *uri;
+ const gchar *uid;
shell_view = e_addressbook_view_get_shell_view (view);
source = e_addressbook_view_get_source (view);
- uri = e_source_get_uri (source);
+ uid = e_source_get_uid (source);
- view_instance = e_shell_view_new_view_instance (shell_view, uri);
+ view_instance = e_shell_view_new_view_instance (shell_view, uid);
g_signal_connect_swapped (
view_instance, "display-view",
G_CALLBACK (addressbook_view_display_view_cb), view);
@@ -579,8 +579,6 @@ addressbook_view_constructed (GObject *object)
* e_book_shell_content_get_current_view() returns the correct
* view in GalViewInstance::loaded signal handlers. */
- g_free (uri);
-
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (parent_class)->constructed (object);
}
@@ -1110,7 +1108,7 @@ folder_bar_message (EAddressbookView *view,
{
EShellView *shell_view;
EShellSidebar *shell_sidebar;
- const gchar *name;
+ const gchar *display_name;
shell_view = e_addressbook_view_get_shell_view (view);
shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
@@ -1118,8 +1116,8 @@ folder_bar_message (EAddressbookView *view,
if (view->priv->source == NULL)
return;
- name = e_source_peek_name (view->priv->source);
- e_shell_sidebar_set_primary_text (shell_sidebar, name);
+ display_name = e_source_get_display_name (view->priv->source);
+ e_shell_sidebar_set_primary_text (shell_sidebar, display_name);
e_shell_sidebar_set_secondary_text (shell_sidebar, message);
}
@@ -1141,6 +1139,7 @@ backend_died (EAddressbookView *view)
EShellView *shell_view;
EAlertSink *alert_sink;
EAddressbookModel *model;
+ ESource *source;
EBook *book;
shell_view = e_addressbook_view_get_shell_view (view);
@@ -1148,10 +1147,11 @@ backend_died (EAddressbookView *view)
model = e_addressbook_view_get_model (view);
book = e_addressbook_model_get_book (model);
+ source = e_book_get_source (book);
e_alert_submit (alert_sink,
"addressbook:backend-died",
- e_book_get_uri (book), NULL);
+ e_source_get_display_name (source), NULL);
}
static void
diff --git a/addressbook/gui/widgets/ea-minicard-view.c b/addressbook/gui/widgets/ea-minicard-view.c
index cc35d57..b28a7e3 100644
--- a/addressbook/gui/widgets/ea-minicard-view.c
+++ b/addressbook/gui/widgets/ea-minicard-view.c
@@ -146,7 +146,7 @@ ea_minicard_view_get_name (AtkObject *accessible)
gchar *string;
EMinicardView *card_view;
EBook *book = NULL;
- const gchar *source_name;
+ const gchar *display_name;
g_return_val_if_fail (EA_IS_MINICARD_VIEW (accessible), NULL);
@@ -160,13 +160,13 @@ ea_minicard_view_get_name (AtkObject *accessible)
card_view = E_MINICARD_VIEW (reflow);
g_object_get (card_view->adapter, "book", &book, NULL);
g_return_val_if_fail (E_IS_BOOK (book), NULL);
- source_name = e_source_peek_name (e_book_get_source (book));
- if (!source_name)
- source_name="";
+ display_name = e_source_get_display_name (e_book_get_source (book));
+ if (display_name == NULL)
+ display_name = "";
string = g_strdup_printf (ngettext ("current address book folder %s has %d card",
"current address book folder %s has %d cards",
- reflow->count), source_name, reflow->count);
+ reflow->count), display_name, reflow->count);
ATK_OBJECT_CLASS (parent_class)->set_name (accessible, string);
g_free (string);
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index 280758f..7a12869 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -29,13 +29,14 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
+#include <libebook/e-destination.h>
+#include <libebook/e-source-address-book.h>
#include <libedataserver/e-data-server-util.h>
#include <libedataserverui/e-book-auth-util.h>
#include <libedataserverui/e-source-selector.h>
#include <e-util/e-util.h>
#include "eab-gui-util.h"
#include "util/eab-book-util.h"
-#include <libebook/e-destination.h>
#include "e-util/e-alert-dialog.h"
#include "e-util/e-html-utils.h"
#include "shell/e-shell.h"
@@ -65,12 +66,13 @@ eab_error_dialog (EAlertSink *alert_sink, const gchar *msg, const GError *error)
void
eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *source, const GError *error)
{
- gchar *label_string, *label = NULL, *uri;
+ gchar *label_string, *label = NULL;
gboolean can_detail_error = TRUE;
+ const gchar *backend_name;
g_return_if_fail (source != NULL);
- uri = e_source_get_uri (source);
+ backend_name = e_source_get_backend_name (source);
if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_OFFLINE_UNAVAILABLE)) {
can_detail_error = FALSE;
@@ -80,25 +82,16 @@ eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *sourc
"to download its contents.");
}
- else if (uri && g_str_has_prefix (uri, "local:")) {
+ else if (g_strcmp0 (backend_name, "local") == 0) {
const gchar *user_data_dir;
- const gchar *source_dir;
- gchar *mangled_source_dir;
+ const gchar *uid;
gchar *path;
+ uid = e_source_get_uid (source);
user_data_dir = e_get_user_data_dir ();
- source_dir = e_source_peek_relative_uri (source);
-
- if (!source_dir || !g_str_equal (source_dir, "system"))
- source_dir = e_source_peek_uid (source);
-
- /* Mangle the URI to not contain invalid characters. */
- mangled_source_dir = g_strdelimit (g_strdup (source_dir), ":/", '_');
path = g_build_filename (
- user_data_dir, "addressbook", mangled_source_dir, NULL);
-
- g_free (mangled_source_dir);
+ user_data_dir, "addressbook", uid, NULL);
label = g_strdup_printf (
_("This address book cannot be opened. Please check that the "
@@ -109,7 +102,7 @@ eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *sourc
}
#ifndef HAVE_LDAP
- else if (uri && !strncmp (uri, "ldap:", 5)) {
+ else if (g_strcmp0 (backend_name, "ldap") == 0) {
/* special case for ldap: contact folders so we can tell the user about openldap */
can_detail_error = FALSE;
@@ -147,7 +140,6 @@ eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *sourc
}
g_free (label);
- g_free (uri);
}
void
@@ -236,21 +228,23 @@ source_selection_changed_cb (ESourceSelector *selector, GtkWidget *ok_button)
}
ESource *
-eab_select_source (ESource *except_source, const gchar *title, const gchar *message, const gchar *select_uid, GtkWindow *parent)
+eab_select_source (ESource *except_source,
+ const gchar *title,
+ const gchar *message,
+ const gchar *select_uid,
+ GtkWindow *parent)
{
+ ESourceRegistry *registry;
ESource *source;
- ESourceList *source_list;
GtkWidget *content_area;
GtkWidget *dialog;
GtkWidget *ok_button;
/* GtkWidget *label; */
GtkWidget *selector;
GtkWidget *scrolled_window;
+ const gchar *extension_name;
gint response;
- if (!e_book_get_addressbooks (&source_list, NULL))
- return NULL;
-
dialog = gtk_dialog_new_with_buttons (_("Select Address Book"), parent,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
NULL);
@@ -262,17 +256,23 @@ eab_select_source (ESource *except_source, const gchar *title, const gchar *mess
/* label = gtk_label_new (message); */
- selector = e_source_selector_new (source_list);
- e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE);
+ registry = e_source_registry_get_default ();
+ extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+ selector = e_source_selector_new (registry, extension_name);
+ e_source_selector_set_show_toggles (
+ E_SOURCE_SELECTOR (selector), FALSE);
if (except_source)
- g_object_set_data (G_OBJECT (ok_button), "except-source", e_source_list_peek_source_by_uid (source_list, e_source_peek_uid (except_source)));
- g_signal_connect (selector, "primary_selection_changed",
- G_CALLBACK (source_selection_changed_cb), ok_button);
+ g_object_set_data (
+ G_OBJECT (ok_button), "except-source", except_source);
+ g_signal_connect (
+ selector, "primary_selection_changed",
+ G_CALLBACK (source_selection_changed_cb), ok_button);
if (select_uid) {
- source = e_source_list_peek_source_by_uid (source_list, select_uid);
+ source = e_source_registry_lookup_by_uid (registry, select_uid);
if (source)
- e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (selector), source);
+ e_source_selector_set_primary_selection (
+ E_SOURCE_SELECTOR (selector), source);
}
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
@@ -469,9 +469,9 @@ eab_transfer_contacts (EBook *source_book,
if (!destination)
return;
- if (strcmp (last_uid, e_source_peek_uid (destination)) != 0) {
+ if (strcmp (last_uid, e_source_get_uid (destination)) != 0) {
g_free (last_uid);
- last_uid = g_strdup (e_source_peek_uid (destination));
+ last_uid = g_strdup (e_source_get_uid (destination));
}
process = g_new (ContactCopyProcess, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]