Restore dbusmenu-qt dependent functionality with Qt 6

This commit is contained in:
Ilya Fedin 2021-10-24 04:31:12 +04:00 committed by John Preston
parent 389ea2af83
commit c50a5db277
2 changed files with 4 additions and 27 deletions

View file

@ -1289,16 +1289,10 @@ elseif (APPLE)
endif() endif()
else() else()
if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION)
if (NOT DESKTOP_APP_QT6)
target_link_libraries(Telegram
PRIVATE
desktop-app::external_statusnotifieritem
desktop-app::external_dbusmenu_qt
)
endif()
target_link_libraries(Telegram target_link_libraries(Telegram
PRIVATE PRIVATE
desktop-app::external_statusnotifieritem
desktop-app::external_dbusmenu_qt
desktop-app::external_glibmm desktop-app::external_glibmm
desktop-app::external_glib desktop-app::external_glib
) )

View file

@ -50,13 +50,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtDBus/QDBusObjectPath> #include <QtDBus/QDBusObjectPath>
#include <QtDBus/QDBusMetaType> #include <QtDBus/QDBusMetaType>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <statusnotifieritem.h> #include <statusnotifieritem.h>
#include <dbusmenuexporter.h> #include <dbusmenuexporter.h>
#else // Qt < 6.0.0
class StatusNotifierItem;
class DBusMenuExporter;
#endif // Qt >= 6.0.0
#include <glibmm.h> #include <glibmm.h>
#include <giomm.h> #include <giomm.h>
@ -394,7 +389,7 @@ void ForceDisabled(QAction *action, bool disabled) {
} }
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
[[maybe_unused]] bool IsIndicatorApplication() { bool IsIndicatorApplication() {
// Hack for indicator-application, // Hack for indicator-application,
// which doesn't handle icons sent across D-Bus: // which doesn't handle icons sent across D-Bus:
// save the icon to a temp file // save the icon to a temp file
@ -422,7 +417,7 @@ void ForceDisabled(QAction *action, bool disabled) {
return Result; return Result;
} }
[[maybe_unused]] std::unique_ptr<QTemporaryFile> TrayIconFile( std::unique_ptr<QTemporaryFile> TrayIconFile(
const QIcon &icon, const QIcon &icon,
QObject *parent = nullptr) { QObject *parent = nullptr) {
static const auto templateName = AppRuntimeDirectory() static const auto templateName = AppRuntimeDirectory()
@ -651,7 +646,6 @@ private:
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
void MainWindow::Private::setSNITrayIcon(int counter, bool muted) { void MainWindow::Private::setSNITrayIcon(int counter, bool muted) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto iconName = GetTrayIconName(counter, muted); const auto iconName = GetTrayIconName(counter, muted);
const auto panelIconName = GetPanelIconName(counter, muted); const auto panelIconName = GetPanelIconName(counter, muted);
@ -687,11 +681,9 @@ void MainWindow::Private::setSNITrayIcon(int counter, bool muted) {
sniTrayIcon->setIconByPixmap(icon); sniTrayIcon->setIconByPixmap(icon);
sniTrayIcon->setToolTipIconByPixmap(icon); sniTrayIcon->setToolTipIconByPixmap(icon);
} }
#endif // Qt < 6.0.0
} }
void MainWindow::Private::attachToSNITrayIcon() { void MainWindow::Private::attachToSNITrayIcon() {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
sniTrayIcon->setToolTipTitle(AppName.utf16()); sniTrayIcon->setToolTipTitle(AppName.utf16());
connect(sniTrayIcon, connect(sniTrayIcon,
&StatusNotifierItem::activateRequested, &StatusNotifierItem::activateRequested,
@ -707,7 +699,6 @@ void MainWindow::Private::attachToSNITrayIcon() {
_public->handleTrayIconActication(QSystemTrayIcon::MiddleClick); _public->handleTrayIconActication(QSystemTrayIcon::MiddleClick);
}); });
}); });
#endif // Qt < 6.0.0
} }
void MainWindow::Private::handleSNIHostRegistered() { void MainWindow::Private::handleSNIHostRegistered() {
@ -796,11 +787,9 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller)
: Window::MainWindow(controller) : Window::MainWindow(controller)
, _private(std::make_unique<Private>(this)) { , _private(std::make_unique<Private>(this)) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qDBusRegisterMetaType<ToolTip>(); qDBusRegisterMetaType<ToolTip>();
qDBusRegisterMetaType<IconPixmap>(); qDBusRegisterMetaType<IconPixmap>();
qDBusRegisterMetaType<IconPixmapList>(); qDBusRegisterMetaType<IconPixmapList>();
#endif // Qt < 6.0.0
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
} }
@ -928,7 +917,6 @@ void MainWindow::psSetupTrayIcon() {
const auto muted = Core::App().unreadBadgeMuted(); const auto muted = Core::App().unreadBadgeMuted();
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (_sniAvailable) { if (_sniAvailable) {
LOG(("Using SNI tray icon.")); LOG(("Using SNI tray icon."));
if (!_private->sniTrayIcon) { if (!_private->sniTrayIcon) {
@ -947,7 +935,6 @@ void MainWindow::psSetupTrayIcon() {
return; return;
} }
#endif // Qt < 6.0.0
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
LOG(("Using Qt tray icon.")); LOG(("Using Qt tray icon."));
@ -970,13 +957,11 @@ void MainWindow::workmodeUpdated(Core::Settings::WorkMode mode) {
return; return;
} else if (mode == WorkMode::WindowOnly) { } else if (mode == WorkMode::WindowOnly) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (_private->sniTrayIcon) { if (_private->sniTrayIcon) {
_private->sniTrayIcon->setContextMenu(0); _private->sniTrayIcon->setContextMenu(0);
_private->sniTrayIcon->deleteLater(); _private->sniTrayIcon->deleteLater();
} }
_private->sniTrayIcon = nullptr; _private->sniTrayIcon = nullptr;
#endif // Qt < 6.0.0
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
if (trayIcon) { if (trayIcon) {
@ -1239,11 +1224,9 @@ void MainWindow::createGlobalMenu() {
about->setMenuRole(QAction::AboutQtRole); about->setMenuRole(QAction::AboutQtRole);
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
_private->mainMenuExporter = new DBusMenuExporter( _private->mainMenuExporter = new DBusMenuExporter(
kMainMenuObjectPath.utf16(), kMainMenuObjectPath.utf16(),
psMainMenu); psMainMenu);
#endif // Qt < 6.0.0
if (_private->appMenuSupported) { if (_private->appMenuSupported) {
RegisterAppMenu(windowHandle(), kMainMenuObjectPath.utf16()); RegisterAppMenu(windowHandle(), kMainMenuObjectPath.utf16());