[frogr] Move checkbox to select dark themes to the settings dialog



commit 3b9f448b28df10745582871971a6982100e82869
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Mon Apr 9 03:06:46 2012 +0200

    Move checkbox to select dark themes to the settings dialog

 data/gtkbuilder/frogr-main-view.xml |   12 +++------
 src/frogr-config.c                  |    2 +-
 src/frogr-controller.c              |   12 ++++++++++
 src/frogr-controller.h              |    2 +
 src/frogr-main-view.c               |   42 -----------------------------------
 src/frogr-settings-dialog.c         |   22 +++++++++++++++++-
 6 files changed, 40 insertions(+), 52 deletions(-)
---
diff --git a/data/gtkbuilder/frogr-main-view.xml b/data/gtkbuilder/frogr-main-view.xml
index 89cf588..e176d5b 100644
--- a/data/gtkbuilder/frogr-main-view.xml
+++ b/data/gtkbuilder/frogr-main-view.xml
@@ -35,10 +35,6 @@
     <property name="label" translatable="yes">Enable _Tooltips</property>
     <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
   </object>
-  <object class="GtkToggleAction" id="use_dark_theme_action">
-    <property name="label" translatable="yes">Use _Dark Theme</property>
-    <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
-  </object>
   <object class="GtkAction" id="edit_details_action">
     <property name="label" translatable="yes">Edit _Detailsâ</property>
     <signal name="activate" handler="_on_action_activated" swapped="no"/>
@@ -537,17 +533,17 @@
               </object>
             </child>
             <child>
-              <object class="GtkCheckMenuItem" id="enable_tooltips_menu_item">
+              <object class="GtkSeparatorMenuItem" id="separator7">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="related_action">enable_tooltips_action</property>
+                <property name="use_action_appearance">False</property>
               </object>
             </child>
             <child>
-              <object class="GtkCheckMenuItem" id="use_dark_theme_menu_item">
+              <object class="GtkCheckMenuItem" id="enable_tooltips_menu_item">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="related_action">use_dark_theme_action</property>
+                <property name="related_action">enable_tooltips_action</property>
               </object>
             </child>
           </object>
diff --git a/src/frogr-config.c b/src/frogr-config.c
index 026baa8..65525ad 100644
--- a/src/frogr-config.c
+++ b/src/frogr-config.c
@@ -985,7 +985,7 @@ frogr_config_init (FrogrConfig *self)
   priv->mainview_sorting_criteria = SORT_AS_LOADED;
   priv->mainview_sorting_reversed = FALSE;
   priv->mainview_enable_tooltips = TRUE;
-  priv->use_dark_theme = FALSE;
+  priv->use_dark_theme = TRUE;
   priv->use_proxy = FALSE;
   priv->use_gnome_proxy = FALSE;
   priv->proxy_host = NULL;
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index f066195..0f45be4 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -2150,6 +2150,9 @@ frogr_controller_init (FrogrController *self)
       frogr_controller_set_proxy (self, use_gnome_proxy,
                                   host, port, username, password);
     }
+
+  /* Select the dark theme if needed */
+  frogr_controller_set_use_dark_theme (self, frogr_config_get_use_dark_theme (priv->config));
 }
 
 
@@ -2709,6 +2712,15 @@ frogr_controller_reorder_pictures (FrogrController *self)
 }
 
 void
+frogr_controller_set_use_dark_theme (FrogrController *self, gboolean value)
+{
+  GtkSettings *gtk_settings = NULL;
+
+  gtk_settings = gtk_settings_get_default ();
+  g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", value, NULL);
+}
+
+void
 frogr_controller_cancel_ongoing_request (FrogrController *self)
 {
   FrogrControllerPrivate *priv = NULL;
diff --git a/src/frogr-controller.h b/src/frogr-controller.h
index b71e27a..a1d0f84 100644
--- a/src/frogr-controller.h
+++ b/src/frogr-controller.h
@@ -120,6 +120,8 @@ void frogr_controller_upload_pictures (FrogrController *self);
 
 void frogr_controller_reorder_pictures (FrogrController *self);
 
+void frogr_controller_set_use_dark_theme (FrogrController *self, gboolean value);
+
 void frogr_controller_cancel_ongoing_request (FrogrController *self);
 
 G_END_DECLS
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 3693009..49b74ce 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -70,7 +70,6 @@ typedef struct _FrogrMainViewPrivate {
   SortingCriteria sorting_criteria;
   gboolean sorting_reversed;
   gboolean tooltips_enabled;
-  gboolean using_dark_theme;
   gint n_selected_pictures;
 
   GtkWindow *window;
@@ -109,7 +108,6 @@ typedef struct _FrogrMainViewPrivate {
   GtkAction *about_action;
   GtkToggleAction *enable_tooltips_action;
   GtkToggleAction *reversed_order_action;
-  GtkToggleAction *use_dark_theme_action;
   GtkToggleAction *sort_as_loaded_action;
   GtkToggleAction *sort_by_title_action;
   GtkToggleAction *sort_by_date_taken_action;
@@ -188,7 +186,6 @@ static void _load_pictures (FrogrMainView *self, GSList *fileuris);
 static void _upload_pictures (FrogrMainView *self);
 static void _show_help_contents (FrogrMainView *self);
 static void _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean reversed);
-static void _use_dark_theme (FrogrMainView *mainview, gboolean enabled);
 
 static void _progress_dialog_response (GtkDialog *dialog,
                                        gint response_id,
@@ -452,11 +449,6 @@ _on_toggle_action_changed (GtkToggleAction *action,
       _reorder_pictures (mainview, priv->sorting_criteria, checked);
       frogr_config_set_mainview_sorting_reversed (priv->config, checked);
     }
-  else if (action == priv->use_dark_theme_action)
-    {
-      frogr_config_set_use_dark_theme (priv->config, checked);
-      _use_dark_theme (mainview, checked);
-    }
   else if (checked)
     {
       /* Radio buttons handling here (only care about 'em when checked) */
@@ -1098,19 +1090,6 @@ _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean rever
 }
 
 static void
-_use_dark_theme (FrogrMainView *mainview, gboolean enabled)
-{
-  FrogrMainViewPrivate *priv = NULL;
-  GtkSettings *gtk_settings = NULL;
-
-  gtk_settings = gtk_settings_get_default ();
-  g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", enabled, NULL);
-
-  priv = FROGR_MAIN_VIEW_GET_PRIVATE (mainview);
-  priv->using_dark_theme = enabled;
-}
-
-static void
 _progress_dialog_response (GtkDialog *dialog,
                            gint response_id,
                            gpointer data)
@@ -1500,10 +1479,6 @@ frogr_main_view_init (FrogrMainView *self)
   GtkWidget *toolbar;
 #endif
 
-#if !GTK_CHECK_VERSION (3,2,0)
-  GtkWidget *dark_theme_menu_item = NULL;
-#endif
-
   /* Init model, controller and configuration */
   priv->model = frogr_main_view_model_new ();
   priv->controller = g_object_ref (frogr_controller_get_instance ());
@@ -1618,9 +1593,6 @@ frogr_main_view_init (FrogrMainView *self)
   priv->reversed_order_action =
     GTK_TOGGLE_ACTION (gtk_builder_get_object (builder,
                                                "reversed_order_action"));
-  priv->use_dark_theme_action =
-    GTK_TOGGLE_ACTION (gtk_builder_get_object (builder,
-                                               "use_dark_theme_action"));
 #ifndef MAC_INTEGRATION
   priv->quit_action =
     GTK_ACTION (gtk_builder_get_object (builder, "quit_action"));
@@ -1645,14 +1617,6 @@ frogr_main_view_init (FrogrMainView *self)
   priv->tooltips_enabled = frogr_config_get_mainview_enable_tooltips (priv->config);
   gtk_toggle_action_set_active (priv->enable_tooltips_action, priv->tooltips_enabled);
 
-#if GTK_CHECK_VERSION (3,2,0)
-  /* Read value for 'use dark theme' (for GTK >= 3.2 only) */
-  priv->using_dark_theme = frogr_config_get_use_dark_theme (priv->config);
-  _use_dark_theme (self, priv->using_dark_theme);
-  gtk_toggle_action_set_active (priv->use_dark_theme_action,
-                                priv->using_dark_theme);
-#endif
-
   /* No selected pictures at the beginning */
   priv->n_selected_pictures = 0;
 
@@ -1790,12 +1754,6 @@ frogr_main_view_init (FrogrMainView *self)
   /* Show the UI */
   gtk_widget_show_all (GTK_WIDGET(priv->window));
 
-#if !GTK_CHECK_VERSION (3,2,0)
-  /* Hide the option to select the dark theme if GTK < 3.2 */
-  dark_theme_menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "use_dark_theme_menu_item"));
-  gtk_widget_hide (dark_theme_menu_item);
-#endif
-
   /* Update UI */
   _update_ui (FROGR_MAIN_VIEW (self));
 
diff --git a/src/frogr-settings-dialog.c b/src/frogr-settings-dialog.c
index 03ac172..403bf98 100644
--- a/src/frogr-settings-dialog.c
+++ b/src/frogr-settings-dialog.c
@@ -69,6 +69,7 @@ typedef struct _FrogrSettingsDialogPrivate {
   GtkWidget *enable_tags_autocompletion_cb;
   GtkWidget *keep_file_extensions_cb;
   GtkWidget *import_tags_cb;
+  GtkWidget *use_dark_theme_cb;
 
   gboolean public_visibility;
   gboolean family_visibility;
@@ -78,6 +79,7 @@ typedef struct _FrogrSettingsDialogPrivate {
   gboolean enable_tags_autocompletion;
   gboolean keep_file_extensions;
   gboolean import_tags;
+  gboolean use_dark_theme;
   FspLicense license;
   FspSafetyLevel safety_level;
   FspContentType content_type;
@@ -495,6 +497,9 @@ _add_misc_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
                         _("_Import Tags from Pictures Metadata"),
                         &priv->import_tags_cb);
   _add_toggleable_item (self, GTK_BOX (box), NULL, FALSE,
+                        _("Use _Dark Theme (if available)"),
+                        &priv->use_dark_theme_cb);
+  _add_toggleable_item (self, GTK_BOX (box), NULL, FALSE,
                         _("_Keep File Extensions in Titles when Loading Pictures"),
                         &priv->keep_file_extensions_cb);
 
@@ -522,6 +527,7 @@ _fill_dialog_with_data (FrogrSettingsDialog *self)
   priv->enable_tags_autocompletion = frogr_config_get_tags_autocompletion (priv->config);
   priv->keep_file_extensions = frogr_config_get_keep_file_extensions (priv->config);
   priv->import_tags = frogr_config_get_import_tags_from_metadata (priv->config);
+  priv->use_dark_theme = frogr_config_get_use_dark_theme (priv->config);
   priv->use_proxy = frogr_config_get_use_proxy (priv->config);
 #ifdef HAVE_LIBSOUP_GNOME
   priv->use_gnome_proxy = frogr_config_get_use_gnome_proxy (priv->config);
@@ -587,6 +593,8 @@ _fill_dialog_with_data (FrogrSettingsDialog *self)
                                 priv->keep_file_extensions);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->import_tags_cb),
                                 priv->import_tags);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_dark_theme_cb),
