From 25850aadeb969691cde82bcb12aa0fbe90ed2c74 Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Mon, 9 Aug 2021 23:40:25 +1000 Subject: [PATCH] Use Flatpak portal for file dialogs --- platform/platformtheme.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/platform/platformtheme.cpp b/platform/platformtheme.cpp index 3eec9a8c..081cfefb 100644 --- a/platform/platformtheme.cpp +++ b/platform/platformtheme.cpp @@ -19,6 +19,11 @@ * *************************************/ #include "platformtheme.h" +#include +#include +#include +#include + #include #include #include @@ -31,7 +36,7 @@ #include #include #include -#include +#include #include #include "iconloaderengine.h" #include "cursorhandler.h" @@ -50,6 +55,8 @@ struct PlatformThemePrivate { QMimeDatabase mimeDb; QMap fonts; + + QPlatformTheme* flatpakPlatformTheme = nullptr; }; PlatformTheme::PlatformTheme() : QPlatformTheme() { @@ -100,6 +107,14 @@ PlatformTheme::PlatformTheme() : QPlatformTheme() { this->updateFont(); this->updatePalette(); + + tDebug("PlatformTheme") << "Using theDesk platform theme"; + + //Initialise the Flatpak platform theme so that we can use the portal to open files + d->flatpakPlatformTheme = QPlatformThemeFactory::create("flatpak", nullptr); + if (d->flatpakPlatformTheme) { + tDebug("PlatformTheme") << "Created Flatpak platform theme"; + } } PlatformTheme::~PlatformTheme() { @@ -126,12 +141,14 @@ void PlatformTheme::showPlatformMenuBar() { bool PlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const { switch (type) { - case QPlatformTheme::FileDialog: case QPlatformTheme::ColorDialog: case QPlatformTheme::FontDialog: return false; case QPlatformTheme::MessageDialog: return true; + case QPlatformTheme::FileDialog: + if (d->flatpakPlatformTheme) return d->flatpakPlatformTheme->usePlatformNativeDialog(type); + return false; } } @@ -140,6 +157,8 @@ QPlatformDialogHelper* PlatformTheme::createPlatformDialogHelper(QPlatformTheme: case QPlatformTheme::MessageDialog: return new MessageDialogHelper(); case QPlatformTheme::FileDialog: + if (d->flatpakPlatformTheme && d->flatpakPlatformTheme->usePlatformNativeDialog(type)) return d->flatpakPlatformTheme->createPlatformDialogHelper(type); + return QPlatformTheme::createPlatformDialogHelper(type); case QPlatformTheme::ColorDialog: case QPlatformTheme::FontDialog: return QPlatformTheme::createPlatformDialogHelper(type);