diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2008-09-12 09:54:07 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-09-12 09:54:07 +0800 |
commit | df6a8262a141e0bec824149e7f65568d2187c5c2 (patch) | |
tree | 463604008060e542f3dcdbfdd5fce4e056af8c1c /addressbook/gui | |
parent | cbe90f148abbfd273f301358c7fa73a58ff5dd41 (diff) | |
download | gsoc2013-evolution-df6a8262a141e0bec824149e7f65568d2187c5c2.tar.gz gsoc2013-evolution-df6a8262a141e0bec824149e7f65568d2187c5c2.tar.zst gsoc2013-evolution-df6a8262a141e0bec824149e7f65568d2187c5c2.zip |
Arrange for an ESourceList to be shared amongst all instances of a type of
shell view. For example, all EBookShellView instances will now share the
same ESourceList instance for address books.
svn path=/branches/kill-bonobo/; revision=36311
Diffstat (limited to 'addressbook/gui')
-rw-r--r-- | addressbook/gui/component/e-book-shell-module.c | 72 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view-private.c | 15 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view-private.h | 8 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view.c | 46 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view.h | 6 |
5 files changed, 110 insertions, 37 deletions
diff --git a/addressbook/gui/component/e-book-shell-module.c b/addressbook/gui/component/e-book-shell-module.c index 117206c9b7..7f4b2a8875 100644 --- a/addressbook/gui/component/e-book-shell-module.c +++ b/addressbook/gui/component/e-book-shell-module.c @@ -57,28 +57,42 @@ GalViewCollection *e_book_shell_module_view_collection = NULL; static void book_module_ensure_sources (EShellModule *shell_module) { + /* XXX This is basically the same algorithm across all modules. + * Maybe we could somehow integrate this into EShellModule? */ + ESourceList *source_list; ESourceGroup *on_this_computer; ESourceGroup *on_ldap_servers; - ESource *personal_source; + ESource *personal; GSList *groups, *iter; - const gchar *base_dir; + const gchar *data_dir; gchar *base_uri; - gchar *base_uri_proto; + gchar *filename; on_this_computer = NULL; on_ldap_servers = NULL; - personal_source = NULL; + personal = NULL; if (!e_book_get_addressbooks (&source_list, NULL)) { g_warning ("Could not get addressbook sources from GConf!"); return; } - base_dir = e_shell_module_get_data_dir (shell_module); - base_uri = g_build_filename (base_dir, "local", NULL); - - base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); + /* Share the source list with all address book views. This + * is accessible via e_book_shell_view_get_source_list(). + * Note: EShellModule takes ownership of the reference. + * + * XXX I haven't yet decided if I want to add a proper + * EShellModule API for this. The mail module would + * not use it. */ + g_object_set_data_full ( + G_OBJECT (shell_module), "source-list", + source_list, (GDestroyNotify) g_object_unref); + + data_dir = e_shell_module_get_data_dir (shell_module); + filename = g_build_filename (data_dir, "local", NULL); + base_uri = g_filename_to_uri (filename, NULL, NULL); + g_free (filename); groups = e_source_list_peek_groups (source_list); for (iter = groups; iter != NULL; iter = iter->next) { @@ -87,14 +101,14 @@ book_module_ensure_sources (EShellModule *shell_module) group_base_uri = e_source_group_peek_base_uri (source_group); - /* Compare only "file://" part. if user home directory - * changes, we do not want to create one more group. */ + /* Compare only "file://" part. If the user's home + * changes, we do not want to create another group. */ if (on_this_computer == NULL && - strncmp (base_uri_proto, group_base_uri, 7) == 0) + strncmp (base_uri, group_base_uri, 7) == 0) on_this_computer = source_group; else if (on_ldap_servers == NULL && - g_str_equal (LDAP_BASE_URI, group_base_uri)) + strcmp (LDAP_BASE_URI, group_base_uri) == 0) on_ldap_servers = source_group; } @@ -105,7 +119,7 @@ book_module_ensure_sources (EShellModule *shell_module) sources = e_source_group_peek_sources (on_this_computer); group_base_uri = e_source_group_peek_base_uri (on_this_computer); - /* Make this group includes a "Personal" source. */ + /* Make sure this group includes a "Personal" source. */ for (iter = sources; iter != NULL; iter = iter->next) { ESource *source = iter->data; const gchar *relative_uri; @@ -114,22 +128,23 @@ book_module_ensure_sources (EShellModule *shell_module) if (relative_uri == NULL) continue; - if (g_str_equal (PERSONAL_RELATIVE_URI, relative_uri)) { - personal_source = source; - break; - } + if (strcmp (PERSONAL_RELATIVE_URI, relative_uri) != 0) + continue; + + personal = source; + break; } /* Make sure we have the correct base URI. This can * change when the user's home directory changes. */ - if (!g_str_equal (base_uri_proto, group_base_uri)) { + if (strcmp (base_uri, group_base_uri) != 0) { e_source_group_set_base_uri ( - on_this_computer, base_uri_proto); + on_this_computer, base_uri); /* XXX We shouldn't need this sync call here as * set_base_uri() results in synching to GConf, * but that happens in an idle loop and too late - * to prevent the user from seeing "Cannot + * to prevent the user from seeing a "Cannot * Open ... because of invalid URI" error. */ e_source_list_sync (source_list, NULL); } @@ -138,13 +153,13 @@ book_module_ensure_sources (EShellModule *shell_module) ESourceGroup *source_group; const gchar *name; - /* Create the local source group. */ name = _("On This Computer"); - source_group = e_source_group_new (name, base_uri_proto); + source_group = e_source_group_new (name, base_uri); e_source_list_add_group (source_list, source_group, -1); + g_object_unref (source_group); } - if (personal_source == NULL) { + if (personal == NULL) { ESource *source; const gchar *name; @@ -160,13 +175,12 @@ book_module_ensure_sources (EShellModule *shell_module) ESourceGroup *source_group; const gchar *name; - /* Create the LDAP source group. */ name = _("On LDAP Servers"); source_group = e_source_group_new (name, LDAP_BASE_URI); e_source_list_add_group (source_list, source_group, -1); + g_object_unref (source_group); } - g_free (base_uri_proto); g_free (base_uri); } @@ -236,10 +250,10 @@ book_module_book_loaded_cb (EBook *book, action = GTK_ACTION (user_data); action_name = gtk_action_get_name (action); - if (g_str_equal (action_name, "contact-new")) + if (strcmp (action_name, "contact-new") == 0) eab_show_contact_editor (book, contact, TRUE, TRUE); - if (g_str_equal (action_name, "contact-list-new")) + if (strcmp (action_name, "contact-list-new") == 0) eab_show_contact_list_editor (book, contact, TRUE, TRUE); g_object_unref (contact); @@ -250,7 +264,7 @@ static void action_contact_new_cb (GtkAction *action, EShellWindow *shell_window) { - EBook *book; + EBook *book = NULL; GConfClient *client; ESourceList *source_list; const gchar *key; @@ -435,7 +449,9 @@ e_shell_module_init (GTypeModule *type_module) shell_module = E_SHELL_MODULE (type_module); shell = e_shell_module_get_shell (shell_module); + /* Register the GType for EBookShellView. */ e_book_shell_view_get_type (type_module); + e_shell_module_set_info (shell_module, &module_info); book_module_ensure_sources (shell_module); diff --git a/addressbook/gui/component/e-book-shell-view-private.c b/addressbook/gui/component/e-book-shell-view-private.c index 4bea688437..1ed66f8289 100644 --- a/addressbook/gui/component/e-book-shell-view-private.c +++ b/addressbook/gui/component/e-book-shell-view-private.c @@ -281,11 +281,18 @@ book_shell_view_primary_selection_changed_cb (EBookShellView *book_shell_view, } void -e_book_shell_view_private_init (EBookShellView *book_shell_view) +e_book_shell_view_private_init (EBookShellView *book_shell_view, + EShellViewClass *shell_view_class) { EBookShellViewPrivate *priv = book_shell_view->priv; + ESourceList *source_list; GHashTable *uid_to_view; GHashTable *uid_to_editor; + GObject *object; + + object = G_OBJECT (shell_view_class->type_module); + source_list = g_object_get_data (object, "source-list"); + g_return_if_fail (E_IS_SOURCE_LIST (source_list)); uid_to_view = g_hash_table_new_full ( g_str_hash, g_str_equal, @@ -297,12 +304,11 @@ e_book_shell_view_private_init (EBookShellView *book_shell_view) (GDestroyNotify) g_free, (GDestroyNotify) g_free); + priv->source_list = g_object_ref (source_list); priv->contact_actions = gtk_action_group_new ("contacts"); priv->activity_handler = e_activity_handler_new (); priv->uid_to_view = uid_to_view; priv->uid_to_editor = uid_to_editor; - - e_book_get_addressbooks (&priv->source_list, NULL); } void @@ -385,6 +391,8 @@ e_book_shell_view_private_dispose (EBookShellView *book_shell_view) { EBookShellViewPrivate *priv = book_shell_view->priv; + DISPOSE (priv->source_list); + DISPOSE (priv->contact_actions); DISPOSE (priv->notebook); @@ -397,7 +405,6 @@ e_book_shell_view_private_dispose (EBookShellView *book_shell_view) g_hash_table_remove_all (priv->uid_to_editor); DISPOSE (priv->book); - DISPOSE (priv->source_list); } void diff --git a/addressbook/gui/component/e-book-shell-view-private.h b/addressbook/gui/component/e-book-shell-view-private.h index ccd344567e..6fbff31c5d 100644 --- a/addressbook/gui/component/e-book-shell-view-private.h +++ b/addressbook/gui/component/e-book-shell-view-private.h @@ -81,6 +81,10 @@ enum { struct _EBookShellViewPrivate { + /*** Module Data ***/ + + ESourceList *source_list; + /*** UI Management ***/ GtkActionGroup *contact_actions; @@ -98,14 +102,14 @@ struct _EBookShellViewPrivate { EBook *book; guint activity_id; - ESourceList *source_list; gchar *password; EABMenu *menu; }; void e_book_shell_view_private_init - (EBookShellView *book_shell_view); + (EBookShellView *book_shell_view, + EShellViewClass *shell_view_class); void e_book_shell_view_private_constructed (EBookShellView *book_shell_view); void e_book_shell_view_private_dispose diff --git a/addressbook/gui/component/e-book-shell-view.c b/addressbook/gui/component/e-book-shell-view.c index 4c06cc5fba..ce0c8f2b55 100644 --- a/addressbook/gui/component/e-book-shell-view.c +++ b/addressbook/gui/component/e-book-shell-view.c @@ -20,6 +20,11 @@ #include "e-book-shell-view-private.h" +enum { + PROP_0, + PROP_SOURCE_LIST +}; + GType e_book_shell_view_type = 0; static gpointer parent_class; @@ -151,6 +156,23 @@ book_shell_view_source_list_changed_cb (EBookShellView *book_shell_view, } static void +book_shell_view_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_SOURCE_LIST: + g_value_set_object ( + value, e_book_shell_view_get_source_list ( + E_BOOK_SHELL_VIEW (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void book_shell_view_dispose (GObject *object) { e_book_shell_view_private_dispose (E_BOOK_SHELL_VIEW (object)); @@ -217,6 +239,7 @@ book_shell_view_class_init (EBookShellViewClass *class, g_type_class_add_private (class, sizeof (EBookShellViewPrivate)); object_class = G_OBJECT_CLASS (class); + object_class->get_property = book_shell_view_get_property; object_class->dispose = book_shell_view_dispose; object_class->finalize = book_shell_view_finalize; object_class->constructed = book_shell_view_constructed; @@ -226,15 +249,26 @@ book_shell_view_class_init (EBookShellViewClass *class, shell_view_class->icon_name = "x-office-address-book"; shell_view_class->type_module = type_module; shell_view_class->changed = book_shell_view_changed; + + g_object_class_install_property ( + object_class, + PROP_SOURCE_LIST, + g_param_spec_object ( + "source-list", + _("Source List"), + _("The registry of address books"), + E_TYPE_SOURCE_LIST, + G_PARAM_READABLE)); } static void -book_shell_view_init (EBookShellView *book_shell_view) +book_shell_view_init (EBookShellView *book_shell_view, + EShellViewClass *shell_view_class) { book_shell_view->priv = E_BOOK_SHELL_VIEW_GET_PRIVATE (book_shell_view); - e_book_shell_view_private_init (book_shell_view); + e_book_shell_view_private_init (book_shell_view, shell_view_class); g_signal_connect_swapped ( book_shell_view->priv->source_list, "changed", @@ -267,3 +301,11 @@ e_book_shell_view_get_type (GTypeModule *type_module) return e_book_shell_view_type; } + +ESourceList * +e_book_shell_view_get_source_list (EBookShellView *book_shell_view) +{ + g_return_val_if_fail (E_IS_BOOK_SHELL_VIEW (book_shell_view), NULL); + + return book_shell_view->priv->source_list; +} diff --git a/addressbook/gui/component/e-book-shell-view.h b/addressbook/gui/component/e-book-shell-view.h index 9071fc7ba4..9dcb48e980 100644 --- a/addressbook/gui/component/e-book-shell-view.h +++ b/addressbook/gui/component/e-book-shell-view.h @@ -22,6 +22,7 @@ #define E_BOOK_SHELL_VIEW_H #include <e-shell-view.h> +#include <libedataserver/e-source-list.h> /* Standard GObject macros */ #define E_TYPE_BOOK_SHELL_VIEW \ @@ -59,7 +60,10 @@ struct _EBookShellViewClass { EShellViewClass parent_class; }; -GType e_book_shell_view_get_type (GTypeModule *type_module); +GType e_book_shell_view_get_type + (GTypeModule *type_module); +ESourceList * e_book_shell_view_get_source_list + (EBookShellView *book_shell_view); G_END_DECLS |