mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Move glib usage to glibmm
This commit is contained in:
parent
b38d6667c4
commit
8042a83fd2
22 changed files with 594 additions and 642 deletions
|
@ -73,6 +73,7 @@ PRIVATE
|
||||||
if (LINUX)
|
if (LINUX)
|
||||||
target_link_libraries(Telegram
|
target_link_libraries(Telegram
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
desktop-app::external_glibmm
|
||||||
desktop-app::external_glib
|
desktop-app::external_glib
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "platform/platform_file_utilities.h"
|
#include "platform/platform_file_utilities.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "base/platform/base_platform_file_utilities.h"
|
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "history/view/media/history_view_gif.h"
|
#include "history/view/media/history_view_gif.h"
|
||||||
|
@ -49,6 +48,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
#include <QtCore/QBuffer>
|
#include <QtCore/QBuffer>
|
||||||
|
#include <QtCore/QMimeType>
|
||||||
|
#include <QtCore/QMimeDatabase>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -1724,7 +1725,10 @@ bool IsIpRevealingName(const QString &filepath) {
|
||||||
return ranges::binary_search(
|
return ranges::binary_search(
|
||||||
kExtensions,
|
kExtensions,
|
||||||
FileExtension(filepath).toLower()
|
FileExtension(filepath).toLower()
|
||||||
) || base::Platform::IsNonExtensionMimeFrom(filepath, kMimeTypes);
|
) || ranges::binary_search(
|
||||||
|
kMimeTypes,
|
||||||
|
QMimeDatabase().mimeTypeForFile(QFileInfo(filepath)).name()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
base::binary_guard ReadImageAsync(
|
base::binary_guard ReadImageAsync(
|
||||||
|
|
|
@ -16,11 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include <QtGui/QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
|
|
||||||
extern "C" {
|
#include <glibmm.h>
|
||||||
#undef signals
|
#include <giomm.h>
|
||||||
#include <gio/gio.h>
|
|
||||||
#define signals public
|
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
using Platform::internal::GtkIntegration;
|
using Platform::internal::GtkIntegration;
|
||||||
|
|
||||||
|
@ -28,12 +25,15 @@ namespace Platform {
|
||||||
namespace File {
|
namespace File {
|
||||||
|
|
||||||
void UnsafeOpenUrl(const QString &url) {
|
void UnsafeOpenUrl(const QString &url) {
|
||||||
if (!g_app_info_launch_default_for_uri(
|
try {
|
||||||
url.toUtf8().constData(),
|
if (Gio::AppInfo::launch_default_for_uri(url.toStdString())) {
|
||||||
nullptr,
|
return;
|
||||||
nullptr)) {
|
}
|
||||||
QDesktopServices::openUrl(url);
|
} catch (const Glib::Error &e) {
|
||||||
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeOpenEmailLink(const QString &email) {
|
void UnsafeOpenEmailLink(const QString &email) {
|
||||||
|
@ -46,27 +46,27 @@ bool UnsafeShowOpenWith(const QString &filepath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto integration = GtkIntegration::Instance()) {
|
if (const auto integration = GtkIntegration::Instance()) {
|
||||||
const auto absolutePath = QFileInfo(filepath).absoluteFilePath();
|
return integration->showOpenWithDialog(filepath);
|
||||||
return integration->showOpenWithDialog(absolutePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeLaunch(const QString &filepath) {
|
void UnsafeLaunch(const QString &filepath) {
|
||||||
const auto absolutePath = QFileInfo(filepath).absoluteFilePath();
|
try {
|
||||||
|
if (Gio::AppInfo::launch_default_for_uri(
|
||||||
if (!g_app_info_launch_default_for_uri(
|
Glib::filename_to_uri(filepath.toStdString()))) {
|
||||||
g_filename_to_uri(
|
return;
|
||||||
absolutePath.toUtf8().constData(),
|
|
||||||
nullptr,
|
|
||||||
nullptr),
|
|
||||||
nullptr,
|
|
||||||
nullptr)) {
|
|
||||||
if (!UnsafeShowOpenWith(filepath)) {
|
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
|
|
||||||
}
|
}
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (UnsafeShowOpenWith(filepath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace File
|
} // namespace File
|
||||||
|
|
|
@ -12,9 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#undef signals
|
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
#define signals public
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
class QLibrary;
|
class QLibrary;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#undef signals
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#define signals public
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
|
@ -9,15 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "core/sandbox.h"
|
#include "core/sandbox.h"
|
||||||
#include "media/player/media_player_instance.h"
|
#include "media/player/media_player_instance.h"
|
||||||
|
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
||||||
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
||||||
|
|
||||||
#include <QtDBus/QDBusConnection>
|
#include <glibmm.h>
|
||||||
#include <QtDBus/QDBusConnectionInterface>
|
#include <giomm.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#undef signals
|
|
||||||
#include <gio/gio.h>
|
|
||||||
#define signals public
|
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
@ -31,149 +27,137 @@ constexpr auto kMATEObjectPath = "/org/mate/SettingsDaemon/MediaKeys"_cs;
|
||||||
constexpr auto kInterface = kService;
|
constexpr auto kInterface = kService;
|
||||||
constexpr auto kMATEInterface = "org.mate.SettingsDaemon.MediaKeys"_cs;
|
constexpr auto kMATEInterface = "org.mate.SettingsDaemon.MediaKeys"_cs;
|
||||||
|
|
||||||
void KeyPressed(
|
|
||||||
GDBusConnection *connection,
|
|
||||||
const gchar *sender_name,
|
|
||||||
const gchar *object_path,
|
|
||||||
const gchar *interface_name,
|
|
||||||
const gchar *signal_name,
|
|
||||||
GVariant *parameters,
|
|
||||||
gpointer user_data) {
|
|
||||||
gchar *appUtf8;
|
|
||||||
gchar *keyUtf8;
|
|
||||||
g_variant_get(parameters, "(ss)", &appUtf8, &keyUtf8);
|
|
||||||
const auto app = QString::fromUtf8(appUtf8);
|
|
||||||
const auto key = QString::fromUtf8(keyUtf8);
|
|
||||||
g_free(keyUtf8);
|
|
||||||
g_free(appUtf8);
|
|
||||||
|
|
||||||
if (app != QCoreApplication::applicationName()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
||||||
if (key == qstr("Play")) {
|
|
||||||
Media::Player::instance()->playPause();
|
|
||||||
} else if (key == qstr("Stop")) {
|
|
||||||
Media::Player::instance()->stop();
|
|
||||||
} else if (key == qstr("Next")) {
|
|
||||||
Media::Player::instance()->next();
|
|
||||||
} else if (key == qstr("Previous")) {
|
|
||||||
Media::Player::instance()->previous();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
GSDMediaKeys::GSDMediaKeys() {
|
class GSDMediaKeys::Private : public sigc::trackable {
|
||||||
GError *error = nullptr;
|
public:
|
||||||
const auto interface = QDBusConnection::sessionBus().interface();
|
Glib::RefPtr<Gio::DBus::Connection> dbusConnection;
|
||||||
|
|
||||||
if (!interface) {
|
Glib::ustring service;
|
||||||
return;
|
Glib::ustring objectPath;
|
||||||
|
Glib::ustring interface;
|
||||||
|
uint signalId = 0;
|
||||||
|
bool grabbed = false;
|
||||||
|
|
||||||
|
void keyPressed(
|
||||||
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
|
const Glib::ustring &sender_name,
|
||||||
|
const Glib::ustring &object_path,
|
||||||
|
const Glib::ustring &interface_name,
|
||||||
|
const Glib::ustring &signal_name,
|
||||||
|
const Glib::VariantContainerBase ¶meters);
|
||||||
|
};
|
||||||
|
|
||||||
|
void GSDMediaKeys::Private::keyPressed(
|
||||||
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
|
const Glib::ustring &sender_name,
|
||||||
|
const Glib::ustring &object_path,
|
||||||
|
const Glib::ustring &interface_name,
|
||||||
|
const Glib::ustring &signal_name,
|
||||||
|
const Glib::VariantContainerBase ¶meters) {
|
||||||
|
try {
|
||||||
|
auto parametersCopy = parameters;
|
||||||
|
|
||||||
|
const auto app = base::Platform::GlibVariantCast<Glib::ustring>(
|
||||||
|
parametersCopy.get_child(0));
|
||||||
|
|
||||||
|
const auto key = base::Platform::GlibVariantCast<Glib::ustring>(
|
||||||
|
parametersCopy.get_child(1));
|
||||||
|
|
||||||
|
if (app != QCoreApplication::applicationName().toStdString()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
|
if (key == "Play") {
|
||||||
|
Media::Player::instance()->playPause();
|
||||||
|
} else if (key == "Stop") {
|
||||||
|
Media::Player::instance()->stop();
|
||||||
|
} else if (key == "Next") {
|
||||||
|
Media::Player::instance()->next();
|
||||||
|
} else if (key == "Previous") {
|
||||||
|
Media::Player::instance()->previous();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (...) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (interface->isServiceRegistered(kService.utf16())) {
|
GSDMediaKeys::GSDMediaKeys()
|
||||||
_service = kService.utf16();
|
: _private(std::make_unique<Private>()) {
|
||||||
_objectPath = kObjectPath.utf16();
|
try {
|
||||||
_interface = kInterface.utf16();
|
_private->dbusConnection = Gio::DBus::Connection::get_sync(
|
||||||
} else if (interface->isServiceRegistered(kOldService.utf16())) {
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
_service = kOldService.utf16();
|
|
||||||
_objectPath = kObjectPath.utf16();
|
if (base::Platform::DBus::NameHasOwner(
|
||||||
_interface = kInterface.utf16();
|
_private->dbusConnection,
|
||||||
} else if (interface->isServiceRegistered(kMATEService.utf16())) {
|
std::string(kService))) {
|
||||||
_service = kMATEService.utf16();
|
_private->service = std::string(kService);
|
||||||
_objectPath = kMATEObjectPath.utf16();
|
_private->objectPath = std::string(kObjectPath);
|
||||||
_interface = kMATEInterface.utf16();
|
_private->interface = std::string(kInterface);
|
||||||
} else {
|
} else if (base::Platform::DBus::NameHasOwner(
|
||||||
return;
|
_private->dbusConnection,
|
||||||
|
std::string(kOldService))) {
|
||||||
|
_private->service = std::string(kOldService);
|
||||||
|
_private->objectPath = std::string(kObjectPath);
|
||||||
|
_private->interface = std::string(kInterface);
|
||||||
|
} else if (base::Platform::DBus::NameHasOwner(
|
||||||
|
_private->dbusConnection,
|
||||||
|
std::string(kMATEService))) {
|
||||||
|
_private->service = std::string(kMATEService);
|
||||||
|
_private->objectPath = std::string(kMATEObjectPath);
|
||||||
|
_private->interface = std::string(kMATEInterface);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_private->dbusConnection->call_sync(
|
||||||
|
_private->objectPath,
|
||||||
|
_private->interface,
|
||||||
|
"GrabMediaPlayerKeys",
|
||||||
|
base::Platform::MakeGlibVariant(std::tuple{
|
||||||
|
Glib::ustring(
|
||||||
|
QCoreApplication::applicationName()
|
||||||
|
.toStdString()),
|
||||||
|
uint(0),
|
||||||
|
}),
|
||||||
|
_private->service);
|
||||||
|
|
||||||
|
_private->grabbed = true;
|
||||||
|
|
||||||
|
_private->signalId = _private->dbusConnection->signal_subscribe(
|
||||||
|
sigc::mem_fun(_private.get(), &Private::keyPressed),
|
||||||
|
_private->service,
|
||||||
|
_private->interface,
|
||||||
|
"MediaPlayerKeyPressed",
|
||||||
|
_private->objectPath);
|
||||||
|
} catch (...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_dbusConnection = g_bus_get_sync(
|
|
||||||
G_BUS_TYPE_SESSION,
|
|
||||||
nullptr,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
LOG(("GSD Media Keys Error: %1").arg(error->message));
|
|
||||||
g_error_free(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto reply = g_dbus_connection_call_sync(
|
|
||||||
_dbusConnection,
|
|
||||||
_service.toUtf8().constData(),
|
|
||||||
_objectPath.toUtf8().constData(),
|
|
||||||
_interface.toUtf8().constData(),
|
|
||||||
"GrabMediaPlayerKeys",
|
|
||||||
g_variant_new(
|
|
||||||
"(su)",
|
|
||||||
QCoreApplication::applicationName().toUtf8().constData(),
|
|
||||||
0),
|
|
||||||
nullptr,
|
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
|
||||||
-1,
|
|
||||||
nullptr,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
if (!error) {
|
|
||||||
_grabbed = true;
|
|
||||||
g_variant_unref(reply);
|
|
||||||
} else {
|
|
||||||
LOG(("GSD Media Keys Error: %1").arg(error->message));
|
|
||||||
g_error_free(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
_signalId = g_dbus_connection_signal_subscribe(
|
|
||||||
_dbusConnection,
|
|
||||||
_service.toUtf8().constData(),
|
|
||||||
_interface.toUtf8().constData(),
|
|
||||||
"MediaPlayerKeyPressed",
|
|
||||||
_objectPath.toUtf8().constData(),
|
|
||||||
nullptr,
|
|
||||||
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
||||||
KeyPressed,
|
|
||||||
nullptr,
|
|
||||||
nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GSDMediaKeys::~GSDMediaKeys() {
|
GSDMediaKeys::~GSDMediaKeys() {
|
||||||
GError *error = nullptr;
|
if (_private->dbusConnection) {
|
||||||
|
if (_private->signalId != 0) {
|
||||||
if (_signalId != 0) {
|
_private->dbusConnection->signal_unsubscribe(_private->signalId);
|
||||||
g_dbus_connection_signal_unsubscribe(
|
|
||||||
_dbusConnection,
|
|
||||||
_signalId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_grabbed) {
|
|
||||||
auto reply = g_dbus_connection_call_sync(
|
|
||||||
_dbusConnection,
|
|
||||||
_service.toUtf8().constData(),
|
|
||||||
_objectPath.toUtf8().constData(),
|
|
||||||
_interface.toUtf8().constData(),
|
|
||||||
"ReleaseMediaPlayerKeys",
|
|
||||||
g_variant_new(
|
|
||||||
"(s)",
|
|
||||||
QCoreApplication::applicationName().toUtf8().constData()),
|
|
||||||
nullptr,
|
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
|
||||||
-1,
|
|
||||||
nullptr,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
if (!error) {
|
|
||||||
_grabbed = false;
|
|
||||||
g_variant_unref(reply);
|
|
||||||
} else {
|
|
||||||
LOG(("GSD Media Keys Error: %1").arg(error->message));
|
|
||||||
g_error_free(error);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (_dbusConnection) {
|
if (_private->grabbed) {
|
||||||
g_object_unref(_dbusConnection);
|
try {
|
||||||
|
_private->dbusConnection->call_sync(
|
||||||
|
_private->objectPath,
|
||||||
|
_private->interface,
|
||||||
|
"ReleaseMediaPlayerKeys",
|
||||||
|
base::Platform::MakeGlibVariant(std::tuple{
|
||||||
|
Glib::ustring(
|
||||||
|
QCoreApplication::applicationName()
|
||||||
|
.toStdString())
|
||||||
|
}),
|
||||||
|
_private->service);
|
||||||
|
|
||||||
|
_private->grabbed = false;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef struct _GDBusConnection GDBusConnection;
|
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
@ -24,12 +22,8 @@ public:
|
||||||
~GSDMediaKeys();
|
~GSDMediaKeys();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GDBusConnection *_dbusConnection = nullptr;
|
class Private;
|
||||||
QString _service;
|
const std::unique_ptr<Private> _private;
|
||||||
QString _objectPath;
|
|
||||||
QString _interface;
|
|
||||||
uint _signalId = 0;
|
|
||||||
bool _grabbed = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
|
@ -8,10 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#undef signals
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#define signals public
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
// To be able to compile with gtk-2.0 headers as well
|
// To be able to compile with gtk-2.0 headers as well
|
||||||
|
|
|
@ -10,16 +10,39 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "main/main_domain.h"
|
#include "main/main_domain.h"
|
||||||
#include "window/notifications_manager.h"
|
#include "window/notifications_manager.h"
|
||||||
#include "platform/linux/specific_linux.h"
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
||||||
|
|
||||||
#include <QtDBus/QDBusConnection>
|
#include <QtDBus/QDBusConnection>
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kNotificationService = "org.freedesktop.Notifications"_cs;
|
||||||
|
|
||||||
|
bool IsNotificationServiceActivatable() {
|
||||||
|
static const auto Result = [] {
|
||||||
|
try {
|
||||||
|
const auto connection = Gio::DBus::Connection::get_sync(
|
||||||
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
|
|
||||||
|
return ranges::contains(
|
||||||
|
base::Platform::DBus::ListActivatableNames(connection),
|
||||||
|
Glib::ustring(std::string(kNotificationService)));
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
NotificationServiceWatcher::NotificationServiceWatcher()
|
NotificationServiceWatcher::NotificationServiceWatcher()
|
||||||
: _dbusWatcher(
|
: _dbusWatcher(
|
||||||
qsl("org.freedesktop.Notifications"),
|
kNotificationService.utf16(),
|
||||||
QDBusConnection::sessionBus(),
|
QDBusConnection::sessionBus(),
|
||||||
QDBusServiceWatcher::WatchForOwnerChange) {
|
QDBusServiceWatcher::WatchForOwnerChange) {
|
||||||
const auto signal = &QDBusServiceWatcher::serviceOwnerChanged;
|
const auto signal = &QDBusServiceWatcher::serviceOwnerChanged;
|
||||||
|
|
|
@ -30,6 +30,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
||||||
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
@ -41,7 +45,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
#include <QtDBus/QDBusInterface>
|
#include <QtDBus/QDBusInterface>
|
||||||
#include <QtDBus/QDBusConnection>
|
#include <QtDBus/QDBusConnection>
|
||||||
#include <QtDBus/QDBusConnectionInterface>
|
|
||||||
#include <QtDBus/QDBusServiceWatcher>
|
#include <QtDBus/QDBusServiceWatcher>
|
||||||
#include <QtDBus/QDBusMessage>
|
#include <QtDBus/QDBusMessage>
|
||||||
#include <QtDBus/QDBusReply>
|
#include <QtDBus/QDBusReply>
|
||||||
|
@ -52,11 +55,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <statusnotifieritem.h>
|
#include <statusnotifieritem.h>
|
||||||
#include <dbusmenuexporter.h>
|
#include <dbusmenuexporter.h>
|
||||||
|
|
||||||
extern "C" {
|
#include <glibmm.h>
|
||||||
#undef signals
|
#include <giomm.h>
|
||||||
#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 {
|
||||||
|
@ -337,19 +337,23 @@ bool IsIndicatorApplication() {
|
||||||
// save the icon to a temp file
|
// save the icon to a temp file
|
||||||
// and set the icon name to that filename.
|
// and set the icon name to that filename.
|
||||||
static const auto Result = [] {
|
static const auto Result = [] {
|
||||||
const auto interface = QDBusConnection::sessionBus().interface();
|
try {
|
||||||
|
const auto connection = Gio::DBus::Connection::get_sync(
|
||||||
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
|
|
||||||
if (!interface) {
|
const auto ubuntuIndicator = base::Platform::DBus::NameHasOwner(
|
||||||
return false;
|
connection,
|
||||||
|
"com.canonical.indicator.application");
|
||||||
|
|
||||||
|
const auto ayatanaIndicator = base::Platform::DBus::NameHasOwner(
|
||||||
|
connection,
|
||||||
|
"org.ayatana.indicator.application");
|
||||||
|
|
||||||
|
return ubuntuIndicator || ayatanaIndicator;
|
||||||
|
} catch (...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto ubuntuIndicator = interface->isServiceRegistered(
|
return false;
|
||||||
qsl("com.canonical.indicator.application"));
|
|
||||||
|
|
||||||
const auto ayatanaIndicator = interface->isServiceRegistered(
|
|
||||||
qsl("org.ayatana.indicator.application"));
|
|
||||||
|
|
||||||
return ubuntuIndicator || ayatanaIndicator;
|
|
||||||
}();
|
}();
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -461,13 +465,17 @@ quint32 djbStringHash(QString string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAppMenuSupported() {
|
bool IsAppMenuSupported() {
|
||||||
const auto interface = QDBusConnection::sessionBus().interface();
|
try {
|
||||||
|
const auto connection = Gio::DBus::Connection::get_sync(
|
||||||
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
|
|
||||||
if (!interface) {
|
return base::Platform::DBus::NameHasOwner(
|
||||||
return false;
|
connection,
|
||||||
|
std::string(kAppMenuService));
|
||||||
|
} catch (...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return interface->isServiceRegistered(kAppMenuService.utf16());
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterAppMenu(uint winId, const QString &menuPath) {
|
void RegisterAppMenu(uint winId, const QString &menuPath) {
|
||||||
|
@ -527,8 +535,16 @@ void ForceDisabled(QAction *action, bool disabled) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
class MainWindow::Private {
|
||||||
|
public:
|
||||||
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
Glib::RefPtr<Gio::DBus::Connection> dbusConnection;
|
||||||
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
};
|
||||||
|
|
||||||
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||||
: Window::MainWindow(controller) {
|
: Window::MainWindow(controller)
|
||||||
|
, _private(std::make_unique<Private>()) {
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
qDBusRegisterMetaType<ToolTip>();
|
qDBusRegisterMetaType<ToolTip>();
|
||||||
qDBusRegisterMetaType<IconPixmap>();
|
qDBusRegisterMetaType<IconPixmap>();
|
||||||
|
@ -540,22 +556,31 @@ void MainWindow::initHook() {
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
_sniAvailable = IsSNIAvailable();
|
_sniAvailable = IsSNIAvailable();
|
||||||
|
|
||||||
_sniDBusProxy = g_dbus_proxy_new_for_bus_sync(
|
try {
|
||||||
G_BUS_TYPE_SESSION,
|
_private->dbusConnection = Gio::DBus::Connection::get_sync(
|
||||||
G_DBUS_PROXY_FLAGS_NONE,
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
nullptr,
|
|
||||||
kSNIWatcherService.utf8().constData(),
|
|
||||||
kSNIWatcherObjectPath.utf8().constData(),
|
|
||||||
kSNIWatcherInterface.utf8().constData(),
|
|
||||||
nullptr,
|
|
||||||
nullptr);
|
|
||||||
|
|
||||||
if (_sniDBusProxy) {
|
_sniRegisteredSignalId = _private->dbusConnection->signal_subscribe(
|
||||||
g_signal_connect(
|
[](
|
||||||
_sniDBusProxy,
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
"g-signal",
|
const Glib::ustring &sender_name,
|
||||||
G_CALLBACK(sniSignalEmitted),
|
const Glib::ustring &object_path,
|
||||||
nullptr);
|
const Glib::ustring &interface_name,
|
||||||
|
const Glib::ustring &signal_name,
|
||||||
|
const Glib::VariantContainerBase ¶meters) {
|
||||||
|
if (signal_name == "StatusNotifierHostRegistered") {
|
||||||
|
crl::on_main([] {
|
||||||
|
if (const auto window = App::wnd()) {
|
||||||
|
window->handleSNIHostRegistered();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
std::string(kSNIWatcherService),
|
||||||
|
std::string(kSNIWatcherInterface),
|
||||||
|
"StatusNotifierHostRegistered",
|
||||||
|
std::string(kSNIWatcherObjectPath));
|
||||||
|
} catch (...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sniWatcher = new QDBusServiceWatcher(
|
auto sniWatcher = new QDBusServiceWatcher(
|
||||||
|
@ -689,21 +714,6 @@ void MainWindow::attachToSNITrayIcon() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::sniSignalEmitted(
|
|
||||||
GDBusProxy *proxy,
|
|
||||||
gchar *sender_name,
|
|
||||||
gchar *signal_name,
|
|
||||||
GVariant *parameters,
|
|
||||||
gpointer user_data) {
|
|
||||||
if (signal_name == qstr("StatusNotifierHostRegistered")) {
|
|
||||||
crl::on_main([] {
|
|
||||||
if (const auto window = App::wnd()) {
|
|
||||||
window->handleSNIHostRegistered();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::handleSNIHostRegistered() {
|
void MainWindow::handleSNIHostRegistered() {
|
||||||
if (_sniAvailable) {
|
if (_sniAvailable) {
|
||||||
return;
|
return;
|
||||||
|
@ -1241,6 +1251,10 @@ void MainWindow::handleVisibleChangedHook(bool visible) {
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
if (_sniRegisteredSignalId != 0) {
|
||||||
|
_private->dbusConnection->signal_unsubscribe(_sniRegisteredSignalId);
|
||||||
|
}
|
||||||
|
|
||||||
delete _sniTrayIcon;
|
delete _sniTrayIcon;
|
||||||
|
|
||||||
if (_appMenuSupported) {
|
if (_appMenuSupported) {
|
||||||
|
@ -1249,10 +1263,6 @@ MainWindow::~MainWindow() {
|
||||||
|
|
||||||
delete _mainMenuExporter;
|
delete _mainMenuExporter;
|
||||||
delete psMainMenu;
|
delete psMainMenu;
|
||||||
|
|
||||||
if (_sniDBusProxy) {
|
|
||||||
g_object_unref(_sniDBusProxy);
|
|
||||||
}
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,6 @@ class PopupMenu;
|
||||||
class QTemporaryFile;
|
class QTemporaryFile;
|
||||||
class DBusMenuExporter;
|
class DBusMenuExporter;
|
||||||
class StatusNotifierItem;
|
class StatusNotifierItem;
|
||||||
|
|
||||||
typedef void* gpointer;
|
|
||||||
typedef char gchar;
|
|
||||||
typedef struct _GVariant GVariant;
|
|
||||||
typedef struct _GDBusProxy GDBusProxy;
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
@ -75,6 +70,8 @@ protected:
|
||||||
style::color color) = 0;
|
style::color color) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class Private;
|
||||||
|
const std::unique_ptr<Private> _private;
|
||||||
bool _sniAvailable = false;
|
bool _sniAvailable = false;
|
||||||
base::unique_qptr<Ui::PopupMenu> _trayIconMenuXEmbed;
|
base::unique_qptr<Ui::PopupMenu> _trayIconMenuXEmbed;
|
||||||
|
|
||||||
|
@ -82,7 +79,7 @@ private:
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
StatusNotifierItem *_sniTrayIcon = nullptr;
|
StatusNotifierItem *_sniTrayIcon = nullptr;
|
||||||
GDBusProxy *_sniDBusProxy = nullptr;
|
uint _sniRegisteredSignalId = 0;
|
||||||
std::unique_ptr<QTemporaryFile> _trayIconFile;
|
std::unique_ptr<QTemporaryFile> _trayIconFile;
|
||||||
|
|
||||||
bool _appMenuSupported = false;
|
bool _appMenuSupported = false;
|
||||||
|
@ -137,13 +134,6 @@ private:
|
||||||
void psLinuxStrikeOut();
|
void psLinuxStrikeOut();
|
||||||
void psLinuxMonospace();
|
void psLinuxMonospace();
|
||||||
void psLinuxClearFormat();
|
void psLinuxClearFormat();
|
||||||
|
|
||||||
static void sniSignalEmitted(
|
|
||||||
GDBusProxy *proxy,
|
|
||||||
gchar *sender_name,
|
|
||||||
gchar *signal_name,
|
|
||||||
GVariant *parameters,
|
|
||||||
gpointer user_data);
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "window/notifications_utilities.h"
|
#include "window/notifications_utilities.h"
|
||||||
#include "base/platform/base_platform_info.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 "platform/linux/specific_linux.h"
|
#include "platform/linux/specific_linux.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/core_settings.h"
|
#include "core/core_settings.h"
|
||||||
|
@ -19,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include <QtCore/QVersionNumber>
|
#include <QtCore/QVersionNumber>
|
||||||
#include <QtDBus/QDBusConnection>
|
#include <QtDBus/QDBusConnection>
|
||||||
#include <QtDBus/QDBusConnectionInterface>
|
|
||||||
#include <QtDBus/QDBusMessage>
|
#include <QtDBus/QDBusMessage>
|
||||||
#include <QtDBus/QDBusPendingCall>
|
#include <QtDBus/QDBusPendingCall>
|
||||||
#include <QtDBus/QDBusPendingCallWatcher>
|
#include <QtDBus/QDBusPendingCallWatcher>
|
||||||
|
@ -27,11 +28,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtDBus/QDBusReply>
|
#include <QtDBus/QDBusReply>
|
||||||
#include <QtDBus/QDBusError>
|
#include <QtDBus/QDBusError>
|
||||||
|
|
||||||
extern "C" {
|
#include <glibmm.h>
|
||||||
#undef signals
|
#include <giomm.h>
|
||||||
#include <gio/gio.h>
|
|
||||||
#define signals public
|
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace Notifications {
|
namespace Notifications {
|
||||||
|
@ -55,15 +53,25 @@ std::optional<ServerInformation> CurrentServerInformation;
|
||||||
QStringList CurrentCapabilities;
|
QStringList CurrentCapabilities;
|
||||||
|
|
||||||
bool GetServiceRegistered() {
|
bool GetServiceRegistered() {
|
||||||
const auto interface = QDBusConnection::sessionBus().interface();
|
try {
|
||||||
const auto activatable = IsNotificationServiceActivatable();
|
const auto connection = Gio::DBus::Connection::get_sync(
|
||||||
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
|
|
||||||
return interface
|
static const auto activatable = ranges::contains(
|
||||||
? interface->isServiceRegistered(kService.utf16()) || activatable
|
base::Platform::DBus::ListActivatableNames(connection),
|
||||||
: activatable;
|
Glib::ustring(std::string(kService)));
|
||||||
|
|
||||||
|
return base::Platform::DBus::NameHasOwner(
|
||||||
|
connection,
|
||||||
|
std::string(kService)) || activatable;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetServerInformation(Fn<void(std::optional<ServerInformation>)> callback) {
|
void GetServerInformation(
|
||||||
|
Fn<void(std::optional<ServerInformation>)> callback) {
|
||||||
using ServerInformationReply = QDBusPendingReply<
|
using ServerInformationReply = QDBusPendingReply<
|
||||||
QString,
|
QString,
|
||||||
QString,
|
QString,
|
||||||
|
@ -229,24 +237,24 @@ ServerInformation CurrentServerInformationValue() {
|
||||||
return CurrentServerInformation.value_or(ServerInformation{});
|
return CurrentServerInformation.value_or(ServerInformation{});
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GetImageKey(const QVersionNumber &specificationVersion) {
|
Glib::ustring GetImageKey(const QVersionNumber &specificationVersion) {
|
||||||
const auto normalizedVersion = specificationVersion.normalized();
|
const auto normalizedVersion = specificationVersion.normalized();
|
||||||
|
|
||||||
if (normalizedVersion.isNull()) {
|
if (normalizedVersion.isNull()) {
|
||||||
LOG(("Native Notification Error: specification version is null"));
|
LOG(("Native Notification Error: specification version is null"));
|
||||||
return QString();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normalizedVersion >= QVersionNumber(1, 2)) {
|
if (normalizedVersion >= QVersionNumber(1, 2)) {
|
||||||
return qsl("image-data");
|
return "image-data";
|
||||||
} else if (normalizedVersion == QVersionNumber(1, 1)) {
|
} else if (normalizedVersion == QVersionNumber(1, 1)) {
|
||||||
return qsl("image_data");
|
return "image_data";
|
||||||
}
|
}
|
||||||
|
|
||||||
return qsl("icon_data");
|
return "icon_data";
|
||||||
}
|
}
|
||||||
|
|
||||||
class NotificationData {
|
class NotificationData : public sigc::trackable {
|
||||||
public:
|
public:
|
||||||
using NotificationId = Window::Notifications::Manager::NotificationId;
|
using NotificationId = Window::Notifications::Manager::NotificationId;
|
||||||
|
|
||||||
|
@ -270,40 +278,35 @@ public:
|
||||||
void setImage(const QString &imagePath);
|
void setImage(const QString &imagePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GDBusConnection *_dbusConnection = nullptr;
|
Glib::RefPtr<Gio::DBus::Connection> _dbusConnection;
|
||||||
base::weak_ptr<Manager> _manager;
|
base::weak_ptr<Manager> _manager;
|
||||||
GCancellable *_cancellable = nullptr;
|
|
||||||
|
|
||||||
QString _title;
|
Glib::ustring _title;
|
||||||
QString _body;
|
Glib::ustring _body;
|
||||||
std::vector<QString> _actions;
|
std::vector<Glib::ustring> _actions;
|
||||||
base::flat_map<QString, GVariant*> _hints;
|
std::map<Glib::ustring, Glib::VariantBase> _hints;
|
||||||
QString _imageKey;
|
Glib::ustring _imageKey;
|
||||||
QImage _image;
|
|
||||||
|
|
||||||
uint _notificationId = 0;
|
uint _notificationId = 0;
|
||||||
guint _actionInvokedSignalId = 0;
|
uint _actionInvokedSignalId = 0;
|
||||||
guint _notificationRepliedSignalId = 0;
|
uint _notificationRepliedSignalId = 0;
|
||||||
guint _notificationClosedSignalId = 0;
|
uint _notificationClosedSignalId = 0;
|
||||||
NotificationId _id;
|
NotificationId _id;
|
||||||
|
|
||||||
void notificationClosed(uint id, uint reason);
|
void notificationClosed(uint id, uint reason);
|
||||||
void actionInvoked(uint id, const QString &actionName);
|
void actionInvoked(uint id, const Glib::ustring &actionName);
|
||||||
void notificationReplied(uint id, const QString &text);
|
void notificationReplied(uint id, const Glib::ustring &text);
|
||||||
|
|
||||||
static void notificationShown(
|
void notificationShown(
|
||||||
GObject *source_object,
|
const Glib::RefPtr<Gio::AsyncResult> &result);
|
||||||
GAsyncResult *res,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void signalEmitted(
|
void signalEmitted(
|
||||||
GDBusConnection *connection,
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
const gchar *sender_name,
|
const Glib::ustring &sender_name,
|
||||||
const gchar *object_path,
|
const Glib::ustring &object_path,
|
||||||
const gchar *interface_name,
|
const Glib::ustring &interface_name,
|
||||||
const gchar *signal_name,
|
const Glib::ustring &signal_name,
|
||||||
GVariant *parameters,
|
const Glib::VariantContainerBase ¶meters);
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -317,20 +320,16 @@ NotificationData::NotificationData(
|
||||||
NotificationId id,
|
NotificationId id,
|
||||||
bool hideReplyButton)
|
bool hideReplyButton)
|
||||||
: _manager(manager)
|
: _manager(manager)
|
||||||
, _cancellable(g_cancellable_new())
|
, _title(title.toStdString())
|
||||||
, _title(title)
|
|
||||||
, _imageKey(GetImageKey(CurrentServerInformationValue().specVersion))
|
, _imageKey(GetImageKey(CurrentServerInformationValue().specVersion))
|
||||||
, _id(id) {
|
, _id(id) {
|
||||||
GError *error = nullptr;
|
try {
|
||||||
|
_dbusConnection = Gio::DBus::Connection::get_sync(
|
||||||
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
LOG(("Native Notification Error: %1").arg(
|
||||||
|
QString::fromStdString(e.what())));
|
||||||
|
|
||||||
_dbusConnection = g_bus_get_sync(
|
|
||||||
G_BUS_TYPE_SESSION,
|
|
||||||
nullptr,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
LOG(("Native Notification Error: %1").arg(error->message));
|
|
||||||
g_error_free(error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,300 +337,236 @@ NotificationData::NotificationData(
|
||||||
|
|
||||||
if (capabilities.contains(qsl("body-markup"))) {
|
if (capabilities.contains(qsl("body-markup"))) {
|
||||||
_body = subtitle.isEmpty()
|
_body = subtitle.isEmpty()
|
||||||
? msg.toHtmlEscaped()
|
? msg.toHtmlEscaped().toStdString()
|
||||||
: qsl("<b>%1</b>\n%2")
|
: qsl("<b>%1</b>\n%2")
|
||||||
.arg(subtitle.toHtmlEscaped())
|
.arg(subtitle.toHtmlEscaped())
|
||||||
.arg(msg.toHtmlEscaped());
|
.arg(msg.toHtmlEscaped()).toStdString();
|
||||||
} else {
|
} else {
|
||||||
_body = subtitle.isEmpty()
|
_body = subtitle.isEmpty()
|
||||||
? msg
|
? msg.toStdString()
|
||||||
: qsl("%1\n%2").arg(subtitle).arg(msg);
|
: qsl("%1\n%2").arg(subtitle).arg(msg).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capabilities.contains(qsl("actions"))) {
|
if (capabilities.contains("actions")) {
|
||||||
_actions.push_back(qsl("default"));
|
_actions.push_back("default");
|
||||||
_actions.push_back(QString());
|
_actions.push_back({});
|
||||||
|
|
||||||
if (!hideReplyButton) {
|
if (!hideReplyButton) {
|
||||||
_actions.push_back(qsl("mail-mark-read"));
|
_actions.push_back("mail-mark-read");
|
||||||
_actions.push_back(tr::lng_context_mark_read(tr::now));
|
_actions.push_back(
|
||||||
|
tr::lng_context_mark_read(tr::now).toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capabilities.contains(qsl("inline-reply")) && !hideReplyButton) {
|
if (capabilities.contains("inline-reply") && !hideReplyButton) {
|
||||||
_actions.push_back(qsl("inline-reply"));
|
_actions.push_back("inline-reply");
|
||||||
_actions.push_back(tr::lng_notification_reply(tr::now));
|
_actions.push_back(
|
||||||
|
tr::lng_notification_reply(tr::now).toStdString());
|
||||||
|
|
||||||
_notificationRepliedSignalId = g_dbus_connection_signal_subscribe(
|
_notificationRepliedSignalId = _dbusConnection->signal_subscribe(
|
||||||
_dbusConnection,
|
sigc::mem_fun(this, &NotificationData::signalEmitted),
|
||||||
kService.utf8().constData(),
|
std::string(kService),
|
||||||
kInterface.utf8().constData(),
|
std::string(kInterface),
|
||||||
"NotificationReplied",
|
"NotificationReplied",
|
||||||
kObjectPath.utf8().constData(),
|
std::string(kObjectPath));
|
||||||
nullptr,
|
|
||||||
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
||||||
signalEmitted,
|
|
||||||
this,
|
|
||||||
nullptr);
|
|
||||||
} 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.push_back(qsl("mail-reply-sender"));
|
_actions.push_back("mail-reply-sender");
|
||||||
_actions.push_back(tr::lng_notification_reply(tr::now));
|
_actions.push_back(
|
||||||
|
tr::lng_notification_reply(tr::now).toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
_actionInvokedSignalId = g_dbus_connection_signal_subscribe(
|
_actionInvokedSignalId = _dbusConnection->signal_subscribe(
|
||||||
_dbusConnection,
|
sigc::mem_fun(this, &NotificationData::signalEmitted),
|
||||||
kService.utf8().constData(),
|
std::string(kService),
|
||||||
kInterface.utf8().constData(),
|
std::string(kInterface),
|
||||||
"ActionInvoked",
|
"ActionInvoked",
|
||||||
kObjectPath.utf8().constData(),
|
std::string(kObjectPath));
|
||||||
nullptr,
|
|
||||||
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
||||||
signalEmitted,
|
|
||||||
this,
|
|
||||||
nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capabilities.contains(qsl("action-icons"))) {
|
if (capabilities.contains("action-icons")) {
|
||||||
_hints.emplace(qsl("action-icons"), g_variant_new_boolean(true));
|
_hints["action-icons"] = Glib::Variant<bool>::create(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// suppress system sound if telegram sound activated,
|
// suppress system sound if telegram sound activated,
|
||||||
// otherwise use system sound
|
// otherwise use system sound
|
||||||
if (capabilities.contains(qsl("sound"))) {
|
if (capabilities.contains("sound")) {
|
||||||
if (Core::App().settings().soundNotify()) {
|
if (Core::App().settings().soundNotify()) {
|
||||||
_hints.emplace(
|
_hints["suppress-sound"] = Glib::Variant<bool>::create(true);
|
||||||
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.emplace(
|
_hints["sound-name"] = Glib::Variant<Glib::ustring>::create(
|
||||||
qsl("sound-name"),
|
"message-new-instant");
|
||||||
g_variant_new_string("message-new-instant"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capabilities.contains(qsl("x-canonical-append"))) {
|
if (capabilities.contains("x-canonical-append")) {
|
||||||
_hints.emplace(
|
_hints["x-canonical-append"] = Glib::Variant<Glib::ustring>::create(
|
||||||
qsl("x-canonical-append"),
|
"true");
|
||||||
g_variant_new_string("true"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_hints.emplace(qsl("category"), g_variant_new_string("im.received"));
|
_hints["category"] = Glib::Variant<Glib::ustring>::create("im.received");
|
||||||
|
|
||||||
_hints.emplace(
|
_hints["desktop-entry"] = Glib::Variant<Glib::ustring>::create(
|
||||||
qsl("desktop-entry"),
|
GetLauncherBasename().toStdString());
|
||||||
g_variant_new_string(GetLauncherBasename().toUtf8().constData()));
|
|
||||||
|
|
||||||
_notificationClosedSignalId = g_dbus_connection_signal_subscribe(
|
_notificationClosedSignalId = _dbusConnection->signal_subscribe(
|
||||||
_dbusConnection,
|
sigc::mem_fun(this, &NotificationData::signalEmitted),
|
||||||
kService.utf8().constData(),
|
std::string(kService),
|
||||||
kInterface.utf8().constData(),
|
std::string(kInterface),
|
||||||
"NotificationClosed",
|
"NotificationClosed",
|
||||||
kObjectPath.utf8().constData(),
|
std::string(kObjectPath));
|
||||||
nullptr,
|
|
||||||
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
||||||
signalEmitted,
|
|
||||||
this,
|
|
||||||
nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationData::~NotificationData() {
|
NotificationData::~NotificationData() {
|
||||||
if (_dbusConnection) {
|
if (_dbusConnection) {
|
||||||
if (_actionInvokedSignalId != 0) {
|
if (_actionInvokedSignalId != 0) {
|
||||||
g_dbus_connection_signal_unsubscribe(
|
_dbusConnection->signal_unsubscribe(_actionInvokedSignalId);
|
||||||
_dbusConnection,
|
|
||||||
_actionInvokedSignalId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_notificationRepliedSignalId != 0) {
|
if (_notificationRepliedSignalId != 0) {
|
||||||
g_dbus_connection_signal_unsubscribe(
|
_dbusConnection->signal_unsubscribe(_notificationRepliedSignalId);
|
||||||
_dbusConnection,
|
|
||||||
_notificationRepliedSignalId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_notificationClosedSignalId != 0) {
|
if (_notificationClosedSignalId != 0) {
|
||||||
g_dbus_connection_signal_unsubscribe(
|
_dbusConnection->signal_unsubscribe(_notificationClosedSignalId);
|
||||||
_dbusConnection,
|
|
||||||
_notificationClosedSignalId);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_unref(_dbusConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &[key, value] : _hints) {
|
|
||||||
if (value) {
|
|
||||||
g_variant_unref(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_cancellable_cancel(_cancellable);
|
|
||||||
g_object_unref(_cancellable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::show() {
|
void NotificationData::show() {
|
||||||
GVariantBuilder actionsBuilder, hintsBuilder;
|
try {
|
||||||
GError *error = nullptr;
|
const auto iconName = _imageKey.empty()
|
||||||
|
|| _hints.find(_imageKey) == end(_hints)
|
||||||
|
? Glib::ustring(GetIconName().toStdString())
|
||||||
|
: Glib::ustring();
|
||||||
|
|
||||||
g_variant_builder_init(&actionsBuilder, G_VARIANT_TYPE("as"));
|
_dbusConnection->call(
|
||||||
for (const auto &value : _actions) {
|
std::string(kObjectPath),
|
||||||
g_variant_builder_add(
|
std::string(kInterface),
|
||||||
&actionsBuilder,
|
"Notify",
|
||||||
"s",
|
base::Platform::MakeGlibVariant(std::tuple{
|
||||||
value.toUtf8().constData());
|
Glib::ustring(std::string(AppName)),
|
||||||
}
|
uint(0),
|
||||||
|
iconName,
|
||||||
|
_title,
|
||||||
|
_body,
|
||||||
|
_actions,
|
||||||
|
_hints,
|
||||||
|
-1,
|
||||||
|
}),
|
||||||
|
sigc::mem_fun(this, &NotificationData::notificationShown),
|
||||||
|
std::string(kService));
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
LOG(("Native Notification Error: %1").arg(
|
||||||
|
QString::fromStdString(e.what())));
|
||||||
|
|
||||||
g_variant_builder_init(&hintsBuilder, G_VARIANT_TYPE("a{sv}"));
|
const auto manager = _manager;
|
||||||
for (auto &[key, value] : _hints) {
|
const auto my = _id;
|
||||||
g_variant_builder_add(
|
|
||||||
&hintsBuilder,
|
|
||||||
"{sv}",
|
|
||||||
key.toUtf8().constData(),
|
|
||||||
value);
|
|
||||||
|
|
||||||
value = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto iconName = _imageKey.isEmpty() || !_hints.contains(_imageKey)
|
|
||||||
? GetIconName()
|
|
||||||
: QString();
|
|
||||||
|
|
||||||
g_dbus_connection_call(
|
|
||||||
_dbusConnection,
|
|
||||||
kService.utf8().constData(),
|
|
||||||
kObjectPath.utf8().constData(),
|
|
||||||
kInterface.utf8().constData(),
|
|
||||||
"Notify",
|
|
||||||
g_variant_new(
|
|
||||||
"(susssasa{sv}i)",
|
|
||||||
AppName.utf8().constData(),
|
|
||||||
0,
|
|
||||||
iconName.toUtf8().constData(),
|
|
||||||
_title.toUtf8().constData(),
|
|
||||||
_body.toUtf8().constData(),
|
|
||||||
&actionsBuilder,
|
|
||||||
&hintsBuilder,
|
|
||||||
-1),
|
|
||||||
nullptr,
|
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
|
||||||
-1,
|
|
||||||
_cancellable,
|
|
||||||
notificationShown,
|
|
||||||
this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationData::notificationShown(
|
|
||||||
GObject *source_object,
|
|
||||||
GAsyncResult *res,
|
|
||||||
gpointer user_data) {
|
|
||||||
GError *error = nullptr;
|
|
||||||
|
|
||||||
auto reply = g_dbus_connection_call_finish(
|
|
||||||
reinterpret_cast<GDBusConnection*>(source_object),
|
|
||||||
res,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
if (error && error->code == G_IO_ERROR_CANCELLED) {
|
|
||||||
g_error_free(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto notificationData = reinterpret_cast<NotificationData*>(
|
|
||||||
user_data);
|
|
||||||
|
|
||||||
if (!notificationData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!error) {
|
|
||||||
g_variant_get(reply, "(u)", ¬ificationData->_notificationId);
|
|
||||||
g_variant_unref(reply);
|
|
||||||
} else {
|
|
||||||
const auto manager = notificationData->_manager;
|
|
||||||
const auto my = notificationData->_id;
|
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
manager->clearNotification(my);
|
manager->clearNotification(my);
|
||||||
});
|
});
|
||||||
LOG(("Native Notification Error: %1").arg(error->message));
|
|
||||||
g_error_free(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotificationData::notificationShown(
|
||||||
|
const Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||||
|
try {
|
||||||
|
auto reply = _dbusConnection->call_finish(result);
|
||||||
|
_notificationId = base::Platform::GlibVariantCast<uint>(
|
||||||
|
reply.get_child(0));
|
||||||
|
|
||||||
|
return;
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
LOG(("Native Notification Error: %1").arg(
|
||||||
|
QString::fromStdString(e.what())));
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
LOG(("Native Notification Error: %1").arg(
|
||||||
|
QString::fromStdString(e.what())));
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto manager = _manager;
|
||||||
|
const auto my = _id;
|
||||||
|
crl::on_main(manager, [=] {
|
||||||
|
manager->clearNotification(my);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void NotificationData::close() {
|
void NotificationData::close() {
|
||||||
g_dbus_connection_call(
|
try {
|
||||||
_dbusConnection,
|
_dbusConnection->call(
|
||||||
kService.utf8().constData(),
|
std::string(kObjectPath),
|
||||||
kObjectPath.utf8().constData(),
|
std::string(kInterface),
|
||||||
kInterface.utf8().constData(),
|
"CloseNotification",
|
||||||
"CloseNotification",
|
base::Platform::MakeGlibVariant(std::tuple{
|
||||||
g_variant_new("(u)", _notificationId),
|
_notificationId,
|
||||||
nullptr,
|
}),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
{},
|
||||||
-1,
|
std::string(kService));
|
||||||
nullptr,
|
} catch (const Glib::Error &e) {
|
||||||
nullptr,
|
LOG(("Native Notification Error: %1").arg(
|
||||||
nullptr);
|
QString::fromStdString(e.what())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::setImage(const QString &imagePath) {
|
void NotificationData::setImage(const QString &imagePath) {
|
||||||
if (_imageKey.isEmpty()) {
|
if (_imageKey.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_image = QImage(imagePath).convertToFormat(QImage::Format_RGBA8888);
|
const auto image = QImage(imagePath)
|
||||||
|
.convertToFormat(QImage::Format_RGBA8888);
|
||||||
|
|
||||||
_hints.emplace(_imageKey, g_variant_new(
|
_hints[_imageKey] = base::Platform::MakeGlibVariant(std::tuple{
|
||||||
"(iiibii@ay)",
|
image.width(),
|
||||||
_image.width(),
|
image.height(),
|
||||||
_image.height(),
|
image.bytesPerLine(),
|
||||||
_image.bytesPerLine(),
|
|
||||||
true,
|
true,
|
||||||
8,
|
8,
|
||||||
4,
|
4,
|
||||||
g_variant_new_from_data(
|
std::vector<uchar>(
|
||||||
G_VARIANT_TYPE("ay"),
|
image.constBits(),
|
||||||
_image.constBits(),
|
image.constBits() + image.sizeInBytes()),
|
||||||
_image.sizeInBytes(),
|
});
|
||||||
true,
|
|
||||||
nullptr,
|
|
||||||
nullptr)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::signalEmitted(
|
void NotificationData::signalEmitted(
|
||||||
GDBusConnection *connection,
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||||
const gchar *sender_name,
|
const Glib::ustring &sender_name,
|
||||||
const gchar *object_path,
|
const Glib::ustring &object_path,
|
||||||
const gchar *interface_name,
|
const Glib::ustring &interface_name,
|
||||||
const gchar *signal_name,
|
const Glib::ustring &signal_name,
|
||||||
GVariant *parameters,
|
const Glib::VariantContainerBase ¶meters) {
|
||||||
gpointer user_data) {
|
try {
|
||||||
const auto notificationData = reinterpret_cast<NotificationData*>(
|
auto parametersCopy = parameters;
|
||||||
user_data);
|
|
||||||
|
|
||||||
if (!notificationData) {
|
if (signal_name == "ActionInvoked") {
|
||||||
return;
|
const auto id = base::Platform::GlibVariantCast<uint>(
|
||||||
}
|
parametersCopy.get_child(0));
|
||||||
|
|
||||||
if(signal_name == qstr("ActionInvoked")) {
|
const auto actionName = base::Platform::GlibVariantCast<
|
||||||
guint32 id;
|
Glib::ustring>(parametersCopy.get_child(1));
|
||||||
gchar *actionName;
|
|
||||||
g_variant_get(parameters, "(us)", &id, &actionName);
|
|
||||||
notificationData->actionInvoked(id, actionName);
|
|
||||||
g_free(actionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(signal_name == qstr("NotificationReplied")) {
|
actionInvoked(id, actionName);
|
||||||
guint32 id;
|
} else if (signal_name == "NotificationReplied") {
|
||||||
gchar *text;
|
const auto id = base::Platform::GlibVariantCast<uint>(
|
||||||
g_variant_get(parameters, "(us)", &id, &text);
|
parametersCopy.get_child(0));
|
||||||
notificationData->notificationReplied(id, text);
|
|
||||||
g_free(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(signal_name == qstr("NotificationClosed")) {
|
const auto text = base::Platform::GlibVariantCast<Glib::ustring>(
|
||||||
guint32 id;
|
parametersCopy.get_child(1));
|
||||||
guint32 reason;
|
|
||||||
g_variant_get(parameters, "(uu)", &id, &reason);
|
notificationReplied(id, text);
|
||||||
notificationData->notificationClosed(id, reason);
|
} else if (signal_name == "NotificationClosed") {
|
||||||
|
const auto id = base::Platform::GlibVariantCast<uint>(
|
||||||
|
parametersCopy.get_child(0));
|
||||||
|
|
||||||
|
const auto reason = base::Platform::GlibVariantCast<uint>(
|
||||||
|
parametersCopy.get_child(1));
|
||||||
|
|
||||||
|
notificationClosed(id, reason);
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
LOG(("Native Notification Error: %1").arg(
|
||||||
|
QString::fromStdString(e.what())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,19 +580,21 @@ void NotificationData::notificationClosed(uint id, uint reason) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::actionInvoked(uint id, const QString &actionName) {
|
void NotificationData::actionInvoked(
|
||||||
|
uint id,
|
||||||
|
const Glib::ustring &actionName) {
|
||||||
if (id != _notificationId) {
|
if (id != _notificationId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionName == qsl("default")
|
if (actionName == "default"
|
||||||
|| actionName == qsl("mail-reply-sender")) {
|
|| actionName == "mail-reply-sender") {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = _id;
|
const auto my = _id;
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
manager->notificationActivated(my);
|
manager->notificationActivated(my);
|
||||||
});
|
});
|
||||||
} else if (actionName == qsl("mail-mark-read")) {
|
} else if (actionName == "mail-mark-read") {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = _id;
|
const auto my = _id;
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
|
@ -666,12 +603,16 @@ void NotificationData::actionInvoked(uint id, const QString &actionName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::notificationReplied(uint id, const QString &text) {
|
void NotificationData::notificationReplied(
|
||||||
|
uint id,
|
||||||
|
const Glib::ustring &text) {
|
||||||
if (id == _notificationId) {
|
if (id == _notificationId) {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = _id;
|
const auto my = _id;
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
manager->notificationReplied(my, { text, {} });
|
manager->notificationReplied(
|
||||||
|
my,
|
||||||
|
{ QString::fromStdString(text), {} });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/update_checker.h"
|
#include "core/update_checker.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
|
|
||||||
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
||||||
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
@ -41,19 +45,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
#include <QtDBus/QDBusInterface>
|
#include <QtDBus/QDBusInterface>
|
||||||
#include <QtDBus/QDBusConnection>
|
#include <QtDBus/QDBusConnection>
|
||||||
#include <QtDBus/QDBusConnectionInterface>
|
|
||||||
#include <QtDBus/QDBusMessage>
|
#include <QtDBus/QDBusMessage>
|
||||||
#include <QtDBus/QDBusReply>
|
#include <QtDBus/QDBusReply>
|
||||||
#include <QtDBus/QDBusError>
|
#include <QtDBus/QDBusError>
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#undef signals
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#define signals public
|
#include <glibmm.h>
|
||||||
} // extern "C"
|
#include <giomm.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -83,31 +83,6 @@ constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
std::unique_ptr<internal::NotificationServiceWatcher> NSWInstance;
|
std::unique_ptr<internal::NotificationServiceWatcher> NSWInstance;
|
||||||
|
|
||||||
QStringList ListDBusActivatableNames() {
|
|
||||||
static const auto Result = [&] {
|
|
||||||
const auto message = QDBusMessage::createMethodCall(
|
|
||||||
qsl("org.freedesktop.DBus"),
|
|
||||||
qsl("/org/freedesktop/DBus"),
|
|
||||||
qsl("org.freedesktop.DBus"),
|
|
||||||
qsl("ListActivatableNames"));
|
|
||||||
|
|
||||||
const QDBusReply<QStringList> reply = QDBusConnection::sessionBus()
|
|
||||||
.call(message);
|
|
||||||
|
|
||||||
if (reply.isValid()) {
|
|
||||||
return reply.value();
|
|
||||||
} else if (reply.error().type() != QDBusError::Disconnected) {
|
|
||||||
LOG(("ListActivatableNames Error: %1: %2")
|
|
||||||
.arg(reply.error().name())
|
|
||||||
.arg(reply.error().message()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return QStringList{};
|
|
||||||
}();
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PortalAutostart(bool start, bool silent = false) {
|
void PortalAutostart(bool start, bool silent = false) {
|
||||||
if (cExeName().isEmpty()) {
|
if (cExeName().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -177,17 +152,23 @@ bool IsXDGDesktopPortalKDEPresent() {
|
||||||
|
|
||||||
bool IsIBusPortalPresent() {
|
bool IsIBusPortalPresent() {
|
||||||
static const auto Result = [&] {
|
static const auto Result = [&] {
|
||||||
const auto interface = QDBusConnection::sessionBus().interface();
|
try {
|
||||||
const auto activatableNames = ListDBusActivatableNames();
|
const auto connection = Gio::DBus::Connection::get_sync(
|
||||||
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
||||||
|
|
||||||
const auto serviceRegistered = interface
|
const auto serviceRegistered = base::Platform::DBus::NameHasOwner(
|
||||||
&& interface->isServiceRegistered(
|
connection,
|
||||||
qsl("org.freedesktop.portal.IBus"));
|
"org.freedesktop.portal.IBus");
|
||||||
|
|
||||||
const auto serviceActivatable = activatableNames.contains(
|
const auto serviceActivatable = ranges::contains(
|
||||||
qsl("org.freedesktop.portal.IBus"));
|
base::Platform::DBus::ListActivatableNames(connection),
|
||||||
|
"org.freedesktop.portal.IBus");
|
||||||
|
|
||||||
return serviceRegistered || serviceActivatable;
|
return serviceRegistered || serviceActivatable;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -443,17 +424,6 @@ bool CanOpenDirectoryWithPortal() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsNotificationServiceActivatable() {
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
static const auto Result = ListDBusActivatableNames().contains(
|
|
||||||
qsl("org.freedesktop.Notifications"));
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString AppRuntimeDirectory() {
|
QString AppRuntimeDirectory() {
|
||||||
static const auto Result = [&] {
|
static const auto Result = [&] {
|
||||||
auto runtimeDir = QStandardPaths::writableLocation(
|
auto runtimeDir = QStandardPaths::writableLocation(
|
||||||
|
@ -598,8 +568,7 @@ void psActivateProcess(uint64 pid) {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QString GetHomeDir() {
|
QString GetHomeDir() {
|
||||||
const auto home = QString(g_get_home_dir());
|
const auto home = QString::fromStdString(Glib::get_home_dir());
|
||||||
|
|
||||||
if (!home.isEmpty() && !home.endsWith('/')) {
|
if (!home.isEmpty() && !home.endsWith('/')) {
|
||||||
return home + '/';
|
return home + '/';
|
||||||
}
|
}
|
||||||
|
@ -682,6 +651,9 @@ void start() {
|
||||||
qputenv("PULSE_PROP_application.name", AppName.utf8());
|
qputenv("PULSE_PROP_application.name", AppName.utf8());
|
||||||
qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1());
|
qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1());
|
||||||
|
|
||||||
|
Glib::init();
|
||||||
|
Gio::init();
|
||||||
|
|
||||||
if (const auto integration = BaseGtkIntegration::Instance()) {
|
if (const auto integration = BaseGtkIntegration::Instance()) {
|
||||||
integration->prepareEnvironment();
|
integration->prepareEnvironment();
|
||||||
} else {
|
} else {
|
||||||
|
@ -775,75 +747,65 @@ void InstallLauncher(bool force) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterCustomScheme(bool force) {
|
void RegisterCustomScheme(bool force) {
|
||||||
if (cExeName().isEmpty()) {
|
try {
|
||||||
return;
|
if (cExeName().isEmpty()) {
|
||||||
}
|
|
||||||
|
|
||||||
GError *error = nullptr;
|
|
||||||
|
|
||||||
const auto neededCommandlineBuilder = qsl("%1 -workdir %2 --").arg(
|
|
||||||
QString(EscapeShell(QFile::encodeName(cExeDir() + cExeName()))),
|
|
||||||
QString(EscapeShell(QFile::encodeName(cWorkingDir()))));
|
|
||||||
|
|
||||||
const auto neededCommandline = qsl("%1 %u")
|
|
||||||
.arg(neededCommandlineBuilder);
|
|
||||||
|
|
||||||
auto currentAppInfo = g_app_info_get_default_for_type(
|
|
||||||
kHandlerTypeName.utf8().constData(),
|
|
||||||
true);
|
|
||||||
|
|
||||||
if (currentAppInfo) {
|
|
||||||
const auto currentCommandline = QString(
|
|
||||||
g_app_info_get_commandline(currentAppInfo));
|
|
||||||
|
|
||||||
g_object_unref(currentAppInfo);
|
|
||||||
|
|
||||||
if (currentCommandline == neededCommandline) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto registeredAppInfoList = g_app_info_get_recommended_for_type(
|
const auto neededCommandlineBuilder = qsl("%1 -workdir %2 --").arg(
|
||||||
kHandlerTypeName.utf8().constData());
|
QString(EscapeShell(QFile::encodeName(cExeDir() + cExeName()))),
|
||||||
|
QString(EscapeShell(QFile::encodeName(cWorkingDir()))));
|
||||||
|
|
||||||
for (auto l = registeredAppInfoList; l != nullptr; l = l->next) {
|
const auto neededCommandline = qsl("%1 %u")
|
||||||
const auto currentRegisteredAppInfo = reinterpret_cast<GAppInfo*>(
|
.arg(neededCommandlineBuilder);
|
||||||
l->data);
|
|
||||||
|
|
||||||
const auto currentAppInfoId = QString(
|
const auto currentAppInfo = Gio::AppInfo::get_default_for_type(
|
||||||
g_app_info_get_id(currentRegisteredAppInfo));
|
std::string(kHandlerTypeName),
|
||||||
|
true);
|
||||||
|
|
||||||
const auto currentCommandline = QString(
|
if (currentAppInfo) {
|
||||||
g_app_info_get_commandline(currentRegisteredAppInfo));
|
const auto currentCommandline = QString::fromStdString(
|
||||||
|
currentAppInfo->get_commandline());
|
||||||
|
|
||||||
if (currentCommandline == neededCommandline
|
if (currentCommandline == neededCommandline) {
|
||||||
&& currentAppInfoId.startsWith(qsl("userapp-"))) {
|
return;
|
||||||
g_app_info_delete(currentRegisteredAppInfo);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (registeredAppInfoList) {
|
auto registeredAppInfoList = g_app_info_get_recommended_for_type(
|
||||||
g_list_free_full(registeredAppInfoList, g_object_unref);
|
kHandlerTypeName.utf8().constData());
|
||||||
}
|
|
||||||
|
|
||||||
auto newAppInfo = g_app_info_create_from_commandline(
|
for (auto l = registeredAppInfoList; l != nullptr; l = l->next) {
|
||||||
neededCommandlineBuilder.toUtf8().constData(),
|
const auto currentRegisteredAppInfo = reinterpret_cast<GAppInfo*>(
|
||||||
AppName.utf8().constData(),
|
l->data);
|
||||||
G_APP_INFO_CREATE_SUPPORTS_URIS,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
if (newAppInfo) {
|
const auto currentAppInfoId = QString(
|
||||||
g_app_info_set_as_default_for_type(
|
g_app_info_get_id(currentRegisteredAppInfo));
|
||||||
newAppInfo,
|
|
||||||
kHandlerTypeName.utf8().constData(),
|
|
||||||
&error);
|
|
||||||
|
|
||||||
g_object_unref(newAppInfo);
|
const auto currentCommandline = QString(
|
||||||
}
|
g_app_info_get_commandline(currentRegisteredAppInfo));
|
||||||
|
|
||||||
if (error) {
|
if (currentCommandline == neededCommandline
|
||||||
LOG(("App Error: %1").arg(error->message));
|
&& currentAppInfoId.startsWith(qsl("userapp-"))) {
|
||||||
g_error_free(error);
|
g_app_info_delete(currentRegisteredAppInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (registeredAppInfoList) {
|
||||||
|
g_list_free_full(registeredAppInfoList, g_object_unref);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto newAppInfo = Gio::AppInfo::create_from_commandline(
|
||||||
|
neededCommandlineBuilder.toStdString(),
|
||||||
|
std::string(AppName),
|
||||||
|
Gio::AppInfoCreateFlags::APP_INFO_CREATE_SUPPORTS_URIS);
|
||||||
|
|
||||||
|
if (newAppInfo) {
|
||||||
|
newAppInfo->set_as_default_for_type(
|
||||||
|
std::string(kHandlerTypeName));
|
||||||
|
}
|
||||||
|
} catch (const Glib::Error &e) {
|
||||||
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ bool InSnap();
|
||||||
bool AreQtPluginsBundled();
|
bool AreQtPluginsBundled();
|
||||||
bool UseXDGDesktopPortal();
|
bool UseXDGDesktopPortal();
|
||||||
bool CanOpenDirectoryWithPortal();
|
bool CanOpenDirectoryWithPortal();
|
||||||
bool IsNotificationServiceActivatable();
|
|
||||||
|
|
||||||
QString AppRuntimeDirectory();
|
QString AppRuntimeDirectory();
|
||||||
QString GetLauncherBasename();
|
QString GetLauncherBasename();
|
||||||
|
|
2
Telegram/ThirdParty/fcitx-qt5
vendored
2
Telegram/ThirdParty/fcitx-qt5
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit f95f76d637990f66f056eb099d46e3b5e6e7366f
|
Subproject commit 77cb995a1ed0c30401e43388842b99610b53569e
|
2
Telegram/ThirdParty/fcitx5-qt
vendored
2
Telegram/ThirdParty/fcitx5-qt
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 47628ac9f81b589d8e69f82b121d08773b06e813
|
Subproject commit 8543204b9a3792e0dbd4163ee9420e896f4f49d8
|
2
Telegram/ThirdParty/qt5ct
vendored
2
Telegram/ThirdParty/qt5ct
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 59be9d1d995348687702a18ce3d653c07389cfa2
|
Subproject commit 9f60cd2352a4dcc55c8ca267f29bd8fff5c6a659
|
|
@ -458,6 +458,52 @@ RUN DESTDIR="$LibrariesPath/xkbcommon-cache" meson install -C build
|
||||||
WORKDIR ..
|
WORKDIR ..
|
||||||
RUN rm -rf libxkbcommon
|
RUN rm -rf libxkbcommon
|
||||||
|
|
||||||
|
FROM builder AS mm-common
|
||||||
|
RUN git clone -b 1.0.2 --depth=1 $GIT/GNOME/mm-common.git
|
||||||
|
|
||||||
|
WORKDIR mm-common
|
||||||
|
RUN NOCONFIGURE=1 ./autogen.sh
|
||||||
|
RUN ./configure --enable-network
|
||||||
|
RUN make -j$(nproc)
|
||||||
|
RUN make DESTDIR="$LibrariesPath/mm-common-cache" install
|
||||||
|
|
||||||
|
WORKDIR ..
|
||||||
|
RUN rm -rf mm-common
|
||||||
|
|
||||||
|
FROM builder AS libsigcplusplus
|
||||||
|
COPY --from=mm-common ${LibrariesPath}/mm-common-cache /
|
||||||
|
|
||||||
|
RUN git clone -b 2.10.6 --depth=1 $GIT/libsigcplusplus/libsigcplusplus.git
|
||||||
|
|
||||||
|
WORKDIR libsigcplusplus
|
||||||
|
ENV ACLOCAL_PATH="/usr/local/share/aclocal"
|
||||||
|
RUN NOCONFIGURE=1 ./autogen.sh
|
||||||
|
RUN ./configure --enable-maintainer-mode --enable-static --disable-documentation
|
||||||
|
RUN make -j$(nproc)
|
||||||
|
RUN make DESTDIR="$LibrariesPath/libsigcplusplus-cache" install
|
||||||
|
|
||||||
|
WORKDIR ..
|
||||||
|
RUN rm -rf libsigcplusplus
|
||||||
|
|
||||||
|
FROM patches AS glibmm
|
||||||
|
COPY --from=mm-common ${LibrariesPath}/mm-common-cache /
|
||||||
|
COPY --from=libsigcplusplus ${LibrariesPath}/libsigcplusplus-cache /
|
||||||
|
RUN yum -y install perl-XML-Parser
|
||||||
|
|
||||||
|
# equals to glib version of Ubuntu 14.04
|
||||||
|
RUN git clone -b 2.40.0 --depth=1 $GIT/GNOME/glibmm.git
|
||||||
|
|
||||||
|
WORKDIR glibmm
|
||||||
|
RUN git apply ../patches/glibmm.patch
|
||||||
|
ENV ACLOCAL_PATH="/usr/local/share/aclocal"
|
||||||
|
RUN NOCONFIGURE=1 ./autogen.sh
|
||||||
|
RUN ./configure --enable-maintainer-mode --enable-static --disable-documentation
|
||||||
|
RUN make -j$(nproc)
|
||||||
|
RUN make DESTDIR="$LibrariesPath/glibmm-cache" install
|
||||||
|
|
||||||
|
WORKDIR ..
|
||||||
|
RUN rm -rf glibmm
|
||||||
|
|
||||||
FROM patches AS qt
|
FROM patches AS qt
|
||||||
|
|
||||||
COPY --from=libffi ${LibrariesPath}/libffi-cache /
|
COPY --from=libffi ${LibrariesPath}/libffi-cache /
|
||||||
|
@ -636,6 +682,8 @@ COPY --from=ffmpeg ${LibrariesPath}/ffmpeg-cache /
|
||||||
COPY --from=openal ${LibrariesPath}/openal-cache /
|
COPY --from=openal ${LibrariesPath}/openal-cache /
|
||||||
COPY --from=openssl ${LibrariesPath}/openssl-cache /
|
COPY --from=openssl ${LibrariesPath}/openssl-cache /
|
||||||
COPY --from=xkbcommon ${LibrariesPath}/xkbcommon-cache /
|
COPY --from=xkbcommon ${LibrariesPath}/xkbcommon-cache /
|
||||||
|
COPY --from=libsigcplusplus ${LibrariesPath}/libsigcplusplus-cache /
|
||||||
|
COPY --from=glibmm ${LibrariesPath}/glibmm-cache /
|
||||||
COPY --from=qt ${LibrariesPath}/qt-cache /
|
COPY --from=qt ${LibrariesPath}/qt-cache /
|
||||||
COPY --from=kwayland ${LibrariesPath}/kwayland-cache /
|
COPY --from=kwayland ${LibrariesPath}/kwayland-cache /
|
||||||
COPY --from=breakpad ${LibrariesPath}/breakpad breakpad
|
COPY --from=breakpad ${LibrariesPath}/breakpad breakpad
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9005da2a22740668fc3f16597ca08dffbc4b008b
|
Subproject commit 06e0afae84d45a8c4587329d56b7c5754190dc97
|
|
@ -1 +1 @@
|
||||||
Subproject commit db65fca0aa6f0e1225d45a0a6eeecfafdab5cce0
|
Subproject commit af41bff7e49e2018a905755d8dea60d2d1f7b8f3
|
2
cmake
2
cmake
|
@ -1 +1 @@
|
||||||
Subproject commit ac193a597d6b953f9869a240e21e275ce6e388cb
|
Subproject commit 2f4cbdd1263ad350776413633bb01e8122147274
|
|
@ -75,6 +75,7 @@ parts:
|
||||||
- python
|
- python
|
||||||
- libasound2-dev
|
- libasound2-dev
|
||||||
- libglib2.0-dev
|
- libglib2.0-dev
|
||||||
|
- libglibmm-2.4-dev
|
||||||
- libgtk-3-dev
|
- libgtk-3-dev
|
||||||
- liblzma-dev
|
- liblzma-dev
|
||||||
- libopus-dev
|
- libopus-dev
|
||||||
|
@ -88,6 +89,7 @@ parts:
|
||||||
stage-packages:
|
stage-packages:
|
||||||
- libasound2
|
- libasound2
|
||||||
- libglib2.0-0
|
- libglib2.0-0
|
||||||
|
- libglibmm-2.4-1v5
|
||||||
- libgtk-3-0
|
- libgtk-3-0
|
||||||
- liblzma5
|
- liblzma5
|
||||||
- libopus0
|
- libopus0
|
||||||
|
|
Loading…
Add table
Reference in a new issue