+                                priv->use_dark_theme);
 
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_proxy_cb),
                                 priv->use_proxy);
@@ -631,6 +639,7 @@ _save_data (FrogrSettingsDialog *self)
   frogr_config_set_tags_autocompletion (priv->config, priv->enable_tags_autocompletion);
   frogr_config_set_keep_file_extensions (priv->config, priv->keep_file_extensions);
   frogr_config_set_import_tags_from_metadata (priv->config, priv->import_tags);
+  frogr_config_set_use_dark_theme (priv->config, priv->use_dark_theme);
 
   frogr_config_set_use_proxy (priv->config, priv->use_proxy);
 #ifdef HAVE_LIBSOUP_GNOME
@@ -790,7 +799,13 @@ _on_button_toggled (GtkToggleButton *button, gpointer data)
   if (GTK_WIDGET (button) == priv->import_tags_cb)
     {
       priv->import_tags = active;
-      DEBUG ("Don't import tags from pictures metadata set to %s", active ? "TRUE" : "FALSE");
+      DEBUG ("import tags from pictures metadata set to %s", active ? "TRUE" : "FALSE");
+    }
+
+  if (GTK_WIDGET (button) == priv->use_dark_theme_cb)
+    {
+      priv->use_dark_theme = active;
+      DEBUG ("Use Dark Theme if Available set to %s", active ? "TRUE" : "FALSE");
     }
 
   if (GTK_WIDGET (button) == priv->use_proxy_cb)
@@ -874,6 +889,9 @@ static void _dialog_response_cb (GtkDialog *dialog, gint response, gpointer data
   else
     frogr_controller_set_proxy (priv->controller, FALSE, NULL, NULL, NULL, NULL);
 
+  /* Update dark theme related stuff */
+  frogr_controller_set_use_dark_theme (priv->controller, priv->use_dark_theme);
+
   gtk_widget_hide (GTK_WIDGET (self));
 }
 
@@ -947,6 +965,7 @@ frogr_settings_dialog_init (FrogrSettingsDialog *self)
   priv->enable_tags_autocompletion_cb = NULL;
   priv->keep_file_extensions_cb = NULL;
   priv->import_tags_cb = NULL;
+  priv->use_dark_theme_cb = NULL;
   priv->use_proxy_cb = NULL;
   priv->use_gnome_proxy_cb = NULL;
   priv->proxy_host_label = NULL;
@@ -968,6 +987,7 @@ frogr_settings_dialog_init (FrogrSettingsDialog *self)
   priv->enable_tags_autocompletion = TRUE;
   priv->keep_file_extensions = FALSE;
   priv->import_tags = TRUE;
+  priv->use_dark_theme = TRUE;
   priv->use_proxy = FALSE;
   priv->use_gnome_proxy = FALSE;
   priv->proxy_host = NULL;



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