network: Make the device field private

With getIndicatorIcon() replacing the main use of the .device
field, we can make this a private API.

https://bugzilla.gnome.org/show_bug.cgi?id=701954
This commit is contained in:
Jasper St. Pierre 2013-06-11 19:56:17 -04:00
parent 6ef2d4a4cc
commit 465c77ddcf

View File

@ -290,34 +290,34 @@ const NMDevice = new Lang.Class({
_setDevice: function(device) {
if (device) {
this.device = device;
this.device._delegate = this;
this._stateChangedId = this.device.connect('state-changed', Lang.bind(this, this._deviceStateChanged));
this._activeConnectionChangedId = this.device.connect('notify::active-connection', Lang.bind(this, this._activeConnectionChanged));
} else if (this.device) {
this.device._delegate = null;
this._device = device;
this._device._delegate = this;
this._stateChangedId = this._device.connect('state-changed', Lang.bind(this, this._deviceStateChanged));
this._activeConnectionChangedId = this._device.connect('notify::active-connection', Lang.bind(this, this._activeConnectionChanged));
} else if (this._device) {
this._device._delegate = null;
if (this._stateChangedId) {
// Need to go through GObject.Object.prototype because
// nm_device_disconnect conflicts with g_signal_disconnect
GObject.Object.prototype.disconnect.call(this.device, this._stateChangedId);
GObject.Object.prototype.disconnect.call(this._device, this._stateChangedId);
this._stateChangedId = 0;
}
if (this._activeConnectionChangedId) {
GObject.Object.prototype.disconnect.call(this.device, this._activeConnectionChangedId);
GObject.Object.prototype.disconnect.call(this._device, this._activeConnectionChangedId);
this._stateChangedId = 0;
}
if (this._firmwareChangedId) {
GObject.Object.prototype.disconnect.call(this.device, this._firmwareChangedId);
GObject.Object.prototype.disconnect.call(this._device, this._firmwareChangedId);
this._firmwareChangedId = 0;
}
this.device = null;
this._device = null;
}
},
deactivate: function() {
this.device.disconnect(null);
this._device.disconnect(null);
return true;
},
@ -330,7 +330,7 @@ const NMDevice = new Lang.Class({
// Otherwise, if no connection is currently configured,
// try automatic configuration (or summon the config dialog)
if (this._connections.length == 1) {
this._client.activate_connection(this._connections[0].connection, this.device || null, null, null);
this._client.activate_connection(this._connections[0].connection, this._device || null, null, null);
return true;
} else if (this._connections.length == 0) {
return this._activateAutomaticConnection();
@ -341,16 +341,16 @@ const NMDevice = new Lang.Class({
_activateAutomaticConnection: function() {
let connection = new NetworkManager.Connection();
this._client.add_and_activate_connection(connection, this.device, null, null);
this._client.add_and_activate_connection(connection, this._device, null, null);
return true;
},
get connected() {
return this.device && this.device.state == NetworkManager.DeviceState.ACTIVATED;
return this._device && this._device.state == NetworkManager.DeviceState.ACTIVATED;
},
_activeConnectionChanged: function() {
let activeConnection = this.device.active_connection;
let activeConnection = this._device.active_connection;
if (activeConnection == this._activeConnection)
// nothing to do
@ -368,7 +368,7 @@ const NMDevice = new Lang.Class({
},
connectionValid: function(connection) {
return this.device.connection_valid(connection);
return this._device.connection_valid(connection);
},
setEnabled: function(enabled) {
@ -377,10 +377,10 @@ const NMDevice = new Lang.Class({
},
getStatusLabel: function() {
if (!this.device)
if (!this._device)
return null;
switch(this.device.state) {
switch(this._device.state) {
case NetworkManager.DeviceState.DISCONNECTED:
case NetworkManager.DeviceState.ACTIVATED:
return null;
@ -404,8 +404,8 @@ const NMDevice = new Lang.Class({
// firmware missing), that are exposed by different properties (whose state may
// or may not updated when we receive state-changed).
if (!this._firmwareChangedId)
this._firmwareChangedId = this.device.connect('notify::firmware-missing', Lang.bind(this, this._substateChanged));
if (this.device.firmware_missing) {
this._firmwareChangedId = this._device.connect('notify::firmware-missing', Lang.bind(this, this._substateChanged));
if (this._device.firmware_missing) {
/* Translators: this is for devices that require some kind of firmware or kernel
module, which is missing */
return _("firmware missing");
@ -416,14 +416,14 @@ const NMDevice = new Lang.Class({
case NetworkManager.DeviceState.FAILED:
return _("connection failed");
default:
log('Device state invalid, is %d'.format(this.device.state));
log('Device state invalid, is %d'.format(this._device.state));
return 'invalid';
}
},
syncDescription: function() {
if (this.device && this.device._description)
this.statusItem.label.text = this.device._description;
if (this._device && this._device._description)
this.statusItem.label.text = this._device._description;
},
_queueCreateSection: function() {
@ -444,7 +444,7 @@ const NMDevice = new Lang.Class({
},
_shouldShowConnectionList: function() {
return (this.device.state >= NetworkManager.DeviceState.DISCONNECTED);
return (this._device.state >= NetworkManager.DeviceState.DISCONNECTED);
},
_createSection: function() {
@ -482,7 +482,7 @@ const NMDevice = new Lang.Class({
let item = new PopupMenu.PopupMenuItem(obj.name);
item.connect('activate', Lang.bind(this, function() {
this._client.activate_connection(connection, this.device, null, null);
this._client.activate_connection(connection, this._device, null, null);
}));
return item;
},
@ -523,7 +523,7 @@ const NMDevice = new Lang.Class({
_updateStatusItem: function() {
if (this._firmwareChangedId) {
GObject.Object.prototype.disconnect.call(this.device, this._firmwareChangedId);
GObject.Object.prototype.disconnect.call(this._device, this._firmwareChangedId);
this._firmwareChangedId = 0;
}
@ -573,7 +573,7 @@ const NMDeviceWired = new Lang.Class({
},
getIndicatorIcon: function() {
if (this.device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
return 'network-wired-acquiring-symbolic';
else
return 'network-wired-symbolic';
@ -638,7 +638,7 @@ const NMDeviceModem = new Lang.Class({
},
get connected() {
return this._enabled && this.device.state == NetworkManager.DeviceState.ACTIVATED;
return this._enabled && this._device.state == NetworkManager.DeviceState.ACTIVATED;
},
destroy: function() {
@ -685,12 +685,12 @@ const NMDeviceModem = new Lang.Class({
// Mobile wizard is too complex for the shell UI and
// is handled by the network panel
Util.spawn(['gnome-control-center', 'network',
'connect-3g', this.device.get_path()]);
'connect-3g', this._device.get_path()]);
return true;
},
getIndicatorIcon: function() {
if (this.device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
return 'network-cellular-acquiring-symbolic';
if (!this.mobileDevice) {
@ -725,7 +725,7 @@ const NMDeviceBluetooth = new Lang.Class({
},
getIndicatorIcon: function() {
if (this.device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
return 'network-wired-acquiring-symbolic';
else
return 'network-wired-symbolic';
@ -746,7 +746,7 @@ const NMDeviceWireless = new Lang.Class({
let accessPoints = device.get_access_points() || [ ];
accessPoints.forEach(Lang.bind(this, function(ap) {
this._accessPointAdded(this.device, ap);
this._accessPointAdded(this._device, ap);
}));
this._activeApChanged();
@ -760,17 +760,17 @@ const NMDeviceWireless = new Lang.Class({
destroy: function() {
if (this._apChangedId) {
// see above for this HACK
GObject.Object.prototype.disconnect.call(this.device, this._apChangedId);
GObject.Object.prototype.disconnect.call(this._device, this._apChangedId);
this._apChangedId = 0;
}
if (this._apAddedId) {
GObject.Object.prototype.disconnect.call(this.device, 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);
GObject.Object.prototype.disconnect.call(this._device, this._apRemovedId);
this._apRemovedId = 0;
}
@ -798,14 +798,14 @@ const NMDeviceWireless = new Lang.Class({
if (accessPoint.get_ssid() != null) {
accessPoint.disconnect(accessPoint._notifySsidId);
accessPoint._notifySsidId = 0;
this._accessPointAdded(this.device, accessPoint);
this._accessPointAdded(this._device, accessPoint);
}
},
_activeApChanged: function() {
this._activeNetwork = null;
let activeAp = this.device.active_access_point;
let activeAp = this._device.active_access_point;
if (activeAp) {
let res = this._findExistingNetwork(activeAp);
@ -1138,7 +1138,7 @@ const NMDeviceWireless = new Lang.Class({
else
title = _("Connected (private)");
this._activeConnectionItem = new NMNetworkMenuItem(this.device.active_access_point);
this._activeConnectionItem = new NMNetworkMenuItem(this._device.active_access_point);
this._activeConnectionItem.setSensitive(false);
this._activeConnectionItem.setOrnament(PopupMenu.Ornament.DOT);
},
@ -1157,7 +1157,7 @@ const NMDeviceWireless = new Lang.Class({
let accessPoints = network.accessPoints;
for (let i = 0; i < accessPoints.length; i++) {
if (accessPoints[i].connection_valid(connection)) {
this._client.activate_connection(connection, this.device, accessPoints[i].dbus_path, null);
this._client.activate_connection(connection, this._device, accessPoints[i].dbus_path, null);
break;
}
}
@ -1170,10 +1170,10 @@ const NMDeviceWireless = new Lang.Class({
// 802.1x-enabled APs require further configuration, so they're
// handled in gnome-control-center
Util.spawn(['gnome-control-center', 'network', 'connect-8021x-wifi',
this.device.get_path(), accessPoints[0].dbus_path]);
this._device.get_path(), accessPoints[0].dbus_path]);
} else {
let connection = new NetworkManager.Connection();
this._client.add_and_activate_connection(connection, this.device, accessPoints[0].dbus_path, null)
this._client.add_and_activate_connection(connection, this._device, accessPoints[0].dbus_path, null)
}
}));
}
@ -1215,7 +1215,7 @@ const NMDeviceWireless = new Lang.Class({
},
_updateAccessPoint: function() {
let ap = this.device.active_access_point;
let ap = this._device.active_access_point;
if (this._activeAccessPoint == ap)
return;
@ -1239,12 +1239,12 @@ const NMDeviceWireless = new Lang.Class({
},
getIndicatorIcon: function() {
if (this.device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
return 'network-wireless-acquiring-symbolic';
let ap = this.device.active_access_point;
let ap = this._device.active_access_point;
if (!ap) {
if (this.device.mode != NM80211Mode.ADHOC)
if (this._device.mode != NM80211Mode.ADHOC)
log('An active wireless connection, in infrastructure mode, involves no access point?');
return 'network-wireless-connected-symbolic';
@ -1273,7 +1273,7 @@ const NMDeviceVirtual = new Lang.Class({
},
addConnection: function(connection) {
if (!this.device && !this.hasConnections())
if (!this._device && !this.hasConnections())
this.statusItem.label.text = NMGtk.utils_get_connection_device_name(connection);
this.parent(connection);
@ -1292,7 +1292,7 @@ const NMDeviceVirtual = new Lang.Class({
},
removeDevice: function(device) {
if (device == this.device) {
if (device == this._device) {
this._setDevice(null);
this._updateStatusItem();
this.emit('state-changed');
@ -1304,7 +1304,7 @@ const NMDeviceVirtual = new Lang.Class({
},
getIndicatorIcon: function() {
if (this.device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
if (this._device.active_connection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
return 'network-wired-acquiring-symbolic';
else
return 'network-wired-connected-symbolic';