From ac7bc2a229767a132000e2f500856091fcfb422d Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 13 Nov 2006 08:27:16 +0000 Subject: [PATCH] [Brice Maron] ability to remove a group (and eventually contacts in this group too). fixes #485 --- src/common/contacts.py | 9 +++++++++ src/roster_window.py | 31 +++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/common/contacts.py b/src/common/contacts.py index 7010ed222..1153f591c 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -242,6 +242,15 @@ class Contacts: return self._contacts[account][jid][0] return None + def get_contacts_from_group(self, account, group): + '''Returns all contacts in the given group''' + group_contacts = [] + for jid in self._contacts[account]: + contacts = self.get_contacts_from_jid(account, jid) + if group in contacts[0].groups: + group_contacts += contacts + return group_contacts + def define_metacontacts(self, account, tags_list): self._metacontacts_tags[account] = tags_list diff --git a/src/roster_window.py b/src/roster_window.py index ce56a3558..744ac446c 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1391,6 +1391,22 @@ class RosterWindow: model[iter][C_EDITABLE] = True # set 'editable' to True self.tree.set_cursor(path, self.tree.get_column(0), True) + def on_remove_group_item_activated(self, widget, group, account): + dlg = dialogs.ConfirmationDialogCheck(_('Remove Group'), + _('Do you want to remove the group %s from the roster ?' % group), + _('Remove also all contacts in this group from your roster')) + dlg.set_default_response(gtk.BUTTONS_OK_CANCEL) + response = dlg.run() + if response == gtk.RESPONSE_OK: + for contact in gajim.contacts.get_contacts_from_group(account, group): + if not dlg.is_checked(): + self.remove_contact_from_group(account, contact, group) + gajim.connections[account].update_contact(contact.jid, + contact.name, contact.groups) + self.add_contact_to_roster(contact.jid, account) + else: + gajim.connections[account].unsubscribe(contact.jid) + def on_assign_pgp_key(self, widget, contact, account): attached_keys = gajim.config.get_per('accounts', account, 'attached_gpg_keys').split() @@ -1916,18 +1932,26 @@ class RosterWindow: menu.append(rename_item) rename_item.connect('activate', self.on_rename, iter, path) + # Remove group + remove_item = gtk.ImageMenuItem(_('_Remove from Roster')) + icon = gtk.image_new_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU) + remove_item.set_image(icon) + menu.append(remove_item) + remove_item.connect('activate', self.on_remove_group_item_activated, + group, account) + # unsensitive if account is not connected if gajim.connections[account].connected < 2: rename_item.set_sensitive(False) send_group_message_item = gtk.MenuItem(_('Send Group M_essage')) - + send_group_message_submenu = gtk.Menu() send_group_message_item.set_submenu(send_group_message_submenu) menu.append(send_group_message_item) - + group_message_to_all_item = gtk.MenuItem(_('To all users')) send_group_message_submenu.append(group_message_to_all_item) - + group_message_to_all_online_item = gtk.MenuItem(_('To all online users')) send_group_message_submenu.append(group_message_to_all_online_item) list_ = [] # list of (jid, account) tuples @@ -1947,7 +1971,6 @@ class RosterWindow: group_message_to_all_item.connect('activate', self.on_send_single_message_menuitem_activate, account, list_) - event_button = gtkgui_helpers.get_possible_button_event(event) menu.attach_to_widget(self.tree, None)