From 16ab9b9edc13346b76a867562f8fa7cbbd6cf91a Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 11 Dec 2010 23:51:20 -0500 Subject: [PATCH] manager: If 2 URI names collide, make the names more verbose --- src/virtManager/connection.py | 27 ++++++++++++++++++++------- src/virtManager/manager.py | 22 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/virtManager/connection.py b/src/virtManager/connection.py index e90a8504c..354ab4f4c 100644 --- a/src/virtManager/connection.py +++ b/src/virtManager/connection.py @@ -418,7 +418,7 @@ class vmmConnection(vmmGObject): # Connection pretty print routines - def _get_pretty_desc(self, active, shorthost): + def _get_pretty_desc(self, active, shorthost, show_trans): def match_whole_string(orig, reg): match = re.match(reg, orig) if not match: @@ -429,14 +429,19 @@ class vmmConnection(vmmGObject): def is_ip_addr(orig): return match_whole_string(orig, "[0-9.]+") - (scheme, ignore, hostname, + (scheme, username, hostname, path, ignore, ignore) = virtinst.util.uri_split(self.uri) hv = "" rest = "" - scheme = scheme.split("+")[0] + transport = "" + port = "" + if scheme.count("+"): + transport = scheme.split("+")[1] + scheme = scheme.split("+")[0] if hostname.count(":"): + port = hostname.split(":")[1] hostname = hostname.split(":")[0] if hostname: @@ -456,6 +461,14 @@ class vmmConnection(vmmGObject): else: hv = scheme.capitalize() + if show_trans: + if transport: + hv += "+" + transport + if username: + hostname = username + "@" + hostname + if port: + hostname += ":" + port + if path and path != "/system" and path != "/": if path == "/session": hv += " Usermode" @@ -464,11 +477,11 @@ class vmmConnection(vmmGObject): return "%s (%s)" % (rest, hv) - def get_pretty_desc_inactive(self, shorthost=True): - return self._get_pretty_desc(False, shorthost) + def get_pretty_desc_inactive(self, shorthost=True, transport=False): + return self._get_pretty_desc(False, shorthost, transport) - def get_pretty_desc_active(self, shorthost=True): - return self._get_pretty_desc(True, shorthost) + def get_pretty_desc_active(self, shorthost=True, transport=False): + return self._get_pretty_desc(True, shorthost, transport) ####################### diff --git a/src/virtManager/manager.py b/src/virtManager/manager.py index 194e923a2..b817f0a71 100644 --- a/src/virtManager/manager.py +++ b/src/virtManager/manager.py @@ -825,6 +825,24 @@ class vmmManager(vmmGObjectUI): row = self._append_connection(vmlist.get_model(), conn) vmlist.get_selection().select_iter(row) + # Try to make sure that 2 row descriptions don't collide + connrows = [] + descs = [] + for row in self.rows.values(): + if row[ROW_IS_CONN]: + connrows.append(row) + for row in connrows: + descs.append(row[ROW_NAME]) + + for row in connrows: + conn = row[ROW_HANDLE] + name = row[ROW_NAME] + if descs.count(name) <= 1: + continue + + newname = conn.get_pretty_desc_inactive(False, True) + self.conn_refresh_resources(conn, newname) + def _remove_connection(self, engine_ignore, conn): model = self.window.get_widget("vm-list").get_model() parent = self.rows[conn.get_uri()].iter @@ -879,11 +897,13 @@ class vmmManager(vmmGObjectUI): self.conn_refresh_resources(conn) self.vm_selected() - def conn_refresh_resources(self, conn): + def conn_refresh_resources(self, conn, newname=None): vmlist = self.window.get_widget("vm-list") model = vmlist.get_model() row = self.rows[conn.get_uri()] + if newname: + row[ROW_NAME] = newname row[ROW_MARKUP] = self._build_conn_markup(conn, row) row[ROW_STATUS] = ("%s" % conn.get_state_text())