vorta icon indicating copy to clipboard operation
vorta copied to clipboard

Multiple selection does not work for directories.

Open m3nu opened this issue 1 year ago • 17 comments
trafficstars

Discussed in https://github.com/borgbase/vorta/discussions/1867

Originally posted by user723045 December 10, 2023 Hello. On the Source tab, I add directories and files to the list for backup. I noticed that when I select multiple files by holding down the shift key it works fine. But when I try to add several directories at a time in the same way, it does not work and only one single directory is added. This is very inconvenient if you need to select many directories, you have to make many more clicks.

I'm using borg 1.2.6 and Vorta 0.8.12 on Kali linux. I installed packages using apt.

m3nu avatar Dec 11 '23 16:12 m3nu

Possible bug in how we deal with dirs/files.

m3nu avatar Dec 11 '23 16:12 m3nu

In src/vorta/utils.py:

def choose_file_dialog(parent, title, want_folder=True):
    dialog = QFileDialog(parent, title, os.path.expanduser('~'))
    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)
    return dialog

This is the function responsible for selecting sources, as we are using QFileDialog which doesn't have any feature to allow us to select multiple directories in one go. To do this, we need to find an alternative.

SAMAD101 avatar Dec 14 '23 16:12 SAMAD101

Is this really a limitation of Qt or are we using QFileDialog incorrectly?

real-yfprojects avatar Dec 14 '23 17:12 real-yfprojects

Is this really a limitation of Qt or are we using QFileDialog incorrectly? Its is a limitation. Though alternatively, we can use QTreeView with QAbstractItemView.SelectionMode.MultiSelection selection mode.

def choose_file_dialog(parent, title, want_folder=True):
    dialog = QFileDialog(parent, title, os.path.expanduser('~'))
    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)
        dir_dialog = dialog.findChild(QTreeView)
        dir_dialog.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
    return dialog

But here, just the problem is that dialog.selectedFiles() will not return the directories so, need to figure out a way to make it happen somehow.

SAMAD101 avatar Dec 14 '23 18:12 SAMAD101

Made a PR, not complete yet, now you can select multiple directories but none of them get added to the sources if selected multiple. If you select only one, that will do. So, it's halfway there.

SAMAD101 avatar Dec 14 '23 19:12 SAMAD101

Is this really a limitation of Qt or are we using QFileDialog incorrectly?

Its is a limitation. Though alternatively, we can use QTreeView with QAbstractItemView.SelectionMode.MultiSelection selection mode.

I think QFileDialog is better suited for single file/dir selection such as save dialog, than is the case here. Even if the manual says it's for single and multi.

I agree with the use of a treeview way as stated. Its more efficient and user friendly IMHO. I've worked with such a GUI in KDE's integrated kup-backup solution and it was very good.

Example for treeview:
kup_treeview

The checkboxes are great for this i think. If you guys want to take a look at the code they use... warning, its in C++ / QT). This should be the right func for this:filedigger.cpp#L122

Greets

madeddy avatar Jan 16 '24 15:01 madeddy

Is it still open? Can I work on this? I have worked on qt5 before, I think i can fix this. Can you assign it to me?

rajb957 avatar Jan 31 '24 11:01 rajb957

Is it still open? Can I work on this? I have worked on qt5 before, I think i can fix this. Can you assign it to me?

I'm still looking into it, but you can surely help

SAMAD101 avatar Jan 31 '24 17:01 SAMAD101

Is it still open? Can I work on this? I have worked on qt5 before, I think i can fix this. Can you assign it to me?

Whoever provides a mergeable PR first will be merged. However you can also choose to tackle another issue as there are plenty floating around.

real-yfprojects avatar Feb 09 '24 12:02 real-yfprojects

I've analyzed the issue and concluded that it can be effectively resolved by using a custom QFileDialog. Most native file dialogs do not support selecting multiple directories due to inherent limitations in their standard interfaces. However, a custom file dialog can overcome this problem.

By enabling the DontUseNativeDialog option, QFileDialog switches from using the operating system's native dialog to a Qt-implemented dialog. This custom dialog is consistent across all platforms and can be extensively customized. Importantly, it supports features not available in native dialogs, such as the ability to select multiple directories at once. This functionality is essential for our use case but is typically unsupported by the default file dialogs on most operating systems.

Should I proceed with implementing this solution? It would involve using a custom QFileDialog to open when the user needs to select multiple folders, allowing for the selection of multiple directories in a single action.

rajb957 avatar Feb 14 '24 13:02 rajb957

It would involve using a custom QFileDialog

You mean custom in the sense of not being native, although provided by the framework? In that case this seems to be a good solution. If this would mean implementing a file dialog in Vorta's code base, I would oppose the idea.

real-yfprojects avatar Feb 14 '24 18:02 real-yfprojects

Yes i mean custom in sense of not being native, but provided by the framework. It would uniformize the FileDialog across all operating systems and the FileDialog set by the user's file manager will not be used.

rajb957 avatar Feb 14 '24 18:02 rajb957

I have made a pull request and allowed multiselecting directories at other places as well including archives and choosing borg backup directory at places where only one directory needs to be selected if multiple directories are selected the first directory selected will be taken

rajb957 avatar Feb 14 '24 20:02 rajb957

Hello, I've made some updates to the pull request. I believe the changes are ready for review and merging. Could you please take a look and let me know if there are any further changes needed or if it's ready for merging? Thanks!

rajb957 avatar Feb 15 '24 18:02 rajb957

Hi there, I've just noticed there might be one trailing whitespace that I forgot to remove. However, aside from that, all test cases pass on my local machine. I'm a bit puzzled by the font-related test case failure. Could you please take a look at the latest changes and help identify the issue with the font test case? Your insights would be greatly appreciated. Thanks in advance for your assistance!

rajb957 avatar Feb 16 '24 13:02 rajb957

Hi @real-yfprojects, If this issue is still open, I would like to work on it. Can you assign it to me?

hasrat17 avatar Feb 25 '24 14:02 hasrat17

We already have 2 PRs for this. Would be good to take the best of each and just merge something

https://github.com/borgbase/vorta/pulls?q=is%3Apr+is%3Aopen+multiselect+OR+multiselection

m3nu avatar Feb 25 '24 15:02 m3nu