diff --git a/data/glade/advanced_menuitem_menu.glade b/data/glade/advanced_menuitem_menu.glade index c15a28ce3..b331dbb3e 100644 --- a/data/glade/advanced_menuitem_menu.glade +++ b/data/glade/advanced_menuitem_menu.glade @@ -11,7 +11,7 @@ True - + True gtk-new 1 @@ -32,11 +32,23 @@ - + True _Blocked Contacts True + + + + True + gtk-stop + 1 + 0.5 + 0.5 + 0 + 0 + + @@ -67,7 +79,7 @@ True - + True gtk-new 1 @@ -109,7 +121,7 @@ True - + True gtk-clear 1 diff --git a/data/glade/blocked_contacts_window.glade b/data/glade/blocked_contacts_window.glade index 9c22f40bc..9b2e870b0 100644 --- a/data/glade/blocked_contacts_window.glade +++ b/data/glade/blocked_contacts_window.glade @@ -50,6 +50,7 @@ False False False + @@ -65,11 +66,73 @@ 3 True True - gtk-remove - True GTK_RELIEF_NORMAL True + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-remove + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Unblock + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + 0 diff --git a/data/glade/roster_contact_context_menu.glade b/data/glade/roster_contact_context_menu.glade index 68af27275..4d2bd8030 100644 --- a/data/glade/roster_contact_context_menu.glade +++ b/data/glade/roster_contact_context_menu.glade @@ -12,7 +12,7 @@ True - + True gtk-jump-to 1 @@ -32,7 +32,7 @@ True - + True gtk-go-up 1 @@ -52,7 +52,7 @@ True - + True gtk-new 1 @@ -72,7 +72,7 @@ True - + True gtk-go-back 1 @@ -91,7 +91,7 @@ True - + True gtk-refresh 1 @@ -111,48 +111,6 @@ - - - True - _Block - True - - - - - True - gtk-stop - 1 - 0.5 - 0.5 - 0 - 0 - - - - - - - - True - _Unblock - True - - - - - True - gtk-stop - 1 - 0.5 - 0.5 - 0 - 0 - - - - - True @@ -166,7 +124,7 @@ True - + True gtk-file 1 @@ -186,7 +144,7 @@ - + True gtk-dialog-authentication 1 @@ -206,7 +164,7 @@ True - + True gtk-info 1 @@ -226,7 +184,7 @@ True - + True gtk-execute 1 @@ -251,7 +209,7 @@ True - + True gtk-dialog-question 1 @@ -272,7 +230,7 @@ True - + True gtk-go-up 1 @@ -292,7 +250,7 @@ True - + True gtk-go-down 1 @@ -312,7 +270,7 @@ True - + True gtk-stop 1 @@ -329,13 +287,55 @@ + + + True + _Block + True + + + + + True + gtk-no + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + _Unblock + True + + + + + True + gtk-yes + 1 + 0.5 + 0.5 + 0 + 0 + + + + + _Add to Roster True - + True gtk-add 1 @@ -354,7 +354,7 @@ True - + True gtk-remove 1 @@ -386,7 +386,7 @@ True - + True gtk-justify-fill 1 diff --git a/src/dialogs.py b/src/dialogs.py index 6a3388450..a322f8375 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -56,7 +56,7 @@ class EditGroupsDialog: if len(list_) == 1: contact = list_[0][0] self.xml.get_widget('nickname_label').set_markup( - _("Contact name: %s") % contact.get_shown_name()) + _('Contact name: %s') % contact.get_shown_name()) self.xml.get_widget('jid_label').set_markup( _('Jabber ID: %s') % contact.jid) else: @@ -2308,12 +2308,11 @@ class BlockedContactsWindow: self.remove_button = self.xml.get_widget('remove_button') self.contacts_treeview = self.xml.get_widget('contacts_treeview') renderer = gtk.CellRendererText() - self.store = gtk.ListStore(str) self.contacts_treeview.set_model(self.store) - column = gtk.TreeViewColumn("Contact", renderer, text=0) + column = gtk.TreeViewColumn('Contact', renderer, text=0) self.contacts_treeview.append_column(column) if len(gajim.connections) > 1: @@ -2321,7 +2320,6 @@ class BlockedContactsWindow: else: title = _('Blocked Contacts') self.window.set_title(title) - self.window.show_all() self.xml.signal_autoconnect(self) gajim.connections[self.account].get_privacy_list('block') @@ -2332,38 +2330,53 @@ class BlockedContactsWindow: del gajim.interface.instances[self.account][key_name] def on_remove_button_clicked(self, widget): - tags=[] + if self.contacts_treeview.get_selection().get_selected()[1] == None: + return + tags = [] rule_selected = self.store.get_path( self.contacts_treeview.get_selection().get_selected()[1])[0] for i in range(0,len(self.global_rules)): if i != rule_selected: tags.append(self.global_rules[i]) + else: + deleted_rule = self.global_rules[i] for rule in self.global_rules_to_append: tags.append(rule) gajim.connections[self.account].set_privacy_list( 'block', tags) - gajim.connections[self.account].set_active_list('block') - gajim.connections[self.account].set_default_list('block') gajim.connections[self.account].get_privacy_list('block') if len(tags) == 0: self.privacy_list_received([]) gajim.connections[self.account].blocked_contacts = [] + gajim.connections[self.account].blocked_groups = [] gajim.connections[self.account].blocked_list = [] gajim.connections[self.account].set_default_list('') gajim.connections[self.account].set_active_list('') gajim.connections[self.account].del_privacy_list('block') - + status = gajim.connections[self.account].connected + msg = gajim.connections[self.account].status + show = gajim.SHOW_LIST[gajim.connections[self.account].connected] + if deleted_rule['type'] == 'jid': + gajim.connections[self.account].send_custom_status(show, msg, + deleted_rule['value']) + else: + for jid in gajim.contacts.get_jid_list(self.account): + contact = gajim.contacts.get_contact_with_highest_priority( + self.account, jid) + if deleted_rule['value'] in contact.groups: + gajim.connections[self.account].send_custom_status(show, msg, + contact.jid) def privacy_list_received(self, rules): self.store.clear() self.global_rules = [] self.global_rules_to_append = [] for rule in rules: - if rule['type'] == "jid" and rule['action'] == "deny": + if rule['type'] == 'jid' and rule['action'] == 'deny': #self.global_rules[text_item] = rule self.store.append([rule['value']]) self.global_rules.append(rule) - elif rule['type'] == "group" and rule['action'] == "deny": + elif rule['type'] == 'group' and rule['action'] == 'deny': text_item = _('Group %s') % rule['value'] self.store.append([text_item]) self.global_rules.append(rule) diff --git a/src/roster_window.py b/src/roster_window.py index ac7c0d38e..66f58c9df 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1425,6 +1425,7 @@ class RosterWindow: on_response_ok = (remove, list_)) def on_block(self, widget, iter, blockedlist): + ''' When clicked on the 'block' button in context menu. ''' model = self.tree.get_model() accounts = [] if blockedlist == None: @@ -1435,50 +1436,86 @@ class RosterWindow: self.send_status(account, 'offline', msg, to = jid) new_rule = {'order': u'1', 'type': u'jid', 'action': u'deny', 'value' : jid, 'child': [u'message', u'iq', u'presence-out']} - else: - model = self.tree.get_model() - group = model[iter][C_JID].decode('utf-8') - msg = self.get_status_message('offline') - for (contact, account) in blockedlist: - if account not in accounts: - if gajim.connections[account].privacy_rules_supported: - accounts.append(account) - self.send_status(account, 'offline', msg, to = contact.jid) - else: - self.send_status(account, 'offline', msg, to = contact.jid) - new_rule = {'order': u'1', 'type': u'group', 'action': u'deny', - 'value' : group, 'child': [u'message', u'iq', u'presence-out']} - for account in accounts: gajim.connections[account].blocked_list.append(new_rule) - gajim.connections[account].set_privacy_list( + else: + msg = self.get_status_message('offline') + if iter == None: + for (contact, account) in blockedlist: + if account not in accounts: + if gajim.connections[account].privacy_rules_supported: + accounts.append(account) + self.send_status(account, 'offline', msg, to = contact.jid) + new_rule = {'order': u'1', 'type': u'jid', + 'action': u'deny', 'value' : contact.jid, + 'child': [u'message', u'iq', u'presence-out']} + gajim.connections[account].blocked_list.append(new_rule) + else: + self.send_status(account, 'offline', msg, to = contact.jid) + new_rule = {'order': u'1', 'type': u'jid', + 'action': u'deny', 'value' : contact.jid, + 'child': [u'message', u'iq', u'presence-out']} + gajim.connections[account].blocked_list.append(new_rule) + else: + group = model[iter][C_JID].decode('utf-8') + msg = self.get_status_message('offline') + for (contact, account) in blockedlist: + if account not in accounts: + if gajim.connections[account].privacy_rules_supported: + accounts.append(account) + self.send_status(account, 'offline', msg, to = contact.jid) + else: + self.send_status(account, 'offline', msg, to = contact.jid) + new_rule = {'order': u'1', 'type': u'group', 'action': u'deny', + 'value' : group, 'child': [u'message', u'iq', u'presence-out']} + gajim.connections[account].blocked_list.append(new_rule) + for account in accounts: + gajim.connections[account].set_privacy_list( 'block', gajim.connections[account].blocked_list) if len(gajim.connections[account].blocked_list) == 1: gajim.connections[account].set_active_list('block') gajim.connections[account].set_default_list('block') gajim.connections[account].get_privacy_list('block') - def on_unblock(self, widget, iter, blockedlist): + def on_unblock(self, widget, iter, group_list): + ''' When clicked on the 'unblock' button in context menu. ''' model = self.tree.get_model() accounts = [] - if blockedlist == None: + if group_list == None: jid = model[iter][C_JID].decode('utf-8') jid_account = model[iter][C_ACCOUNT].decode('utf-8') accounts.append(jid_account) gajim.connections[jid_account].new_blocked_list = [] for rule in gajim.connections[jid_account].blocked_list: - if rule['action'] != 'deny' or rule['type'] != 'jid' or rule['value'] != jid: + if rule['action'] != 'deny' or rule['type'] != 'jid' \ + or rule['value'] != jid: gajim.connections[jid_account].new_blocked_list.append(rule) else: - model = self.tree.get_model() - group = model[iter][C_JID].decode('utf-8') - for (contact, account) in blockedlist: - if account not in accounts: - if gajim.connections[account].privacy_rules_supported: - accounts.append(account) - gajim.connections[account].new_blocked_list = [] - for rule in gajim.connections[account].blocked_list: - if rule['action'] != 'deny' or rule['type'] != 'group' or rule['value'] != group: - gajim.connections[account].new_blocked_list.append(rule) + if iter == None: + for (contact, account) in group_list: + if account not in accounts: + if gajim.connections[account].privacy_rules_supported: + accounts.append(account) + gajim.connections[account].new_blocked_list = [] + gajim.connections[account].to_unblock = [] + gajim.connections[account].to_unblock.append(contact.jid) + else: + gajim.connections[account].to_unblock.append(contact.jid) + for account in accounts: + for rule in gajim.connections[account].blocked_list: + if rule['action'] != 'deny' or rule['type'] != 'jid' \ + or rule['value'] not in gajim.connections[account].to_unblock: + gajim.connections[account].new_blocked_list.append(rule) + else: + group = model[iter][C_JID].decode('utf-8') + for (contact, account) in group_list: + if account not in accounts: + if gajim.connections[account].privacy_rules_supported: + accounts.append(account) + gajim.connections[account].new_blocked_list = [] + for rule in gajim.connections[account].blocked_list: + if rule['action'] != 'deny' or rule['type'] != 'group' \ + or rule['value'] != group: + gajim.connections[account].new_blocked_list.append(rule) for account in accounts: gajim.connections[account].set_privacy_list( 'block', gajim.connections[account].new_blocked_list) @@ -1490,7 +1527,10 @@ class RosterWindow: gajim.connections[account].set_default_list('') gajim.connections[account].set_active_list('') gajim.connections[account].del_privacy_list('block') - if blockedlist == None: + if gajim.interface.instances[account].has_key('blocked_contacts'): + gajim.interface.instances[account]['blocked_contacts'].\ + privacy_list_received([]) + if group_list == None: status = gajim.connections[jid_account].connected msg = gajim.connections[jid_account].status if not self.regroup: @@ -1499,7 +1539,7 @@ class RosterWindow: show = helpers.get_global_show() self.send_status(jid_account, show, msg, to = jid) else: - for (contact, account) in blockedlist: + for (contact, account) in group_list: if not self.regroup: show = gajim.SHOW_LIST[gajim.connections[account].connected] else: # accounts merged @@ -2146,6 +2186,7 @@ class RosterWindow: connected_accounts = [] contacts_transport = -1 # -1 is at start, False when not from the same, None when jabber + is_blocked = True for iter in iters: jid = model[iter][C_JID].decode('utf-8') account = model[iter][C_ACCOUNT].decode('utf-8') @@ -2160,6 +2201,8 @@ class RosterWindow: contacts_transport = transport if contacts_transport != transport: contacts_transport = False + if jid not in gajim.connections[account].blocked_contacts: + is_blocked = False list_.append((contact, account)) menu = gtk.Menu() @@ -2229,6 +2272,18 @@ class RosterWindow: send_group_message_item.connect('activate', self.on_send_single_message_menuitem_activate, account, list_) + if is_blocked: + unblock_menuitem = gtk.ImageMenuItem(_('_Unblock')) + icon = gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) + unblock_menuitem.set_image(icon) + unblock_menuitem.connect('activate', self.on_unblock, None, list_) + menu.append(unblock_menuitem) + else: + block_menuitem = gtk.ImageMenuItem(_('_Block')) + icon = gtk.image_new_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU) + block_menuitem.set_image(icon) + block_menuitem.connect('activate', self.on_block, None, list_) + menu.append(block_menuitem) # unsensitive if one account is not connected if one_account_offline: remove_item.set_sensitive(False) @@ -2330,13 +2385,13 @@ class RosterWindow: if group not in helpers.special_groups + (_('General'),): if is_blocked: unblock_menuitem = gtk.ImageMenuItem(_('_Unblock')) - icon = gtk.image_new_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_MENU) + icon = gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) unblock_menuitem.set_image(icon) unblock_menuitem.connect('activate', self.on_unblock, iter, list_) menu.append(unblock_menuitem) else: block_menuitem = gtk.ImageMenuItem(_('_Block')) - icon = gtk.image_new_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_MENU) + icon = gtk.image_new_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU) block_menuitem.set_image(icon) block_menuitem.connect('activate', self.on_block, iter, list_) menu.append(block_menuitem)