From 92608f9eaaa6ac9d4bf28f9fa59edaae6001fe07 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Sun, 25 Jun 2023 01:27:46 +0530 Subject: [PATCH] Assign names to repos. By @diivi (#1665) --- src/vorta/assets/UI/repoadd.ui | 557 ++++++++++++++------------- src/vorta/assets/icons/eye-slash.svg | 2 +- src/vorta/assets/icons/eye.svg | 2 +- src/vorta/borg/borg_job.py | 3 +- src/vorta/borg/info_repo.py | 8 +- src/vorta/borg/init.py | 2 + src/vorta/store/connection.py | 2 +- src/vorta/store/migrations.py | 11 + src/vorta/store/models.py | 1 + src/vorta/views/archive_tab.py | 7 +- src/vorta/views/repo_add_dialog.py | 7 + src/vorta/views/repo_tab.py | 4 +- tests/test_repo.py | 4 +- 13 files changed, 332 insertions(+), 278 deletions(-) diff --git a/src/vorta/assets/UI/repoadd.ui b/src/vorta/assets/UI/repoadd.ui index 643e2a77..b0f86141 100644 --- a/src/vorta/assets/UI/repoadd.ui +++ b/src/vorta/assets/UI/repoadd.ui @@ -1,278 +1,299 @@ - AddRepository - - - - 0 - 0 - 466 - 274 - - - + AddRepository + + + + 0 + 0 + 583 + 338 + + + + true + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 20 + + + + + 11 + + + + + + + Qt::PlainText + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + true - - - - 0 - - - - - - 0 - 0 - - - - - 0 - 20 - - - - - 11 - - + + + + + + + + 0 + 0 + + + + 0 + + + + General + + + + QFormLayout::ExpandingFieldsGrow + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + true + + + + Initialize New Backup Repository + + + + + + + Repository URL: + + + + + + + 0 + + + 0 + + + + + ssh://abc123@abc123.repo.borgbase.com/./repo + + + + + + + Choose a local folder + + + ... + + + + :/icons/folder-open.svg:/icons/folder-open.svg + + + + + + + Choose a remote repository + + + ... + + + + :/icons/globe.svg:/icons/globe.svg + + + + + + + + + Repository Name: + + + + + + + Macbook Pro Office (optional) + + + + + - + - - Qt::PlainText - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - 0 - 0 - - - - 0 - - - - General - - - - QFormLayout::ExpandingFieldsGrow - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - true - - - - Initialize New Backup Repository - - - - - - - Repository URL: - - - - - - - 0 - - - 0 - - - - - ssh://abc123@abc123.repo.borgbase.com/./repo - - - - - - - Choose a local folder - - - ... - - - - :/icons/folder-open.svg:/icons/folder-open.svg - - - - - - - Choose a remote repository - - - ... - - - - :/icons/globe.svg:/icons/globe.svg - - - - - - - - - Borg passphrase: - - - - - - - true - - - QLineEdit::Password - - - - - - - true - - - QLineEdit::Password - - - - - - - Confirm passphrase: - - - - - - - TextLabel - - - - - - - - Advanced - - - - QFormLayout::ExpandingFieldsGrow - - - 5 - - - 5 - - - 5 - - - 5 - - - - - SSH Key: - - - - - - - - 0 - 0 - - - - - Automatically choose SSH Key (default) - - - - - - - - Encryption: - - - - - - - - 0 - 0 - - - - - - - - Extra Borg Arguments: - - - - - - - + + + + + Borg passphrase: + - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + true + + + QLineEdit::Password + + + + + + + Confirm passphrase: + + + + + + + true + + + QLineEdit::Password + + + + + + + TextLabel + + + + + + + + Advanced + + + + QFormLayout::ExpandingFieldsGrow + + + 5 + + + 5 + + + 5 + + + 5 + + + + + SSH Key: + + + + + + + + 0 + 0 + + + + + Automatically choose SSH Key (default) + - - - - - + + + + + Encryption: + + + + + + + + 0 + 0 + + + + + + + + Extra Borg Arguments: + + + + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + diff --git a/src/vorta/assets/icons/eye-slash.svg b/src/vorta/assets/icons/eye-slash.svg index f4fb73f8..e4d04343 100644 --- a/src/vorta/assets/icons/eye-slash.svg +++ b/src/vorta/assets/icons/eye-slash.svg @@ -1,5 +1,5 @@ - - 64: + self._set_status(self.tr('Repository name must be less than 64 characters.')) + return False + if RepoModel.get_or_none(RepoModel.url == self.values['repo_url']) is not None: self._set_status(self.tr('This repo has already been added.')) return False diff --git a/src/vorta/views/repo_tab.py b/src/vorta/views/repo_tab.py index 2f6b52fb..96b614b0 100644 --- a/src/vorta/views/repo_tab.py +++ b/src/vorta/views/repo_tab.py @@ -79,8 +79,10 @@ def set_icons(self): def set_repos(self): self.repoSelector.clear() self.repoSelector.addItem(self.tr('No repository selected'), None) + # set tooltip = url for each item in the repoSelector for repo in RepoModel.select(): - self.repoSelector.addItem(repo.url, repo.id) + self.repoSelector.addItem(f"{repo.name + ' - ' if repo.name else ''}{repo.url}", repo.id) + self.repoSelector.setItemData(self.repoSelector.count() - 1, repo.url, QtCore.Qt.ItemDataRole.ToolTipRole) def populate_from_profile(self): try: diff --git a/tests/test_repo.py b/tests/test_repo.py index bfbb75c7..b5b07096 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -85,8 +85,10 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output): main.repoTab.new_repo() # couldn't click menu add_repo_window = main.repoTab._window test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain + test_repo_name = 'Test Repo' qtbot.keyClicks(add_repo_window.repoURL, test_repo_url) + qtbot.keyClicks(add_repo_window.repoName, test_repo_name) qtbot.keyClicks(add_repo_window.passwordLineEdit, LONG_PASSWORD) qtbot.keyClicks(add_repo_window.confirmLineEdit, LONG_PASSWORD) @@ -103,7 +105,7 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output): keyring = VortaKeyring.get_keyring() assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD - assert main.repoTab.repoSelector.currentText() == test_repo_url + assert main.repoTab.repoSelector.currentText() == f"{test_repo_name} - {test_repo_url}" def test_ssh_dialog(qapp, qtbot, tmpdir):