Skip to content

Commit

Permalink
[Enhancement] Better status message when adding existing repo
Browse files Browse the repository at this point in the history
- Avoids freezing UI when an existing repo is added

Closes #1306
  • Loading branch information
DaffyTheDuck committed Mar 15, 2023
1 parent c4d16e2 commit 85e9d09
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/vorta/views/repo_add_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from PyQt5 import QtCore, uic
from PyQt5.QtWidgets import QAction, QApplication, QDialogButtonBox, QLineEdit
Expand All @@ -9,6 +10,8 @@
from vorta.utils import borg_compat, choose_file_dialog, get_asset, get_private_keys, validate_passwords
from vorta.views.utils import get_colored_icon

logger = logging.getLogger(__name__)

uifile = get_asset('UI/repoadd.ui')
AddRepoUI, AddRepoBase = uic.loadUiType(uifile)

Expand All @@ -27,7 +30,7 @@ def __init__(self, parent=None):
self.saveButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
self.saveButton.setText(self.tr("Add"))

self.buttonBox.rejected.connect(self.close)
self.buttonBox.rejected.connect(lambda: (self.cancel_job(), self.close()))
self.buttonBox.accepted.connect(self.run)
self.chooseLocalFolderButton.clicked.connect(self.choose_local_backup_folder)
self.useRemoteRepoButton.clicked.connect(self.use_remote_repo_action)
Expand Down Expand Up @@ -211,6 +214,11 @@ def password_listener(self):
self.passwordLabel.setText(translate('utils', msg))
return not bool(msg)

def cancel_job(self):
if self.job:
self.job.cancel()
logger.info('Cancelled adding repo.')


class ExistingRepoWindow(AddRepoWindow):
def __init__(self):
Expand Down Expand Up @@ -242,10 +250,10 @@ def run(self):
params = BorgInfoRepoJob.prepare(self.values)
if params['ok']:
self.saveButton.setEnabled(False)
thread = BorgInfoRepoJob(params['cmd'], params)
thread.updated.connect(self._set_status)
thread.result.connect(self.run_result)
self.thread = thread # Needs to be connected to self for tests to work.
self.thread.run()
job = BorgInfoRepoJob(params['cmd'], params)
job.updated.connect(self._set_status)
job.result.connect(self.run_result)
self.job = job # Needs to be connected to self for tests to work.
QApplication.instance().jobs_manager.add_job(job)
else:
self._set_status(params['message'])

0 comments on commit 85e9d09

Please sign in to comment.