Add NewConfirmationCheckDialog
This commit is contained in:
		
							parent
							
								
									4c062bf93d
								
							
						
					
					
						commit
						760b94f27f
					
				
					 2 changed files with 54 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -15,6 +15,7 @@
 | 
			
		|||
from collections import namedtuple
 | 
			
		||||
 | 
			
		||||
from gi.repository import Gtk
 | 
			
		||||
from gi.repository import Pango
 | 
			
		||||
 | 
			
		||||
from gajim.common import app
 | 
			
		||||
from gajim.common import helpers
 | 
			
		||||
| 
						 | 
				
			
			@ -53,6 +54,11 @@ class DialogButton(namedtuple('DialogButton', ('response text callback args '
 | 
			
		|||
                default_kwargs['response'] = Gtk.ResponseType.OK
 | 
			
		||||
                default_kwargs['text'] = _('Delete')
 | 
			
		||||
                default_kwargs['action'] = ButtonAction.DESTRUCTIVE
 | 
			
		||||
 | 
			
		||||
            elif type_ == 'Remove':
 | 
			
		||||
                default_kwargs['response'] = Gtk.ResponseType.OK
 | 
			
		||||
                default_kwargs['text'] = _('Remove')
 | 
			
		||||
                default_kwargs['action'] = ButtonAction.DESTRUCTIVE
 | 
			
		||||
            else:
 | 
			
		||||
                raise ValueError('Unknown button type: %s ' % type_)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1037,6 +1043,37 @@ class NewConfirmationDialog(Gtk.MessageDialog):
 | 
			
		|||
        self.show_all()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NewConfirmationCheckDialog(NewConfirmationDialog):
 | 
			
		||||
    def __init__(self, title, text, sec_text, check_text,
 | 
			
		||||
                 buttons, modal=True, transient_for=None):
 | 
			
		||||
        NewConfirmationDialog.__init__(self,
 | 
			
		||||
                                       title,
 | 
			
		||||
                                       text,
 | 
			
		||||
                                       sec_text,
 | 
			
		||||
                                       buttons,
 | 
			
		||||
                                       transient_for=transient_for,
 | 
			
		||||
                                       modal=modal)
 | 
			
		||||
 | 
			
		||||
        self._checkbutton = Gtk.CheckButton.new_with_mnemonic(check_text)
 | 
			
		||||
        self._checkbutton.set_can_focus(False)
 | 
			
		||||
        self._checkbutton.set_margin_start(30)
 | 
			
		||||
        self._checkbutton.set_margin_end(30)
 | 
			
		||||
        label = self._checkbutton.get_child()
 | 
			
		||||
        label.set_line_wrap(True)
 | 
			
		||||
        label.set_max_width_chars(50)
 | 
			
		||||
        label.set_halign(Gtk.Align.START)
 | 
			
		||||
        label.set_line_wrap_mode(Pango.WrapMode.WORD)
 | 
			
		||||
        label.set_margin_start(10)
 | 
			
		||||
 | 
			
		||||
        self.get_content_area().add(self._checkbutton)
 | 
			
		||||
 | 
			
		||||
    def _on_response(self, _dialog, response):
 | 
			
		||||
        button = self._buttons.get(response)
 | 
			
		||||
        if button is not None:
 | 
			
		||||
            button.args.insert(0, self._checkbutton.get_active())
 | 
			
		||||
        super()._on_response(_dialog, response)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ShortcutsWindow:
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        transient = app.app.get_active_window()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,6 +71,8 @@ from gajim.gtk.dialogs import InputDialog
 | 
			
		|||
from gajim.gtk.dialogs import WarningDialog
 | 
			
		||||
from gajim.gtk.dialogs import InformationDialog
 | 
			
		||||
from gajim.gtk.dialogs import NonModalConfirmationDialog
 | 
			
		||||
from gajim.gtk.dialogs import NewConfirmationCheckDialog
 | 
			
		||||
from gajim.gtk.dialogs import DialogButton
 | 
			
		||||
from gajim.gtk.join_groupchat import JoinGroupchatWindow
 | 
			
		||||
from gajim.gtk.single_message import SingleMessageWindow
 | 
			
		||||
from gajim.gtk.add_contact import AddNewContactWindow
 | 
			
		||||
| 
						 | 
				
			
			@ -3347,7 +3349,7 @@ class RosterWindow:
 | 
			
		|||
        """
 | 
			
		||||
        Remove a contact. list_ is a list of (contact, account) tuples
 | 
			
		||||
        """
 | 
			
		||||
        def on_ok(is_checked, list_):
 | 
			
		||||
        def on_ok(is_checked):
 | 
			
		||||
            remove_auth = True
 | 
			
		||||
            if len(list_) == 1:
 | 
			
		||||
                contact = list_[0][0]
 | 
			
		||||
| 
						 | 
				
			
			@ -3366,8 +3368,8 @@ class RosterWindow:
 | 
			
		|||
                    contact.show = 'offline'
 | 
			
		||||
                    app.contacts.add_contact(account, contact)
 | 
			
		||||
                    self.add_contact(contact.jid, account)
 | 
			
		||||
        def on_ok2(list_):
 | 
			
		||||
            on_ok(False, list_)
 | 
			
		||||
        def on_ok2():
 | 
			
		||||
            on_ok(False)
 | 
			
		||||
 | 
			
		||||
        if len(list_) == 1:
 | 
			
		||||
            contact = list_[0][0]
 | 
			
		||||
| 
						 | 
				
			
			@ -3380,19 +3382,22 @@ class RosterWindow:
 | 
			
		|||
                ConfirmationDialog(pritext, sectext + \
 | 
			
		||||
                    _('By removing this contact you also remove authorization '
 | 
			
		||||
                    'resulting in them always seeing you as offline.'),
 | 
			
		||||
                    on_response_ok=(on_ok2, list_))
 | 
			
		||||
                    on_response_ok=on_ok2)
 | 
			
		||||
            elif _('Not in Roster') in contact.get_shown_groups():
 | 
			
		||||
                # Contact is not in roster
 | 
			
		||||
                ConfirmationDialog(pritext, sectext + \
 | 
			
		||||
                    _('Do you want to continue?'), on_response_ok=(on_ok2,
 | 
			
		||||
                    list_))
 | 
			
		||||
                    _('Do you want to continue?'), on_response_ok=on_ok2)
 | 
			
		||||
            else:
 | 
			
		||||
                ConfirmationDialogCheck(pritext, sectext + \
 | 
			
		||||
                NewConfirmationCheckDialog(
 | 
			
		||||
                    _('Remove'),
 | 
			
		||||
                    pritext, sectext + \
 | 
			
		||||
                    _('By removing this contact you also by default remove '
 | 
			
		||||
                    'authorization resulting in them always seeing you as'
 | 
			
		||||
                    ' offline.'),
 | 
			
		||||
                    _('I want this contact to know my status after removal'),
 | 
			
		||||
                    on_response_ok=(on_ok, list_))
 | 
			
		||||
                      'authorization resulting in them always seeing you as'
 | 
			
		||||
                      ' offline.'),
 | 
			
		||||
                    _('_I want this contact to know my status after removal'),
 | 
			
		||||
                    [DialogButton.make('Cancel'),
 | 
			
		||||
                     DialogButton.make('Remove', callback=on_ok)],
 | 
			
		||||
                     modal=False).show()
 | 
			
		||||
        else:
 | 
			
		||||
            # several contact to remove at the same time
 | 
			
		||||
            pritext = _('Contacts will be removed from your roster')
 | 
			
		||||
| 
						 | 
				
			
			@ -3403,8 +3408,7 @@ class RosterWindow:
 | 
			
		|||
            sectext = _('By removing these contacts:%s\nyou also remove '
 | 
			
		||||
                'authorization resulting in them always seeing you as '
 | 
			
		||||
                'offline.') % jids
 | 
			
		||||
            ConfirmationDialog(pritext, sectext,
 | 
			
		||||
                on_response_ok=(on_ok2, list_))
 | 
			
		||||
            ConfirmationDialog(pritext, sectext, on_response_ok=on_ok2)
 | 
			
		||||
 | 
			
		||||
    def on_send_custom_status(self, widget, contact_list, show, group=None):
 | 
			
		||||
        """
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue