Adapt to lib_base's XDP API changes
This commit is contained in:
		
							parent
							
								
									80f1f079f1
								
							
						
					
					
						commit
						62e82a42fb
					
				
					 4 changed files with 28 additions and 73 deletions
				
			
		| 
						 | 
				
			
			@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include "platform/platform_file_utilities.h"
 | 
			
		||||
#include "base/platform/base_platform_info.h"
 | 
			
		||||
#include "base/platform/linux/base_linux_glibmm_helper.h"
 | 
			
		||||
#include "base/platform/linux/base_linux_wayland_integration.h"
 | 
			
		||||
#include "base/platform/linux/base_linux_xdp_utilities.h"
 | 
			
		||||
#include "storage/localstorage.h"
 | 
			
		||||
#include "base/random.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -20,8 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include <glibmm.h>
 | 
			
		||||
#include <giomm.h>
 | 
			
		||||
 | 
			
		||||
using base::Platform::WaylandIntegration;
 | 
			
		||||
 | 
			
		||||
namespace Platform {
 | 
			
		||||
namespace FileDialog {
 | 
			
		||||
namespace XDP {
 | 
			
		||||
| 
						 | 
				
			
			@ -29,9 +27,7 @@ namespace {
 | 
			
		|||
 | 
			
		||||
using Type = ::FileDialog::internal::Type;
 | 
			
		||||
 | 
			
		||||
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
 | 
			
		||||
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
 | 
			
		||||
constexpr auto kXDGDesktopPortalFileChooserInterface = "org.freedesktop.portal.FileChooser"_cs;
 | 
			
		||||
constexpr auto kXDPFileChooserInterface = "org.freedesktop.portal.FileChooser"_cs;
 | 
			
		||||
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
 | 
			
		||||
 | 
			
		||||
const char *filterRegExp =
 | 
			
		||||
| 
						 | 
				
			
			@ -90,12 +86,12 @@ void ComputeFileChooserPortalVersion() {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	connection->call(
 | 
			
		||||
		std::string(kXDGDesktopPortalObjectPath),
 | 
			
		||||
		std::string(base::Platform::XDP::kObjectPath),
 | 
			
		||||
		std::string(kPropertiesInterface),
 | 
			
		||||
		"Get",
 | 
			
		||||
		base::Platform::MakeGlibVariant(std::tuple{
 | 
			
		||||
			Glib::ustring(
 | 
			
		||||
				std::string(kXDGDesktopPortalFileChooserInterface)),
 | 
			
		||||
				std::string(kXDPFileChooserInterface)),
 | 
			
		||||
			Glib::ustring("version"),
 | 
			
		||||
		}),
 | 
			
		||||
		[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
 | 
			
		||||
| 
						 | 
				
			
			@ -123,7 +119,7 @@ void ComputeFileChooserPortalVersion() {
 | 
			
		|||
					QString::fromStdString(e.what())));
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		std::string(kXDGDesktopPortalService));
 | 
			
		||||
		std::string(base::Platform::XDP::kService));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is a patched copy of file dialog from qxdgdesktopportal theme plugin.
 | 
			
