Commit 245cecf1 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

Rework PassphraseDialog

parent a9499386
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<requires lib="gtk+" version="3.20"/>
<object class="GtkDialog" id="passphrase_dialog">
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="border_width">18</property>
<property name="title" translatable="yes">Passphrase</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<signal name="destroy" handler="on_passphrase_dialog_destroy" swapped="no"/>
<child>
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox4">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area3">
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">12</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label">gtk-cancel</property>
<property name="label">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok_button">
<property name="label">gtk-ok</property>
<property name="label">_OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
<property name="use_underline">True</property>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="vbox30">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<property name="spacing">18</property>
<child>
<object class="GtkLabel" id="message_label">
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="wrap">True</property>
<property name="icon_name">dialog-password-symbolic</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">5</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="passphrase_entry">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="visibility">False</property>
<property name="activates_default">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="message_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">6</property>
<property name="wrap">True</property>
<property name="max_width_chars">40</property>
<property name="xalign">0</property>
<style>
<class name="bold"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="passphrase_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="visibility">False</property>
<property name="activates_default">True</property>
<property name="input_purpose">password</property>
<property name="input_hints">GTK_INPUT_HINT_NO_SPELLCHECK | GTK_INPUT_HINT_NONE</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="save_passphrase_checkbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="save_passphrase_checkbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......
......@@ -217,68 +217,6 @@ class EditGroupsDialog:
column.add_attribute(renderer, 'active', 1)
column.add_attribute(renderer, 'inconsistent', 2)
class PassphraseDialog:
"""
Class for Passphrase dialog
"""
def __init__(self, titletext, labeltext, checkbuttontext=None,
ok_handler=None, cancel_handler=None, transient_for=None):
self.xml = get_builder('passphrase_dialog.ui')
self.window = self.xml.get_object('passphrase_dialog')
self.passphrase_entry = self.xml.get_object('passphrase_entry')
self.passphrase = -1
self.window.set_title(titletext)
self.xml.get_object('message_label').set_text(labeltext)
self.ok = False
self.cancel_handler = cancel_handler
self.ok_handler = ok_handler
okbutton = self.xml.get_object('ok_button')
okbutton.connect('clicked', self.on_okbutton_clicked)
cancelbutton = self.xml.get_object('cancel_button')
cancelbutton.connect('clicked', self.on_cancelbutton_clicked)
self.xml.connect_signals(self)
if transient_for is None:
transient_for = app.app.get_active_window()
self.window.set_transient_for(transient_for)
self.window.show_all()
self.check = bool(checkbuttontext)
checkbutton = self.xml.get_object('save_passphrase_checkbutton')
if self.check:
checkbutton.set_label(checkbuttontext)
else:
checkbutton.hide()
def on_okbutton_clicked(self, widget):
if not self.ok_handler:
return
passph = self.passphrase_entry.get_text()
if self.check:
checked = self.xml.get_object('save_passphrase_checkbutton').\
get_active()
else:
checked = False
self.ok = True
self.window.destroy()
if isinstance(self.ok_handler, tuple):
self.ok_handler[0](passph, checked, *self.ok_handler[1:])
else:
self.ok_handler(passph, checked)
def on_cancelbutton_clicked(self, widget):
self.window.destroy()
def on_passphrase_dialog_destroy(self, widget):
if self.cancel_handler and not self.ok:
self.cancel_handler()
class ChangeActivityDialog:
PAGELIST = [
......
......@@ -31,13 +31,13 @@ from gajim.common.connection import Connection
from gajim.common.zeroconf.connection_zeroconf import ConnectionZeroconf
from gajim import gui_menu_builder
from gajim.dialogs import PassphraseDialog
from gajim.gtk.settings import SettingsDialog
from gajim.gtk.settings import SettingsBox
from gajim.gtk.dialogs import ConfirmationDialog
from gajim.gtk.dialogs import ConfirmationDialogDoubleRadio
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import PassphraseDialog
from gajim.gtk.dialogs import YesNoDialog
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
......
......@@ -1071,6 +1071,65 @@ class InvitationReceivedDialog(Gtk.ApplicationWindow):
self.destroy()
class PassphraseDialog:
"""
Class for Passphrase dialog
"""
def __init__(self, titletext, labeltext, checkbuttontext=None,
ok_handler=None, cancel_handler=None, transient_for=None):
self._ui = get_builder('passphrase_dialog.ui')
self.window = self._ui.get_object('passphrase_dialog')
self.passphrase = -1
self.window.set_title(titletext)
self._ui.message_label.set_text(labeltext)
self.ok = False
self.cancel_handler = cancel_handler
self.ok_handler = ok_handler
self._ui.ok_button.connect('clicked', self.on_okbutton_clicked)
self._ui.cancel_button.connect('clicked', self.on_cancelbutton_clicked)
self._ui.connect_signals(self)
if transient_for is None:
transient_for = app.app.get_active_window()
self.window.set_transient_for(transient_for)
self.window.show_all()
self.check = bool(checkbuttontext)
if self._ui.save_passphrase_checkbutton:
self._ui.save_passphrase_checkbutton.set_label(checkbuttontext)
else:
self._ui.save_passphrase_checkbutton.hide()
def on_okbutton_clicked(self, widget):
if not self.ok_handler:
return
passph = self._ui.passphrase_entry.get_text()
if self.check:
checked = self._ui.save_passphrase_checkbutton.get_active()
else:
checked = False
self.ok = True
self.window.destroy()
if isinstance(self.ok_handler, tuple):
self.ok_handler[0](passph, checked, *self.ok_handler[1:])
else:
self.ok_handler(passph, checked)
def on_cancelbutton_clicked(self, widget):
self.window.destroy()
def on_passphrase_dialog_destroy(self, widget):
if self.cancel_handler and not self.ok:
self.cancel_handler()
class NewConfirmationDialog(Gtk.MessageDialog):
def __init__(self, title, text, sec_text, buttons,
modal=True, transient_for=None):
......
......@@ -109,6 +109,7 @@ from gajim.gtk.dialogs import WarningDialog
from gajim.gtk.dialogs import InformationDialog
from gajim.gtk.dialogs import InputDialog
from gajim.gtk.dialogs import YesNoDialog
from gajim.gtk.dialogs import PassphraseDialog
from gajim.gtk.dialogs import PlainConnectionDialog
from gajim.gtk.dialogs import SSLErrorDialog
from gajim.gtk.dialogs import ChangeNickDialog
......@@ -574,9 +575,10 @@ class Interface:
obj.conn.on_client_cert_passphrase('', obj.con, obj.port,
obj.secure_tuple)
dialogs.PassphraseDialog(_('Certificate Passphrase Required'),
_('Enter the certificate passphrase for account %s') % \
obj.conn.name, ok_handler=on_ok, cancel_handler=on_cancel)
PassphraseDialog(_('Certificate Passphrase Required'),
_('Enter the certificate passphrase for account %s') % \
obj.conn.name, ok_handler=on_ok,
cancel_handler=on_cancel)
def handle_event_password_required(self, obj):
#('PASSWORD_REQUIRED', account, None)
......@@ -595,7 +597,7 @@ class Interface:
obj.conn.disconnect(reconnect=False, immediately=True)
del self.pass_dialog[account]
self.pass_dialog[account] = dialogs.PassphraseDialog(
self.pass_dialog[account] = PassphraseDialog(
_('Password Required'), text, _('Save password'), ok_handler=on_ok,
cancel_handler=on_cancel)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment