we can now edit groups of multiple contacts. Fixes #1514

This commit is contained in:
Yann Leboulanger 2006-07-28 10:25:58 +00:00
parent 1dcc955551
commit 1ee455edb7
2 changed files with 109 additions and 74 deletions

View File

@ -44,18 +44,25 @@ from common import helpers
class EditGroupsDialog: class EditGroupsDialog:
'''Class for the edit group dialog window''' '''Class for the edit group dialog window'''
def __init__(self, user, account): def __init__(self, list_):
'''list_ is a list of (contact, account) tuples'''
self.xml = gtkgui_helpers.get_glade('edit_groups_dialog.glade') self.xml = gtkgui_helpers.get_glade('edit_groups_dialog.glade')
self.dialog = self.xml.get_widget('edit_groups_dialog') self.dialog = self.xml.get_widget('edit_groups_dialog')
self.dialog.set_transient_for(gajim.interface.roster.window) self.dialog.set_transient_for(gajim.interface.roster.window)
self.account = account self.list_ = list_
self.user = user
self.changes_made = False self.changes_made = False
self.list = self.xml.get_widget('groups_treeview') self.list = self.xml.get_widget('groups_treeview')
self.xml.get_widget('nickname_label').set_markup( if len(list_) == 1:
_("Contact's name: <i>%s</i>") % user.get_shown_name()) contact = list_[0][0]
self.xml.get_widget('jid_label').set_markup( self.xml.get_widget('nickname_label').set_markup(
_('JID: <i>%s</i>') % user.jid) _("Contact's name: <i>%s</i>") % contact.get_shown_name())
self.xml.get_widget('jid_label').set_markup(
_('JID: <i>%s</i>') % contact.jid)
else:
self.xml.get_widget('nickname_label').set_no_show_all(True)
self.xml.get_widget('nickname_label').hide()
self.xml.get_widget('jid_label').set_no_show_all(True)
self.xml.get_widget('jid_label').hide()
self.xml.signal_autoconnect(self) self.xml.signal_autoconnect(self)
self.init_list() self.init_list()
@ -63,67 +70,71 @@ class EditGroupsDialog:
def run(self): def run(self):
self.dialog.show_all() self.dialog.show_all()
if self.changes_made: if self.changes_made:
gajim.connections[self.account].update_contact(self.user.jid, for (contact, account) in self.list_:
self.user.name, self.user.groups) gajim.connections[account].update_contact(contact.jid, contact.name,
contact.groups)
def on_edit_groups_dialog_response(self, widget, response_id): def on_edit_groups_dialog_response(self, widget, response_id):
if response_id == gtk.RESPONSE_CLOSE: if response_id == gtk.RESPONSE_CLOSE:
self.dialog.destroy() self.dialog.destroy()
def update_contact(self): def update_contact(self):
tag = gajim.contacts.get_metacontacts_tag(self.account, self.user.jid) for (contact, account) in self.list_:
if not tag: tag = gajim.contacts.get_metacontacts_tag(account, contact.jid)
gajim.interface.roster.remove_contact(self.user, self.account) if not tag:
gajim.interface.roster.add_contact_to_roster(self.user.jid, gajim.interface.roster.remove_contact(contact, account)
self.account) gajim.interface.roster.add_contact_to_roster(contact.jid, account)
gajim.connections[self.account].update_contact(self.user.jid, gajim.connections[account].update_contact(contact.jid, contact.name,
self.user.name, self.user.groups) contact.groups)
return
all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue continue
for _jid in all_jid[_account]: all_jid = gajim.contacts.get_metacontacts_jids(tag)
c = gajim.contacts.get_first_contact_from_jid(_account, _jid) for _account in all_jid:
if not c: if not gajim.interface.roster.regroup and _account != account:
continue continue
gajim.interface.roster.remove_contact(c, _account) for _jid in all_jid[_account]:
gajim.interface.roster.add_contact_to_roster(_jid, _account) c = gajim.contacts.get_first_contact_from_jid(_account, _jid)
gajim.connections[_account].update_contact(_jid, c.name, c.groups) if not c:
continue
gajim.interface.roster.remove_contact(c, _account)
gajim.interface.roster.add_contact_to_roster(_jid, _account)
gajim.connections[_account].update_contact(_jid, c.name,
c.groups)
def remove_group(self, group): def remove_group(self, group):
'''add group group to self.user and all his brothers''' '''remove group group from all contacts and all their brothers'''
tag = gajim.contacts.get_metacontacts_tag(self.account, self.user.jid) for (contact, account) in self.list_:
if not tag: tag = gajim.contacts.get_metacontacts_tag(account, contact.jid)
if group in self.user.groups: if not tag:
self.user.groups.remove(group) if group in contact.groups:
return contact.groups.remove(group)
all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue continue
for _jid in all_jid[_account]: all_jid = gajim.contacts.get_metacontacts_jids(tag)
contacts = gajim.contacts.get_contact(_account, _jid) for _account in all_jid:
for contact in contacts: if not gajim.interface.roster.regroup and _account != account:
if group in contact.groups: continue
contact.groups.remove(group) for _jid in all_jid[_account]:
contacts = gajim.contacts.get_contact(_account, _jid)
for c in contacts:
if group in c.groups:
c.groups.remove(group)
def add_group(self, group): def add_group(self, group):
'''add group group to self.user and all his brothers''' '''add group group to all contacts and all their brothers'''
tag = gajim.contacts.get_metacontacts_tag(self.account, self.user.jid) for (contact, account) in self.list_:
if not tag: tag = gajim.contacts.get_metacontacts_tag(account, contact.jid)
if group not in self.user.groups: if not tag:
self.user.groups.append(group) if group not in contact.groups:
return contact.groups.append(group)
all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue continue
for _jid in all_jid[_account]: all_jid = gajim.contacts.get_metacontacts_jids(tag)
contacts = gajim.contacts.get_contact(_account, _jid) for _account in all_jid:
for contact in contacts: if not gajim.interface.roster.regroup and _account != account:
if not group in contact.groups: continue
contact.groups.append(group) for _jid in all_jid[_account]:
contacts = gajim.contacts.get_contact(_account, _jid)
for c in contacts:
if not group in c.groups:
c.groups.append(group)
def on_add_button_clicked(self, widget): def on_add_button_clicked(self, widget):
group = self.xml.get_widget('group_entry').get_text().decode('utf-8') group = self.xml.get_widget('group_entry').get_text().decode('utf-8')
@ -145,7 +156,11 @@ class EditGroupsDialog:
def group_toggled_cb(self, cell, path): def group_toggled_cb(self, cell, path):
self.changes_made = True self.changes_made = True
model = self.list.get_model() model = self.list.get_model()
model[path][1] = not model[path][1] if model[path][2]:
model[path][2] = False
model[path][1] = True
else:
model[path][1] = not model[path][1]
group = model[path][0].decode('utf-8') group = model[path][0].decode('utf-8')
if model[path][1]: if model[path][1]:
self.add_group(group) self.add_group(group)
@ -154,23 +169,39 @@ class EditGroupsDialog:
self.update_contact() self.update_contact()
def init_list(self): def init_list(self):
store = gtk.ListStore(str, bool) store = gtk.ListStore(str, bool, bool)
self.list.set_model(store) self.list.set_model(store)
for column in self.list.get_columns(): # Clear treeview when re-drawing for column in self.list.get_columns(): # Clear treeview when re-drawing
self.list.remove_column(column) self.list.remove_column(column)
groups = [] # Store accounts in a list so we can sort them accounts = []
for g in gajim.groups[self.account].keys(): # Store groups in a list so we can sort them and the number of contacts in
if g in helpers.special_groups: # it
continue groups = {}
in_group = False for (contact, account) in self.list_:
if g in self.user.groups: if account not in accounts:
in_group = True accounts.append(account)
groups.append([g, in_group]) for g in gajim.groups[account].keys():
groups.sort() if g in helpers.special_groups:
for group in groups: continue
if g in groups:
continue
groups[g] = 0
for g in contact.groups:
groups[g] += 1
group_list = groups.keys()
group_list.sort()
for group in group_list:
iter = store.append() iter = store.append()
store.set(iter, 0, group[0]) # Group name store.set(iter, 0, group) # Group name
store.set(iter, 1, group[1]) # In group boolean if groups[group] == 0:
store.set(iter, 1, False)
else:
store.set(iter, 1, True)
if groups[group] == len(self.list_):
# all contacts are in this group
store.set(iter, 2, False)
else:
store.set(iter, 2, True)
column = gtk.TreeViewColumn(_('Group')) column = gtk.TreeViewColumn(_('Group'))
column.set_expand(True) column.set_expand(True)
self.list.append_column(column) self.list.append_column(column)
@ -185,7 +216,7 @@ class EditGroupsDialog:
column.pack_start(renderer) column.pack_start(renderer)
renderer.set_property('activatable', True) renderer.set_property('activatable', True)
renderer.connect('toggled', self.group_toggled_cb) renderer.connect('toggled', self.group_toggled_cb)
column.set_attributes(renderer, active = 1) column.set_attributes(renderer, active = 1, inconsistent = 2)
class PassphraseDialog: class PassphraseDialog:
'''Class for Passphrase dialog''' '''Class for Passphrase dialog'''

View File

@ -1290,8 +1290,8 @@ class RosterWindow:
keys_str += jid + ' ' + keys[jid] + ' ' keys_str += jid + ' ' + keys[jid] + ' '
gajim.config.set_per('accounts', account, 'attached_gpg_keys', keys_str) gajim.config.set_per('accounts', account, 'attached_gpg_keys', keys_str)
def on_edit_groups(self, widget, contact, account): def on_edit_groups(self, widget, list_):
dlg = dialogs.EditGroupsDialog(contact, account) dlg = dialogs.EditGroupsDialog(list_)
dlg.run() dlg.run()
def on_history(self, widget, contact, account): def on_history(self, widget, contact, account):
@ -1444,8 +1444,8 @@ class RosterWindow:
assign_openpgp_key_menuitem.set_no_show_all(False) assign_openpgp_key_menuitem.set_no_show_all(False)
add_to_roster_menuitem.hide() add_to_roster_menuitem.hide()
add_to_roster_menuitem.set_no_show_all(True) add_to_roster_menuitem.set_no_show_all(True)
edit_groups_menuitem.connect('activate', self.on_edit_groups, contact, edit_groups_menuitem.connect('activate', self.on_edit_groups, [(
account) contact,account)])
if gajim.config.get('usegpg'): if gajim.config.get('usegpg'):
assign_openpgp_key_menuitem.connect('activate', assign_openpgp_key_menuitem.connect('activate',
@ -1592,6 +1592,10 @@ class RosterWindow:
invite_item.set_submenu(sub_menu) invite_item.set_submenu(sub_menu)
menu.append(invite_item) menu.append(invite_item)
edit_groups_item = gtk.MenuItem(_('Edit _Groups'))
menu.append(edit_groups_item)
edit_groups_item.connect('activate', self.on_edit_groups, list_)
# unsensitive if one account is not connected # unsensitive if one account is not connected
if one_account_offline: if one_account_offline:
remove_item.set_sensitive(False) remove_item.set_sensitive(False)