[gnome-commander/GSettings] Adds gsettings for file pane font settings



commit e08cc179a0aae29b0deb68a448730cdd3eb41487
Author: Uwe Scholz <uwescholz src gnome org>
Date:   Sun Dec 13 21:30:04 2015 +0100

    Adds gsettings for file pane font settings

 data/org.gnome.gnome-commander.gschema.xml |   19 +++-
 src/Makefile.am                            |    1 +
 src/gnome-cmd-settings.cc                  |  192 ++++++++++++++++++++++++++++
 src/gnome-cmd-settings.h                   |   42 ++++++
 src/main.cc                                |    4 +
 5 files changed, 256 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index c7f2c22..4c13160 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -2,8 +2,23 @@
 
 <schemalist>
 
-  <schema id="org.gnome.gnome-commander" path="/org/gnome/gnome-commander/">
-
+  <schema gettext-domain="gnome-commander" id="org.gnome.gnome-commander" path="/org/gnome/gnome-commander/">
+    <child name="preferences" schema="org.gnome.gnome-commander.preferences"/>
+  </schema>
+  <schema gettext-domain="gnome-commander" id="org.gnome.gnome-commander.preferences" 
path="/org/gnome/gnome-commander/preferences/">
+    <child name="layout" schema="org.gnome.gnome-commander.preferences.layout"/>
+  </schema>
+  <schema gettext-domain="gnome-commander" id="org.gnome.gnome-commander.preferences.layout" 
path="/org/gnome/gnome-commander/preferences/layout/">
+    <key name="use-default-font" type="b">
+      <default>true</default>
+      <summary>Use Default Font</summary>
+      <description>Whether to use the system's default fixed width font for the file panels instead of a 
font specific to gnome-commander. If this option is turned off, then the font named in the "File panes" 
option will be used instead of the system font.</description>
+    </key>
+    <key name="panel-font" type="s">
+      <default l10n="messages">'DejaVu Sans Mono 8'</default>
+      <summary>Panel Font</summary>
+      <description>A custom font that will be used for the file panes. This will only take effect if the 
"Use Default Font" option is turned off.</description>
+    </key>
   </schema>
 
 </schemalist>
diff --git a/src/Makefile.am b/src/Makefile.am
index fec1554..79f67ee 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,6 +61,7 @@ gnome_commander_SOURCES = \
        gnome-cmd-regex.h \
        gnome-cmd-quicksearch-popup.h gnome-cmd-quicksearch-popup.cc \
        gnome-cmd-selection-profile-component.h gnome-cmd-selection-profile-component.cc \
+       gnome-cmd-settings.h gnome-cmd-settings.cc \
        gnome-cmd-style.h gnome-cmd-style.cc \
        gnome-cmd-treeview.h gnome-cmd-treeview.cc \
        gnome-cmd-types.h \
diff --git a/src/gnome-cmd-settings.cc b/src/gnome-cmd-settings.cc
new file mode 100644
index 0000000..e196300
--- /dev/null
+++ b/src/gnome-cmd-settings.cc
@@ -0,0 +1,192 @@
+/**
+ * @file gnome-cmd-settings.cc
+ * @brief Functions for storing settings of GCMD using GSettings
+ * @copyright (C) 2013-2015 Uwe Scholz\n
+ *
+ * @copyright This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * @copyright This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * @copyright You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <stdio.h>
+#include <gio/gio.h>
+#include "gnome-cmd-settings.h"
+
+struct _GcmdSettings
+{
+    GObject parent;
+
+    GSettings *interface;
+    GSettings *layout;
+    GSettings *history;
+    GSettings *advanced_rename_tool;
+    GSettings *search_tool;
+    GSettings *bookmarks_tool;
+    GSettings *connections;
+    GSettings *bookmarks;
+    GSettings *selections;
+    GSettings *key_bindings;
+};
+
+G_DEFINE_TYPE (GcmdSettings, gcmd_settings, G_TYPE_OBJECT)
+
+static void
+gcmd_settings_finalize (GObject *object)
+{
+//    GcmdSettings *gs = GCMD_SETTINGS (object);
+//
+//    g_free (gs->old_scheme);
+//
+    G_OBJECT_CLASS (gcmd_settings_parent_class)->finalize (object);
+}
+
+static void
+gcmd_settings_dispose (GObject *object)
+{
+    GcmdSettings *gs = GCMD_SETTINGS (object);
+
+    g_clear_object (&gs->interface);
+    g_clear_object (&gs->layout);
+    g_clear_object (&gs->history);
+    g_clear_object (&gs->advanced_rename_tool);
+    g_clear_object (&gs->search_tool);
+    g_clear_object (&gs->bookmarks_tool);
+    g_clear_object (&gs->connections);
+    g_clear_object (&gs->bookmarks);
+    g_clear_object (&gs->selections);
+    g_clear_object (&gs->key_bindings);
+
+    G_OBJECT_CLASS (gcmd_settings_parent_class)->dispose (object);
+}
+
+static void
+set_font (GcmdSettings *gs,
+          const gchar *font)
+{
+    //Hier muss jetzt die Schrift in den Panels aktualisiert werden!
+    printf("%s\n", font);
+}
+
+static void
+on_system_font_changed (GSettings     *settings,
+                        const gchar   *key,
+                        GcmdSettings *gs)
+{
+
+    gboolean use_default_font;
+
+    use_default_font = g_settings_get_boolean (gs->layout,
+                           GCMD_SETTINGS_USE_DEFAULT_FONT);
+
+    if (use_default_font)
+    {
+        gchar *font;
+
+        font = g_settings_get_string (settings, key);
+        set_font (gs, font);
+        g_free (font);
+    }
+}
+
+static void
+on_use_default_font_changed (GSettings     *settings,
+                             const gchar   *key,
+                             GcmdSettings *gs)
+{
+    gboolean def;
+    gchar *font;
+
+    def = g_settings_get_boolean (settings, key);
+
+    if (def)
+    {
+        font = g_settings_get_string (gs->interface,
+                          GCMD_SETTINGS_SYSTEM_FONT);
+    }
+    else
+    {
+        font = g_settings_get_string (gs->layout,
+                          GCMD_SETTINGS_PANEL_FONT);
+    }
+
+    set_font (gs, font);
+
+    g_free (font);
+}
+
+static void
+on_layout_font_changed (GSettings     *settings,
+                        const gchar   *key,
+                        GcmdSettings *gs)
+{
+    gboolean use_default_font;
+
+    use_default_font = g_settings_get_boolean (gs->layout,
+                           GCMD_SETTINGS_USE_DEFAULT_FONT);
+
+    if (!use_default_font)
+    {
+        gchar *font;
+
+        font = g_settings_get_string (settings, key);
+        set_font (gs, font);
+        g_free (font);
+    }
+}
+
+static void
+gcmd_settings_class_init (GcmdSettingsClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+    object_class->finalize = gcmd_settings_finalize;
+    object_class->dispose = gcmd_settings_dispose;
+}
+
+GcmdSettings *
+gcmd_settings_new ()
+{
+    return (GcmdSettings *) g_object_new (GCMD_TYPE_SETTINGS, NULL);
+}
+
+static void
+gcmd_settings_init (GcmdSettings *gs)
+{
+    gs->interface = g_settings_new ("org.gnome.desktop.interface");
+    gs->layout = g_settings_new ("org.gnome.gnome-commander.preferences.layout");
+
+    g_signal_connect (gs->interface,
+                      "changed::monospace-font-name",
+                      G_CALLBACK (on_system_font_changed),
+                      gs);
+
+    g_signal_connect (gs->layout,
+                      "changed::use-default-font",
+                      G_CALLBACK (on_use_default_font_changed),
+                      gs);
+
+    g_signal_connect (gs->layout,
+                      "changed::panel-font",
+                      G_CALLBACK (on_layout_font_changed),
+                      gs);
+
+    //gs->history = g_settings_new ("org.gnome.gnome-commander.preferences.history");
+    //gs->advanced_rename_tool = g_settings_new ("org.gnome.gnome-commander.preferences.rename-tool");
+    //gs->search_tool = g_settings_new ("org.gnome.gnome-commander.preferences.search-tool");
+    //gs->bookmarks_tool = g_settings_new ("org.gnome.gnome-commander.preferences.bookmarks-tool");
+    //gs->connections = g_settings_new ("org.gnome.gnome-commander.preferences.connections");
+    //gs->bookmarks = g_settings_new ("org.gnome.gnome-commander.preferences.bookmarks");
+    //gs->selections = g_settings_new ("org.gnome.gnome-commander.preferences.selections");
+    //gs->key_bindings = g_settings_new ("org.gnome.gnome-commander.preferences.key-bindings");
+    
+}
diff --git a/src/gnome-cmd-settings.h b/src/gnome-cmd-settings.h
new file mode 100644
index 0000000..972f310
--- /dev/null
+++ b/src/gnome-cmd-settings.h
@@ -0,0 +1,42 @@
+/**
+ * @file gnome-cmd-settings.h
+ * @brief Functions for storing settings of GCMD using GSettings
+ * @copyright (C) 2013-2015 Uwe Scholz\n
+ *
+ * @copyright This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * @copyright This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * @copyright You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __GNOME_CMD_SETTINGS_H__
+#define __GNOME_CMD_SETTINGS_H__
+
+#include <glib-object.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define GCMD_TYPE_SETTINGS (gcmd_settings_get_type ())
+
+G_DECLARE_FINAL_TYPE (GcmdSettings, gcmd_settings, GCMD, SETTINGS, GObject)
+
+GcmdSettings *gcmd_settings_new (void);
+
+/* key constants */
+#define GCMD_SETTINGS_USE_DEFAULT_FONT                "use-default-font"
+#define GCMD_SETTINGS_PANEL_FONT                      "panel-font"
+#define GCMD_SETTINGS_SYSTEM_FONT                     "monospace-font-name"
+
+G_END_DECLS
+
+#endif // __GNOME_CMD_SETTINGS_H__
diff --git a/src/main.cc b/src/main.cc
index 62c7bac..b9f0fb5 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -43,6 +43,7 @@ extern "C"
 #include "plugin_manager.h"
 #include "gnome-cmd-python-plugin.h"
 #include "tags/gnome-cmd-tags.h"
+#include "gnome-cmd-settings.h"
 
 using namespace std;
 
@@ -96,6 +97,7 @@ int main (int argc, char *argv[])
     GnomeProgram *program;
     GOptionContext *option_context;
     UniqueApp *app;
+    GcmdSettings *settings = NULL;
 
     main_win = NULL;
 
@@ -142,9 +144,11 @@ int main (int argc, char *argv[])
     create_dir_if_needed (conf_dir);
     g_free (conf_dir);
 
+    /* Load Settings */
     IMAGE_init ();
     gcmd_user_actions.init();
     gnome_cmd_data.load();
+    settings = gcmd_settings_new ();
 
     app = unique_app_new ("org.gnome.GnomeCommander", NULL);
 


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