2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported NMApplet */
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Clutter, Gio, GLib, GObject, NM, St } = imports.gi;
|
2011-01-25 21:08:12 +00:00
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2014-01-28 22:18:10 +00:00
|
|
|
const Animation = imports.ui.animation;
|
2011-01-25 21:08:12 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
2013-06-12 04:03:36 +00:00
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
2011-01-25 21:08:12 +00:00
|
|
|
const ModemManager = imports.misc.modemManager;
|
2014-01-28 22:18:10 +00:00
|
|
|
const Rfkill = imports.ui.status.rfkill;
|
2011-01-25 21:08:12 +00:00
|
|
|
const Util = imports.misc.util;
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2011-01-25 21:08:12 +00:00
|
|
|
const NMConnectionCategory = {
|
2011-03-26 17:38:20 +00:00
|
|
|
INVALID: 'invalid',
|
2014-01-23 19:25:06 +00:00
|
|
|
WIRED: 'wired',
|
2011-01-25 21:08:12 +00:00
|
|
|
WIRELESS: 'wireless',
|
|
|
|
WWAN: 'wwan',
|
2019-08-20 21:43:54 +00:00
|
|
|
VPN: 'vpn',
|
2011-01-25 21:08:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const NMAccessPointSecurity = {
|
|
|
|
NONE: 1,
|
|
|
|
WEP: 2,
|
2011-05-03 17:21:45 +00:00
|
|
|
WPA_PSK: 3,
|
|
|
|
WPA2_PSK: 4,
|
|
|
|
WPA_ENT: 5,
|
2019-08-20 21:43:54 +00:00
|
|
|
WPA2_ENT: 6,
|
2011-01-25 21:08:12 +00:00
|
|
|
};
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var MAX_DEVICE_ITEMS = 4;
|
2016-05-13 17:42:04 +00:00
|
|
|
|
2011-01-25 21:08:12 +00:00
|
|
|
// small optimization, to avoid using [] all the time
|
2017-10-31 10:38:20 +00:00
|
|
|
const NM80211Mode = NM['80211Mode'];
|
|
|
|
const NM80211ApFlags = NM['80211ApFlags'];
|
|
|
|
const NM80211ApSecurityFlags = NM['80211ApSecurityFlags'];
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var PortalHelperResult = {
|
2014-02-17 17:06:35 +00:00
|
|
|
CANCELLED: 0,
|
|
|
|
COMPLETED: 1,
|
2019-08-20 21:43:54 +00:00
|
|
|
RECHECK: 2,
|
2014-02-17 17:06:35 +00:00
|
|
|
};
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const PortalHelperIface = loadInterfaceXML('org.gnome.Shell.PortalHelper');
|
2014-02-17 17:06:35 +00:00
|
|
|
const PortalHelperProxy = Gio.DBusProxy.makeProxyWrapper(PortalHelperIface);
|
|
|
|
|
2011-01-25 21:08:12 +00:00
|
|
|
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 18:05:53 +00:00
|
|
|
function ssidToLabel(ssid) {
|
2017-10-31 10:38:20 +00:00
|
|
|
let label = NM.utils_ssid_to_utf8(ssid.get_data());
|
2011-08-03 18:05:53 +00:00
|
|
|
if (!label)
|
|
|
|
label = _("<unknown>");
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2019-02-04 11:30:53 +00:00
|
|
|
function ensureActiveConnectionProps(active) {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (!active._primaryDevice) {
|
2019-06-21 09:47:40 +00:00
|
|
|
let devices = active.get_devices();
|
|
|
|
if (devices.length > 0) {
|
|
|
|
// This list is guaranteed to have at most one device in it.
|
|
|
|
let device = devices[0]._delegate;
|
|
|
|
active._primaryDevice = device;
|
|
|
|
}
|
2013-10-03 12:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NMConnectionItem = class {
|
|
|
|
constructor(section, connection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
this._section = section;
|
|
|
|
this._connection = connection;
|
|
|
|
this._activeConnection = null;
|
|
|
|
this._activeConnectionChangedId = 0;
|
2011-03-25 15:27:56 +00:00
|
|
|
|
2014-02-08 14:02:05 +00:00
|
|
|
this._buildUI();
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-08 14:02:05 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_buildUI() {
|
2013-04-29 19:11:14 +00:00
|
|
|
this.labelItem = new PopupMenu.PopupMenuItem('');
|
2017-12-02 00:27:35 +00:00
|
|
|
this.labelItem.connect('activate', this._toggle.bind(this));
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2014-02-08 14:02:05 +00:00
|
|
|
this.radioItem = new PopupMenu.PopupMenuItem(this._connection.get_id(), false);
|
2017-12-02 00:27:35 +00:00
|
|
|
this.radioItem.connect('activate', this._activate.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2013-04-29 19:11:14 +00:00
|
|
|
this.labelItem.destroy();
|
2014-02-08 14:02:05 +00:00
|
|
|
this.radioItem.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
updateForConnection(connection) {
|
2014-02-08 13:32:23 +00:00
|
|
|
// connection should always be the same object
|
|
|
|
// (and object path) as this._connection, but
|
|
|
|
// this can be false if NetworkManager was restarted
|
|
|
|
// and picked up connections in a different order
|
|
|
|
// Just to be safe, we set it here again
|
|
|
|
|
|
|
|
this._connection = connection;
|
2014-02-08 14:02:05 +00:00
|
|
|
this.radioItem.label.text = connection.get_id();
|
2014-02-08 13:32:23 +00:00
|
|
|
this._sync();
|
|
|
|
this.emit('name-changed');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-08 13:32:23 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getName() {
|
2013-08-19 21:07:37 +00:00
|
|
|
return this._connection.get_id();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-03-25 15:27:56 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
isActive() {
|
2013-06-12 00:13:37 +00:00
|
|
|
if (this._activeConnection == null)
|
|
|
|
return false;
|
2011-03-25 15:27:56 +00:00
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
return this._activeConnection.state <= NM.ActiveConnectionState.ACTIVATED;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2013-04-29 19:11:14 +00:00
|
|
|
let isActive = this.isActive();
|
2014-01-28 20:30:28 +00:00
|
|
|
this.labelItem.label.text = isActive ? _("Turn Off") : this._section.getConnectLabel();
|
2014-02-08 14:02:05 +00:00
|
|
|
this.radioItem.setOrnament(isActive ? PopupMenu.Ornament.DOT : PopupMenu.Ornament.NONE);
|
2013-06-12 00:13:37 +00:00
|
|
|
this.emit('icon-changed');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_toggle() {
|
2013-06-12 00:13:37 +00:00
|
|
|
if (this._activeConnection == null)
|
|
|
|
this._section.activateConnection(this._connection);
|
2011-04-07 21:21:08 +00:00
|
|
|
else
|
2013-06-12 00:13:37 +00:00
|
|
|
this._section.deactivateConnection(this._activeConnection);
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2013-06-12 00:13:37 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_activate() {
|
2014-02-08 14:02:05 +00:00
|
|
|
if (this._activeConnection == null)
|
|
|
|
this._section.activateConnection(this._connection);
|
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_connectionStateChanged(_ac, _newstate, _reason) {
|
2013-06-12 00:13:37 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setActiveConnection(activeConnection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
if (this._activeConnectionChangedId > 0) {
|
|
|
|
this._activeConnection.disconnect(this._activeConnectionChangedId);
|
|
|
|
this._activeConnectionChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._activeConnection = activeConnection;
|
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
if (this._activeConnection) {
|
2013-08-19 21:38:59 +00:00
|
|
|
this._activeConnectionChangedId = this._activeConnection.connect('notify::state',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._connectionStateChanged.bind(this));
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2013-06-12 00:13:37 +00:00
|
|
|
Signals.addSignalMethods(NMConnectionItem.prototype);
|
|
|
|
|
2019-04-18 20:55:34 +00:00
|
|
|
var NMConnectionSection = class NMConnectionSection {
|
2017-10-31 01:19:44 +00:00
|
|
|
constructor(client) {
|
2019-04-18 20:55:34 +00:00
|
|
|
if (this.constructor === NMConnectionSection)
|
2020-02-14 15:10:34 +00:00
|
|
|
throw new TypeError('Cannot instantiate abstract type %s'.format(this.constructor.name));
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2013-04-26 23:28:48 +00:00
|
|
|
this._client = client;
|
|
|
|
|
2014-01-14 22:49:47 +00:00
|
|
|
this._connectionItems = new Map();
|
2013-04-26 23:28:48 +00:00
|
|
|
this._connections = [];
|
|
|
|
|
2013-04-29 19:11:14 +00:00
|
|
|
this._labelSection = new PopupMenu.PopupMenuSection();
|
2014-02-08 14:02:05 +00:00
|
|
|
this._radioSection = new PopupMenu.PopupMenuSection();
|
2013-04-26 23:28:48 +00:00
|
|
|
|
2013-04-29 19:11:14 +00:00
|
|
|
this.item = new PopupMenu.PopupSubMenuMenuItem('', true);
|
|
|
|
this.item.menu.addMenuItem(this._labelSection);
|
2014-02-08 14:02:05 +00:00
|
|
|
this.item.menu.addMenuItem(this._radioSection);
|
2013-04-26 23:28:48 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._notifyConnectivityId = this._client.connect('notify::connectivity', this._iconChanged.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2014-03-15 11:40:13 +00:00
|
|
|
if (this._notifyConnectivityId != 0) {
|
|
|
|
this._client.disconnect(this._notifyConnectivityId);
|
|
|
|
this._notifyConnectivityId = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-02 22:11:48 +00:00
|
|
|
this.item.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_iconChanged() {
|
2014-03-15 11:40:13 +00:00
|
|
|
this._sync();
|
|
|
|
this.emit('icon-changed');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-03-15 11:40:13 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2014-01-14 22:49:47 +00:00
|
|
|
let nItems = this._connectionItems.size;
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
this._radioSection.actor.visible = nItems > 1;
|
|
|
|
this._labelSection.actor.visible = nItems == 1;
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2015-08-06 09:19:37 +00:00
|
|
|
this.item.label.text = this._getStatus();
|
2013-04-29 19:11:14 +00:00
|
|
|
this.item.icon.icon_name = this._getMenuIcon();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMenuIcon() {
|
2014-01-29 21:46:37 +00:00
|
|
|
return this.getIndicatorIcon();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-29 21:46:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getConnectLabel() {
|
2014-01-28 20:30:28 +00:00
|
|
|
return _("Connect");
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-28 20:30:28 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_connectionValid(_connection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectionSortFunction(one, two) {
|
2014-02-08 13:33:32 +00:00
|
|
|
return GLib.utf8_collate(one.get_id(), two.get_id());
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_makeConnectionItem(connection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
return new NMConnectionItem(this, connection);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
checkConnection(connection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
if (!this._connectionValid(connection))
|
|
|
|
return;
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2019-05-15 19:32:29 +00:00
|
|
|
// This function is called every time the connection is added or updated.
|
2014-02-08 13:32:23 +00:00
|
|
|
// In the usual case, we already added this connection and UUID
|
|
|
|
// didn't change. So we need to check if we already have an item,
|
|
|
|
// and update it for properties in the connection that changed
|
|
|
|
// (the only one we care about is the name)
|
|
|
|
// But it's also possible we didn't know about this connection
|
|
|
|
// (eg, during coldplug, or because it was updated and suddenly
|
2019-05-15 19:32:29 +00:00
|
|
|
// it's valid for this device), in which case we add a new item.
|
2014-02-08 13:32:23 +00:00
|
|
|
|
|
|
|
let item = this._connectionItems.get(connection.get_uuid());
|
|
|
|
if (item)
|
2017-02-13 13:52:23 +00:00
|
|
|
this._updateForConnection(item, connection);
|
2014-02-08 13:32:23 +00:00
|
|
|
else
|
|
|
|
this._addConnection(connection);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateForConnection(item, connection) {
|
2017-02-13 13:52:23 +00:00
|
|
|
let pos = this._connections.indexOf(connection);
|
|
|
|
|
|
|
|
this._connections.splice(pos, 1);
|
2017-12-02 00:27:35 +00:00
|
|
|
pos = Util.insertSorted(this._connections, connection, this._connectionSortFunction.bind(this));
|
2017-02-13 13:52:23 +00:00
|
|
|
this._labelSection.moveMenuItem(item.labelItem, pos);
|
|
|
|
this._radioSection.moveMenuItem(item.radioItem, pos);
|
|
|
|
|
|
|
|
item.updateForConnection(connection);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-13 13:52:23 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_addConnection(connection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
let item = this._makeConnectionItem(connection);
|
|
|
|
if (!item)
|
|
|
|
return;
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2019-01-28 00:42:00 +00:00
|
|
|
item.connect('icon-changed', () => this._iconChanged());
|
2019-08-20 00:20:08 +00:00
|
|
|
item.connect('activation-failed', (o, reason) => {
|
2013-06-12 00:13:37 +00:00
|
|
|
this.emit('activation-failed', reason);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-12-02 00:27:35 +00:00
|
|
|
item.connect('name-changed', this._sync.bind(this));
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
let pos = Util.insertSorted(this._connections, connection, this._connectionSortFunction.bind(this));
|
2013-04-29 19:11:14 +00:00
|
|
|
this._labelSection.addMenuItem(item.labelItem, pos);
|
2014-02-08 14:02:05 +00:00
|
|
|
this._radioSection.addMenuItem(item.radioItem, pos);
|
2013-06-12 00:13:37 +00:00
|
|
|
this._connectionItems.set(connection.get_uuid(), item);
|
2013-04-29 19:11:14 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
removeConnection(connection) {
|
2014-03-08 18:54:09 +00:00
|
|
|
let uuid = connection.get_uuid();
|
|
|
|
let item = this._connectionItems.get(uuid);
|
|
|
|
if (item == undefined)
|
|
|
|
return;
|
|
|
|
|
|
|
|
item.destroy();
|
|
|
|
this._connectionItems.delete(uuid);
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2013-06-12 00:13:37 +00:00
|
|
|
let pos = this._connections.indexOf(connection);
|
2012-08-29 14:22:24 +00:00
|
|
|
this._connections.splice(pos, 1);
|
2013-04-29 19:11:14 +00:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2013-06-12 00:13:37 +00:00
|
|
|
Signals.addSignalMethods(NMConnectionSection.prototype);
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2019-04-18 20:55:34 +00:00
|
|
|
var NMConnectionDevice = class NMConnectionDevice extends NMConnectionSection {
|
2017-10-31 01:19:44 +00:00
|
|
|
constructor(client, device) {
|
|
|
|
super(client);
|
2019-04-18 20:55:34 +00:00
|
|
|
|
|
|
|
if (this.constructor === NMConnectionDevice)
|
2020-02-14 15:10:34 +00:00
|
|
|
throw new TypeError('Cannot instantiate abstract type %s'.format(this.constructor.name));
|
2019-04-18 20:55:34 +00:00
|
|
|
|
2013-06-12 00:13:37 +00:00
|
|
|
this._device = device;
|
2015-08-06 09:19:37 +00:00
|
|
|
this._description = '';
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._autoConnectItem = this.item.menu.addAction(_("Connect"), this._autoConnect.bind(this));
|
|
|
|
this._deactivateItem = this._radioSection.addAction(_("Turn Off"), this.deactivateConnection.bind(this));
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._stateChangedId = this._device.connect('state-changed', this._deviceStateChanged.bind(this));
|
|
|
|
this._activeConnectionChangedId = this._device.connect('notify::active-connection', this._activeConnectionChanged.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_canReachInternet() {
|
2014-02-03 23:04:43 +00:00
|
|
|
if (this._client.primary_connection != this._device.active_connection)
|
|
|
|
return true;
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
return this._client.connectivity == NM.ConnectivityState.FULL;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-03 23:04:43 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_autoConnect() {
|
2017-10-31 10:38:20 +00:00
|
|
|
let connection = new NM.SimpleConnection();
|
|
|
|
this._client.add_and_activate_connection_async(connection, this._device, null, null, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-23 19:25:06 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2013-06-12 00:13:37 +00:00
|
|
|
if (this._stateChangedId) {
|
2018-07-24 09:49:00 +00:00
|
|
|
GObject.signal_handler_disconnect(this._device, this._stateChangedId);
|
2013-06-12 00:13:37 +00:00
|
|
|
this._stateChangedId = 0;
|
|
|
|
}
|
|
|
|
if (this._activeConnectionChangedId) {
|
2018-07-24 09:49:00 +00:00
|
|
|
GObject.signal_handler_disconnect(this._device, this._activeConnectionChangedId);
|
2014-01-23 21:11:11 +00:00
|
|
|
this._activeConnectionChangedId = 0;
|
2012-10-03 21:38:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
super.destroy();
|
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_activeConnectionChanged() {
|
2013-04-29 19:11:14 +00:00
|
|
|
if (this._activeConnection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
let item = this._connectionItems.get(this._activeConnection.connection.get_uuid());
|
2013-04-29 19:11:14 +00:00
|
|
|
item.setActiveConnection(null);
|
2017-10-31 10:38:20 +00:00
|
|
|
this._activeConnection = null;
|
2013-04-29 19:11:14 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_deviceStateChanged(device, newstate, oldstate, reason) {
|
2013-06-12 00:13:37 +00:00
|
|
|
if (newstate == oldstate) {
|
|
|
|
log('device emitted state-changed without actually changing state');
|
|
|
|
return;
|
|
|
|
}
|
2012-12-04 13:49:34 +00:00
|
|
|
|
2013-06-12 00:13:37 +00: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 */
|
2017-10-31 10:38:20 +00:00
|
|
|
if (newstate == NM.DeviceState.FAILED &&
|
2019-08-20 00:51:42 +00:00
|
|
|
reason != NM.DeviceStateReason.NO_SECRETS)
|
2013-06-12 00:13:37 +00:00
|
|
|
this.emit('activation-failed', reason);
|
|
|
|
|
2013-04-29 19:11:14 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectionValid(connection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
return this._device.connection_valid(connection);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
activateConnection(connection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
this._client.activate_connection_async(connection, this._device, null, null, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
deactivateConnection(_activeConnection) {
|
2013-06-12 00:13:37 +00:00
|
|
|
this._device.disconnect(null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-12-04 13:49:34 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setDeviceDescription(desc) {
|
2013-07-17 05:01:44 +00:00
|
|
|
this._description = desc;
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-07-17 05:01:44 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getDescription() {
|
2013-07-17 05:01:44 +00:00
|
|
|
return this._description;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2014-01-14 22:49:47 +00:00
|
|
|
let nItems = this._connectionItems.size;
|
2019-08-19 19:38:51 +00:00
|
|
|
this._autoConnectItem.visible = nItems == 0;
|
2019-04-12 21:00:49 +00:00
|
|
|
this._deactivateItem.visible = this._device.state > NM.DeviceState.DISCONNECTED;
|
2017-10-31 10:38:20 +00:00
|
|
|
|
|
|
|
if (this._activeConnection == null) {
|
2018-08-16 10:59:36 +00:00
|
|
|
let activeConnection = this._device.active_connection;
|
|
|
|
if (activeConnection && activeConnection.connection) {
|
|
|
|
let item = this._connectionItems.get(activeConnection.connection.get_uuid());
|
|
|
|
if (item) {
|
|
|
|
this._activeConnection = activeConnection;
|
2019-02-04 11:30:53 +00:00
|
|
|
ensureActiveConnectionProps(this._activeConnection);
|
2018-08-16 10:59:36 +00:00
|
|
|
item.setActiveConnection(this._activeConnection);
|
|
|
|
}
|
2017-10-31 10:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
super._sync();
|
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getStatus() {
|
2013-06-11 23:56:17 +00:00
|
|
|
if (!this._device)
|
2013-08-19 21:14:15 +00:00
|
|
|
return '';
|
2012-12-04 13:49:34 +00:00
|
|
|
|
2019-01-29 01:27:05 +00:00
|
|
|
switch (this._device.state) {
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.DISCONNECTED:
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Off").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.ACTIVATED:
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Connected").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.UNMANAGED:
|
2011-05-09 14:15:03 +00:00
|
|
|
/* Translators: this is for network devices that are physically present but are not
|
2015-08-06 09:19:37 +00:00
|
|
|
under NetworkManager's control (and thus cannot be used in the menu);
|
|
|
|
%s is a network identifier */
|
|
|
|
return _("%s Unmanaged").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.DEACTIVATING:
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Disconnecting").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.PREPARE:
|
|
|
|
case NM.DeviceState.CONFIG:
|
|
|
|
case NM.DeviceState.IP_CONFIG:
|
|
|
|
case NM.DeviceState.IP_CHECK:
|
|
|
|
case NM.DeviceState.SECONDARIES:
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Connecting").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.NEED_AUTH:
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: this is for network connections that require some kind of key or password; %s is a network identifier */
|
2015-08-20 15:07:46 +00:00
|
|
|
return _("%s Requires Authentication").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.UNAVAILABLE:
|
2011-03-25 16:10:38 +00:00
|
|
|
// This state is actually a compound of various states (generically unavailable,
|
2013-06-12 18:38:20 +00:00
|
|
|
// firmware missing), that are exposed by different properties (whose state may
|
|
|
|
// or may not updated when we receive state-changed).
|
2013-06-11 23:56:17 +00:00
|
|
|
if (this._device.firmware_missing) {
|
2011-03-25 16:10:38 +00:00
|
|
|
/* Translators: this is for devices that require some kind of firmware or kernel
|
2015-08-06 09:19:37 +00:00
|
|
|
module, which is missing; %s is a network identifier */
|
2015-08-20 15:07:46 +00:00
|
|
|
return _("Firmware Missing For %s").format(this._getDescription());
|
2011-03-25 16:10:38 +00:00
|
|
|
}
|
|
|
|
/* Translators: this is for a network device that cannot be activated (for example it
|
2015-08-06 09:19:37 +00:00
|
|
|
is disabled by rfkill, or it has no coverage; %s is a network identifier */
|
|
|
|
return _("%s Unavailable").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.DeviceState.FAILED:
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
2015-08-20 15:07:46 +00:00
|
|
|
return _("%s Connection Failed").format(this._getDescription());
|
2011-01-25 21:08:12 +00:00
|
|
|
default:
|
2013-06-11 23:56:17 +00:00
|
|
|
log('Device state invalid, is %d'.format(this._device.state));
|
2011-01-25 21:08:12 +00:00
|
|
|
return 'invalid';
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2014-01-23 19:25:06 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NMDeviceWired = class extends NMConnectionDevice {
|
|
|
|
constructor(client, device) {
|
|
|
|
super(client, device);
|
2014-01-23 19:25:06 +00:00
|
|
|
|
2017-08-19 16:08:28 +00:00
|
|
|
this.item.menu.addSettingsAction(_("Wired Settings"), 'gnome-network-panel.desktop');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
return NMConnectionCategory.WIRED;
|
|
|
|
}
|
2014-01-23 19:25:06 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_hasCarrier() {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (this._device instanceof NM.DeviceEthernet)
|
2014-01-28 22:41:13 +00:00
|
|
|
return this._device.carrier;
|
|
|
|
else
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-23 19:25:06 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2019-04-12 21:00:49 +00:00
|
|
|
this.item.visible = this._hasCarrier();
|
2017-10-31 01:19:44 +00:00
|
|
|
super._sync();
|
|
|
|
}
|
2014-01-23 19:25:06 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getIndicatorIcon() {
|
2014-01-29 21:46:37 +00:00
|
|
|
if (this._device.active_connection) {
|
|
|
|
let state = this._device.active_connection.state;
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
if (state == NM.ActiveConnectionState.ACTIVATING) {
|
2014-01-29 21:46:37 +00:00
|
|
|
return 'network-wired-acquiring-symbolic';
|
2017-10-31 10:38:20 +00:00
|
|
|
} else if (state == NM.ActiveConnectionState.ACTIVATED) {
|
2014-02-03 23:04:43 +00:00
|
|
|
if (this._canReachInternet())
|
|
|
|
return 'network-wired-symbolic';
|
|
|
|
else
|
|
|
|
return 'network-wired-no-route-symbolic';
|
|
|
|
} else {
|
2014-01-29 21:46:37 +00:00
|
|
|
return 'network-wired-disconnected-symbolic';
|
2014-02-03 23:04:43 +00:00
|
|
|
}
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2014-01-23 19:25:06 +00:00
|
|
|
return 'network-wired-disconnected-symbolic';
|
2019-01-29 21:02:57 +00:00
|
|
|
}
|
2014-01-23 19:25:06 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NMDeviceModem = class extends NMConnectionDevice {
|
|
|
|
constructor(client, device) {
|
|
|
|
super(client, device);
|
2013-10-02 17:39:58 +00:00
|
|
|
|
2017-08-19 16:08:28 +00:00
|
|
|
this.item.menu.addSettingsAction(_("Mobile Broadband Settings"), 'gnome-network-panel.desktop');
|
2013-10-02 17:39:58 +00:00
|
|
|
|
2013-06-12 00:13:37 +00:00
|
|
|
this._mobileDevice = null;
|
|
|
|
|
|
|
|
let capabilities = device.current_capabilities;
|
|
|
|
if (device.udi.indexOf('/org/freedesktop/ModemManager1/Modem') == 0)
|
|
|
|
this._mobileDevice = new ModemManager.BroadbandModem(device.udi, capabilities);
|
2017-10-31 10:38:20 +00:00
|
|
|
else if (capabilities & NM.DeviceModemCapabilities.GSM_UMTS)
|
2013-06-12 00:13:37 +00:00
|
|
|
this._mobileDevice = new ModemManager.ModemGsm(device.udi);
|
2017-10-31 10:38:20 +00:00
|
|
|
else if (capabilities & NM.DeviceModemCapabilities.CDMA_EVDO)
|
2013-06-12 00:13:37 +00:00
|
|
|
this._mobileDevice = new ModemManager.ModemCdma(device.udi);
|
2017-10-31 10:38:20 +00:00
|
|
|
else if (capabilities & NM.DeviceModemCapabilities.LTE)
|
2013-06-12 00:13:37 +00:00
|
|
|
this._mobileDevice = new ModemManager.ModemGsm(device.udi);
|
|
|
|
|
|
|
|
if (this._mobileDevice) {
|
2017-12-02 00:27:35 +00:00
|
|
|
this._operatorNameId = this._mobileDevice.connect('notify::operator-name', this._sync.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
this._signalQualityId = this._mobileDevice.connect('notify::signal-quality', () => {
|
2014-03-15 11:40:13 +00:00
|
|
|
this._iconChanged();
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
return NMConnectionCategory.WWAN;
|
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_autoConnect() {
|
2013-04-29 19:11:14 +00:00
|
|
|
Util.spawn(['gnome-control-center', 'network',
|
|
|
|
'connect-3g', this._device.get_path()]);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2011-01-25 21:08:12 +00:00
|
|
|
if (this._operatorNameId) {
|
2013-06-12 00:13:37 +00:00
|
|
|
this._mobileDevice.disconnect(this._operatorNameId);
|
2011-01-25 21:08:12 +00:00
|
|
|
this._operatorNameId = 0;
|
|
|
|
}
|
|
|
|
if (this._signalQualityId) {
|
2013-06-12 00:13:37 +00:00
|
|
|
this._mobileDevice.disconnect(this._signalQualityId);
|
2011-01-25 21:08:12 +00:00
|
|
|
this._signalQualityId = 0;
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
super.destroy();
|
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getStatus() {
|
2013-10-03 12:31:58 +00:00
|
|
|
if (!this._client.wwan_hardware_enabled)
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Hardware Disabled").format(this._getDescription());
|
2013-10-03 12:31:58 +00:00
|
|
|
else if (!this._client.wwan_enabled)
|
|
|
|
/* Translators: this is for a network device that cannot be activated
|
2015-08-06 09:19:37 +00:00
|
|
|
because it's disabled by rfkill (airplane mode); %s is a network identifier */
|
|
|
|
return _("%s Disabled").format(this._getDescription());
|
2017-10-31 10:38:20 +00:00
|
|
|
else if (this._device.state == NM.DeviceState.ACTIVATED &&
|
2013-10-03 12:49:21 +00:00
|
|
|
this._mobileDevice && this._mobileDevice.operator_name)
|
|
|
|
return this._mobileDevice.operator_name;
|
2013-10-03 12:31:58 +00:00
|
|
|
else
|
2017-10-31 01:19:44 +00:00
|
|
|
return super._getStatus();
|
|
|
|
}
|
2013-10-03 12:31:58 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getIndicatorIcon() {
|
2014-01-29 21:46:37 +00:00
|
|
|
if (this._device.active_connection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (this._device.active_connection.state == NM.ActiveConnectionState.ACTIVATING)
|
2014-01-29 21:46:37 +00:00
|
|
|
return 'network-cellular-acquiring-symbolic';
|
|
|
|
|
|
|
|
return this._getSignalIcon();
|
|
|
|
} else {
|
2013-04-29 19:11:14 +00:00
|
|
|
return 'network-cellular-signal-none-symbolic';
|
2014-01-29 21:46:37 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getSignalIcon() {
|
2020-02-14 15:10:34 +00:00
|
|
|
return 'network-cellular-signal-%s-symbolic'.format(
|
|
|
|
signalToIcon(this._mobileDevice.signal_quality));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NMDeviceBluetooth = class extends NMConnectionDevice {
|
|
|
|
constructor(client, device) {
|
|
|
|
super(client, device);
|
2013-10-02 17:39:58 +00:00
|
|
|
|
2017-08-19 16:08:28 +00:00
|
|
|
this.item.menu.addSettingsAction(_("Bluetooth Settings"), 'gnome-network-panel.desktop');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
return NMConnectionCategory.WWAN;
|
|
|
|
}
|
2013-10-02 17:39:58 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getDescription() {
|
2014-01-28 20:30:28 +00:00
|
|
|
return this._device.name;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-28 20:30:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getConnectLabel() {
|
2015-10-23 15:17:51 +00:00
|
|
|
return _("Connect to Internet");
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-28 20:30:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getIndicatorIcon() {
|
2014-01-29 21:46:37 +00:00
|
|
|
if (this._device.active_connection) {
|
|
|
|
let state = this._device.active_connection.state;
|
2017-10-31 10:38:20 +00:00
|
|
|
if (state == NM.ActiveConnectionState.ACTIVATING)
|
2014-01-29 21:46:37 +00:00
|
|
|
return 'network-cellular-acquiring-symbolic';
|
2017-10-31 10:38:20 +00:00
|
|
|
else if (state == NM.ActiveConnectionState.ACTIVATED)
|
2014-01-29 21:46:37 +00:00
|
|
|
return 'network-cellular-connected-symbolic';
|
|
|
|
else
|
|
|
|
return 'network-cellular-signal-none-symbolic';
|
|
|
|
} else {
|
2013-04-29 19:11:14 +00:00
|
|
|
return 'network-cellular-signal-none-symbolic';
|
2014-01-29 21:46:37 +00:00
|
|
|
}
|
2013-04-29 19:11:14 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2019-05-22 16:27:15 +00:00
|
|
|
var NMWirelessDialogItem = GObject.registerClass({
|
|
|
|
Signals: {
|
|
|
|
'selected': {},
|
2019-08-20 21:43:54 +00:00
|
|
|
},
|
2019-05-22 16:27:15 +00:00
|
|
|
}, class NMWirelessDialogItem extends St.BoxLayout {
|
|
|
|
_init(network) {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._network = network;
|
|
|
|
this._ap = network.accessPoints[0];
|
|
|
|
|
2019-05-22 16:27:15 +00:00
|
|
|
super._init({ style_class: 'nm-dialog-item',
|
|
|
|
can_focus: true,
|
|
|
|
reactive: true });
|
|
|
|
|
2013-10-17 17:04:13 +00:00
|
|
|
let action = new Clutter.ClickAction();
|
2019-01-28 00:42:00 +00:00
|
|
|
action.connect('clicked', () => this.grab_key_focus());
|
2019-05-22 16:27:15 +00:00
|
|
|
this.add_action(action);
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
let title = ssidToLabel(this._ap.get_ssid());
|
2019-10-21 18:44:00 +00:00
|
|
|
this._label = new St.Label({
|
|
|
|
text: title,
|
|
|
|
x_expand: true,
|
|
|
|
});
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2019-05-22 16:27:15 +00:00
|
|
|
this.label_actor = this._label;
|
2019-10-21 18:44:00 +00:00
|
|
|
this.add_child(this._label);
|
2013-08-19 14:31:31 +00:00
|
|
|
|
|
|
|
this._selectedIcon = new St.Icon({ style_class: 'nm-dialog-icon',
|
|
|
|
icon_name: 'object-select-symbolic' });
|
2019-05-22 16:27:15 +00:00
|
|
|
this.add(this._selectedIcon);
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2019-10-21 18:44:00 +00:00
|
|
|
this._icons = new St.BoxLayout({
|
|
|
|
style_class: 'nm-dialog-icons',
|
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
});
|
|
|
|
this.add_child(this._icons);
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this._secureIcon = new St.Icon({ style_class: 'nm-dialog-icon' });
|
|
|
|
if (this._ap._secType != NMAccessPointSecurity.NONE)
|
|
|
|
this._secureIcon.icon_name = 'network-wireless-encrypted-symbolic';
|
|
|
|
this._icons.add_actor(this._secureIcon);
|
|
|
|
|
2013-08-19 14:31:31 +00:00
|
|
|
this._signalIcon = new St.Icon({ style_class: 'nm-dialog-icon' });
|
2013-06-12 04:03:36 +00:00
|
|
|
this._icons.add_actor(this._signalIcon);
|
2013-09-20 16:50:36 +00:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-09-20 16:50:36 +00:00
|
|
|
|
2019-09-10 05:42:48 +00:00
|
|
|
vfunc_key_focus_in() {
|
|
|
|
this.emit('selected');
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2013-09-20 16:50:36 +00:00
|
|
|
this._signalIcon.icon_name = this._getSignalIcon();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
updateBestAP(ap) {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._ap = ap;
|
2013-09-20 16:50:36 +00:00
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setActive(isActive) {
|
2013-08-19 14:31:31 +00:00
|
|
|
this._selectedIcon.opacity = isActive ? 255 : 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-08-19 14:31:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getSignalIcon() {
|
2020-02-14 15:10:34 +00:00
|
|
|
if (this._ap.mode == NM80211Mode.ADHOC) {
|
2013-06-12 04:03:36 +00:00
|
|
|
return 'network-workgroup-symbolic';
|
2020-02-14 15:10:34 +00:00
|
|
|
} else {
|
|
|
|
return 'network-wireless-signal-%s-symbolic'.format(
|
|
|
|
signalToIcon(this._ap.strength));
|
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
}
|
2019-05-22 16:27:15 +00:00
|
|
|
});
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2019-05-23 20:45:44 +00:00
|
|
|
var NMWirelessDialog = GObject.registerClass(
|
|
|
|
class NMWirelessDialog extends ModalDialog.ModalDialog {
|
|
|
|
_init(client, device) {
|
|
|
|
super._init({ styleClass: 'nm-dialog' });
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this._client = client;
|
|
|
|
this._device = device;
|
|
|
|
|
2014-01-28 22:18:10 +00:00
|
|
|
this._wirelessEnabledChangedId = this._client.connect('notify::wireless-enabled',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._syncView.bind(this));
|
2014-01-28 22:18:10 +00:00
|
|
|
|
|
|
|
this._rfkill = Rfkill.getRfkillManager();
|
|
|
|
this._airplaneModeChangedId = this._rfkill.connect('airplane-mode-changed',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._syncView.bind(this));
|
2014-01-28 22:18:10 +00:00
|
|
|
|
2013-06-12 04:03:36 +00:00
|
|
|
this._networks = [];
|
|
|
|
this._buildLayout();
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
let connections = client.get_connections();
|
2017-10-31 00:38:18 +00:00
|
|
|
this._connections = connections.filter(
|
|
|
|
connection => device.connection_valid(connection)
|
|
|
|
);
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._apAddedId = device.connect('access-point-added', this._accessPointAdded.bind(this));
|
|
|
|
this._apRemovedId = device.connect('access-point-removed', this._accessPointRemoved.bind(this));
|
|
|
|
this._activeApChangedId = device.connect('notify::active-access-point', this._activeApChanged.bind(this));
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
// accessPointAdded will also create dialog items
|
2019-01-29 01:27:05 +00:00
|
|
|
let accessPoints = device.get_access_points() || [];
|
2017-10-31 00:38:18 +00:00
|
|
|
accessPoints.forEach(ap => {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._accessPointAdded(this._device, ap);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this._selectedNetwork = null;
|
2013-08-19 14:31:31 +00:00
|
|
|
this._activeApChanged();
|
2013-06-12 04:03:36 +00:00
|
|
|
this._updateSensitivity();
|
2014-01-28 22:18:10 +00:00
|
|
|
this._syncView();
|
2014-01-29 21:28:17 +00:00
|
|
|
|
2019-08-19 18:50:33 +00:00
|
|
|
this._scanTimeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 15, this._onScanTimeout.bind(this));
|
2016-06-21 17:48:44 +00:00
|
|
|
GLib.Source.set_name_by_id(this._scanTimeoutId, '[gnome-shell] this._onScanTimeout');
|
|
|
|
this._onScanTimeout();
|
2017-03-14 19:32:50 +00:00
|
|
|
|
|
|
|
let id = Main.sessionMode.connect('updated', () => {
|
|
|
|
if (Main.sessionMode.allowSettings)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Main.sessionMode.disconnect(id);
|
|
|
|
this.close();
|
|
|
|
});
|
2019-05-23 20:45:44 +00:00
|
|
|
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2019-05-23 20:45:44 +00:00
|
|
|
_onDestroy() {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (this._apAddedId) {
|
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._apAddedId);
|
|
|
|
this._apAddedId = 0;
|
|
|
|
}
|
|
|
|
if (this._apRemovedId) {
|
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._apRemovedId);
|
|
|
|
this._apRemovedId = 0;
|
|
|
|
}
|
2013-08-19 14:31:31 +00:00
|
|
|
if (this._activeApChangedId) {
|
|
|
|
GObject.Object.prototype.disconnect.call(this._device, this._activeApChangedId);
|
|
|
|
this._activeApChangedId = 0;
|
|
|
|
}
|
2014-01-28 22:18:10 +00:00
|
|
|
if (this._wirelessEnabledChangedId) {
|
|
|
|
this._client.disconnect(this._wirelessEnabledChangedId);
|
|
|
|
this._wirelessEnabledChangedId = 0;
|
|
|
|
}
|
|
|
|
if (this._airplaneModeChangedId) {
|
|
|
|
this._rfkill.disconnect(this._airplaneModeChangedId);
|
|
|
|
this._airplaneModeChangedId = 0;
|
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2016-06-21 17:48:44 +00:00
|
|
|
if (this._scanTimeoutId) {
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._scanTimeoutId);
|
2016-06-21 17:48:44 +00:00
|
|
|
this._scanTimeoutId = 0;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onScanTimeout() {
|
2017-10-31 10:38:20 +00:00
|
|
|
this._device.request_scan_async(null, null);
|
2016-06-21 17:48:44 +00:00
|
|
|
return GLib.SOURCE_CONTINUE;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-21 17:48:44 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_activeApChanged() {
|
2013-08-19 14:31:31 +00:00
|
|
|
if (this._activeNetwork)
|
|
|
|
this._activeNetwork.item.setActive(false);
|
|
|
|
|
|
|
|
this._activeNetwork = null;
|
|
|
|
if (this._device.active_access_point) {
|
|
|
|
let idx = this._findNetwork(this._device.active_access_point);
|
|
|
|
if (idx >= 0)
|
|
|
|
this._activeNetwork = this._networks[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._activeNetwork)
|
|
|
|
this._activeNetwork.item.setActive(true);
|
|
|
|
this._updateSensitivity();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-08-19 14:31:31 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateSensitivity() {
|
2014-01-28 22:18:10 +00:00
|
|
|
let connectSensitive = this._client.wireless_enabled && this._selectedNetwork && (this._selectedNetwork != this._activeNetwork);
|
2013-06-12 04:03:36 +00:00
|
|
|
this._connectButton.reactive = connectSensitive;
|
|
|
|
this._connectButton.can_focus = connectSensitive;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncView() {
|
2014-01-28 22:18:10 +00:00
|
|
|
if (this._rfkill.airplaneMode) {
|
|
|
|
this._airplaneBox.show();
|
|
|
|
|
|
|
|
this._airplaneIcon.icon_name = 'airplane-mode-symbolic';
|
|
|
|
this._airplaneHeadline.text = _("Airplane Mode is On");
|
|
|
|
this._airplaneText.text = _("Wi-Fi is disabled when airplane mode is on.");
|
|
|
|
this._airplaneButton.label = _("Turn Off Airplane Mode");
|
|
|
|
|
|
|
|
this._airplaneButton.visible = !this._rfkill.hwAirplaneMode;
|
|
|
|
this._airplaneInactive.visible = this._rfkill.hwAirplaneMode;
|
|
|
|
this._noNetworksBox.hide();
|
|
|
|
} else if (!this._client.wireless_enabled) {
|
|
|
|
this._airplaneBox.show();
|
|
|
|
|
|
|
|
this._airplaneIcon.icon_name = 'dialog-information-symbolic';
|
|
|
|
this._airplaneHeadline.text = _("Wi-Fi is Off");
|
|
|
|
this._airplaneText.text = _("Wi-Fi needs to be turned on in order to connect to a network.");
|
|
|
|
this._airplaneButton.label = _("Turn On Wi-Fi");
|
|
|
|
|
|
|
|
this._airplaneButton.show();
|
|
|
|
this._airplaneInactive.hide();
|
|
|
|
this._noNetworksBox.hide();
|
|
|
|
} else {
|
|
|
|
this._airplaneBox.hide();
|
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
this._noNetworksBox.visible = this._networks.length == 0;
|
2014-01-28 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this._noNetworksBox.visible)
|
|
|
|
this._noNetworksSpinner.play();
|
|
|
|
else
|
|
|
|
this._noNetworksSpinner.stop();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-08-12 17:19:32 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_buildLayout() {
|
2013-06-12 04:03:36 +00:00
|
|
|
let headline = new St.BoxLayout({ style_class: 'nm-dialog-header-hbox' });
|
|
|
|
|
|
|
|
let icon = new St.Icon({ style_class: 'nm-dialog-header-icon',
|
|
|
|
icon_name: 'network-wireless-signal-excellent-symbolic' });
|
|
|
|
|
|
|
|
let titleBox = new St.BoxLayout({ vertical: true });
|
|
|
|
let title = new St.Label({ style_class: 'nm-dialog-header',
|
|
|
|
text: _("Wi-Fi Networks") });
|
|
|
|
let subtitle = new St.Label({ style_class: 'nm-dialog-subheader',
|
|
|
|
text: _("Select a network") });
|
|
|
|
titleBox.add(title);
|
|
|
|
titleBox.add(subtitle);
|
|
|
|
|
|
|
|
headline.add(icon);
|
|
|
|
headline.add(titleBox);
|
|
|
|
|
|
|
|
this.contentLayout.style_class = 'nm-dialog-content';
|
|
|
|
this.contentLayout.add(headline);
|
|
|
|
|
2019-10-21 18:44:00 +00:00
|
|
|
this._stack = new St.Widget({
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
|
|
|
y_expand: true,
|
|
|
|
});
|
2013-08-12 17:19:32 +00:00
|
|
|
|
2013-06-12 04:03:36 +00:00
|
|
|
this._itemBox = new St.BoxLayout({ vertical: true });
|
|
|
|
this._scrollView = new St.ScrollView({ style_class: 'nm-dialog-scroll-view' });
|
2013-08-12 17:19:32 +00:00
|
|
|
this._scrollView.set_x_expand(true);
|
|
|
|
this._scrollView.set_y_expand(true);
|
2018-11-27 12:45:36 +00:00
|
|
|
this._scrollView.set_policy(St.PolicyType.NEVER,
|
|
|
|
St.PolicyType.AUTOMATIC);
|
2013-06-12 04:03:36 +00:00
|
|
|
this._scrollView.add_actor(this._itemBox);
|
2013-08-12 17:19:32 +00:00
|
|
|
this._stack.add_child(this._scrollView);
|
|
|
|
|
2014-01-28 22:18:10 +00:00
|
|
|
this._noNetworksBox = new St.BoxLayout({ vertical: true,
|
|
|
|
style_class: 'no-networks-box',
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
|
2018-11-28 15:41:09 +00:00
|
|
|
this._noNetworksSpinner = new Animation.Spinner(16);
|
2019-07-16 09:24:13 +00:00
|
|
|
this._noNetworksBox.add_actor(this._noNetworksSpinner);
|
2014-01-28 22:18:10 +00:00
|
|
|
this._noNetworksBox.add_actor(new St.Label({ style_class: 'no-networks-label',
|
|
|
|
text: _("No Networks") }));
|
|
|
|
this._stack.add_child(this._noNetworksBox);
|
|
|
|
|
|
|
|
this._airplaneBox = new St.BoxLayout({ vertical: true,
|
|
|
|
style_class: 'nm-dialog-airplane-box',
|
2013-08-12 17:19:32 +00:00
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
2014-01-28 22:18:10 +00:00
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
this._airplaneIcon = new St.Icon({ icon_size: 48 });
|
2015-01-16 00:39:52 +00:00
|
|
|
this._airplaneHeadline = new St.Label({ style_class: 'nm-dialog-airplane-headline headline' });
|
2014-01-28 22:18:10 +00:00
|
|
|
this._airplaneText = new St.Label({ style_class: 'nm-dialog-airplane-text' });
|
|
|
|
|
2019-08-19 19:13:01 +00:00
|
|
|
let airplaneSubStack = new St.Widget({ layout_manager: new Clutter.BinLayout() });
|
2015-01-16 14:33:56 +00:00
|
|
|
this._airplaneButton = new St.Button({ style_class: 'modal-dialog-button button' });
|
2017-10-31 00:38:18 +00:00
|
|
|
this._airplaneButton.connect('clicked', () => {
|
2014-01-28 22:18:10 +00:00
|
|
|
if (this._rfkill.airplaneMode)
|
|
|
|
this._rfkill.airplaneMode = false;
|
|
|
|
else
|
|
|
|
this._client.wireless_enabled = true;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2014-01-28 22:18:10 +00:00
|
|
|
airplaneSubStack.add_actor(this._airplaneButton);
|
|
|
|
this._airplaneInactive = new St.Label({ style_class: 'nm-dialog-airplane-text',
|
|
|
|
text: _("Use hardware switch to turn off") });
|
|
|
|
airplaneSubStack.add_actor(this._airplaneInactive);
|
|
|
|
|
2019-10-21 18:44:00 +00:00
|
|
|
this._airplaneBox.add_child(this._airplaneIcon);
|
|
|
|
this._airplaneBox.add_child(this._airplaneHeadline);
|
|
|
|
this._airplaneBox.add_child(this._airplaneText);
|
|
|
|
this._airplaneBox.add_child(airplaneSubStack);
|
2014-01-28 22:18:10 +00:00
|
|
|
this._stack.add_child(this._airplaneBox);
|
2013-08-12 17:19:32 +00:00
|
|
|
|
2019-10-21 18:44:00 +00:00
|
|
|
this.contentLayout.add_child(this._stack);
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._disconnectButton = this.addButton({ action: this.close.bind(this),
|
2013-06-12 04:03:36 +00:00
|
|
|
label: _("Cancel"),
|
2019-11-05 19:37:28 +00:00
|
|
|
key: Clutter.KEY_Escape });
|
2017-12-02 00:27:35 +00:00
|
|
|
this._connectButton = this.addButton({ action: this._connect.bind(this),
|
2013-06-12 04:03:36 +00:00
|
|
|
label: _("Connect"),
|
2019-11-05 19:37:28 +00:00
|
|
|
key: Clutter.KEY_Return });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connect() {
|
2013-06-12 04:03:36 +00:00
|
|
|
let network = this._selectedNetwork;
|
|
|
|
if (network.connections.length > 0) {
|
|
|
|
let connection = network.connections[0];
|
2017-10-31 10:38:20 +00:00
|
|
|
this._client.activate_connection_async(connection, this._device, null, null, null);
|
2013-06-12 04:03:36 +00:00
|
|
|
} else {
|
2014-01-23 19:35:10 +00:00
|
|
|
let accessPoints = network.accessPoints;
|
2019-08-19 19:33:15 +00:00
|
|
|
if ((accessPoints[0]._secType == NMAccessPointSecurity.WPA2_ENT) ||
|
|
|
|
(accessPoints[0]._secType == NMAccessPointSecurity.WPA_ENT)) {
|
2013-06-12 04:03:36 +00:00
|
|
|
// 802.1x-enabled APs require further configuration, so they're
|
|
|
|
// handled in gnome-control-center
|
2017-10-20 13:29:07 +00:00
|
|
|
Util.spawn(['gnome-control-center', 'wifi', 'connect-8021x-wifi',
|
2018-09-18 23:05:42 +00:00
|
|
|
this._device.get_path(), accessPoints[0].get_path()]);
|
2013-06-12 04:03:36 +00:00
|
|
|
} else {
|
2017-10-31 10:38:20 +00:00
|
|
|
let connection = new NM.SimpleConnection();
|
2019-01-29 01:18:52 +00:00
|
|
|
this._client.add_and_activate_connection_async(connection, this._device, accessPoints[0].get_path(), null, null);
|
2013-06-12 04:03:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.close();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_notifySsidCb(accessPoint) {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (accessPoint.get_ssid() != null) {
|
|
|
|
accessPoint.disconnect(accessPoint._notifySsidId);
|
|
|
|
accessPoint._notifySsidId = 0;
|
|
|
|
this._accessPointAdded(this._device, accessPoint);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getApSecurityType(accessPoint) {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (accessPoint._secType)
|
|
|
|
return accessPoint._secType;
|
|
|
|
|
|
|
|
let flags = accessPoint.flags;
|
2019-01-31 13:43:52 +00:00
|
|
|
let wpaFlags = accessPoint.wpa_flags;
|
|
|
|
let rsnFlags = accessPoint.rsn_flags;
|
2013-06-12 04:03:36 +00:00
|
|
|
let type;
|
2019-01-31 13:43:52 +00:00
|
|
|
if (rsnFlags != NM80211ApSecurityFlags.NONE) {
|
2013-06-12 04:03:36 +00:00
|
|
|
/* RSN check first so that WPA+WPA2 APs are treated as RSN/WPA2 */
|
2019-01-31 13:43:52 +00:00
|
|
|
if (rsnFlags & NM80211ApSecurityFlags.KEY_MGMT_802_1X)
|
2019-01-29 20:18:46 +00:00
|
|
|
type = NMAccessPointSecurity.WPA2_ENT;
|
|
|
|
else if (rsnFlags & NM80211ApSecurityFlags.KEY_MGMT_PSK)
|
|
|
|
type = NMAccessPointSecurity.WPA2_PSK;
|
2019-01-31 13:43:52 +00:00
|
|
|
} else if (wpaFlags != NM80211ApSecurityFlags.NONE) {
|
|
|
|
if (wpaFlags & NM80211ApSecurityFlags.KEY_MGMT_802_1X)
|
2013-06-12 04:03:36 +00:00
|
|
|
type = NMAccessPointSecurity.WPA_ENT;
|
2019-01-31 13:43:52 +00:00
|
|
|
else if (wpaFlags & NM80211ApSecurityFlags.KEY_MGMT_PSK)
|
2019-01-29 20:18:46 +00:00
|
|
|
type = NMAccessPointSecurity.WPA_PSK;
|
2013-06-12 04:03:36 +00:00
|
|
|
} else {
|
2019-08-20 02:24:37 +00:00
|
|
|
// eslint-disable-next-line no-lonely-if
|
2013-06-12 04:03:36 +00:00
|
|
|
if (flags & NM80211ApFlags.PRIVACY)
|
|
|
|
type = NMAccessPointSecurity.WEP;
|
|
|
|
else
|
|
|
|
type = NMAccessPointSecurity.NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cache the found value to avoid checking flags all the time
|
|
|
|
accessPoint._secType = type;
|
|
|
|
return type;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_networkSortFunction(one, two) {
|
2013-06-12 04:03:36 +00:00
|
|
|
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;
|
|
|
|
|
2018-03-02 22:31:36 +00:00
|
|
|
let oneAp = one.accessPoints[0] || null;
|
|
|
|
let twoAp = two.accessPoints[0] || null;
|
|
|
|
|
|
|
|
if (oneAp != null && twoAp == null)
|
|
|
|
return -1;
|
|
|
|
else if (oneAp == null && twoAp != null)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
let oneStrength = oneAp.strength;
|
|
|
|
let twoStrength = twoAp.strength;
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
// place stronger connections first
|
|
|
|
if (oneStrength != twoStrength)
|
|
|
|
return oneStrength < twoStrength ? 1 : -1;
|
|
|
|
|
|
|
|
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);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_networkCompare(network, accessPoint) {
|
2019-08-19 17:55:49 +00:00
|
|
|
if (!network.ssid.equal(accessPoint.get_ssid()))
|
2013-06-12 04:03:36 +00:00
|
|
|
return false;
|
|
|
|
if (network.mode != accessPoint.mode)
|
|
|
|
return false;
|
|
|
|
if (network.security != this._getApSecurityType(accessPoint))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_findExistingNetwork(accessPoint) {
|
2013-06-12 04:03:36 +00:00
|
|
|
for (let i = 0; i < this._networks.length; i++) {
|
|
|
|
let network = this._networks[i];
|
|
|
|
for (let j = 0; j < network.accessPoints.length; j++) {
|
|
|
|
if (network.accessPoints[j] == accessPoint)
|
|
|
|
return { network: i, ap: j };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_findNetwork(accessPoint) {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (accessPoint.get_ssid() == null)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._networks.length; i++) {
|
|
|
|
if (this._networkCompare(this._networks[i], accessPoint))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_checkConnections(network, accessPoint) {
|
2017-10-31 00:38:18 +00:00
|
|
|
this._connections.forEach(connection => {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (accessPoint.connection_valid(connection) &&
|
2019-08-20 00:51:42 +00:00
|
|
|
!network.connections.includes(connection))
|
2013-06-12 04:03:36 +00:00
|
|
|
network.connections.push(connection);
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_accessPointAdded(device, accessPoint) {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (accessPoint.get_ssid() == null) {
|
|
|
|
// This access point is not visible yet
|
|
|
|
// Wait for it to get a ssid
|
2017-12-02 00:27:35 +00:00
|
|
|
accessPoint._notifySsidId = accessPoint.connect('notify::ssid', this._notifySsidCb.bind(this));
|
2013-06-12 04:03:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let pos = this._findNetwork(accessPoint);
|
|
|
|
let network;
|
|
|
|
|
|
|
|
if (pos != -1) {
|
|
|
|
network = this._networks[pos];
|
2018-07-14 20:56:22 +00:00
|
|
|
if (network.accessPoints.includes(accessPoint)) {
|
2013-06-12 04:03:36 +00:00
|
|
|
log('Access point was already seen, not adding again');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
Util.insertSorted(network.accessPoints, accessPoint, (one, two) => {
|
2013-06-12 04:03:36 +00:00
|
|
|
return two.strength - one.strength;
|
|
|
|
});
|
|
|
|
network.item.updateBestAP(network.accessPoints[0]);
|
|
|
|
this._checkConnections(network, accessPoint);
|
|
|
|
|
|
|
|
this._resortItems();
|
|
|
|
} else {
|
2019-02-12 14:02:09 +00:00
|
|
|
network = {
|
|
|
|
ssid: accessPoint.get_ssid(),
|
|
|
|
mode: accessPoint.mode,
|
|
|
|
security: this._getApSecurityType(accessPoint),
|
|
|
|
connections: [],
|
|
|
|
item: null,
|
|
|
|
accessPoints: [accessPoint],
|
|
|
|
};
|
2013-06-12 04:03:36 +00:00
|
|
|
network.ssidText = ssidToLabel(network.ssid);
|
|
|
|
this._checkConnections(network, accessPoint);
|
|
|
|
|
|
|
|
let newPos = Util.insertSorted(this._networks, network, this._networkSortFunction);
|
|
|
|
this._createNetworkItem(network);
|
2019-04-12 21:00:49 +00:00
|
|
|
this._itemBox.insert_child_at_index(network.item, newPos);
|
2013-06-12 04:03:36 +00:00
|
|
|
}
|
2013-08-12 17:19:32 +00:00
|
|
|
|
2014-01-28 22:18:10 +00:00
|
|
|
this._syncView();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_accessPointRemoved(device, accessPoint) {
|
2013-06-12 04:03:36 +00:00
|
|
|
let res = this._findExistingNetwork(accessPoint);
|
|
|
|
|
|
|
|
if (res == null) {
|
|
|
|
log('Removing an access point that was never added');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let network = this._networks[res.network];
|
|
|
|
network.accessPoints.splice(res.ap, 1);
|
|
|
|
|
|
|
|
if (network.accessPoints.length == 0) {
|
2019-04-12 21:00:49 +00:00
|
|
|
network.item.destroy();
|
2013-06-12 04:03:36 +00:00
|
|
|
this._networks.splice(res.network, 1);
|
|
|
|
} else {
|
|
|
|
network.item.updateBestAP(network.accessPoints[0]);
|
|
|
|
this._resortItems();
|
|
|
|
}
|
2013-08-12 17:19:32 +00:00
|
|
|
|
2014-01-28 22:18:10 +00:00
|
|
|
this._syncView();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_resortItems() {
|
2013-06-12 04:03:36 +00:00
|
|
|
let adjustment = this._scrollView.vscroll.adjustment;
|
|
|
|
let scrollValue = adjustment.value;
|
|
|
|
|
|
|
|
this._itemBox.remove_all_children();
|
2017-10-31 00:38:18 +00:00
|
|
|
this._networks.forEach(network => {
|
2019-04-12 21:00:49 +00:00
|
|
|
this._itemBox.add_child(network.item);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
adjustment.value = scrollValue;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_selectNetwork(network) {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (this._selectedNetwork)
|
2019-04-12 21:00:49 +00:00
|
|
|
this._selectedNetwork.item.remove_style_pseudo_class('selected');
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this._selectedNetwork = network;
|
|
|
|
this._updateSensitivity();
|
|
|
|
|
|
|
|
if (this._selectedNetwork)
|
2019-04-12 21:00:49 +00:00
|
|
|
this._selectedNetwork.item.add_style_pseudo_class('selected');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createNetworkItem(network) {
|
2013-06-12 04:03:36 +00:00
|
|
|
network.item = new NMWirelessDialogItem(network);
|
2013-08-19 14:31:31 +00:00
|
|
|
network.item.setActive(network == this._selectedNetwork);
|
2017-10-31 00:38:18 +00:00
|
|
|
network.item.connect('selected', () => {
|
2019-04-12 21:00:49 +00:00
|
|
|
Util.ensureActorVisibleInScrollView(this._scrollView, network.item);
|
2013-06-12 04:03:36 +00:00
|
|
|
this._selectNetwork(network);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2019-04-12 21:00:49 +00:00
|
|
|
network.item.connect('destroy', () => {
|
2018-03-02 22:44:44 +00:00
|
|
|
let keyFocus = global.stage.key_focus;
|
2019-04-12 21:00:49 +00:00
|
|
|
if (keyFocus && keyFocus.contains(network.item))
|
2018-03-02 22:44:44 +00:00
|
|
|
this._itemBox.grab_key_focus();
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2019-05-23 20:45:44 +00:00
|
|
|
});
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NMDeviceWireless = class {
|
|
|
|
constructor(client, device) {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._client = client;
|
|
|
|
this._device = device;
|
|
|
|
|
|
|
|
this._description = '';
|
|
|
|
|
|
|
|
this.item = new PopupMenu.PopupSubMenuMenuItem('', true);
|
2017-12-02 00:27:35 +00:00
|
|
|
this.item.menu.addAction(_("Select Network"), this._showDialog.bind(this));
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this._toggleItem = new PopupMenu.PopupMenuItem('');
|
2017-12-02 00:27:35 +00:00
|
|
|
this._toggleItem.connect('activate', this._toggleWifi.bind(this));
|
2013-06-12 04:03:36 +00:00
|
|
|
this.item.menu.addMenuItem(this._toggleItem);
|
|
|
|
|
2017-08-19 16:08:28 +00:00
|
|
|
this.item.menu.addSettingsAction(_("Wi-Fi Settings"), 'gnome-wifi-panel.desktop');
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._wirelessEnabledChangedId = this._client.connect('notify::wireless-enabled', this._sync.bind(this));
|
|
|
|
this._wirelessHwEnabledChangedId = this._client.connect('notify::wireless-hardware-enabled', this._sync.bind(this));
|
|
|
|
this._activeApChangedId = this._device.connect('notify::active-access-point', this._activeApChanged.bind(this));
|
|
|
|
this._stateChangedId = this._device.connect('state-changed', this._deviceStateChanged.bind(this));
|
|
|
|
this._notifyConnectivityId = this._client.connect('notify::connectivity', this._iconChanged.bind(this));
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
return NMConnectionCategory.WIRELESS;
|
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_iconChanged() {
|
2014-03-15 11:40:13 +00:00
|
|
|
this._sync();
|
|
|
|
this.emit('icon-changed');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-03-15 11:40:13 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (this._activeApChangedId) {
|
2018-07-24 09:49:00 +00:00
|
|
|
GObject.signal_handler_disconnect(this._device, this._activeApChangedId);
|
2013-06-12 04:03:36 +00:00
|
|
|
this._activeApChangedId = 0;
|
|
|
|
}
|
|
|
|
if (this._stateChangedId) {
|
2018-07-24 09:49:00 +00:00
|
|
|
GObject.signal_handler_disconnect(this._device, this._stateChangedId);
|
2013-06-12 04:03:36 +00:00
|
|
|
this._stateChangedId = 0;
|
|
|
|
}
|
|
|
|
if (this._strengthChangedId > 0) {
|
|
|
|
this._activeAccessPoint.disconnect(this._strengthChangedId);
|
|
|
|
this._strengthChangedId = 0;
|
|
|
|
}
|
2013-10-08 19:23:30 +00:00
|
|
|
if (this._wirelessEnabledChangedId) {
|
|
|
|
this._client.disconnect(this._wirelessEnabledChangedId);
|
|
|
|
this._wirelessEnabledChangedId = 0;
|
|
|
|
}
|
|
|
|
if (this._wirelessHwEnabledChangedId) {
|
|
|
|
this._client.disconnect(this._wirelessHwEnabledChangedId);
|
|
|
|
this._wirelessHwEnabledChangedId = 0;
|
|
|
|
}
|
2014-02-24 16:25:38 +00:00
|
|
|
if (this._dialog) {
|
|
|
|
this._dialog.destroy();
|
|
|
|
this._dialog = null;
|
|
|
|
}
|
2014-03-15 11:40:13 +00:00
|
|
|
if (this._notifyConnectivityId) {
|
|
|
|
this._client.disconnect(this._notifyConnectivityId);
|
|
|
|
this._notifyConnectivityId = 0;
|
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this.item.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_deviceStateChanged(device, newstate, oldstate, reason) {
|
2013-06-12 04:03:36 +00:00
|
|
|
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 */
|
2017-10-31 10:38:20 +00:00
|
|
|
if (newstate == NM.DeviceState.FAILED &&
|
2019-08-20 00:51:42 +00:00
|
|
|
reason != NM.DeviceStateReason.NO_SECRETS)
|
2013-06-12 04:03:36 +00:00
|
|
|
this.emit('activation-failed', reason);
|
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_toggleWifi() {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._client.wireless_enabled = !this._client.wireless_enabled;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_showDialog() {
|
2017-10-31 10:38:20 +00:00
|
|
|
this._dialog = new NMWirelessDialog(this._client, this._device);
|
2017-12-02 00:27:35 +00:00
|
|
|
this._dialog.connect('closed', this._dialogClosed.bind(this));
|
2013-06-12 04:03:36 +00:00
|
|
|
this._dialog.open();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_dialogClosed() {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._dialog = null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_strengthChanged() {
|
2014-03-15 11:40:13 +00:00
|
|
|
this._iconChanged();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_activeApChanged() {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (this._activeAccessPoint) {
|
|
|
|
this._activeAccessPoint.disconnect(this._strengthChangedId);
|
|
|
|
this._strengthChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._activeAccessPoint = this._device.active_access_point;
|
|
|
|
|
|
|
|
if (this._activeAccessPoint) {
|
|
|
|
this._strengthChangedId = this._activeAccessPoint.connect('notify::strength',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._strengthChanged.bind(this));
|
2013-06-12 04:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._toggleItem.label.text = this._client.wireless_enabled ? _("Turn Off") : _("Turn On");
|
2019-04-12 21:00:49 +00:00
|
|
|
this._toggleItem.visible = this._client.wireless_hardware_enabled;
|
2013-06-12 04:03:36 +00:00
|
|
|
|
|
|
|
this.item.icon.icon_name = this._getMenuIcon();
|
2015-08-06 09:19:37 +00:00
|
|
|
this.item.label.text = this._getStatus();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setDeviceDescription(desc) {
|
2013-06-12 04:03:36 +00:00
|
|
|
this._description = desc;
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getStatus() {
|
2013-06-12 04:03:36 +00:00
|
|
|
let ap = this._device.active_access_point;
|
|
|
|
|
2014-02-03 23:04:43 +00:00
|
|
|
if (this._isHotSpotMaster())
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Hotspot Active").format(this._description);
|
2017-10-31 10:38:20 +00:00
|
|
|
else if (this._device.state >= NM.DeviceState.PREPARE &&
|
|
|
|
this._device.state < NM.DeviceState.ACTIVATED)
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Connecting").format(this._description);
|
2014-02-03 23:04:43 +00:00
|
|
|
else if (ap)
|
2013-10-02 14:48:35 +00:00
|
|
|
return ssidToLabel(ap.get_ssid());
|
|
|
|
else if (!this._client.wireless_hardware_enabled)
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Hardware Disabled").format(this._description);
|
2013-10-02 14:48:35 +00:00
|
|
|
else if (!this._client.wireless_enabled)
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Off").format(this._description);
|
2017-10-31 10:38:20 +00:00
|
|
|
else if (this._device.state == NM.DeviceState.DISCONNECTED)
|
2015-08-06 09:19:37 +00:00
|
|
|
/* Translators: %s is a network identifier */
|
|
|
|
return _("%s Not Connected").format(this._description);
|
2013-10-02 14:48:35 +00:00
|
|
|
else
|
|
|
|
return '';
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMenuIcon() {
|
2013-06-12 04:03:36 +00:00
|
|
|
if (this._device.active_connection)
|
|
|
|
return this.getIndicatorIcon();
|
|
|
|
else
|
|
|
|
return 'network-wireless-signal-none-symbolic';
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 04:03:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_canReachInternet() {
|
2014-02-03 23:04:43 +00:00
|
|
|
if (this._client.primary_connection != this._device.active_connection)
|
|
|
|
return true;
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
return this._client.connectivity == NM.ConnectivityState.FULL;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-03 23:04:43 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_isHotSpotMaster() {
|
2014-02-03 23:04:43 +00:00
|
|
|
if (!this._device.active_connection)
|
|
|
|
return false;
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
let connection = this._device.active_connection.connection;
|
2014-02-03 23:04:43 +00:00
|
|
|
if (!connection)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let ip4config = connection.get_setting_ip4_config();
|
|
|
|
if (!ip4config)
|
|
|
|
return false;
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
return ip4config.get_method() == NM.SETTING_IP4_CONFIG_METHOD_SHARED;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-03 23:04:43 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getIndicatorIcon() {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (this._device.state < NM.DeviceState.PREPARE)
|
2014-01-29 21:46:37 +00:00
|
|
|
return 'network-wireless-disconnected-symbolic';
|
2017-10-31 10:38:20 +00:00
|
|
|
if (this._device.state < NM.DeviceState.ACTIVATED)
|
2013-06-12 04:03:36 +00:00
|
|
|
return 'network-wireless-acquiring-symbolic';
|
|
|
|
|
2014-02-03 23:04:43 +00:00
|
|
|
if (this._isHotSpotMaster())
|
|
|
|
return 'network-wireless-hotspot-symbolic';
|
|
|
|
|
2013-06-12 04:03:36 +00:00
|
|
|
let ap = this._device.active_access_point;
|
|
|
|
if (!ap) {
|
|
|
|
if (this._device.mode != NM80211Mode.ADHOC)
|
|
|
|
log('An active wireless connection, in infrastructure mode, involves no access point?');
|
|
|
|
|
2014-02-03 23:04:43 +00:00
|
|
|
if (this._canReachInternet())
|
|
|
|
return 'network-wireless-connected-symbolic';
|
|
|
|
else
|
|
|
|
return 'network-wireless-no-route-symbolic';
|
2013-06-12 04:03:36 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 23:04:43 +00:00
|
|
|
if (this._canReachInternet())
|
2020-02-14 15:10:34 +00:00
|
|
|
return 'network-wireless-signal-%s-symbolic'.format(signalToIcon(ap.strength));
|
2014-02-03 23:04:43 +00:00
|
|
|
else
|
|
|
|
return 'network-wireless-no-route-symbolic';
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2013-06-12 04:03:36 +00:00
|
|
|
Signals.addSignalMethods(NMDeviceWireless.prototype);
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NMVpnConnectionItem = class extends NMConnectionItem {
|
2017-10-31 00:03:21 +00:00
|
|
|
isActive() {
|
2013-04-26 23:21:02 +00:00
|
|
|
if (this._activeConnection == null)
|
|
|
|
return false;
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
return this._activeConnection.vpn_state != NM.VpnConnectionState.DISCONNECTED;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-26 23:21:02 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_buildUI() {
|
2014-02-08 14:02:05 +00:00
|
|
|
this.labelItem = new PopupMenu.PopupMenuItem('');
|
2017-12-02 00:27:35 +00:00
|
|
|
this.labelItem.connect('activate', this._toggle.bind(this));
|
2014-02-08 14:02:05 +00:00
|
|
|
|
|
|
|
this.radioItem = new PopupMenu.PopupSwitchMenuItem(this._connection.get_id(), false);
|
2017-12-02 00:27:35 +00:00
|
|
|
this.radioItem.connect('toggled', this._toggle.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-08 14:02:05 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2014-02-08 14:02:05 +00:00
|
|
|
let isActive = this.isActive();
|
|
|
|
this.labelItem.label.text = isActive ? _("Turn Off") : this._section.getConnectLabel();
|
|
|
|
this.radioItem.setToggleState(isActive);
|
|
|
|
this.radioItem.setStatus(this._getStatus());
|
|
|
|
this.emit('icon-changed');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-08 14:02:05 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getStatus() {
|
2013-04-26 23:21:02 +00:00
|
|
|
if (this._activeConnection == null)
|
|
|
|
return null;
|
|
|
|
|
2019-01-29 01:27:05 +00:00
|
|
|
switch (this._activeConnection.vpn_state) {
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.VpnConnectionState.DISCONNECTED:
|
|
|
|
case NM.VpnConnectionState.ACTIVATED:
|
2012-08-29 14:22:24 +00:00
|
|
|
return null;
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.VpnConnectionState.PREPARE:
|
|
|
|
case NM.VpnConnectionState.CONNECT:
|
|
|
|
case NM.VpnConnectionState.IP_CONFIG_GET:
|
2016-09-29 22:00:13 +00:00
|
|
|
return _("connecting…");
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.VpnConnectionState.NEED_AUTH:
|
2012-08-29 14:22:24 +00:00
|
|
|
/* Translators: this is for network connections that require some kind of key or password */
|
|
|
|
return _("authentication required");
|
2017-10-31 10:38:20 +00:00
|
|
|
case NM.VpnConnectionState.FAILED:
|
2012-08-29 14:22:24 +00:00
|
|
|
return _("connection failed");
|
|
|
|
default:
|
|
|
|
return 'invalid';
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectionStateChanged(ac, newstate, reason) {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (newstate == NM.VpnConnectionState.FAILED &&
|
|
|
|
reason != NM.VpnConnectionStateReason.NO_SECRETS) {
|
2012-08-29 14:22:24 +00:00
|
|
|
// FIXME: if we ever want to show something based on reason,
|
2017-10-31 10:38:20 +00:00
|
|
|
// we need to convert from NM.VpnConnectionStateReason
|
|
|
|
// to NM.DeviceStateReason
|
2012-08-29 14:22:24 +00:00
|
|
|
this.emit('activation-failed', reason);
|
|
|
|
}
|
|
|
|
|
2013-10-01 14:24:01 +00:00
|
|
|
this.emit('icon-changed');
|
2017-10-31 01:19:44 +00:00
|
|
|
super._connectionStateChanged();
|
|
|
|
}
|
2013-04-26 23:21:02 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setActiveConnection(activeConnection) {
|
2013-04-26 23:21:02 +00:00
|
|
|
if (this._activeConnectionChangedId > 0) {
|
|
|
|
this._activeConnection.disconnect(this._activeConnectionChangedId);
|
|
|
|
this._activeConnectionChangedId = 0;
|
2012-08-29 14:22:24 +00:00
|
|
|
}
|
2013-04-29 19:20:45 +00:00
|
|
|
|
2013-04-26 23:21:02 +00:00
|
|
|
this._activeConnection = activeConnection;
|
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
if (this._activeConnection) {
|
2013-04-26 23:21:02 +00:00
|
|
|
this._activeConnectionChangedId = this._activeConnection.connect('vpn-state-changed',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._connectionStateChanged.bind(this));
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2013-04-26 23:21:02 +00:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:20:45 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getIndicatorIcon() {
|
2013-04-26 23:21:02 +00:00
|
|
|
if (this._activeConnection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (this._activeConnection.vpn_state < NM.VpnConnectionState.ACTIVATED)
|
2013-04-29 19:20:45 +00:00
|
|
|
return 'network-vpn-acquiring-symbolic';
|
|
|
|
else
|
|
|
|
return 'network-vpn-symbolic';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2013-04-26 23:21:02 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NMVpnSection = class extends NMConnectionSection {
|
|
|
|
constructor(client) {
|
|
|
|
super(client);
|
2014-02-17 14:04:40 +00:00
|
|
|
|
2017-08-20 15:52:48 +00:00
|
|
|
this.item.menu.addSettingsAction(_("VPN Settings"), 'gnome-network-panel.desktop');
|
2017-12-21 15:51:28 +00:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-12-21 15:51:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2017-12-21 15:51:28 +00:00
|
|
|
let nItems = this._connectionItems.size;
|
2019-08-19 19:38:51 +00:00
|
|
|
this.item.visible = nItems > 0;
|
2017-12-21 15:51:28 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
super._sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
get category() {
|
|
|
|
return NMConnectionCategory.VPN;
|
|
|
|
}
|
2014-02-17 14:04:40 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getDescription() {
|
2013-04-29 19:11:14 +00:00
|
|
|
return _("VPN");
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getStatus() {
|
2014-03-04 13:02:00 +00:00
|
|
|
let values = this._connectionItems.values();
|
|
|
|
for (let item of values) {
|
|
|
|
if (item.isActive())
|
|
|
|
return item.getName();
|
|
|
|
}
|
|
|
|
|
2015-08-06 09:19:37 +00:00
|
|
|
return _("VPN Off");
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-03-04 13:02:00 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMenuIcon() {
|
2013-04-29 19:11:14 +00:00
|
|
|
return this.getIndicatorIcon() || 'network-vpn-symbolic';
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:11:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
activateConnection(connection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
this._client.activate_connection_async(connection, null, null, null, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-26 23:21:02 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
deactivateConnection(activeConnection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
this._client.deactivate_connection(activeConnection, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-26 23:21:02 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setActiveConnections(vpnConnections) {
|
2014-01-14 22:49:47 +00:00
|
|
|
let connections = this._connectionItems.values();
|
2019-08-20 00:51:42 +00:00
|
|
|
for (let item of connections)
|
2013-08-23 20:21:30 +00:00
|
|
|
item.setActiveConnection(null);
|
2019-08-20 00:51:42 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
vpnConnections.forEach(a => {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (a.connection) {
|
|
|
|
let item = this._connectionItems.get(a.connection.get_uuid());
|
2016-12-20 20:00:42 +00:00
|
|
|
item.setActiveConnection(a);
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-29 19:20:45 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_makeConnectionItem(connection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
return new NMVpnConnectionItem(this, connection);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 00:13:37 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getIndicatorIcon() {
|
2013-04-26 23:21:02 +00:00
|
|
|
let items = this._connectionItems.values();
|
2014-01-14 22:49:47 +00:00
|
|
|
for (let item of items) {
|
2013-04-26 23:21:02 +00:00
|
|
|
let icon = item.getIndicatorIcon();
|
2013-04-29 19:20:45 +00:00
|
|
|
if (icon)
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
return '';
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2017-10-31 10:38:20 +00:00
|
|
|
Signals.addSignalMethods(NMVpnSection.prototype);
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var DeviceCategory = class extends PopupMenu.PopupMenuSection {
|
|
|
|
constructor(category) {
|
|
|
|
super();
|
2016-05-13 17:42:04 +00:00
|
|
|
|
|
|
|
this._category = category;
|
|
|
|
|
|
|
|
this.devices = [];
|
|
|
|
|
|
|
|
this.section = new PopupMenu.PopupMenuSection();
|
2017-12-02 00:27:35 +00:00
|
|
|
this.section.box.connect('actor-added', this._sync.bind(this));
|
|
|
|
this.section.box.connect('actor-removed', this._sync.bind(this));
|
2016-05-13 17:42:04 +00:00
|
|
|
this.addMenuItem(this.section);
|
|
|
|
|
|
|
|
this._summaryItem = new PopupMenu.PopupSubMenuMenuItem('', true);
|
|
|
|
this._summaryItem.icon.icon_name = this._getSummaryIcon();
|
|
|
|
this.addMenuItem(this._summaryItem);
|
|
|
|
|
|
|
|
this._summaryItem.menu.addSettingsAction(_('Network Settings'),
|
|
|
|
'gnome-network-panel.desktop');
|
2019-04-12 21:00:49 +00:00
|
|
|
this._summaryItem.hide();
|
2016-05-13 17:42:04 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-05-13 17:42:04 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2016-05-13 17:42:04 +00:00
|
|
|
let nDevices = this.section.box.get_children().reduce(
|
2017-10-31 00:38:18 +00:00
|
|
|
(prev, child) => prev + (child.visible ? 1 : 0), 0);
|
2016-05-13 17:42:04 +00:00
|
|
|
this._summaryItem.label.text = this._getSummaryLabel(nDevices);
|
|
|
|
let shouldSummarize = nDevices > MAX_DEVICE_ITEMS;
|
2019-04-12 21:00:49 +00:00
|
|
|
this._summaryItem.visible = shouldSummarize;
|
2016-05-13 17:42:04 +00:00
|
|
|
this.section.actor.visible = !shouldSummarize;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-05-13 17:42:04 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getSummaryIcon() {
|
2019-01-29 01:27:05 +00:00
|
|
|
switch (this._category) {
|
2019-02-01 12:21:00 +00:00
|
|
|
case NMConnectionCategory.WIRED:
|
|
|
|
return 'network-wired-symbolic';
|
|
|
|
case NMConnectionCategory.WIRELESS:
|
|
|
|
case NMConnectionCategory.WWAN:
|
|
|
|
return 'network-wireless-symbolic';
|
2016-05-13 17:42:04 +00:00
|
|
|
}
|
|
|
|
return '';
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-05-13 17:42:04 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getSummaryLabel(nDevices) {
|
2019-01-29 01:27:05 +00:00
|
|
|
switch (this._category) {
|
2019-02-01 12:21:00 +00:00
|
|
|
case NMConnectionCategory.WIRED:
|
|
|
|
return ngettext("%s Wired Connection",
|
|
|
|
"%s Wired Connections",
|
|
|
|
nDevices).format(nDevices);
|
|
|
|
case NMConnectionCategory.WIRELESS:
|
|
|
|
return ngettext("%s Wi-Fi Connection",
|
|
|
|
"%s Wi-Fi Connections",
|
|
|
|
nDevices).format(nDevices);
|
|
|
|
case NMConnectionCategory.WWAN:
|
|
|
|
return ngettext("%s Modem Connection",
|
|
|
|
"%s Modem Connections",
|
|
|
|
nDevices).format(nDevices);
|
2016-05-13 17:42:04 +00:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2019-10-28 18:35:33 +00:00
|
|
|
var NMApplet = GObject.registerClass(
|
|
|
|
class Indicator extends PanelMenu.SystemIndicator {
|
2019-07-16 09:24:13 +00:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2012-06-19 17:50:37 +00:00
|
|
|
|
2013-07-19 10:05:47 +00:00
|
|
|
this._primaryIndicator = this._addIndicator();
|
|
|
|
this._vpnIndicator = this._addIndicator();
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2012-09-03 17:57:53 +00:00
|
|
|
// Device types
|
|
|
|
this._dtypes = { };
|
2017-10-31 10:38:20 +00:00
|
|
|
this._dtypes[NM.DeviceType.ETHERNET] = NMDeviceWired;
|
|
|
|
this._dtypes[NM.DeviceType.WIFI] = NMDeviceWireless;
|
|
|
|
this._dtypes[NM.DeviceType.MODEM] = NMDeviceModem;
|
|
|
|
this._dtypes[NM.DeviceType.BT] = NMDeviceBluetooth;
|
2012-09-03 17:57:53 +00:00
|
|
|
|
|
|
|
// Connection types
|
|
|
|
this._ctypes = { };
|
2017-10-31 10:38:20 +00:00
|
|
|
this._ctypes[NM.SETTING_WIRED_SETTING_NAME] = NMConnectionCategory.WIRED;
|
|
|
|
this._ctypes[NM.SETTING_WIRELESS_SETTING_NAME] = NMConnectionCategory.WIRELESS;
|
|
|
|
this._ctypes[NM.SETTING_BLUETOOTH_SETTING_NAME] = NMConnectionCategory.WWAN;
|
|
|
|
this._ctypes[NM.SETTING_CDMA_SETTING_NAME] = NMConnectionCategory.WWAN;
|
|
|
|
this._ctypes[NM.SETTING_GSM_SETTING_NAME] = NMConnectionCategory.WWAN;
|
|
|
|
this._ctypes[NM.SETTING_VPN_SETTING_NAME] = NMConnectionCategory.VPN;
|
2012-09-03 17:57:53 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
NM.Client.new_async(null, this._clientGot.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-09-03 17:57:53 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_clientGot(obj, result) {
|
2017-10-31 10:38:20 +00:00
|
|
|
this._client = NM.Client.new_finish(result);
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2019-01-29 01:27:05 +00:00
|
|
|
this._activeConnections = [];
|
|
|
|
this._connections = [];
|
|
|
|
this._connectivityQueue = [];
|
2012-05-18 16:34:07 +00:00
|
|
|
|
|
|
|
this._mainConnection = null;
|
2013-04-29 19:20:45 +00:00
|
|
|
this._mainConnectionIconChangedId = 0;
|
2017-06-13 02:24:12 +00:00
|
|
|
this._mainConnectionStateChangedId = 0;
|
2012-05-18 16:34:07 +00:00
|
|
|
|
2013-08-27 18:58:50 +00:00
|
|
|
this._notification = null;
|
|
|
|
|
2012-08-29 17:42:11 +00:00
|
|
|
this._nmDevices = [];
|
2011-01-25 21:08:12 +00:00
|
|
|
this._devices = { };
|
|
|
|
|
2016-05-13 17:42:04 +00:00
|
|
|
let categories = [NMConnectionCategory.WIRED,
|
|
|
|
NMConnectionCategory.WIRELESS,
|
|
|
|
NMConnectionCategory.WWAN];
|
|
|
|
for (let category of categories) {
|
|
|
|
this._devices[category] = new DeviceCategory(category);
|
|
|
|
this.menu.addMenuItem(this._devices[category]);
|
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
this._vpnSection = new NMVpnSection(this._client);
|
2017-12-02 00:27:35 +00:00
|
|
|
this._vpnSection.connect('activation-failed', this._onActivationFailed.bind(this));
|
|
|
|
this._vpnSection.connect('icon-changed', this._updateIcon.bind(this));
|
2013-06-07 17:23:57 +00:00
|
|
|
this.menu.addMenuItem(this._vpnSection.item);
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2012-09-03 17:57:53 +00:00
|
|
|
this._readConnections();
|
|
|
|
this._readDevices();
|
|
|
|
this._syncNMState();
|
2015-06-03 10:30:12 +00:00
|
|
|
this._syncMainConnection();
|
2017-10-31 10:38:20 +00:00
|
|
|
this._syncVpnConnections();
|
2012-09-03 17:57:53 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._client.connect('notify::nm-running', this._syncNMState.bind(this));
|
|
|
|
this._client.connect('notify::networking-enabled', this._syncNMState.bind(this));
|
|
|
|
this._client.connect('notify::state', this._syncNMState.bind(this));
|
|
|
|
this._client.connect('notify::primary-connection', this._syncMainConnection.bind(this));
|
|
|
|
this._client.connect('notify::activating-connection', this._syncMainConnection.bind(this));
|
|
|
|
this._client.connect('notify::active-connections', this._syncVpnConnections.bind(this));
|
|
|
|
this._client.connect('notify::connectivity', this._syncConnectivity.bind(this));
|
|
|
|
this._client.connect('device-added', this._deviceAdded.bind(this));
|
|
|
|
this._client.connect('device-removed', this._deviceRemoved.bind(this));
|
|
|
|
this._client.connect('connection-added', this._connectionAdded.bind(this));
|
|
|
|
this._client.connect('connection-removed', this._connectionRemoved.bind(this));
|
|
|
|
|
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2013-06-12 07:37:50 +00:00
|
|
|
this._sessionUpdated();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-06-12 07:37:50 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sessionUpdated() {
|
2013-06-12 07:37:50 +00:00
|
|
|
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
2013-06-07 17:23:57 +00:00
|
|
|
this.menu.setSensitive(sensitive);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_ensureSource() {
|
2011-01-25 21:08:12 +00:00
|
|
|
if (!this._source) {
|
2011-10-08 22:00:32 +00:00
|
|
|
this._source = new MessageTray.Source(_("Network Manager"),
|
2012-08-31 21:25:26 +00:00
|
|
|
'network-transmit-receive');
|
2013-10-13 20:01:56 +00:00
|
|
|
this._source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
|
2011-10-08 22:00:32 +00:00
|
|
|
|
2019-08-19 20:20:35 +00:00
|
|
|
this._source.connect('destroy', () => (this._source = null));
|
2011-01-25 21:08:12 +00:00
|
|
|
Main.messageTray.add(this._source);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_readDevices() {
|
2019-01-29 01:27:05 +00:00
|
|
|
let devices = this._client.get_devices() || [];
|
2011-01-25 21:08:12 +00:00
|
|
|
for (let i = 0; i < devices.length; ++i) {
|
2019-03-07 19:26:12 +00:00
|
|
|
try {
|
|
|
|
this._deviceAdded(this._client, devices[i], true);
|
|
|
|
} catch (e) {
|
2020-02-14 15:10:34 +00:00
|
|
|
log('Failed to add device %s: %s'.format(devices[i], e.toString()));
|
2019-03-07 19:26:12 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
2012-08-29 17:42:11 +00:00
|
|
|
this._syncDeviceNames();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_notify(iconName, title, text, urgency) {
|
2013-08-27 18:58:50 +00:00
|
|
|
if (this._notification)
|
|
|
|
this._notification.destroy();
|
2011-08-22 16:21:31 +00:00
|
|
|
|
|
|
|
this._ensureSource();
|
|
|
|
|
2012-09-14 14:33:52 +00:00
|
|
|
let gicon = new Gio.ThemedIcon({ name: iconName });
|
2019-08-19 19:06:04 +00:00
|
|
|
this._notification = new MessageTray.Notification(this._source, title, text, { gicon });
|
2013-08-27 18:58:50 +00:00
|
|
|
this._notification.setUrgency(urgency);
|
|
|
|
this._notification.setTransient(true);
|
2017-10-31 00:38:18 +00:00
|
|
|
this._notification.connect('destroy', () => {
|
2013-08-27 18:58:50 +00:00
|
|
|
this._notification = null;
|
2011-08-22 16:21:31 +00:00
|
|
|
});
|
2019-05-13 21:32:31 +00:00
|
|
|
this._source.showNotification(this._notification);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-22 16:21:31 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_onActivationFailed(_device, _reason) {
|
2012-08-29 14:22:24 +00:00
|
|
|
// XXX: nm-applet has no special text depending on reason
|
|
|
|
// but I'm not sure of this generic message
|
2013-08-27 18:58:50 +00:00
|
|
|
this._notify('network-error-symbolic',
|
|
|
|
_("Connection failed"),
|
|
|
|
_("Activation of network connection failed"),
|
|
|
|
MessageTray.Urgency.HIGH);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 14:22:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncDeviceNames() {
|
2017-10-31 10:38:20 +00:00
|
|
|
let names = NM.Device.disambiguate_names(this._nmDevices);
|
2013-04-25 18:00:11 +00:00
|
|
|
for (let i = 0; i < this._nmDevices.length; i++) {
|
|
|
|
let device = this._nmDevices[i];
|
2013-07-17 05:01:44 +00:00
|
|
|
let description = names[i];
|
2013-04-25 18:00:11 +00:00
|
|
|
if (device._delegate)
|
2013-07-17 05:01:44 +00:00
|
|
|
device._delegate.setDeviceDescription(description);
|
2012-08-29 17:42:11 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 17:42:11 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_deviceAdded(client, device, skipSyncDeviceNames) {
|
2011-01-25 21:08:12 +00:00
|
|
|
if (device._delegate) {
|
|
|
|
// already seen, not adding again
|
|
|
|
return;
|
|
|
|
}
|
2012-12-04 13:49:34 +00:00
|
|
|
|
2011-01-25 21:08:12 +00:00
|
|
|
let wrapperClass = this._dtypes[device.get_device_type()];
|
|
|
|
if (wrapperClass) {
|
2017-10-31 10:38:20 +00:00
|
|
|
let wrapper = new wrapperClass(this._client, device);
|
2013-06-12 00:13:37 +00:00
|
|
|
device._delegate = wrapper;
|
2012-12-04 13:49:34 +00:00
|
|
|
this._addDeviceWrapper(wrapper);
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2012-08-29 17:42:11 +00:00
|
|
|
this._nmDevices.push(device);
|
2019-05-07 15:21:09 +00:00
|
|
|
this._deviceChanged(device, skipSyncDeviceNames);
|
2013-07-17 05:10:42 +00:00
|
|
|
|
2019-05-07 15:21:09 +00:00
|
|
|
device.connect('notify::interface', () => {
|
|
|
|
this._deviceChanged(device, false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_deviceChanged(device, skipSyncDeviceNames) {
|
|
|
|
let wrapper = device._delegate;
|
|
|
|
|
|
|
|
if (!skipSyncDeviceNames)
|
|
|
|
this._syncDeviceNames();
|
|
|
|
|
|
|
|
if (wrapper instanceof NMConnectionSection) {
|
|
|
|
this._connections.forEach(connection => {
|
|
|
|
wrapper.checkConnection(connection);
|
|
|
|
});
|
2012-08-21 14:55:40 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_addDeviceWrapper(wrapper) {
|
2012-12-04 13:49:34 +00:00
|
|
|
wrapper._activationFailedId = wrapper.connect('activation-failed',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onActivationFailed.bind(this));
|
2012-12-04 13:49:34 +00:00
|
|
|
|
|
|
|
let section = this._devices[wrapper.category].section;
|
2013-04-29 19:11:14 +00:00
|
|
|
section.addMenuItem(wrapper.item);
|
2012-12-04 13:49:34 +00:00
|
|
|
|
|
|
|
let devices = this._devices[wrapper.category].devices;
|
|
|
|
devices.push(wrapper);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-12-04 13:49:34 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_deviceRemoved(client, device) {
|
2012-12-04 13:49:34 +00: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 21:08:12 +00:00
|
|
|
log('Removing a network device that was not added');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-12 20:05:31 +00:00
|
|
|
this._removeDeviceWrapper(wrapper);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-12-04 13:49:34 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_removeDeviceWrapper(wrapper) {
|
2013-04-26 04:25:14 +00:00
|
|
|
wrapper.disconnect(wrapper._activationFailedId);
|
2011-01-25 21:08:12 +00:00
|
|
|
wrapper.destroy();
|
|
|
|
|
|
|
|
let devices = this._devices[wrapper.category].devices;
|
|
|
|
let pos = devices.indexOf(wrapper);
|
|
|
|
devices.splice(pos, 1);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMainConnection() {
|
2013-08-23 20:21:30 +00:00
|
|
|
let connection;
|
|
|
|
|
2013-09-01 02:33:03 +00:00
|
|
|
connection = this._client.get_primary_connection();
|
2013-08-23 20:21:30 +00:00
|
|
|
if (connection) {
|
2019-02-04 11:30:53 +00:00
|
|
|
ensureActiveConnectionProps(connection);
|
2013-08-23 20:21:30 +00:00
|
|
|
return connection;
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:21:30 +00:00
|
|
|
connection = this._client.get_activating_connection();
|
|
|
|
if (connection) {
|
2019-02-04 11:30:53 +00:00
|
|
|
ensureActiveConnectionProps(connection);
|
2013-08-23 20:21:30 +00:00
|
|
|
return connection;
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:21:30 +00:00
|
|
|
return null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-08-23 20:21:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncMainConnection() {
|
2013-04-29 19:20:45 +00:00
|
|
|
if (this._mainConnectionIconChangedId > 0) {
|
|
|
|
this._mainConnection._primaryDevice.disconnect(this._mainConnectionIconChangedId);
|
|
|
|
this._mainConnectionIconChangedId = 0;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:21:30 +00:00
|
|
|
if (this._mainConnectionStateChangedId > 0) {
|
|
|
|
this._mainConnection.disconnect(this._mainConnectionStateChangedId);
|
|
|
|
this._mainConnectionStateChangedId = 0;
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:21:30 +00:00
|
|
|
this._mainConnection = this._getMainConnection();
|
2013-04-29 19:20:45 +00:00
|
|
|
|
|
|
|
if (this._mainConnection) {
|
2013-08-23 20:21:30 +00:00
|
|
|
if (this._mainConnection._primaryDevice)
|
2017-12-02 00:27:35 +00:00
|
|
|
this._mainConnectionIconChangedId = this._mainConnection._primaryDevice.connect('icon-changed', this._updateIcon.bind(this));
|
|
|
|
this._mainConnectionStateChangedId = this._mainConnection.connect('notify::state', this._mainConnectionStateChanged.bind(this));
|
2013-08-23 20:21:30 +00:00
|
|
|
this._mainConnectionStateChanged();
|
2013-04-29 19:20:45 +00:00
|
|
|
}
|
2013-08-16 23:32:54 +00:00
|
|
|
|
|
|
|
this._updateIcon();
|
2014-02-17 17:06:35 +00:00
|
|
|
this._syncConnectivity();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncVpnConnections() {
|
2013-08-23 20:21:30 +00:00
|
|
|
let activeConnections = this._client.get_active_connections() || [];
|
2017-10-31 00:38:18 +00:00
|
|
|
let vpnConnections = activeConnections.filter(
|
2019-08-19 19:38:51 +00:00
|
|
|
a => a instanceof NM.VpnConnection
|
2017-10-31 00:38:18 +00:00
|
|
|
);
|
|
|
|
vpnConnections.forEach(a => {
|
2019-02-04 11:30:53 +00:00
|
|
|
ensureActiveConnectionProps(a);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-08-23 20:21:30 +00:00
|
|
|
this._vpnSection.setActiveConnections(vpnConnections);
|
2011-09-04 19:17:33 +00:00
|
|
|
|
2013-08-23 20:21:30 +00:00
|
|
|
this._updateIcon();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-08-23 20:21:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_mainConnectionStateChanged() {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (this._mainConnection.state == NM.ActiveConnectionState.ACTIVATED && this._notification)
|
2013-08-27 18:58:50 +00:00
|
|
|
this._notification.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-09-04 19:17:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_ignoreConnection(connection) {
|
2012-08-21 14:55:40 +00:00
|
|
|
let setting = connection.get_setting_connection();
|
|
|
|
if (!setting)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Ignore slave connections
|
|
|
|
if (setting.get_master())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-21 14:55:40 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_addConnection(connection) {
|
2012-08-21 14:55:40 +00:00
|
|
|
if (this._ignoreConnection(connection))
|
|
|
|
return;
|
2012-05-31 17:13:16 +00:00
|
|
|
if (connection._updatedId) {
|
2011-01-25 21:08:12 +00:00
|
|
|
// connection was already seen
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
connection._updatedId = connection.connect('changed', this._updateConnection.bind(this));
|
2011-01-25 21:08:12 +00:00
|
|
|
|
|
|
|
this._updateConnection(connection);
|
|
|
|
this._connections.push(connection);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_readConnections() {
|
2017-10-31 10:38:20 +00:00
|
|
|
let connections = this._client.get_connections();
|
2017-12-02 00:27:35 +00:00
|
|
|
connections.forEach(this._addConnection.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-25 20:24:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectionAdded(client, connection) {
|
2013-04-25 20:24:14 +00:00
|
|
|
this._addConnection(connection);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectionRemoved(client, connection) {
|
2011-01-25 21:08:12 +00:00
|
|
|
let pos = this._connections.indexOf(connection);
|
|
|
|
if (pos != -1)
|
2014-11-16 23:50:14 +00:00
|
|
|
this._connections.splice(pos, 1);
|
2011-01-25 21:08:12 +00:00
|
|
|
|
|
|
|
let section = connection._section;
|
2011-03-26 17:38:20 +00:00
|
|
|
|
2013-05-22 21:35:29 +00:00
|
|
|
if (section == NMConnectionCategory.INVALID)
|
|
|
|
return;
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2013-06-12 20:05:31 +00:00
|
|
|
if (section == NMConnectionCategory.VPN) {
|
2013-05-22 21:35:29 +00:00
|
|
|
this._vpnSection.removeConnection(connection);
|
|
|
|
} else {
|
|
|
|
let devices = this._devices[section].devices;
|
2013-06-12 04:03:36 +00:00
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
if (devices[i] instanceof NMConnectionSection)
|
|
|
|
devices[i].removeConnection(connection);
|
|
|
|
}
|
2012-12-04 13:49:34 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 21:08:12 +00:00
|
|
|
connection.disconnect(connection._updatedId);
|
2017-10-31 10:38:20 +00:00
|
|
|
connection._updatedId = 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateConnection(connection) {
|
2017-10-31 10:38:20 +00:00
|
|
|
let connectionSettings = connection.get_setting_by_name(NM.SETTING_CONNECTION_SETTING_NAME);
|
2011-01-25 21:08:12 +00:00
|
|
|
connection._type = connectionSettings.type;
|
2011-03-26 17:38:20 +00:00
|
|
|
connection._section = this._ctypes[connection._type] || NMConnectionCategory.INVALID;
|
2011-01-25 21:08:12 +00:00
|
|
|
|
|
|
|
let section = connection._section;
|
2011-03-26 17:38:20 +00:00
|
|
|
|
2013-05-22 21:35:29 +00:00
|
|
|
if (section == NMConnectionCategory.INVALID)
|
|
|
|
return;
|
|
|
|
|
2013-06-12 20:05:31 +00:00
|
|
|
if (section == NMConnectionCategory.VPN) {
|
2012-08-29 14:22:24 +00:00
|
|
|
this._vpnSection.checkConnection(connection);
|
2011-01-25 21:08:12 +00:00
|
|
|
} else {
|
|
|
|
let devices = this._devices[section].devices;
|
2017-10-31 00:38:18 +00:00
|
|
|
devices.forEach(wrapper => {
|
2013-08-07 10:44:38 +00:00
|
|
|
if (wrapper instanceof NMConnectionSection)
|
|
|
|
wrapper.checkConnection(connection);
|
|
|
|
});
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncNMState() {
|
2019-07-16 09:24:13 +00:00
|
|
|
this.visible = this._client.nm_running;
|
2013-06-07 17:23:57 +00:00
|
|
|
this.menu.actor.visible = this._client.networking_enabled;
|
2014-02-17 17:06:35 +00:00
|
|
|
|
2018-04-17 20:51:34 +00:00
|
|
|
this._updateIcon();
|
2014-02-17 17:06:35 +00:00
|
|
|
this._syncConnectivity();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-17 17:06:35 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_flushConnectivityQueue() {
|
2014-02-17 17:06:35 +00:00
|
|
|
if (this._portalHelperProxy) {
|
|
|
|
for (let item of this._connectivityQueue)
|
|
|
|
this._portalHelperProxy.CloseRemote(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._connectivityQueue = [];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-17 17:06:35 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_closeConnectivityCheck(path) {
|
2014-02-17 17:06:35 +00:00
|
|
|
let index = this._connectivityQueue.indexOf(path);
|
|
|
|
|
|
|
|
if (index >= 0) {
|
|
|
|
if (this._portalHelperProxy)
|
|
|
|
this._portalHelperProxy.CloseRemote(path);
|
|
|
|
|
|
|
|
this._connectivityQueue.splice(index, 1);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-17 17:06:35 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_portalHelperDone(proxy, emitter, parameters) {
|
2014-02-17 17:06:35 +00:00
|
|
|
let [path, result] = parameters;
|
|
|
|
|
|
|
|
if (result == PortalHelperResult.CANCELLED) {
|
|
|
|
// Keep the connection in the queue, so the user is not
|
|
|
|
// spammed with more logins until we next flush the queue,
|
|
|
|
// which will happen once he chooses a better connection
|
|
|
|
// or we get to full connectivity through other means
|
|
|
|
} else if (result == PortalHelperResult.COMPLETED) {
|
|
|
|
this._closeConnectivityCheck(path);
|
|
|
|
} else if (result == PortalHelperResult.RECHECK) {
|
2019-08-20 00:20:08 +00:00
|
|
|
this._client.check_connectivity_async(null, (client, res) => {
|
2014-02-17 17:06:35 +00:00
|
|
|
try {
|
2019-08-20 00:20:08 +00:00
|
|
|
let state = client.check_connectivity_finish(res);
|
2017-10-31 10:38:20 +00:00
|
|
|
if (state >= NM.ConnectivityState.FULL)
|
2014-02-17 17:06:35 +00:00
|
|
|
this._closeConnectivityCheck(path);
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) { }
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2014-02-17 17:06:35 +00:00
|
|
|
} else {
|
2020-02-14 15:10:34 +00:00
|
|
|
log('Invalid result from portal helper: %s'.format(result));
|
2014-02-17 17:06:35 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-02-17 17:06:35 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncConnectivity() {
|
2014-02-17 17:06:35 +00:00
|
|
|
if (this._mainConnection == null ||
|
2017-10-31 10:38:20 +00:00
|
|
|
this._mainConnection.state != NM.ActiveConnectionState.ACTIVATED) {
|
2014-02-17 17:06:35 +00:00
|
|
|
this._flushConnectivityQueue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:38:20 +00:00
|
|
|
let isPortal = this._client.connectivity == NM.ConnectivityState.PORTAL;
|
2014-02-17 17:06:35 +00:00
|
|
|
// For testing, allow interpreting any value != FULL as PORTAL, because
|
|
|
|
// LIMITED (no upstream route after the default gateway) is easy to obtain
|
|
|
|
// with a tethered phone
|
|
|
|
// NONE is also possible, with a connection configured to force no default route
|
|
|
|
// (but in general we should only prompt a portal if we know there is a portal)
|
|
|
|
if (GLib.getenv('GNOME_SHELL_CONNECTIVITY_TEST') != null)
|
2017-10-31 10:38:20 +00:00
|
|
|
isPortal = isPortal || this._client.connectivity < NM.ConnectivityState.FULL;
|
2017-02-19 15:38:07 +00:00
|
|
|
if (!isPortal || Main.sessionMode.isGreeter)
|
2014-02-17 17:06:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
let path = this._mainConnection.get_path();
|
|
|
|
for (let item of this._connectivityQueue) {
|
|
|
|
if (item == path)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let timestamp = global.get_current_time();
|
|
|
|
if (this._portalHelperProxy) {
|
|
|
|
this._portalHelperProxy.AuthenticateRemote(path, '', timestamp);
|
|
|
|
} else {
|
|
|
|
new PortalHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PortalHelper',
|
2017-10-31 00:38:18 +00:00
|
|
|
'/org/gnome/Shell/PortalHelper', (proxy, error) => {
|
2014-02-17 17:06:35 +00:00
|
|
|
if (error) {
|
2020-02-14 15:10:34 +00:00
|
|
|
log('Error launching the portal helper: %s'.format(error));
|
2014-02-17 17:06:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._portalHelperProxy = proxy;
|
2017-12-02 00:27:35 +00:00
|
|
|
proxy.connectSignal('Done', this._portalHelperDone.bind(this));
|
2014-02-17 17:06:35 +00:00
|
|
|
|
|
|
|
proxy.AuthenticateRemote(path, '', timestamp);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2014-02-17 17:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._connectivityQueue.push(path);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateIcon() {
|
2016-05-19 16:22:02 +00:00
|
|
|
if (!this._client.networking_enabled) {
|
2014-03-10 18:11:50 +00:00
|
|
|
this._primaryIndicator.visible = false;
|
2011-01-25 21:08:12 +00:00
|
|
|
} else {
|
2016-05-19 16:22:02 +00:00
|
|
|
let dev = null;
|
|
|
|
if (this._mainConnection)
|
|
|
|
dev = this._mainConnection._primaryDevice;
|
|
|
|
|
|
|
|
let state = this._client.get_state();
|
2017-10-31 10:38:20 +00:00
|
|
|
let connected = state == NM.State.CONNECTED_GLOBAL;
|
2016-05-19 16:22:02 +00:00
|
|
|
this._primaryIndicator.visible = (dev != null) || connected;
|
|
|
|
if (dev) {
|
2013-08-23 20:21:30 +00:00
|
|
|
this._primaryIndicator.icon_name = dev.getIndicatorIcon();
|
2016-05-19 16:22:02 +00:00
|
|
|
} else if (connected) {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (this._client.connectivity == NM.ConnectivityState.FULL)
|
2016-05-19 16:22:02 +00:00
|
|
|
this._primaryIndicator.icon_name = 'network-wired-symbolic';
|
|
|
|
else
|
|
|
|
this._primaryIndicator.icon_name = 'network-wired-no-route-symbolic';
|
|
|
|
}
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 21:27:25 +00:00
|
|
|
this._vpnIndicator.icon_name = this._vpnSection.getIndicatorIcon();
|
2019-11-21 09:04:12 +00:00
|
|
|
this._vpnIndicator.visible = this._vpnIndicator.icon_name !== null;
|
2011-01-25 21:08:12 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|