[gnome-shell-extensions] places-menu: show the computer pretty name for the file system root
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions] places-menu: show the computer pretty name for the file system root
- Date: Wed, 13 Feb 2013 21:45:19 +0000 (UTC)
commit 2f5c095f7a0d2f85a0673ad0605ba7fbed2e0645
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Feb 10 17:06:21 2013 +0100
places-menu: show the computer pretty name for the file system root
As Nautilus does, query hostnamed for the pretty hostname and watch
for changes.
If hostnamed is not available, we just show Computer, as before.
https://bugzilla.gnome.org/show_bug.cgi?id=693240
extensions/places-menu/extension.js | 26 +++++++++++++--
extensions/places-menu/placeDisplay.js | 56 +++++++++++++++++++++++++++++--
2 files changed, 75 insertions(+), 7 deletions(-)
---
diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js
index 474bd14..be94084 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 d7d069a..a8acf30 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 = <interface name="org.freedesktop.hostname1">
+<property name="PrettyHostname" type="s" access="read" />
+</interface>;
+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"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]