* YesNo dialog now destroy itself when we click on a button

* yes YesNo dialog when a contact removes us to as if user wants to remove it too
 * fix some coding standards
This commit is contained in:
Yann Leboulanger 2008-01-22 16:06:16 +00:00
parent 335079dd9b
commit d27f9a9c85
2 changed files with 84 additions and 55 deletions

View File

@ -256,7 +256,7 @@ class PassphraseDialog:
self.window.destroy() self.window.destroy()
return passphrase, checked return passphrase, checked
def __init__(self, titletext, labeltext, checkbuttontext=None, is_modal = True, def __init__(self, titletext, labeltext, checkbuttontext=None, is_modal=True,
ok_handler = None, cancel_handler = None): ok_handler = None, cancel_handler = None):
self.xml = gtkgui_helpers.get_glade('passphrase_dialog.glade') self.xml = gtkgui_helpers.get_glade('passphrase_dialog.glade')
self.window = self.xml.get_widget('passphrase_dialog') self.window = self.xml.get_widget('passphrase_dialog')
@ -1223,12 +1223,32 @@ class YesNoDialog(HigDialog):
def __init__(self, pritext, sectext='', on_response_yes = None, def __init__(self, pritext, sectext='', on_response_yes = None,
on_response_no = None): on_response_no = None):
'''HIG compliant YesNo dialog.''' '''HIG compliant YesNo dialog.'''
self.user_response_yes = on_response_yes
self.user_response_no = on_response_no
HigDialog.__init__( self, None, HigDialog.__init__( self, None,
gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, pritext, sectext, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, pritext, sectext,
on_response_yes = on_response_yes, on_response_no = on_response_no) on_response_yes=self.on_response_yes,
on_response_no=self.on_response_no)
self.set_modal(False) self.set_modal(False)
self.popup() self.popup()
def on_response_yes(self, widget):
if self.user_response_yes:
if isinstance(self.user_response_yes, tuple):
self.user_response_yes[0](*self.user_response_yes[1:])
else:
self.user_response_yes(self.is_checked())
self.destroy()
def on_response_no(self, widget):
if self.user_response_no:
if isinstance(self.user_response_no, tuple):
self.user_response_no[0](*self.user_response_no[1:])
else:
self.user_response_no()
self.destroy()
class ConfirmationDialogCheck(ConfirmationDialog): class ConfirmationDialogCheck(ConfirmationDialog):
'''HIG compliant confirmation dialog with checkbutton.''' '''HIG compliant confirmation dialog with checkbutton.'''
def __init__(self, pritext, sectext='', checktext = '', def __init__(self, pritext, sectext='', checktext = '',
@ -1264,7 +1284,7 @@ class ConfirmationDialogCheck(ConfirmationDialog):
def on_response_cancel(self, widget): def on_response_cancel(self, widget):
if self.user_response_cancel: if self.user_response_cancel:
if isinstance(self.user_response_cancel, tuple): if isinstance(self.user_response_cancel, tuple):
self.user_response_cancel[0](*self.user_response_ok[1:]) self.user_response_cancel[0](*self.user_response_cancel[1:])
else: else:
self.user_response_cancel() self.user_response_cancel()
self.destroy() self.destroy()

View File

@ -455,7 +455,7 @@ class Interface:
def handle_event_http_auth(self, account, data): def handle_event_http_auth(self, account, data):
#('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg)) #('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg))
def response(widget, account, iq_obj, answer): def response(account, iq_obj, answer):
self.dialog.destroy() self.dialog.destroy()
gajim.connections[account].build_http_auth_answer(iq_obj, answer) gajim.connections[account].build_http_auth_answer(iq_obj, answer)
@ -948,13 +948,22 @@ class Interface:
self.remote_ctrl.raise_signal('Subscribed', (account, array)) self.remote_ctrl.raise_signal('Subscribed', (account, array))
def handle_event_unsubscribed(self, account, jid): def handle_event_unsubscribed(self, account, jid):
dialogs.InformationDialog(_('Contact "%s" removed subscription from you')\
% jid, _('You will always see him or her as offline.'))
# FIXME: Per RFC 3921, we can "deny" ack as well, but the GUI does not show deny
gajim.connections[account].ack_unsubscribed(jid) gajim.connections[account].ack_unsubscribed(jid)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal('Unsubscribed', (account, jid)) self.remote_ctrl.raise_signal('Unsubscribed', (account, jid))
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if not contact:
return
def on_yes(list_):
self.roster.on_req_usub(None, list_)
list_ = [(contact, account)]
dialogs.YesNoDialog(
_('Contact "%s" removed subscription from you') % jid,
_('You will always see him or her as offline.\nDo you want to remove him or her from your contact list?'),
on_response_yes = (on_yes, list_))
# FIXME: Per RFC 3921, we can "deny" ack as well, but the GUI does not show deny
def handle_event_agent_info_error(self, account, agent): def handle_event_agent_info_error(self, account, agent):
#('AGENT_ERROR_INFO', account, (agent)) #('AGENT_ERROR_INFO', account, (agent))
try: try:
@ -1932,12 +1941,12 @@ class Interface:
negotiated, not_acceptable, ask_user = session.verify_options_bob(form) negotiated, not_acceptable, ask_user = session.verify_options_bob(form)
if ask_user: if ask_user:
def accept_nondefault_options(widget): def accept_nondefault_options():
self.dialog.destroy() self.dialog.destroy()
negotiated.update(ask_user) negotiated.update(ask_user)
session.respond_e2e_bob(form, negotiated, not_acceptable) session.respond_e2e_bob(form, negotiated, not_acceptable)
def reject_nondefault_options(widget): def reject_nondefault_options():
self.dialog.destroy() self.dialog.destroy()
for key in ask_user.keys(): for key in ask_user.keys():
not_acceptable.append(key) not_acceptable.append(key)
@ -1973,7 +1982,7 @@ class Interface:
session.check_identity = _cb session.check_identity = _cb
if ask_user: if ask_user:
def accept_nondefault_options(widget): def accept_nondefault_options():
dialog.destroy() dialog.destroy()
negotiated.update(ask_user) negotiated.update(ask_user)
@ -1983,7 +1992,7 @@ class Interface:
except exceptions.NegotiationError, details: except exceptions.NegotiationError, details:
session.fail_bad_negotiation(details) session.fail_bad_negotiation(details)
def reject_nondefault_options(widget): def reject_nondefault_options():
session.reject_negotiation() session.reject_negotiation()
dialog.destroy() dialog.destroy()
@ -2237,7 +2246,7 @@ class Interface:
gajim.config.set_per('accounts', account, 'ssl_fingerprint_sha1', gajim.config.set_per('accounts', account, 'ssl_fingerprint_sha1',
data[0]) data[0])
gajim.connections[account].ssl_certificate_accepted() gajim.connections[account].ssl_certificate_accepted()
def on_no(widget): def on_no():
dialog.destroy() dialog.destroy()
gajim.connections[account].disconnect(on_purpose=True) gajim.connections[account].disconnect(on_purpose=True)
self.handle_event_status(account, 'offline') self.handle_event_status(account, 'offline')