[gnome-media] Fix GConf handling in sound-theme



commit 9c9d27c03b404deb01b9f986c2ed753c389002f8
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 22 15:09:00 2010 +0100

    Fix GConf handling in sound-theme
    
    Fix crasher when using the sound panel the second time around,
    as the GConf handlers were not cleaned up, we were accessing the
    now destroyed sound-theme bits.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=617025

 sound-theme/gvc-sound-theme-chooser.c |   74 ++++++++++++++++----------------
 sound-theme/gvc-sound-theme-editor.c  |   59 ++++++++++++++------------
 2 files changed, 68 insertions(+), 65 deletions(-)
---
diff --git a/sound-theme/gvc-sound-theme-chooser.c b/sound-theme/gvc-sound-theme-chooser.c
index ae2fb7b..732cd1a 100644
--- a/sound-theme/gvc-sound-theme-chooser.c
+++ b/sound-theme/gvc-sound-theme-chooser.c
@@ -47,6 +47,9 @@ struct GvcSoundThemeChooserPrivate
         GtkWidget *theme_box;
         GtkWidget *selection_box;
         GtkWidget *click_feedback_button;
+        GConfClient *client;
+        guint sounds_dir_id;
+        guint metacity_dir_id;
 };
 
 static void     gvc_sound_theme_chooser_class_init (GvcSoundThemeChooserClass *klass);
@@ -95,7 +98,6 @@ on_combobox_changed (GtkComboBox          *widget,
 {
         GtkTreeIter   iter;
         GtkTreeModel *model;
-        GConfClient  *client;
         char         *theme_name;
 
         if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (chooser->priv->combo_box), &iter) == FALSE) {
@@ -107,19 +109,15 @@ on_combobox_changed (GtkComboBox          *widget,
 
         g_assert (theme_name != NULL);
 
-        client = gconf_client_get_default ();
-
         /* special case for no sounds */
         if (strcmp (theme_name, NO_SOUNDS_THEME_NAME) == 0) {
-                gconf_client_set_bool (client, EVENT_SOUNDS_KEY, FALSE, NULL);
-                g_object_unref (client);
+                gconf_client_set_bool (chooser->priv->client, EVENT_SOUNDS_KEY, FALSE, NULL);
                 return;
         } else {
-                gconf_client_set_bool (client, EVENT_SOUNDS_KEY, TRUE, NULL);
+                gconf_client_set_bool (chooser->priv->client, EVENT_SOUNDS_KEY, TRUE, NULL);
         }
 
-        gconf_client_set_string (client, SOUND_THEME_KEY, theme_name, NULL);
-        g_object_unref (client);
+        gconf_client_set_string (chooser->priv->client, SOUND_THEME_KEY, theme_name, NULL);
 
         g_free (theme_name);
 
@@ -949,20 +947,17 @@ update_theme (GvcSoundThemeChooser *chooser)
         char        *theme_name;
         gboolean     events_enabled;
         gboolean     bell_enabled;
-        GConfClient *client;
         gboolean     feedback_enabled;
 
-        client = gconf_client_get_default ();
-
-        bell_enabled = gconf_client_get_bool (client, AUDIO_BELL_KEY, NULL);
+        bell_enabled = gconf_client_get_bool (chooser->priv->client, AUDIO_BELL_KEY, NULL);
         //set_audible_bell_enabled (chooser, bell_enabled);
 
-        feedback_enabled = gconf_client_get_bool (client, INPUT_SOUNDS_KEY, NULL);
+        feedback_enabled = gconf_client_get_bool (chooser->priv->client, INPUT_SOUNDS_KEY, NULL);
         set_input_feedback_enabled (chooser, feedback_enabled);
 
-        events_enabled = gconf_client_get_bool (client, EVENT_SOUNDS_KEY, NULL);
+        events_enabled = gconf_client_get_bool (chooser->priv->client, EVENT_SOUNDS_KEY, NULL);
         if (events_enabled) {
-                theme_name = gconf_client_get_string (client, SOUND_THEME_KEY, NULL);
+                theme_name = gconf_client_get_string (chooser->priv->client, SOUND_THEME_KEY, NULL);
         } else {
                 theme_name = g_strdup (NO_SOUNDS_THEME_NAME);
         }
@@ -975,8 +970,6 @@ update_theme (GvcSoundThemeChooser *chooser)
         update_alerts_from_theme_name (chooser, theme_name);
 
         g_free (theme_name);
-
-        g_object_unref (client);
 }
 
 static GObject *
@@ -1013,14 +1006,11 @@ static void
 on_click_feedback_toggled (GtkToggleButton      *button,
                            GvcSoundThemeChooser *chooser)
 {
-        GConfClient *client;
         gboolean     enabled;
 
         enabled = gtk_toggle_button_get_active (button);
 
-        client = gconf_client_get_default ();
-        gconf_client_set_bool (client, INPUT_SOUNDS_KEY, enabled, NULL);
-        g_object_unref (client);
+        gconf_client_set_bool (chooser->priv->client, INPUT_SOUNDS_KEY, enabled, NULL);
 }
 
 static void
@@ -1084,7 +1074,6 @@ gvc_sound_theme_chooser_init (GvcSoundThemeChooser *chooser)
         GtkWidget   *label;
         GtkWidget   *scrolled_window;
         GtkWidget   *alignment;
-        GConfClient *client;
         char        *str;
 
         chooser->priv = GVC_SOUND_THEME_CHOOSER_GET_PRIVATE (chooser);
@@ -1099,7 +1088,7 @@ gvc_sound_theme_chooser_init (GvcSoundThemeChooser *chooser)
         gtk_box_pack_start (GTK_BOX (chooser->priv->theme_box), chooser->priv->combo_box, FALSE, FALSE, 6);
         gtk_label_set_mnemonic_widget (GTK_LABEL (label), chooser->priv->combo_box);
 
-        client = gconf_client_get_default ();
+        chooser->priv->client = gconf_client_get_default ();
 
         str = g_strdup_printf ("<b>%s</b>", _("C_hoose an alert sound:"));
         chooser->priv->selection_box = box = gtk_frame_new (str);
@@ -1134,7 +1123,7 @@ gvc_sound_theme_chooser_init (GvcSoundThemeChooser *chooser)
 
         chooser->priv->click_feedback_button = gtk_check_button_new_with_mnemonic (_("Enable _window and button sounds"));
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chooser->priv->click_feedback_button),
-                                      gconf_client_get_bool (client, INPUT_SOUNDS_KEY, NULL));
+                                      gconf_client_get_bool (chooser->priv->client, INPUT_SOUNDS_KEY, NULL));
         gtk_box_pack_start (GTK_BOX (chooser),
                             chooser->priv->click_feedback_button,
                             FALSE, FALSE, 0);
