diff options
Diffstat (limited to 'plugins/bbdb/bbdb.c')
-rw-r--r-- | plugins/bbdb/bbdb.c | 132 |
1 files changed, 108 insertions, 24 deletions
diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c index 17eb26f176..a4b363af51 100644 --- a/plugins/bbdb/bbdb.c +++ b/plugins/bbdb/bbdb.c @@ -40,7 +40,7 @@ #include <string.h> #include <libebook/e-book.h> -#include <libedataserverui/e-source-option-menu.h> +#include <libedataserverui/e-source-combo-box.h> #include <e-util/e-config.h> #include <mail/em-config.h> @@ -71,10 +71,49 @@ static gboolean bbdb_timeout (gpointer data); static void bbdb_do_it (EBook *book, const char *name, const char *email); static void add_email_to_contact (EContact *contact, const char *email); static void enable_toggled_cb (GtkWidget *widget, gpointer data); -static void source_changed_cb (GtkWidget *widget, ESource *source, gpointer data); +static void source_changed_cb (ESourceComboBox *source_combo_box, struct bbdb_stuff *stuff); static GtkWidget *create_addressbook_option_menu (struct bbdb_stuff *stuff, int 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; +} + int e_plugin_lib_enable (EPluginLib *ep, int enable) { @@ -343,8 +382,23 @@ enable_toggled_cb (GtkWidget *widget, gpointer data) gtk_widget_set_sensitive (stuff->option_menu, active); if (active && !gconf_client_get_string (stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK, NULL)) { - selected_source = e_source_option_menu_peek_selected (E_SOURCE_OPTION_MENU (stuff->option_menu)); - gconf_client_set_string (stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK, e_source_get_uri (selected_source), NULL); + const gchar *uri = NULL; + GError *error = NULL; + + selected_source = e_source_combo_box_get_active ( + E_SOURCE_COMBO_BOX (stuff->option_menu)); + if (selected_source != NULL) + uri = e_source_get_uri (selected_source); + + gconf_client_set_string ( + stuff->target->gconf, + GCONF_KEY_WHICH_ADDRESSBOOK, + uri, &error); + + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } } } @@ -362,7 +416,8 @@ enable_gaim_toggled_cb (GtkWidget *widget, gpointer data) gtk_widget_set_sensitive (stuff->gaim_option_menu, active); if (active && !gconf_client_get_string (stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK_GAIM, NULL)) { - selected_source = e_source_option_menu_peek_selected (E_SOURCE_OPTION_MENU (stuff->gaim_option_menu)); + selected_source = e_source_combo_box_get_active ( + E_SOURCE_COMBO_BOX (stuff->gaim_option_menu)); gconf_client_set_string (stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK_GAIM, e_source_get_uri (selected_source), NULL); } } @@ -374,48 +429,77 @@ synchronize_button_clicked_cb (GtkWidget *button) } static void -source_changed_cb (GtkWidget *widget, ESource *source, gpointer data) +source_changed_cb (ESourceComboBox *source_combo_box, + struct bbdb_stuff *stuff) { - struct bbdb_stuff *stuff = (struct bbdb_stuff *) data; - - gconf_client_set_string (stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK, e_source_get_uri (source), NULL); + ESource *source; + GError *error = NULL; + + source = e_source_combo_box_get_active (source_combo_box); + g_return_if_fail (source != NULL); + + gconf_client_set_string ( + stuff->target->gconf, + GCONF_KEY_WHICH_ADDRESSBOOK, + e_source_get_uri (source), &error); + + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } } static void -gaim_source_changed_cb (GtkWidget *widget, ESource *source, gpointer data) +gaim_source_changed_cb (ESourceComboBox *source_combo_box, + struct bbdb_stuff *stuff) { - struct bbdb_stuff *stuff = (struct bbdb_stuff *) data; - gconf_client_set_string (stuff->target->gconf, GCONF_KEY_WHICH_ADDRESSBOOK_GAIM, e_source_get_uri (source), NULL); + ESource *source; + GError *error = NULL; + + source = e_source_combo_box_get_active (source_combo_box); + g_return_if_fail (source != NULL); + + gconf_client_set_string ( + stuff->target->gconf, + GCONF_KEY_WHICH_ADDRESSBOOK_GAIM, + e_source_get_uri (source), &error); + + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } } static GtkWidget * create_addressbook_option_menu (struct bbdb_stuff *stuff, int type) { - GtkWidget *menu; + GtkWidget *combo_box; ESourceList *source_list; - char *selected_source_uri; ESource *selected_source; + char *selected_source_uri; GConfClient *gconf = stuff->target->gconf; source_list = e_source_list_new_for_gconf (gconf, "/apps/evolution/addressbook/sources"); - menu = e_source_option_menu_new (source_list); + combo_box = e_source_combo_box_new (source_list); if (type == GAIM_ADDRESSBOOK) selected_source_uri = gconf_client_get_string (gconf, GCONF_KEY_WHICH_ADDRESSBOOK_GAIM, NULL); else selected_source_uri = gconf_client_get_string (gconf, GCONF_KEY_WHICH_ADDRESSBOOK, NULL); - if (selected_source_uri != NULL) { - selected_source = e_source_new_with_absolute_uri ("", selected_source_uri); - e_source_option_menu_select (E_SOURCE_OPTION_MENU (menu), selected_source); - g_free (selected_source_uri); - } + selected_source = find_esource_by_uri ( + source_list, selected_source_uri); + g_free (selected_source_uri); + + if (selected_source != NULL) + e_source_combo_box_set_active ( + E_SOURCE_COMBO_BOX (combo_box), selected_source); - gtk_widget_show (menu); + gtk_widget_show (combo_box); stuff->source_list = source_list; - return menu; + return combo_box; } GtkWidget * @@ -481,7 +565,7 @@ bbdb_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data) /* Source selection option menu */ option = create_addressbook_option_menu (stuff, AUTOMATIC_CONTACTS_ADDRESSBOOK); - g_signal_connect (option, "source_selected", G_CALLBACK (source_changed_cb), stuff); + g_signal_connect (option, "changed", G_CALLBACK (source_changed_cb), stuff); gtk_widget_set_sensitive (option, gconf_client_get_bool (target->gconf, GCONF_KEY_ENABLE, NULL)); gtk_box_pack_start (GTK_BOX (inner_vbox), option, FALSE, FALSE, 0); stuff->option_menu = option; @@ -517,7 +601,7 @@ bbdb_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data) /* Gaim Source Selection Option Menu */ gaim_option = create_addressbook_option_menu (stuff, GAIM_ADDRESSBOOK); - g_signal_connect (gaim_option, "source_selected", G_CALLBACK (gaim_source_changed_cb), stuff); + g_signal_connect (gaim_option, "changed", G_CALLBACK (gaim_source_changed_cb), stuff); gtk_widget_set_sensitive (gaim_option, gconf_client_get_bool (target->gconf, GCONF_KEY_ENABLE_GAIM, NULL)); gtk_box_pack_start (GTK_BOX (inner_vbox), gaim_option, FALSE, FALSE, 0); stuff->gaim_option_menu = gaim_option; |