2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-01-25 16:08:12 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const GObject = imports.gi.GObject;
|
2012-08-26 09:49:18 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2011-01-25 16:08:12 -05:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const NetworkManager = imports.gi.NetworkManager;
|
|
|
|
const NMClient = imports.gi.NMClient;
|
2013-04-25 14:00:11 -04:00
|
|
|
const NMGtk = imports.gi.NMGtk;
|
2011-01-25 16:08:12 -05:00
|
|
|
const Signals = imports.signals;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
const Hash = imports.misc.hash;
|
2011-01-25 16:08:12 -05:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
2012-11-03 21:11:08 -04:00
|
|
|
const NotificationDaemon = imports.ui.notificationDaemon;
|
2011-01-25 16:08:12 -05:00
|
|
|
const ModemManager = imports.misc.modemManager;
|
|
|
|
const Util = imports.misc.util;
|
|
|
|
|
|
|
|
const NMConnectionCategory = {
|
2011-03-26 13:38:20 -04:00
|
|
|
INVALID: 'invalid',
|
2011-01-25 16:08:12 -05:00
|
|
|
WIRED: 'wired',
|
|
|
|
WIRELESS: 'wireless',
|
|
|
|
WWAN: 'wwan',
|
|
|
|
VPN: 'vpn'
|
|
|
|
};
|
|
|
|
|
|
|
|
const NMAccessPointSecurity = {
|
|
|
|
NONE: 1,
|
|
|
|
WEP: 2,
|
2011-05-03 13:21:45 -04:00
|
|
|
WPA_PSK: 3,
|
|
|
|
WPA2_PSK: 4,
|
|
|
|
WPA_ENT: 5,
|
|
|
|
WPA2_ENT: 6
|
2011-01-25 16:08:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// small optimization, to avoid using [] all the time
|
|
|
|
const NM80211Mode = NetworkManager['80211Mode'];
|
|
|
|
const NM80211ApFlags = NetworkManager['80211ApFlags'];
|
|
|
|
const NM80211ApSecurityFlags = NetworkManager['80211ApSecurityFlags'];
|
|
|
|
|
2011-04-06 12:11:23 -04:00
|
|
|
// number of wireless networks that should be visible
|
2012-12-03 10:59:28 -05:00
|
|
|
// (the remaining are placed into More…)
|
2011-04-06 12:11:23 -04:00
|
|
|
const NUM_VISIBLE_NETWORKS = 5;
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
function ssidCompare(one, two) {
|
|
|
|
if (!one || !two)
|
|
|
|
return false;
|
|
|
|
if (one.length != two.length)
|
|
|
|
return false;
|
|
|
|
for (let i = 0; i < one.length; i++) {
|
|
|
|
if (one[i] != two[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// shared between NMNetworkMenuItem and NMDeviceWWAN
|
|
|
|
function signalToIcon(value) {
|
|
|
|
if (value > 80)
|
|
|
|
return 'excellent';
|
|
|
|
if (value > 55)
|
|
|
|
return 'good';
|
|
|
|
if (value > 30)
|
|
|
|
return 'ok';
|
|
|
|
if (value > 5)
|
|
|
|
return 'weak';
|
|
|
|
return 'none';
|
|
|
|
}
|
|
|
|
|
2011-08-03 14:05:53 -04:00
|
|
|
function ssidToLabel(ssid) {
|
|
|
|
let label = NetworkManager.utils_ssid_to_utf8(ssid);
|
|
|
|
if (!label)
|
|
|
|
label = _("<unknown>");
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const NMNetworkMenuItem = new Lang.Class({
|
|
|
|
Name: 'NMNetworkMenuItem',
|
|
|
|
Extends: PopupMenu.PopupBaseMenuItem,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-26 12:12:29 -04:00
|
|
|
_init: function(bestAP) {
|
|
|
|
this.parent();
|
2011-03-25 11:27:56 -04:00
|
|
|
|
2012-05-29 14:02:48 -04:00
|
|
|
this.bestAP = bestAP;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-26 12:12:29 -04:00
|
|
|
let ssid = this.bestAP.get_ssid();
|
|
|
|
let title = ssidToLabel(ssid);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2011-03-25 11:27:56 -04:00
|
|
|
this._label = new St.Label({ text: title });
|
2012-01-05 13:00:06 -05:00
|
|
|
this.actor.label_actor = this._label;
|
2011-03-25 11:27:56 -04:00
|
|
|
this.addActor(this._label);
|
|
|
|
this._icons = new St.BoxLayout({ style_class: 'nm-menu-item-icons' });
|
|
|
|
this.addActor(this._icons, { align: St.Align.END });
|
|
|
|
|
|
|
|
this._signalIcon = new St.Icon({ icon_name: this._getIcon(),
|
|
|
|
style_class: 'popup-menu-icon' });
|
|
|
|
this._icons.add_actor(this._signalIcon);
|
|
|
|
|
2011-03-29 11:45:45 -04:00
|
|
|
this._secureIcon = new St.Icon({ style_class: 'popup-menu-icon' });
|
2013-04-25 16:38:05 -04:00
|
|
|
if (this.bestAP._secType != NMAccessPointSecurity.NONE)
|
2012-05-30 09:58:37 -04:00
|
|
|
this._secureIcon.icon_name = 'network-wireless-encrypted-symbolic';
|
2011-03-29 11:45:45 -04:00
|
|
|
this._icons.add_actor(this._secureIcon);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2012-05-29 14:02:48 -04:00
|
|
|
updateBestAP: function(ap) {
|
|
|
|
this.bestAP = ap;
|
2011-03-25 11:27:56 -04:00
|
|
|
this._signalIcon.icon_name = this._getIcon();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_getIcon: function() {
|
2011-04-07 17:21:08 -04:00
|
|
|
if (this.bestAP.mode == NM80211Mode.ADHOC)
|
2012-05-30 09:58:37 -04:00
|
|
|
return 'network-workgroup-symbolic';
|
2011-04-07 17:21:08 -04:00
|
|
|
else
|
2012-05-30 09:58:37 -04:00
|
|
|
return 'network-wireless-signal-' + signalToIcon(this.bestAP.strength) + '-symbolic';
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2011-11-20 08:10:48 -05:00
|
|
|
const NMWirelessSectionTitleMenuItem = new Lang.Class({
|
|
|
|
Name: 'NMWirelessSectionTitleMenuItem',
|
|
|
|
Extends: PopupMenu.PopupSwitchMenuItem,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-25 17:20:57 -04:00
|
|
|
_init: function(client) {
|
|
|
|
this.parent(_("Wi-Fi"), false, { style_class: 'popup-subtitle-menu-item' });
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
this._client = client;
|
2013-04-25 17:20:57 -04:00
|
|
|
this._client.connect('notify::wireless-enabled', Lang.bind(this, this._propertyChanged));
|
|
|
|
this._client.connect('notify::wireless-hardware-enabled', Lang.bind(this, this._propertyChanged));
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
this._propertyChanged();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateForDevice: function(device) {
|
|
|
|
// we show the switch
|
|
|
|
// - if there not just one device
|
2011-12-02 15:50:10 -05:00
|
|
|
// - if the switch is off (but it can be turned on)
|
2011-01-25 16:08:12 -05:00
|
|
|
// - if the device is activated or disconnected
|
2011-12-02 15:50:10 -05:00
|
|
|
if (!this._hardwareEnabled) {
|
|
|
|
this.setStatus(_("hardware disabled"));
|
|
|
|
} else if (device && this._softwareEnabled) {
|
2011-01-25 16:08:12 -05:00
|
|
|
let text = device.getStatusLabel();
|
|
|
|
this.setStatus(text);
|
|
|
|
} else
|
|
|
|
this.setStatus(null);
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: function(event) {
|
2011-11-20 08:10:48 -05:00
|
|
|
this.parent(event);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-25 17:20:57 -04:00
|
|
|
this._client.wireless_set_enabled(this._switch.state);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_propertyChanged: function() {
|
2013-04-25 17:20:57 -04:00
|
|
|
this._softwareEnabled = this._client.wireless_enabled;
|
|
|
|
this._hardwareEnabled = this._client.wireless_hardware_enabled;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
let enabled = this._softwareEnabled && this._hardwareEnabled;
|
|
|
|
this.setToggleState(enabled);
|
|
|
|
if (!this._hardwareEnabled)
|
|
|
|
/* Translators: this indicates that wireless or wwan is disabled by hardware killswitch */
|
|
|
|
this.setStatus(_("disabled"));
|
|
|
|
|
|
|
|
this.emit('enabled-changed', enabled);
|
|
|
|
}
|
2011-11-20 08:10:48 -05:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-26 19:28:48 -04:00
|
|
|
const NMDevice = new Lang.Class({
|
|
|
|
Name: 'NMDevice',
|
2011-11-20 11:07:14 -05:00
|
|
|
Abstract: true,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-26 19:28:48 -04:00
|
|
|
_init: function(client, device, connections) {
|
|
|
|
this._client = client;
|
|
|
|
this._setDevice(device);
|
|
|
|
|
|
|
|
this._connections = [];
|
2013-04-26 18:47:22 -04:00
|
|
|
connections.forEach(Lang.bind(this, this.checkConnection));
|
2013-04-26 19:28:48 -04:00
|
|
|
|
|
|
|
this._activeConnection = null;
|
|
|
|
this._activeConnectionItem = null;
|
|
|
|
this._overflowItem = null;
|
|
|
|
|
|
|
|
this.statusItem = new PopupMenu.PopupSwitchMenuItem('', this.connected, { style_class: 'popup-subtitle-menu-item' });
|
|
|
|
this._statusChanged = this.statusItem.connect('toggled', Lang.bind(this, function(item, state) {
|
|
|
|
let ok;
|
|
|
|
if (state)
|
|
|
|
ok = this.activate();
|
|
|
|
else
|
|
|
|
ok = this.deactivate();
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
item.setToggleState(!state);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._updateStatusItem();
|
|
|
|
this.section = new PopupMenu.PopupMenuSection();
|
|
|
|
|
|
|
|
this._deferredWorkId = Main.initializeDeferredWork(this.section.actor, Lang.bind(this, this._createSection));
|
2012-08-29 10:22:24 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
checkConnection: function(connection) {
|
|
|
|
let pos = this._findConnection(connection.get_uuid());
|
|
|
|
let exists = pos != -1;
|
|
|
|
let valid = this.connectionValid(connection);
|
|
|
|
let similar = false;
|
|
|
|
if (exists) {
|
|
|
|
let existing = this._connections[pos];
|
|
|
|
|
|
|
|
// Check if connection changed name or id
|
|
|
|
similar = existing.name == connection.get_id() &&
|
|
|
|
existing.timestamp == connection._timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exists && valid && similar) {
|
|
|
|
// Nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exists)
|
|
|
|
this.removeConnection(connection);
|
|
|
|
if (valid)
|
|
|
|
this.addConnection(connection);
|
|
|
|
},
|
|
|
|
|
|
|
|
addConnection: function(connection) {
|
|
|
|
// record the connection
|
|
|
|
let obj = {
|
|
|
|
connection: connection,
|
|
|
|
name: connection.get_id(),
|
|
|
|
uuid: connection.get_uuid(),
|
|
|
|
timestamp: connection._timestamp,
|
|
|
|
item: null,
|
|
|
|
};
|
|
|
|
Util.insertSorted(this._connections, obj, this._connectionSortFunction);
|
|
|
|
|
|
|
|
this._queueCreateSection();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeConnection: function(connection) {
|
|
|
|
let pos = this._findConnection(connection.get_uuid());
|
|
|
|
if (pos == -1) {
|
|
|
|
// this connection was never added, nothing to do here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let obj = this._connections[pos];
|
|
|
|
if (obj.item)
|
|
|
|
obj.item.destroy();
|
|
|
|
this._connections.splice(pos, 1);
|
|
|
|
|
|
|
|
if (this._connections.length <= 1) {
|
|
|
|
// We need to show the automatic connection again
|
|
|
|
// (or in the case of NMDeviceWired, we want to hide
|
|
|
|
// the only explicit connection)
|
|
|
|
this._queueCreateSection();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_findConnection: function(uuid) {
|
|
|
|
for (let i = 0; i < this._connections.length; i++) {
|
|
|
|
let obj = this._connections[i];
|
|
|
|
if (obj.uuid == uuid)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
_connectionSortFunction: function(one, two) {
|
|
|
|
if (one.timestamp == two.timestamp)
|
|
|
|
return GLib.utf8_collate(one.name, two.name);
|
|
|
|
|
|
|
|
return two.timestamp - one.timestamp;
|
|
|
|
},
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
destroy: function() {
|
2012-12-04 08:49:34 -05:00
|
|
|
this._setDevice(null);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-10-03 17:38:35 -04:00
|
|
|
if (this._deferredWorkId) {
|
|
|
|
// Just clear out, the actual removal is handled when the
|
|
|
|
// actor is destroyed
|
|
|
|
this._deferredWorkId = 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
this._clearSection();
|
2011-03-31 17:23:29 -04:00
|
|
|
if (this.statusItem)
|
|
|
|
this.statusItem.destroy();
|
2011-01-25 16:08:12 -05:00
|
|
|
this.section.destroy();
|
|
|
|
},
|
|
|
|
|
2012-12-04 08:49:34 -05:00
|
|
|
_setDevice: function(device) {
|
|
|
|
if (device) {
|
2013-06-11 19:56:17 -04:00
|
|
|
this._device = device;
|
|
|
|
this._device._delegate = this;
|
|
|
|
this._stateChangedId = this._device.connect('state-changed', Lang.bind(this, this._deviceStateChanged));
|
|
|
|
this._activeConnectionChangedId = this._device.connect('notify::active-connection', Lang.bind(this, this._activeConnectionChanged));
|
|
|
|
} else if (this._device) {
|
|
|
|
this._device._delegate = null;
|
2012-12-04 08:49:34 -05:00
|
|
|
|
|
|
|
if (this._stateChangedId) {
|
|
|
|
// Need to go through GObject.Object.prototype because
|
|
|
|
// nm_device_disconnect conflicts with g_signal_disconnect
|
2013-06-11 19:56:17 -04:00
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._stateChangedId);
|
2012-12-04 08:49:34 -05:00
|
|
|
this._stateChangedId = 0;
|
|
|
|
}
|
2013-04-26 21:44:59 -04:00
|
|
|
if (this._activeConnectionChangedId) {
|
2013-06-11 19:56:17 -04:00
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._activeConnectionChangedId);
|
2013-04-26 21:44:59 -04:00
|
|
|
this._stateChangedId = 0;
|
|
|
|
}
|
2012-12-04 08:49:34 -05:00
|
|
|
if (this._firmwareChangedId) {
|
2013-06-11 19:56:17 -04:00
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._firmwareChangedId);
|
2012-12-04 08:49:34 -05:00
|
|
|
this._firmwareChangedId = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-11 19:56:17 -04:00
|
|
|
this._device = null;
|
2012-12-04 08:49:34 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
deactivate: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
this._device.disconnect(null);
|
2012-08-31 15:43:30 -04:00
|
|
|
return true;
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
activate: function() {
|
|
|
|
if (this._activeConnection)
|
|
|
|
// nothing to do
|
2012-08-31 15:43:30 -04:00
|
|
|
return true;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-08-31 15:43:30 -04:00
|
|
|
// 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) {
|
2013-06-11 19:56:17 -04:00
|
|
|
this._client.activate_connection(this._connections[0].connection, this._device || null, null, null);
|
2012-08-31 15:43:30 -04:00
|
|
|
return true;
|
|
|
|
} else if (this._connections.length == 0) {
|
|
|
|
return this._activateAutomaticConnection();
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2012-08-31 15:43:30 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_activateAutomaticConnection: function() {
|
2013-04-25 16:48:27 -04:00
|
|
|
let connection = new NetworkManager.Connection();
|
2013-06-11 19:56:17 -04:00
|
|
|
this._client.add_and_activate_connection(connection, this._device, null, null);
|
2013-04-25 16:48:27 -04:00
|
|
|
return true;
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
get connected() {
|
2013-06-11 19:56:17 -04:00
|
|
|
return this._device && this._device.state == NetworkManager.DeviceState.ACTIVATED;
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2013-04-26 21:44:59 -04:00
|
|
|
_activeConnectionChanged: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
let activeConnection = this._device.active_connection;
|
2012-08-29 10:22:24 -04:00
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
if (activeConnection == this._activeConnection)
|
|
|
|
// nothing to do
|
|
|
|
return;
|
|
|
|
|
|
|
|
// remove any UI
|
|
|
|
if (this._activeConnectionItem) {
|
|
|
|
this._activeConnectionItem.destroy();
|
|
|
|
this._activeConnectionItem = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._activeConnection = activeConnection;
|
|
|
|
|
2011-11-15 12:22:24 -05:00
|
|
|
this._queueCreateSection();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
connectionValid: function(connection) {
|
2013-06-11 19:56:17 -04:00
|
|
|
return this._device.connection_valid(connection);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setEnabled: function(enabled) {
|
|
|
|
// do nothing by default, we want to keep the conneciton list visible
|
2012-08-29 10:22:24 -04:00
|
|
|
// in the majority of cases (wired, wwan)
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2013-06-11 21:06:58 -04:00
|
|
|
_firmwareChanged: function() {
|
|
|
|
if (this._firmwareChangedId) {
|
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._firmwareChangedId);
|
|
|
|
this._firmwareChangedId = 0;
|
|
|
|
}
|
|
|
|
this._substateChanged();
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
getStatusLabel: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
if (!this._device)
|
2012-12-04 08:49:34 -05:00
|
|
|
return null;
|
|
|
|
|
2013-06-11 19:56:17 -04:00
|
|
|
switch(this._device.state) {
|
2011-01-25 16:08:12 -05:00
|
|
|
case NetworkManager.DeviceState.DISCONNECTED:
|
|
|
|
case NetworkManager.DeviceState.ACTIVATED:
|
|
|
|
return null;
|
2011-05-09 10:15:03 -04:00
|
|
|
case NetworkManager.DeviceState.UNMANAGED:
|
|
|
|
/* Translators: this is for network devices that are physically present but are not
|
|
|
|
under NetworkManager's control (and thus cannot be used in the menu) */
|
|
|
|
return _("unmanaged");
|
|
|
|
case NetworkManager.DeviceState.DEACTIVATING:
|
|
|
|
return _("disconnecting...");
|
2011-01-25 16:08:12 -05:00
|
|
|
case NetworkManager.DeviceState.PREPARE:
|
|
|
|
case NetworkManager.DeviceState.CONFIG:
|
|
|
|
case NetworkManager.DeviceState.IP_CONFIG:
|
2011-04-19 09:31:54 -04:00
|
|
|
case NetworkManager.DeviceState.IP_CHECK:
|
|
|
|
case NetworkManager.DeviceState.SECONDARIES:
|
2011-01-25 16:08:12 -05:00
|
|
|
return _("connecting...");
|
|
|
|
case NetworkManager.DeviceState.NEED_AUTH:
|
|
|
|
/* Translators: this is for network connections that require some kind of key or password */
|
|
|
|
return _("authentication required");
|
|
|
|
case NetworkManager.DeviceState.UNAVAILABLE:
|
2011-03-25 12:10:38 -04:00
|
|
|
// This state is actually a compound of various states (generically unavailable,
|
2013-06-12 14:38:20 -04:00
|
|
|
// firmware missing), that are exposed by different properties (whose state may
|
|
|
|
// or may not updated when we receive state-changed).
|
2013-06-11 19:56:17 -04:00
|
|
|
if (this._device.firmware_missing) {
|
2013-06-11 21:06:58 -04:00
|
|
|
if (!this._firmwareChangedId)
|
|
|
|
this._firmwareChangedId = this._device.connect('notify::firmware-missing', Lang.bind(this, this._firmwareChanged));
|
|
|
|
|
2011-03-25 12:10:38 -04:00
|
|
|
/* Translators: this is for devices that require some kind of firmware or kernel
|
|
|
|
module, which is missing */
|
|
|
|
return _("firmware missing");
|
|
|
|
}
|
|
|
|
/* Translators: this is for a network device that cannot be activated (for example it
|
|
|
|
is disabled by rfkill, or it has no coverage */
|
|
|
|
return _("unavailable");
|
2011-01-25 16:08:12 -05:00
|
|
|
case NetworkManager.DeviceState.FAILED:
|
|
|
|
return _("connection failed");
|
|
|
|
default:
|
2013-06-11 19:56:17 -04:00
|
|
|
log('Device state invalid, is %d'.format(this._device.state));
|
2011-01-25 16:08:12 -05:00
|
|
|
return 'invalid';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-29 13:42:11 -04:00
|
|
|
syncDescription: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
if (this._device && this._device._description)
|
|
|
|
this.statusItem.label.text = this._device._description;
|
2012-08-29 13:42:11 -04:00
|
|
|
},
|
|
|
|
|
2011-11-15 12:22:24 -05:00
|
|
|
_queueCreateSection: function() {
|
2012-10-03 17:38:35 -04:00
|
|
|
if (this._deferredWorkId) {
|
|
|
|
this._clearSection();
|
|
|
|
Main.queueDeferredWork(this._deferredWorkId);
|
|
|
|
}
|
2011-11-15 12:22:24 -05:00
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_clearSection: function() {
|
|
|
|
// Clear everything
|
|
|
|
this.section.removeAll();
|
|
|
|
this._activeConnectionItem = null;
|
2011-06-02 10:22:36 -04:00
|
|
|
this._overflowItem = null;
|
2011-01-25 16:08:12 -05:00
|
|
|
for (let i = 0; i < this._connections.length; i++) {
|
|
|
|
this._connections[i].item = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_shouldShowConnectionList: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
return (this._device.state >= NetworkManager.DeviceState.DISCONNECTED);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_createSection: function() {
|
|
|
|
if (!this._shouldShowConnectionList())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._activeConnection) {
|
|
|
|
this._createActiveConnectionItem();
|
|
|
|
this.section.addMenuItem(this._activeConnectionItem);
|
|
|
|
}
|
|
|
|
if (this._connections.length > 0) {
|
2011-06-02 10:22:36 -04:00
|
|
|
let activeOffset = this._activeConnectionItem ? 1 : 0;
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
for(let j = 0; j < this._connections.length; ++j) {
|
|
|
|
let obj = this._connections[j];
|
|
|
|
if (this._activeConnection &&
|
|
|
|
obj.connection == this._activeConnection._connection)
|
|
|
|
continue;
|
|
|
|
obj.item = this._createConnectionItem(obj);
|
2011-06-02 10:22:36 -04:00
|
|
|
|
|
|
|
if (j + activeOffset >= NUM_VISIBLE_NETWORKS) {
|
|
|
|
if (!this._overflowItem) {
|
2012-12-03 10:59:28 -05:00
|
|
|
this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More…"));
|
2011-06-02 10:22:36 -04:00
|
|
|
this.section.addMenuItem(this._overflowItem);
|
|
|
|
}
|
|
|
|
this._overflowItem.menu.addMenuItem(obj.item);
|
|
|
|
} else
|
|
|
|
this.section.addMenuItem(obj.item);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_createConnectionItem: function(obj) {
|
2011-03-25 09:36:59 -04:00
|
|
|
let connection = obj.connection;
|
2011-01-25 16:08:12 -05:00
|
|
|
let item = new PopupMenu.PopupMenuItem(obj.name);
|
2011-03-25 09:36:59 -04:00
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
item.connect('activate', Lang.bind(this, function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
this._client.activate_connection(connection, this._device, null, null);
|
2011-01-25 16:08:12 -05:00
|
|
|
}));
|
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
|
|
|
_createActiveConnectionItem: function() {
|
|
|
|
let title;
|
|
|
|
let active = this._activeConnection._connection;
|
|
|
|
if (active) {
|
2012-06-05 17:32:52 -04:00
|
|
|
title = active.get_id();
|
2011-01-25 16:08:12 -05:00
|
|
|
} else {
|
|
|
|
/* TRANSLATORS: this is the indication that a connection for another logged in user is active,
|
|
|
|
and we cannot access its settings (including the name) */
|
|
|
|
title = _("Connected (private)");
|
|
|
|
}
|
|
|
|
this._activeConnectionItem = new PopupMenu.PopupMenuItem(title, { reactive: false });
|
2013-04-19 20:57:38 -04:00
|
|
|
this._activeConnectionItem.setOrnament(PopupMenu.Ornament.DOT);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_deviceStateChanged: function(device, newstate, oldstate, reason) {
|
|
|
|
if (newstate == oldstate) {
|
|
|
|
log('device emitted state-changed without actually changing state');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-02 15:02:59 -04:00
|
|
|
/* 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) {
|
2011-01-25 16:08:12 -05:00
|
|
|
this.emit('activation-failed', reason);
|
|
|
|
}
|
|
|
|
|
2011-03-31 17:23:29 -04:00
|
|
|
this._updateStatusItem();
|
|
|
|
|
2011-11-15 12:22:24 -05:00
|
|
|
this._queueCreateSection();
|
2011-03-31 17:23:29 -04:00
|
|
|
this.emit('state-changed');
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateStatusItem: function() {
|
2011-01-25 16:08:12 -05:00
|
|
|
this.statusItem.setStatus(this.getStatusLabel());
|
|
|
|
this.statusItem.setToggleState(this.connected);
|
|
|
|
},
|
|
|
|
|
2011-03-25 12:10:38 -04:00
|
|
|
_substateChanged: function() {
|
|
|
|
this.statusItem.setStatus(this.getStatusLabel());
|
|
|
|
|
|
|
|
this.emit('state-changed');
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2013-04-26 19:28:48 -04:00
|
|
|
Signals.addSignalMethods(NMDevice.prototype);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-11-16 11:29:07 -05:00
|
|
|
const NMDeviceSimple = new Lang.Class({
|
|
|
|
Name: 'NMDeviceSimple',
|
2011-11-20 11:07:14 -05:00
|
|
|
Extends: NMDevice,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
_init: function(client, device, connections) {
|
|
|
|
this.category = NMConnectionCategory.WIRED;
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(client, device, connections);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2011-03-25 12:12:38 -04:00
|
|
|
_createSection: function() {
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-03-25 12:12:38 -04:00
|
|
|
|
|
|
|
// if we have only one connection (normal or automatic)
|
|
|
|
// we hide the connection list, and use the switch to control
|
|
|
|
// the device
|
|
|
|
// we can do it here because addConnection and removeConnection
|
|
|
|
// both call _createSection at some point
|
2012-05-02 16:29:51 -04:00
|
|
|
this.section.actor.visible = this._connections.length > 1;
|
2012-11-16 11:29:07 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const NMDeviceWired = new Lang.Class({
|
|
|
|
Name: 'NMDeviceWired',
|
|
|
|
Extends: NMDeviceSimple,
|
|
|
|
|
|
|
|
_init: function(client, device, connections) {
|
2013-01-14 10:20:59 -05:00
|
|
|
device._description = _("Wired");
|
2012-11-16 11:29:07 -05:00
|
|
|
this.category = NMConnectionCategory.WIRED;
|
|
|
|
|
|
|
|
this.parent(client, device, connections);
|
2011-03-25 12:12:38 -04:00
|
|
|
},
|
2013-04-29 15:20:45 -04:00
|
|
|
|
|
|
|
getIndicatorIcon: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
|
2013-04-29 15:20:45 -04:00
|
|
|
return 'network-wired-acquiring-symbolic';
|
|
|
|
else
|
|
|
|
return 'network-wired-symbolic';
|
|
|
|
},
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const NMDeviceModem = new Lang.Class({
|
|
|
|
Name: 'NMDeviceModem',
|
|
|
|
Extends: NMDevice,
|
2013-06-12 15:27:09 -04:00
|
|
|
category: NMConnectionCategory.WWAN,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
_init: function(client, device, connections) {
|
2013-01-14 10:20:59 -05:00
|
|
|
device._description = _("Mobile broadband");
|
2011-01-25 16:08:12 -05:00
|
|
|
this._enabled = true;
|
|
|
|
this.mobileDevice = null;
|
|
|
|
|
|
|
|
this._capabilities = device.current_capabilities;
|
2013-02-05 04:01:53 -05:00
|
|
|
// Support new ModemManager1 devices
|
|
|
|
if (device.udi.indexOf('/org/freedesktop/ModemManager1/Modem') == 0) {
|
|
|
|
this.mobileDevice = new ModemManager.BroadbandModem(device.udi, device.current_capabilities);
|
|
|
|
} else if (this._capabilities & NetworkManager.DeviceModemCapabilities.GSM_UMTS) {
|
2011-01-25 16:08:12 -05:00
|
|
|
this.mobileDevice = new ModemManager.ModemGsm(device.udi);
|
|
|
|
} else if (this._capabilities & NetworkManager.DeviceModemCapabilities.CDMA_EVDO) {
|
|
|
|
this.mobileDevice = new ModemManager.ModemCdma(device.udi);
|
|
|
|
} else if (this._capabilities & NetworkManager.DeviceModemCapabilities.LTE) {
|
2013-02-05 04:05:50 -05:00
|
|
|
this.mobileDevice = new ModemManager.ModemGsm(device.udi);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mobileDevice) {
|
|
|
|
this._operatorNameId = this.mobileDevice.connect('notify::operator-name', Lang.bind(this, function() {
|
|
|
|
if (this._operatorItem) {
|
|
|
|
let name = this.mobileDevice.operator_name;
|
|
|
|
if (name) {
|
|
|
|
this._operatorItem.label.text = name;
|
|
|
|
this._operatorItem.actor.show();
|
|
|
|
} else
|
|
|
|
this._operatorItem.actor.hide();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
this._signalQualityId = this.mobileDevice.connect('notify::signal-quality', Lang.bind(this, function() {
|
|
|
|
if (this._operatorItem) {
|
|
|
|
this._operatorItem.setIcon(this._getSignalIcon());
|
|
|
|
}
|
2013-04-29 15:20:45 -04:00
|
|
|
this.emit('icon-changed');
|
2011-01-25 16:08:12 -05:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(client, device, connections);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setEnabled: function(enabled) {
|
|
|
|
this._enabled = enabled;
|
|
|
|
if (this.category == NMConnectionCategory.WWAN) {
|
|
|
|
if (enabled) {
|
|
|
|
// prevent "network unavailable" statuses
|
|
|
|
this.statusItem.setStatus(null);
|
|
|
|
} else
|
|
|
|
this.statusItem.setStatus(this.getStatusLabel());
|
|
|
|
}
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(enabled);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
get connected() {
|
2013-06-11 19:56:17 -04:00
|
|
|
return this._enabled && this._device.state == NetworkManager.DeviceState.ACTIVATED;
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
if (this._operatorNameId) {
|
|
|
|
this.mobileDevice.disconnect(this._operatorNameId);
|
|
|
|
this._operatorNameId = 0;
|
|
|
|
}
|
|
|
|
if (this._signalQualityId) {
|
|
|
|
this.mobileDevice.disconnect(this._signalQualityId);
|
|
|
|
this._signalQualityId = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_getSignalIcon: function() {
|
2012-05-30 09:58:37 -04:00
|
|
|
return 'network-cellular-signal-' + signalToIcon(this.mobileDevice.signal_quality) + '-symbolic';
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_createSection: function() {
|
2011-04-02 16:27:20 -04:00
|
|
|
if (!this._shouldShowConnectionList())
|
|
|
|
return;
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
if (this.mobileDevice) {
|
|
|
|
// If operator_name is null, just pass the empty string, as the item is hidden anyway
|
|
|
|
this._operatorItem = new PopupMenu.PopupImageMenuItem(this.mobileDevice.operator_name || '',
|
|
|
|
this._getSignalIcon(),
|
|
|
|
{ reactive: false });
|
2011-04-02 16:27:20 -04:00
|
|
|
if (!this.mobileDevice.operator_name)
|
2011-01-25 16:08:12 -05:00
|
|
|
this._operatorItem.actor.hide();
|
|
|
|
this.section.addMenuItem(this._operatorItem);
|
|
|
|
}
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2011-04-02 16:27:20 -04:00
|
|
|
_clearSection: function() {
|
2011-01-25 16:08:12 -05:00
|
|
|
this._operatorItem = null;
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2012-08-31 15:43:30 -04:00
|
|
|
_activateAutomaticConnection: function() {
|
2011-08-22 12:21:31 -04:00
|
|
|
// Mobile wizard is too complex for the shell UI and
|
|
|
|
// is handled by the network panel
|
|
|
|
Util.spawn(['gnome-control-center', 'network',
|
2013-06-11 19:56:17 -04:00
|
|
|
'connect-3g', this._device.get_path()]);
|
2012-08-31 15:43:30 -04:00
|
|
|
return true;
|
|
|
|
},
|
2013-04-29 15:20:45 -04:00
|
|
|
|
|
|
|
getIndicatorIcon: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
|
2013-04-29 15:20:45 -04:00
|
|
|
return 'network-cellular-acquiring-symbolic';
|
|
|
|
|
|
|
|
if (!this.mobileDevice) {
|
|
|
|
// this can happen for bluetooth in PAN mode
|
|
|
|
return 'network-cellular-connected-symbolic';
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._getSignalIcon();
|
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const NMDeviceBluetooth = new Lang.Class({
|
|
|
|
Name: 'NMDeviceBluetooth',
|
|
|
|
Extends: NMDevice,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
_init: function(client, device, connections) {
|
2013-01-14 10:20:59 -05:00
|
|
|
device._description = _("Bluetooth");
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
this.category = NMConnectionCategory.WWAN;
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(client, device, connections);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2012-08-31 15:43:30 -04:00
|
|
|
_activateAutomaticConnection: function() {
|
|
|
|
// FIXME: DUN devices are configured like modems, so
|
2013-04-25 16:48:27 -04:00
|
|
|
// We need to spawn the mobile wizard
|
2012-08-31 15:43:30 -04:00
|
|
|
// but the network panel doesn't support bluetooth at the moment
|
|
|
|
// so we just create an empty connection and hope
|
|
|
|
// that this phone supports PAN
|
|
|
|
|
|
|
|
return this.parent();
|
2013-04-29 15:20:45 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getIndicatorIcon: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
|
2013-04-29 15:20:45 -04:00
|
|
|
return 'network-wired-acquiring-symbolic';
|
|
|
|
else
|
|
|
|
return 'network-wired-symbolic';
|
|
|
|
},
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const NMDeviceWireless = new Lang.Class({
|
|
|
|
Name: 'NMDeviceWireless',
|
|
|
|
Extends: NMDevice,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
_init: function(client, device, connections) {
|
|
|
|
this.category = NMConnectionCategory.WIRELESS;
|
|
|
|
|
|
|
|
this._overflowItem = null;
|
|
|
|
this._networks = [ ];
|
|
|
|
|
2013-04-29 12:28:02 -04:00
|
|
|
this.parent(client, device, connections);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
let accessPoints = device.get_access_points() || [ ];
|
2013-04-29 12:28:02 -04:00
|
|
|
accessPoints.forEach(Lang.bind(this, function(ap) {
|
2013-06-11 19:56:17 -04:00
|
|
|
this._accessPointAdded(this._device, ap);
|
2013-04-29 12:28:02 -04:00
|
|
|
}));
|
2012-05-29 14:02:48 -04:00
|
|
|
|
2013-04-25 21:04:32 -04:00
|
|
|
this._activeApChanged();
|
2011-04-06 12:11:23 -04:00
|
|
|
this._networks.sort(this._networkSortFunction);
|
|
|
|
|
|
|
|
this._apChangedId = device.connect('notify::active-access-point', Lang.bind(this, this._activeApChanged));
|
2011-01-25 16:08:12 -05:00
|
|
|
this._apAddedId = device.connect('access-point-added', Lang.bind(this, this._accessPointAdded));
|
|
|
|
this._apRemovedId = device.connect('access-point-removed', Lang.bind(this, this._accessPointRemoved));
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2011-04-06 12:11:23 -04:00
|
|
|
if (this._apChangedId) {
|
2011-01-25 16:08:12 -05:00
|
|
|
// see above for this HACK
|
2013-06-11 19:56:17 -04:00
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._apChangedId);
|
2011-04-06 12:11:23 -04:00
|
|
|
this._apChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._apAddedId) {
|
2013-06-11 19:56:17 -04:00
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._apAddedId);
|
2011-01-25 16:08:12 -05:00
|
|
|
this._apAddedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._apRemovedId) {
|
2013-06-11 19:56:17 -04:00
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._apRemovedId);
|
2011-01-25 16:08:12 -05:00
|
|
|
this._apRemovedId = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setEnabled: function(enabled) {
|
2012-03-16 18:53:14 -04:00
|
|
|
this.statusItem.actor.visible = enabled;
|
|
|
|
this.section.actor.visible = enabled;
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
activate: function() {
|
|
|
|
if (this._activeConnection)
|
|
|
|
// nothing to do
|
2012-08-31 15:43:30 -04:00
|
|
|
return true;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-08-31 15:43:30 -04:00
|
|
|
// All possible policy we can have here is just broken
|
|
|
|
// NM autoconnects when wifi devices are enabled, and if it
|
|
|
|
// didn't, there is a good reason
|
|
|
|
// User, pick a connection from the list, thank you
|
|
|
|
return false;
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2011-06-02 11:42:26 -04:00
|
|
|
_notifySsidCb: function(accessPoint) {
|
|
|
|
if (accessPoint.get_ssid() != null) {
|
|
|
|
accessPoint.disconnect(accessPoint._notifySsidId);
|
|
|
|
accessPoint._notifySsidId = 0;
|
2013-06-11 19:56:17 -04:00
|
|
|
this._accessPointAdded(this._device, accessPoint);
|
2011-06-02 11:42:26 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-04-06 12:11:23 -04:00
|
|
|
_activeApChanged: function() {
|
|
|
|
this._activeNetwork = null;
|
|
|
|
|
2013-06-11 19:56:17 -04:00
|
|
|
let activeAp = this._device.active_access_point;
|
2011-04-06 12:11:23 -04:00
|
|
|
|
|
|
|
if (activeAp) {
|
2011-10-14 10:46:52 -04:00
|
|
|
let res = this._findExistingNetwork(activeAp);
|
2011-06-02 11:42:26 -04:00
|
|
|
|
2011-10-14 10:46:52 -04:00
|
|
|
if (res != null)
|
|
|
|
this._activeNetwork = this._networks[res.network];
|
2011-04-06 12:11:23 -04:00
|
|
|
}
|
|
|
|
|
2013-04-26 21:44:59 -04:00
|
|
|
// we don't refresh the view here, _activeConnectionChanged will
|
2011-04-06 12:11:23 -04:00
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_getApSecurityType: function(accessPoint) {
|
|
|
|
if (accessPoint._secType)
|
|
|
|
return accessPoint._secType;
|
|
|
|
|
|
|
|
let flags = accessPoint.flags;
|
|
|
|
let wpa_flags = accessPoint.wpa_flags;
|
|
|
|
let rsn_flags = accessPoint.rsn_flags;
|
|
|
|
let type;
|
2011-05-03 13:21:45 -04:00
|
|
|
if (rsn_flags != NM80211ApSecurityFlags.NONE) {
|
|
|
|
/* RSN check first so that WPA+WPA2 APs are treated as RSN/WPA2 */
|
|
|
|
if (rsn_flags & NM80211ApSecurityFlags.KEY_MGMT_802_1X)
|
|
|
|
type = NMAccessPointSecurity.WPA2_ENT;
|
|
|
|
else if (rsn_flags & NM80211ApSecurityFlags.KEY_MGMT_PSK)
|
|
|
|
type = NMAccessPointSecurity.WPA2_PSK;
|
|
|
|
} else if (wpa_flags != NM80211ApSecurityFlags.NONE) {
|
|
|
|
if (wpa_flags & NM80211ApSecurityFlags.KEY_MGMT_802_1X)
|
|
|
|
type = NMAccessPointSecurity.WPA_ENT;
|
|
|
|
else if (wpa_flags & NM80211ApSecurityFlags.KEY_MGMT_PSK)
|
|
|
|
type = NMAccessPointSecurity.WPA_PSK;
|
|
|
|
} else {
|
|
|
|
if (flags & NM80211ApFlags.PRIVACY)
|
|
|
|
type = NMAccessPointSecurity.WEP;
|
|
|
|
else
|
|
|
|
type = NMAccessPointSecurity.NONE;
|
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
// cache the found value to avoid checking flags all the time
|
|
|
|
accessPoint._secType = type;
|
|
|
|
return type;
|
|
|
|
},
|
|
|
|
|
2011-04-06 12:11:23 -04:00
|
|
|
_networkSortFunction: function(one, two) {
|
|
|
|
let oneHasConnection = one.connections.length != 0;
|
|
|
|
let twoHasConnection = two.connections.length != 0;
|
|
|
|
|
|
|
|
// place known connections first
|
|
|
|
// (-1 = good order, 1 = wrong order)
|
|
|
|
if (oneHasConnection && !twoHasConnection)
|
|
|
|
return -1;
|
|
|
|
else if (!oneHasConnection && twoHasConnection)
|
|
|
|
return 1;
|
|
|
|
|
2012-05-29 14:02:48 -04:00
|
|
|
let oneStrength = one.accessPoints[0].strength;
|
|
|
|
let twoStrength = two.accessPoints[0].strength;
|
|
|
|
|
|
|
|
// place stronger connections first
|
|
|
|
if (oneStrength != twoStrength)
|
|
|
|
return oneStrength < twoStrength ? 1 : -1;
|
|
|
|
|
2011-04-06 12:11:23 -04:00
|
|
|
let oneHasSecurity = one.security != NMAccessPointSecurity.NONE;
|
|
|
|
let twoHasSecurity = two.security != NMAccessPointSecurity.NONE;
|
|
|
|
|
|
|
|
// place secure connections first
|
|
|
|
// (we treat WEP/WPA/WPA2 the same as there is no way to
|
|
|
|
// take them apart from the UI)
|
|
|
|
if (oneHasSecurity && !twoHasSecurity)
|
|
|
|
return -1;
|
|
|
|
else if (!oneHasSecurity && twoHasSecurity)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// sort alphabetically
|
|
|
|
return GLib.utf8_collate(one.ssidText, two.ssidText);
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_networkCompare: function(network, accessPoint) {
|
|
|
|
if (!ssidCompare(network.ssid, accessPoint.get_ssid()))
|
|
|
|
return false;
|
|
|
|
if (network.mode != accessPoint.mode)
|
|
|
|
return false;
|
|
|
|
if (network.security != this._getApSecurityType(accessPoint))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2011-10-14 10:46:52 -04:00
|
|
|
_findExistingNetwork: function(accessPoint) {
|
|
|
|
for (let i = 0; i < this._networks.length; i++) {
|
2013-04-25 21:18:20 -04:00
|
|
|
let network = this._networks[i];
|
|
|
|
for (let j = 0; j < network.accessPoints.length; j++) {
|
|
|
|
if (network.accessPoints[j] == accessPoint)
|
2011-10-14 10:46:52 -04:00
|
|
|
return { network: i, ap: j };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_findNetwork: function(accessPoint) {
|
2011-06-02 11:42:26 -04:00
|
|
|
if (accessPoint.get_ssid() == null)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
for (let i = 0; i < this._networks.length; i++) {
|
|
|
|
if (this._networkCompare(this._networks[i], accessPoint))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2012-05-29 14:02:48 -04:00
|
|
|
_onApStrengthChanged: function(ap) {
|
|
|
|
let res = this._findExistingNetwork(ap);
|
|
|
|
if (res == null) {
|
|
|
|
// Uhm... stale signal?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let network = this._networks[res.network];
|
|
|
|
network.accessPoints.splice(res.ap, 1);
|
|
|
|
Util.insertSorted(network.accessPoints, ap, function(one, two) {
|
|
|
|
return two.strength - one.strength;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._networks.splice(res.network, 1);
|
|
|
|
let newPos = Util.insertSorted(this._networks, network, Lang.bind(this, this._networkSortFunction));
|
|
|
|
|
2012-10-03 17:40:48 -04:00
|
|
|
if (newPos != res.network)
|
2012-05-29 14:02:48 -04:00
|
|
|
this._queueCreateSection();
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_accessPointAdded: function(device, accessPoint) {
|
2011-06-02 11:42:26 -04:00
|
|
|
if (accessPoint.get_ssid() == null) {
|
|
|
|
// This access point is not visible yet
|
|
|
|
// Wait for it to get a ssid
|
|
|
|
accessPoint._notifySsidId = accessPoint.connect('notify::ssid', Lang.bind(this, this._notifySsidCb));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
let pos = this._findNetwork(accessPoint);
|
2013-04-25 21:18:20 -04:00
|
|
|
let network;
|
2011-04-06 12:11:23 -04:00
|
|
|
let needsupdate = false;
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
if (pos != -1) {
|
2013-04-25 21:18:20 -04:00
|
|
|
network = this._networks[pos];
|
|
|
|
if (network.accessPoints.indexOf(accessPoint) != -1) {
|
2011-01-25 16:08:12 -05:00
|
|
|
log('Access point was already seen, not adding again');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
Util.insertSorted(network.accessPoints, accessPoint, function(one, two) {
|
2012-05-29 14:02:48 -04:00
|
|
|
return two.strength - one.strength;
|
|
|
|
});
|
2013-04-25 21:18:20 -04:00
|
|
|
if (network.item)
|
|
|
|
network.item.updateBestAP(network.accessPoints[0]);
|
2011-01-25 16:08:12 -05:00
|
|
|
} else {
|
2013-04-25 21:18:20 -04:00
|
|
|
network = { ssid: accessPoint.get_ssid(),
|
|
|
|
mode: accessPoint.mode,
|
|
|
|
security: this._getApSecurityType(accessPoint),
|
|
|
|
connections: [ ],
|
|
|
|
item: null,
|
|
|
|
accessPoints: [ accessPoint ]
|
|
|
|
};
|
|
|
|
network.ssidText = ssidToLabel(network.ssid);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2012-05-29 14:02:48 -04:00
|
|
|
accessPoint._updateId = accessPoint.connect('notify::strength', Lang.bind(this, this._onApStrengthChanged));
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
// check if this enables new connections for this group
|
|
|
|
for (let i = 0; i < this._connections.length; i++) {
|
|
|
|
let connection = this._connections[i].connection;
|
2011-04-25 18:13:12 -04:00
|
|
|
if (accessPoint.connection_valid(connection) &&
|
2013-04-25 21:18:20 -04:00
|
|
|
network.connections.indexOf(connection) == -1) {
|
|
|
|
network.connections.push(connection);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 14:02:48 -04:00
|
|
|
if (pos != -1)
|
|
|
|
this._networks.splice(pos, 1);
|
2013-04-25 21:18:20 -04:00
|
|
|
let newPos = Util.insertSorted(this._networks, network, this._networkSortFunction);
|
2011-12-17 17:54:45 -05:00
|
|
|
|
2012-05-29 14:02:48 -04:00
|
|
|
// Queue an update of the UI if we changed the order
|
2012-10-03 17:40:48 -04:00
|
|
|
if (newPos != pos)
|
2011-11-15 12:22:24 -05:00
|
|
|
this._queueCreateSection();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_accessPointRemoved: function(device, accessPoint) {
|
2012-05-29 14:02:48 -04:00
|
|
|
if (accessPoint._updateId) {
|
|
|
|
accessPoint.disconnect(accessPoint._updateId);
|
|
|
|
accessPoint._updateId = 0;
|
|
|
|
}
|
|
|
|
|
2011-10-14 10:46:52 -04:00
|
|
|
let res = this._findExistingNetwork(accessPoint);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2011-10-14 10:46:52 -04:00
|
|
|
if (res == null) {
|
2011-01-25 16:08:12 -05:00
|
|
|
log('Removing an access point that was never added');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
let network = this._networks[res.network];
|
|
|
|
network.accessPoints.splice(res.ap, 1);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
if (network.accessPoints.length == 0) {
|
|
|
|
if (this._activeNetwork == network)
|
2011-09-18 08:27:50 -04:00
|
|
|
this._activeNetwork = null;
|
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
if (network.item)
|
|
|
|
network.item.destroy();
|
2011-06-27 11:45:24 -04:00
|
|
|
|
|
|
|
if (this._overflowItem) {
|
2013-04-25 21:18:20 -04:00
|
|
|
if (!network.isMore) {
|
2011-06-27 11:45:24 -04:00
|
|
|
// we removed an item in the main menu, and we have a more submenu
|
|
|
|
// we need to extract the first item in more and move it to the submenu
|
|
|
|
|
2011-10-17 08:43:08 -04:00
|
|
|
let item = this._overflowItem.menu.firstMenuItem;
|
2013-04-25 21:18:20 -04:00
|
|
|
if (item && item._network) {
|
2011-10-17 08:43:08 -04:00
|
|
|
item.destroy();
|
|
|
|
// clear the cycle, and allow the construction of the new item
|
2013-04-25 21:18:20 -04:00
|
|
|
item._network.item = null;
|
2011-10-17 08:43:08 -04:00
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
this._createNetworkItem(item._network, NUM_VISIBLE_NETWORKS-1);
|
2011-10-17 08:43:08 -04:00
|
|
|
} else {
|
|
|
|
log('The more... menu was existing and empty! This should not happen');
|
2011-06-27 11:45:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This can happen if the removed connection is from the overflow
|
|
|
|
// menu, or if we just moved the last connection out from the menu
|
2011-10-17 08:43:08 -04:00
|
|
|
if (this._overflowItem.menu.numMenuItems == 0) {
|
2011-06-27 11:45:24 -04:00
|
|
|
this._overflowItem.destroy();
|
|
|
|
this._overflowItem = null;
|
|
|
|
}
|
2011-03-28 15:27:03 -04:00
|
|
|
}
|
2011-06-27 11:45:24 -04:00
|
|
|
|
2012-05-29 14:02:48 -04:00
|
|
|
this._networks.splice(res.network, 1);
|
|
|
|
} else {
|
|
|
|
let okPrev = true, okNext = true;
|
|
|
|
|
|
|
|
if (res.network > 0)
|
2013-04-25 21:18:20 -04:00
|
|
|
okPrev = this._networkSortFunction(this._networks[res.network - 1], network) >= 0;
|
2012-05-29 14:02:48 -04:00
|
|
|
if (res.network < this._networks.length-1)
|
2013-04-25 21:18:20 -04:00
|
|
|
okNext = this._networkSortFunction(this._networks[res.network + 1], network) <= 0;
|
2012-05-29 14:02:48 -04:00
|
|
|
|
2012-10-03 17:40:48 -04:00
|
|
|
if (!okPrev || !okNext)
|
2012-05-29 14:02:48 -04:00
|
|
|
this._queueCreateSection();
|
2013-04-25 21:18:20 -04:00
|
|
|
else if (network.item)
|
|
|
|
network.item.updateBestAP(network.accessPoints[0]);
|
2012-05-29 14:02:48 -04:00
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_clearSection: function() {
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
for (let i = 0; i < this._networks.length; i++)
|
|
|
|
this._networks[i].item = null;
|
|
|
|
this._overflowItem = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeConnection: function(connection) {
|
2012-05-31 13:13:16 -04:00
|
|
|
let pos = this._findConnection(connection.get_uuid());
|
2011-01-25 16:08:12 -05:00
|
|
|
if (pos == -1) {
|
|
|
|
// removing connection that was never added
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let obj = this._connections[pos];
|
|
|
|
this._connections.splice(pos, 1);
|
|
|
|
|
2011-11-15 12:22:24 -05:00
|
|
|
let forceupdate = false;
|
2011-01-25 16:08:12 -05:00
|
|
|
for (let i = 0; i < this._networks.length; i++) {
|
2013-04-25 21:18:20 -04:00
|
|
|
let network = this._networks[i];
|
|
|
|
let connections = network.connections;
|
2011-01-25 16:08:12 -05:00
|
|
|
for (let k = 0; k < connections.length; k++) {
|
2012-05-31 13:13:16 -04:00
|
|
|
if (connections[k].get_uuid() == connection.get_uuid()) {
|
2011-01-25 16:08:12 -05:00
|
|
|
// remove the connection from the access point group
|
2013-04-26 01:34:50 -04:00
|
|
|
connections.splice(k, 1);
|
2011-11-15 12:22:24 -05:00
|
|
|
forceupdate = forceupdate || connections.length == 0;
|
2011-04-06 12:11:23 -04:00
|
|
|
|
2011-11-15 12:22:24 -05:00
|
|
|
if (forceupdate)
|
2011-04-06 12:11:23 -04:00
|
|
|
break;
|
2011-11-15 12:22:24 -05:00
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
if (network.item) {
|
2013-04-25 16:32:01 -04:00
|
|
|
network.item.destroy();
|
|
|
|
network.item = null;
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-15 12:22:24 -05:00
|
|
|
if (forceupdate) {
|
2011-04-06 12:11:23 -04:00
|
|
|
this._networks.sort(this._networkSortFunction);
|
2011-11-15 12:22:24 -05:00
|
|
|
this._queueCreateSection();
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addConnection: function(connection) {
|
|
|
|
// record the connection
|
|
|
|
let obj = {
|
|
|
|
connection: connection,
|
2012-05-31 13:13:16 -04:00
|
|
|
name: connection.get_id(),
|
|
|
|
uuid: connection.get_uuid(),
|
2011-01-25 16:08:12 -05:00
|
|
|
};
|
|
|
|
this._connections.push(obj);
|
|
|
|
|
|
|
|
// find an appropriate access point
|
2011-04-06 12:11:23 -04:00
|
|
|
let forceupdate = false;
|
2011-01-25 16:08:12 -05:00
|
|
|
for (let i = 0; i < this._networks.length; i++) {
|
2013-04-25 21:18:20 -04:00
|
|
|
let network = this._networks[i];
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
// Check if connection is valid for any of these access points
|
2013-04-25 21:18:20 -04:00
|
|
|
for (let k = 0; k < network.accessPoints.length; k++) {
|
|
|
|
let ap = network.accessPoints[k];
|
2011-04-25 18:13:12 -04:00
|
|
|
if (ap.connection_valid(connection)) {
|
2013-04-25 21:18:20 -04:00
|
|
|
network.connections.push(connection);
|
2011-04-06 12:11:23 -04:00
|
|
|
// this potentially changes the sorting order
|
|
|
|
forceupdate = true;
|
2011-01-25 16:08:12 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forceupdate) {
|
2011-04-06 12:11:23 -04:00
|
|
|
this._networks.sort(this._networkSortFunction);
|
2011-11-15 12:22:24 -05:00
|
|
|
this._queueCreateSection();
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_createActiveConnectionItem: function() {
|
2012-06-05 17:32:52 -04:00
|
|
|
let title;
|
|
|
|
if (this._activeConnection && this._activeConnection._connection)
|
|
|
|
title = this._activeConnection._connection.get_id();
|
|
|
|
else
|
|
|
|
title = _("Connected (private)");
|
|
|
|
|
2013-06-11 19:56:17 -04:00
|
|
|
this._activeConnectionItem = new NMNetworkMenuItem(this._device.active_access_point);
|
2013-04-26 12:12:29 -04:00
|
|
|
this._activeConnectionItem.setSensitive(false);
|
2013-04-19 20:57:38 -04:00
|
|
|
this._activeConnectionItem.setOrnament(PopupMenu.Ornament.DOT);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
_createNetworkItem: function(network, position) {
|
|
|
|
if(!network.accessPoints || network.accessPoints.length == 0) {
|
2011-09-18 08:25:45 -04:00
|
|
|
// this should not happen, but I have no idea why it happens
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-25 20:39:19 -04:00
|
|
|
network.item = new NMNetworkMenuItem(network.accessPoints[0]);
|
2013-04-25 21:18:20 -04:00
|
|
|
if(network.connections.length > 0) {
|
2013-04-25 20:39:19 -04:00
|
|
|
let connection = network.connections[0];
|
|
|
|
network.item._connection = connection;
|
|
|
|
network.item.connect('activate', Lang.bind(this, function() {
|
|
|
|
let accessPoints = network.accessPoints;
|
|
|
|
for (let i = 0; i < accessPoints.length; i++) {
|
|
|
|
if (accessPoints[i].connection_valid(connection)) {
|
2013-06-11 19:56:17 -04:00
|
|
|
this._client.activate_connection(connection, this._device, accessPoints[i].dbus_path, null);
|
2013-04-25 20:39:19 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2011-04-06 12:11:23 -04:00
|
|
|
} else {
|
2013-04-25 21:18:20 -04:00
|
|
|
network.item.connect('activate', Lang.bind(this, function() {
|
|
|
|
let accessPoints = network.accessPoints;
|
2011-05-03 14:31:45 -04:00
|
|
|
if ( (accessPoints[0]._secType == NMAccessPointSecurity.WPA2_ENT)
|
|
|
|
|| (accessPoints[0]._secType == NMAccessPointSecurity.WPA_ENT)) {
|
2011-08-22 12:21:31 -04:00
|
|
|
// 802.1x-enabled APs require further configuration, so they're
|
|
|
|
// handled in gnome-control-center
|
|
|
|
Util.spawn(['gnome-control-center', 'network', 'connect-8021x-wifi',
|
2013-06-11 19:56:17 -04:00
|
|
|
this._device.get_path(), accessPoints[0].dbus_path]);
|
2011-05-03 14:31:45 -04:00
|
|
|
} else {
|
2013-04-25 16:48:27 -04:00
|
|
|
let connection = new NetworkManager.Connection();
|
2013-06-11 19:56:17 -04:00
|
|
|
this._client.add_and_activate_connection(connection, this._device, accessPoints[0].dbus_path, null)
|
2011-05-03 14:31:45 -04:00
|
|
|
}
|
2011-04-06 12:11:23 -04:00
|
|
|
}));
|
|
|
|
}
|
2013-04-25 21:18:20 -04:00
|
|
|
network.item._network = network;
|
2011-10-17 08:43:08 -04:00
|
|
|
|
2011-06-27 11:45:24 -04:00
|
|
|
if (position < NUM_VISIBLE_NETWORKS) {
|
2013-04-25 21:18:20 -04:00
|
|
|
network.isMore = false;
|
|
|
|
this.section.addMenuItem(network.item, position);
|
2011-06-27 11:45:24 -04:00
|
|
|
} else {
|
2011-04-06 12:11:23 -04:00
|
|
|
if (!this._overflowItem) {
|
2012-12-03 10:59:28 -05:00
|
|
|
this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More…"));
|
2011-04-06 12:11:23 -04:00
|
|
|
this.section.addMenuItem(this._overflowItem);
|
|
|
|
}
|
2013-04-25 21:18:20 -04:00
|
|
|
this._overflowItem.menu.addMenuItem(network.item, position - NUM_VISIBLE_NETWORKS);
|
|
|
|
network.isMore = true;
|
2011-04-06 12:11:23 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_createSection: function() {
|
|
|
|
if (!this._shouldShowConnectionList())
|
|
|
|
return;
|
|
|
|
|
2011-11-15 12:22:24 -05:00
|
|
|
if (this._activeNetwork) {
|
2011-01-25 16:08:12 -05:00
|
|
|
this._createActiveConnectionItem();
|
|
|
|
this.section.addMenuItem(this._activeConnectionItem);
|
|
|
|
}
|
|
|
|
|
2011-04-06 12:11:23 -04:00
|
|
|
let activeOffset = this._activeConnectionItem ? 1 : 0;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
for(let j = 0; j < this._networks.length; j++) {
|
2013-04-25 21:18:20 -04:00
|
|
|
let network = this._networks[j];
|
|
|
|
if (network == this._activeNetwork) {
|
2011-11-19 13:01:24 -05:00
|
|
|
activeOffset--;
|
2011-01-25 16:08:12 -05:00
|
|
|
continue;
|
2011-11-19 13:01:24 -05:00
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-25 21:18:20 -04:00
|
|
|
this._createNetworkItem(network, j + activeOffset);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
},
|
2013-04-29 15:20:45 -04:00
|
|
|
|
|
|
|
_updateAccessPoint: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
let ap = this._device.active_access_point;
|
2013-04-29 15:20:45 -04:00
|
|
|
if (this._activeAccessPoint == ap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._activeAccessPoint) {
|
|
|
|
this._activeAccessPoint.disconnect(this._strengthChangedId);
|
|
|
|
this._strengthChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._activeAccessPoint = ap;
|
|
|
|
|
|
|
|
if (this._activeAccessPoint) {
|
|
|
|
this._strengthChangedId = this._activeAccessPoint.connect('notify::strength',
|
|
|
|
Lang.bind(this, this._strengthChanged));
|
|
|
|
}
|
|
|
|
|
|
|
|
this._syncStatusLabel();
|
|
|
|
},
|
|
|
|
|
|
|
|
_strengthChanged: function() {
|
|
|
|
this.emit('icon-changed');
|
|
|
|
},
|
|
|
|
|
|
|
|
getIndicatorIcon: function() {
|
2013-06-11 19:56:17 -04:00
|
|
|
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
|
2013-04-29 15:20:45 -04:00
|
|
|
return 'network-wireless-acquiring-symbolic';
|
|
|
|
|
2013-06-11 19:56:17 -04:00
|
|
|
let ap = this._device.active_access_point;
|
2013-04-29 15:20:45 -04:00
|
|
|
if (!ap) {
|
2013-06-11 19:56:17 -04:00
|
|
|
if (this._device.mode != NM80211Mode.ADHOC)
|
2013-04-29 15:20:45 -04:00
|
|
|
log('An active wireless connection, in infrastructure mode, involves no access point?');
|
|
|
|
|
|
|
|
return 'network-wireless-connected-symbolic';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'network-wireless-signal-' + signalToIcon(ap.strength) + '-symbolic';
|
|
|
|
},
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
const NMVPNConnectionItem = new Lang.Class({
|
|
|
|
Name: 'NMVPNConnectionItem',
|
2012-08-29 10:22:24 -04:00
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
_init: function(client, connection) {
|
2012-08-29 10:22:24 -04:00
|
|
|
this._client = client;
|
2013-04-26 19:21:02 -04:00
|
|
|
this.connection = connection;
|
|
|
|
this._activeConnection = null;
|
|
|
|
this._activeConnectionChangedId = 0;
|
2012-08-29 10:22:24 -04:00
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
this.menuItem = new PopupMenu.PopupSwitchMenuItem(connection.get_id(), false,
|
|
|
|
{ style_class: 'popup-subtitle-menu-item' });
|
|
|
|
this.menuItem.connect('toggled', Lang.bind(this, this._toggle));
|
|
|
|
|
|
|
|
this._sync();
|
2012-08-29 10:22:24 -04:00
|
|
|
},
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
destroy: function() {
|
|
|
|
this.menuItem.destroy();
|
2012-08-29 10:22:24 -04:00
|
|
|
},
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
isActive: function() {
|
|
|
|
if (this._activeConnection == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return this._activeConnection.vpn_state == NetworkManager.VPNConnectionState.ACTIVATED;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getStatus: function() {
|
|
|
|
if (this._activeConnection == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
switch(this._activeConnection.vpn_state) {
|
2012-08-29 10:22:24 -04:00
|
|
|
case NetworkManager.VPNConnectionState.DISCONNECTED:
|
|
|
|
case NetworkManager.VPNConnectionState.ACTIVATED:
|
|
|
|
return null;
|
|
|
|
case NetworkManager.VPNConnectionState.PREPARE:
|
|
|
|
case NetworkManager.VPNConnectionState.CONNECT:
|
|
|
|
case NetworkManager.VPNConnectionState.IP_CONFIG_GET:
|
|
|
|
return _("connecting...");
|
|
|
|
case NetworkManager.VPNConnectionState.NEED_AUTH:
|
|
|
|
/* Translators: this is for network connections that require some kind of key or password */
|
|
|
|
return _("authentication required");
|
|
|
|
case NetworkManager.VPNConnectionState.FAILED:
|
|
|
|
return _("connection failed");
|
|
|
|
default:
|
|
|
|
return 'invalid';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
_toggle: function() {
|
|
|
|
if (this._activeConnection == null)
|
|
|
|
this._client.activate_connection(this.connection, null, null, null);
|
|
|
|
else
|
|
|
|
this._client.deactivate_connection(this._activeConnection);
|
2012-08-29 10:22:24 -04:00
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
this._sync();
|
2012-08-29 10:22:24 -04:00
|
|
|
},
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
_sync: function() {
|
|
|
|
this.menuItem.setToggleState(this.isActive());
|
|
|
|
this.menuItem.setStatus(this._getStatus());
|
|
|
|
this.emit('icon-changed');
|
2012-08-29 10:22:24 -04:00
|
|
|
},
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
_connectionStateChanged: function(ac, newstate, reason) {
|
2012-10-02 15:02:59 -04:00
|
|
|
if (newstate == NetworkManager.VPNConnectionState.FAILED &&
|
|
|
|
reason != NetworkManager.VPNConnectionStateReason.NO_SECRETS) {
|
2012-08-29 10:22:24 -04:00
|
|
|
// FIXME: if we ever want to show something based on reason,
|
|
|
|
// we need to convert from NetworkManager.VPNConnectionStateReason
|
|
|
|
// to NetworkManager.DeviceStateReason
|
|
|
|
this.emit('activation-failed', reason);
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
setActiveConnection: function(activeConnection) {
|
|
|
|
if (this._activeConnectionChangedId > 0) {
|
|
|
|
this._activeConnection.disconnect(this._activeConnectionChangedId);
|
|
|
|
this._activeConnectionChangedId = 0;
|
2012-08-29 10:22:24 -04:00
|
|
|
}
|
2013-04-29 15:20:45 -04:00
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
this._activeConnection = activeConnection;
|
|
|
|
|
|
|
|
if (this._activeConnection)
|
|
|
|
this._activeConnectionChangedId = this._activeConnection.connect('vpn-state-changed',
|
|
|
|
Lang.bind(this, this._connectionStateChanged));
|
|
|
|
|
|
|
|
this._sync();
|
2013-04-29 15:20:45 -04:00
|
|
|
},
|
|
|
|
|
2013-04-26 19:21:02 -04:00
|
|
|
getIndicatorIcon: function() {
|
|
|
|
if (this._activeConnection) {
|
|
|
|
if (this._activeConnection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
|
2013-04-29 15:20:45 -04:00
|
|
|
return 'network-vpn-acquiring-symbolic';
|
|
|
|
else
|
|
|
|
return 'network-vpn-symbolic';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
},
|
2013-04-26 19:21:02 -04:00
|
|
|
});
|
|
|
|
Signals.addSignalMethods(NMVPNConnectionItem.prototype);
|
|
|
|
|
|
|
|
const NMVPNSection = new Lang.Class({
|
|
|
|
Name: 'NMVPNSection',
|
|
|
|
category: NMConnectionCategory.VPN,
|
|
|
|
|
|
|
|
_init: function(client) {
|
|
|
|
this._client = client;
|
|
|
|
this._connectionItems = new Hash.Map();
|
|
|
|
|
|
|
|
this.section = new PopupMenu.PopupMenuSection();
|
|
|
|
},
|
|
|
|
|
|
|
|
checkConnection: function(connection) {
|
|
|
|
if (this._connectionItems.has(connection.get_uuid()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let item = new NMVPNConnectionItem(this._client, connection);
|
|
|
|
|
|
|
|
item.connect('icon-changed', Lang.bind(this, function() {
|
|
|
|
this.emit('icon-changed');
|
|
|
|
}));
|
|
|
|
item.connect('activation-failed', Lang.bind(this, function(item, reason) {
|
|
|
|
this.emit('activation-failed', reason);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.section.addMenuItem(item.menuItem);
|
|
|
|
this._connectionItems.set(connection.get_uuid(), item);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeConnection: function(connection) {
|
|
|
|
this._connectionItems.get(connection.get_uuid()).destroy();
|
|
|
|
this._connectionItems.delete(connection.get_uuid());
|
|
|
|
},
|
|
|
|
|
|
|
|
addActiveConnection: function(activeConnection) {
|
|
|
|
let item = this._connectionItems.get(activeConnection._connection.get_uuid());
|
|
|
|
item.setActiveConnection(activeConnection);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeActiveConnection: function(activeConnection) {
|
|
|
|
let item = this._connectionItems.get(activeConnection._connection.get_uuid());
|
|
|
|
item.setActiveConnection(null);
|
|
|
|
},
|
2013-04-29 15:20:45 -04:00
|
|
|
|
|
|
|
getIndicatorIcon: function() {
|
2013-04-26 19:21:02 -04:00
|
|
|
let items = this._connectionItems.values();
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
let item = items[i];
|
|
|
|
let icon = item.getIndicatorIcon();
|
2013-04-29 15:20:45 -04:00
|
|
|
if (icon)
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
return '';
|
2012-08-29 10:22:24 -04:00
|
|
|
},
|
|
|
|
});
|
2013-04-26 19:21:02 -04:00
|
|
|
Signals.addSignalMethods(NMVPNSection.prototype);
|
2012-08-29 10:22:24 -04:00
|
|
|
|
2011-11-20 09:38:48 -05:00
|
|
|
const NMApplet = new Lang.Class({
|
|
|
|
Name: 'NMApplet',
|
2012-08-26 09:49:18 -04:00
|
|
|
Extends: PanelMenu.SystemStatusButton,
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
_init: function() {
|
2012-09-13 14:30:38 -04:00
|
|
|
this.parent('network-offline-symbolic', _('Network'));
|
2012-06-19 13:50:37 -04:00
|
|
|
|
2013-05-31 19:03:09 -04:00
|
|
|
this._vpnIcon = this.addIcon(null);
|
|
|
|
this._vpnIcon.hide();
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-09-03 13:57:53 -04:00
|
|
|
// Device types
|
|
|
|
this._dtypes = { };
|
|
|
|
this._dtypes[NetworkManager.DeviceType.ETHERNET] = NMDeviceWired;
|
|
|
|
this._dtypes[NetworkManager.DeviceType.WIFI] = NMDeviceWireless;
|
|
|
|
this._dtypes[NetworkManager.DeviceType.MODEM] = NMDeviceModem;
|
|
|
|
this._dtypes[NetworkManager.DeviceType.BT] = NMDeviceBluetooth;
|
|
|
|
this._dtypes[NetworkManager.DeviceType.INFINIBAND] = NMDeviceSimple;
|
|
|
|
// TODO: WiMax support
|
|
|
|
|
|
|
|
// Connection types
|
|
|
|
this._ctypes = { };
|
|
|
|
this._ctypes[NetworkManager.SETTING_WIRELESS_SETTING_NAME] = NMConnectionCategory.WIRELESS;
|
|
|
|
this._ctypes[NetworkManager.SETTING_WIRED_SETTING_NAME] = NMConnectionCategory.WIRED;
|
|
|
|
this._ctypes[NetworkManager.SETTING_PPPOE_SETTING_NAME] = NMConnectionCategory.WIRED;
|
|
|
|
this._ctypes[NetworkManager.SETTING_PPP_SETTING_NAME] = NMConnectionCategory.WIRED;
|
|
|
|
this._ctypes[NetworkManager.SETTING_BLUETOOTH_SETTING_NAME] = NMConnectionCategory.WWAN;
|
|
|
|
this._ctypes[NetworkManager.SETTING_CDMA_SETTING_NAME] = NMConnectionCategory.WWAN;
|
|
|
|
this._ctypes[NetworkManager.SETTING_GSM_SETTING_NAME] = NMConnectionCategory.WWAN;
|
|
|
|
this._ctypes[NetworkManager.SETTING_INFINIBAND_SETTING_NAME] = NMConnectionCategory.WIRED;
|
|
|
|
this._ctypes[NetworkManager.SETTING_VPN_SETTING_NAME] = NMConnectionCategory.VPN;
|
|
|
|
|
|
|
|
NMClient.Client.new_async(null, Lang.bind(this, this._clientGot));
|
|
|
|
NMClient.RemoteSettings.new_async(null, null, Lang.bind(this, this._remoteSettingsGot));
|
|
|
|
},
|
|
|
|
|
|
|
|
_clientGot: function(obj, result) {
|
|
|
|
this._client = NMClient.Client.new_finish(result);
|
|
|
|
|
|
|
|
this._tryLateInit();
|
|
|
|
},
|
|
|
|
|
|
|
|
_remoteSettingsGot: function(obj, result) {
|
|
|
|
this._settings = NMClient.RemoteSettings.new_finish(result);
|
|
|
|
|
|
|
|
this._tryLateInit();
|
|
|
|
},
|
|
|
|
|
|
|
|
_tryLateInit: function() {
|
|
|
|
if (!this._client || !this._settings)
|
|
|
|
return;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
this._statusSection = new PopupMenu.PopupMenuSection();
|
2012-09-11 08:00:22 -04:00
|
|
|
this._statusItem = new PopupMenu.PopupMenuItem('', { reactive: false });
|
2011-01-25 16:08:12 -05:00
|
|
|
this._statusSection.addMenuItem(this._statusItem);
|
|
|
|
this._statusSection.addAction(_("Enable networking"), Lang.bind(this, function() {
|
|
|
|
this._client.networking_enabled = true;
|
|
|
|
}));
|
|
|
|
this._statusSection.actor.hide();
|
|
|
|
this.menu.addMenuItem(this._statusSection);
|
2011-08-19 14:42:20 -04:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-05-18 12:34:07 -04:00
|
|
|
this._activeConnections = [ ];
|
|
|
|
this._connections = [ ];
|
|
|
|
|
|
|
|
this._mainConnection = null;
|
2013-04-29 15:20:45 -04:00
|
|
|
this._mainConnectionIconChangedId = 0;
|
2012-05-18 12:34:07 -04:00
|
|
|
|
2012-08-29 13:42:11 -04:00
|
|
|
this._nmDevices = [];
|
2011-01-25 16:08:12 -05:00
|
|
|
this._devices = { };
|
|
|
|
|
|
|
|
this._devices.wired = {
|
|
|
|
section: new PopupMenu.PopupMenuSection(),
|
|
|
|
devices: [ ],
|
|
|
|
};
|
|
|
|
|
|
|
|
this._devices.wired.section.actor.hide();
|
|
|
|
this.menu.addMenuItem(this._devices.wired.section);
|
2011-08-19 14:42:20 -04:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
this._devices.wireless = {
|
|
|
|
section: new PopupMenu.PopupMenuSection(),
|
|
|
|
devices: [ ],
|
2013-04-25 17:20:57 -04:00
|
|
|
item: this._makeWirelessToggle()
|
2011-01-25 16:08:12 -05:00
|
|
|
};
|
|
|
|
this._devices.wireless.section.addMenuItem(this._devices.wireless.item);
|
|
|
|
this._devices.wireless.section.actor.hide();
|
|
|
|
this.menu.addMenuItem(this._devices.wireless.section);
|
2011-08-19 14:42:20 -04:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
this._devices.wwan = {
|
|
|
|
section: new PopupMenu.PopupMenuSection(),
|
|
|
|
devices: [ ],
|
|
|
|
};
|
|
|
|
this._devices.wwan.section.actor.hide();
|
|
|
|
this.menu.addMenuItem(this._devices.wwan.section);
|
2011-08-19 14:42:20 -04:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-29 13:12:14 -04:00
|
|
|
this._vpnSection = new NMVPNSection(this._client);
|
2012-08-29 10:22:24 -04:00
|
|
|
this._vpnSection.connect('activation-failed', Lang.bind(this, this._onActivationFailed));
|
2013-04-29 15:20:45 -04:00
|
|
|
this._vpnSection.connect('icon-changed', Lang.bind(this, this._updateIcon));
|
2012-08-29 10:22:24 -04:00
|
|
|
this.menu.addMenuItem(this._vpnSection.section);
|
2011-08-19 14:42:20 -04:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2011-08-23 10:14:55 -04:00
|
|
|
this.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-09-03 13:57:53 -04:00
|
|
|
this._readConnections();
|
|
|
|
this._readDevices();
|
|
|
|
this._syncNMState();
|
|
|
|
|
|
|
|
this._client.connect('notify::manager-running', Lang.bind(this, this._syncNMState));
|
|
|
|
this._client.connect('notify::networking-enabled', Lang.bind(this, this._syncNMState));
|
|
|
|
this._client.connect('notify::state', Lang.bind(this, this._syncNMState));
|
2013-07-03 13:47:21 -04:00
|
|
|
this._client.connect('notify::active-connections', Lang.bind(this, this._syncActiveConnections));
|
2012-09-03 13:57:53 -04:00
|
|
|
this._client.connect('device-added', Lang.bind(this, this._deviceAdded));
|
|
|
|
this._client.connect('device-removed', Lang.bind(this, this._deviceRemoved));
|
|
|
|
this._settings.connect('new-connection', Lang.bind(this, this._newConnection));
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_ensureSource: function() {
|
|
|
|
if (!this._source) {
|
2011-10-08 18:00:32 -04:00
|
|
|
this._source = new MessageTray.Source(_("Network Manager"),
|
2012-08-31 17:25:26 -04:00
|
|
|
'network-transmit-receive');
|
2012-11-03 21:11:08 -04:00
|
|
|
this._source.policy = new NotificationDaemon.NotificationApplicationPolicy('gnome-network-panel');
|
2011-10-08 18:00:32 -04:00
|
|
|
|
2011-08-22 12:21:31 -04:00
|
|
|
this._source.connect('destroy', Lang.bind(this, function() {
|
2011-01-25 16:08:12 -05:00
|
|
|
this._source = null;
|
|
|
|
}));
|
|
|
|
Main.messageTray.add(this._source);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-04-25 17:20:57 -04:00
|
|
|
_makeWirelessToggle: function() {
|
|
|
|
let item = new NMWirelessSectionTitleMenuItem(this._client);
|
2011-01-25 16:08:12 -05:00
|
|
|
item.connect('enabled-changed', Lang.bind(this, function(item, enabled) {
|
2013-04-25 17:20:57 -04:00
|
|
|
let devices = this._devices.wireless.devices;
|
2011-01-25 16:08:12 -05:00
|
|
|
devices.forEach(function(dev) {
|
|
|
|
dev.setEnabled(enabled);
|
|
|
|
});
|
2013-04-25 17:20:57 -04:00
|
|
|
this._syncSectionTitle('wireless');
|
2011-01-25 16:08:12 -05:00
|
|
|
}));
|
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
|
|
|
_syncSectionTitle: function(category) {
|
|
|
|
let devices = this._devices[category].devices;
|
|
|
|
let item = this._devices[category].item;
|
|
|
|
let section = this._devices[category].section;
|
2012-12-04 08:49:34 -05:00
|
|
|
|
2013-06-12 16:05:31 -04:00
|
|
|
if (devices.length == 0)
|
2011-01-25 16:08:12 -05:00
|
|
|
section.actor.hide();
|
|
|
|
else {
|
|
|
|
section.actor.show();
|
2012-08-29 13:42:11 -04:00
|
|
|
|
|
|
|
// Sync the relation between the section title
|
|
|
|
// item (the one with the airplane mode switch)
|
|
|
|
// and the individual device switches
|
|
|
|
if (item) {
|
|
|
|
if (devices.length == 1) {
|
|
|
|
let dev = devices[0];
|
|
|
|
dev.statusItem.actor.hide();
|
|
|
|
item.updateForDevice(dev);
|
|
|
|
} else {
|
|
|
|
devices.forEach(function(dev) {
|
|
|
|
dev.statusItem.actor.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
// remove status text from the section title item
|
|
|
|
item.updateForDevice(null);
|
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_readDevices: function() {
|
|
|
|
let devices = this._client.get_devices() || [ ];
|
|
|
|
for (let i = 0; i < devices.length; ++i) {
|
2012-08-29 13:42:11 -04:00
|
|
|
this._deviceAdded(this._client, devices[i], true);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2012-08-29 13:42:11 -04:00
|
|
|
this._syncDeviceNames();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2011-08-22 12:21:31 -04:00
|
|
|
_notifyForDevice: function(device, iconName, title, text, urgency) {
|
|
|
|
if (device._notification)
|
|
|
|
device._notification.destroy();
|
|
|
|
|
|
|
|
/* must call after destroying previous notification,
|
|
|
|
or this._source will be cleared */
|
|
|
|
this._ensureSource();
|
|
|
|
|
2012-09-14 10:33:52 -04:00
|
|
|
let gicon = new Gio.ThemedIcon({ name: iconName });
|
2011-08-22 12:21:31 -04:00
|
|
|
device._notification = new MessageTray.Notification(this._source, title, text,
|
2012-09-14 10:33:52 -04:00
|
|
|
{ gicon: gicon });
|
2011-08-22 12:21:31 -04:00
|
|
|
device._notification.setUrgency(urgency);
|
|
|
|
device._notification.setTransient(true);
|
|
|
|
device._notification.connect('destroy', function() {
|
|
|
|
device._notification = null;
|
|
|
|
});
|
|
|
|
this._source.notify(device._notification);
|
|
|
|
},
|
|
|
|
|
2012-08-29 10:22:24 -04:00
|
|
|
_onActivationFailed: function(device, reason) {
|
|
|
|
// XXX: nm-applet has no special text depending on reason
|
|
|
|
// but I'm not sure of this generic message
|
|
|
|
this._notifyForDevice(device, 'network-error-symbolic',
|
|
|
|
_("Connection failed"),
|
|
|
|
_("Activation of network connection failed"),
|
|
|
|
MessageTray.Urgency.HIGH);
|
|
|
|
},
|
|
|
|
|
2012-08-29 13:42:11 -04:00
|
|
|
_syncDeviceNames: function() {
|
2013-04-25 14:00:11 -04:00
|
|
|
let names = NMGtk.utils_disambiguate_device_names(this._nmDevices);
|
|
|
|
for (let i = 0; i < this._nmDevices.length; i++) {
|
|
|
|
let device = this._nmDevices[i];
|
|
|
|
device._description = names[i];
|
|
|
|
if (device._delegate)
|
2013-01-14 10:20:59 -05:00
|
|
|
device._delegate.syncDescription();
|
2012-08-29 13:42:11 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_deviceAdded: function(client, device, skipSyncDeviceNames) {
|
2011-01-25 16:08:12 -05:00
|
|
|
if (device._delegate) {
|
|
|
|
// already seen, not adding again
|
|
|
|
return;
|
|
|
|
}
|
2012-12-04 08:49:34 -05:00
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
let wrapperClass = this._dtypes[device.get_device_type()];
|
|
|
|
if (wrapperClass) {
|
2012-12-04 08:49:34 -05:00
|
|
|
let wrapper = new wrapperClass(this._client, device, this._connections);
|
|
|
|
this._addDeviceWrapper(wrapper);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2012-08-29 13:42:11 -04:00
|
|
|
this._nmDevices.push(device);
|
|
|
|
if (!skipSyncDeviceNames)
|
|
|
|
this._syncDeviceNames();
|
2012-08-21 10:55:40 -04:00
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2012-12-04 08:49:34 -05:00
|
|
|
_addDeviceWrapper: function(wrapper) {
|
|
|
|
wrapper._activationFailedId = wrapper.connect('activation-failed',
|
|
|
|
Lang.bind(this, this._onActivationFailed));
|
|
|
|
wrapper._deviceStateChangedId = wrapper.connect('state-changed', Lang.bind(this, function(dev) {
|
|
|
|
this._syncSectionTitle(dev.category);
|
|
|
|
}));
|
|
|
|
|
|
|
|
let section = this._devices[wrapper.category].section;
|
|
|
|
section.addMenuItem(wrapper.statusItem);
|
|
|
|
section.addMenuItem(wrapper.section);
|
|
|
|
|
|
|
|
let devices = this._devices[wrapper.category].devices;
|
|
|
|
devices.push(wrapper);
|
2013-01-28 18:23:31 -05:00
|
|
|
|
|
|
|
this._syncSectionTitle(wrapper.category);
|
2012-12-04 08:49:34 -05:00
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_deviceRemoved: function(client, device) {
|
2012-12-04 08:49:34 -05:00
|
|
|
let pos = this._nmDevices.indexOf(device);
|
|
|
|
if (pos != -1) {
|
|
|
|
this._nmDevices.splice(pos, 1);
|
|
|
|
this._syncDeviceNames();
|
|
|
|
}
|
|
|
|
|
|
|
|
let wrapper = device._delegate;
|
|
|
|
if (!wrapper) {
|
2011-01-25 16:08:12 -05:00
|
|
|
log('Removing a network device that was not added');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-12 16:05:31 -04:00
|
|
|
this._removeDeviceWrapper(wrapper);
|
2012-12-04 08:49:34 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_removeDeviceWrapper: function(wrapper) {
|
2013-04-26 00:25:14 -04:00
|
|
|
wrapper.disconnect(wrapper._activationFailedId);
|
|
|
|
wrapper.disconnect(wrapper._deviceStateChangedId);
|
2011-01-25 16:08:12 -05:00
|
|
|
wrapper.destroy();
|
|
|
|
|
|
|
|
let devices = this._devices[wrapper.category].devices;
|
|
|
|
let pos = devices.indexOf(wrapper);
|
|
|
|
devices.splice(pos, 1);
|
|
|
|
|
|
|
|
this._syncSectionTitle(wrapper.category)
|
|
|
|
},
|
|
|
|
|
2012-08-21 10:55:40 -04:00
|
|
|
_getSupportedActiveConnections: function() {
|
|
|
|
let activeConnections = this._client.get_active_connections() || [ ];
|
|
|
|
let supportedConnections = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < activeConnections.length; i++) {
|
|
|
|
let devices = activeConnections[i].get_devices();
|
|
|
|
if (!devices || !devices[0])
|
|
|
|
continue;
|
|
|
|
// Ignore connections via unrecognized device types
|
|
|
|
if (!this._dtypes[devices[0].device_type])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Ignore slave connections
|
|
|
|
let connectionPath = activeConnections[i].connection;
|
2013-06-08 09:24:20 -04:00
|
|
|
let connection = this._settings.get_connection_by_path(connectionPath);
|
|
|
|
|
|
|
|
// connection might be null, if libnm-glib fails to create
|
|
|
|
// the object due to version incompatibility, or if the
|
|
|
|
// connection is not visible to the current user
|
|
|
|
if (connection && this._ignoreConnection(connection))
|
2012-08-21 10:55:40 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
supportedConnections.push(activeConnections[i]);
|
|
|
|
}
|
|
|
|
return supportedConnections;
|
|
|
|
},
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
_syncActiveConnections: function() {
|
|
|
|
let closedConnections = [ ];
|
2012-08-21 10:55:40 -04:00
|
|
|
let newActiveConnections = this._getSupportedActiveConnections();
|
2011-01-25 16:08:12 -05:00
|
|
|
for (let i = 0; i < this._activeConnections.length; i++) {
|
|
|
|
let a = this._activeConnections[i];
|
|
|
|
if (newActiveConnections.indexOf(a) == -1) // connection is removed
|
|
|
|
closedConnections.push(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < closedConnections.length; i++) {
|
2013-06-06 15:41:48 -04:00
|
|
|
let a = closedConnections[i];
|
2013-04-26 21:44:59 -04:00
|
|
|
if (a._type == NetworkManager.SETTING_VPN_SETTING_NAME)
|
|
|
|
this._vpnSection.removeActiveConnection(a);
|
2013-06-06 15:41:48 -04:00
|
|
|
if (a._inited) {
|
|
|
|
a.disconnect(a._notifyStateId);
|
|
|
|
a.disconnect(a._notifyDefaultId);
|
|
|
|
a.disconnect(a._notifyDefault6Id);
|
|
|
|
a._inited = false;
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-29 15:20:45 -04:00
|
|
|
if (this._mainConnectionIconChangedId > 0) {
|
|
|
|
this._mainConnection._primaryDevice.disconnect(this._mainConnectionIconChangedId);
|
|
|
|
this._mainConnectionIconChangedId = 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
this._activeConnections = newActiveConnections;
|
|
|
|
this._mainConnection = null;
|
2012-06-19 13:50:37 -04:00
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
let activating = null;
|
|
|
|
let default_ip4 = null;
|
|
|
|
let default_ip6 = null;
|
2013-05-08 17:54:32 -04:00
|
|
|
let active_any = null;
|
2011-01-25 16:08:12 -05:00
|
|
|
for (let i = 0; i < this._activeConnections.length; i++) {
|
|
|
|
let a = this._activeConnections[i];
|
|
|
|
|
|
|
|
if (!a._inited) {
|
2013-07-03 13:47:21 -04:00
|
|
|
a._notifyDefaultId = a.connect('notify::default', Lang.bind(this, this._syncActiveConnections));
|
|
|
|
a._notifyDefault6Id = a.connect('notify::default6', Lang.bind(this, this._syncActiveConnections));
|
2011-09-04 15:17:33 -04:00
|
|
|
a._notifyStateId = a.connect('notify::state', Lang.bind(this, this._notifyActivated));
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
a._inited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!a._connection) {
|
|
|
|
a._connection = this._settings.get_connection_by_path(a.connection);
|
|
|
|
|
|
|
|
if (a._connection) {
|
|
|
|
a._type = a._connection._type;
|
|
|
|
a._section = this._ctypes[a._type];
|
|
|
|
} else {
|
|
|
|
a._connection = null;
|
|
|
|
a._type = null;
|
|
|
|
a._section = null;
|
|
|
|
log('Cannot find connection for active (or connection cannot be read)');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a['default'])
|
|
|
|
default_ip4 = a;
|
|
|
|
if (a.default6)
|
|
|
|
default_ip6 = a;
|
2012-06-19 13:50:37 -04:00
|
|
|
|
2013-05-08 17:54:32 -04:00
|
|
|
if (a.state == NetworkManager.ActiveConnectionState.ACTIVATING)
|
2011-01-25 16:08:12 -05:00
|
|
|
activating = a;
|
2013-05-15 11:40:49 -04:00
|
|
|
else if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED)
|
2013-05-08 17:54:32 -04:00
|
|
|
active_any = a;
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
if (!a._primaryDevice) {
|
2013-04-26 21:44:59 -04:00
|
|
|
if (a._type != NetworkManager.SETTING_VPN_SETTING_NAME) {
|
2013-04-29 13:09:01 -04:00
|
|
|
// This list is guaranteed to have one device in it.
|
|
|
|
a._primaryDevice = a.get_devices()[0]._delegate;
|
2013-04-26 21:44:59 -04:00
|
|
|
} else {
|
2012-08-29 10:22:24 -04:00
|
|
|
a._primaryDevice = this._vpnSection;
|
2013-04-26 21:44:59 -04:00
|
|
|
this._vpnSection.addActiveConnection(a);
|
|
|
|
}
|
2011-09-04 15:17:33 -04:00
|
|
|
|
|
|
|
if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED
|
|
|
|
&& a._primaryDevice && a._primaryDevice._notification) {
|
|
|
|
a._primaryDevice._notification.destroy();
|
|
|
|
a._primaryDevice._notification = null;
|
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-08 17:54:32 -04:00
|
|
|
this._mainConnection = activating || default_ip4 || default_ip6 || active_any || null;
|
2013-04-29 15:20:45 -04:00
|
|
|
|
|
|
|
if (this._mainConnection) {
|
|
|
|
let dev = this._mainConnection._primaryDevice;
|
|
|
|
this._mainConnectionIconChangedId = dev.connect('icon-changed', Lang.bind(this, this._updateIcon));
|
2013-07-03 13:47:21 -04:00
|
|
|
this._updateIcon();
|
2013-04-29 15:20:45 -04:00
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
2011-09-04 15:17:33 -04:00
|
|
|
_notifyActivated: function(activeConnection) {
|
|
|
|
if (activeConnection.state == NetworkManager.ActiveConnectionState.ACTIVATED
|
|
|
|
&& activeConnection._primaryDevice && activeConnection._primaryDevice._notification) {
|
|
|
|
activeConnection._primaryDevice._notification.destroy();
|
|
|
|
activeConnection._primaryDevice._notification = null;
|
|
|
|
}
|
|
|
|
|
2013-07-03 13:47:21 -04:00
|
|
|
this._syncActiveConnections();
|
2011-09-04 15:17:33 -04:00
|
|
|
},
|
|
|
|
|
2012-08-21 10:55:40 -04:00
|
|
|
_ignoreConnection: function(connection) {
|
|
|
|
let setting = connection.get_setting_connection();
|
|
|
|
if (!setting)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Ignore slave connections
|
|
|
|
if (setting.get_master())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2013-04-25 16:24:14 -04:00
|
|
|
_addConnection: function(connection) {
|
2012-08-21 10:55:40 -04:00
|
|
|
if (this._ignoreConnection(connection))
|
|
|
|
return;
|
2012-05-31 13:13:16 -04:00
|
|
|
if (connection._updatedId) {
|
2011-01-25 16:08:12 -05:00
|
|
|
// connection was already seen
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
connection._removedId = connection.connect('removed', Lang.bind(this, this._connectionRemoved));
|
|
|
|
connection._updatedId = connection.connect('updated', Lang.bind(this, this._updateConnection));
|
|
|
|
|
|
|
|
this._updateConnection(connection);
|
|
|
|
this._connections.push(connection);
|
2013-04-25 16:24:14 -04:00
|
|
|
},
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-04-25 16:24:14 -04:00
|
|
|
_readConnections: function() {
|
|
|
|
let connections = this._settings.list_connections();
|
|
|
|
connections.forEach(Lang.bind(this, this._addConnection));
|
|
|
|
},
|
|
|
|
|
|
|
|
_newConnection: function(settings, connection) {
|
|
|
|
this._addConnection(connection);
|
2013-07-03 13:47:21 -04:00
|
|
|
this._syncActiveConnections();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_connectionRemoved: function(connection) {
|
|
|
|
let pos = this._connections.indexOf(connection);
|
|
|
|
if (pos != -1)
|
2013-04-26 01:34:50 -04:00
|
|
|
this._connections.splice(connection, 1);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
let section = connection._section;
|
2011-03-26 13:38:20 -04:00
|
|
|
|
2013-05-22 17:35:29 -04:00
|
|
|
if (section == NMConnectionCategory.INVALID)
|
|
|
|
return;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2013-06-12 16:05:31 -04:00
|
|
|
if (section == NMConnectionCategory.VPN) {
|
2013-05-22 17:35:29 -04:00
|
|
|
this._vpnSection.removeConnection(connection);
|
|
|
|
} else {
|
|
|
|
let devices = this._devices[section].devices;
|
|
|
|
for (let i = 0; i < devices.length; i++)
|
|
|
|
devices[i].removeConnection(connection);
|
2012-12-04 08:49:34 -05:00
|
|
|
}
|
|
|
|
|
2011-01-25 16:08:12 -05:00
|
|
|
connection.disconnect(connection._removedId);
|
|
|
|
connection.disconnect(connection._updatedId);
|
2012-05-31 13:13:16 -04:00
|
|
|
connection._removedId = connection._updatedId = 0;
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateConnection: function(connection) {
|
|
|
|
let connectionSettings = connection.get_setting_by_name(NetworkManager.SETTING_CONNECTION_SETTING_NAME);
|
|
|
|
connection._type = connectionSettings.type;
|
2011-03-26 13:38:20 -04:00
|
|
|
connection._section = this._ctypes[connection._type] || NMConnectionCategory.INVALID;
|
2011-01-25 16:08:12 -05:00
|
|
|
connection._timestamp = connectionSettings.timestamp;
|
|
|
|
|
|
|
|
let section = connection._section;
|
2011-03-26 13:38:20 -04:00
|
|
|
|
2013-05-22 17:35:29 -04:00
|
|
|
if (section == NMConnectionCategory.INVALID)
|
|
|
|
return;
|
|
|
|
|
2013-06-12 16:05:31 -04:00
|
|
|
if (section == NMConnectionCategory.VPN) {
|
2012-08-29 10:22:24 -04:00
|
|
|
this._vpnSection.checkConnection(connection);
|
2011-01-25 16:08:12 -05:00
|
|
|
} else {
|
|
|
|
let devices = this._devices[section].devices;
|
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
devices[i].checkConnection(connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_hideDevices: function() {
|
|
|
|
this._devicesHidden = true;
|
|
|
|
|
|
|
|
for (let category in this._devices)
|
|
|
|
this._devices[category].section.actor.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
_showNormal: function() {
|
|
|
|
if (!this._devicesHidden) // nothing to do
|
|
|
|
return;
|
|
|
|
this._devicesHidden = false;
|
|
|
|
|
|
|
|
this._statusSection.actor.hide();
|
|
|
|
|
2012-05-18 12:34:07 -04:00
|
|
|
this._syncSectionTitle(NMConnectionCategory.WIRED);
|
|
|
|
this._syncSectionTitle(NMConnectionCategory.WIRELESS);
|
|
|
|
this._syncSectionTitle(NMConnectionCategory.WWAN);
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_syncNMState: function() {
|
2012-08-26 10:05:46 -04:00
|
|
|
this.mainIcon.visible = this._client.manager_running;
|
2012-09-01 08:42:53 -04:00
|
|
|
this.actor.visible = this.mainIcon.visible;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
if (!this._client.networking_enabled) {
|
2012-05-30 09:58:37 -04:00
|
|
|
this.setIcon('network-offline-symbolic');
|
2011-01-25 16:08:12 -05:00
|
|
|
this._hideDevices();
|
|
|
|
this._statusItem.label.text = _("Networking is disabled");
|
|
|
|
this._statusSection.actor.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._showNormal();
|
2013-07-03 13:47:21 -04:00
|
|
|
this._syncActiveConnections();
|
2011-01-25 16:08:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateIcon: function() {
|
|
|
|
let hasApIcon = false;
|
|
|
|
let hasMobileIcon = false;
|
|
|
|
|
2013-04-29 15:20:45 -04:00
|
|
|
if (!this._mainConnection) {
|
2012-05-30 09:58:37 -04:00
|
|
|
this.setIcon('network-offline-symbolic');
|
2011-01-25 16:08:12 -05:00
|
|
|
} else {
|
2013-04-29 15:20:45 -04:00
|
|
|
let dev = this._mainConnection._primaryDevice;
|
|
|
|
if (!dev) {
|
|
|
|
log('Active connection with no primary device?');
|
|
|
|
return;
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2013-04-29 15:20:45 -04:00
|
|
|
this.setIcon(dev.getIndicatorIcon());
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
|
2013-04-29 15:20:45 -04:00
|
|
|
this._vpnIcon.icon_name = this._vpnSection.getIndicatorIcon();
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2011-11-20 09:38:48 -05:00
|
|
|
});
|