[gnome-games/sudoku-vala] sudoku: settings saved to gsettings



commit 1e7f19090170a846dcd51fe1b90defcb45f65549
Author: Tiffany Antopolski <tiffany antopolski com>
Date:   Mon Apr 11 13:52:10 2011 +1000

    sudoku: settings saved to gsettings

 gnome-sudoku/data/Makefile.am                      |    9 ++++-
 gnome-sudoku/data/gnome-sudoku.ui                  |    3 +-
 .../data/org.gnome.gnome-sudoku.gschema.xml.in     |   17 +++++++++
 gnome-sudoku/src/gnome-sudoku.vala                 |   38 ++++++++++++++-----
 4 files changed, 55 insertions(+), 12 deletions(-)
---
diff --git a/gnome-sudoku/data/Makefile.am b/gnome-sudoku/data/Makefile.am
index 5da5d41..1319621 100644
--- a/gnome-sudoku/data/Makefile.am
+++ b/gnome-sudoku/data/Makefile.am
@@ -6,14 +6,21 @@ puzzle_DATA = \
 	very_hard
 
 uidir = $(datadir)/gnome-sudoku
+
+gsettings_SCHEMAS = org.gnome.gnome-sudoku.gschema.xml
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
+
 ui_DATA = \
 	gnome-sudoku.ui 
 
 man_MANS = gnome-sudoku.6
 
-EXTRA_DIST = \
+EXTRA_DIST = org.gnome.gnome-sudoku.xml.in \
 	$(puzzle_DATA)	\
 	$(ui_DATA)	\
 	$(man_MANS)
 
+CLEANFILES = $(gsettings_SCHEMAS)
+
 -include $(top_srcdir)/git.mk
diff --git a/gnome-sudoku/data/gnome-sudoku.ui b/gnome-sudoku/data/gnome-sudoku.ui
index 8c17ffe..c84af85 100644
--- a/gnome-sudoku/data/gnome-sudoku.ui
+++ b/gnome-sudoku/data/gnome-sudoku.ui
@@ -4,7 +4,8 @@
   <!-- interface-naming-policy project-wide -->
   <object class="GtkWindow" id="sudoku_app">
     <property name="title" translatable="yes">Sudoku</property>
-    <signal name="delete_event" handler="quit_cb"/>
+    <signal name="window-state-event" handler="sudoku_app_window_state_event_cb" swapped="no"/>
+    <signal name="delete-event" handler="quit_cb" swapped="no"/>
     <child>
       <object class="GtkVBox" id="main_vbox">
         <property name="visible">True</property>
diff --git a/gnome-sudoku/data/org.gnome.gnome-sudoku.gschema.xml.in b/gnome-sudoku/data/org.gnome.gnome-sudoku.gschema.xml.in
new file mode 100644
index 0000000..0c04a87
--- /dev/null
+++ b/gnome-sudoku/data/org.gnome.gnome-sudoku.gschema.xml.in
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+
+  <schema path="/org/gnome/gnome-sudoku/"
+id="org.gnome.gnome-sudoku.Settings" gettext-domain="gnome-games">
+    <key type="b" name="fullscreen">
+      <default>false</default>
+      <_summary>A flag to enable fullscreen mode</_summary>
+      <_description>A flag to enable fullscreen mode</_description>
+    </key>
+    <key name="show-toolbar" type="b">
+      <default>false</default>
+      <_summary>A flag to enable the toolbar</_summary>
+      <_description>A flag to enable the toolbar</_description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gnome-sudoku/src/gnome-sudoku.vala b/gnome-sudoku/src/gnome-sudoku.vala
index c12143d..379343d 100644
--- a/gnome-sudoku/src/gnome-sudoku.vala
+++ b/gnome-sudoku/src/gnome-sudoku.vala
@@ -1,16 +1,20 @@
 public class Application
 {
+    private Settings settings;
     private Gtk.Builder builder;
 
     private SudokuGame game;
     private Gtk.Toolbar toolbar;
     private Gtk.Window window;
     private SudokuView view;
+    private Gtk.CheckMenuItem fullscreen_menu;
 
     private Gtk.AboutDialog? about_dialog = null;
 
     public Application ()
     {
+        settings = new Settings ("org.gnome.gnome-sudoku.Settings");
+
         builder = new Gtk.Builder ();
         try
         {
@@ -21,9 +25,12 @@ public class Application
             GLib.warning ("Could not load UI: %s", e.message);
         }
         window = (Gtk.Window) builder.get_object ("sudoku_app");
+        fullscreen_menu = (Gtk.CheckMenuItem) builder.get_object ("toggle_fullscreen_imagemenuitem");
         var main_vbox = (Gtk.VBox) builder.get_object ("main_vbox");
         toolbar = (Gtk.Toolbar) builder.get_object ("sudoku_toolbar");
-
+        settings.bind ("show-toolbar", builder.get_object ("sudoku_toolbar"), "visible", SettingsBindFlags.DEFAULT);
+        settings.bind("show-toolbar", builder.get_object ("toggle_toolbar_imagemenuitem"), "active", SettingsBindFlags.GET); 
+        
         game = new SudokuGame ();
         game.set_from_string ("---------" +
                               "-----3-85" +
@@ -38,12 +45,13 @@ public class Application
         view = new SudokuView (game);
         view.show ();
         main_vbox.pack_start (view);
-        toolbar.hide();         
         builder.connect_signals (this);
     }
     
     public void start ()
     {
+        if (settings.get_boolean ("fullscreen"))
+            window.fullscreen ();
         show ();
     }
 
@@ -100,17 +108,27 @@ public class Application
         Gtk.main_quit ();
     }
 
+    [CCode (cname = "G_MODULE_EXPORT sudoku_app_window_state_event_cb", instance_pos = -1)]
+    public bool sudoku_app_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
+    {
+        if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
+        {
+            bool is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
+            settings.set_boolean ("fullscreen", is_fullscreen);
+            fullscreen_menu.active = is_fullscreen;
+        }
+
+        return false;
+    }
+
+
     [CCode (cname = "G_MODULE_EXPORT toggle_fullscreen_cb", instance_pos = -1)]
     public void toggle_fullscreen_cb (Gtk.CheckMenuItem item)
     {  
-        /* Assume window is fullscreen afterward. No attempt
-         * is made to account for the state of the toggle.
-         */
-
-        if (item.active)
-                window.fullscreen();
-        else
-                window.unfullscreen();
+        if (item.active) 
+                window.fullscreen (); 
+        else 
+                window.unfullscreen ();
     }
 
     [CCode (cname = "G_MODULE_EXPORT toggle_toolbar_cb", instance_pos = -1)]



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