[baobab] application: Do not use a static global object
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] application: Do not use a static global object
- Date: Sat, 12 Jul 2014 14:55:57 +0000 (UTC)
commit f1914e7d237b12ccce3f659ec262fabc7e1e3e6a
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sat Jul 12 16:30:13 2014 +0200
application: Do not use a static global object
src/baobab-application.vala | 25 +++++++------------------
src/baobab-scanner.vala | 2 +-
src/baobab-window.vala | 3 ++-
3 files changed, 10 insertions(+), 20 deletions(-)
---
diff --git a/src/baobab-application.vala b/src/baobab-application.vala
index 0fdbaa0..b8eb004 100644
--- a/src/baobab-application.vala
+++ b/src/baobab-application.vala
@@ -23,7 +23,6 @@
namespace Baobab {
public class Application : Gtk.Application {
- static Application baobab;
const OptionEntry[] option_entries = {
{ "version", 'v', 0, OptionArg.NONE, null, N_("Print version information and exit"), null },
@@ -34,8 +33,8 @@ namespace Baobab {
{ "quit", on_quit_activate }
};
- Settings prefs_settings;
- Settings ui_settings;
+ public Settings prefs_settings { get; private set; }
+ public Settings ui_settings { get; private set; }
protected override void activate () {
new Window (this);
@@ -48,9 +47,11 @@ namespace Baobab {
}
}
- public static HashTable<File, unowned File> get_excluded_locations () {
- var app = baobab;
+ public static new Application get_default () {
+ return (Application) GLib.Application.get_default ();
+ }
+ public HashTable<File, unowned File> get_excluded_locations () {
var excluded_locations = new HashTable<File, unowned File> (File.hash, File.equal);
excluded_locations.add (File.new_for_path ("/proc"));
excluded_locations.add (File.new_for_path ("/sys"));
@@ -60,7 +61,7 @@ namespace Baobab {
excluded_locations.add (home.get_child (".gvfs"));
var root = File.new_for_path ("/");
- foreach (var uri in app.prefs_settings.get_value ("excluded-uris")) {
+ foreach (var uri in prefs_settings.get_value ("excluded-uris")) {
var file = File.new_for_uri ((string) uri);
if (!file.equal (root)) {
excluded_locations.add (file);
@@ -73,8 +74,6 @@ namespace Baobab {
protected override void startup () {
base.startup ();
- baobab = this;
-
// Load custom CSS
var css_provider = new Gtk.CssProvider ();
var css_file = File.new_for_uri ("resource:///org/gnome/baobab/baobab.css");
@@ -116,16 +115,6 @@ namespace Baobab {
add_action_entries (action_entries, this);
}
- public static Settings get_prefs_settings () {
- var app = baobab;
- return app.prefs_settings;
- }
-
- public static Settings get_ui_settings () {
- var app = baobab;
- return app.ui_settings;
- }
-
void on_quit_activate () {
quit ();
}
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 8da38f8..9f6620a 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -432,7 +432,7 @@ namespace Baobab {
});
set_sort_column_id (Columns.SIZE, Gtk.SortType.DESCENDING);
- excluded_locations = Application.get_excluded_locations ();
+ excluded_locations = Application.get_default ().get_excluded_locations ();
if (ScanFlags.EXCLUDE_MOUNTS in flags) {
foreach (unowned UnixMountEntry mount in UnixMountEntry.get (null)) {
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 102f444..e5a49b1 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -128,6 +128,8 @@ namespace Baobab {
busy_cursor = new Gdk.Cursor (Gdk.CursorType.WATCH);
}
+ ui_settings = Application.get_default ().ui_settings;
+
add_action_entries (action_entries, this);
location_list.set_adjustment (location_scrolled_window.get_vadjustment ());
@@ -141,7 +143,6 @@ namespace Baobab {
infobar_close_button.clicked.connect (() => { clear_message (); });
- ui_settings = Application.get_ui_settings ();
lookup_action ("active-chart").change_state (ui_settings.get_value ("active-chart"));
chart_stack.notify["visible-child-name"].connect (on_chart_stack_child_changed);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]