From 5d4e2561be790743b327ddced7808ab9edbdfe77 Mon Sep 17 00:00:00 2001 From: brl Date: Sat, 19 Dec 2015 16:17:12 +0000 Subject: [PATCH] Gnome shell status area menu --- .../firewall@subgraph.com/extension.js | 4 ++ gnome-shell/firewall@subgraph.com/menu.js | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 gnome-shell/firewall@subgraph.com/menu.js diff --git a/gnome-shell/firewall@subgraph.com/extension.js b/gnome-shell/firewall@subgraph.com/extension.js index fbde8d9..6bcecb7 100644 --- a/gnome-shell/firewall@subgraph.com/extension.js +++ b/gnome-shell/firewall@subgraph.com/extension.js @@ -3,6 +3,7 @@ const Gio = imports.gi.Gio; const Extension = imports.misc.extensionUtils.getCurrentExtension(); const Dialog = Extension.imports.dialog; +const Menu = Extension.imports.menu; function init() { return new FirewallSupport(); @@ -12,6 +13,7 @@ const FirewallSupport = new Lang.Class({ Name: 'FirewallSupport', _init: function() { + this.menu = new Menu.FirewallMenu(); this.handler = null; }, @@ -24,8 +26,10 @@ const FirewallSupport = new Lang.Class({ enable: function() { this._destroyHandler(); this.handler = new FirewallPromptHandler(); + this.menu.install(); }, disable: function() { + this.menu.destroy(); this._destroyHandler(); } }); diff --git a/gnome-shell/firewall@subgraph.com/menu.js b/gnome-shell/firewall@subgraph.com/menu.js new file mode 100644 index 0000000..a16745d --- /dev/null +++ b/gnome-shell/firewall@subgraph.com/menu.js @@ -0,0 +1,70 @@ +const Lang = imports.lang; + +const Main = imports.ui.main; +const PopupMenu = imports.ui.popupMenu; + + +const FirewallMenu = new Lang.Class({ + Name: 'FirewallSupport', + + _init: function() { + this.aggregate = Main.panel.statusArea.aggregateMenu; + }, + + install: function() { + this.createMenu(); + let idx = this.findMenu(this.aggregate._power.menu); + if(idx >= 0) { + this.aggregate.menu.addMenuItem(this.menu, idx); + } + }, + + destroy: function() { + if(this.menu) { + this.menu.destroy(); + this.menu = null; + } + }, + + findMenu: function(menu) { + let items = this.aggregate.menu._getMenuItems(); + for(let i = 0; i < items.length; i++) { + if(items[i] == menu) { + return i; + } + } + return -1; + }, + + createMenu: function() { + if(this.menu) { + this.menu.destroy(); + } + this.menu = new PopupMenu.PopupMenuSection(); + this.item = new PopupMenu.PopupSubMenuMenuItem("Firewall", true); + this.item.icon.icon_name = "security-high-symbolic"; + this.toggle = new PopupMenu.PopupSwitchMenuItem("Firewall Enabled", false); + this.toggle.connect('toggled', Lang.bind(this, this.onToggle)); + this.item.menu.addMenuItem(this.toggle); + + this.item.menu.addAction("Connection Monitor", Lang.bind(this, this.onMonitor)); + this.item.menu.addAction("Firewall Settings", Lang.bind(this, this.onSettings)); + this.menu.addMenuItem(this.item); + }, + + onToggle: function() { + if(this.toggle.state) { + log("Toggle ON"); + } else { + log("Toggle OFF"); + } + }, + + onSettings: function() { + log("Firewall Settings clicked"); + }, + + onMonitor: function() { + log("Connection monitor clicked"); + }, +}); \ No newline at end of file