diff --git a/src/chat_control.py b/src/chat_control.py index ce9583e7b3ec45f7a4ba1ffd9c4ceceda11b4c3c..b31ec65fb1385ea86887589c0cd13531861bd162 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -2200,18 +2200,24 @@ class ChatControl(ChatControlBase): self.conv_textview.del_handlers() self.msg_textview.destroy() - def allow_shutdown(self, method): + def allow_shutdown(self, method, on_yes, on_no, on_minimize): if time.time() - gajim.last_message_time[self.account]\ [self.get_full_jid()] < 2: # 2 seconds + def on_ok(): + on_yes(self) + + def on_cancel(): + on_no(self) + dialog = dialogs.ConfirmationDialog( # %s is being replaced in the code with JID _('You just received a new message from "%s"') % self.contact.jid, _('If you close this tab and you have history disabled, '\ - 'this message will be lost.')) - if dialog.get_response() != gtk.RESPONSE_OK: - return 'no' # stop the propagation of the event - return 'yes' + 'this message will be lost.'), on_response_ok=on_ok, + on_response_cancel=on_cancel) + return + on_yes(self) def handle_incoming_chatstate(self): ''' handle incoming chatstate that jid SENT TO us ''' diff --git a/src/dialogs.py b/src/dialogs.py index 43e7a97b011fc6564ac536f49a407492983e1a0f..a140e4a7b9aa187d7f9cdc9a1b1972835565b8e1 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1362,9 +1362,10 @@ class ConfirmationDialogCheck(ConfirmationDialog): def on_response_cancel(self, widget): if self.user_response_cancel: if isinstance(self.user_response_cancel, tuple): - self.user_response_cancel[0](*self.user_response_cancel[1:]) + self.user_response_cancel[0](self.is_checked(), + *self.user_response_cancel[1:]) else: - self.user_response_cancel() + self.user_response_cancel(self.is_checked()) self.destroy() def is_checked(self): diff --git a/src/groupchat_control.py b/src/groupchat_control.py index cf5b79fdc969f7d9aadcf8abb55ab24811305384..3f4628a55b70bec6c807df8c6af1d646cd6d375b 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -1667,37 +1667,47 @@ class GroupchatControl(ChatControlBase): # Remove unread events from systray gajim.events.remove_events(self.account, self.room_jid) - def allow_shutdown(self, method): + def allow_shutdown(self, method, on_yes, on_no, on_minimize): if self.contact.jid in gajim.config.get_per('accounts', self.account, 'minimized_gc').split(' '): - return 'minimize' + on_minimize(self) + return if method == self.parent_win.CLOSE_ESC: model, iter = self.list_treeview.get_selection().get_selected() if iter: self.list_treeview.get_selection().unselect_all() - return 'no' - retval = 'yes' + on_no(self) + return includes = gajim.config.get('confirm_close_muc_rooms').split(' ') excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ') # whether to ask for comfirmation before closing muc if (gajim.config.get('confirm_close_muc') or self.room_jid in includes) \ and gajim.gc_connected[self.account][self.room_jid] and self.room_jid not\ in excludes: + + def on_ok(clicked): + if clicked: + # user does not want to be asked again + gajim.config.set('confirm_close_muc', False) + on_yes(self) + + def on_cancel(clicked): + if clicked: + # user does not want to be asked again + gajim.config.set('confirm_close_muc', False) + on_no(self) + pritext = _('Are you sure you want to leave group chat "%s"?')\ % self.name sectext = _('If you close this window, you will be disconnected ' 'from this group chat.') dialog = dialogs.ConfirmationDialogCheck(pritext, sectext, - _('Do _not ask me again')) - - if dialog.get_response() != gtk.RESPONSE_OK: - retval = 'no' - - if dialog.is_checked(): # user does not want to be asked again - gajim.config.set('confirm_close_muc', False) + _('Do _not ask me again'), on_response_ok=on_ok, + on_response_cancel=on_cancel) + return - return retval + on_yes(self) def set_control_active(self, state): self.conv_textview.allow_focus_out_line = True diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 36f0899f3653a3d7680341cf53a02137ec092159..a0a2e2d175e7d028e9f36d4d50e5167868726a2c 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -730,9 +730,8 @@ Description=xmpp sectext = _('Would you like to make Gajim the default Jabber client?') checktext = _('Always check to see if Gajim is the default Jabber client ' 'on startup') - def on_cancel(): - gajim.config.set('check_if_gajim_is_default', - dlg.is_checked()) + def on_cancel(checked): + gajim.config.set('check_if_gajim_is_default', checked) dlg = dialogs.ConfirmationDialogCheck(pritext, sectext, checktext, set_gajim_as_xmpp_handler, on_cancel) if gajim.config.get('check_if_gajim_is_default'): diff --git a/src/message_control.py b/src/message_control.py index ed48828aeb2f3d76da57a99b0c90b740568e7721..d8ddacf1c5d8d092ec95db9eb0254afe6d98e7be 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -62,12 +62,14 @@ class MessageControl: or inactive (state is False)''' pass # Derived classes MUST implement this method - def allow_shutdown(self, method): + def allow_shutdown(self, method, on_response_yes, on_response_no, + on_response_minimize): '''Called to check is a control is allowed to shutdown. If a control is not in a suitable shutdown state this method - should return 'no', else 'yes' or 'minimize' ''' + should call on_response_no, else on_response_yes or + on_response_minimize ''' # NOTE: Derived classes MAY implement this - return 'yes' + on_response_yes(self) def shutdown(self): # NOTE: Derived classes MUST implement this diff --git a/src/message_window.py b/src/message_window.py index e7745042a3bdb32f18c78b031a2c7b555b69e955..50fbdc3211a8a002a81eab90eea025d8c19a13fb 100644 --- a/src/message_window.py +++ b/src/message_window.py @@ -65,6 +65,8 @@ class MessageWindow(object): # dict { handler id: widget}. Keeps callbacks, which # lead to cylcular references self.handlers = {} + # Don't show warning dialogs when we want to delete the window + self.dont_warn_on_delete = False self.widget_name = 'message_window' self.xml = gtkgui_helpers.get_glade('%s.glade' % self.widget_name) @@ -182,18 +184,30 @@ class MessageWindow(object): self.redraw_tab(ctrl) def _on_window_delete(self, win, event): + if self.dont_warn_on_delete: + # Destroy the window + return False + + def on_yes(ctrl): + if self.on_delete_ok == 1: + self.dont_warn_on_delete = True + win.destroy() + self.on_delete_ok -= 1 + + def on_no(ctrl): + return + + def on_minimize(ctrl): + self.on_delete_ok -= 1 + ctrl.minimize() + # Make sure all controls are okay with being deleted ctrl_to_minimize = [] + self.on_delete_ok = self.get_nb_controls() for ctrl in self.controls(): - allow_shutdown = ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON) - if allow_shutdown == 'no': - return True # halt the delete - elif allow_shutdown == 'minimize': - ctrl_to_minimize.append(ctrl) - # If all are ok, minimize the one that need to be minimized - for ctrl in ctrl_to_minimize: - ctrl.minimize() - return False + ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON, on_yes, on_no, + on_minimize) + return True # halt the delete for the moment def _on_window_destroy(self, win): for ctrl in self.controls(): @@ -607,6 +621,13 @@ class MessageWindow(object): for ctrl in jid_dict.values(): yield ctrl + def get_nb_controls(self): + nb_ctrl = 0 + for jid_dict in self._controls.values(): + for ctrl in jid_dict.values(): + nb_ctrl += 1 + return nb_ctrl + def move_to_next_unread_tab(self, forward): ind = self.notebook.get_current_page() current = ind diff --git a/src/roster_window.py b/src/roster_window.py index 72f41d3fe2dd06ee69eff8c3453d43c1209899f5..24d6597e0f8b5e9207e769eaeb287da8afce1575 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -3795,7 +3795,7 @@ class RosterWindow: 'line. Generally it is used when the same person has several Jabber ' 'accounts or transport accounts.') dlg = dialogs.ConfirmationDialogCheck(pritext, sectext, - _('Do _not ask me again'), on_response_ok = merge_contacts) + _('Do _not ask me again'), on_response_ok=merge_contacts) if not confirm_metacontacts: # First time we see this window dlg.checkbutton.set_active(True)