From aa8f26c2c8ade16858384541bb48d4b8710e1953 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 20 Feb 2024 16:38:44 +0530 Subject: [PATCH] feat: directories multiselections --- src/vorta/utils.py | 5 +++-- src/vorta/views/archive_tab.py | 3 ++- src/vorta/views/repo_add_dialog.py | 3 ++- src/vorta/views/source_tab.py | 8 +++++--- tests/integration/conftest.py | 3 +++ tests/unit/conftest.py | 3 +++ tests/unit/test_archives.py | 3 +++ 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/vorta/utils.py b/src/vorta/utils.py index 46b392c3a..de20e797c 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -177,10 +177,11 @@ def choose_file_dialog(parent, title, want_folder=True): dialog.setFileMode(QFileDialog.FileMode.Directory if want_folder else QFileDialog.FileMode.ExistingFiles) dialog.setParent(parent, QtCore.Qt.WindowType.Sheet) if want_folder: + dialog.setOption(QFileDialog.Option.ShowDirsOnly) list_view = dialog.findChild(QTreeView) list_view.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection) - dialog.exec() - return dialog.selectedFiles() + + return dialog def is_ssh_private_key_file(filepath: str) -> bool: diff --git a/src/vorta/views/archive_tab.py b/src/vorta/views/archive_tab.py index d2af5757b..7ef851d36 100644 --- a/src/vorta/views/archive_tab.py +++ b/src/vorta/views/archive_tab.py @@ -642,7 +642,8 @@ def receive(): self.app.jobs_manager.add_job(job) dialog = choose_file_dialog(self, self.tr("Choose Mount Point"), want_folder=True) - dialog.open(receive) + dialog.exec() + receive() def mount_result(self, result): if result['returncode'] == 0: diff --git a/src/vorta/views/repo_add_dialog.py b/src/vorta/views/repo_add_dialog.py index cd265a333..d0d22c29d 100644 --- a/src/vorta/views/repo_add_dialog.py +++ b/src/vorta/views/repo_add_dialog.py @@ -72,7 +72,8 @@ def receive(): self.is_remote_repo = False dialog = choose_file_dialog(self, self.tr("Choose Location of Borg Repository")) - dialog.open(receive) + dialog.exec() + receive() def use_remote_repo_action(self): self.repoURL.setText('') diff --git a/src/vorta/views/source_tab.py b/src/vorta/views/source_tab.py index f97834740..158d932b2 100644 --- a/src/vorta/views/source_tab.py +++ b/src/vorta/views/source_tab.py @@ -286,7 +286,8 @@ def sources_update(self): self.update_path_info(row) # Update data for each entry def source_add(self, want_folder): - def receive(dirs): + def receive(): + dirs = dialog.selectedFiles() for dir in dirs: if not os.access(dir, os.R_OK): msg = QMessageBox() @@ -301,8 +302,9 @@ def receive(dirs): msg = self.tr("Choose directory to back up") if want_folder else self.tr("Choose file(s) to back up") - paths = choose_file_dialog(self, msg, want_folder=want_folder) - receive(paths) + dialog = choose_file_dialog(self, msg, want_folder) + dialog.exec() + receive() def source_copy(self, index=None): """ diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 683271f54..8dffd8d7a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -190,6 +190,9 @@ def __init__(self, *args, **kwargs): def open(self, func): func() + def exec(self): + return 1 + def selectedFiles(self): if self.subdirectory: return [str(tmpdir.join(self.subdirectory))] diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index e622a2118..2d689d40e 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -86,6 +86,9 @@ def __init__(self, *args, **kwargs): def open(self, func): func() + def exec(self): + return 1 + def selectedFiles(self): return ['/tmp'] diff --git a/tests/unit/test_archives.py b/tests/unit/test_archives.py index e0a7fb1aa..3a04f1470 100644 --- a/tests/unit/test_archives.py +++ b/tests/unit/test_archives.py @@ -14,6 +14,9 @@ class MockFileDialog: def open(self, func): func() + def exec(self): + return 1 + def selectedFiles(self): return ['/tmp']