Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy to clipboard #157

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion nitrokeyapp/secrets_tab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional

from PyQt5.QtCore import Qt, QThread, QTimer, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QIcon
from PyQt5.QtGui import QGuiApplication, QIcon
from PyQt5.QtWidgets import QDialog, QListWidgetItem, QWidget

from nitrokeyapp.add_secret_dialog import AddSecretDialog
Expand Down Expand Up @@ -65,6 +65,9 @@ def __init__(self, parent: Optional[QWidget] = None) -> None:
self.otp_timer.timeout.connect(self.update_otp_timeout)
self.otp_timer.setInterval(1000)

self.clipboard = QGuiApplication.clipboard()
self.originalText = self.clipboard.text()

self.ui = Ui_SecretsTab()
self.ui.setupUi(self)

Expand All @@ -81,6 +84,7 @@ def __init__(self, parent: Optional[QWidget] = None) -> None:
self.ui.buttonDelete.pressed.connect(self.delete_credential)
self.ui.buttonRefresh.pressed.connect(self.refresh_credential_list)
self.ui.checkBoxProtected.stateChanged.connect(self.refresh_credential_list)
self.ui.pushButtonOtpCopyToClipbord.pressed.connect(self.copy_to_clipboard)
self.ui.pushButtonOtpGenerate.pressed.connect(self.generate_otp)
self.ui.secretsList.currentItemChanged.connect(self.credential_changed)

Expand Down Expand Up @@ -169,6 +173,7 @@ def credentials_listed(self, credentials: list[Credential]) -> None:
@pyqtSlot(OtpData)
def otp_generated(self, data: OtpData) -> None:
self.ui.lineEditOtp.setText(data.otp)
self.data_otp = data.otp

if data.validity:
start, end = data.validity
Expand All @@ -184,6 +189,9 @@ def otp_generated(self, data: OtpData) -> None:
self.ui.labelOtp.show()
self.ui.lineEditOtp.show()

def copy_to_clipboard(self) -> None:
self.clipboard.setText(self.data_otp)

def add_credential(self, credential: Credential) -> QListWidgetItem:
icon = (
"lock_FILL0_wght500_GRAD0_opsz40"
Expand Down Expand Up @@ -234,6 +242,7 @@ def hide_otp(self) -> None:
self.ui.progressBarOtpTimeout.hide()
self.ui.labelOtp.hide()
self.ui.lineEditOtp.hide()
self.ui.pushButtonOtpCopyToClipbord.hide()

credential = self.get_current_credential()
self.update_otp_generation(credential)
Expand All @@ -249,6 +258,7 @@ def update_otp_timeout(self) -> None:
timeout = int((self.otp_timeout - datetime.now()).total_seconds())
if timeout >= 0:
self.ui.progressBarOtpTimeout.setValue(timeout)
self.ui.pushButtonOtpCopyToClipbord.show()
else:
self.hide_otp()

Expand Down
26 changes: 9 additions & 17 deletions nitrokeyapp/ui/secrets_tab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,7 @@
<height>457</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBoxMetadata">
<property name="title">
Expand Down Expand Up @@ -224,9 +212,6 @@
<string>One-Time Password</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="horizontalSpacing">
<number>20</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelAlgorithm">
<property name="text">
Expand Down Expand Up @@ -280,13 +265,20 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="3" column="0">
<widget class="QPushButton" name="pushButtonOtpGenerate">
<property name="text">
<string>Generate</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="pushButtonOtpCopyToClipbord">
<property name="text">
<string notr="true">Copy to Clipbord</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down