mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use GDBus to send notifications to avoid Q_OBJECT
This commit is contained in:
parent
bc7925985c
commit
e4ac70090e
3 changed files with 234 additions and 213 deletions
|
@ -157,32 +157,38 @@ if (LINUX)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (LINUX AND (NOT TDESKTOP_DISABLE_GTK_INTEGRATION OR NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION))
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(GLIB2 REQUIRED IMPORTED_TARGET glib-2.0)
|
||||||
|
pkg_check_modules(GOBJECT REQUIRED IMPORTED_TARGET gobject-2.0)
|
||||||
|
pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
|
||||||
|
|
||||||
|
target_link_libraries(Telegram
|
||||||
|
PRIVATE
|
||||||
|
PkgConfig::GLIB2
|
||||||
|
PkgConfig::GOBJECT
|
||||||
|
PkgConfig::GIO
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(Telegram PRIVATE -Wno-register)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (LINUX AND NOT TDESKTOP_DISABLE_GTK_INTEGRATION)
|
if (LINUX AND NOT TDESKTOP_DISABLE_GTK_INTEGRATION)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
target_compile_options(Telegram PRIVATE -Wno-register)
|
|
||||||
|
|
||||||
if (DESKTOP_APP_USE_PACKAGED AND NOT DESKTOP_APP_USE_PACKAGED_LAZY)
|
if (DESKTOP_APP_USE_PACKAGED AND NOT DESKTOP_APP_USE_PACKAGED_LAZY)
|
||||||
pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)
|
|
||||||
pkg_check_modules(GOBJECT2 REQUIRED IMPORTED_TARGET gobject-2.0)
|
|
||||||
pkg_check_modules(GLIB2 REQUIRED IMPORTED_TARGET glib-2.0)
|
|
||||||
pkg_check_modules(GTK3 REQUIRED IMPORTED_TARGET gtk+-3.0)
|
pkg_check_modules(GTK3 REQUIRED IMPORTED_TARGET gtk+-3.0)
|
||||||
|
pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)
|
||||||
|
|
||||||
target_link_libraries(Telegram
|
target_link_libraries(Telegram
|
||||||
PRIVATE
|
PRIVATE
|
||||||
PkgConfig::X11
|
|
||||||
PkgConfig::GOBJECT2
|
|
||||||
PkgConfig::GLIB2
|
|
||||||
PkgConfig::GTK3
|
PkgConfig::GTK3
|
||||||
|
PkgConfig::X11
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
pkg_search_module(GTK REQUIRED gtk+-2.0 gtk+-3.0)
|
pkg_search_module(GTK REQUIRED gtk+-2.0 gtk+-3.0)
|
||||||
target_link_libraries(Telegram
|
|
||||||
PRIVATE
|
|
||||||
X11
|
|
||||||
gobject-2.0
|
|
||||||
glib-2.0
|
|
||||||
)
|
|
||||||
target_include_directories(Telegram PRIVATE ${GTK_INCLUDE_DIRS})
|
target_include_directories(Telegram PRIVATE ${GTK_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(Telegram PRIVATE X11)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
#include <QtCore/QVersionNumber>
|
#include <QtCore/QVersionNumber>
|
||||||
|
#include <QtDBus/QDBusConnection>
|
||||||
#include <QtDBus/QDBusMessage>
|
#include <QtDBus/QDBusMessage>
|
||||||
#include <QtDBus/QDBusReply>
|
#include <QtDBus/QDBusReply>
|
||||||
#include <QtDBus/QDBusError>
|
#include <QtDBus/QDBusError>
|
||||||
#include <QtDBus/QDBusMetaType>
|
|
||||||
|
extern "C" {
|
||||||
|
#undef signals
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#define signals public
|
||||||
|
} // extern "C"
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
@ -31,10 +37,13 @@ namespace Notifications {
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kDBusTimeout = 30000;
|
||||||
constexpr auto kService = "org.freedesktop.Notifications"_cs;
|
constexpr auto kService = "org.freedesktop.Notifications"_cs;
|
||||||
constexpr auto kObjectPath = "/org/freedesktop/Notifications"_cs;
|
constexpr auto kObjectPath = "/org/freedesktop/Notifications"_cs;
|
||||||
constexpr auto kInterface = kService;
|
constexpr auto kInterface = kService;
|
||||||
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
|
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
|
||||||
|
constexpr auto kImageDataType = "(iiibii@ay)"_cs;
|
||||||
|
constexpr auto kNotifyArgsType = "(susssasa{sv}i)"_cs;
|
||||||
|
|
||||||
bool NotificationsSupported = false;
|
bool NotificationsSupported = false;
|
||||||
bool InhibitedNotSupported = false;
|
bool InhibitedNotSupported = false;
|
||||||
|
@ -53,7 +62,11 @@ void ComputeSupported(bool wait = false) {
|
||||||
watcher,
|
watcher,
|
||||||
&QDBusPendingCallWatcher::finished,
|
&QDBusPendingCallWatcher::finished,
|
||||||
[=](QDBusPendingCallWatcher *call) {
|
[=](QDBusPendingCallWatcher *call) {
|
||||||
QDBusPendingReply<QString, QString, QString, QString> reply = *call;
|
QDBusPendingReply<
|
||||||
|
QString,
|
||||||
|
QString,
|
||||||
|
QString,
|
||||||
|
QString> reply = *call;
|
||||||
|
|
||||||
if (reply.isValid()) {
|
if (reply.isValid()) {
|
||||||
NotificationsSupported = true;
|
NotificationsSupported = true;
|
||||||
|
@ -203,7 +216,57 @@ QString GetImageKey(const QVersionNumber &specificationVersion) {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
class NotificationData {
|
||||||
|
public:
|
||||||
|
using NotificationId = Window::Notifications::Manager::NotificationId;
|
||||||
|
|
||||||
|
NotificationData(
|
||||||
|
const base::weak_ptr<Manager> &manager,
|
||||||
|
const QString &title,
|
||||||
|
const QString &subtitle,
|
||||||
|
const QString &msg,
|
||||||
|
NotificationId id,
|
||||||
|
bool hideReplyButton);
|
||||||
|
|
||||||
|
NotificationData(const NotificationData &other) = delete;
|
||||||
|
NotificationData &operator=(const NotificationData &other) = delete;
|
||||||
|
NotificationData(NotificationData &&other) = delete;
|
||||||
|
NotificationData &operator=(NotificationData &&other) = delete;
|
||||||
|
|
||||||
|
~NotificationData();
|
||||||
|
|
||||||
|
bool show();
|
||||||
|
void close();
|
||||||
|
void setImage(const QString &imagePath);
|
||||||
|
|
||||||
|
void notificationClosed(uint id, uint reason);
|
||||||
|
void actionInvoked(uint id, const QString &actionName);
|
||||||
|
void notificationReplied(uint id, const QString &text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
GDBusProxy *_dbusProxy;
|
||||||
|
base::weak_ptr<Manager> _manager;
|
||||||
|
|
||||||
|
QString _title;
|
||||||
|
QString _body;
|
||||||
|
std::vector<QString> _actions;
|
||||||
|
base::flat_map<QString, GVariant*> _hints;
|
||||||
|
QString _imageKey;
|
||||||
|
QImage _image;
|
||||||
|
|
||||||
|
uint _notificationId = 0;
|
||||||
|
NotificationId _id;
|
||||||
|
|
||||||
|
static void signalEmitted(
|
||||||
|
GDBusProxy *proxy,
|
||||||
|
gchar *sender_name,
|
||||||
|
gchar *signal_name,
|
||||||
|
GVariant *parameters,
|
||||||
|
NotificationData *notificationData);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
using Notification = std::shared_ptr<NotificationData>;
|
||||||
|
|
||||||
NotificationData::NotificationData(
|
NotificationData::NotificationData(
|
||||||
const base::weak_ptr<Manager> &manager,
|
const base::weak_ptr<Manager> &manager,
|
||||||
|
@ -212,7 +275,15 @@ NotificationData::NotificationData(
|
||||||
const QString &msg,
|
const QString &msg,
|
||||||
NotificationId id,
|
NotificationId id,
|
||||||
bool hideReplyButton)
|
bool hideReplyButton)
|
||||||
: _dbusConnection(QDBusConnection::sessionBus())
|
: _dbusProxy(g_dbus_proxy_new_for_bus_sync(
|
||||||
|
G_BUS_TYPE_SESSION,
|
||||||
|
G_DBUS_PROXY_FLAGS_NONE,
|
||||||
|
nullptr,
|
||||||
|
kService.utf8(),
|
||||||
|
kObjectPath.utf8(),
|
||||||
|
kInterface.utf8(),
|
||||||
|
nullptr,
|
||||||
|
nullptr))
|
||||||
, _manager(manager)
|
, _manager(manager)
|
||||||
, _title(title)
|
, _title(title)
|
||||||
, _imageKey(GetImageKey(ParseSpecificationVersion(
|
, _imageKey(GetImageKey(ParseSpecificationVersion(
|
||||||
|
@ -233,116 +304,134 @@ NotificationData::NotificationData(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capabilities.contains(qsl("actions"))) {
|
if (capabilities.contains(qsl("actions"))) {
|
||||||
_actions << qsl("default") << QString();
|
_actions.push_back(qsl("default"));
|
||||||
|
_actions.push_back(QString());
|
||||||
|
|
||||||
_actions
|
_actions.push_back(qsl("mail-mark-read"));
|
||||||
<< qsl("mail-mark-read")
|
_actions.push_back(tr::lng_context_mark_read(tr::now));
|
||||||
<< tr::lng_context_mark_read(tr::now);
|
|
||||||
|
|
||||||
if (capabilities.contains(qsl("inline-reply")) && !hideReplyButton) {
|
if (capabilities.contains(qsl("inline-reply")) && !hideReplyButton) {
|
||||||
_actions
|
_actions.push_back(qsl("inline-reply"));
|
||||||
<< qsl("inline-reply")
|
_actions.push_back(tr::lng_notification_reply(tr::now));
|
||||||
<< tr::lng_notification_reply(tr::now);
|
|
||||||
|
|
||||||
_dbusConnection.connect(
|
|
||||||
kService.utf16(),
|
|
||||||
kObjectPath.utf16(),
|
|
||||||
kInterface.utf16(),
|
|
||||||
qsl("NotificationReplied"),
|
|
||||||
this,
|
|
||||||
SLOT(notificationReplied(uint,QString)));
|
|
||||||
} else {
|
} else {
|
||||||
// icon name according to https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
|
// icon name according to https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
|
||||||
_actions
|
_actions.push_back(qsl("mail-reply-sender"));
|
||||||
<< qsl("mail-reply-sender")
|
_actions.push_back(tr::lng_notification_reply(tr::now));
|
||||||
<< tr::lng_notification_reply(tr::now);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dbusConnection.connect(
|
|
||||||
kService.utf16(),
|
|
||||||
kObjectPath.utf16(),
|
|
||||||
kInterface.utf16(),
|
|
||||||
qsl("ActionInvoked"),
|
|
||||||
this,
|
|
||||||
SLOT(actionInvoked(uint,QString)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capabilities.contains(qsl("action-icons"))) {
|
if (capabilities.contains(qsl("action-icons"))) {
|
||||||
_hints["action-icons"] = true;
|
_hints.emplace(qsl("action-icons"), g_variant_new_boolean(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// suppress system sound if telegram sound activated, otherwise use system sound
|
// suppress system sound if telegram sound activated,
|
||||||
|
// otherwise use system sound
|
||||||
if (capabilities.contains(qsl("sound"))) {
|
if (capabilities.contains(qsl("sound"))) {
|
||||||
if (Core::App().settings().soundNotify()) {
|
if (Core::App().settings().soundNotify()) {
|
||||||
_hints["suppress-sound"] = true;
|
_hints.emplace(
|
||||||
|
qsl("suppress-sound"),
|
||||||
|
g_variant_new_boolean(true));
|
||||||
} else {
|
} else {
|
||||||
// sound name according to http://0pointer.de/public/sound-naming-spec.html
|
// sound name according to http://0pointer.de/public/sound-naming-spec.html
|
||||||
_hints["sound-name"] = qsl("message-new-instant");
|
_hints.emplace(
|
||||||
|
qsl("sound-name"),
|
||||||
|
g_variant_new_string("message-new-instant"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capabilities.contains(qsl("x-canonical-append"))) {
|
if (capabilities.contains(qsl("x-canonical-append"))) {
|
||||||
_hints["x-canonical-append"] = qsl("true");
|
_hints.emplace(
|
||||||
|
qsl("x-canonical-append"),
|
||||||
|
g_variant_new_string("true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
_hints["category"] = qsl("im.received");
|
_hints.emplace(qsl("category"), g_variant_new_string("im.received"));
|
||||||
_hints["desktop-entry"] = GetLauncherBasename();
|
|
||||||
|
|
||||||
_dbusConnection.connect(
|
_hints.emplace(
|
||||||
kService.utf16(),
|
qsl("desktop-entry"),
|
||||||
kObjectPath.utf16(),
|
g_variant_new_string(GetLauncherBasename().toUtf8()));
|
||||||
kInterface.utf16(),
|
|
||||||
qsl("NotificationClosed"),
|
g_signal_connect(_dbusProxy, "g-signal", G_CALLBACK(signalEmitted), this);
|
||||||
this,
|
}
|
||||||
SLOT(notificationClosed(uint)));
|
|
||||||
|
NotificationData::~NotificationData() {
|
||||||
|
g_object_unref(_dbusProxy);
|
||||||
|
|
||||||
|
for (const auto &[key, value] : _hints) {
|
||||||
|
if (value) {
|
||||||
|
g_variant_unref(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotificationData::show() {
|
bool NotificationData::show() {
|
||||||
|
GVariantBuilder actionsBuilder, hintsBuilder;
|
||||||
|
GError *error = nullptr;
|
||||||
|
|
||||||
|
g_variant_builder_init(&actionsBuilder, G_VARIANT_TYPE("as"));
|
||||||
|
for (const auto &value : _actions) {
|
||||||
|
g_variant_builder_add(
|
||||||
|
&actionsBuilder,
|
||||||
|
"s",
|
||||||
|
value.toUtf8().constData());
|
||||||
|
}
|
||||||
|
|
||||||
|
g_variant_builder_init(&hintsBuilder, G_VARIANT_TYPE("a{sv}"));
|
||||||
|
for (auto &[key, value] : _hints) {
|
||||||
|
g_variant_builder_add(
|
||||||
|
&hintsBuilder,
|
||||||
|
"{sv}",
|
||||||
|
key.toUtf8().constData(),
|
||||||
|
value);
|
||||||
|
|
||||||
|
value = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
const auto iconName = _imageKey.isEmpty() || !_hints.contains(_imageKey)
|
const auto iconName = _imageKey.isEmpty() || !_hints.contains(_imageKey)
|
||||||
? GetIconName()
|
? GetIconName()
|
||||||
: QString();
|
: QString();
|
||||||
|
|
||||||
auto message = QDBusMessage::createMethodCall(
|
auto reply = g_dbus_proxy_call_sync(
|
||||||
kService.utf16(),
|
_dbusProxy,
|
||||||
kObjectPath.utf16(),
|
"Notify",
|
||||||
kInterface.utf16(),
|
g_variant_new(
|
||||||
qsl("Notify"));
|
kNotifyArgsType.utf8(),
|
||||||
|
AppName.utf8().constData(),
|
||||||
|
0,
|
||||||
|
iconName.toUtf8().constData(),
|
||||||
|
_title.toUtf8().constData(),
|
||||||
|
_body.toUtf8().constData(),
|
||||||
|
&actionsBuilder,
|
||||||
|
&hintsBuilder,
|
||||||
|
-1),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
kDBusTimeout,
|
||||||
|
nullptr,
|
||||||
|
&error);
|
||||||
|
|
||||||
message.setArguments({
|
const auto replyValid = !error;
|
||||||
AppName.utf16(),
|
|
||||||
uint(0),
|
|
||||||
iconName,
|
|
||||||
_title,
|
|
||||||
_body,
|
|
||||||
_actions,
|
|
||||||
_hints,
|
|
||||||
-1
|
|
||||||
});
|
|
||||||
|
|
||||||
const QDBusReply<uint> reply = _dbusConnection.call(
|
if (replyValid) {
|
||||||
message);
|
g_variant_get(reply, "(u)", &_notificationId);
|
||||||
|
g_variant_unref(reply);
|
||||||
if (reply.isValid()) {
|
|
||||||
_notificationId = reply.value();
|
|
||||||
} else {
|
} else {
|
||||||
LOG(("Native notification error: %1").arg(reply.error().message()));
|
LOG(("Native notification error: %1").arg(error->message));
|
||||||
|
g_error_free(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return reply.isValid();
|
return replyValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::close() {
|
void NotificationData::close() {
|
||||||
auto message = QDBusMessage::createMethodCall(
|
g_dbus_proxy_call(
|
||||||
kService.utf16(),
|
_dbusProxy,
|
||||||
kObjectPath.utf16(),
|
"CloseNotification",
|
||||||
kInterface.utf16(),
|
g_variant_new("(u)", _notificationId),
|
||||||
qsl("CloseNotification"));
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
-1,
|
||||||
message.setArguments({
|
nullptr,
|
||||||
_notificationId
|
nullptr,
|
||||||
});
|
nullptr);
|
||||||
|
|
||||||
_dbusConnection.send(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::setImage(const QString &imagePath) {
|
void NotificationData::setImage(const QString &imagePath) {
|
||||||
|
@ -350,31 +439,60 @@ void NotificationData::setImage(const QString &imagePath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto image = QImage(imagePath)
|
_image = QImage(imagePath).convertToFormat(QImage::Format_RGBA8888);
|
||||||
.convertToFormat(QImage::Format_RGBA8888);
|
|
||||||
|
|
||||||
const QByteArray imageBytes(
|
_hints.emplace(_imageKey, g_variant_new(
|
||||||
(const char*)image.constBits(),
|
kImageDataType.utf8(),
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
_image.width(),
|
||||||
image.byteCount());
|
_image.height(),
|
||||||
#else // Qt < 5.10.0
|
_image.bytesPerLine(),
|
||||||
image.sizeInBytes());
|
|
||||||
#endif // Qt >= 5.10.0
|
|
||||||
|
|
||||||
const auto imageData = ImageData{
|
|
||||||
image.width(),
|
|
||||||
image.height(),
|
|
||||||
image.bytesPerLine(),
|
|
||||||
true,
|
true,
|
||||||
8,
|
8,
|
||||||
4,
|
4,
|
||||||
imageBytes
|
g_variant_new_from_data(
|
||||||
};
|
G_VARIANT_TYPE("ay"),
|
||||||
|
_image.constBits(),
|
||||||
_hints[_imageKey] = QVariant::fromValue(imageData);
|
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
_image.byteCount(),
|
||||||
|
#else // Qt < 5.10.0
|
||||||
|
_image.sizeInBytes(),
|
||||||
|
#endif // Qt >= 5.10.0
|
||||||
|
true,
|
||||||
|
nullptr,
|
||||||
|
nullptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::notificationClosed(uint id) {
|
void NotificationData::signalEmitted(
|
||||||
|
GDBusProxy *proxy,
|
||||||
|
gchar *sender_name,
|
||||||
|
gchar *signal_name,
|
||||||
|
GVariant *parameters,
|
||||||
|
NotificationData *notificationData) {
|
||||||
|
if(signal_name == qstr("ActionInvoked")) {
|
||||||
|
guint32 id;
|
||||||
|
gchar *actionName;
|
||||||
|
g_variant_get(parameters, "(us)", &id, &actionName);
|
||||||
|
notificationData->actionInvoked(id, actionName);
|
||||||
|
g_free(actionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(signal_name == qstr("NotificationReplied")) {
|
||||||
|
guint32 id;
|
||||||
|
gchar *text;
|
||||||
|
g_variant_get(parameters, "(us)", &id, &text);
|
||||||
|
notificationData->notificationReplied(id, text);
|
||||||
|
g_free(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(signal_name == qstr("NotificationClosed")) {
|
||||||
|
guint32 id;
|
||||||
|
guint32 reason;
|
||||||
|
g_variant_get(parameters, "(uu)", &id, &reason);
|
||||||
|
notificationData->notificationClosed(id, reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationData::notificationClosed(uint id, uint reason) {
|
||||||
if (id == _notificationId) {
|
if (id == _notificationId) {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = _id;
|
const auto my = _id;
|
||||||
|
@ -415,37 +533,7 @@ void NotificationData::notificationReplied(uint id, const QString &text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusArgument &operator<<(
|
} // namespace
|
||||||
QDBusArgument &argument,
|
|
||||||
const NotificationData::ImageData &imageData) {
|
|
||||||
argument.beginStructure();
|
|
||||||
argument
|
|
||||||
<< imageData.width
|
|
||||||
<< imageData.height
|
|
||||||
<< imageData.rowStride
|
|
||||||
<< imageData.hasAlpha
|
|
||||||
<< imageData.bitsPerSample
|
|
||||||
<< imageData.channels
|
|
||||||
<< imageData.data;
|
|
||||||
argument.endStructure();
|
|
||||||
return argument;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDBusArgument &operator>>(
|
|
||||||
const QDBusArgument &argument,
|
|
||||||
NotificationData::ImageData &imageData) {
|
|
||||||
argument.beginStructure();
|
|
||||||
argument
|
|
||||||
>> imageData.width
|
|
||||||
>> imageData.height
|
|
||||||
>> imageData.rowStride
|
|
||||||
>> imageData.hasAlpha
|
|
||||||
>> imageData.bitsPerSample
|
|
||||||
>> imageData.channels
|
|
||||||
>> imageData.data;
|
|
||||||
argument.endStructure();
|
|
||||||
return argument;
|
|
||||||
}
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
bool SkipAudio() {
|
bool SkipAudio() {
|
||||||
|
@ -544,8 +632,6 @@ private:
|
||||||
Manager::Private::Private(not_null<Manager*> manager, Type type)
|
Manager::Private::Private(not_null<Manager*> manager, Type type)
|
||||||
: _cachedUserpics(type)
|
: _cachedUserpics(type)
|
||||||
, _manager(manager) {
|
, _manager(manager) {
|
||||||
qDBusRegisterMetaType<NotificationData::ImageData>();
|
|
||||||
|
|
||||||
if (!Supported()) {
|
if (!Supported()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,76 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/platform_notifications_manager.h"
|
#include "platform/platform_notifications_manager.h"
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
#include <QtDBus/QDBusConnection>
|
|
||||||
#include <QtDBus/QDBusArgument>
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace Notifications {
|
namespace Notifications {
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
class NotificationData : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
using NotificationId = Window::Notifications::Manager::NotificationId;
|
|
||||||
|
|
||||||
NotificationData(
|
|
||||||
const base::weak_ptr<Manager> &manager,
|
|
||||||
const QString &title,
|
|
||||||
const QString &subtitle,
|
|
||||||
const QString &msg,
|
|
||||||
NotificationId id,
|
|
||||||
bool hideReplyButton);
|
|
||||||
|
|
||||||
NotificationData(const NotificationData &other) = delete;
|
|
||||||
NotificationData &operator=(const NotificationData &other) = delete;
|
|
||||||
NotificationData(NotificationData &&other) = delete;
|
|
||||||
NotificationData &operator=(NotificationData &&other) = delete;
|
|
||||||
|
|
||||||
bool show();
|
|
||||||
void close();
|
|
||||||
void setImage(const QString &imagePath);
|
|
||||||
|
|
||||||
struct ImageData {
|
|
||||||
int width, height, rowStride;
|
|
||||||
bool hasAlpha;
|
|
||||||
int bitsPerSample, channels;
|
|
||||||
QByteArray data;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
QDBusConnection _dbusConnection;
|
|
||||||
base::weak_ptr<Manager> _manager;
|
|
||||||
|
|
||||||
QString _title;
|
|
||||||
QString _body;
|
|
||||||
QStringList _actions;
|
|
||||||
QVariantMap _hints;
|
|
||||||
QString _imageKey;
|
|
||||||
|
|
||||||
uint _notificationId = 0;
|
|
||||||
NotificationId _id;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void notificationClosed(uint id);
|
|
||||||
void actionInvoked(uint id, const QString &actionName);
|
|
||||||
void notificationReplied(uint id, const QString &text);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
using Notification = std::shared_ptr<NotificationData>;
|
|
||||||
|
|
||||||
QDBusArgument &operator<<(
|
|
||||||
QDBusArgument &argument,
|
|
||||||
const NotificationData::ImageData &imageData);
|
|
||||||
|
|
||||||
const QDBusArgument &operator>>(
|
|
||||||
const QDBusArgument &argument,
|
|
||||||
NotificationData::ImageData &imageData);
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
class Manager
|
class Manager
|
||||||
: public Window::Notifications::NativeManager
|
: public Window::Notifications::NativeManager
|
||||||
, public base::has_weak_ptr {
|
, public base::has_weak_ptr {
|
||||||
|
@ -110,7 +43,3 @@ private:
|
||||||
|
|
||||||
} // namespace Notifications
|
} // namespace Notifications
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
Q_DECLARE_METATYPE(Platform::Notifications::NotificationData::ImageData)
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue