~ubuntu-branches/ubuntu/precise/gnome-games/precise

« back to all changes in this revision

Viewing changes to swell-foop/src/Settings.js

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-03-19 20:46:10 UTC
  • mfrom: (1.1.105)
  • Revision ID: package-import@ubuntu.com-20120319204610-2nd2xqq39j8y7t5q
Tags: 1:3.3.92-0ubuntu1
* New upstream release.
  - Swell Foop ported to Vala, no longer in staging
    (LP: #939200, LP: #939210)
* debian/patches/git_fix-iagno-ai.patch: Dropped, upstream
* debian/control.in:
  - Drop no longer needed swell-foop dependencies
* debian/rules:
  - Don't install staging games
* debian/swell-foop.install:
  - Don't install gir files any more; they're not needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Gtk = imports.gi.Gtk;
2
 
Gio = imports.gi.Gio;
3
 
GtkBuilder = imports.gtkbuilder;
4
 
main = imports.main;
5
 
ThemeLoader = imports.ThemeLoader;
6
 
GnomeGamesSupport = imports.gi.GnomeGamesSupport;
7
 
 
8
 
_ = imports.gettext.gettext;
9
 
 
10
 
// Defaults
11
 
var theme, colors, zealous, size;
12
 
var default_theme = _("Shapes and Colors");
13
 
var default_size = 1;
14
 
var default_colors = 3;
15
 
var default_zealous = true;
16
 
 
17
 
// Map theme names to themes
18
 
var themes = ThemeLoader.load_themes();
19
 
var sizes = [{name: _("Small"), columns: 6, rows: 5},
20
 
             {name: _("Normal"), columns: 15, rows: 10},
21
 
             {name: _("Large"), columns: 20, rows: 15}];
22
 
 
23
 
settings = new Gio.Settings ({schema_id: "org.gnome.swell-foop"});
24
 
 
25
 
try
26
 
{
27
 
        theme = themes[settings.get_string("theme")];
28
 
        size = settings.get_int("size");
29
 
        colors = settings.get_int("colors");
30
 
        zealous = settings.get_boolean("zealous");
31
 
        
32
 
        if(colors < 2 || colors > 4)
33
 
                colors = default_colors;
34
 
        
35
 
        if(theme == null)
36
 
                theme = themes[default_theme];
37
 
}
38
 
catch(e)
39
 
{
40
 
        print("Couldn't load settings: " + e.message);
41
 
        theme = themes[default_theme];
42
 
        size = default_size;
43
 
        colors = default_colors;
44
 
        zealous = default_zealous;
45
 
}
46
 
 
47
 
// Settings Event Handler
48
 
 
49
 
SettingsWatcher = new GType({
50
 
        parent: Gtk.Button.type, // TODO: Can I make something inherit directly from GObject?!
51
 
        name: "SettingsWatcher",
52
 
        signals: [{name: "theme_changed"}, {name: "size_changed"}, {name: "colors_changed"}],
53
 
        init: function()
54
 
        {
55
 
                
56
 
        }
57
 
});
58
 
 
59
 
var Watcher = new SettingsWatcher();
60
 
 
61
 
// Settings UI
62
 
 
63
 
handlers = {
64
 
        select_theme: function(selector, ud)
65
 
        {
66
 
                new_theme = themes[selector.get_active_text()];
67
 
 
68
 
                if(new_theme == theme)
69
 
                        return;
70
 
                
71
 
                theme = new_theme;
72
 
                ThemeLoader.load_theme(main.stage, theme);
73
 
                
74
 
                settings.set_string("theme", selector.get_active_text());       
75
 
                Watcher.signal.theme_changed.emit();
76
 
        },
77
 
        set_zealous_animation: function(widget, ud)
78
 
        {
79
 
                zealous = widget.active;
80
 
                settings.set_boolean("zealous", zealous);
81
 
        },
82
 
        update_size: function(widget, ud)
83
 
        {
84
 
                new_size = widget.get_active();
85
 
                
86
 
                if(new_size == size)
87
 
                        return;
88
 
                
89
 
                size = new_size;
90
 
                
91
 
                settings.set_int("size", size); 
92
 
                Watcher.signal.size_changed.emit();
93
 
        },
94
 
        update_colors: function(widget, ud)
95
 
        {
96
 
                new_colors = widget.get_value();
97
 
                
98
 
                if(new_colors == colors)
99
 
                        return;
100
 
 
101
 
                colors = new_colors;
102
 
 
103
 
                settings.set_int("colors", colors);
104
 
                Watcher.signal.colors_changed.emit();
105
 
        },
106
 
        reset_defaults: function(widget, ud)
107
 
        {
108
 
                print("Not yet implemented.");
109
 
        }
110
 
};
111
 
 
112
 
// Settings UI Helper Functions
113
 
 
114
 
function show_settings()
115
 
{
116
 
        b = new Gtk.Builder();
117
 
        b.add_from_file(imports.Path.file_prefix + "/settings.ui");
118
 
        b.connect_signals(handlers);
119
 
 
120
 
        populate_theme_selector(b.get_object("theme-selector"));
121
 
        populate_size_selector(b.get_object("size-selector"));
122
 
        
123
 
        // Set current values
124
 
        b.get_object("size-selector").set_active(size);
125
 
        b.get_object("colors-spinner").value = colors;
126
 
        b.get_object("zealous-checkbox").active = zealous;
127
 
        
128
 
        settings_dialog = b.get_object("dialog1");
129
 
        settings_dialog.set_transient_for(main.window);
130
 
        
131
 
        var result = settings_dialog.run();
132
 
        
133
 
        settings_dialog.destroy();
134
 
}
135
 
 
136
 
function populate_size_selector(selector)
137
 
{
138
 
        for(var i in sizes)
139
 
        {
140
 
                selector.append_text(sizes[i].name);
141
 
        }
142
 
}
143
 
 
144
 
function populate_theme_selector(selector)
145
 
{
146
 
        var i = 0;
147
 
 
148
 
        for(var th in themes)
149
 
        {
150
 
                selector.append_text(themes[th].name);
151
 
                
152
 
                if(themes[th].name == theme.name)
153
 
                        selector.set_active(i);
154
 
                
155
 
                i++;
156
 
        }
157
 
}