-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
751 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import binascii | ||
import logging | ||
from base64 import b32decode, b32encode | ||
from enum import Enum | ||
from random import randbytes | ||
from typing import Callable, Optional | ||
|
||
from PySide6.QtCore import Qt, QThread, QTimer, Signal, Slot | ||
from PySide6.QtGui import QGuiApplication | ||
from PySide6.QtWidgets import QLineEdit, QListWidgetItem, QWidget | ||
|
||
from nitrokeyapp.common_ui import CommonUi | ||
from nitrokeyapp.device_data import DeviceData | ||
from nitrokeyapp.qt_utils_mix_in import QtUtilsMixIn | ||
from nitrokeyapp.worker import Worker | ||
|
||
from .worker import SettingsWorker | ||
|
||
# logger = logging.getLogger(__name__) | ||
|
||
# class SettingsTabState(Enum): | ||
# Initial = 0 | ||
# ShowCred = 1 | ||
# AddCred = 2 | ||
# EditCred = 3 | ||
# | ||
# NotAvailable = 99 | ||
|
||
|
||
class SettingsTab(QtUtilsMixIn, QWidget): | ||
# standard UI | ||
# busy_state_changed = Signal(bool) | ||
# error = Signal(str, Exception) | ||
# start_touch = Signal() | ||
# stop_touch = Signal() | ||
|
||
# worker triggers | ||
# trigger_add_credential = Signal(DeviceData, Credential, bytes) | ||
|
||
def __init__(self, parent: Optional[QWidget] = None) -> None: | ||
QWidget.__init__(self, parent) | ||
QtUtilsMixIn.__init__(self) | ||
|
||
self.data: Optional[DeviceData] = None | ||
self.common_ui = CommonUi() | ||
|
||
self.worker_thread = QThread() | ||
self._worker = SettingsWorker(self.common_ui) | ||
self._worker.moveToThread(self.worker_thread) | ||
self.worker_thread.start() | ||
|
||
self.ui = self.load_ui("settings_tab.ui", self) | ||
|
||
@property | ||
def title(self) -> str: | ||
return "Settings" | ||
|
||
@property | ||
def widget(self) -> QWidget: | ||
return self.ui | ||
|
||
@property | ||
def worker(self) -> Optional[Worker]: | ||
return self._worker | ||
|
||
def reset(self) -> None: | ||
self.data = None | ||
|
||
def refresh(self, data: DeviceData, force: bool = False) -> None: | ||
if data == self.data and not force: | ||
return | ||
self.reset() | ||
self.data = data | ||
|
||
def set_device_data( | ||
self, path: str, uuid: str, version: str, variant: str, init_status: str | ||
) -> None: | ||
self.ui.nk3_path.setText(path) | ||
self.ui.nk3_uuid.setText(uuid) | ||
self.ui.nk3_version.setText(version) | ||
self.ui.nk3_variant.setText(variant) | ||
self.ui.nk3_status.setText(init_status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from PySide6.QtCore import Signal, Slot | ||
|
||
from nitrokeyapp.common_ui import CommonUi | ||
from nitrokeyapp.device_data import DeviceData | ||
from nitrokeyapp.update import UpdateGUI | ||
from nitrokeyapp.worker import Job, Worker | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class UpdateDevice(Job): | ||
device_updated = Signal(bool) | ||
|
||
def __init__( | ||
self, | ||
common_ui: CommonUi, | ||
data: DeviceData, | ||
) -> None: | ||
super().__init__(common_ui) | ||
|
||
self.data = data | ||
|
||
self.image: Optional[str] = None | ||
|
||
self.device_updated.connect(lambda _: self.finished.emit()) | ||
|
||
self.update_gui = UpdateGUI(self.common_ui) | ||
self.common_ui.prompt.confirmed.connect(self.cancel_busy_wait) | ||
|
||
def run(self) -> None: | ||
if not self.image: | ||
success = self.data.update(self.update_gui) | ||
else: | ||
success = self.data.update(self.update_gui, self.image) | ||
|
||
self.device_updated.emit(success) | ||
|
||
@Slot() | ||
def cleanup(self) -> None: | ||
self.common_ui.prompt.confirmed.disconnect() | ||
|
||
@Slot(bool) | ||
def cancel_busy_wait(self, confirmed: bool) -> None: | ||
self.update_gui.await_confirmation = confirmed | ||
|
||
|
||
class SettingsWorker(Worker): | ||
# TODO: remove DeviceData from signatures | ||
device_updated = Signal(bool) | ||
|
||
def __init__(self, common_ui: CommonUi) -> None: | ||
super().__init__(common_ui) | ||
|
||
@Slot(DeviceData) | ||
def update_device(self, data: DeviceData) -> None: | ||
job = UpdateDevice(self.common_ui, data) | ||
job.device_updated.connect(self.device_updated) | ||
self.run(job) | ||
|
||
@Slot(DeviceData, str) | ||
def update_device_file(self, data: DeviceData, filename: str) -> None: | ||
job = UpdateDevice(self.common_ui, data) | ||
job.image = filename | ||
job.device_updated.connect(self.device_updated) | ||
self.run(job) |
Oops, something went wrong.