network: Rename "apObj" to "network"

We put these "access point objects" in "this._networks" and
"this._activeNetwork", so let's rename it. This also makes
the fact that each "access point object" can contain multiple
access points a tiny bit less confusing.

https://bugzilla.gnome.org/show_bug.cgi?id=698918
This commit is contained in:
Jasper St. Pierre 2013-04-25 21:18:20 -04:00
parent b4b00a48d9
commit bfdf069d2d

View File

@ -814,20 +814,20 @@ const NMDeviceWireless = new Lang.Class({
} }
let pos = this._findNetwork(ap); let pos = this._findNetwork(ap);
let obj; let network;
if (pos != -1) { if (pos != -1) {
obj = this._networks[pos]; network = this._networks[pos];
obj.accessPoints.push(ap); network.accessPoints.push(ap);
} else { } else {
obj = { ssid: ap.get_ssid(), network = { ssid: ap.get_ssid(),
mode: ap.mode, mode: ap.mode,
security: this._getApSecurityType(ap), security: this._getApSecurityType(ap),
connections: [ ], connections: [ ],
item: null, item: null,
accessPoints: [ ap ] accessPoints: [ ap ]
}; };
obj.ssidText = ssidToLabel(obj.ssid); network.ssidText = ssidToLabel(network.ssid);
this._networks.push(obj); this._networks.push(network);
} }
ap._updateId = ap.connect('notify::strength', Lang.bind(this, this._onApStrengthChanged)); ap._updateId = ap.connect('notify::strength', Lang.bind(this, this._onApStrengthChanged));
@ -835,8 +835,8 @@ const NMDeviceWireless = new Lang.Class({
for (let j = 0; j < validConnections.length; j++) { for (let j = 0; j < validConnections.length; j++) {
let connection = validConnections[j]; let connection = validConnections[j];
if (ap.connection_valid(connection) && if (ap.connection_valid(connection) &&
obj.connections.indexOf(connection) == -1) { network.connections.indexOf(connection) == -1) {
obj.connections.push(connection); network.connections.push(connection);
} }
} }
} }
@ -992,9 +992,9 @@ const NMDeviceWireless = new Lang.Class({
_findExistingNetwork: function(accessPoint) { _findExistingNetwork: function(accessPoint) {
for (let i = 0; i < this._networks.length; i++) { for (let i = 0; i < this._networks.length; i++) {
let apObj = this._networks[i]; let network = this._networks[i];
for (let j = 0; j < apObj.accessPoints.length; j++) { for (let j = 0; j < network.accessPoints.length; j++) {
if (apObj.accessPoints[j] == accessPoint) if (network.accessPoints[j] == accessPoint)
return { network: i, ap: j }; return { network: i, ap: j };
} }
} }
@ -1042,30 +1042,30 @@ const NMDeviceWireless = new Lang.Class({
} }
let pos = this._findNetwork(accessPoint); let pos = this._findNetwork(accessPoint);
let apObj; let network;
let needsupdate = false; let needsupdate = false;
if (pos != -1) { if (pos != -1) {
apObj = this._networks[pos]; network = this._networks[pos];
if (apObj.accessPoints.indexOf(accessPoint) != -1) { if (network.accessPoints.indexOf(accessPoint) != -1) {
log('Access point was already seen, not adding again'); log('Access point was already seen, not adding again');
return; return;
} }
Util.insertSorted(apObj.accessPoints, accessPoint, function(one, two) { Util.insertSorted(network.accessPoints, accessPoint, function(one, two) {
return two.strength - one.strength; return two.strength - one.strength;
}); });
if (apObj.item) if (network.item)
apObj.item.updateBestAP(apObj.accessPoints[0]); network.item.updateBestAP(network.accessPoints[0]);
} else { } else {
apObj = { ssid: accessPoint.get_ssid(), network = { ssid: accessPoint.get_ssid(),
mode: accessPoint.mode, mode: accessPoint.mode,
security: this._getApSecurityType(accessPoint), security: this._getApSecurityType(accessPoint),
connections: [ ], connections: [ ],
item: null, item: null,
accessPoints: [ accessPoint ] accessPoints: [ accessPoint ]
}; };
apObj.ssidText = ssidToLabel(apObj.ssid); network.ssidText = ssidToLabel(network.ssid);
} }
accessPoint._updateId = accessPoint.connect('notify::strength', Lang.bind(this, this._onApStrengthChanged)); accessPoint._updateId = accessPoint.connect('notify::strength', Lang.bind(this, this._onApStrengthChanged));
@ -1073,14 +1073,14 @@ const NMDeviceWireless = new Lang.Class({
for (let i = 0; i < this._connections.length; i++) { for (let i = 0; i < this._connections.length; i++) {
let connection = this._connections[i].connection; let connection = this._connections[i].connection;
if (accessPoint.connection_valid(connection) && if (accessPoint.connection_valid(connection) &&
apObj.connections.indexOf(connection) == -1) { network.connections.indexOf(connection) == -1) {
apObj.connections.push(connection); network.connections.push(connection);
} }
} }
if (pos != -1) if (pos != -1)
this._networks.splice(pos, 1); this._networks.splice(pos, 1);
let newPos = Util.insertSorted(this._networks, apObj, this._networkSortFunction); let newPos = Util.insertSorted(this._networks, network, this._networkSortFunction);
// Queue an update of the UI if we changed the order // Queue an update of the UI if we changed the order
if (newPos != pos) if (newPos != pos)
@ -1100,28 +1100,28 @@ const NMDeviceWireless = new Lang.Class({
return; return;
} }
let apObj = this._networks[res.network]; let network = this._networks[res.network];
apObj.accessPoints.splice(res.ap, 1); network.accessPoints.splice(res.ap, 1);
if (apObj.accessPoints.length == 0) { if (network.accessPoints.length == 0) {
if (this._activeNetwork == apObj) if (this._activeNetwork == network)
this._activeNetwork = null; this._activeNetwork = null;
if (apObj.item) if (network.item)
apObj.item.destroy(); network.item.destroy();
if (this._overflowItem) { if (this._overflowItem) {
if (!apObj.isMore) { if (!network.isMore) {
// we removed an item in the main menu, and we have a more submenu // we removed an item in the main menu, and we have a more submenu
// we need to extract the first item in more and move it to the submenu // we need to extract the first item in more and move it to the submenu
let item = this._overflowItem.menu.firstMenuItem; let item = this._overflowItem.menu.firstMenuItem;
if (item && item._apObj) { if (item && item._network) {
item.destroy(); item.destroy();
// clear the cycle, and allow the construction of the new item // clear the cycle, and allow the construction of the new item
item._apObj.item = null; item._network.item = null;
this._createNetworkItem(item._apObj, NUM_VISIBLE_NETWORKS-1); this._createNetworkItem(item._network, NUM_VISIBLE_NETWORKS-1);
} else { } else {
log('The more... menu was existing and empty! This should not happen'); log('The more... menu was existing and empty! This should not happen');
} }
@ -1140,14 +1140,14 @@ const NMDeviceWireless = new Lang.Class({
let okPrev = true, okNext = true; let okPrev = true, okNext = true;
if (res.network > 0) if (res.network > 0)
okPrev = this._networkSortFunction(this._networks[res.network - 1], apObj) >= 0; okPrev = this._networkSortFunction(this._networks[res.network - 1], network) >= 0;
if (res.network < this._networks.length-1) if (res.network < this._networks.length-1)
okNext = this._networkSortFunction(this._networks[res.network + 1], apObj) <= 0; okNext = this._networkSortFunction(this._networks[res.network + 1], network) <= 0;
if (!okPrev || !okNext) if (!okPrev || !okNext)
this._queueCreateSection(); this._queueCreateSection();
else if (apObj.item) else if (network.item)
apObj.item.updateBestAP(apObj.accessPoints[0]); network.item.updateBestAP(network.accessPoints[0]);
} }
}, },
@ -1186,8 +1186,8 @@ const NMDeviceWireless = new Lang.Class({
let forceupdate = false; let forceupdate = false;
for (let i = 0; i < this._networks.length; i++) { for (let i = 0; i < this._networks.length; i++) {
let apObj = this._networks[i]; let network = this._networks[i];
let connections = apObj.connections; let connections = network.connections;
for (let k = 0; k < connections.length; k++) { for (let k = 0; k < connections.length; k++) {
if (connections[k].get_uuid() == connection.get_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
@ -1197,9 +1197,9 @@ const NMDeviceWireless = new Lang.Class({
if (forceupdate) if (forceupdate)
break; break;
if (apObj.item) { if (network.item) {
if (apObj.item instanceof PopupMenu.PopupSubMenuMenuItem) { if (network.item instanceof PopupMenu.PopupSubMenuMenuItem) {
let items = apObj.item.menu._getMenuItems(); let items = network.item.menu._getMenuItems();
if (items.length == 2) { if (items.length == 2) {
// we need to update the connection list to convert this to a normal item // we need to update the connection list to convert this to a normal item
forceupdate = true; forceupdate = true;
@ -1212,8 +1212,8 @@ const NMDeviceWireless = new Lang.Class({
} }
} }
} else { } else {
apObj.item.destroy(); network.item.destroy();
apObj.item = null; network.item = null;
} }
} }
break; break;
@ -1239,13 +1239,13 @@ const NMDeviceWireless = new Lang.Class({
// find an appropriate access point // find an appropriate access point
let forceupdate = false; let forceupdate = false;
for (let i = 0; i < this._networks.length; i++) { for (let i = 0; i < this._networks.length; i++) {
let apObj = this._networks[i]; let network = this._networks[i];
// Check if connection is valid for any of these access points // Check if connection is valid for any of these access points
for (let k = 0; k < apObj.accessPoints.length; k++) { for (let k = 0; k < network.accessPoints.length; k++) {
let ap = apObj.accessPoints[k]; let ap = network.accessPoints[k];
if (ap.connection_valid(connection)) { if (ap.connection_valid(connection)) {
apObj.connections.push(connection); network.connections.push(connection);
// this potentially changes the sorting order // this potentially changes the sorting order
forceupdate = true; forceupdate = true;
break; break;
@ -1271,25 +1271,25 @@ const NMDeviceWireless = new Lang.Class({
this._activeConnectionItem.setOrnament(PopupMenu.Ornament.DOT); this._activeConnectionItem.setOrnament(PopupMenu.Ornament.DOT);
}, },
_createNetworkItem: function(apObj, position) { _createNetworkItem: function(network, position) {
if(!apObj.accessPoints || apObj.accessPoints.length == 0) { if(!network.accessPoints || network.accessPoints.length == 0) {
// this should not happen, but I have no idea why it happens // this should not happen, but I have no idea why it happens
return; return;
} }
if(apObj.connections.length > 0) { if(network.connections.length > 0) {
if (apObj.connections.length == 1) { if (network.connections.length == 1) {
apObj.item = this._createAPItem(apObj.connections[0], apObj, false); network.item = this._createAPItem(network.connections[0], network, false);
} else { } else {
let title = apObj.ssidText; let title = network.ssidText;
apObj.item = new PopupMenu.PopupSubMenuMenuItem(title); network.item = new PopupMenu.PopupSubMenuMenuItem(title);
for (let i = 0; i < apObj.connections.length; i++) for (let i = 0; i < network.connections.length; i++)
apObj.item.menu.addMenuItem(this._createAPItem(apObj.connections[i], apObj, true)); network.item.menu.addMenuItem(this._createAPItem(network.connections[i], network, true));
} }
} else { } else {
apObj.item = new NMNetworkMenuItem(apObj.accessPoints[0]); network.item = new NMNetworkMenuItem(network.accessPoints[0]);
apObj.item.connect('activate', Lang.bind(this, function() { network.item.connect('activate', Lang.bind(this, function() {
let accessPoints = apObj.accessPoints; let accessPoints = network.accessPoints;
if ( (accessPoints[0]._secType == NMAccessPointSecurity.WPA2_ENT) if ( (accessPoints[0]._secType == NMAccessPointSecurity.WPA2_ENT)
|| (accessPoints[0]._secType == NMAccessPointSecurity.WPA_ENT)) { || (accessPoints[0]._secType == NMAccessPointSecurity.WPA_ENT)) {
// 802.1x-enabled APs require further configuration, so they're // 802.1x-enabled APs require further configuration, so they're
@ -1302,18 +1302,18 @@ const NMDeviceWireless = new Lang.Class({
} }
})); }));
} }
apObj.item._apObj = apObj; network.item._network = network;
if (position < NUM_VISIBLE_NETWORKS) { if (position < NUM_VISIBLE_NETWORKS) {
apObj.isMore = false; network.isMore = false;
this.section.addMenuItem(apObj.item, position); this.section.addMenuItem(network.item, position);
} else { } else {
if (!this._overflowItem) { if (!this._overflowItem) {
this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More…")); this._overflowItem = new PopupMenu.PopupSubMenuMenuItem(_("More…"));
this.section.addMenuItem(this._overflowItem); this.section.addMenuItem(this._overflowItem);
} }
this._overflowItem.menu.addMenuItem(apObj.item, position - NUM_VISIBLE_NETWORKS); this._overflowItem.menu.addMenuItem(network.item, position - NUM_VISIBLE_NETWORKS);
apObj.isMore = true; network.isMore = true;
} }
}, },
@ -1329,13 +1329,13 @@ const NMDeviceWireless = new Lang.Class({
let activeOffset = this._activeConnectionItem ? 1 : 0; let activeOffset = this._activeConnectionItem ? 1 : 0;
for(let j = 0; j < this._networks.length; j++) { for(let j = 0; j < this._networks.length; j++) {
let apObj = this._networks[j]; let network = this._networks[j];
if (apObj == this._activeNetwork) { if (network == this._activeNetwork) {
activeOffset--; activeOffset--;
continue; continue;
} }
this._createNetworkItem(apObj, j + activeOffset); this._createNetworkItem(network, j + activeOffset);
} }
}, },
}); });