[niepce/gtk3: 3/6] Remove the custom theme Use Gtk::Settings to say "prefer dark" Fix prefs UI to be a checkbox. Fix Gt



commit bcb5f1eaa95cc7e9827fa2bb4c9cb0a3eaac8c29
Author: Hub Figuiere <hub figuiere net>
Date:   Wed Nov 30 22:07:40 2011 -0800

    Remove the custom theme
    Use Gtk::Settings to say "prefer dark"
    Fix prefs UI to be a checkbox.
    Fix GtkGrid.

 data/themes/Makefile.am                     |    3 --
 data/themes/niepce-dark.gtkrc               |   38 ----------------------
 src/fwk/toolkit/application.cpp             |   45 +++++++-------------------
 src/fwk/toolkit/application.hpp             |   12 +------
 src/niepce/ui/dialogs/preferences.ui        |   28 ++++------------
 src/niepce/ui/dialogs/preferencesdialog.cpp |   36 +++++++--------------
 src/niepce/ui/niepceapplication.cpp         |    4 --
 7 files changed, 33 insertions(+), 133 deletions(-)
---
diff --git a/data/themes/Makefile.am b/data/themes/Makefile.am
index d815f37..6dc49e3 100644
--- a/data/themes/Makefile.am
+++ b/data/themes/Makefile.am
@@ -2,6 +2,3 @@
 
 EXTRA_DIST = README
 
-themesdir = @datadir@/niepce/themes/
-
-dist_themes_DATA = niepce-dark.gtkrc
diff --git a/src/fwk/toolkit/application.cpp b/src/fwk/toolkit/application.cpp
index f4c4f0d..ba086fa 100644
--- a/src/fwk/toolkit/application.cpp
+++ b/src/fwk/toolkit/application.cpp
@@ -25,6 +25,7 @@
 #include <glibmm/i18n.h>
 #include <gtkmm/main.h>
 #include <gtkmm/aboutdialog.h>
+#include <gtkmm/settings.h>
 
 #include "fwk/base/debug.hpp"
 #include "fwk/utils/boost.hpp"
@@ -43,7 +44,6 @@ Application::Application(const char * name)
     , m_refUIManager(Gtk::UIManager::create())
     , m_module_manager(new ModuleManager())
 {
-    register_theme(_("System"), "");
 }
 
 
@@ -59,42 +59,27 @@ Application::Ptr Application::app()
 }
 
 
-Glib::ustring Application::get_rc_path()
-{
-    return m_config.getValue("ui_theme_file", "");
-}
-
 Glib::RefPtr<Gtk::IconTheme> Application::getIconTheme() const
 {
     return Gtk::IconTheme::get_default();
 }
 
-int Application::get_use_custom_theme() const
+bool Application::get_use_dark_theme() const
 {
-    int v;
+    bool v;
     try {
-        v = boost::lexical_cast<int>(m_config.getValue("ui_theme_set", "0"));
+        v = boost::lexical_cast<bool>(m_config.getValue("ui_dark_theme", "0"));
     } 
     catch(...) {
-        v = 0;
+        v = false;
     }
-    return v != 0;
+    return v;
 }
 
-void Application::set_use_custom_theme(int theme_idx)
+void Application::set_use_dark_theme(bool value)
 {
-    m_config.setValue("ui_theme_set",
-                      boost::lexical_cast<Glib::ustring>(theme_idx));
-    if((theme_idx > -1) && ((size_t)theme_idx < m_themes.size())) {
-        m_config.setValue("ui_theme_file", m_themes[theme_idx].second);
-    }
-}
-
-
-void Application::register_theme(const Glib::ustring & label,
-                                 const std::string & path)
-{
-    m_themes.push_back(std::make_pair(label, path));
+    m_config.setValue("ui_dark_theme",
+                      boost::lexical_cast<Glib::ustring>(value));
 }
 
 
@@ -110,15 +95,9 @@ int Application::main(boost::function<Application::Ptr (void)> constructor,
     Gtk::Main kit(argc, argv);
     Application::Ptr app = constructor();
 
-#if GTKMM2
-    DBG_OUT("use_custon_theme %d", app->get_use_custom_theme());
-    if(app->get_use_custom_theme() != -1) {
-        std::string rcpath = app->get_rc_path();
-        if(!rcpath.empty()) {
-            Gtk::RC rc(rcpath);
-        }
-    }
-#endif
+    bool use_dark = app->get_use_dark_theme();
+    Glib::RefPtr<Gtk::Settings> settings = Gtk::Settings::get_default();
+    settings->set_property("gtk-application-prefer-dark-theme", use_dark);
 
     Frame::Ptr window(app->makeMainFrame());
     app->add(window);
diff --git a/src/fwk/toolkit/application.hpp b/src/fwk/toolkit/application.hpp
index cdd4d67..df7125a 100644
--- a/src/fwk/toolkit/application.hpp
+++ b/src/fwk/toolkit/application.hpp
@@ -45,13 +45,8 @@ public:
 
     virtual ~Application();
 
-    virtual Glib::ustring get_rc_path();
-    virtual int get_use_custom_theme() const;
-    virtual void set_use_custom_theme(int theme_idx);
-    const std::vector<ThemeDesc> & get_available_themes() const
-        {
-            return m_themes;
-        }
+    virtual bool get_use_dark_theme() const;
+    virtual void set_use_dark_theme(bool value);
 
     virtual Frame::Ptr makeMainFrame() = 0;
 
@@ -88,13 +83,10 @@ protected:
     Application(const char *);
     static Application::Ptr m_application; 
     virtual void on_about();
-    void register_theme(const Glib::ustring & label,
-                        const std::string &path);
 private:
     Configuration                m_config;
     Glib::RefPtr<Gtk::UIManager> m_refUIManager;
     UndoHistory                  m_undo;
-    std::vector<ThemeDesc>       m_themes;
     ModuleManager               *m_module_manager;
 };
 
