[gnome-shell/wip/aggregate-menu: 37/57] network: Implement new designs for VPN/modem submenus
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/aggregate-menu: 37/57] network: Implement new designs for VPN/modem submenus
- Date: Wed, 17 Jul 2013 06:38:10 +0000 (UTC)
commit 61a7d863fb65fd5707730e9fd6390c69693341f4
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Jun 11 21:40:27 2013 -0400
network: Implement new designs for VPN/modem submenus
js/ui/status/network.js | 228 ++++++++++++++++++++++++-----------------------
1 files changed, 115 insertions(+), 113 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 788b54d..cb8cc55 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -79,14 +79,22 @@ const NMConnectionItem = new Lang.Class({
this._activeConnection = null;
this._activeConnectionChangedId = 0;
- this.menuItem = new PopupMenu.PopupSwitchMenuItem(connection.get_id(), false);
- this.menuItem.connect('toggled', Lang.bind(this, this._toggle));
+ this.labelItem = new PopupMenu.PopupMenuItem('');
+ this.labelItem.connect('activate', Lang.bind(this, this._toggle));
+
+ this.switchItem = new PopupMenu.PopupSwitchMenuItem(connection.get_id(), false);
+ this.switchItem.connect('toggled', Lang.bind(this, this._toggle));
this._sync();
},
destroy: function() {
- this.menuItem.destroy();
+ this.labelItem.destroy();
+ this.switchItem.destroy();
+ },
+
+ getName: function() {
+ return this.connection.get_id();
},
isActive: function() {
@@ -97,8 +105,10 @@ const NMConnectionItem = new Lang.Class({
},
_sync: function() {
- this.menuItem.setToggleState(this._getIsActive());
- this.menuItem.setStatus(this._getStatus());
+ let isActive = this.isActive();
+ this.labelItem.label.text = isActive ? _("Turn Off") : _("Connect");
+ this.switchItem.setToggleState(isActive);
+ this.switchItem.setStatus(this._getStatus());
this.emit('icon-changed');
},
@@ -145,21 +155,15 @@ const NMConnectionSection = new Lang.Class({
this._connectionItems = new Hash.Map();
this._connections = [];
- this.section = new PopupMenu.PopupMenuSection();
- this.statusItem = new PopupMenu.PopupSwitchMenuItem('', this.connected);
- this._statusChanged = this.statusItem.connect('toggled', Lang.bind(this, function(item, state) {
- let ok;
- if (state)
- ok = this.activate();
- else
- ok = this.deactivate();
+ this._labelSection = new PopupMenu.PopupMenuSection();
+ this._switchSection = new PopupMenu.PopupMenuSection();
- if (!ok)
- item.setToggleState(!state);
- }));
+ this.item = new PopupMenu.PopupSubMenuMenuItem('', true);
+ this.item.menu.addMenuItem(this._labelSection);
+ this.item.menu.addMenuItem(this._switchSection);
- this._updateStatusItem();
+ this.connect('icon-changed', Lang.bind(this, this._sync));
},
destroy: function() {
@@ -167,6 +171,27 @@ const NMConnectionSection = new Lang.Class({
this.section.destroy();
},
+ _sync: function() {
+ let nItems = this._connectionItems.size();
+
+ this._switchSection.actor.visible = (nItems > 1);
+ this._labelSection.actor.visible = (nItems == 1);
+
+ this.item.status.text = this._getStatus();
+ this.item.icon.icon_name = this._getMenuIcon();
+ },
+
+ _getStatus: function() {
+ let values = this._connectionItems.values();
+ for (let i = 0; i < values; i++) {
+ let item = values[i];
+ if (item.isActive())
+ return item.getName();
+ }
+
+ return _("Off");
+ },
+
_hasConnection: function(connection) {
return this._connectionItems.has(connection.get_uuid());
},
@@ -186,6 +211,10 @@ const NMConnectionSection = new Lang.Class({
return new NMConnectionItem(this._client, connection);
},
+ syncDescription: function() {
+ this.item.label.text = this._getDescription();
+ },
+
checkConnection: function(connection) {
if (!this._connectionValid(connection))
return;
@@ -209,8 +238,10 @@ const NMConnectionSection = new Lang.Class({
}));
let pos = Util.insertSorted(this._connections, connection, this._connectionSortFunction);
- this.section.addMenuItem(item.menuItem, pos);
+ this._labelSection.addMenuItem(item.labelItem, pos);
+ this._switchSection.addMenuItem(item.switchItem, pos);
this._connectionItems.set(connection.get_uuid(), item);
+ this._sync();
},
removeConnection: function(connection) {
@@ -219,6 +250,12 @@ const NMConnectionSection = new Lang.Class({
let pos = this._connections.indexOf(connection);
this._connections.splice(pos, 1);
+
+ this._sync();
+ },
+
+ _getMenuIcon: function() {
+ return this.getIndicatorIcon();
},
getIndicatorIcon: function() {
@@ -243,6 +280,9 @@ const NMDeviceModem = new Lang.Class({
this._client = client;
this._device = device;
+ this._autoConnectItem = this.item.menu.addSettingsAction(_("Connect"), Lang.bind(this,
this._autoConnect));
+ this.item.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
+
this._mobileDevice = null;
let capabilities = device.current_capabilities;
@@ -299,47 +339,50 @@ const NMDeviceModem = new Lang.Class({
this.parent();
},
- _connectionValid: function(connection) {
- return this._device.connection_valid(connection);
+ _autoConnect: function() {
+ Util.spawn(['gnome-control-center', 'network',
+ 'connect-3g', this._device.get_path()]);
},
- deactivate: function() {
- this._device.disconnect(null);
- return true;
+ _activeConnectionChanged: function() {
+ if (this._activeConnection) {
+ let item = this._connectionItems.get(this._activeConnection._connection.get_uuid());
+ item.setActiveConnection(null);
+ }
+
+ this._activeConnection = this._device.active_connection;
+
+ if (this._activeConnection) {
+ let item = this._connectionItems.get(this._activeConnection._connection.get_uuid());
+ item.setActiveConnection(this._activeConnection);
+ }
},
- activate: function() {
- if (this._activeConnection)
- // nothing to do
- return true;
+ _deviceStateChanged: function(device, newstate, oldstate, reason) {
+ if (newstate == oldstate) {
+ log('device emitted state-changed without actually changing state');
+ return;
+ }
- // If there is only one connection available, use that
- // Otherwise, if no connection is currently configured,
- // try automatic configuration (or summon the config dialog)
- if (this._connections.length == 1) {
- this._client.activate_connection(this._connections[0].connection, this._device || null, null,
null);
- return true;
- } else if (this._connections.length == 0) {
- return this._activateAutomaticConnection();
+ /* Emit a notification if activation fails, but don't do it
+ if the reason is no secrets, as that indicates the user
+ cancelled the agent dialog */
+ if (newstate == NetworkManager.DeviceState.FAILED &&
+ reason != NetworkManager.DeviceStateReason.NO_SECRETS) {
+ this.emit('activation-failed', reason);
}
- return false;
+ this._sync();
},
- _activateAutomaticConnection: function() {
- let connection = new NetworkManager.Connection();
- this._client.add_and_activate_connection(connection, this._device, null, null);
- return true;
+ _sync: function() {
+ let nItems = this._connectionItems.size();
+ this._autoConnectItem.actor.visible = (nItems == 0);
+ this.parent();
},
- _activeConnectionChanged: function() {
- let activeConnection = this._device.active_connection;
-
- if (activeConnection == this._activeConnection)
- // nothing to do
- return;
-
- this._activeConnection = activeConnection;
+ _connectionValid: function(connection) {
+ return this._device.connection_valid(connection);
},
_getStatus: function() {
@@ -385,71 +428,10 @@ const NMDeviceModem = new Lang.Class({
}
},
- syncDescription: function() {
- if (this._device && this._device._description)
- this.statusItem.label.text = this._device._description;
- },
-
- _deviceStateChanged: function(device, newstate, oldstate, reason) {
- if (newstate == oldstate) {
- log('device emitted state-changed without actually changing state');
- return;
- }
-
- /* Emit a notification if activation fails, but don't do it
- if the reason is no secrets, as that indicates the user
- cancelled the agent dialog */
- if (newstate == NetworkManager.DeviceState.FAILED &&
- reason != NetworkManager.DeviceStateReason.NO_SECRETS) {
- this.emit('activation-failed', reason);
- }
-
- this._updateStatusItem();
- },
-
- _updateStatusItem: function() {
- this.statusItem.setStatus(this.getStatusLabel());
- this.statusItem.setToggleState(this.connected);
- },
-
- _substateChanged: function() {
- this.statusItem.setStatus(this.getStatusLabel());
- },
-
_getSignalIcon: function() {
return 'network-cellular-signal-' + signalToIcon(this._mobileDevice.signal_quality) + '-symbolic';
},
- _createSection: function() {
- if (!this._shouldShowConnectionList())
- return;
-
- if (this._mobileDevice) {
- // If operator_name is null, just pass the empty string, as the item is hidden anyway
- this._operatorItem = new PopupMenu.PopupMenuItem(this._mobileDevice.operator_name || '',
- { style_class: 'popup-status-menu-item' });
- if (!this._mobileDevice.operator_name)
- this._operatorItem.actor.hide();
- this.section.addMenuItem(this._operatorItem);
- }
-
- this.parent();
- },
-
- _clearSection: function() {
- this._operatorItem = null;
-
- this.parent();
- },
-
- _activateAutomaticConnection: function() {
- // Mobile wizard is too complex for the shell UI and
- // is handled by the network panel
- Util.spawn(['gnome-control-center', 'network',
- 'connect-3g', this._device.get_path()]);
- return true;
- },
-
getIndicatorIcon: function() {
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
return 'network-cellular-acquiring-symbolic';
@@ -540,6 +522,27 @@ const NMVPNSection = new Lang.Class({
Extends: NMConnectionSection,
category: NMConnectionCategory.VPN,
+ _init: function(client) {
+ this.parent(client);
+
+ this.syncDescription();
+ this._sync();
+ },
+
+ _sync: function() {
+ let nItems = this._connectionItems.size();
+ this.item.actor.visible = (nItems > 0);
+ this.parent();
+ },
+
+ _getDescription: function() {
+ return _("VPN");
+ },
+
+ _getMenuIcon: function() {
+ return this.parent() || 'network-vpn-symbolic';
+ },
+
addActiveConnection: function(activeConnection) {
let item = this._connectionItems.get(activeConnection._connection.get_uuid());
item.setActiveConnection(activeConnection);
@@ -627,7 +630,7 @@ const NMApplet = new Lang.Class({
this._vpnSection = new NMVPNSection(this._client);
this._vpnSection.connect('activation-failed', Lang.bind(this, this._onActivationFailed));
this._vpnSection.connect('icon-changed', Lang.bind(this, this._updateIcon));
- this._section.addMenuItem(this._vpnSection.section);
+ this._section.addMenuItem(this._vpnSection.item);
this._readDevices();
this._syncNMState();
@@ -723,8 +726,7 @@ const NMApplet = new Lang.Class({
Lang.bind(this, this._onActivationFailed));
let section = this._devices[wrapper.category].section;
- section.addMenuItem(wrapper.statusItem);
- section.addMenuItem(wrapper.section);
+ section.addMenuItem(wrapper.item);
let devices = this._devices[wrapper.category].devices;
devices.push(wrapper);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]