improve minimize on close code

This commit is contained in:
Yann Leboulanger 2007-06-15 18:30:48 +00:00
parent 0758be7c14
commit 0a165c813b
4 changed files with 41 additions and 34 deletions

View File

@ -1658,13 +1658,13 @@ class ChatControl(ChatControlBase):
[self.get_full_jid()] < 2: [self.get_full_jid()] < 2:
# 2 seconds # 2 seconds
dialog = dialogs.ConfirmationDialog( dialog = dialogs.ConfirmationDialog(
#%s is being replaced in the code with JID # %s is being replaced in the code with JID
_('You just received a new message from "%s"') % self.contact.jid, _('You just received a new message from "%s"') % self.contact.jid,
_('If you close this tab and you have history disabled, '\ _('If you close this tab and you have history disabled, '\
'this message will be lost.')) 'this message will be lost.'))
if dialog.get_response() != gtk.RESPONSE_OK: if dialog.get_response() != gtk.RESPONSE_OK:
return False #stop the propagation of the event return 'no' # stop the propagation of the event
return True return 'yes'
def handle_incoming_chatstate(self): def handle_incoming_chatstate(self):
''' handle incoming chatstate that jid SENT TO us ''' ''' handle incoming chatstate that jid SENT TO us '''

View File

@ -1439,29 +1439,28 @@ class GroupchatControl(ChatControlBase):
instance = dialogs.InputDialog(title, prompt, proposed_nick, instance = dialogs.InputDialog(title, prompt, proposed_nick,
is_modal = False, ok_handler = on_ok) is_modal = False, ok_handler = on_ok)
def minimize(self, status='offline'):
# Minimize it
win = gajim.interface.msg_win_mgr.get_window(self.contact.jid,
self.account)
ctrl = win.get_control(self.contact.jid, self.account)
ctrl_page = win.notebook.page_num(ctrl.widget)
control = win.notebook.get_nth_page(ctrl_page)
win.notebook.remove_page(ctrl_page)
control.unparent()
ctrl.parent_win = None
gajim.interface.minimized_controls[self.account][self.contact.jid] = \
ctrl
del win._controls[self.account][self.contact.jid]
gajim.interface.roster.add_groupchat_to_roster(self.account,
self.contact.jid, status = self.subject)
def shutdown(self, status='offline'): def shutdown(self, status='offline'):
if self.contact.jid in gajim.config.get_per('accounts', self.account,
'minimized_gc').split(' '):
# Minimize it
win = gajim.interface.msg_win_mgr.get_window(self.contact.jid,
self.account)
ctrl = win.get_control(self.contact.jid, self.account)
ctrl_page = win.notebook.page_num(ctrl.widget)
control = win.notebook.get_nth_page(ctrl_page)
win.notebook.remove_page(ctrl_page)
control.unparent()
ctrl.parent_win = None
gajim.interface.minimized_controls[self.account][self.contact.jid] = \
ctrl
del win._controls[self.account][self.contact.jid]
gajim.interface.roster.add_groupchat_to_roster(self.account,
self.contact.jid, status = self.subject)
return
gajim.connections[self.account].send_gc_status(self.nick, self.room_jid, gajim.connections[self.account].send_gc_status(self.nick, self.room_jid,
show='offline', status=status) show='offline', status=status)
nick_list = gajim.contacts.get_nick_list(self.account, self.room_jid) nick_list = gajim.contacts.get_nick_list(self.account, self.room_jid)
@ -1491,16 +1490,15 @@ class GroupchatControl(ChatControlBase):
gajim.events.remove_events(self.account, self.room_jid) gajim.events.remove_events(self.account, self.room_jid)
def allow_shutdown(self, method): def allow_shutdown(self, method):
'''If check_selection is True, '''
if self.contact.jid in gajim.config.get_per('accounts', self.account, if self.contact.jid in gajim.config.get_per('accounts', self.account,
'minimized_gc').split(' '): 'minimized_gc').split(' '):
return True return 'minimize'
if method == self.parent_win.CLOSE_ESC: if method == self.parent_win.CLOSE_ESC:
model, iter = self.list_treeview.get_selection().get_selected() model, iter = self.list_treeview.get_selection().get_selected()
if iter: if iter:
self.list_treeview.get_selection().unselect_all() self.list_treeview.get_selection().unselect_all()
return False return 'no'
retval = True retval = 'yes'
includes = gajim.config.get('confirm_close_muc_rooms').split(' ') includes = gajim.config.get('confirm_close_muc_rooms').split(' ')
excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ') excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ')
# whether to ask for comfirmation before closing muc # whether to ask for comfirmation before closing muc
@ -1516,7 +1514,7 @@ class GroupchatControl(ChatControlBase):
_('Do _not ask me again')) _('Do _not ask me again'))
if dialog.get_response() != gtk.RESPONSE_OK: if dialog.get_response() != gtk.RESPONSE_OK:
retval = False retval = 'no'
if dialog.is_checked(): # user does not want to be asked again if dialog.is_checked(): # user does not want to be asked again
gajim.config.set('confirm_close_muc', False) gajim.config.set('confirm_close_muc', False)

View File

@ -56,9 +56,9 @@ class MessageControl:
def allow_shutdown(self, method): def allow_shutdown(self, method):
'''Called to check is a control is allowed to shutdown. '''Called to check is a control is allowed to shutdown.
If a control is not in a suitable shutdown state this method If a control is not in a suitable shutdown state this method
should return False''' should return 'no', else 'yes' or 'minimize' '''
# NOTE: Derived classes MAY implement this # NOTE: Derived classes MAY implement this
return True return 'yes'
def shutdown(self): def shutdown(self):
# NOTE: Derived classes MUST implement this # NOTE: Derived classes MUST implement this

View File

@ -147,8 +147,12 @@ class MessageWindow:
def _on_window_delete(self, win, event): def _on_window_delete(self, win, event):
# Make sure all controls are okay with being deleted # Make sure all controls are okay with being deleted
for ctrl in self.controls(): for ctrl in self.controls():
if not ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON): if ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON) == 'no':
return True # halt the delete return True # halt the delete
# If all are ok, minimize the one that need to be minimized
for ctrl in self.controls():
if ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON) == 'minimize':
ctrl.minimize()
return False return False
def _on_window_destroy(self, win): def _on_window_destroy(self, win):
@ -301,7 +305,12 @@ class MessageWindow:
'''reason is only for gc (offline status message) '''reason is only for gc (offline status message)
if force is True, do not ask any confirmation''' if force is True, do not ask any confirmation'''
# Shutdown the MessageControl # Shutdown the MessageControl
if not force and not ctrl.allow_shutdown(method): allow_shutdown = ctrl.allow_shutdown(method)
if not force and allow_shutdown == 'no':
return
if allow_shutdown == 'minimize' and method != self.CLOSE_COMMAND:
ctrl.minimize()
self.check_tabs()
return return
if reason is not None: # We are leaving gc with a status message if reason is not None: # We are leaving gc with a status message
ctrl.shutdown(reason) ctrl.shutdown(reason)