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

« back to all changes in this revision

Viewing changes to src/baobab-location.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2012-11-05 18:19:47 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20121105181947-a5c9utsx2buosfmy
Tags: 3.6.2-0ubuntu1
* New upstream version:
  - Minor tweaks to the UI
* debian/patches/baobab_about_segfault.patch: 
  - don't segfault when opening the about dialog (lp: #1020810)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
1
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
/* Baobab - disk usage analyzer
3
3
 *
4
4
 * Copyright (C) 2012  Paolo Borelli <pborelli@gnome.org>
21
21
 
22
22
namespace Baobab {
23
23
 
 
24
    [DBus (name = "org.freedesktop.hostname1")]
 
25
    interface HostnameIface : Object {
 
26
        public abstract string pretty_hostname { owned get; set; }
 
27
        public abstract string hostname { owned get; set; }
 
28
    }
 
29
 
24
30
    public class Location {
25
31
        public string name { get; private set; }
26
32
        public File? file { get; private set; }
37
43
 
38
44
        public Scanner? scanner { get; private set; }
39
45
 
 
46
        public bool is_home {
 
47
            get {
 
48
                return home_location == this;
 
49
            }
 
50
        }
 
51
 
40
52
        private static const string FS_ATTRIBUTES =
41
53
            FileAttribute.FILESYSTEM_SIZE + "," +
42
54
            FileAttribute.FILESYSTEM_USED;
48
60
 
49
61
        private static Location? home_location = null;
50
62
 
 
63
        string get_hostname () throws Error {
 
64
            HostnameIface hostname_iface;
 
65
            hostname_iface = Bus.get_proxy_sync (BusType.SYSTEM,
 
66
                                                 "org.freedesktop.hostname1",
 
67
                                                 "/org/freedesktop/hostname1");
 
68
            var pretty_name = hostname_iface.pretty_hostname;
 
69
            if (pretty_name != "") {
 
70
                return pretty_name;
 
71
            } else {
 
72
                return hostname_iface.hostname;
 
73
            }
 
74
        }
 
75
 
51
76
        void make_this_home_location () {
52
77
            name = _("Home folder");
53
78
            icon = new ThemedIcon ("user-home");
88
113
        }
89
114
 
90
115
        public Location.for_main_volume () {
91
 
            name = _("Main volume");
 
116
            try {
 
117
                name = get_hostname ();
 
118
            } catch (Error e) {
 
119
                name = _("Main volume");
 
120
            }
 
121
 
92
122
            file = File.new_for_path ("/");
93
123
            get_file_info ();
94
124
            icon = new ThemedIcon ("drive-harddisk-system");
143
173
                icon = volume.get_icon ();
144
174
                file = null;
145
175
                info = null;
146
 
                size = 0;
147
 
                used = 0;
 
176
                size = null;
 
177
                used = null;
148
178
                scanner = null;
149
179
            }
150
180
        }