diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js index 474bd145..be94084e 100644 --- a/extensions/places-menu/extension.js +++ b/extensions/places-menu/extension.js @@ -30,9 +30,24 @@ const PlaceMenuItem = new Lang.Class({ this.parent(); this._info = info; - this.addActor(new St.Icon({ gicon: info.icon, - icon_size: PLACE_ICON_SIZE })); - this.addActor(new St.Label({ text: info.name })); + this._icon = new St.Icon({ gicon: info.icon, + icon_size: PLACE_ICON_SIZE }); + this.addActor(this._icon); + + this._label = new St.Label({ text: info.name }); + this.addActor(this._label); + + this._changedId = info.connect('changed', + Lang.bind(this, this._propertiesChanged)); + }, + + destroy: function() { + if (this._changedId) { + this._info.disconnect(this._changedId); + this._changedId = 0; + } + + this.parent(); }, activate: function(event) { @@ -40,6 +55,11 @@ const PlaceMenuItem = new Lang.Class({ this.parent(event); }, + + _propertiesChanged: function(info) { + this._icon.gicon = info.icon; + this._label.text = info.name; + }, }); const SECTIONS = [ diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js index d7d069a1..a8acf30a 100644 --- a/extensions/places-menu/placeDisplay.js +++ b/extensions/places-menu/placeDisplay.js @@ -18,6 +18,11 @@ const Gettext = imports.gettext.domain('gnome-shell-extensions'); const _ = Gettext.gettext; const N_ = function(x) { return x; } +const Hostname1Iface = + +; +const Hostname1 = Gio.DBusProxy.makeProxyWrapper(Hostname1Iface); + const PlaceInfo = new Lang.Class({ Name: 'PlaceInfo', @@ -28,6 +33,9 @@ const PlaceInfo = new Lang.Class({ this.icon = icon ? new Gio.ThemedIcon({ name: icon }) : this.getIcon(); }, + destroy: function() { + }, + isRemovable: function() { return false; }, @@ -80,6 +88,47 @@ const PlaceInfo = new Lang.Class({ } }, }); +Signals.addSignalMethods(PlaceInfo.prototype); + +const RootInfo = new Lang.Class({ + Name: 'RootInfo', + Extends: PlaceInfo, + + _init: function() { + this.parent('devices', Gio.File.new_for_path('/'), _("Computer")); + + this._proxy = new Hostname1(Gio.DBus.system, + 'org.freedesktop.hostname1', + '/org/freedesktop/hostname1', + Lang.bind(this, function(obj, error) { + if (error) + return; + + this._proxy.connect('g-properties-changed', + Lang.bind(this, this._propertiesChanged)); + this._propertiesChanged(obj); + })); + }, + + getIcon: function() { + return new Gio.ThemedIcon({ name: 'drive-harddisk-symbolic' }); + }, + + _propertiesChanged: function(proxy) { + // GDBusProxy will emit a g-properties-changed when hostname1 goes down + // ignore it + if (proxy.g_name_owner) { + this.name = proxy.PrettyHostname || _("Computer"); + this.emit('changed'); + } + }, + + destroy: function() { + this._proxy.run_dispose(); + this.parent(); + } +}); + const PlaceDeviceInfo = new Lang.Class({ Name: 'PlaceDeviceInfo', @@ -218,14 +267,13 @@ const PlacesManager = new Lang.Class({ let networkMounts = []; let networkVolumes = []; + this._places.devices.forEach(function (p) { p.destroy(); }); this._places.devices = []; + this._places.network.forEach(function (p) { p.destroy(); }); this._places.network = []; /* Add standard places */ - this._places.devices.push(new PlaceInfo('devices', - Gio.File.new_for_path('/'), - _("Computer"), - 'drive-harddisk-symbolic')); + this._places.devices.push(new RootInfo()); this._places.network.push(new PlaceInfo('network', Gio.File.new_for_uri('network:///'), _("Browse Network"),