[baobab] Replace "Main volume" with hostname when available



commit 039c1e03e213c44868416c827498598fcec31f3e
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Fri Sep 28 19:35:36 2012 +0200

    Replace "Main volume" with hostname when available
    
    As requested by designers.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685048

 src/baobab-location.vala |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/src/baobab-location.vala b/src/baobab-location.vala
index 7eb30f1..e10e4ff 100644
--- a/src/baobab-location.vala
+++ b/src/baobab-location.vala
@@ -21,6 +21,12 @@
 
 namespace Baobab {
 
+    [DBus (name = "org.freedesktop.hostname1")]
+    interface HostnameIface : Object {
+        public abstract string pretty_hostname { owned get; set; }
+        public abstract string hostname { owned get; set; }
+    }
+
     public class Location {
         public string name { get; private set; }
         public File? file { get; private set; }
@@ -48,6 +54,19 @@ namespace Baobab {
 
         private static Location? home_location = null;
 
+        string get_hostname () throws Error {
+            HostnameIface hostname_iface;
+            hostname_iface = Bus.get_proxy_sync (BusType.SYSTEM,
+                                                 "org.freedesktop.hostname1",
+                                                 "/org/freedesktop/hostname1");
+            var pretty_name = hostname_iface.pretty_hostname;
+            if (pretty_name != "") {
+                return pretty_name;
+            } else {
+                return hostname_iface.hostname;
+            }
+        }
+
         void make_this_home_location () {
             name = _("Home folder");
             icon = new ThemedIcon ("user-home");
@@ -88,7 +107,12 @@ namespace Baobab {
         }
 
         public Location.for_main_volume () {
-            name = _("Main volume");
+            try {
+                name = get_hostname ();
+            } catch (Error e) {
+                name = _("Main volume");
+            }
+
             file = File.new_for_path ("/");
             get_file_info ();
             icon = new ThemedIcon ("drive-harddisk-system");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]