NetworkMenu: fix updating connection lists
Ensure that the UI is updated when a connection changes name or id, even if it was already known by a device. Also, use less private properties on NMConnection objects, as they can become stale and cause problems. https://bugzilla.gnome.org/show_bug.cgi?id=677097
This commit is contained in:
parent
41c3795a7b
commit
35b142f23f
@ -304,9 +304,10 @@ const NMDevice = new Lang.Class({
|
|||||||
// record the connection
|
// record the connection
|
||||||
let obj = {
|
let obj = {
|
||||||
connection: connections[i],
|
connection: connections[i],
|
||||||
name: connections[i]._name,
|
name: connections[i].get_id(),
|
||||||
uuid: connections[i]._uuid,
|
uuid: connections[i].get_uuid(),
|
||||||
timestamp: connections[i]._timestamp,
|
timestamp: connections[i]._timestamp,
|
||||||
|
item: null,
|
||||||
};
|
};
|
||||||
this._connections.push(obj);
|
this._connections.push(obj);
|
||||||
}
|
}
|
||||||
@ -401,48 +402,46 @@ const NMDevice = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
checkConnection: function(connection) {
|
checkConnection: function(connection) {
|
||||||
let pos = this._findConnection(connection._uuid);
|
let pos = this._findConnection(connection.get_uuid());
|
||||||
let exists = pos != -1;
|
let exists = pos != -1;
|
||||||
let valid = this.connectionValid(connection);
|
let valid = this.connectionValid(connection);
|
||||||
|
let similar = false;
|
||||||
|
if (exists) {
|
||||||
|
let existing = this._connections[pos];
|
||||||
|
|
||||||
if (exists && !valid)
|
// Check if connection changed name or id
|
||||||
this.removeConnection(connection);
|
similar = existing.name == connection.get_id() &&
|
||||||
else if (!exists && valid)
|
existing.timestamp == connection._timestamp;
|
||||||
this.addConnection(connection);
|
|
||||||
else if (exists && valid) {
|
|
||||||
// propagate changes and update the UI
|
|
||||||
|
|
||||||
if (this._connections[pos].timestamp != connection._timestamp) {
|
|
||||||
this._connections[pos].timestamp = connection._timestamp;
|
|
||||||
this._connections.sort(this._connectionSortFunction);
|
|
||||||
|
|
||||||
this._clearSection();
|
|
||||||
this._queueCreateSection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exists && valid && similar) {
|
||||||
|
// Nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists)
|
||||||
|
this.removeConnection(connection);
|
||||||
|
if (valid)
|
||||||
|
this.addConnection(connection);
|
||||||
},
|
},
|
||||||
|
|
||||||
addConnection: function(connection) {
|
addConnection: function(connection) {
|
||||||
// record the connection
|
// record the connection
|
||||||
let obj = {
|
let obj = {
|
||||||
connection: connection,
|
connection: connection,
|
||||||
name: connection._name,
|
name: connection.get_id(),
|
||||||
uuid: connection._uuid,
|
uuid: connection.get_uuid(),
|
||||||
timestamp: connection._timestamp,
|
timestamp: connection._timestamp,
|
||||||
|
item: null,
|
||||||
};
|
};
|
||||||
this._connections.push(obj);
|
Util.insertSorted(this._connections, obj, this._connectionSortFunction);
|
||||||
this._connections.sort(this._connectionSortFunction);
|
|
||||||
|
|
||||||
this._clearSection();
|
this._clearSection();
|
||||||
this._queueCreateSection();
|
this._queueCreateSection();
|
||||||
},
|
},
|
||||||
|
|
||||||
removeConnection: function(connection) {
|
removeConnection: function(connection) {
|
||||||
if (!connection._uuid) {
|
let pos = this._findConnection(connection.get_uuid());
|
||||||
log('Cannot remove a connection without an UUID');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let pos = this._findConnection(connection._uuid);
|
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
// this connection was never added, nothing to do here
|
// this connection was never added, nothing to do here
|
||||||
return;
|
return;
|
||||||
@ -712,10 +711,10 @@ const NMDeviceWired = new Lang.Class({
|
|||||||
|
|
||||||
_createAutomaticConnection: function() {
|
_createAutomaticConnection: function() {
|
||||||
let connection = new NetworkManager.Connection();
|
let connection = new NetworkManager.Connection();
|
||||||
connection._uuid = NetworkManager.utils_uuid_generate();
|
let uuid = NetworkManager.utils_uuid_generate();
|
||||||
connection.add_setting(new NetworkManager.SettingWired());
|
connection.add_setting(new NetworkManager.SettingWired());
|
||||||
connection.add_setting(new NetworkManager.SettingConnection({
|
connection.add_setting(new NetworkManager.SettingConnection({
|
||||||
uuid: connection._uuid,
|
uuid: uuid,
|
||||||
id: this._autoConnectionName,
|
id: this._autoConnectionName,
|
||||||
type: NetworkManager.SETTING_WIRED_SETTING_NAME,
|
type: NetworkManager.SETTING_WIRED_SETTING_NAME,
|
||||||
autoconnect: true
|
autoconnect: true
|
||||||
@ -859,10 +858,10 @@ const NMDeviceBluetooth = new Lang.Class({
|
|||||||
|
|
||||||
_createAutomaticConnection: function() {
|
_createAutomaticConnection: function() {
|
||||||
let connection = new NetworkManager.Connection;
|
let connection = new NetworkManager.Connection;
|
||||||
connection._uuid = NetworkManager.utils_uuid_generate();
|
let uuid = NetworkManager.utils_uuid_generate();
|
||||||
connection.add_setting(new NetworkManager.SettingBluetooth);
|
connection.add_setting(new NetworkManager.SettingBluetooth);
|
||||||
connection.add_setting(new NetworkManager.SettingConnection({
|
connection.add_setting(new NetworkManager.SettingConnection({
|
||||||
uuid: connection._uuid,
|
uuid: uuid,
|
||||||
id: this._autoConnectionName,
|
id: this._autoConnectionName,
|
||||||
type: NetworkManager.SETTING_BLUETOOTH_SETTING_NAME,
|
type: NetworkManager.SETTING_BLUETOOTH_SETTING_NAME,
|
||||||
autoconnect: false
|
autoconnect: false
|
||||||
@ -1323,9 +1322,7 @@ const NMDeviceWireless = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeConnection: function(connection) {
|
removeConnection: function(connection) {
|
||||||
if (!connection._uuid)
|
let pos = this._findConnection(connection.get_uuid());
|
||||||
return;
|
|
||||||
let pos = this._findConnection(connection._uuid);
|
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
// removing connection that was never added
|
// removing connection that was never added
|
||||||
return;
|
return;
|
||||||
@ -1339,7 +1336,7 @@ const NMDeviceWireless = new Lang.Class({
|
|||||||
let apObj = this._networks[i];
|
let apObj = this._networks[i];
|
||||||
let connections = apObj.connections;
|
let connections = apObj.connections;
|
||||||
for (let k = 0; k < connections.length; k++) {
|
for (let k = 0; k < connections.length; k++) {
|
||||||
if (connections[k]._uuid == connection._uuid) {
|
if (connections[k].get_uuid() == connection.get_uuid()) {
|
||||||
// remove the connection from the access point group
|
// remove the connection from the access point group
|
||||||
connections.splice(k);
|
connections.splice(k);
|
||||||
forceupdate = forceupdate || connections.length == 0;
|
forceupdate = forceupdate || connections.length == 0;
|
||||||
@ -1355,7 +1352,7 @@ const NMDeviceWireless = new Lang.Class({
|
|||||||
forceupdate = true;
|
forceupdate = true;
|
||||||
} else {
|
} else {
|
||||||
for (let j = 0; j < items.length; j++) {
|
for (let j = 0; j < items.length; j++) {
|
||||||
if (items[j]._connection._uuid == connection._uuid) {
|
if (items[j]._connection.get_uuid() == connection.get_uuid()) {
|
||||||
items[j].destroy();
|
items[j].destroy();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1382,8 +1379,8 @@ const NMDeviceWireless = new Lang.Class({
|
|||||||
// record the connection
|
// record the connection
|
||||||
let obj = {
|
let obj = {
|
||||||
connection: connection,
|
connection: connection,
|
||||||
name: connection._name,
|
name: connection.get_id(),
|
||||||
uuid: connection._uuid,
|
uuid: connection.get_uuid(),
|
||||||
};
|
};
|
||||||
this._connections.push(obj);
|
this._connections.push(obj);
|
||||||
|
|
||||||
@ -1878,7 +1875,7 @@ const NMApplet = new Lang.Class({
|
|||||||
let connections = this._settings.list_connections();
|
let connections = this._settings.list_connections();
|
||||||
for (let i = 0; i < connections.length; i++) {
|
for (let i = 0; i < connections.length; i++) {
|
||||||
let connection = connections[i];
|
let connection = connections[i];
|
||||||
if (connection._uuid) {
|
if (connection._updatedId) {
|
||||||
// connection was already seen (for example because NetworkManager was restarted)
|
// connection was already seen (for example because NetworkManager was restarted)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1891,7 +1888,7 @@ const NMApplet = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_newConnection: function(settings, connection) {
|
_newConnection: function(settings, connection) {
|
||||||
if (connection._uuid) {
|
if (connection._updatedId) {
|
||||||
// connection was already seen
|
// connection was already seen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1922,23 +1919,20 @@ const NMApplet = new Lang.Class({
|
|||||||
devices[i].removeConnection(connection);
|
devices[i].removeConnection(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection._uuid = null;
|
|
||||||
connection.disconnect(connection._removedId);
|
connection.disconnect(connection._removedId);
|
||||||
connection.disconnect(connection._updatedId);
|
connection.disconnect(connection._updatedId);
|
||||||
|
connection._removedId = connection._updatedId = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateConnection: function(connection) {
|
_updateConnection: function(connection) {
|
||||||
let connectionSettings = connection.get_setting_by_name(NetworkManager.SETTING_CONNECTION_SETTING_NAME);
|
let connectionSettings = connection.get_setting_by_name(NetworkManager.SETTING_CONNECTION_SETTING_NAME);
|
||||||
connection._type = connectionSettings.type;
|
connection._type = connectionSettings.type;
|
||||||
|
|
||||||
connection._section = this._ctypes[connection._type] || NMConnectionCategory.INVALID;
|
connection._section = this._ctypes[connection._type] || NMConnectionCategory.INVALID;
|
||||||
connection._name = connectionSettings.id;
|
|
||||||
connection._uuid = connectionSettings.uuid;
|
|
||||||
connection._timestamp = connectionSettings.timestamp;
|
connection._timestamp = connectionSettings.timestamp;
|
||||||
|
|
||||||
let section = connection._section;
|
let section = connection._section;
|
||||||
|
|
||||||
if (connection._section == NMConnectionCategory.INVALID)
|
if (section == NMConnectionCategory.INVALID)
|
||||||
return;
|
return;
|
||||||
if (section == NMConnectionCategory.VPN) {
|
if (section == NMConnectionCategory.VPN) {
|
||||||
this._devices.vpn.device.checkConnection(connection);
|
this._devices.vpn.device.checkConnection(connection);
|
||||||
|
Loading…
Reference in New Issue
Block a user