		||||
| 
						 | 
				
			
			@ -262,17 +258,6 @@ XDPFileDialog::~XDPFileDialog() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void XDPFileDialog::openPortal() {
 | 
			
		||||
	std::stringstream parentWindowId;
 | 
			
		||||
 | 
			
		||||
	if (const auto integration = WaylandIntegration::Instance()) {
 | 
			
		||||
		if (const auto handle = integration->nativeHandle(_parent)
 | 
			
		||||
			; !handle.isEmpty()) {
 | 
			
		||||
			parentWindowId << "wayland:" << handle.toStdString();
 | 
			
		||||
		}
 | 
			
		||||
	} else if (IsX11() && _parent) {
 | 
			
		||||
		parentWindowId << "x11:" << std::hex << _parent->winId();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::map<Glib::ustring, Glib::VariantBase> options;
 | 
			
		||||
	if (!_acceptLabel.empty()) {
 | 
			
		||||
		options["accept_label"] = Glib::Variant<Glib::ustring>::create(
 | 
			
		||||
| 
						 | 
				
			
			@ -448,13 +433,13 @@ void XDPFileDialog::openPortal() {
 | 
			
		|||
			requestPath);
 | 
			
		||||
 | 
			
		||||
		_dbusConnection->call(
 | 
			
		||||
			std::string(kXDGDesktopPortalObjectPath),
 | 
			
		||||
			std::string(kXDGDesktopPortalFileChooserInterface),
 | 
			
		||||
			std::string(base::Platform::XDP::kObjectPath),
 | 
			
		||||
			std::string(kXDPFileChooserInterface),
 | 
			
		||||
			_acceptMode == QFileDialog::AcceptSave
 | 
			
		||||
				? "SaveFile"
 | 
			
		||||
				: "OpenFile",
 | 
			
		||||
			base::Platform::MakeGlibVariant(std::tuple{
 | 
			
		||||
				Glib::ustring(parentWindowId.str()),
 | 
			
		||||
				base::Platform::XDP::ParentWindowID(_parent),
 | 
			
		||||
				_windowTitle,
 | 
			
		||||
				options,
 | 
			
		||||
			}),
 | 
			
		||||
| 
						 | 
				
			
			@ -503,7 +488,7 @@ void XDPFileDialog::openPortal() {
 | 
			
		|||
					});
 | 
			
		||||
				}
 | 
			
		||||
			}),
 | 
			
		||||
			std::string(kXDGDesktopPortalService));
 | 
			
		||||
			std::string(base::Platform::XDP::kService));
 | 
			
		||||
	} catch (...) {
 | 
			
		||||
		_failedToOpen = true;
 | 
			
		||||
		_reject.fire({});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
 | 
			
		||||
#include "base/platform/base_platform_info.h"
 | 
			
		||||
#include "base/platform/linux/base_linux_glibmm_helper.h"
 | 
			
		||||
#include "base/platform/linux/base_linux_wayland_integration.h"
 | 
			
		||||
#include "base/platform/linux/base_linux_xdp_utilities.h"
 | 
			
		||||
#include "core/application.h"
 | 
			
		||||
#include "window/window_controller.h"
 | 
			
		||||
#include "base/random.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -21,16 +21,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include <giomm.h>
 | 
			
		||||
#include <private/qguiapplication_p.h>
 | 
			
		||||
 | 
			
		||||
using base::Platform::WaylandIntegration;
 | 
			
		||||
 | 
			
		||||
namespace Platform {
 | 
			
		||||
namespace File {
 | 
			
		||||
namespace internal {
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
 | 
			
		||||
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
 | 
			
		||||
constexpr auto kXDGDesktopPortalOpenURIInterface = "org.freedesktop.portal.OpenURI"_cs;
 | 
			
		||||
constexpr auto kXDPOpenURIInterface = "org.freedesktop.portal.OpenURI"_cs;
 | 
			
		||||
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
 | 
			
		||||
 | 
			
		||||
} // namespace
 | 
			
		||||
| 
						 | 
				
			
			@ -41,15 +37,15 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
 | 
			
		|||
			Gio::DBus::BusType::BUS_TYPE_SESSION);
 | 
			
		||||
 | 
			
		||||
		auto reply = connection->call_sync(
 | 
			
		||||
			std::string(kXDGDesktopPortalObjectPath),
 | 
			
		||||
			std::string(base::Platform::XDP::kObjectPath),
 | 
			
		||||
			std::string(kPropertiesInterface),
 | 
			
		||||
			"Get",
 | 
			
		||||
			base::Platform::MakeGlibVariant(std::tuple{
 | 
			
		||||
				Glib::ustring(
 | 
			
		||||
					std::string(kXDGDesktopPortalOpenURIInterface)),
 | 
			
		||||
					std::string(kXDPOpenURIInterface)),
 | 
			
		||||
				Glib::ustring("version"),
 | 
			
		||||
			}),
 | 
			
		||||
			std::string(kXDGDesktopPortalService));
 | 
			
		||||
			std::string(base::Platform::XDP::kService));
 | 
			
