[four-in-a-row: 52/72] moved settings to Prefs
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row: 52/72] moved settings to Prefs
- Date: Sun, 16 Dec 2018 21:01:09 +0000 (UTC)
commit 1261d5ce3474987e83e77e2e5549219a6904c50e
Author: Jacob Humphrey <jacob ryan humphrey gmail com>
Date: Sat Dec 15 01:46:09 2018 -0600
moved settings to Prefs
src/main.vala | 6 +-----
src/prefs-box.vala | 10 +++++-----
src/prefs.vala | 31 +++++++++++--------------------
3 files changed, 17 insertions(+), 30 deletions(-)
---
diff --git a/src/main.vala b/src/main.vala
index 5cb033b..7846fbb 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -74,8 +74,7 @@ public enum SoundID {
FourInARow? application;
Gtk.ApplicationWindow window;
-Settings settings;
-//Prefs p;
+//Settings settings;
public int main(string[] argv) {
Intl.setlocale();
@@ -95,11 +94,8 @@ public int main(string[] argv) {
return 1;
}
- settings = new GLib.Settings("org.gnome.four-in-a-row");
-
Environment.set_application_name(_(APPNAME_LONG));
-
application.game_init();
if (!GameBoardView.instance.load_pixmaps())
diff --git a/src/prefs-box.vala b/src/prefs-box.vala
index 6c80ef0..8f01f3a 100644
--- a/src/prefs-box.vala
+++ b/src/prefs-box.vala
@@ -99,7 +99,7 @@ class PrefsBox : Gtk.Dialog {
/* keyboard tab */
label = new Gtk.Label.with_mnemonic(_("Keyboard Controls"));
- controls_list = new GamesControlsList(settings);
+ controls_list = new GamesControlsList(Prefs.instance.settings);
controls_list.add_controls("key-left", _("Move left"), DEFAULT_KEY_LEFT,
"key-right", _("Move right"), DEFAULT_KEY_RIGHT,
"key-drop", _("Drop marble"), DEFAULT_KEY_DROP);
@@ -116,8 +116,8 @@ class PrefsBox : Gtk.Dialog {
Prefs.instance.theme_changed.connect((theme_id) => {
combobox_theme.set_active(theme_id);
});
- Prefs.instance.sound_changed.connect((sound) => {
- checkbutton_sound.set_active(sound);
+ Prefs.instance.notify["do_sound"].connect(() => {
+ checkbutton_sound.set_active(Prefs.instance.do_sound);
});
}
@@ -128,7 +128,7 @@ class PrefsBox : Gtk.Dialog {
void on_select_theme(Gtk.ComboBox combo) {
int id = combo.get_active();
- settings.set_int("theme-id", id);
+ Prefs.instance.theme_id = id;
}
void on_select_opponent(Gtk.ComboBox w) {
@@ -139,7 +139,7 @@ class PrefsBox : Gtk.Dialog {
w.get_model().get(iter, 1, out value);
Prefs.instance.level[PlayerID.PLAYER2] = (Level)value;
- settings.set_int("opponent", value);
+ Prefs.instance.settings.set_int("opponent", value);
Scorebox.instance.reset();
global::application.who_starts = PlayerID.PLAYER2; /* This gets reversed in game_reset. */
global::application.game_reset();
diff --git a/src/prefs.vala b/src/prefs.vala
index 57f12ea..0bb128f 100644
--- a/src/prefs.vala
+++ b/src/prefs.vala
@@ -19,19 +19,19 @@
* along with GNOME Four-in-a-row. If not, see <http://www.gnu.org/licenses/>.
*/
-class Prefs {
- bool _do_sound;
- public bool do_sound {
- get {
- return settings.get_boolean("sound");
+class Prefs : Object {
+ public bool do_sound{ get; set;}
+ public int theme_id {
+ get{
+ return settings.get_int("theme-id");
}
- private set {
- settings.set_boolean("sound", value);
+ set{
+ settings.set_int("theme-id", value);
}
}
- public int theme_id;
public Level level[2];
public int keypress[3];
+ public Settings settings;
static Once<Prefs> _instance;
public static Prefs instance { get {
@@ -41,6 +41,7 @@ class Prefs {
}}
public Prefs() {
+ settings = new GLib.Settings("org.gnome.four-in-a-row");
level[PlayerID.PLAYER1] = Level.HUMAN; /* Human. Always human. */
level[PlayerID.PLAYER2] = (Level) settings.get_int("opponent");
keypress[Move.LEFT] = settings.get_int("key-left");
@@ -49,6 +50,7 @@ class Prefs {
theme_id = settings.get_int("theme-id");
settings.changed.connect(settings_changed_cb);
+ settings.bind("sound", this, "do_sound", SettingsBindFlags.DEFAULT);
level[PlayerID.PLAYER1] = sane_player_level(level[PlayerID.PLAYER1]);
level[PlayerID.PLAYER2] = sane_player_level(level[PlayerID.PLAYER2]);
@@ -70,19 +72,8 @@ class Prefs {
*/
public signal void theme_changed(int theme_id);
- /**
- * sound_changed:
- *
- * emmited when the sound fx are enabled/disabled
- *
- * @sound: true if sound is enabled
- */
- public signal void sound_changed(bool sound);
-
public void settings_changed_cb(string key) {
- if (key == "sound") {
- sound_changed(do_sound);
- } else if (key == "key-left") {
+ if (key == "key-left") {
keypress[Move.LEFT] = settings.get_int("key-left");
} else if (key == "key-right") {
keypress[Move.RIGHT] = settings.get_int("key-right");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]