[evolution] Bug 739585 - [Automatic Contacts] Show configuration also in Edit->Plugins



commit 7e524aa3ef773c7089988378400dcff71ac9c165
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 11 17:27:16 2014 +0100

    Bug 739585 - [Automatic Contacts] Show configuration also in Edit->Plugins

 plugins/bbdb/bbdb.c |   86 +++++++++++++++++++++++++++++----------------------
 1 files changed, 49 insertions(+), 37 deletions(-)
---
diff --git a/plugins/bbdb/bbdb.c b/plugins/bbdb/bbdb.c
index babe98d..4e05864 100644
--- a/plugins/bbdb/bbdb.c
+++ b/plugins/bbdb/bbdb.c
@@ -37,6 +37,7 @@
 
 /* Plugin hooks */
 gint e_plugin_lib_enable (EPlugin *ep, gint enable);
+GtkWidget *e_plugin_lib_get_configure_widget (EPlugin *plugin);
 void bbdb_handle_send (EPlugin *ep, EMEventTargetComposer *target);
 GtkWidget *bbdb_page_factory (EPlugin *ep, EConfigHookItemFactoryData *hook_data);
 
@@ -52,8 +53,7 @@ static void bbdb_do_it (EBookClient *client, const gchar *name, const gchar *ema
 static void add_email_to_contact (EContact *contact, const gchar *email);
 static void enable_toggled_cb (GtkWidget *widget, gpointer data);
 static void source_changed_cb (ESourceComboBox *source_combo_box, struct bbdb_stuff *stuff);
-static GtkWidget *create_addressbook_combo_box (struct bbdb_stuff *stuff, gint type);
-static void cleanup_cb (GObject *o, gpointer data);
+static GtkWidget *bbdb_create_config_widget (void);
 
 /* How often check, in minutes. Read only on plugin enable. Use <= 0 to disable polling. */
 static gint
@@ -99,6 +99,12 @@ e_plugin_lib_enable (EPlugin *ep,
        return 0;
 }
 
+GtkWidget *
+e_plugin_lib_get_configure_widget (EPlugin *plugin)
+{
+       return bbdb_create_config_widget ();
+}
+
 static gboolean
 bbdb_timeout (gpointer data)
 {
@@ -628,15 +634,14 @@ gaim_source_changed_cb (ESourceComboBox *source_combo_box,
 
 static GtkWidget *
 create_addressbook_combo_box (struct bbdb_stuff *stuff,
-                              gint type)
+                              gint type,
+                             GSettings *settings)
 {
        EShell *shell;
-       ESource *source;
        ESourceRegistry *registry;
        GtkWidget *combo_box;
        const gchar *extension_name;
-       gchar *uid;
-       GSettings *settings = g_settings_new (CONF_SCHEMA);
+       const gchar *key;
 
        shell = e_shell_get_default ();
        registry = e_shell_get_registry (shell);
@@ -644,32 +649,25 @@ create_addressbook_combo_box (struct bbdb_stuff *stuff,
        combo_box = e_source_combo_box_new (registry, extension_name);
 
        if (type == GAIM_ADDRESSBOOK)
-               uid = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK_GAIM);
+               key = CONF_KEY_WHICH_ADDRESSBOOK_GAIM;
        else
-               uid = g_settings_get_string (settings, CONF_KEY_WHICH_ADDRESSBOOK);
-       source = e_source_registry_ref_source (registry, uid);
-       g_free (uid);
+               key = CONF_KEY_WHICH_ADDRESSBOOK;
 
-       if (source != NULL) {
-               e_source_combo_box_set_active (
-                       E_SOURCE_COMBO_BOX (combo_box), source);
-               g_object_unref (source);
-       }
+       g_settings_bind (
+               settings, key,
+               combo_box, "active-id",
+               G_SETTINGS_BIND_GET);
 
        gtk_widget_show (combo_box);
 
-       g_object_unref (settings);
-
        return combo_box;
 }
 
-GtkWidget *
-bbdb_page_factory (EPlugin *ep,
-                   EConfigHookItemFactoryData *hook_data)
+static GtkWidget *
+bbdb_create_config_widget (void)
 {
        struct bbdb_stuff *stuff;
        GtkWidget *page;
-       GtkWidget *tab_label;
        GtkWidget *frame;
        GtkWidget *frame_label;
        GtkWidget *padding_label;
@@ -691,8 +689,6 @@ bbdb_page_factory (EPlugin *ep,
        /* Create a new notebook page */
        page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
        gtk_container_set_border_width (GTK_CONTAINER (page), 12);
-       tab_label = gtk_label_new (_("Automatic Contacts"));
-       gtk_notebook_append_page (GTK_NOTEBOOK (hook_data->parent), page, tab_label);
 
        /* Frame */
        frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
@@ -716,7 +712,10 @@ bbdb_page_factory (EPlugin *ep,
 
        /* Enable BBDB checkbox */
        check = gtk_check_button_new_with_mnemonic (_("Create _address book entries when sending mails"));
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), g_settings_get_boolean (settings, 
CONF_KEY_ENABLE));
+       g_settings_bind (
+               settings, CONF_KEY_ENABLE,
+               check, "active",
+               G_SETTINGS_BIND_GET);
        g_signal_connect (
                check, "toggled",
                G_CALLBACK (enable_toggled_cb), stuff);
@@ -726,11 +725,14 @@ bbdb_page_factory (EPlugin *ep,
        gtk_box_pack_start (GTK_BOX (inner_vbox), label, FALSE, FALSE, 0);
 
        /* Source selection combo box */
-       combo_box = create_addressbook_combo_box (stuff, AUTOMATIC_CONTACTS_ADDRESSBOOK);
+       combo_box = create_addressbook_combo_box (stuff, AUTOMATIC_CONTACTS_ADDRESSBOOK, settings);
+       g_settings_bind (
+               settings, CONF_KEY_ENABLE,
+               combo_box, "sensitive",
+               G_SETTINGS_BIND_GET);
        g_signal_connect (
                combo_box, "changed",
                G_CALLBACK (source_changed_cb), stuff);
-       gtk_widget_set_sensitive (combo_box, g_settings_get_boolean (settings, CONF_KEY_ENABLE));
        gtk_box_pack_start (GTK_BOX (inner_vbox), combo_box, FALSE, FALSE, 0);
        stuff->combo_box = combo_box;
 
@@ -755,7 +757,10 @@ bbdb_page_factory (EPlugin *ep,
 
        /* Enable Gaim Checkbox */
        check_gaim = gtk_check_button_new_with_mnemonic (_("_Synchronize contact info and images from Pidgin 
buddy list"));
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_gaim), g_settings_get_boolean (settings, 
CONF_KEY_ENABLE_GAIM));
+       g_settings_bind (
+               settings, CONF_KEY_ENABLE_GAIM,
+               check_gaim, "active",
+               G_SETTINGS_BIND_GET);
        g_signal_connect (
                check_gaim, "toggled",
                G_CALLBACK (enable_gaim_toggled_cb), stuff);
@@ -765,11 +770,14 @@ bbdb_page_factory (EPlugin *ep,
        gtk_box_pack_start (GTK_BOX (inner_vbox), gaim_label, FALSE, FALSE, 0);
 
        /* Gaim Source Selection Combo Box */
-       gaim_combo_box = create_addressbook_combo_box (stuff, GAIM_ADDRESSBOOK);
+       gaim_combo_box = create_addressbook_combo_box (stuff, GAIM_ADDRESSBOOK, settings);
        g_signal_connect (
                gaim_combo_box, "changed",
                G_CALLBACK (gaim_source_changed_cb), stuff);
-       gtk_widget_set_sensitive (gaim_combo_box, g_settings_get_boolean (settings, CONF_KEY_ENABLE_GAIM));
+       g_settings_bind (
+               settings, CONF_KEY_ENABLE_GAIM,
+               gaim_combo_box, "sensitive",
+               G_SETTINGS_BIND_GET);
        gtk_box_pack_start (GTK_BOX (inner_vbox), gaim_combo_box, FALSE, FALSE, 0);
        stuff->gaim_combo_box = gaim_combo_box;
 
@@ -781,9 +789,7 @@ bbdb_page_factory (EPlugin *ep,
        gtk_box_pack_start (GTK_BOX (inner_vbox), button, FALSE, FALSE, 0);
 
        /* Clean up */
-       g_signal_connect (
-               page, "destroy",
-               G_CALLBACK (cleanup_cb), stuff);
+       g_object_set_data_full (G_OBJECT (page), "bbdb-config-data", stuff, g_free);
 
        gtk_widget_show_all (page);
 
@@ -792,11 +798,17 @@ bbdb_page_factory (EPlugin *ep,
        return page;
 }
 
-static void
-cleanup_cb (GObject *o,
-            gpointer data)
+GtkWidget *
+bbdb_page_factory (EPlugin *ep,
+                   EConfigHookItemFactoryData *hook_data)
 {
-       struct bbdb_stuff *stuff = data;
+       GtkWidget *page;
+       GtkWidget *tab_label;
 
-       g_free (stuff);
+       page = bbdb_create_config_widget ();
+
+       tab_label = gtk_label_new (_("Automatic Contacts"));
+       gtk_notebook_append_page (GTK_NOTEBOOK (hook_data->parent), page, tab_label);
+
+       return page;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]