Changeset 10157

Show
Ignore:
Timestamp:
08/08/08 17:19:08 (4 months ago)
Author:
asterix
Message:

warning dialogs when closing a chat window are non blocking

Location:
trunk/src
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/chat_control.py

    r10111 r10157  
    22012201                self.msg_textview.destroy() 
    22022202 
    2203         def allow_shutdown(self, method): 
     2203        def allow_shutdown(self, method, on_yes, on_no, on_minimize): 
    22042204                if time.time() - gajim.last_message_time[self.account]\ 
    22052205                [self.get_full_jid()] < 2: 
    22062206                        # 2 seconds 
     2207                        def on_ok(): 
     2208                                on_yes(self) 
     2209 
     2210                        def on_cancel(): 
     2211                                on_no(self) 
     2212 
    22072213                        dialog = dialogs.ConfirmationDialog( 
    22082214                                # %s is being replaced in the code with JID 
    22092215                                _('You just received a new message from "%s"') % self.contact.jid, 
    22102216                                _('If you close this tab and you have history disabled, '\ 
    2211                                 'this message will be lost.')) 
    2212                         if dialog.get_response() != gtk.RESPONSE_OK: 
    2213                                 return 'no' # stop the propagation of the event 
    2214                 return 'yes' 
     2217                                'this message will be lost.'), on_response_ok=on_ok, 
     2218                                on_response_cancel=on_cancel) 
     2219                        return 
     2220                on_yes(self) 
    22152221 
    22162222        def handle_incoming_chatstate(self): 
  • trunk/src/dialogs.py

    r10155 r10157  
    13631363                if self.user_response_cancel: 
    13641364                        if isinstance(self.user_response_cancel, tuple): 
    1365                                 self.user_response_cancel[0](*self.user_response_cancel[1:]) 
     1365                                self.user_response_cancel[0](self.is_checked(), 
     1366                                        *self.user_response_cancel[1:]) 
    13661367                        else: 
    1367                                 self.user_response_cancel() 
     1368                                self.user_response_cancel(self.is_checked()) 
    13681369                self.destroy() 
    13691370 
  • trunk/src/groupchat_control.py

    r10154 r10157  
    16681668                gajim.events.remove_events(self.account, self.room_jid) 
    16691669 
    1670         def allow_shutdown(self, method): 
     1670        def allow_shutdown(self, method, on_yes, on_no, on_minimize): 
    16711671                if self.contact.jid in gajim.config.get_per('accounts', self.account, 
    16721672                'minimized_gc').split(' '): 
    1673                         return 'minimize' 
     1673                        on_minimize(self) 
     1674                        return 
    16741675                if method == self.parent_win.CLOSE_ESC: 
    16751676                        model, iter = self.list_treeview.get_selection().get_selected() 
    16761677                        if iter: 
    16771678                                self.list_treeview.get_selection().unselect_all() 
    1678                                 return 'no' 
    1679                 retval = 'yes' 
     1679                                on_no(self) 
     1680                                return 
    16801681                includes = gajim.config.get('confirm_close_muc_rooms').split(' ') 
    16811682                excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ') 
     
    16841685                and gajim.gc_connected[self.account][self.room_jid] and self.room_jid not\ 
    16851686                in excludes: 
     1687 
     1688                        def on_ok(clicked): 
     1689                                if clicked: 
     1690                                        # user does not want to be asked again 
     1691                                        gajim.config.set('confirm_close_muc', False) 
     1692                                on_yes(self) 
     1693 
     1694                        def on_cancel(clicked): 
     1695                                if clicked: 
     1696                                        # user does not want to be asked again 
     1697                                        gajim.config.set('confirm_close_muc', False) 
     1698                                on_no(self) 
     1699 
    16861700                        pritext = _('Are you sure you want to leave group chat "%s"?')\ 
    16871701                                % self.name 
     
    16901704 
    16911705                        dialog = dialogs.ConfirmationDialogCheck(pritext, sectext, 
    1692                                                 _('Do _not ask me again')) 
    1693  
    1694                         if dialog.get_response() != gtk.RESPONSE_OK: 
    1695                                 retval = 'no' 
    1696  
    1697                         if dialog.is_checked(): # user does not want to be asked again 
    1698                                 gajim.config.set('confirm_close_muc', False) 
    1699  
    1700                 return retval 
     1706                                _('Do _not ask me again'), on_response_ok=on_ok, 
     1707                                on_response_cancel=on_cancel) 
     1708                        return 
     1709 
     1710                on_yes(self) 
    17011711 
    17021712        def set_control_active(self, state): 
  • trunk/src/gtkgui_helpers.py

    r10142 r10157  
    731731                checktext = _('Always check to see if Gajim is the default Jabber client ' 
    732732                        'on startup') 
    733                 def on_cancel(): 
    734                         gajim.config.set('check_if_gajim_is_default', 
    735                                 dlg.is_checked()) 
     733                def on_cancel(checked): 
     734                        gajim.config.set('check_if_gajim_is_default', checked) 
    736735                dlg = dialogs.ConfirmationDialogCheck(pritext, sectext, checktext, 
    737736                        set_gajim_as_xmpp_handler, on_cancel) 
  • trunk/src/message_control.py

    r10084 r10157  
    6363                pass  # Derived classes MUST implement this method 
    6464 
    65         def allow_shutdown(self, method): 
     65        def allow_shutdown(self, method, on_response_yes, on_response_no, 
     66        on_response_minimize): 
    6667                '''Called to check is a control is allowed to shutdown. 
    6768                If a control is not in a suitable shutdown state this method 
    68                 should return 'no', else 'yes' or 'minimize' ''' 
     69                should call on_response_no, else on_response_yes or 
     70                on_response_minimize ''' 
    6971                # NOTE: Derived classes MAY implement this 
    70                 return 'yes' 
     72                on_response_yes(self) 
    7173 
    7274        def shutdown(self): 
  • trunk/src/message_window.py

    r10107 r10157  
    6666                # lead to cylcular references 
    6767                self.handlers = {} 
     68                # Don't show warning dialogs when we want to delete the window 
     69                self.dont_warn_on_delete = False 
    6870 
    6971                self.widget_name = 'message_window' 
     
    183185 
    184186        def _on_window_delete(self, win, event): 
     187                if self.dont_warn_on_delete: 
     188                        # Destroy the window 
     189                        return False 
     190 
     191                def on_yes(ctrl): 
     192                        if self.on_delete_ok == 1: 
     193                                self.dont_warn_on_delete = True 
     194                                win.destroy() 
     195                        self.on_delete_ok -= 1 
     196 
     197                def on_no(ctrl): 
     198                        return 
     199 
     200                def on_minimize(ctrl): 
     201                        self.on_delete_ok -= 1 
     202                        ctrl.minimize() 
     203 
    185204                # Make sure all controls are okay with being deleted 
    186205                ctrl_to_minimize = [] 
     206                self.on_delete_ok = self.get_nb_controls() 
    187207                for ctrl in self.controls(): 
    188                         allow_shutdown = ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON) 
    189                         if allow_shutdown == 'no': 
    190                                 return True # halt the delete 
    191                         elif allow_shutdown == 'minimize': 
    192                                 ctrl_to_minimize.append(ctrl) 
    193                 # If all are ok, minimize the one that need to be minimized 
    194                 for ctrl in ctrl_to_minimize: 
    195                         ctrl.minimize() 
    196                 return False 
     208                        ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON, on_yes, on_no, 
     209                                on_minimize) 
     210                return True # halt the delete for the moment 
    197211 
    198212        def _on_window_destroy(self, win): 
     
    607621                        for ctrl in jid_dict.values(): 
    608622                                yield ctrl 
     623 
     624        def get_nb_controls(self): 
     625                nb_ctrl = 0 
     626                for jid_dict in self._controls.values(): 
     627                        for ctrl in jid_dict.values(): 
     628                                nb_ctrl += 1 
     629                return nb_ctrl 
    609630 
    610631        def move_to_next_unread_tab(self, forward): 
  • trunk/src/roster_window.py

    r10155 r10157  
    37963796                        'accounts or transport accounts.') 
    37973797                dlg = dialogs.ConfirmationDialogCheck(pritext, sectext, 
    3798                         _('Do _not ask me again'), on_response_ok = merge_contacts) 
     3798                        _('Do _not ask me again'), on_response_ok=merge_contacts) 
    37993799                if not confirm_metacontacts: # First time we see this window 
    38003800                        dlg.checkbutton.set_active(True)