Commit 976d0c5f authored by Jan Grulich's avatar Jan Grulich

FileChooser portal: add support for opening directories

Summary: BUG: 419874

Test Plan: This is also implemented on Qt side and currently on review: https://codereview.qt-project.org/c/qt/qtbase/+/297872. Tested with xdg-portal-test-kde using mentioned Qt patch.

Reviewers: apol, #plasma

Reviewed By: apol

Subscribers: broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D29071
parent 53360eeb
......@@ -133,6 +133,7 @@ uint FileChooserPortal::OpenFile(const QDBusObjectPath &handle,
qCDebug(XdgDesktopPortalKdeFileChooser) << " title: " << title;
qCDebug(XdgDesktopPortalKdeFileChooser) << " options: " << options;
bool directory = false;
bool modalDialog = true;
bool multipleFiles = false;
QString acceptLabel;
......@@ -163,6 +164,10 @@ uint FileChooserPortal::OpenFile(const QDBusObjectPath &handle,
multipleFiles = options.value(QStringLiteral("multiple")).toBool();
}
if (options.contains(QStringLiteral("directory"))) {
directory = options.value(QStringLiteral("directory")).toBool();
}
if (options.contains(QStringLiteral("filters"))) {
FilterListList filterListList = qdbus_cast<FilterListList>(options.value(QStringLiteral("filters")));
for (const FilterList &filterList : filterListList) {
......@@ -185,7 +190,8 @@ uint FileChooserPortal::OpenFile(const QDBusObjectPath &handle,
Utils::setParentWindow(fileDialog.data(), parent_window);
fileDialog->setWindowTitle(title);
fileDialog->setModal(modalDialog);
fileDialog->m_fileWidget->setMode(multipleFiles ? KFile::Mode::Files | KFile::Mode::ExistingOnly : KFile::Mode::File | KFile::Mode::ExistingOnly);
KFile::Mode mode = directory ? KFile::Mode::Directory : multipleFiles ? KFile::Mode::Files : KFile::Mode::File;
fileDialog->m_fileWidget->setMode(mode | KFile::Mode::ExistingOnly);
fileDialog->m_fileWidget->okButton()->setText(!acceptLabel.isEmpty() ? acceptLabel : i18n("Open"));
if (!nameFilters.isEmpty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment