[gnome-games] [same-gnome-clutter] Pull in theme selector loading code, settings display, etc.



commit 8492d2d96892b40d55b90141e6d3fc3ed0d27d85
Author: Tim Horton <hortont424 gmail com>
Date:   Sun Jul 12 19:56:13 2009 -0400

    [same-gnome-clutter] Pull in theme selector loading code, settings display, etc.

 same-gnome-clutter/Makefile.am      |    2 +
 same-gnome-clutter/data/settings.ui |    2 +-
 same-gnome-clutter/src/Settings.js  |  108 +++++++++++++++++++++++++++++++++++
 same-gnome-clutter/src/main.js      |    3 +-
 4 files changed, 113 insertions(+), 2 deletions(-)
---
diff --git a/same-gnome-clutter/Makefile.am b/same-gnome-clutter/Makefile.am
index 4db137a..aed5e65 100644
--- a/same-gnome-clutter/Makefile.am
+++ b/same-gnome-clutter/Makefile.am
@@ -7,6 +7,7 @@ same_DATA = \
     src/Board.js \
     src/Light.js \
     src/main.js \
+    src/Settings.js \
     data/same-gnome.ui \
     data/settings.ui \
     src/Score.js \
@@ -32,6 +33,7 @@ EXTRA_DIST = \
     src/Board.js \
     src/Light.js \
     src/main.js \
+    src/Settings.js \
     data/same-gnome.ui \
     data/settings.ui \
     src/Score.js \
diff --git a/same-gnome-clutter/data/settings.ui b/same-gnome-clutter/data/settings.ui
index b4d9f07..4309e1c 100644
--- a/same-gnome-clutter/data/settings.ui
+++ b/same-gnome-clutter/data/settings.ui
@@ -131,7 +131,7 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkComboBox" id="theme-selector1">
+                              <object class="GtkComboBox" id="theme-selector">
                                 <property name="visible">True</property>
                                 <property name="model">liststore1</property>
                               </object>
diff --git a/same-gnome-clutter/src/Settings.js b/same-gnome-clutter/src/Settings.js
index e69de29..1d0134e 100644
--- a/same-gnome-clutter/src/Settings.js
+++ b/same-gnome-clutter/src/Settings.js
@@ -0,0 +1,108 @@
+Gtk = imports.gi.Gtk;
+Gio = imports.gi.Gio;
+GtkBuilder = imports.gtkbuilder;
+main = imports.main;
+GConf = imports.gi.GConf;
+ThemeLoader = imports.ThemeLoader;
+
+GConf.init(Seed.argv);
+
+// Defaults
+var theme;
+var default_theme = "Tango";
+
+// Map theme names to themes
+var themes = ThemeLoader.load_themes();
+
+try
+{
+	gconf_client = GConf.Client.get_default();
+	theme = themes[gconf_client.get_string("/apps/same-gnome-clutter/theme")];
+	
+	if(theme == null)
+		theme = themes[default_theme];
+}
+catch(e)
+{
+	print("Couldn't load settings from GConf.");
+	theme = themes[default_theme];
+}
+
+// Settings Event Handler
+
+SettingsWatcher = new GType({
+	parent: Gtk.Button.type, // TODO: Can I make something inherit directly from GObject?!
+	name: "SettingsWatcher",
+	signals: [{name: "theme_changed"}],
+	init: function()
+	{
+		
+	}
+});
+
+var Watcher = new SettingsWatcher();
+
+// Settings UI
+
+handlers = {
+	select_theme: function(selector, ud)
+	{
+		new_theme = themes[selector.get_active_text()];
+		
+		if(new_theme == theme)
+			return;
+		
+		theme = new_theme;
+		ThemeLoader.load_theme(main.stage, theme);
+		
+		try
+		{
+			gconf_client.set_string("/apps/lightsoff/theme", selector.get_active_text());
+		}
+		catch(e)
+		{
+			Seed.print("Couldn't save settings to GConf.");
+		}
+	
+		Watcher.signal.theme_changed.emit();
+	}
+};
+
+// Settings UI Helper Functions
+
+function show_settings()
+{
+	b = new Gtk.Builder();
+	b.add_from_file(imports.Path.file_prefix + "/settings.ui");
+	b.connect_signals(handlers);
+
+	populate_theme_selector(b.get_object("theme-selector"));
+
+	settings_dialog = b.get_object("dialog1");
+	settings_dialog.set_transient_for(main.window);
+	
+	var result = settings_dialog.run();
+	
+	settings_dialog.destroy();
+}
+
+function populate_theme_selector(selector)
+{
+	// Since we're using GtkBuilder, we can't make a Gtk.ComboBox.text. Instead,
+	// we'll construct the cell renderer here, once, and use that.
+	var cell = new Gtk.CellRendererText();
+	selector.pack_start(cell, true);
+	selector.add_attribute(cell, "text", 0);
+
+	var i = 0;
+
+	for(var th in themes)
+	{
+		selector.append_text(themes[th].name);
+		
+		if(themes[th].name == theme.name)
+			selector.set_active(i);
+		
+		i++;
+	}
+}
diff --git a/same-gnome-clutter/src/main.js b/same-gnome-clutter/src/main.js
index a754bdd..a66326f 100755
--- a/same-gnome-clutter/src/main.js
+++ b/same-gnome-clutter/src/main.js
@@ -34,11 +34,12 @@ Light = imports.Light;
 Board = imports.Board;
 Score = imports.Score;
 About = imports.About;
+Settings = imports.Settings;
 
 handlers = {
 	show_settings: function(selector, ud)
 	{
-		//Settings.show_settings();
+		Settings.show_settings();
 	},
 	show_about: function(selector, ud)
 	{



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