Use XDG Desktop Portal only when variable is set

This commit is contained in:
Ilya Fedin 2020-02-19 18:44:26 +04:00 committed by John Preston
parent bbc516cf43
commit ca1623f34a
3 changed files with 24 additions and 11 deletions

View File

@ -87,7 +87,7 @@ bool NativeSupported() {
#ifndef TDESKTOP_FORCE_GTK_FILE_DIALOG #ifndef TDESKTOP_FORCE_GTK_FILE_DIALOG
return false; return false;
#endif // TDESKTOP_FORCE_GTK_FILE_DIALOG #endif // TDESKTOP_FORCE_GTK_FILE_DIALOG
return !Platform::IsXDGDesktopPortalPresent() return !Platform::UseXDGDesktopPortal()
&& Platform::internal::GdkHelperLoaded() && Platform::internal::GdkHelperLoaded()
&& (Libs::gtk_widget_hide_on_delete != nullptr) && (Libs::gtk_widget_hide_on_delete != nullptr)
&& (Libs::gtk_clipboard_store != nullptr) && (Libs::gtk_clipboard_store != nullptr)

View File

@ -45,8 +45,6 @@ namespace {
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs; constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
constexpr auto kSnapLauncherDir = "/var/lib/snapd/desktop/applications/"_cs; constexpr auto kSnapLauncherDir = "/var/lib/snapd/desktop/applications/"_cs;
bool XDGDesktopPortalPresent = false;
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
void SandboxAutostart(bool autostart) { void SandboxAutostart(bool autostart) {
QVariantMap options; QVariantMap options;
@ -203,9 +201,22 @@ bool InSnap() {
} }
bool IsXDGDesktopPortalPresent() { bool IsXDGDesktopPortalPresent() {
#ifdef TDESKTOP_DISABLE_DBUS_INTEGRATION
static const auto XDGDesktopPortalPresent = false;
#else // TDESKTOP_DISABLE_DBUS_INTEGRATION
static const auto XDGDesktopPortalPresent = QDBusInterface(
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop").isValid();
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
return XDGDesktopPortalPresent; return XDGDesktopPortalPresent;
} }
bool UseXDGDesktopPortal() {
static const auto UsePortal = qEnvironmentVariableIsSet("TDESKTOP_USE_PORTAL")
&& IsXDGDesktopPortalPresent();
return UsePortal;
}
QString ProcessNameByPID(const QString &pid) { QString ProcessNameByPID(const QString &pid) {
constexpr auto kMaxPath = 1024; constexpr auto kMaxPath = 1024;
char result[kMaxPath] = { 0 }; char result[kMaxPath] = { 0 };
@ -414,20 +425,21 @@ namespace Platform {
void start() { void start() {
FallbackFontConfig(); FallbackFontConfig();
#if !defined(TDESKTOP_DISABLE_DBUS_INTEGRATION) && defined(TDESKTOP_FORCE_GTK_FILE_DIALOG) #ifdef TDESKTOP_FORCE_GTK_FILE_DIALOG
LOG(("Checking for XDG Desktop Portal...")); LOG(("Checking for XDG Desktop Portal..."));
XDGDesktopPortalPresent = 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 // this can give us a chance to use a proper file dialog for current session
if(XDGDesktopPortalPresent) { if(IsXDGDesktopPortalPresent()) {
LOG(("XDG Desktop Portal is present!")); LOG(("XDG Desktop Portal is present!"));
qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal"); if(UseXDGDesktopPortal()) {
LOG(("Usage of XDG Desktop Portal is enabled."));
qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal");
} else {
LOG(("Usage of XDG Desktop Portal is disabled."));
}
} else { } else {
LOG(("XDG Desktop Portal is not present :(")); LOG(("XDG Desktop Portal is not present :("));
} }
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION && TDESKTOP_FORCE_GTK_FILE_DIALOG #endif // TDESKTOP_FORCE_GTK_FILE_DIALOG
} }
void finish() { void finish() {

View File

@ -24,6 +24,7 @@ bool InSandbox();
bool InSnap(); bool InSnap();
bool IsXDGDesktopPortalPresent(); bool IsXDGDesktopPortalPresent();
bool UseXDGDesktopPortal();
QString ProcessNameByPID(const QString &pid); QString ProcessNameByPID(const QString &pid);
QString CurrentExecutablePath(int argc, char *argv[]); QString CurrentExecutablePath(int argc, char *argv[]);