we can now remove sevral contacts in the same time. fpr #1514

This commit is contained in:
Yann Leboulanger 2006-07-24 09:39:38 +00:00
parent a90017399b
commit 00106e5b5f
1 changed files with 71 additions and 51 deletions

View File

@ -1378,7 +1378,7 @@ class RosterWindow:
self.on_send_single_message_menuitem_activate, account, contact) self.on_send_single_message_menuitem_activate, account, contact)
rename_menuitem.connect('activate', self.on_rename, iter, path) rename_menuitem.connect('activate', self.on_rename, iter, path)
remove_from_roster_menuitem.connect('activate', self.on_req_usub, remove_from_roster_menuitem.connect('activate', self.on_req_usub,
contact, account) [(contact, account)])
information_menuitem.connect('activate', self.on_info, contact, information_menuitem.connect('activate', self.on_info, contact,
account) account)
history_menuitem.connect('activate', self.on_history, contact, history_menuitem.connect('activate', self.on_history, contact,
@ -1459,9 +1459,13 @@ class RosterWindow:
def make_multiple_contact_menu(self, event, iters): def make_multiple_contact_menu(self, event, iters):
'''Make group's popup menu''' '''Make group's popup menu'''
model = self.tree.get_model() model = self.tree.get_model()
# path = model.get_path(iter) list_ = [] # list of (jid, account) tuples
# group = model[iter][C_JID].decode('utf-8') for iter in iters:
# account = model[iter][C_ACCOUNT].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
account = model[iter][C_ACCOUNT].decode('utf-8')
contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
list_.append((contact, account))
menu = gtk.Menu() menu = gtk.Menu()
@ -1469,9 +1473,9 @@ class RosterWindow:
icon = gtk.image_new_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU) icon = gtk.image_new_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU)
remove_item.set_image(icon) remove_item.set_image(icon)
menu.append(remove_item) menu.append(remove_item)
#TODO remove_item.connect('activate', self.on_req_usub, list_)
# remove_item.connect('activate', self.on_rename, iter, path)
#TODO
# # unsensitive if account is not connected # # unsensitive if account is not connected
# if gajim.connections[account].connected < 2: # if gajim.connections[account].connected < 2:
# rename_item.set_sensitive(False) # rename_item.set_sensitive(False)
@ -1781,7 +1785,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
contact = gajim.contacts.get_contact_with_highest_priority(account, contact = gajim.contacts.get_contact_with_highest_priority(account,
jid) jid)
if type == 'contact': if type == 'contact':
self.on_req_usub(widget, contact, account) self.on_req_usub(widget, [(contact, account)])
elif type == 'agent': elif type == 'agent':
self.on_remove_agent(widget, contact, account) self.on_remove_agent(widget, contact, account)
@ -1900,54 +1904,70 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
else: else:
self.tree.expand_row(path, False) self.tree.expand_row(path, False)
def on_req_usub(self, widget, contact, account): def on_req_usub(self, widget, list_):
'''Remove a contact''' '''Remove a contact. list_ is a list of (contact, account) tuples'''
def on_ok(widget, contact, account): def on_ok(widget, list_):
self.dialog.destroy() self.dialog.destroy()
remove_auth = True remove_auth = True
if contact.sub != 'to' and self.dialog.is_checked(): if len(list_) == 1:
remove_auth = False contact = list_[0][0]
gajim.connections[account].unsubscribe(contact.jid, remove_auth) if contact.sub != 'to' and self.dialog.is_checked():
for c in gajim.contacts.get_contact(account, contact.jid): remove_auth = False
self.remove_contact(c, account) for (contact, account) in list_:
gajim.contacts.remove_jid(account, c.jid) gajim.connections[account].unsubscribe(contact.jid, remove_auth)
need_readd = False for c in gajim.contacts.get_contact(account, contact.jid):
if not remove_auth and contact.sub == 'both': self.remove_contact(c, account)
contact.name = '' gajim.contacts.remove_jid(account, c.jid)
contact.groups = [] need_readd = False
contact.sub = 'from' if not remove_auth and contact.sub == 'both':
gajim.contacts.add_contact(account, contact) contact.name = ''
self.add_contact_to_roster(contact.jid, account) contact.groups = []
elif gajim.awaiting_events[account].has_key(contact.jid): contact.sub = 'from'
need_readd = True gajim.contacts.add_contact(account, contact)
elif gajim.interface.msg_win_mgr.has_window(contact.jid, account): self.add_contact_to_roster(contact.jid, account)
if _('Not in Roster') in contact.groups: elif gajim.awaiting_events[account].has_key(contact.jid):
# Close chat window
msg_win = gajim.interface.msg_win_mgr.get_window(contact.jid,
account)
ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid,
account)
msg_win.remove_tab(ctrl)
else:
need_readd = True need_readd = True
if need_readd: elif gajim.interface.msg_win_mgr.has_window(contact.jid, account):
c = gajim.contacts.create_contact(jid = contact.jid, if _('Not in Roster') in contact.groups:
name = '', groups = [_('Not in Roster')], # Close chat window
show = 'not in roster', status = '', ask = 'none', msg_win = gajim.interface.msg_win_mgr.get_window(contact.jid,
keyID = contact.keyID) account)
gajim.contacts.add_contact(account, c) ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid,
self.add_contact_to_roster(contact.jid, account) account)
pritext = _('Contact "%s" will be removed from your roster') % \ msg_win.remove_tab(ctrl)
contact.get_shown_name() else:
if contact.sub == 'to': need_readd = True
self.dialog = dialogs.ConfirmationDialog(pritext, if need_readd:
_('By removing this contact you also remove authorization resulting in him or her always seeing you as offline.'), c = gajim.contacts.create_contact(jid = contact.jid,
on_response_ok = (on_ok, contact, account)) name = '', groups = [_('Not in Roster')],
show = 'not in roster', status = '', ask = 'none',
keyID = contact.keyID)
gajim.contacts.add_contact(account, c)
self.add_contact_to_roster(contact.jid, account)
if len(list_) == 1:
contact = list_[0][0]
account = list_[0][1]
pritext = _('Contact "%s" will be removed from your roster') % \
contact.get_shown_name()
if contact.sub == 'to':
self.dialog = dialogs.ConfirmationDialog(pritext,
_('By removing this contact you also remove authorization resulting in him or her always seeing you as offline.'),
on_response_ok = (on_ok, list_))
else:
self.dialog = dialogs.ConfirmationDialogCheck(pritext,
_('By removing this contact you also by default remove authorization resulting in him or her always seeing you as offline.'),
_('I want this contact to know my status after removal'),
on_response_ok = (on_ok, list_))
else: else:
self.dialog = dialogs.ConfirmationDialogCheck(pritext, # several contact to remove at the same time
_('By removing this contact you also by default remove authorization resulting in him or her always seeing you as offline.'), pritext = _('Contacts will be removed from your roster')
_('I want this contact to know my status after removal'), jids = ''
on_response_ok = (on_ok, contact, account)) for (contact, account) in list_:
jids += '\n ' + contact.get_shown_name() + ','
sectext = _('By removing these contacts:%s\nyou also remove authorization resulting in them always seeing you as offline.') % jids
self.dialog = dialogs.ConfirmationDialog(pritext, sectext,
on_response_ok = (on_ok, list_))
def forget_gpg_passphrase(self, keyid): def forget_gpg_passphrase(self, keyid):
if self.gpg_passphrase.has_key(keyid): if self.gpg_passphrase.has_key(keyid):