changeset 4d5c6be751db in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=4d5c6be751db
description: Improve group renaming efficiency. Fixes #4212
diffstat:
src/common/connection.py | 5 ++
src/common/xmpp/roster_nb.py | 10 +++++
src/common/zeroconf/connection_zeroconf.py | 5 ++
src/common/zeroconf/roster_zeroconf.py | 4 ++
src/roster_window.py | 63
+++++++++++++++++++++++--------
5 files changed, 70 insertions(+), 17 deletions(-)
diffs (144 lines):
diff -r 6eecfdb97a5a -r 4d5c6be751db src/common/connection.py
--- a/src/common/connection.py Sat Sep 26 11:55:49 2009 +0200
+++ b/src/common/connection.py Sat Sep 26 20:23:59 2009 +0200
@@ -1487,6 +1487,11 @@
self.connection.getRoster().setItem(jid = jid, name =
name,
groups = groups)
+ def update_contacts(self, contacts):
+ '''update multiple roster items on jabber server'''
+ if self.connection:
+ self.connection.getRoster().setItemMulti(contacts)
+
def send_new_account_infos(self, form, is_form):
if is_form:
# Get username and password and put them in
new_account_info
diff -r 6eecfdb97a5a -r 4d5c6be751db src/common/xmpp/roster_nb.py
--- a/src/common/xmpp/roster_nb.py Sat Sep 26 11:55:49 2009 +0200
+++ b/src/common/xmpp/roster_nb.py Sat Sep 26 20:23:59 2009 +0200
@@ -174,6 +174,16 @@
item=query.setTag('item',attrs)
for group in groups:
item.addChild(node=Node('group',payload=[group]))
self._owner.send(iq)
+ def setItemMulti(self,items):
+ ''' Renames multiple contacts and sets their group lists.'''
+ iq=Iq('set',NS_ROSTER)
+ query=iq.getTag('query')
+ for i in items:
+ attrs={'jid':i['jid']}
+ if i['name']: attrs['name']=i['name']
+ item=query.setTag('item',attrs)
+ for group in i['groups']:
item.addChild(node=Node('group',payload=[group]))
+ self._owner.send(iq)
def getItems(self):
''' Return list of all [bare] JIDs that the roster is currently
tracks.'''
return self._data.keys()
diff -r 6eecfdb97a5a -r 4d5c6be751db src/common/zeroconf/connection_zeroconf.py
--- a/src/common/zeroconf/connection_zeroconf.py Sat Sep 26 11:55:49
2009 +0200
+++ b/src/common/zeroconf/connection_zeroconf.py Sat Sep 26 20:23:59
2009 +0200
@@ -526,6 +526,11 @@
self.connection.getRoster().setItem(jid = jid, name =
name,
groups = groups)
+ def update_contacts(self, contacts):
+ '''update multiple roster items'''
+ if self.connection:
+ self.connection.getRoster().setItemMulti(contacts)
+
def new_account(self, name, config, sync = False):
gajim.log.debug('This should not happen (new_account)')
diff -r 6eecfdb97a5a -r 4d5c6be751db src/common/zeroconf/roster_zeroconf.py
--- a/src/common/zeroconf/roster_zeroconf.py Sat Sep 26 11:55:49 2009 +0200
+++ b/src/common/zeroconf/roster_zeroconf.py Sat Sep 26 20:23:59 2009 +0200
@@ -88,6 +88,10 @@
self._data[jid]['status'] = status
self._data[jid]['show'] = status
+ def setItemMulti(self, items):
+ for i in items:
+ self.setItem(jid=i['jid'], name=i['name'],
groups=i['groups'])
+
def delItem(self, jid):
#print 'roster_zeroconf.py: delItem %s' % jid
if jid in self._data:
diff -r 6eecfdb97a5a -r 4d5c6be751db src/roster_window.py
--- a/src/roster_window.py Sat Sep 26 11:55:49 2009 +0200
+++ b/src/roster_window.py Sat Sep 26 20:23:59 2009 +0200
@@ -848,6 +848,51 @@
'''Remove transport from roster and redraw account and group.'''
self.remove_contact(jid, account, force=True, backend=True)
return True
+
+ def rename_group(self, old_name, new_name):
+ """
+ rename a roster group
+ """
+ if old_name == new_name:
+ return
+
+ # Groups may not change name from or to a special groups
+ for g in helpers.special_groups:
+ if g in (new_name, old_name):
+ return
+
+ # update all contacts in the given group
+ if self.regroup:
+ accounts = gajim.connections.keys()
+ else:
+ accounts = [account,]
+
+ for acc in accounts:
+ changed_contacts = []
+ for jid in gajim.contacts.get_jid_list(acc):
+ contact =
gajim.contacts.get_first_contact_from_jid(acc, jid)
+ if old_name not in contact.groups:
+ continue
+
+ self.remove_contact(jid, acc, force=True)
+
+ contact.groups.remove(old_name)
+ if new_name not in contact.groups:
+ contact.groups.append(new_name)
+
+ changed_contacts.append({'jid':jid,
'name':contact.name,
+ 'groups':contact.groups})
+
+
gajim.connections[acc].update_contacts(changed_contacts)
+
+ for c in changed_contacts:
+ self.add_contact(c['jid'], acc)
+
+ self._adjust_group_expand_collapse_state(new_name, acc)
+
+ self.draw_group(old_name, acc)
+ self.draw_group(new_name, acc)
+
def add_contact_to_groups(self, jid, account, groups, update=True):
'''Add contact to given groups and redraw them.
@@ -2711,23 +2756,7 @@
win.show_title()
elif row_type == 'group':
# in C_JID column, we hold the group name
(which is not escaped)
- if old_text == new_text:
- return
- # Groups may not change name from or to a
special groups
- for g in helpers.special_groups:
- if g in (new_text, old_text):
- return
- # update all contacts in the given group
- if self.regroup:
- accounts = gajim.connections.keys()
- else:
- accounts = [account,]
- for acc in accounts:
- for jid in
gajim.contacts.get_jid_list(acc):
- contact =
gajim.contacts.get_first_contact_from_jid(acc, jid)
- if old_text in contact.groups:
-
self.add_contact_to_groups(jid, acc, [new_text,])
-
self.remove_contact_from_groups(jid, acc, [old_text,])
+ self.rename_group(old_text, new_text)
def on_canceled():
if 'rename' in gajim.interface.instances:
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits