From 3d994b58a08c1b26dd845dbdba480a65dcd16b82 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 21 Apr 2024 01:20:59 +0400 Subject: [PATCH] ShowXDPOpenWithDialog -> UnsafeShowOpenWith --- Telegram/CMakeLists.txt | 2 - .../platform/linux/file_utilities_linux.cpp | 119 ++++++++++++++++ .../platform/linux/file_utilities_linux.h | 6 - .../linux/linux_xdp_open_with_dialog.cpp | 129 ------------------ .../linux/linux_xdp_open_with_dialog.h | 18 --- 5 files changed, 119 insertions(+), 155 deletions(-) delete mode 100644 Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp delete mode 100644 Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index c99cd34b5..d0ea8561d 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1202,8 +1202,6 @@ PRIVATE platform/linux/linux_wayland_integration_dummy.cpp platform/linux/linux_wayland_integration.cpp platform/linux/linux_wayland_integration.h - platform/linux/linux_xdp_open_with_dialog.cpp - platform/linux/linux_xdp_open_with_dialog.h platform/linux/file_utilities_linux.cpp platform/linux/file_utilities_linux.h platform/linux/launcher_linux.cpp diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp index 2f9c0d9f9..d79e4778e 100644 --- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp @@ -6,3 +6,122 @@ For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "platform/linux/file_utilities_linux.h" + +#include "base/platform/base_platform_info.h" +#include "base/platform/linux/base_linux_xdp_utilities.h" +#include "base/platform/linux/base_linux_xdg_activation_token.h" +#include "base/random.h" + +#include +#include +#include + +namespace Platform { +namespace File { +namespace { + +using namespace gi::repository; +using base::Platform::XdgActivationToken; + +} // namespace + +bool UnsafeShowOpenWith(const QString &filepath) { + auto proxy = XdpOpenURI::OpenURIProxy::new_for_bus_sync( + Gio::BusType::SESSION_, + Gio::DBusProxyFlags::NONE_, + base::Platform::XDP::kService, + base::Platform::XDP::kObjectPath, + nullptr); + + if (!proxy) { + return false; + } + + auto interface = XdpOpenURI::OpenURI(proxy); + if (interface.get_version() < 3) { + return false; + } + + const auto fd = open( + QFile::encodeName(filepath).constData(), + O_RDONLY); + + if (fd == -1) { + return false; + } + + const auto fdGuard = gsl::finally([&] { close(fd); }); + + const auto handleToken = "tdesktop" + + std::to_string(base::RandomValue()); + + std::string uniqueName = proxy.get_connection().get_unique_name(); + uniqueName.erase(0, 1); + uniqueName.replace(uniqueName.find('.'), 1, 1, '_'); + + auto request = XdpRequest::Request( + XdpRequest::RequestProxy::new_sync( + proxy.get_connection(), + Gio::DBusProxyFlags::NONE_, + base::Platform::XDP::kService, + base::Platform::XDP::kObjectPath + + std::string("/request/") + + uniqueName + + '/' + + handleToken, + nullptr, + nullptr)); + + if (!request) { + return false; + } + + auto loop = GLib::MainLoop::new_(); + + const auto signalId = request.signal_response().connect([=]( + XdpRequest::Request, + guint, + GLib::Variant) mutable { + loop.quit(); + }); + + const auto signalGuard = gsl::finally([&] { + request.disconnect(signalId); + }); + + auto result = interface.call_open_file_sync( + base::Platform::XDP::ParentWindowID(), + GLib::Variant::new_handle(0), + GLib::Variant::new_array({ + GLib::Variant::new_dict_entry( + GLib::Variant::new_string("handle_token"), + GLib::Variant::new_variant( + GLib::Variant::new_string(handleToken))), + GLib::Variant::new_dict_entry( + GLib::Variant::new_string("activation_token"), + GLib::Variant::new_variant( + GLib::Variant::new_string( + XdgActivationToken().toStdString()))), + GLib::Variant::new_dict_entry( + GLib::Variant::new_string("ask"), + GLib::Variant::new_variant( + GLib::Variant::new_boolean(true))), + }), + Gio::UnixFDList::new_from_array((std::array{ fd }).data(), 1), + nullptr); + + if (!result) { + return false; + } + + QWidget window; + window.setAttribute(Qt::WA_DontShowOnScreen); + window.setWindowModality(Qt::ApplicationModal); + window.show(); + loop.run(); + + return true; +} + +} // namespace File +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.h b/Telegram/SourceFiles/platform/linux/file_utilities_linux.h index baced1178..2054d3f32 100644 --- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.h +++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.h @@ -9,8 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_file_utilities.h" -#include "platform/linux/linux_xdp_open_with_dialog.h" - namespace Platform { namespace File { @@ -30,10 +28,6 @@ inline bool UnsafeShowOpenWithDropdown(const QString &filepath) { return false; } -inline bool UnsafeShowOpenWith(const QString &filepath) { - return internal::ShowXDPOpenWithDialog(filepath); -} - inline void UnsafeLaunch(const QString &filepath) { return ::File::internal::UnsafeLaunchDefault(filepath); } diff --git a/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp b/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp deleted file mode 100644 index 9e409b900..000000000 --- a/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "platform/linux/linux_xdp_open_with_dialog.h" - -#include "base/platform/base_platform_info.h" -#include "base/platform/linux/base_linux_xdp_utilities.h" -#include "base/platform/linux/base_linux_xdg_activation_token.h" -#include "base/random.h" - -#include -#include -#include - -namespace Platform { -namespace File { -namespace internal { -namespace { - -using namespace gi::repository; -using base::Platform::XdgActivationToken; - -} // namespace - -bool ShowXDPOpenWithDialog(const QString &filepath) { - auto proxy = XdpOpenURI::OpenURIProxy::new_for_bus_sync( - Gio::BusType::SESSION_, - Gio::DBusProxyFlags::NONE_, - base::Platform::XDP::kService, - base::Platform::XDP::kObjectPath, - nullptr); - - if (!proxy) { - return false; - } - - auto interface = XdpOpenURI::OpenURI(proxy); - if (interface.get_version() < 3) { - return false; - } - - const auto fd = open( - QFile::encodeName(filepath).constData(), - O_RDONLY); - - if (fd == -1) { - return false; - } - - const auto fdGuard = gsl::finally([&] { close(fd); }); - - const auto handleToken = "tdesktop" - + std::to_string(base::RandomValue()); - - std::string uniqueName = proxy.get_connection().get_unique_name(); - uniqueName.erase(0, 1); - uniqueName.replace(uniqueName.find('.'), 1, 1, '_'); - - auto request = XdpRequest::Request( - XdpRequest::RequestProxy::new_sync( - proxy.get_connection(), - Gio::DBusProxyFlags::NONE_, - base::Platform::XDP::kService, - base::Platform::XDP::kObjectPath - + std::string("/request/") - + uniqueName - + '/' - + handleToken, - nullptr, - nullptr)); - - if (!request) { - return false; - } - - auto loop = GLib::MainLoop::new_(); - - const auto signalId = request.signal_response().connect([=]( - XdpRequest::Request, - guint, - GLib::Variant) mutable { - loop.quit(); - }); - - const auto signalGuard = gsl::finally([&] { - request.disconnect(signalId); - }); - - auto result = interface.call_open_file_sync( - base::Platform::XDP::ParentWindowID(), - GLib::Variant::new_handle(0), - GLib::Variant::new_array({ - GLib::Variant::new_dict_entry( - GLib::Variant::new_string("handle_token"), - GLib::Variant::new_variant( - GLib::Variant::new_string(handleToken))), - GLib::Variant::new_dict_entry( - GLib::Variant::new_string("activation_token"), - GLib::Variant::new_variant( - GLib::Variant::new_string( - XdgActivationToken().toStdString()))), - GLib::Variant::new_dict_entry( - GLib::Variant::new_string("ask"), - GLib::Variant::new_variant( - GLib::Variant::new_boolean(true))), - }), - Gio::UnixFDList::new_from_array((std::array{ fd }).data(), 1), - nullptr); - - if (!result) { - return false; - } - - QWidget window; - window.setAttribute(Qt::WA_DontShowOnScreen); - window.setWindowModality(Qt::ApplicationModal); - window.show(); - loop.run(); - - return true; -} - -} // namespace internal -} // namespace File -} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.h b/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.h deleted file mode 100644 index a848baaf5..000000000 --- a/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.h +++ /dev/null @@ -1,18 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -namespace Platform { -namespace File { -namespace internal { - -bool ShowXDPOpenWithDialog(const QString &filepath); - -} // namespace internal -} // namespace File -} // namespace Platform