@@ -1144,22 +1133,20 @@ gvc_sound_theme_chooser_init (GvcSoundThemeChooser *chooser)
                           chooser);
 
 
-        gconf_client_add_dir (client, KEY_SOUNDS_DIR,
+        gconf_client_add_dir (chooser->priv->client, KEY_SOUNDS_DIR,
                               GCONF_CLIENT_PRELOAD_ONELEVEL,
                               NULL);
-        gconf_client_notify_add (client,
-                                 KEY_SOUNDS_DIR,
-                                 (GConfClientNotifyFunc)on_key_changed,
-                                 chooser, NULL, NULL);
-        gconf_client_add_dir (client, KEY_METACITY_DIR,
+        chooser->priv->sounds_dir_id = gconf_client_notify_add (chooser->priv->client,
+								KEY_SOUNDS_DIR,
+								(GConfClientNotifyFunc)on_key_changed,
+								chooser, NULL, NULL);
+        gconf_client_add_dir (chooser->priv->client, KEY_METACITY_DIR,
                               GCONF_CLIENT_PRELOAD_ONELEVEL,
                               NULL);
-        gconf_client_notify_add (client,
-                                 KEY_METACITY_DIR,
-                                 (GConfClientNotifyFunc)on_key_changed,
-                                 chooser, NULL, NULL);
-
-        g_object_unref (client);
+        chooser->priv->metacity_dir_id = gconf_client_notify_add (chooser->priv->client,
+								  KEY_METACITY_DIR,
+								  (GConfClientNotifyFunc)on_key_changed,
+								  chooser, NULL, NULL);
 
         /* FIXME: should accept drag and drop themes.  should also
            add an "Add Theme..." item to the theme combobox */
@@ -1175,7 +1162,20 @@ gvc_sound_theme_chooser_finalize (GObject *object)
 
         sound_theme_chooser = GVC_SOUND_THEME_CHOOSER (object);
 
-        g_return_if_fail (sound_theme_chooser->priv != NULL);
+	if (sound_theme_chooser->priv != NULL) {
+		if (sound_theme_chooser->priv->sounds_dir_id > 0) {
+			gconf_client_notify_remove (sound_theme_chooser->priv->client,
+						    sound_theme_chooser->priv->sounds_dir_id);
+			sound_theme_chooser->priv->sounds_dir_id = 0;
+		}
+		if (sound_theme_chooser->priv->metacity_dir_id > 0) {
+			gconf_client_notify_remove (sound_theme_chooser->priv->client,
+						    sound_theme_chooser->priv->metacity_dir_id);
+			sound_theme_chooser->priv->metacity_dir_id = 0;
+		}
+		g_object_unref (sound_theme_chooser->priv->client);
+		sound_theme_chooser->priv->client = NULL;
+	}
 
         G_OBJECT_CLASS (gvc_sound_theme_chooser_parent_class)->finalize (object);
 }
diff --git a/sound-theme/gvc-sound-theme-editor.c b/sound-theme/gvc-sound-theme-editor.c
index 52b563b..d56c991 100644
--- a/sound-theme/gvc-sound-theme-editor.c
+++ b/sound-theme/gvc-sound-theme-editor.c
@@ -43,6 +43,9 @@ struct GvcSoundThemeEditorPrivate
         GtkWidget *theme_box;
         GtkWidget *selection_box;
         GtkWidget *click_feedback_button;
+        GConfClient *client;
+        guint sounds_dir_id;
+        guint metacity_dir_id;
 };
 
 static void     gvc_sound_theme_editor_class_init (GvcSoundThemeEditorClass *klass);
