NetworkMenu: fix connection name update

If the connection name is changed, the UUID doesn't necessarily,
so checkConnection would take the early return path. Make sure
we update the existing menu item too.

https://bugzilla.gnome.org/show_bug.cgi?id=723570
This commit is contained in:
Giovanni Campagna 2014-02-08 14:32:23 +01:00
parent f43ff45683
commit 488a42696c

View File

@ -118,6 +118,19 @@ const NMConnectionItem = new Lang.Class({
this.switchItem.destroy(); this.switchItem.destroy();
}, },
updateForConnection: function(connection) {
// 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;
this.switchItem.label.text = connection.get_id();
this._sync();
this.emit('name-changed');
},
getName: function() { getName: function() {
return this._connection.get_id(); return this._connection.get_id();
}, },
@ -231,10 +244,6 @@ const NMConnectionSection = new Lang.Class({
return _("Connect"); return _("Connect");
}, },
_hasConnection: function(connection) {
return this._connectionItems.has(connection.get_uuid());
},
_connectionValid: function(connection) { _connectionValid: function(connection) {
return true; return true;
}, },
@ -254,10 +263,20 @@ const NMConnectionSection = new Lang.Class({
if (!this._connectionValid(connection)) if (!this._connectionValid(connection))
return; return;
if (this._hasConnection(connection)) // This function is called everytime connection is added or updated
return; // 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
// it's valid for this device), in which case we add a new item
this._addConnection(connection); let item = this._connectionItems.get(connection.get_uuid());
if (item)
item.updateForConnection(connection);
else
this._addConnection(connection);
}, },
_addConnection: function(connection) { _addConnection: function(connection) {
@ -271,6 +290,7 @@ const NMConnectionSection = new Lang.Class({
item.connect('activation-failed', Lang.bind(this, function(item, reason) { item.connect('activation-failed', Lang.bind(this, function(item, reason) {
this.emit('activation-failed', reason); this.emit('activation-failed', reason);
})); }));
item.connect('name-changed', Lang.bind(this, this._sync));
let pos = Util.insertSorted(this._connections, connection, Lang.bind(this, this._connectionSortFunction)); let pos = Util.insertSorted(this._connections, connection, Lang.bind(this, this._connectionSortFunction));
this._labelSection.addMenuItem(item.labelItem, pos); this._labelSection.addMenuItem(item.labelItem, pos);