commit 273eeeaac4c96d092d2a467c3e43195678488e15
parent 96d773e0cc01c6bcb00a09af7f701dfd27e3209f
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date: Sun, 27 Mar 2011 13:25:38 +0800
Preferences.instance
Diffstat:
4 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/src/spek-preferences-dialog.vala b/src/spek-preferences-dialog.vala
@@ -20,8 +20,6 @@ using Gtk;
namespace Spek {
public class PreferencesDialog : Gtk.Dialog {
- private Preferences prefs = new Preferences ();
-
public PreferencesDialog () {
title = _("Preferences");
modal = true;
@@ -47,8 +45,8 @@ namespace Spek {
var language_label = new Label.with_mnemonic (_("_Language:"));
language_box.pack_start (language_label, false, false, 0);
var language_combo = new ComboBox.text ();
- for (int i = 0; i < prefs.languages.length[0]; i++) {
- language_combo.append_text (prefs.languages[i,1]);
+ for (int i = 0; i < Preferences.instance.languages.length[0]; i++) {
+ language_combo.append_text (Preferences.instance.languages[i,1]);
}
language_label.mnemonic_widget = language_combo;
language_box.pack_start (language_combo, false, false, 0);
diff --git a/src/spek-preferences.vala b/src/spek-preferences.vala
@@ -35,7 +35,7 @@ namespace Spek {
{"uk", "Українська"}
};
- public Preferences () {
+ private Preferences () {
languages[0,1] = _("(system default)");
file_name = Path.build_filename (Environment.get_user_config_dir (), "spek");
DirUtils.create_with_parents (file_name, 0755);
@@ -53,6 +53,16 @@ namespace Spek {
output.puts (key_file.to_data ());
}
+ private static Preferences _instance;
+ public static Preferences instance {
+ get {
+ if (_instance == null) {
+ _instance = new Preferences ();
+ }
+ return _instance;
+ }
+ }
+
public bool check_update {
get {
try {
diff --git a/src/spek-window.vala b/src/spek-window.vala
@@ -285,8 +285,7 @@ namespace Spek {
private void * check_version () {
// Does the user want to check for updates?
- var prefs = new Preferences ();
- var check = prefs.check_update;
+ var check = Preferences.instance.check_update;
if (!check) {
return null;
}
@@ -296,7 +295,7 @@ namespace Spek {
time_val.get_current_time ();
Date today = Date ();
today.set_time_val (time_val);
- int day = prefs.last_update;
+ int day = Preferences.instance.last_update;
int diff = (int) today.get_julian () - day;
if (diff < 7) {
return null;
@@ -313,8 +312,8 @@ namespace Spek {
}
// Update the preferences.
- prefs.check_update = check;
- prefs.last_update = (int) today.get_julian ();
+ Preferences.instance.check_update = check;
+ Preferences.instance.last_update = (int) today.get_julian ();
return null;
}
}
diff --git a/src/spek.vala b/src/spek.vala
@@ -30,11 +30,9 @@ namespace Spek {
int main (string[] args) {
Platform.fix_args (args);
- var prefs = new Preferences ();
- if (prefs.language.length > 0) {
- Environment.set_variable ("LC_ALL", prefs.language, true);
+ if (Preferences.instance.language.length > 0) {
+ Environment.set_variable ("LC_ALL", Preferences.instance.language, true);
}
- prefs = null;
// Intl.setlocale (LocaleCategory.ALL, prefs.language);
Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);