Use new glibmm 2.78 API

This commit is contained in:
Ilya Fedin 2023-05-20 18:20:10 +04:00 committed by John Preston
parent d7d493e0bf
commit f817df9d7f
8 changed files with 123 additions and 129 deletions

View File

@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/platform_integration.h"
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "base/platform/linux/base_linux_xdp_utilities.h"
#include "core/sandbox.h"
#include "core/application.h"
@ -125,7 +124,7 @@ LinuxIntegration::LinuxIntegration()
if (group == "org.freedesktop.appearance"
&& key == "color-scheme") {
try {
const auto ivalue = base::Platform::GlibVariantCast<uint>(value);
const auto ivalue = value.get_dynamic<uint>();
crl::on_main([=] {
Core::App().settings().setSystemDarkMode(ivalue == 1);
@ -266,8 +265,9 @@ void LinuxIntegration::LaunchNativeApplication() {
const auto notificationIdVariantType = [] {
try {
return base::Platform::MakeGlibVariant(
NotificationId().toTuple()).get_type();
return Glib::create_variant(
NotificationId().toTuple()
).get_type();
} catch (...) {
return Glib::VariantType();
}
@ -282,9 +282,9 @@ void LinuxIntegration::LaunchNativeApplication() {
const auto &app = Core::App();
app.notifications().manager().notificationActivated(
NotificationId::FromTuple(
base::Platform::GlibVariantCast<
NotificationIdTuple
>(parameter)));
parameter.get_dynamic<NotificationIdTuple>()
)
);
} catch (...) {
}
});
@ -299,10 +299,10 @@ void LinuxIntegration::LaunchNativeApplication() {
const auto &app = Core::App();
app.notifications().manager().notificationReplied(
NotificationId::FromTuple(
base::Platform::GlibVariantCast<
NotificationIdTuple
>(parameter)),
{});
parameter.get_dynamic<NotificationIdTuple>()
),
{}
);
} catch (...) {
}
});

View File