		||||
 | 
			
		||||
		const auto version = base::Platform::GlibVariantCast<uint>(
 | 
			
		||||
			base::Platform::GlibVariantCast<Glib::VariantBase>(
 | 
			
		||||
| 
						 | 
				
			
			@ -72,24 +68,13 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
 | 
			
		|||
		const auto fdGuard = gsl::finally([&] { ::close(fd); });
 | 
			
		||||
 | 
			
		||||
		const auto parentWindowId = [&]() -> Glib::ustring {
 | 
			
		||||
			std::stringstream result;
 | 
			
		||||
 | 
			
		||||
			const auto activeWindow = Core::App().activeWindow();
 | 
			
		||||
			if (!activeWindow) {
 | 
			
		||||
				return result.str();
 | 
			
		||||
				return {};
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			const auto window = activeWindow->widget()->windowHandle();
 | 
			
		||||
			if (const auto integration = WaylandIntegration::Instance()) {
 | 
			
		||||
				if (const auto handle = integration->nativeHandle(window)
 | 
			
		||||
					; !handle.isEmpty()) {
 | 
			
		||||
					result << "wayland:" << handle.toStdString();
 | 
			
		||||
				}
 | 
			
		||||
			} else if (IsX11()) {
 | 
			
		||||
				result << "x11:" << std::hex << window->winId();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return result.str();
 | 
			
		||||
			return base::Platform::XDP::ParentWindowID(
 | 
			
		||||
				activeWindow->widget()->windowHandle());
 | 
			
		||||
		}();
 | 
			
		||||
 | 
			
		||||
		const auto handleToken = Glib::ustring("tdesktop")
 | 
			
		||||
| 
						 | 
				
			
			@ -122,7 +107,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
 | 
			
		|||
				const Glib::VariantContainerBase ¶meters) {
 | 
			
		||||
				loop->quit();
 | 
			
		||||
			},
 | 
			
		||||
			std::string(kXDGDesktopPortalService),
 | 
			
		||||
			std::string(base::Platform::XDP::kService),
 | 
			
		||||
			"org.freedesktop.portal.Request",
 | 
			
		||||
			"Response",
 | 
			
		||||
			requestPath);
 | 
			
		||||
| 
						 | 
				
			
			@ -138,8 +123,8 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
 | 
			
		|||
		auto outFdList = Glib::RefPtr<Gio::UnixFDList>();
 | 
			
		||||
 | 
			
		||||
		connection->call_sync(
 | 
			
		||||
			std::string(kXDGDesktopPortalObjectPath),
 | 
			
		||||
			std::string(kXDGDesktopPortalOpenURIInterface),
 | 
			
		||||
			std::string(base::Platform::XDP::kObjectPath),
 | 
			
		||||
			std::string(kXDPOpenURIInterface),
 | 
			
		||||
			"OpenFile",
 | 
			
		||||
			Glib::VariantContainerBase::create_tuple({
 | 
			
		||||
				Glib::Variant<Glib::ustring>::create(parentWindowId),
 | 
			
		||||
| 
						 | 
				
			
			@ -160,7 +145,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
 | 
			
		|||
			}),
 | 
			
		||||
			fdList,
 | 
			
		||||
			outFdList,
 | 
			
		||||
			std::string(kXDGDesktopPortalService));
 | 
			
		||||
			std::string(base::Platform::XDP::kService));
 | 
			
		||||
 | 
			
		||||
		if (signalId != 0) {
 | 
			
		||||
			QWindow window;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
 | 
			
		||||
#include "base/random.h"
 | 
			
		||||
#include "base/platform/base_platform_info.h"
 | 
			
		||||
#include "base/platform/linux/base_linux_wayland_integration.h"
 | 
			
		||||
#include "platform/linux/linux_desktop_environment.h"
 | 
			
		||||
#include "platform/linux/linux_wayland_integration.h"
 | 
			
		||||
#include "lang/lang_keys.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +55,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
using namespace Platform;
 | 
			
		||||
using BaseWaylandIntegration = base::Platform::WaylandIntegration;
 | 
			
		||||
using Platform::internal::WaylandIntegration;
 | 
			
		||||
 | 
			
		||||
namespace Platform {
 | 
			
		||||
| 
						 | 
				
			
			@ -65,8 +63,6 @@ namespace {
 | 
			
		|||
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
 | 
			
		||||
constexpr auto kIconName = "telegram"_cs;
 | 
			
		||||
 | 
			
		||||
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
 | 
			
		||||
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
 | 
			
		||||
constexpr auto kIBusPortalService = "org.freedesktop.portal.IBus"_cs;
 | 
			
		||||
constexpr auto kWebviewService = "org.telegram.desktop.GtkIntegration.WebviewHelper-%1-%2"_cs;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -81,24 +77,13 @@ void PortalAutostart(bool start, bool silent) {
 | 
			
		|||
			Gio::DBus::BusType::BUS_TYPE_SESSION);
 | 
			
		||||
 | 
			
		||||
		const auto parentWindowId = [&]() -> Glib::ustring {
 | 
			
		||||
			std::stringstream result;
 | 
			
		||||
 | 
			
		||||
			const auto activeWindow = Core::App().activeWindow();
 | 
			
		||||
			if (!activeWindow) {
 | 
			
		||||
				return result.str();
 | 
			
		||||
				return {};
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			const auto window = activeWindow->widget()->windowHandle();
 | 
			
		||||
			if (const auto integration = BaseWaylandIntegration::Instance()) {
 | 
			
		||||
				if (const auto handle = integration->nativeHandle(window)
 | 
			
		||||
					; !handle.isEmpty()) {
 | 
			
		||||
					result << "wayland:" << handle.toStdString();
 | 
			
		||||
				}
 | 
			
		||||
			} else if (IsX11()) {
 | 
			
		||||
				result << "x11:" << std::hex << window->winId();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return result.str();
 | 
			
		||||
			return base::Platform::XDP::ParentWindowID(
 | 
			
		||||
				activeWindow->widget()->windowHandle());
 | 
			
		||||
		}();
 | 
			
		||||
 | 
			
		||||
		const auto handleToken = Glib::ustring("tdesktop")
 | 
			
		||||
| 
						 | 
				
			
			@ -163,7 +148,7 @@ void PortalAutostart(bool start, bool silent) {
 | 
			
		|||
 | 
			
		||||
				loop->quit();
 | 
			
		||||
			},
 | 
			
		||||
			std::string(kXDGDesktopPortalService),
 | 
			
		||||
			std::string(base::Platform::XDP::kService),
 | 
			
		||||
			"org.freedesktop.portal.Request",
 | 
			
		||||
			"Response",
 | 
			
		||||
			requestPath);
 | 
			
		||||
| 
						 | 
				
			
			@ -175,14 +160,14 @@ void PortalAutostart(bool start, bool silent) {
 | 
			
		|||
		});
 | 
			
		||||
 | 
			
		||||
		connection->call_sync(
 | 
			
		||||
			std::string(kXDGDesktopPortalObjectPath),
 | 
			
		||||
			std::string(base::Platform::XDP::kObjectPath),
 | 
			
		||||
			"org.freedesktop.portal.Background",
 | 
			
		||||
			"RequestBackground",
 | 
			
		||||
			base::Platform::MakeGlibVariant(std::tuple{
 | 
			
		||||
				parentWindowId,
 | 
			
		||||
				options,
 | 
			
		||||
			}),
 | 
			
		||||
			std::string(kXDGDesktopPortalService));
 | 
			
		||||
			std::string(base::Platform::XDP::kService));
 | 
			
		||||
 | 
			
		||||
		if (signalId != 0) {
 | 
			
		||||
			QWindow window;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
Subproject commit a23ec1340b65c37f551a9f0870897f0a8f9e5503
 | 
			
		||||
Subproject commit 5ab3cdaef587b8ac8fdf1a96879961fd57ac7ace
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue