[evolution-data-server/account-mgmt: 31/38] Adapt ESourceComboBox to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 31/38] Adapt ESourceComboBox to the new ESource API.
- Date: Thu, 29 Mar 2012 23:54:06 +0000 (UTC)
commit dc77e9b14f6713651e28c5179b45848833ca1fd4
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Nov 30 20:24:09 2010 -0600
Adapt ESourceComboBox to the new ESource API.
.../libedataserverui/libedataserverui-sections.txt | 5 +-
libedataserverui/e-name-selector-dialog.c | 14 +-
libedataserverui/e-source-combo-box.c | 571 ++++++++++----------
libedataserverui/e-source-combo-box.h | 23 +-
tests/libedataserverui/test-source-combo-box.c | 40 +-
5 files changed, 330 insertions(+), 323 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index b0738cf..454a5b5 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -344,8 +344,9 @@ e_passwords_ask_password
<TITLE>ESourceComboBox</TITLE>
ESourceComboBox
e_source_combo_box_new
-e_source_combo_box_get_source_list
-e_source_combo_box_set_source_list
+e_source_combo_box_get_extension_name
+e_source_combo_box_set_extension_name
+e_source_combo_box_get_registry
e_source_combo_box_get_active
e_source_combo_box_set_active
e_source_combo_box_get_active_uid
diff --git a/libedataserverui/e-name-selector-dialog.c b/libedataserverui/e-name-selector-dialog.c
index f36e7fb..4a8e1fc 100644
--- a/libedataserverui/e-name-selector-dialog.c
+++ b/libedataserverui/e-name-selector-dialog.c
@@ -37,6 +37,7 @@
#include <libebook/e-book-client.h>
#include <libebook/e-book-client-view.h>
#include <libebook/e-book-query.h>
+#include <libebook/e-source-address-book.h>
#include "e-source-combo-box.h"
#include "e-destination-store.h"
@@ -147,7 +148,6 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
GtkTreeViewColumn *column;
GtkCellRenderer *cell_renderer;
GtkTreeSelection *selection;
- ESourceList *source_list;
GConfClient *gconf_client;
gchar *uid, *tmp_str;
GtkWidget *name_selector_box;
@@ -176,6 +176,7 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
GtkWidget *destination_box;
GtkWidget *status_message;
GtkWidget *source_combo;
+ ESourceRegistry *registry;
name_selector_dialog->priv =
E_NAME_SELECTOR_DIALOG_GET_PRIVATE (name_selector_dialog);
@@ -322,13 +323,6 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
g_object_unref (G_OBJECT (tmp_relation));
g_object_unref (G_OBJECT (tmp_relation_set));
- /* Get addressbook sources */
-
- if (!e_book_client_get_sources (&source_list, NULL)) {
- g_warning ("ENameSelectorDialog can't find any addressbooks!");
- return;
- }
-
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (name_selector_dialog))), name_selector_box, TRUE, TRUE, 0);
/* Store pointers to relevant widgets */
@@ -393,11 +387,11 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
/* Create source menu */
- source_combo = e_source_combo_box_new (source_list);
+ registry = e_source_registry_get_default ();
+ source_combo = e_source_combo_box_new (registry, "address-book");
g_signal_connect_swapped (
source_combo, "changed",
G_CALLBACK (source_changed), name_selector_dialog);
- g_object_unref (source_list);
if (uid) {
e_source_combo_box_set_active_uid (
diff --git a/libedataserverui/e-source-combo-box.c b/libedataserverui/e-source-combo-box.c
index 0e632a5..976a50d 100644
--- a/libedataserverui/e-source-combo-box.c
+++ b/libedataserverui/e-source-combo-box.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* e-source-option-menu.c
+/* e-source-combo-box.c
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
@@ -22,6 +22,8 @@
#include <config.h>
#endif
+#include <libedataserver/e-source-selectable.h>
+
#include "e-source-combo-box.h"
#include "e-cell-renderer-color.h"
@@ -32,14 +34,16 @@
G_DEFINE_TYPE (ESourceComboBox, e_source_combo_box, GTK_TYPE_COMBO_BOX)
struct _ESourceComboBoxPrivate {
- ESourceList *source_list;
+ ESourceRegistry *registry;
GHashTable *uid_index;
gulong handler_id;
+ gchar *extension_name;
};
enum {
PROP_0,
- PROP_SOURCE_LIST
+ PROP_EXTENSION_NAME,
+ PROP_REGISTRY
};
enum {
@@ -47,194 +51,134 @@ enum {
COLUMN_NAME, /* G_TYPE_STRING */
COLUMN_SENSITIVE, /* G_TYPE_BOOLEAN */
COLUMN_SOURCE, /* G_TYPE_OBJECT */
- COLUMN_VISIBLE, /* G_TYPE_BOOLEAN */
NUM_COLUMNS
};
static gpointer parent_class = NULL;
-static gint
-compare_source_names (ESource *source_a,
- ESource *source_b)
+static gboolean
+source_combo_box_traverse (GNode *node,
+ ESourceComboBox *combo_box)
{
- const gchar *name_a;
- const gchar *name_b;
+ ESource *source;
+ ESourceSelectable *extension = NULL;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GString *indented;
+ GdkColor color;
+ const gchar *ext_name;
+ const gchar *display_name;
+ gboolean sensitive = FALSE;
+ gboolean use_color = FALSE;
+
+ /* Skip the root node. */
+ if (G_NODE_IS_ROOT (node))
+ return FALSE;
- g_return_val_if_fail (E_IS_SOURCE (source_a), -1);
- g_return_val_if_fail (E_IS_SOURCE (source_b), 1);
+ ext_name = e_source_combo_box_get_extension_name (combo_box);
- name_a = e_source_peek_name (source_a);
- name_b = e_source_peek_name (source_b);
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
- return g_utf8_collate (name_a, name_b);
-}
+ source = E_SOURCE (node->data);
+ display_name = e_source_get_display_name (source);
-static void
-source_list_changed_cb (ESourceList *source_list,
- ESourceComboBox *source_combo_box)
-{
- ESourceComboBoxPrivate *priv;
- GtkComboBox *combo_box;
- GtkTreeModel *model;
- GtkListStore *store;
- GtkTreeIter iter;
- GtkTreePath *path;
- GSList *groups;
- GSList *sources, *s;
- const gchar *name;
- const gchar *uid;
- gchar *indented_name;
- gboolean visible = FALSE;
- gboolean iter_valid;
+ indented = g_string_new (NULL);
- priv = source_combo_box->priv;
+ if (ext_name != NULL && e_source_has_extension (source, ext_name))
+ extension = e_source_get_extension (source, ext_name);
- combo_box = GTK_COMBO_BOX (source_combo_box);
+ if (E_IS_SOURCE_SELECTABLE (extension)) {
+ const gchar *color_spec;
+ guint depth;
- model = gtk_combo_box_get_model (combo_box);
- store = GTK_LIST_STORE (model);
+ depth = g_node_depth (node);
+ g_warn_if_fail (depth > 1);
+ while (--depth > 1)
+ g_string_append (indented, " ");
- if (source_list == NULL) {
- gtk_list_store_clear (store);
- return;
- }
+ color_spec = e_source_selectable_get_color (extension);
+ if (color_spec != NULL && *color_spec != '\0')
+ use_color = gdk_color_parse (color_spec, &color);
- /* XXX The algorithm below is needlessly complex. Would be
- * easier just to clear and rebuild the store. There's
- * hardly a performance issue here since source lists
- * are short. */
-
- iter_valid = gtk_tree_model_get_iter_first (model, &iter);
-
- for (groups = e_source_list_peek_groups (source_list);
- groups != NULL; groups = groups->next) {
-
- /* Only show source groups that have sources. */
- if (e_source_group_peek_sources (groups->data) == NULL)
- continue;
-
- name = e_source_group_peek_name (groups->data);
- if (!iter_valid)
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (
- store, &iter,
- COLUMN_COLOR, NULL,
- COLUMN_NAME, name,
- COLUMN_SENSITIVE, FALSE,
- COLUMN_SOURCE, groups->data,
- -1);
- iter_valid = gtk_tree_model_iter_next (model, &iter);
-
- sources = e_source_group_peek_sources (groups->data);
-
- /* Create a shallow copy and sort by name. */
- sources = g_slist_sort (
- g_slist_copy (sources),
- (GCompareFunc) compare_source_names);
-
- for (s = sources; s != NULL; s = s->next) {
- const gchar *color_spec;
- GdkColor color;
-
- name = e_source_peek_name (s->data);
- indented_name = g_strconcat (" ", name, NULL);
-
- color_spec = e_source_peek_color_spec (s->data);
- if (color_spec != NULL) {
- gdk_color_parse (color_spec, &color);
- visible = TRUE;
- }
-
- if (!iter_valid)
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (
- store, &iter,
- COLUMN_COLOR, color_spec ? &color : NULL,
- COLUMN_NAME, indented_name,
- COLUMN_SENSITIVE, TRUE,
- COLUMN_SOURCE, s->data,
- -1);
-
- uid = e_source_peek_uid (s->data);
- path = gtk_tree_model_get_path (model, &iter);
- g_hash_table_replace (
- priv->uid_index, g_strdup (uid),
- gtk_tree_row_reference_new (model, path));
- gtk_tree_path_free (path);
- iter_valid = gtk_tree_model_iter_next (model, &iter);
-
- g_free (indented_name);
- }
- g_slist_free (sources);
+ sensitive = TRUE;
+
+ g_hash_table_insert (
+ combo_box->priv->uid_index,
+ g_strdup (e_source_get_uid (source)),
+ gtk_tree_iter_copy (&iter));
}
- /* Remove any extra references that might be leftover from the original model */
- while (gtk_list_store_iter_is_valid (store, &iter))
- gtk_list_store_remove (store, &iter);
+ g_string_append (indented, display_name);
- /* Set the visible column based on whether we've seen a color. */
- iter_valid = gtk_tree_model_get_iter_first (model, &iter);
- while (iter_valid) {
- gtk_list_store_set (
- store, &iter, COLUMN_VISIBLE, visible, -1);
- iter_valid = gtk_tree_model_iter_next (model, &iter);
- }
+ gtk_list_store_set (
+ GTK_LIST_STORE (model), &iter,
+ COLUMN_COLOR, use_color ? &color : NULL,
+ COLUMN_NAME, indented->str,
+ COLUMN_SENSITIVE, sensitive,
+ COLUMN_SOURCE, source,
+ -1);
+
+ g_string_free (indented, TRUE);
+
+ return FALSE;
}
-static GObject *
-e_source_combo_box_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_properties)
+static void
+source_combo_box_build_model (ESourceComboBox *combo_box)
{
- GtkCellRenderer *renderer;
- GtkListStore *store;
- GObject *object;
+ ESourceRegistry *registry;
+ const gchar *ext_name;
+ GtkTreeModel *model;
+ GNode *root;
- /* Chain up to parent's "constructor" method. */
- object = G_OBJECT_CLASS (parent_class)->constructor (
- type, n_construct_properties, construct_properties);
+ registry = e_source_combo_box_get_registry (combo_box);
+ ext_name = e_source_combo_box_get_extension_name (combo_box);
- store = gtk_list_store_new (
- NUM_COLUMNS,
- GDK_TYPE_COLOR, /* COLUMN_COLOR */
- G_TYPE_STRING, /* COLUMN_NAME */
- G_TYPE_BOOLEAN, /* COLUMN_SENSITIVE */
- G_TYPE_OBJECT, /* COLUMN_SOURCE */
- G_TYPE_BOOLEAN); /* COLUMN_VISIBLE */
- gtk_combo_box_set_model (
- GTK_COMBO_BOX (object), GTK_TREE_MODEL (store));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
+ gtk_list_store_clear (GTK_LIST_STORE (model));
- renderer = e_cell_renderer_color_new ();
- gtk_cell_layout_pack_start (
- GTK_CELL_LAYOUT (object), renderer, FALSE);
- gtk_cell_layout_set_attributes (
- GTK_CELL_LAYOUT (object), renderer,
- "color", COLUMN_COLOR,
- "sensitive", COLUMN_SENSITIVE,
- "visible", COLUMN_VISIBLE,
- NULL);
+ g_hash_table_remove_all (combo_box->priv->uid_index);
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (
- GTK_CELL_LAYOUT (object), renderer, TRUE);
- gtk_cell_layout_set_attributes (
- GTK_CELL_LAYOUT (object), renderer,
- "text", COLUMN_NAME,
- "sensitive", COLUMN_SENSITIVE,
- NULL);
+ /* If we have no extension name, leave the combo box empty. */
+ if (ext_name == NULL)
+ return;
+
+ root = e_source_registry_build_display_tree (registry, ext_name);
+
+ g_node_traverse (
+ root, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+ (GNodeTraverseFunc) source_combo_box_traverse,
+ combo_box);
- return object;
+ g_node_destroy (root);
}
static void
-e_source_combo_box_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+source_combo_box_set_registry (ESourceComboBox *combo_box,
+ ESourceRegistry *registry)
+{
+ g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+ g_return_if_fail (combo_box->priv->registry == NULL);
+
+ combo_box->priv->registry = g_object_ref (registry);
+}
+
+static void
+source_combo_box_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
switch (property_id) {
- case PROP_SOURCE_LIST:
- e_source_combo_box_set_source_list (
+ case PROP_EXTENSION_NAME:
+ e_source_combo_box_set_extension_name (
+ E_SOURCE_COMBO_BOX (object),
+ g_value_get_string (value));
+ return;
+
+ case PROP_REGISTRY:
+ source_combo_box_set_registry (
E_SOURCE_COMBO_BOX (object),
g_value_get_object (value));
return;
@@ -244,15 +188,23 @@ e_source_combo_box_set_property (GObject *object,
}
static void
-e_source_combo_box_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+source_combo_box_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
switch (property_id) {
- case PROP_SOURCE_LIST:
+ case PROP_EXTENSION_NAME:
+ g_value_set_string (
+ value,
+ e_source_combo_box_get_extension_name (
+ E_SOURCE_COMBO_BOX (object)));
+ return;
+
+ case PROP_REGISTRY:
g_value_set_object (
- value, e_source_combo_box_get_source_list (
+ value,
+ e_source_combo_box_get_registry (
E_SOURCE_COMBO_BOX (object)));
return;
}
@@ -261,17 +213,18 @@ e_source_combo_box_get_property (GObject *object,
}
static void
-e_source_combo_box_dispose (GObject *object)
+source_combo_box_dispose (GObject *object)
{
ESourceComboBoxPrivate *priv;
priv = E_SOURCE_COMBO_BOX_GET_PRIVATE (object);
- if (priv->source_list != NULL) {
- g_signal_handler_disconnect (
- priv->source_list, priv->handler_id);
- g_object_unref (priv->source_list);
- priv->source_list = NULL;
+ if (priv->registry != NULL) {
+ g_signal_handlers_disconnect_matched (
+ priv->registry, G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, object);
+ g_object_unref (priv->registry);
+ priv->registry = NULL;
}
g_hash_table_remove_all (priv->uid_index);
@@ -281,12 +234,14 @@ e_source_combo_box_dispose (GObject *object)
}
static void
-e_source_combo_box_finalize (GObject *object)
+source_combo_box_finalize (GObject *object)
{
ESourceComboBoxPrivate *priv;
priv = E_SOURCE_COMBO_BOX_GET_PRIVATE (object);
+ g_free (priv->extension_name);
+
g_hash_table_destroy (priv->uid_index);
/* Chain up to parent's "finalize" method. */
@@ -294,6 +249,24 @@ e_source_combo_box_finalize (GObject *object)
}
static void
+source_combo_box_constructed (GObject *object)
+{
+ ESourceComboBox *combo_box;
+ ESourceRegistry *registry;
+
+ combo_box = E_SOURCE_COMBO_BOX (object);
+ registry = e_source_combo_box_get_registry (combo_box);
+
+ g_signal_connect_swapped (
+ registry, "source-added",
+ G_CALLBACK (source_combo_box_build_model), combo_box);
+
+ g_signal_connect_swapped (
+ registry, "source-removed",
+ G_CALLBACK (source_combo_box_build_model), combo_box);
+}
+
+static void
e_source_combo_box_class_init (ESourceComboBoxClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
@@ -302,119 +275,104 @@ e_source_combo_box_class_init (ESourceComboBoxClass *class)
g_type_class_add_private (class, sizeof (ESourceComboBoxPrivate));
- object_class->constructor = e_source_combo_box_constructor;
- object_class->set_property = e_source_combo_box_set_property;
- object_class->get_property = e_source_combo_box_get_property;
- object_class->dispose = e_source_combo_box_dispose;
- object_class->finalize = e_source_combo_box_finalize;
+ object_class->set_property = source_combo_box_set_property;
+ object_class->get_property = source_combo_box_get_property;
+ object_class->dispose = source_combo_box_dispose;
+ object_class->finalize = source_combo_box_finalize;
+ object_class->constructed = source_combo_box_constructed;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_EXTENSION_NAME,
+ g_param_spec_string (
+ "extension-name",
+ "Extension Name",
+ "ESource extension name to filter",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
g_object_class_install_property (
object_class,
- PROP_SOURCE_LIST,
+ PROP_REGISTRY,
g_param_spec_object (
- "source-list",
- "source-list",
- "List of sources to choose from",
- E_TYPE_SOURCE_LIST,
- G_PARAM_READWRITE));
+ "registry",
+ "Registry",
+ "Registry of ESources",
+ E_TYPE_SOURCE_REGISTRY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
}
static void
-e_source_combo_box_init (ESourceComboBox *source_combo_box)
+e_source_combo_box_init (ESourceComboBox *combo_box)
{
- source_combo_box->priv =
- E_SOURCE_COMBO_BOX_GET_PRIVATE (source_combo_box);
- source_combo_box->priv->uid_index =
- g_hash_table_new_full (
- g_str_hash, g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) gtk_tree_row_reference_free);
+ GtkCellRenderer *renderer;
+ GtkCellLayout *layout;
+ GtkListStore *store;
+
+ combo_box->priv = E_SOURCE_COMBO_BOX_GET_PRIVATE (combo_box);
+
+ combo_box->priv->uid_index = g_hash_table_new_full (
+ (GHashFunc) g_str_hash,
+ (GEqualFunc) g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) gtk_tree_iter_free);
+
+ store = gtk_list_store_new (
+ NUM_COLUMNS,
+ GDK_TYPE_COLOR, /* COLUMN_COLOR */
+ G_TYPE_STRING, /* COLUMN_NAME */
+ G_TYPE_BOOLEAN, /* COLUMN_SENSITIVE */
+ G_TYPE_OBJECT); /* COLUMN_SOURCE */
+ gtk_combo_box_set_model (
+ GTK_COMBO_BOX (combo_box),
+ GTK_TREE_MODEL (store));
+ g_object_unref (store);
+
+ layout = GTK_CELL_LAYOUT (combo_box);
+
+ renderer = e_cell_renderer_color_new ();
+ gtk_cell_layout_pack_start (layout, renderer, FALSE);
+ gtk_cell_layout_set_attributes (
+ layout, renderer,
+ "color", COLUMN_COLOR,
+ "sensitive", COLUMN_SENSITIVE,
+ NULL);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (layout, renderer, TRUE);
+ gtk_cell_layout_set_attributes (
+ layout, renderer,
+ "text", COLUMN_NAME,
+ "sensitive", COLUMN_SENSITIVE,
+ NULL);
}
/**
* e_source_combo_box_new:
- * @source_list: an #ESourceList
+ * @registry: an #ESourceRegistry, or %NULL
+ * @extension_name: an #ESource extension name
*
* Creates a new #ESourceComboBox widget that lets the user pick an #ESource
- * from the provided #ESourceList.
+ * from the provided #ESourceRegistry. The displayed sources are restricted
+ * to those which have an @extension_name extension.
+ *
+ * If @registry is %NULL, the default #ESourceRegistry is used.
*
* Returns: a new #ESourceComboBox
*
* Since: 2.22
**/
GtkWidget *
-e_source_combo_box_new (ESourceList *source_list)
+e_source_combo_box_new (ESourceRegistry *registry,
+ const gchar *extension_name)
{
- 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_SOURCE_COMBO_BOX,
- "source-list", source_list, NULL);
-}
-
-/**
- * e_source_combo_box_get_source_list:
- * @combo_box: an #ESourceComboBox
- *
- * Returns the #ESourceList which is acting as a data source for
- * @combo_box.
- *
- * Returns: an #ESourceList
- *
- * Since: 2.22
- **/
-ESourceList *
-e_source_combo_box_get_source_list (ESourceComboBox *combo_box)
-{
- g_return_val_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box), NULL);
-
- return combo_box->priv->source_list;
-}
-
-/**
- * e_source_combo_box_set_source_list:
- * @combo_box: an #ESourceComboBox
- * @source_list: an #ESourceList
- *
- * Sets the source list used by @source_combo_box to be @source_list. This
- * causes the contents of @source_combo_box to be regenerated.
- *
- * Since: 2.22
- **/
-void
-e_source_combo_box_set_source_list (ESourceComboBox *combo_box,
- ESourceList *source_list)
-{
- g_return_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box));
-
- if (source_list != NULL) {
- g_return_if_fail (E_IS_SOURCE_LIST (source_list));
- g_object_ref (source_list);
- }
-
- if (combo_box->priv->source_list != NULL) {
- g_signal_handler_disconnect (
- combo_box->priv->source_list,
- combo_box->priv->handler_id);
- g_object_unref (combo_box->priv->source_list);
- combo_box->priv->handler_id = 0;
- }
-
- combo_box->priv->source_list = source_list;
-
- /* Reset the tree store. */
- source_list_changed_cb (source_list, combo_box);
-
- /* Watch for source list changes. */
- if (source_list != NULL) {
- combo_box->priv->handler_id =
- g_signal_connect_object (
- source_list, "changed",
- G_CALLBACK (source_list_changed_cb),
- combo_box, 0);
- }
-
- g_object_notify (G_OBJECT (combo_box), "source-list");
+ E_TYPE_SOURCE_COMBO_BOX, "registry", registry,
+ "extension-name", extension_name, NULL);
}
/**
@@ -466,7 +424,7 @@ e_source_combo_box_set_active (ESourceComboBox *combo_box,
g_return_if_fail (E_IS_SOURCE (source));
e_source_combo_box_set_active_uid (
- combo_box, e_source_peek_uid (source));
+ combo_box, e_source_get_uid (source));
}
/**
@@ -491,7 +449,7 @@ e_source_combo_box_get_active_uid (ESourceComboBox *combo_box)
if (source == NULL)
return NULL;
- return e_source_peek_uid (source);
+ return e_source_get_uid (source);
}
/**
@@ -509,34 +467,77 @@ gboolean
e_source_combo_box_set_active_uid (ESourceComboBox *combo_box,
const gchar *uid)
{
- ESourceComboBoxPrivate *priv;
- GtkTreeRowReference *reference;
- GtkComboBox *gtk_combo_box;
- GtkTreeIter iter;
- GtkTreePath *path;
- gboolean iter_was_set;
+ GtkTreeIter *iter;
g_return_val_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box), FALSE);
g_return_val_if_fail (uid != NULL, FALSE);
- priv = combo_box->priv;
- gtk_combo_box = GTK_COMBO_BOX (combo_box);
-
- reference = g_hash_table_lookup (priv->uid_index, uid);
- if (!reference)
+ iter = g_hash_table_lookup (combo_box->priv->uid_index, uid);
+ if (iter == NULL)
return FALSE;
- g_return_val_if_fail (gtk_tree_row_reference_valid (reference), FALSE);
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), iter);
- path = gtk_tree_row_reference_get_path (reference);
- iter_was_set = gtk_tree_model_get_iter (
- gtk_combo_box_get_model (gtk_combo_box), &iter,
- path);
- gtk_tree_path_free (path);
+ return TRUE;
+}
- g_return_val_if_fail (iter_was_set, FALSE);
+/**
+ * e_source_combo_box_get_extension_name:
+ * @combo_box: an #ESourceComboBox
+ *
+ * Returns the extension name used to filter which data sources are
+ * shown in @combo_box.
+ *
+ * Returns: the #ESource extension name
+ *
+ * Since: 3.4
+ **/
+const gchar *
+e_source_combo_box_get_extension_name (ESourceComboBox *combo_box)
+{
+ g_return_val_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box), NULL);
- gtk_combo_box_set_active_iter (gtk_combo_box, &iter);
+ return combo_box->priv->extension_name;
+}
- return TRUE;
+/**
+ * e_source_combo_box_set_extension_name:
+ * @combo_box: an #ESourceComboBox
+ * @extension_name: an #ESource extension name
+ *
+ * Sets the extension name used to filter which data sources are shown in
+ * @combo_box.
+ *
+ * Since: 3.4
+ **/
+void
+e_source_combo_box_set_extension_name (ESourceComboBox *combo_box,
+ const gchar *extension_name)
+{
+ g_return_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box));
+
+ g_free (combo_box->priv->extension_name);
+ combo_box->priv->extension_name = g_strdup (extension_name);
+
+ source_combo_box_build_model (combo_box);
+
+ g_object_notify (G_OBJECT (combo_box), "extension-name");
+}
+
+/**
+ * e_source_combo_box_get_registry:
+ * @combo_box: an #ESourceComboBox
+ *
+ * Returns the #ESourceRegistry supplied to e_source_combo_box_new().
+ *
+ * Returns: the #ESourceRegistry
+ *
+ * Since: 3.4
+ **/
+ESourceRegistry *
+e_source_combo_box_get_registry (ESourceComboBox *combo_box)
+{
+ g_return_val_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box), NULL);
+
+ return combo_box->priv->registry;
}
diff --git a/libedataserverui/e-source-combo-box.h b/libedataserverui/e-source-combo-box.h
index 193732b..0e1722a 100644
--- a/libedataserverui/e-source-combo-box.h
+++ b/libedataserverui/e-source-combo-box.h
@@ -22,7 +22,7 @@
#define E_SOURCE_COMBO_BOX_H
#include <gtk/gtk.h>
-#include <libedataserver/e-source-list.h>
+#include <libedataserver/e-source-registry.h>
#define E_TYPE_SOURCE_COMBO_BOX \
(e_source_combo_box_get_type ())
@@ -61,22 +61,23 @@ struct _ESourceComboBoxClass {
};
GType e_source_combo_box_get_type (void);
-GtkWidget * e_source_combo_box_new (ESourceList *source_list);
-ESourceList * e_source_combo_box_get_source_list
- (ESourceComboBox *combo_box);
-void e_source_combo_box_set_source_list
- (ESourceComboBox *combo_box,
- ESourceList *source_list);
-ESource * e_source_combo_box_get_active
- (ESourceComboBox *combo_box);
-void e_source_combo_box_set_active
- (ESourceComboBox *combo_box,
+GtkWidget * e_source_combo_box_new (ESourceRegistry *registry,
+ const gchar *extension_name);
+ESource * e_source_combo_box_get_active (ESourceComboBox *combo_box);
+void e_source_combo_box_set_active (ESourceComboBox *combo_box,
ESource *source);
const gchar * e_source_combo_box_get_active_uid
(ESourceComboBox *combo_box);
gboolean e_source_combo_box_set_active_uid
(ESourceComboBox *combo_box,
const gchar *uid);
+const gchar * e_source_combo_box_get_extension_name
+ (ESourceComboBox *combo_box);
+void e_source_combo_box_set_extension_name
+ (ESourceComboBox *combo_box,
+ const gchar *extension_name);
+ESourceRegistry *
+ e_source_combo_box_get_registry (ESourceComboBox *combo_box);
G_END_DECLS
diff --git a/tests/libedataserverui/test-source-combo-box.c b/tests/libedataserverui/test-source-combo-box.c
index b144549..67d69be 100644
--- a/tests/libedataserverui/test-source-combo-box.c
+++ b/tests/libedataserverui/test-source-combo-box.c
@@ -20,30 +20,34 @@
* Author: Ettore Perazzoli <ettore ximian com>
*/
+#include <config.h>
+#include <gtk/gtk.h>
+
+#include <libedataserver/e-source-address-book.h>
#include <libedataserverui/e-source-combo-box.h>
+static const gchar *extension_name;
+
static void
source_changed_cb (ESourceComboBox *combo_box)
{
ESource *source;
+ const gchar *display_name;
source = e_source_combo_box_get_active (combo_box);
- g_print ("source selected: \"%s\"\n", e_source_peek_name (source));
+ display_name = e_source_get_display_name (source);
+
+ g_print ("source selected: \"%s\"\n", display_name);
}
static gint
-on_idle_create_widget (const gchar *gconf_path)
+on_idle_create_widget (ESourceRegistry *registry)
{
GtkWidget *window;
GtkWidget *combo_box;
- ESourceList *source_list;
- GConfClient *gconf_client;
-
- gconf_client = gconf_client_get_default ();
- source_list = e_source_list_new_for_gconf (gconf_client, gconf_path);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- combo_box = e_source_combo_box_new (source_list);
+ combo_box = e_source_combo_box_new (registry, extension_name);
g_signal_connect (
combo_box, "changed",
G_CALLBACK (source_changed_cb), NULL);
@@ -51,9 +55,6 @@ on_idle_create_widget (const gchar *gconf_path)
gtk_container_add (GTK_CONTAINER (window), combo_box);
gtk_widget_show_all (window);
- g_object_unref (gconf_client);
- g_object_unref (source_list);
-
return FALSE;
}
@@ -61,16 +62,25 @@ gint
main (gint argc,
gchar **argv)
{
- const gchar *gconf_path;
+ ESourceRegistry *registry;
+ GError *error = NULL;
gtk_init (&argc, &argv);
if (argc < 2)
- gconf_path = "/apps/evolution/calendar/sources";
+ extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
else
- gconf_path = argv[1];
+ extension_name = argv[1];
+
+ registry = e_source_registry_new_sync (NULL, &error);
+
+ if (error != NULL) {
+ g_error ("Failed to load ESource registry: %s",
+ error->message);
+ g_assert_not_reached ();
+ }
- g_idle_add ((GSourceFunc) on_idle_create_widget, (gpointer) gconf_path);
+ g_idle_add ((GSourceFunc) on_idle_create_widget, registry);
gtk_main ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]