network: Remove setActiveConnection/clearActiveConnection

This can be more easily achieved by listening for changes to the
device's active-connection property. VPN will still need support to
track active connections, as it does not have an associated
device. But as VPN can track multiple active connections, the names
"set" and "clear" don't quite fit. Rename them to the more-standard
"add" and "remove".

https://bugzilla.gnome.org/show_bug.cgi?id=701954
This commit is contained in:
Jasper St. Pierre 2013-04-26 21:44:59 -04:00
parent 308b1d6039
commit 2cbee05c8a

View File

@ -302,6 +302,7 @@ const NMDevice = new Lang.Class({
this.device = device; this.device = device;
this.device._delegate = this; this.device._delegate = this;
this._stateChangedId = this.device.connect('state-changed', Lang.bind(this, this._deviceStateChanged)); this._stateChangedId = this.device.connect('state-changed', Lang.bind(this, this._deviceStateChanged));
this._activeConnectionChangedId = this.device.connect('notify::active-connection', Lang.bind(this, this._activeConnectionChanged));
} else if (this.device) { } else if (this.device) {
this.device._delegate = null; this.device._delegate = null;
@ -311,6 +312,10 @@ const NMDevice = new Lang.Class({
GObject.Object.prototype.disconnect.call(this.device, this._stateChangedId); GObject.Object.prototype.disconnect.call(this.device, this._stateChangedId);
this._stateChangedId = 0; this._stateChangedId = 0;
} }
if (this._activeConnectionChangedId) {
GObject.Object.prototype.disconnect.call(this.device, this._activeConnectionChangedId);
this._stateChangedId = 0;
}
if (this._carrierChangedId) { if (this._carrierChangedId) {
GObject.Object.prototype.disconnect.call(this.device, this._carrierChangedId); GObject.Object.prototype.disconnect.call(this.device, this._carrierChangedId);
this._carrierChangedId = 0; this._carrierChangedId = 0;
@ -357,11 +362,9 @@ const NMDevice = new Lang.Class({
return this.device && this.device.state == NetworkManager.DeviceState.ACTIVATED; return this.device && this.device.state == NetworkManager.DeviceState.ACTIVATED;
}, },
clearActiveConnection: function(activeConnection) { _activeConnectionChanged: function() {
this.setActiveConnection(null); let activeConnection = this.device.active_connection;
},
setActiveConnection: function(activeConnection) {
if (activeConnection == this._activeConnection) if (activeConnection == this._activeConnection)
// nothing to do // nothing to do
return; return;
@ -830,7 +833,7 @@ const NMDeviceWireless = new Lang.Class({
this._activeNetwork = this._networks[res.network]; this._activeNetwork = this._networks[res.network];
} }
// we don't refresh the view here, setActiveConnection will // we don't refresh the view here, _activeConnectionChanged will
}, },
_getApSecurityType: function(accessPoint) { _getApSecurityType: function(accessPoint) {
@ -1319,7 +1322,7 @@ const NMVPNSection = new Lang.Class({
} }
}, },
clearActiveConnection: function(activeConnection) { removeActiveConnection: function(activeConnection) {
let pos = this._findConnection(activeConnection.uuid); let pos = this._findConnection(activeConnection.uuid);
if (pos < 0) if (pos < 0)
return; return;
@ -1334,7 +1337,7 @@ const NMVPNSection = new Lang.Class({
} }
}, },
setActiveConnection: function(activeConnection) { addActiveConnection: function(activeConnection) {
let pos = this._findConnection(activeConnection.uuid); let pos = this._findConnection(activeConnection.uuid);
if (pos < 0) if (pos < 0)
return; return;
@ -1777,10 +1780,8 @@ const NMApplet = new Lang.Class({
for (let i = 0; i < closedConnections.length; i++) { for (let i = 0; i < closedConnections.length; i++) {
let a = closedConnections[i]; let a = closedConnections[i];
if (a._primaryDevice) { if (a._type == NetworkManager.SETTING_VPN_SETTING_NAME)
a._primaryDevice.clearActiveConnection(a); this._vpnSection.removeActiveConnection(a);
a._primaryDevice = null;
}
if (a._inited) { if (a._inited) {
a.disconnect(a._notifyStateId); a.disconnect(a._notifyStateId);
a.disconnect(a._notifyDefaultId); a.disconnect(a._notifyDefaultId);
@ -1839,14 +1840,13 @@ const NMApplet = new Lang.Class({
active_vpn = a; active_vpn = a;
if (!a._primaryDevice) { if (!a._primaryDevice) {
if (a._type != NetworkManager.SETTING_VPN_SETTING_NAME) if (a._type != NetworkManager.SETTING_VPN_SETTING_NAME) {
// This list is guaranteed to have one device in it. // This list is guaranteed to have one device in it.
a._primaryDevice = a.get_devices()[0]._delegate; a._primaryDevice = a.get_devices()[0]._delegate;
else } else {
a._primaryDevice = this._vpnSection; a._primaryDevice = this._vpnSection;
this._vpnSection.addActiveConnection(a);
if (a._primaryDevice) }
a._primaryDevice.setActiveConnection(a);
if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED
&& a._primaryDevice && a._primaryDevice._notification) { && a._primaryDevice && a._primaryDevice._notification) {