From 0c27b86cc1eb483f7eb36842d8e03eb66f736321 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 8 Apr 2009 16:28:51 +0000 Subject: [PATCH] Warn user before closing chat window with tabs where we can loose data. Fixes #3645 --- src/chat_control.py | 3 +++ src/groupchat_control.py | 13 +++++++++++++ src/message_control.py | 6 ++++++ src/message_window.py | 24 ++++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/src/chat_control.py b/src/chat_control.py index de4b8382b..0737143b1 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -2327,6 +2327,9 @@ class ChatControl(ChatControlBase): self.conv_textview.del_handlers() self.msg_textview.destroy() + def safe_shutdown(self): + return False + 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: diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 70be4f67c..101f1edb9 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -1796,6 +1796,19 @@ class GroupchatControl(ChatControlBase): # Remove unread events from systray gajim.events.remove_events(self.account, self.room_jid) + def safe_shutdown(self): + if self.contact.jid in gajim.config.get_per('accounts', self.account, + 'minimized_gc').split(' '): + return True + 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: + return False + return True + 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(' '): diff --git a/src/message_control.py b/src/message_control.py index ab580a1ae..de39a7af5 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -71,6 +71,12 @@ class MessageControl: or inactive (state is False)''' pass # Derived classes MUST implement this method + def safe_shutdown(self): + '''Called to check if control can be closed without loosing data. + returns True if control can be closed safely else False''' + # NOTE: Derived classes MAY implement this + return True + def allow_shutdown(self, method, on_response_yes, on_response_no, on_response_minimize): '''Called to check is a control is allowed to shutdown. diff --git a/src/message_window.py b/src/message_window.py index d7a09c046..9a5b74a55 100644 --- a/src/message_window.py +++ b/src/message_window.py @@ -34,6 +34,7 @@ import time import common import gtkgui_helpers import message_control +import dialogs from chat_control import ChatControlBase from common import gajim @@ -193,6 +194,29 @@ class MessageWindow(object): # Destroy the window return False + # Number of controls that will be closed and for which we'll loose data: + # chat, pm, gc that won't go in roster + number_of_closed_control = 0 + for ctrl in self.controls(): + if not ctrl.safe_shutdown(): + number_of_closed_control += 1 + + if number_of_closed_control > 1: + def on_yes1(checked): + if checked: + gajim.config.set('confirm_close_multiple_tabs', False) + self.dont_warn_on_delete = True + win.destroy() + + if not gajim.config.get('confirm_close_multiple_tabs'): + # destroy window + return False + dialogs.YesNoDialog( + _('You are going to close several tabs'), + _('Do you really want to close them all?'), + checktext=_('Do _not ask me again'), on_response_yes=on_yes1) + return True + def on_yes(ctrl): if self.on_delete_ok == 1: self.dont_warn_on_delete = True