Use XDG Desktop Portal for file dialog

This commit is contained in:
Ilya Fedin 2020-01-29 21:41:42 +04:00 committed by John Preston
parent d80b3fda7d
commit 0477bda929
4 changed files with 31 additions and 4 deletions

View File

@ -21,9 +21,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
#include <private/qguiapplication_p.h>
#endif // TDESKTOP_DISABLE_GTK_INTEGRATION
QStringList qt_make_filter_list(const QString &filter);
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
namespace Platform {
namespace File {
@ -87,7 +87,8 @@ bool NativeSupported() {
#ifndef TDESKTOP_FORCE_GTK_FILE_DIALOG
return false;
#endif // TDESKTOP_FORCE_GTK_FILE_DIALOG
return Platform::internal::GdkHelperLoaded()
return !Platform::IsXDGDesktopPortalPresent()
&& Platform::internal::GdkHelperLoaded()
&& (Libs::gtk_widget_hide_on_delete != nullptr)
&& (Libs::gtk_clipboard_store != nullptr)
&& (Libs::gtk_clipboard_get != nullptr)

View File

@ -44,6 +44,8 @@ namespace {
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
bool XDGDesktopPortalIsPresent = false;
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
void SandboxAutostart(bool autostart) {
QVariantMap options;
@ -193,6 +195,10 @@ bool InSnap() {
return Snap;
}
bool IsXDGDesktopPortalPresent() {
return XDGDesktopPortalIsPresent;
};
QString CurrentExecutablePath(int argc, char *argv[]) {
constexpr auto kMaxPath = 1024;
char result[kMaxPath] = { 0 };
@ -372,6 +378,21 @@ namespace Platform {
void start() {
FallbackFontConfig();
#if !defined(TDESKTOP_DISABLE_DBUS_INTEGRATION) && defined(TDESKTOP_FORCE_GTK_FILE_DIALOG)
LOG(("Checking for XDG Desktop Portal..."));
XDGDesktopPortalIsPresent = QDBusInterface(
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop").isValid();
// this can give us a chance to use a proper file dialog for current session
if(XDGDesktopPortalIsPresent) {
LOG(("XDG Desktop Portal is present!"));
qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal");
} else {
LOG(("XDG Desktop Portal is not present :("));
}
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION && TDESKTOP_FORCE_GTK_FILE_DIALOG
}
void finish() {

View File

@ -23,6 +23,8 @@ inline void SetWatchingMediaKeys(bool watching) {
bool InSandbox();
bool InSnap();
bool IsXDGDesktopPortalPresent();
QString CurrentExecutablePath(int argc, char *argv[]);
QString SingleInstanceLocalServerName(const QString &hash);

View File

@ -21,12 +21,15 @@ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
Q_IMPORT_PLUGIN(QGenericEnginePlugin)
#elif defined Q_OS_LINUX // Q_OS_WIN | Q_OS_MAC
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
Q_IMPORT_PLUGIN(QConnmanEnginePlugin)
Q_IMPORT_PLUGIN(QGenericEnginePlugin)
Q_IMPORT_PLUGIN(QNetworkManagerEnginePlugin)
Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin)
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
Q_IMPORT_PLUGIN(QConnmanEnginePlugin)
Q_IMPORT_PLUGIN(QNetworkManagerEnginePlugin)
Q_IMPORT_PLUGIN(QIbusPlatformInputContextPlugin)
Q_IMPORT_PLUGIN(QFcitxPlatformInputContextPlugin)
Q_IMPORT_PLUGIN(QHimePlatformInputContextPlugin)
Q_IMPORT_PLUGIN(NimfInputContextPlugin)
Q_IMPORT_PLUGIN(QXdgDesktopPortalThemePlugin)
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
#endif // Q_OS_WIN | Q_OS_MAC | Q_OS_LINUX