[gnome-shell/wip/aggregate-menu: 49/57] status: Add new airplane mode indicator / menu



commit 7666ed319c2f88fb5c3027757e699518da086712
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon May 27 17:54:50 2013 -0400

    status: Add new airplane mode indicator / menu

 js/Makefile.am         |    1 +
 js/ui/panel.js         |    3 ++
 js/ui/status/rfkill.js |   57 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index 5e5add4..2db22cd 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -92,6 +92,7 @@ nobase_dist_js_DATA =         \
        ui/status/keyboard.js   \
        ui/status/network.js    \
        ui/status/power.js      \
+       ui/status/rfkill.js     \
        ui/status/volume.js     \
        ui/status/bluetooth.js  \
        ui/status/system.js     \
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 4e9a7c5..7a513d2 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -859,6 +859,7 @@ const AggregateMenu = new Lang.Class({
         this._network = new imports.ui.status.network.NMApplet();
         this._bluetooth = new imports.ui.status.bluetooth.Indicator();
         this._power = new imports.ui.status.power.Indicator();
+        this._rfkill = new imports.ui.status.rfkill.Indicator();
         this._volume = new imports.ui.status.volume.Indicator();
         this._brightness = new imports.ui.status.brightness.Indicator();
         this._system = new imports.ui.status.system.Indicator();
@@ -866,6 +867,7 @@ const AggregateMenu = new Lang.Class({
         this._indicators.add_child(this._network.indicators);
         this._indicators.add_child(this._bluetooth.indicators);
         this._indicators.add_child(this._power.indicators);
+        this._indicators.add_child(this._rfkill.indicators);
         this._indicators.add_child(this._volume.indicators);
         this._indicators.add_child(this._system.indicators);
         this._indicators.add_child(new St.Label({ text: '\u25BE' }));
@@ -875,6 +877,7 @@ const AggregateMenu = new Lang.Class({
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
         this.menu.addMenuItem(this._network.menu);
         this.menu.addMenuItem(this._bluetooth.menu);
+        this.menu.addMenuItem(this._rfkill.menu);
         this.menu.addMenuItem(this._power.menu);
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
         this.menu.addMenuItem(this._system.menu);
diff --git a/js/ui/status/rfkill.js b/js/ui/status/rfkill.js
new file mode 100644
index 0000000..615c22a
--- /dev/null
+++ b/js/ui/status/rfkill.js
@@ -0,0 +1,57 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Gio = imports.gi.Gio;
+const Lang = imports.lang;
+
+const PanelMenu = imports.ui.panelMenu;
+const PopupMenu = imports.ui.popupMenu;
+
+const BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill';
+const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
+
+const RfkillManagerInterface = <interface name="org.gnome.SettingsDaemon.Rfkill">
+<property name="AirplaneMode" type="b" access="readwrite" />
+</interface>;
+
+const RfkillManagerProxy = Gio.DBusProxy.makeProxyWrapper(RfkillManagerInterface);
+
+const Indicator = new Lang.Class({
+    Name: 'RfkillIndicator',
+    Extends: PanelMenu.SystemIndicator,
+
+    _init: function() {
+        this.parent();
+
+        this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
+                                             Lang.bind(this, function(proxy, error) {
+                                                 if (error) {
+                                                     log(error.message);
+                                                     return;
+                                                 }
+                                                 this._proxy.connect('g-properties-changed',
+                                                                     Lang.bind(this, 
this._syncAirplaneMode));
+                                                 this._syncAirplaneMode();
+                                             }));
+
+        this._indicator = this.addIndicator(new Gio.ThemedIcon({ name: 'airplane-mode-symbolic' }));
+        this._indicator.hide();
+
+        // The menu only appears when airplane mode is on, so just
+        // statically build it as if it was on, rather than dynamically
+        // changing the menu contents.
+        this._item = new PopupMenu.PopupSubMenuMenuItem(_("Airplane Mode"), true);
+        this._item.icon.icon_name = 'airplane-mode-symbolic';
+        this._item.status.text = _("On");
+        this._item.menu.addAction(_("Turn Off"), Lang.bind(this, function() {
+            this._proxy.AirplaneMode = false;
+        }));
+        this._item.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
+        this.menu.addMenuItem(this._item);
+    },
+
+    _syncAirplaneMode: function() {
+        let airplaneMode = this._proxy.AirplaneMode;
+        this._indicator.visible = airplaneMode;
+        this._item.actor.visible = airplaneMode;
+    },
+});


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