@ -8,7 +8,6 @@ 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_glibmm_helper.h"
#include "base/platform/linux/base_linux_xdp_utilities.h"
#include "base/platform/linux/base_linux_wayland_integration.h"
#include "core/application.h"
@ -34,20 +33,17 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
const auto connection = Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION);
auto reply = connection->call_sync(
const auto version = connection->call_sync(
std::string(base::Platform::XDP::kObjectPath),
std::string(kPropertiesInterface),
"Get",
base::Platform::MakeGlibVariant(std::tuple{
Glib::create_variant(std::tuple{
Glib::ustring(
std::string(kXDPOpenURIInterface)),
Glib::ustring("version"),
}),
std::string(base::Platform::XDP::kService));
const auto version = base::Platform::GlibVariantCast<uint>(
base::Platform::GlibVariantCast<Glib::VariantBase>(
reply.get_child(0)));
std::string(base::Platform::XDP::kService)
).get_child(0).get_dynamic<Glib::Variant<uint>>().get();
if (version < 3) {
return false;
@ -112,7 +108,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
loop->quit();
},
std::string(base::Platform::XDP::kService),
"org.freedesktop.portal.Request",
std::string(base::Platform::XDP::kRequestInterface),
"Response",
requestPath);
@ -128,26 +124,23 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
std::string(base::Platform::XDP::kObjectPath),
std::string(kXDPOpenURIInterface),
"OpenFile",
Glib::VariantContainerBase::create_tuple({
Glib::Variant<Glib::ustring>::create(parentWindowId),
Glib::Variant<int>::create_handle(0),
Glib::Variant<std::map<
Glib::ustring,
Glib::VariantBase
>>::create({
Glib::create_variant(std::tuple{
parentWindowId,
Glib::DBusHandle(),
std::map<Glib::ustring, Glib::VariantBase>{
{
"handle_token",
Glib::Variant<Glib::ustring>::create(handleToken)
Glib::create_variant(handleToken)
},
{
"activation_token",
Glib::Variant<Glib::ustring>::create(activationToken)
Glib::create_variant(activationToken)
},
{
"ask",
Glib::Variant<bool>::create(true)
Glib::create_variant(true)
},
}),
},
}),
Gio::UnixFDList::create(std::vector<int>{ fd }),
outFdList,

View File

@ -26,7 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "base/event_filter.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/input_fields.h"
@ -251,13 +250,11 @@ void MainWindow::updateUnityCounter() {
// According to the spec, it should be of 'x' D-Bus signature,
// which corresponds to signed 64-bit integer
// https://wiki.ubuntu.com/Unity/LauncherAPI#Low_level_DBus_API:_com.canonical.Unity.LauncherEntry
dbusUnityProperties["count"] = Glib::Variant<int64>::create(
counterSlice);
dbusUnityProperties["count-visible"] =
Glib::Variant<bool>::create(true);
dbusUnityProperties["count"] = Glib::create_variant(
int64(counterSlice));
dbusUnityProperties["count-visible"] = Glib::create_variant(true);
} else {
dbusUnityProperties["count-visible"] =
Glib::Variant<bool>::create(false);
dbusUnityProperties["count-visible"] = Glib::create_variant(false);
}
try {
@ -270,7 +267,7 @@ void MainWindow::updateUnityCounter() {
"com.canonical.Unity.LauncherEntry",
"Update",
{},
base::Platform::MakeGlibVariant(std::tuple{
Glib::create_variant(std::tuple{
launcherUrl,
dbusUnityProperties,
}));

View File

@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/options.h"
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "base/platform/linux/base_linux_dbus_utilities.h"
#include "core/application.h"
#include "core/sandbox.h"
@ -43,8 +42,6 @@ constexpr auto kObjectPath = "/org/freedesktop/Notifications"_cs;
constexpr auto kInterface = kService;
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
using namespace base::Platform;
struct ServerInformation {
QString name;
QString vendor;
@ -116,10 +113,10 @@ void StartServiceAsync(Fn<void()> callback) {
const auto connection = Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION);
DBus::StartServiceByNameAsync(
base::Platform::DBus::StartServiceByNameAsync(
connection,
std::string(kService),
[=](Fn<DBus::StartReply()> result) {
[=](Fn<base::Platform::DBus::StartReply()> result) {
Noexcept([&] {
try {
result(); // get the error if any
@ -156,7 +153,7 @@ bool GetServiceRegistered() {
const auto hasOwner = [&] {
try {
return DBus::NameHasOwner(
return base::Platform::DBus::NameHasOwner(
connection,
std::string(kService));
} catch (...) {
@ -167,7 +164,7 @@ bool GetServiceRegistered() {
static const auto activatable = [&] {
try {
return ranges::contains(
DBus::ListActivatableNames(connection),
base::Platform::DBus::ListActivatableNames(connection),
std::string(kService),
&Glib::ustring::raw);
} catch (...) {
@ -195,19 +192,23 @@ void GetServerInformation(
{},
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
Noexcept([&] {
auto reply = connection->call_finish(result);
const auto reply = connection->call_finish(result);
const auto name = GlibVariantCast<Glib::ustring>(
reply.get_child(0));
const auto name = reply.get_child(
0
).get_dynamic<Glib::ustring>();
const auto vendor = GlibVariantCast<Glib::ustring>(
reply.get_child(1));
const auto vendor = reply.get_child(
1
).get_dynamic<Glib::ustring>();
const auto version = GlibVariantCast<Glib::ustring>(
reply.get_child(2));
const auto version = reply.get_child(
2
).get_dynamic<Glib::ustring>();
const auto specVersion = GlibVariantCast<Glib::ustring>(
reply.get_child(3));
const auto specVersion = reply.get_child(
3
).get_dynamic<Glib::ustring>();
crl::on_main([=] {
callback(ServerInformation{
@ -241,18 +242,17 @@ void GetCapabilities(Fn<void(const QStringList &)> callback) {
{},
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
Noexcept([&] {
auto reply = connection->call_finish(result);
QStringList value;
ranges::transform(
GlibVariantCast<std::vector<Glib::ustring>>(
reply.get_child(0)),
connection->call_finish(
result
).get_child(
0
).get_dynamic<std::vector<Glib::ustring>>(),
ranges::back_inserter(value),
QString::fromStdString);
crl::on_main([=] {
callback(value);
});
crl::on_main([=] { callback(value); });
}, [&] {
crl::on_main([=] { callback({}); });
});
@ -272,21 +272,20 @@ void GetInhibited(Fn<void(bool)> callback) {
std::string(kObjectPath),
std::string(kPropertiesInterface),
"Get",
MakeGlibVariant(std::tuple{
Glib::create_variant(std::tuple{
Glib::ustring(std::string(kInterface)),
Glib::ustring("Inhibited"),
}),
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
Noexcept([&] {
auto reply = connection->call_finish(result);
const auto value = connection->call_finish(
result
).get_child(
0
).get_dynamic<Glib::Variant<bool>>(
).get();
const auto value = GlibVariantCast<bool>(
GlibVariantCast<Glib::VariantBase>(
reply.get_child(0)));
crl::on_main([=] {
callback(value);
});
crl::on_main([=] { callback(value); });
}, [&] {
crl::on_main([=] { callback(false); });
});
@ -470,38 +469,38 @@ bool NotificationData::init(
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &signal_name,
Glib::VariantContainerBase parameters) {
const Glib::VariantContainerBase &parameters) {
Noexcept([&] {
if (signal_name == "ActionInvoked") {
const auto id = GlibVariantCast<uint>(
parameters.get_child(0));
const auto id = parameters.get_child(0).get_dynamic<uint>();
const auto actionName = GlibVariantCast<Glib::ustring>(
parameters.get_child(1));
const auto actionName = parameters.get_child(
1
).get_dynamic<Glib::ustring>();
crl::on_main(weak, [=] { actionInvoked(id, actionName); });
} else if (signal_name == "ActivationToken") {
const auto id = GlibVariantCast<uint>(
parameters.get_child(0));
const auto id = parameters.get_child(0).get_dynamic<uint>();
const auto token = GlibVariantCast<Glib::ustring>(
parameters.get_child(1));
const auto token = parameters.get_child(
1
).get_dynamic<Glib::ustring>();
crl::on_main(weak, [=] { activationToken(id, token); });
} else if (signal_name == "NotificationReplied") {
const auto id = GlibVariantCast<uint>(
parameters.get_child(0));
const auto id = parameters.get_child(0).get_dynamic<uint>();
const auto text = GlibVariantCast<Glib::ustring>(
parameters.get_child(1));
const auto text = parameters.get_child(
1
).get_dynamic<Glib::ustring>();
crl::on_main(weak, [=] { notificationReplied(id, text); });
} else if (signal_name == "NotificationClosed") {
const auto id = GlibVariantCast<uint>(
parameters.get_child(0));
const auto id = parameters.get_child(0).get_dynamic<uint>();
const auto reason = GlibVariantCast<uint>(
parameters.get_child(1));
const auto reason = parameters.get_child(
1
).get_dynamic<uint>();
crl::on_main(weak, [=] { notificationClosed(id, reason); });
}
@ -568,30 +567,30 @@ bool NotificationData::init(
}
if (capabilities.contains("action-icons")) {
_hints["action-icons"] = Glib::Variant<bool>::create(true);
_hints["action-icons"] = Glib::create_variant(true);
}
// suppress system sound if telegram sound activated,
// otherwise use system sound
if (capabilities.contains("sound")) {
if (Core::App().settings().soundNotify()) {
_hints["suppress-sound"] = Glib::Variant<bool>::create(true);
_hints["suppress-sound"] = Glib::create_variant(true);
} else {
// sound name according to http://0pointer.de/public/sound-naming-spec.html
_hints["sound-name"] = Glib::Variant<Glib::ustring>::create(
"message-new-instant");
_hints["sound-name"] = Glib::create_variant(
Glib::ustring("message-new-instant"));
}
}
if (capabilities.contains("x-canonical-append")) {
_hints["x-canonical-append"] = Glib::Variant<Glib::ustring>::create(
"true");
_hints["x-canonical-append"] = Glib::create_variant(
Glib::ustring("true"));
}
_hints["category"] = Glib::Variant<Glib::ustring>::create("im.received");
_hints["category"] = Glib::create_variant(Glib::ustring("im.received"));
_hints["desktop-entry"] = Glib::Variant<Glib::ustring>::create(
QGuiApplication::desktopFileName().toStdString());
_hints["desktop-entry"] = Glib::create_variant(
Glib::ustring(QGuiApplication::desktopFileName().toStdString()));
_notificationClosedSignalId = _dbusConnection->signal_subscribe(
signalEmitted,
@ -647,7 +646,7 @@ void NotificationData::show() {
std::string(kObjectPath),
std::string(kInterface),
"Notify",
MakeGlibVariant(std::tuple{
Glib::create_variant(std::tuple{
Glib::ustring(std::string(AppName)),
uint(0),
iconName,
@ -659,9 +658,12 @@ void NotificationData::show() {
}),
[=](const Glib::RefPtr<Gio::AsyncResult> &result) {
Noexcept([&] {
auto reply = connection->call_finish(result);
const auto notificationId = GlibVariantCast<uint>(
reply.get_child(0));
const auto notificationId = connection->call_finish(
result
).get_child(
0
).get_dynamic<uint>();
crl::on_main(weak, [=] {
_notificationId = notificationId;
});
@ -691,7 +693,7 @@ void NotificationData::close() {
std::string(kObjectPath),
std::string(kInterface),
"CloseNotification",
MakeGlibVariant(std::tuple{
Glib::create_variant(std::tuple{
_notificationId,
}),
{},
@ -728,7 +730,7 @@ void NotificationData::setImage(const QImage &image) {
? image.convertToFormat(QImage::Format_RGBA8888)
: image.convertToFormat(QImage::Format_RGB888);
_hints[_imageKey] = MakeGlibVariant(std::tuple{
_hints[_imageKey] = Glib::create_variant(std::tuple{
convertedImage.width(),
convertedImage.height(),
int(convertedImage.bytesPerLine()),
@ -979,19 +981,22 @@ Manager::Private::Private(not_null<Manager*> manager)
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &signal_name,
Glib::VariantContainerBase parameters) {
const Glib::VariantContainerBase &parameters) {
Noexcept([&] {
const auto interface = GlibVariantCast<Glib::ustring>(
parameters.get_child(0));
const auto interface = parameters.get_child(
0
).get_dynamic<Glib::ustring>();
if (interface != kInterface.data()) {
return;
}
const auto inhibited = GlibVariantCast<bool>(
GlibVariantCast<
std::map<Glib::ustring, Glib::VariantBase>
>(parameters.get_child(1)).at("Inhibited"));
const auto inhibited = parameters.get_child(
1
).get_dynamic<std::map<Glib::ustring, Glib::VariantBase>>(
).at(
"Inhibited"
).get_dynamic<bool>();
crl::on_main(weak, [=] {
_inhibited = inhibited;

View File

@ -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_glibmm_helper.h"
#include "base/platform/linux/base_linux_dbus_utilities.h"
#include "base/platform/linux/base_linux_xdp_utilities.h"
#include "platform/linux/linux_desktop_environment.h"
@ -90,13 +89,13 @@ bool PortalAutostart(bool start, bool silent) {
commandline.push_back("-autostart");
std::map<Glib::ustring, Glib::VariantBase> options;
options["handle_token"] = Glib::Variant<Glib::ustring>::create(
handleToken);
options["reason"] = Glib::Variant<Glib::ustring>::create(
tr::lng_settings_auto_start(tr::now).toStdString());
options["autostart"] = Glib::Variant<bool>::create(start);
options["commandline"] = base::Platform::MakeGlibVariant(commandline);
options["dbus-activatable"] = Glib::Variant<bool>::create(false);
options["handle_token"] = Glib::create_variant(handleToken);
options["reason"] = Glib::create_variant(
Glib::ustring(
tr::lng_settings_auto_start(tr::now).toStdString()));
options["autostart"] = Glib::create_variant(start);
options["commandline"] = Glib::create_variant(commandline);
options["dbus-activatable"] = Glib::create_variant(false);
auto uniqueName = connection->get_unique_name();
uniqueName.erase(0, 1);
@ -117,10 +116,11 @@ bool PortalAutostart(bool start, bool silent) {
const Glib::ustring &object_path,
const Glib::ustring &interface_name,
const Glib::ustring &signal_name,
Glib::VariantContainerBase parameters) {
const Glib::VariantContainerBase &parameters) {
try {
const auto response = base::Platform::GlibVariantCast<
uint>(parameters.get_child(0));
const auto response = parameters.get_child(
0
).get_dynamic<uint>();
if (response) {
if (!silent) {
@ -139,7 +139,7 @@ bool PortalAutostart(bool start, bool silent) {
loop->quit();
},
std::string(base::Platform::XDP::kService),
"org.freedesktop.portal.Request",
std::string(base::Platform::XDP::kRequestInterface),
"Response",
requestPath);
@ -153,7 +153,7 @@ bool PortalAutostart(bool start, bool silent) {
std::string(base::Platform::XDP::kObjectPath),
"org.freedesktop.portal.Background",
"RequestBackground",
base::Platform::MakeGlibVariant(std::tuple{
Glib::create_variant(std::tuple{
parentWindowId,
options,
}),
@ -429,8 +429,7 @@ std::optional<bool> IsDarkMode() {
"color-scheme");
if (result.has_value()) {
const auto value = base::Platform::GlibVariantCast<uint>(*result);
return value == 1;
return result->get_dynamic<uint>() == 1;
}
} catch (...) {
}

View File

@ -59,7 +59,7 @@ FROM builder AS patches
RUN git init patches \
&& cd patches \
&& git remote add origin {{ GIT }}/desktop-app/patches.git \
&& git fetch --depth=1 origin 523b061671d4dd2f29979c982a2d03c2cc8eaf4f \
&& git fetch --depth=1 origin edafe1a2484cd6ac9be357aa1e4cda61bf6a8b9a \
&& git reset --hard FETCH_HEAD \
&& rm -rf .git
@ -675,7 +675,7 @@ RUN git clone -b xkbcommon-1.3.1 --depth=1 {{ GIT }}/xkbcommon/libxkbcommon.git
FROM patches AS glibmm
COPY --link --from=libffi {{ LibrariesPath }}/libffi-cache /
RUN git clone -b 2.76.0 --depth=1 {{ GIT }}/GNOME/glibmm.git \
RUN git clone -b 2.77.0 --depth=1 {{ GIT }}/GNOME/glibmm.git \
&& cd glibmm \
&& git apply ../patches/glibmm.patch \
&& CFLAGS="$CFLAGS {{ CFLAGS_LTO }}" CXXFLAGS="$CXXFLAGS {{ CFLAGS_LTO }}" meson build \

2
cmake

@ -1 +1 @@
Subproject commit 6d67365e52480edbde2b2596844c26b56a8644dc
Subproject commit 0620bb7b87a0ec9195151fd5eb0cf38656c1280b

View File

@ -248,7 +248,7 @@ parts:
glibmm:
source: https://github.com/GNOME/glibmm.git
source-depth: 1
source-tag: 2.76.0
source-tag: 2.77.0
plugin: meson
build-packages:
- meson