Skip to content

Commit

Permalink
show message only on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtedde committed Sep 6, 2023
1 parent f018abd commit 25cfc8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/vorta/views/repo_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,15 @@ def create_ssh_key(self):
ssh_add_window = SSHAddWindow()
self._window = ssh_add_window # For tests
ssh_add_window.setParent(self, QtCore.Qt.WindowType.Sheet)
ssh_add_window.create_ssh_key_message.connect(self.init_ssh)
ssh_add_window.create_ssh_key_message.connect(self.create_ssh_key_message)
ssh_add_window.reject.connect(self.init_ssh)
ssh_add_window.create_ssh_key_failure.connect(self.create_ssh_key_failure)
ssh_add_window.open()

def create_ssh_key_message(self, exitCode: int, output_file: str):
def create_ssh_key_failure(self, exit_code):
msg = QMessageBox()
msg.setStandardButtons(QMessageBox.StandardButton.Ok)
msg.setParent(self, QtCore.Qt.WindowType.Sheet)
if exitCode == 0:
msg.setText(self.tr(f"New key was copied to clipboard, and written to:\n{output_file}"))
else:
msg.setText(self.tr('Error during key generation.'))
msg.setText(self.tr(f'Error during key generation. Exited with code {exit_code}.'))
msg.show()

def ssh_copy_to_clipboard_action(self):
Expand All @@ -233,7 +230,6 @@ def ssh_copy_to_clipboard_action(self):
"Use it to set up remote repo permissions."
)
)

else:
msg.setText(self.tr("Could not find public key."))
else:
Expand Down
10 changes: 5 additions & 5 deletions src/vorta/views/ssh_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@


class SSHAddWindow(SSHAddBase, SSHAddUI):
create_ssh_key_message = QtCore.pyqtSignal(int, str)
create_ssh_key_success = QtCore.pyqtSignal()
create_ssh_key_failure = QtCore.pyqtSignal(int)

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -70,17 +71,16 @@ def generate_key(self):
self.sshproc.finished.connect(self.generate_key_result)
self.sshproc.start('ssh-keygen', ['-t', format, '-b', length, '-f', output_path, '-N', ''])

def generate_key_result(self, exitCode):
if exitCode == 0:
def generate_key_result(self, exit_code):
if exit_code == 0:
output_path = os.path.expanduser(self.outputFileTextBox.text())
pub_key = open(output_path + '.pub').read().strip()
clipboard = QApplication.clipboard()
clipboard.setText(pub_key)
self.reject()
self.create_ssh_key_message.emit(exitCode, output_path)
else:
self.reject()
self.create_ssh_key_message.emit(exitCode, "")
self.create_ssh_key_failure.emit(exit_code)

def get_values(self):
return {
Expand Down

0 comments on commit 25cfc8f

Please sign in to comment.