@@ -297,9 +300,7 @@ set_theme_name (GvcSoundThemeEditor *editor,
                 name = "freedesktop";
         }
 
-        client = gconf_client_get_default ();
-        gconf_client_set_string (client, SOUND_THEME_KEY, theme_name, NULL);
-        g_object_unref (client);
+        gconf_client_set_string (editor->priv->client, SOUND_THEME_KEY, theme_name, NULL);
 }
 
 /* Functions to toggle whether the audible bell sound is editable */
@@ -439,7 +440,7 @@ update_theme (GvcSoundThemeEditor *editor)
         GConfClient *client;
         gboolean     feedback_enabled;
 
-        client = gconf_client_get_default ();
+        client = editor->priv->client;
 
         bell_enabled = gconf_client_get_bool (client, AUDIO_BELL_KEY, NULL);
         set_audible_bell_enabled (editor, bell_enabled);
@@ -467,8 +468,6 @@ update_theme (GvcSoundThemeEditor *editor)
                                         NULL);
         }
         g_free (theme_name);
-
-        g_object_unref (client);
 }
 
 static void
@@ -1061,12 +1060,9 @@ setup_theme_custom_selector (GvcSoundThemeEditor *editor,
         GtkCellRenderer   *renderer;
         GtkTreeIter        iter;
         GtkTreeIter        parent;
-        GConfClient       *client;
         CategoryType       type;
         guint              i;
 
-        client = gconf_client_get_default ();
-
         /* Set up the model for the custom view */
         store = gtk_tree_store_new (NUM_COLS,
                                     G_TYPE_STRING,
@@ -1179,9 +1175,6 @@ setup_theme_custom_selector (GvcSoundThemeEditor *editor,
         }
 
         gtk_tree_view_expand_all (GTK_TREE_VIEW (editor->priv->treeview));
-
-
-        g_object_unref (client);
 }
 
 static GObject *
@@ -1299,7 +1292,6 @@ gvc_sound_theme_editor_init (GvcSoundThemeEditor *editor)
         GtkWidget   *box;
         GtkWidget   *label;
         GtkWidget   *scrolled_window;
-        GConfClient *client;
 
         editor->priv = GVC_SOUND_THEME_EDITOR_GET_PRIVATE (editor);
 
@@ -1313,7 +1305,7 @@ gvc_sound_theme_editor_init (GvcSoundThemeEditor *editor)
         gtk_box_pack_start (GTK_BOX (editor->priv->theme_box), editor->priv->combo_box, FALSE, FALSE, 0);
 
 
-        client = gconf_client_get_default ();
+        editor->priv->client = gconf_client_get_default ();
 
         editor->priv->selection_box = box = gtk_vbox_new (FALSE, 0);
         gtk_box_pack_start (GTK_BOX (editor), box, TRUE, TRUE, 0);
@@ -1337,7 +1329,7 @@ gvc_sound_theme_editor_init (GvcSoundThemeEditor *editor)
 
         editor->priv->click_feedback_button = gtk_check_button_new_with_mnemonic (_("Enable window and button sounds"));
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->click_feedback_button),
-                                      gconf_client_get_bool (client, INPUT_SOUNDS_KEY, NULL));
+                                      gconf_client_get_bool (editor->priv->client, INPUT_SOUNDS_KEY, NULL));
         gtk_box_pack_start (GTK_BOX (box),
                             editor->priv->click_feedback_button,
                             FALSE, FALSE, 0);
