[gtranslator] Fix some bugs due to the gsettings migration.



commit 708eefa97763380b70702f674c7d686a96e64a7d
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Sep 8 21:31:20 2010 +0200

    Fix some bugs due to the gsettings migration.

 src/dialogs/gtr-preferences-dialog.c |   65 ++++++++++++++++++++++------------
 src/gtr-window.c                     |   50 ++++++++++++++-----------
 2 files changed, 70 insertions(+), 45 deletions(-)
---
diff --git a/src/dialogs/gtr-preferences-dialog.c b/src/dialogs/gtr-preferences-dialog.c
index 095d2a0..41a452e 100644
--- a/src/dialogs/gtr-preferences-dialog.c
+++ b/src/dialogs/gtr-preferences-dialog.c
@@ -45,6 +45,7 @@
 #include <gtk/gtk.h>
 #include <string.h>
 #include <gtksourceview/gtksourcestyleschememanager.h>
+#include <gdl/gdl.h>
 
 #define GTR_PREFERENCES_DIALOG_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ( \
                                                     (object), \
@@ -159,16 +160,6 @@ on_auto_save_changed (GSettings            *settings,
 static void
 setup_files_autosave_page (GtrPreferencesDialog * dlg)
 {
-  gboolean autosave;
-
-  /*Set initial value */
-  autosave = g_settings_get_boolean (dlg->priv->files_settings,
-                                     GTR_SETTINGS_AUTO_SAVE);
-
-  /*Set sensitive */
-  gtk_widget_set_sensitive (dlg->priv->autosave_interval_spinbutton,
-                            autosave);
-
   g_settings_bind (dlg->priv->files_settings,
                    GTR_SETTINGS_AUTO_SAVE_INTERVAL,
                    dlg->priv->autosave_interval_spinbutton,
@@ -181,9 +172,13 @@ setup_files_autosave_page (GtrPreferencesDialog * dlg)
                    "active",
                    G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
   g_signal_connect (dlg->priv->files_settings,
-                    "changed::auto-save",
+                    "changed::" GTR_SETTINGS_AUTO_SAVE,
                     G_CALLBACK (on_auto_save_changed),
                     dlg);
+  /*Set sensitive */
+  on_auto_save_changed (dlg->priv->files_settings,
+                        GTR_SETTINGS_AUTO_SAVE,
+                        dlg);
 
   g_settings_bind (dlg->priv->files_settings,
                    GTR_SETTINGS_CREATE_BACKUP,
@@ -204,11 +199,12 @@ setup_files_pages (GtrPreferencesDialog * dlg)
 /***************Editor pages****************/
 
 static void
-use_custom_font_checkbutton_toggled (GtkToggleButton * button,
-                                     GtrPreferencesDialog * dlg)
+use_custom_font_changed (GSettings            *settings,
+                         const gchar          *key,
+                         GtrPreferencesDialog *dlg)
 {
   gtk_widget_set_sensitive (dlg->priv->editor_font_hbox,
-                            gtk_toggle_button_get_active (button));
+                            g_settings_get_boolean (settings, key));
 }
 
 static void
@@ -225,14 +221,18 @@ setup_editor_text_display_page (GtrPreferencesDialog * dlg)
                    "active",
                    G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
 
-  /* Connect before binding to set the sensitivity */
-  g_signal_connect (dlg->priv->use_custom_font_checkbutton, "toggled",
-                    G_CALLBACK (use_custom_font_checkbutton_toggled), dlg);
   g_settings_bind (dlg->priv->editor_settings,
                    GTR_SETTINGS_USE_CUSTOM_FONT,
                    dlg->priv->use_custom_font_checkbutton,
                    "active",
                    G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+  g_signal_connect (dlg->priv->editor_settings,
+                    "changed::" GTR_SETTINGS_USE_CUSTOM_FONT,
+                    G_CALLBACK (use_custom_font_changed), dlg);
+  /*Set sensitive */
+  use_custom_font_changed (dlg->priv->editor_settings,
+                           GTR_SETTINGS_USE_CUSTOM_FONT,
+                           dlg);
 
   g_settings_bind (dlg->priv->editor_settings,
                    GTR_SETTINGS_EDITOR_FONT,
@@ -617,9 +617,23 @@ setup_profile_pages (GtrPreferencesDialog *dlg)
 static void
 scheme_color_changed_cb (GtkComboBox * combobox, GtrPreferencesDialog * dlg)
 {
+  gchar *active_text;
+
+  active_text = gtk_combo_box_get_active_text (combobox);
+
   g_settings_set_string (dlg->priv->ui_settings,
                          GTR_SETTINGS_COLOR_SCHEME,
-                         gtk_combo_box_get_active_text (combobox));
+                         active_text);
+  g_free (active_text);
+}
+
+static void
+on_gdl_combobox_changed (GtkComboBox          *combobox,
+                         GtrPreferencesDialog *dlg)
+{
+  g_settings_set_enum (dlg->priv->ui_settings,
+                       GTR_SETTINGS_PANEL_SWITCHER_STYLE,
+                       gtk_combo_box_get_active (combobox));
 }
 
 static void
@@ -631,12 +645,17 @@ setup_interface_pages (GtrPreferencesDialog * dlg)
   gint i = 0;
   GtkListStore *store;
   GtkCellRenderer *cell;
+  GdlSwitcherStyle style;
 
-  g_settings_bind (dlg->priv->ui_settings,
-                   GTR_SETTINGS_PANEL_SWITCHER_STYLE,
-                   dlg->priv->gdl_combobox,
-                   "active",
-                   G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+  style = g_settings_get_enum (dlg->priv->ui_settings,
+                               GTR_SETTINGS_PANEL_SWITCHER_STYLE);
+
+  gtk_combo_box_set_active (GTK_COMBO_BOX (dlg->priv->gdl_combobox),
+                            style);
+  g_signal_connect (dlg->priv->gdl_combobox,
+                    "changed",
+                    G_CALLBACK (on_gdl_combobox_changed),
+                    dlg);
 
   /* Scheme color */
   store = gtk_list_store_new (1, G_TYPE_STRING);
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 5d3974b..851b6bc 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -113,7 +113,8 @@ struct _GtrWindowPrivate
   GtrProfileManager *prof_manager;
   GtkWidget *profile_combo;
 
-  gboolean destroy_has_run : 1;
+  guint destroy_has_run : 1;
+  guint dispose_has_run : 1;
 };
 
 enum
@@ -1783,6 +1784,7 @@ gtr_window_init (GtrWindow * window)
   window->priv->state_settings = g_settings_new ("org.gnome.gtranslator.state.window");
 
   window->priv->destroy_has_run = FALSE;
+  window->priv->dispose_has_run = FALSE;
 
   /* Profile manager */
   window->priv->prof_manager = gtr_profile_manager_get_default ();
@@ -1853,6 +1855,25 @@ gtr_window_init (GtrWindow * window)
 }
 
 static void
+save_panes_state (GtrWindow * window)
+{
+  gchar *filename;
+  gchar *config_folder;
+
+  g_settings_set (window->priv->state_settings, GTR_SETTINGS_WINDOW_SIZE, "(ii)",
+                  window->priv->width, window->priv->height);
+  g_settings_set_int (window->priv->state_settings, GTR_SETTINGS_WINDOW_STATE,
+                      window->priv->window_state);
+
+  config_folder = gtr_dirs_get_user_config_dir ();
+  filename = g_build_filename (config_folder, "gtr-layout.xml", NULL);
+  g_free (config_folder);
+
+  gtr_window_layout_save (window, filename, NULL);
+  g_free (filename);
+}
+
+static void
 gtr_window_dispose (GObject * object)
 {
   GtrWindow *window = GTR_WINDOW (object);
@@ -1860,6 +1881,12 @@ gtr_window_dispose (GObject * object)
 
   DEBUG_PRINT ("window dispose");
 
+  if (!priv->dispose_has_run)
+    {
+      save_panes_state (window);
+      priv->dispose_has_run = TRUE;
+    }
+
   if (priv->ui_settings)
     {
       g_object_unref (priv->ui_settings);
@@ -1904,25 +1931,6 @@ gtr_window_finalize (GObject * object)
 }
 
 static void
-save_panes_state (GtrWindow * window)
-{
-  gchar *filename;
-  gchar *config_folder;
-
-  g_settings_set (window->priv->state_settings, GTR_SETTINGS_WINDOW_SIZE, "(ii)",
-                  window->priv->width, window->priv->height);
-  g_settings_set_int (window->priv->state_settings, GTR_SETTINGS_WINDOW_STATE,
-                      window->priv->window_state);
-
-  config_folder = gtr_dirs_get_user_config_dir ();
-  filename = g_build_filename (config_folder, "gtr-layout.xml", NULL);
-  g_free (config_folder);
-
-  gtr_window_layout_save (window, filename, NULL);
-  g_free (filename);
-}
-
-static void
 gtr_window_destroy (GtkObject * object)
 {
   GtrWindow *window;
@@ -1933,8 +1941,6 @@ gtr_window_destroy (GtkObject * object)
 
   if (!window->priv->destroy_has_run)
     {
-      save_panes_state (window);
-
       if (window->priv->widgets)
         {
           g_hash_table_destroy (window->priv->widgets);



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