~ubuntu-branches/ubuntu/wily/baobab/wily-proposed

« back to all changes in this revision

Viewing changes to src/baobab-application.vala

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-10-15 23:15:13 UTC
  • mfrom: (2.2.1 experimental) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20141015231513-6cpun88orgfpyzdv
Tags: 3.14.1-1ubuntu1
* Merge from Debian unstable. (LP: #1268721) Remaining changes:
* debian/patches/use_traditional_titlebars_in_unity.patch:
  - Use the traditional menubar under Unity
* debian/patches/git_fix_pie_chart.patch:
  - Fx top level pie chart. (LP: #1393333)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
namespace Baobab {
24
24
 
25
25
    public class Application : Gtk.Application {
26
 
        static Application baobab;
27
26
 
28
 
        static bool print_version;
29
27
        const OptionEntry[] option_entries = {
30
 
            { "version", 'v', 0, OptionArg.NONE, ref print_version, N_("Print version information and exit"), null },
 
28
            { "version", 'v', 0, OptionArg.NONE, null, N_("Print version information and exit"), null },
31
29
            { null }
32
30
        };
33
31
 
35
33
            { "quit", on_quit_activate }
36
34
        };
37
35
 
38
 
        Settings prefs_settings;
39
 
        Settings ui_settings;
 
36
        public Settings prefs_settings { get; private set; }
 
37
        public Settings ui_settings { get; private set; }
40
38
 
41
39
        protected override void activate () {
42
40
            new Window (this);
45
43
        protected override void open (File[] files, string hint) {
46
44
            foreach (var file in files) {
47
45
                var window = new Window (this);
48
 
                window.scan_directory (file);
 
46
                window.scan_directory (file, ScanFlags.EXCLUDE_MOUNTS);
49
47
            }
50
48
        }
51
49
 
52
 
        public static HashTable<File, unowned File> get_excluded_locations () {
53
 
            var app = baobab;
 
50
        public static new Application get_default () {
 
51
            return (Application) GLib.Application.get_default ();
 
52
        }
54
53
 
 
54
        public HashTable<File, unowned File> get_excluded_locations () {
55
55
            var excluded_locations = new HashTable<File, unowned File> (File.hash, File.equal);
56
56
            excluded_locations.add (File.new_for_path ("/proc"));
57
57
            excluded_locations.add (File.new_for_path ("/sys"));
61
61
            excluded_locations.add (home.get_child (".gvfs"));
62
62
 
63
63
            var root = File.new_for_path ("/");
64
 
            foreach (var uri in app.prefs_settings.get_value ("excluded-uris")) {
 
64
            foreach (var uri in prefs_settings.get_value ("excluded-uris")) {
65
65
                var file = File.new_for_uri ((string) uri);
66
66
                if (!file.equal (root)) {
67
67
                    excluded_locations.add (file);
74
74
        protected override void startup () {
75
75
            base.startup ();
76
76
 
77
 
            baobab = this;
 
77
            // Load custom CSS
 
78
            var css_provider = new Gtk.CssProvider ();
 
79
            var css_file = File.new_for_uri ("resource:///org/gnome/baobab/baobab.css");
 
80
            try {
 
81
              css_provider.load_from_file (css_file);
 
82
            } catch (Error e) {
 
83
                warning ("loading css: %s", e.message);
 
84
            }
 
85
            Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
78
86
 
79
87
            // Settings
80
88
            ui_settings = new Settings ("org.gnome.baobab.ui");
82
90
 
83
91
            ui_settings.delay ();
84
92
 
85
 
            // Menus: in gnome shell we just use the app menu, since the remaining
86
 
            // items are too few to look ok in a menubar and they are not essential
87
 
            var gtk_settings = Gtk.Settings.get_default ();
88
 
            var builder = new Gtk.Builder ();
89
 
            try {
90
 
                builder.add_from_resource ("/org/gnome/baobab/ui/baobab-menu.ui");
91
 
            } catch (Error e) {
92
 
                error ("loading menu builder file: %s", e.message);
93
 
            }
94
 
            if (gtk_settings.gtk_shell_shows_app_menu && !gtk_settings.gtk_shell_shows_menubar) {
95
 
                var app_menu = builder.get_object ("appmenu") as MenuModel;
96
 
                set_app_menu (app_menu);
97
 
            } else {
98
 
                var menubar = builder.get_object ("menubar") as MenuModel;
99
 
                set_menubar (menubar);
100
 
            }
101
 
 
102
 
            add_accelerator ("F10", "win.gear-menu", null);
 
93
            set_accels_for_action ("win.gear-menu", { "F10" });
 
94
            set_accels_for_action ("win.reload", { "<Primary>r" });
103
95
        }
104
96
 
105
 
        protected override bool local_command_line ([CCode (array_length = false, array_null_terminated = true)] ref unowned string[] arguments, out int exit_status) {
106
 
            var ctx = new OptionContext (_("- Disk Usage Analyzer"));
107
 
 
108
 
            ctx.add_main_entries (option_entries, Config.GETTEXT_PACKAGE);
109
 
            ctx.add_group (Gtk.get_option_group (true));
110
 
 
111
 
            // Workaround for bug #642885
112
 
            unowned string[] argv = arguments;
113
 
 
114
 
            try {
115
 
                ctx.parse (ref argv);
116
 
            } catch (Error e) {
117
 
                exit_status = 1;
118
 
                return true;
119
 
            }
120
 
 
121
 
            if (print_version) {
 
97
        protected override int handle_local_options (GLib.VariantDict options) {
 
98
            if (options.contains("version")) {
122
99
                print ("%s %s\n", Environment.get_application_name (), Config.VERSION);
123
 
                exit_status = 0;
124
 
                return true;
 
100
                return 0;
125
101
            }
126
102
 
127
 
            return base.local_command_line (ref arguments, out exit_status);
 
103
            return -1; 
128
104
        }
129
105
 
130
106
        protected override void shutdown () {
135
111
        public Application () {
136
112
            Object (application_id: "org.gnome.baobab", flags: ApplicationFlags.HANDLES_OPEN);
137
113
 
138
 
            Gd.ensure_types ();
139
 
 
 
114
            add_main_option_entries (option_entries);
140
115
            add_action_entries (action_entries, this);
141
116
        }
142
117
 
143
 
        public static Settings get_prefs_settings () {
144
 
            var app = baobab;
145
 
            return app.prefs_settings;
146
 
        }
147
 
 
148
 
        public static Settings get_ui_settings () {
149
 
            var app = baobab;
150
 
            return app.ui_settings;
151
 
        }
152
 
 
153
118
        void on_quit_activate () {
154
119
            quit ();
155
120
        }