@@ -1347,22 +1339,20 @@ gvc_sound_theme_editor_init (GvcSoundThemeEditor *editor)
                           editor);
 
 
-        gconf_client_add_dir (client, KEY_SOUNDS_DIR,
+        gconf_client_add_dir (editor->priv->client, KEY_SOUNDS_DIR,
                               GCONF_CLIENT_PRELOAD_ONELEVEL,
                               NULL);
-        gconf_client_notify_add (client,
-                                 KEY_SOUNDS_DIR,
-                                 (GConfClientNotifyFunc)on_key_changed,
-                                 editor, NULL, NULL);
-        gconf_client_add_dir (client, KEY_METACITY_DIR,
+        editor->priv->sounds_dir_id = gconf_client_notify_add (editor->priv->client,
+                                                               KEY_SOUNDS_DIR,
+							       (GConfClientNotifyFunc)on_key_changed,
+							       editor, NULL, NULL);
+        gconf_client_add_dir (editor->priv->client, KEY_METACITY_DIR,
                               GCONF_CLIENT_PRELOAD_ONELEVEL,
                               NULL);
-        gconf_client_notify_add (client,
-                                 KEY_METACITY_DIR,
-                                 (GConfClientNotifyFunc)on_key_changed,
-                                 editor, NULL, NULL);
-
-        g_object_unref (client);
+        editor->priv->metacity_dir_id = gconf_client_notify_add (editor->priv->client,
+								 KEY_METACITY_DIR,
+								 (GConfClientNotifyFunc)on_key_changed,
+								 editor, NULL, NULL);
 
         /* FIXME: should accept drag and drop themes.  should also
            add an "Add Theme..." item to the theme combobox */
@@ -1378,7 +1368,20 @@ gvc_sound_theme_editor_finalize (GObject *object)
 
         sound_theme_editor = GVC_SOUND_THEME_EDITOR (object);
 
-        g_return_if_fail (sound_theme_editor->priv != NULL);
+	if (sound_theme_editor->priv != NULL) {
+		if (sound_theme_editor->priv->sounds_dir_id > 0) {
+			gconf_client_notify_remove (sound_theme_editor->priv->client,
+						    sound_theme_editor->priv->sounds_dir_id);
+			sound_theme_editor->priv->sounds_dir_id = 0;
+		}
+		if (sound_theme_editor->priv->metacity_dir_id > 0) {
+			gconf_client_notify_remove (sound_theme_editor->priv->client,
+						    sound_theme_editor->priv->metacity_dir_id);
+			sound_theme_editor->priv->metacity_dir_id = 0;
+		}
+		g_object_unref (sound_theme_editor->priv->client);
+		sound_theme_editor->priv->client = NULL;
+	}
 
         G_OBJECT_CLASS (gvc_sound_theme_editor_parent_class)->finalize (object);
 }



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