mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2025-01-08 12:00:29 +03:00
Use settings.
This commit is contained in:
parent
ebab226185
commit
f05b044225
@ -175,12 +175,10 @@ class Timer(QtCore.QObject):
|
||||
class GuiController(QtCore.QObject, Controller):
|
||||
refreshed = QtCore.Signal()
|
||||
|
||||
def __init__(self, app, reader_name, slot1=0, slot2=0):
|
||||
def __init__(self, app, settings):
|
||||
super(GuiController, self).__init__()
|
||||
self._app = app
|
||||
self._reader_name = reader_name
|
||||
self._slot1 = slot1
|
||||
self._slot2 = slot2
|
||||
self._settings = settings
|
||||
self._needs_read = False
|
||||
self._reader = None
|
||||
self._creds = None
|
||||
@ -195,6 +193,18 @@ class GuiController(QtCore.QObject, Controller):
|
||||
self.startTimer(2000)
|
||||
self.timer.time_changed.connect(self.refresh_codes)
|
||||
|
||||
@property
|
||||
def reader_name(self):
|
||||
return self._settings.get('reader', 'Yubikey')
|
||||
|
||||
@property
|
||||
def slot1(self):
|
||||
return self._settings.get('slot1', 0)
|
||||
|
||||
@property
|
||||
def slot2(self):
|
||||
return self._settings.get('slot2', 0)
|
||||
|
||||
def unlock(self, dev):
|
||||
dev.unlock(self._keystore.get(dev.id))
|
||||
|
||||
@ -206,7 +216,7 @@ class GuiController(QtCore.QObject, Controller):
|
||||
|
||||
@property
|
||||
def otp_enabled(self):
|
||||
return self.otp_supported and bool(self._slot1 or self._slot2)
|
||||
return self.otp_supported and bool(self.slot1 or self.slot2)
|
||||
|
||||
@property
|
||||
def credentials(self):
|
||||
@ -224,7 +234,7 @@ class GuiController(QtCore.QObject, Controller):
|
||||
|
||||
if self._reader is None:
|
||||
for reader in added:
|
||||
if self._reader_name in reader.name:
|
||||
if self.reader_name in reader.name:
|
||||
self._reader = reader
|
||||
self._creds = []
|
||||
ccid_dev = open_scard(reader)
|
||||
@ -308,7 +318,7 @@ class GuiController(QtCore.QObject, Controller):
|
||||
lock = self.grab_lock(lock)
|
||||
device = open_scard(self._reader)
|
||||
self._needs_read = self._reader and device is None
|
||||
creds = self.read_creds(device, self._slot1, self._slot2, timestamp)
|
||||
creds = self.read_creds(device, self.slot1, self.slot2, timestamp)
|
||||
self._set_creds(creds)
|
||||
|
||||
def timerEvent(self, event):
|
||||
@ -316,7 +326,7 @@ class GuiController(QtCore.QObject, Controller):
|
||||
if self._reader is None and self._creds is None and self.otp_enabled:
|
||||
_lock = self.grab_lock()
|
||||
timestamp = self.timer.time
|
||||
read = self.read_creds(None, self._slot1, self._slot2, timestamp)
|
||||
read = self.read_creds(None, self.slot1, self.slot2, timestamp)
|
||||
if read is not None and self._reader is None:
|
||||
self._set_creds(read)
|
||||
event.accept()
|
||||
|
@ -93,7 +93,7 @@ class YubiOathApplication(qt.Application):
|
||||
self._settings = self.settings.get_group('settings')
|
||||
|
||||
reader = self._settings.get('reader', 'Yubikey')
|
||||
self._controller = GuiController(self, reader, 0, 6)
|
||||
self._controller = GuiController(self, self._settings)
|
||||
self._init_window()
|
||||
|
||||
def _init_window(self):
|
||||
@ -159,7 +159,7 @@ class YubiOathApplication(qt.Application):
|
||||
print "TODO"
|
||||
|
||||
def _show_settings(self):
|
||||
SettingsDialog(self.window).exec_()
|
||||
SettingsDialog(self.window, self._settings).exec_()
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -28,13 +28,17 @@ from yubioath.yubicommon import qt
|
||||
from .. import messages as m
|
||||
from PySide import QtGui
|
||||
|
||||
INDENT = 16
|
||||
|
||||
|
||||
class SettingsDialog(qt.Dialog):
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, parent, settings):
|
||||
super(SettingsDialog, self).__init__(parent)
|
||||
self.settings = settings
|
||||
|
||||
self.accepted.connect(self._save)
|
||||
self._build_ui()
|
||||
self._reset()
|
||||
|
||||
def _build_ui(self):
|
||||
layout = QtGui.QFormLayout(self)
|
||||
@ -47,7 +51,7 @@ class SettingsDialog(qt.Dialog):
|
||||
self._slot1_enabled.stateChanged.connect(self._slot1_digits.setEnabled)
|
||||
self._slot1_digits.setEnabled(False)
|
||||
layout.addRow(m.n_digits, self._slot1_digits)
|
||||
layout.labelForField(self._slot1_digits).setIndent(16)
|
||||
layout.labelForField(self._slot1_digits).setIndent(INDENT)
|
||||
|
||||
self._slot2_enabled = QtGui.QCheckBox(m.enable_slot_1 % 2)
|
||||
layout.addRow(self._slot2_enabled)
|
||||
@ -56,7 +60,7 @@ class SettingsDialog(qt.Dialog):
|
||||
self._slot2_enabled.stateChanged.connect(self._slot2_digits.setEnabled)
|
||||
self._slot2_digits.setEnabled(False)
|
||||
layout.addRow(m.n_digits, self._slot2_digits)
|
||||
layout.labelForField(self._slot2_digits).setIndent(16)
|
||||
layout.labelForField(self._slot2_digits).setIndent(INDENT)
|
||||
|
||||
layout.addRow(self.section(m.general))
|
||||
|
||||
@ -72,6 +76,19 @@ class SettingsDialog(qt.Dialog):
|
||||
btns.rejected.connect(self.reject)
|
||||
layout.addRow(btns)
|
||||
|
||||
def _reset(self):
|
||||
slot1 = self.settings.get('slot1')
|
||||
self._slot1_digits.setCurrentIndex(1 if slot1 == 8 else 0)
|
||||
self._slot1_enabled.setChecked(bool(slot1))
|
||||
|
||||
slot2 = self.settings.get('slot2')
|
||||
self._slot2_digits.setCurrentIndex(1 if slot2 == 8 else 0)
|
||||
self._slot2_enabled.setChecked(bool(slot2))
|
||||
|
||||
self._systray.setChecked(self.settings.get('systray', True))
|
||||
|
||||
self._reader_name.setText(self.settings.get('reader', 'Yubikey'))
|
||||
|
||||
@property
|
||||
def slot1(self):
|
||||
return self._slot1_enabled.isChecked() \
|
||||
@ -91,4 +108,7 @@ class SettingsDialog(qt.Dialog):
|
||||
return self._reader_name.text()
|
||||
|
||||
def _save(self):
|
||||
print "TODO: Save settings"
|
||||
self.settings['slot1'] = self.slot1
|
||||
self.settings['slot2'] = self.slot2
|
||||
self.settings['systray'] = self.systray
|
||||
self.settings['reader'] = self.reader_name
|
||||
|
Loading…
Reference in New Issue
Block a user