Warn user before closing chat window with tabs where we can loose data. Fixes #3645

This commit is contained in:
Yann Leboulanger 2009-04-08 16:28:51 +00:00
parent 16456b3b96
commit 0c27b86cc1
4 changed files with 46 additions and 0 deletions

View File

@ -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:

View File

@ -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(' '):

View File

@ -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.

View File

@ -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