diff --git a/src/niepce/ui/dialogs/preferences.ui b/src/niepce/ui/dialogs/preferences.ui
index 027e8b4..bbce090 100644
--- a/src/niepce/ui/dialogs/preferences.ui
+++ b/src/niepce/ui/dialogs/preferences.ui
@@ -61,8 +61,6 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="border_width">12</property>
-                <property name="row_spacing">12</property>
-                <property name="column_spacing">12</property>
                 <property name="n_rows">1</property>
                 <property name="n_columns">2</property>
                 <child>
@@ -103,31 +101,19 @@
                 <property name="n_rows">1</property>
                 <property name="n_columns">2</property>
                 <child>
-                  <object class="GtkLabel" id="label3">
+                  <object class="GtkCheckButton" id="dark_theme_checkbox">
+                    <property name="label" translatable="yes">Use dark interface</property>
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_action_appearance">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">_Theme:	</property>
-                    <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">theme_combo</property>
+                    <property name="draw_indicator">True</property>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkComboBox" id="theme_combo">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="active">0</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">0</property>
-                    <property name="width">1</property>
+                    <property name="width">2</property>
                     <property name="height">1</property>
                   </packing>
                 </child>
diff --git a/src/niepce/ui/dialogs/preferencesdialog.cpp b/src/niepce/ui/dialogs/preferencesdialog.cpp
index d17da24..c427dce 100644
--- a/src/niepce/ui/dialogs/preferencesdialog.cpp
+++ b/src/niepce/ui/dialogs/preferencesdialog.cpp
@@ -42,40 +42,28 @@ void PreferencesDialog::setup_widget()
 
     add_header(_("Preferences"));
 
-    Gtk::ComboBox * theme_combo = NULL;
+    Gtk::CheckButton * theme_checkbutton = NULL;
     Gtk::CheckButton * reopen_checkbutton = NULL;
     fwk::DataBinderPool * binder_pool = new fwk::DataBinderPool();
 
     gtkDialog().signal_hide().connect(boost::bind(&fwk::DataBinderPool::destroy, 
                                               binder_pool));
 		
-    builder()->get_widget("theme_combo", theme_combo);
- 
-		Glib::RefPtr<Gtk::ListStore> model = m_theme_combo_model.inject(*theme_combo);
-		
-		const std::vector<fwk::Application::ThemeDesc> & themes 
-			= fwk::Application::app()->get_available_themes();
-    std::vector<fwk::Application::ThemeDesc>::const_iterator i;
-    for(i = themes.begin(); i != themes.end(); ++i) {
-        DBG_OUT("adding %s", i->first.c_str());
-        Gtk::TreeIter iter = model->append();
-        iter->set_value(m_theme_combo_model.m_col1, i->first); 
-        iter->set_value(m_theme_combo_model.m_col2, i->second); 
-    }
-
-    theme_combo->set_active(fwk::Application::app()
-                            ->get_use_custom_theme());
-    theme_combo->signal_changed().connect(
-			boost::bind(&fwk::Application::set_use_custom_theme,
+    builder()->get_widget("dark_theme_checkbox", theme_checkbutton);
+    
+    theme_checkbutton->set_active(fwk::Application::app()
+                            ->get_use_dark_theme());
+    theme_checkbutton->signal_toggled().connect(
+			boost::bind(&fwk::Application::set_use_dark_theme,
 									fwk::Application::app(),
-									theme_combo->property_active()));
+									theme_checkbutton->property_active()));
 
     builder()->get_widget("reopen_checkbutton", reopen_checkbutton);
     binder_pool->add_binder(new fwk::ConfigDataBinder<bool>(
-															reopen_checkbutton->property_active(),
-															fwk::Application::app()->config(),
-															"reopen_last_library"));
-		m_is_setup = true;
+							    reopen_checkbutton->property_active(),
+							    fwk::Application::app()->config(),
+							    "reopen_last_library"));
+    m_is_setup = true;
 }
 
 
diff --git a/src/niepce/ui/niepceapplication.cpp b/src/niepce/ui/niepceapplication.cpp
index 6859967..b26952f 100644
--- a/src/niepce/ui/niepceapplication.cpp
+++ b/src/niepce/ui/niepceapplication.cpp
@@ -36,10 +36,6 @@ NiepceApplication::NiepceApplication()
     : Application(PACKAGE)
 {
     niepce::Stock::registerStockItems();
-    const char * themedir = DATADIR"/"PACKAGE"/themes/";
-
-    register_theme(_("Niepce Dark"),
-                   std::string(themedir) + "niepce-dark.gtkrc");
 
     fwk::ModuleManager * modmgr = module_manager();
     DBG_ASSERT(modmgr != NULL, "module manager is NULL.");



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