summary refs log tree commit diff
path: root/src/dock/Dock.cpp
diff options
context:
space:
mode:
authord42 <d42@users.noreply.github.com>2022-06-05 11:51:29 +0000
committerGitHub <noreply@github.com>2022-06-05 11:51:29 +0000
commit0e02024084db087552a53520e829f3e4a5ae0cb4 (patch)
tree16277893e42f6e2c4dac1e53abed92dffcdffec1 /src/dock/Dock.cpp
parentTry to fix flatpak upload (diff)
downloadnheko-0e02024084db087552a53520e829f3e4a5ae0cb4.tar.xz
Unread messages count as an Unity compatible badge (#1085)
Co-authored-by: DeepBlueV7.X <nicolas.werner@hotmail.de>
Diffstat (limited to 'src/dock/Dock.cpp')
-rw-r--r--src/dock/Dock.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/dock/Dock.cpp b/src/dock/Dock.cpp
new file mode 100644

index 00000000..04c7507d --- /dev/null +++ b/src/dock/Dock.cpp
@@ -0,0 +1,81 @@ +// SPDX-FileCopyrightText: 2022 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "dock/Dock.h" +#include <QApplication> +#include <QObject> +#if defined(NHEKO_DBUS_SYS) +#include <qdbusconnectioninterface.h> +Dock::Dock(QObject *parent) + : QObject(parent) + , unityServiceWatcher(new QDBusServiceWatcher(this)) +{ + unityServiceWatcher->setConnection(QDBusConnection::sessionBus()); + unityServiceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration | + QDBusServiceWatcher::WatchForRegistration); + unityServiceWatcher->addWatchedService(QStringLiteral("com.canonical.Unity")); + connect(unityServiceWatcher, + &QDBusServiceWatcher::serviceRegistered, + this, + [this](const QString &service) { + Q_UNUSED(service); + unityServiceAvailable = true; + }); + connect(unityServiceWatcher, + &QDBusServiceWatcher::serviceUnregistered, + this, + [this](const QString &service) { + Q_UNUSED(service); + unityServiceAvailable = false; + }); + QDBusPendingCall listNamesCall = + QDBusConnection::sessionBus().interface()->asyncCall(QStringLiteral("ListNames")); + QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(listNamesCall, this); + connect(callWatcher, + &QDBusPendingCallWatcher::finished, + this, + [this](QDBusPendingCallWatcher *watcher) { + QDBusPendingReply<QStringList> reply = *watcher; + watcher->deleteLater(); + + if (reply.isError()) { + return; + } + + const QStringList &services = reply.value(); + + unityServiceAvailable = services.contains(QLatin1String("com.canonical.Unity")); + }); +} + +void +Dock::setUnreadCount(const int count) +{ + unitySetNotificationCount(count); +} +void +Dock::unitySetNotificationCount(const int count) +{ + if (unityServiceAvailable) { + const QString launcherId = qApp->desktopFileName() + QLatin1String(".desktop"); + + const QVariantMap properties{{QStringLiteral("count-visible"), count > 0}, + {QStringLiteral("count"), count}}; + + QDBusMessage message = + QDBusMessage::createSignal(QStringLiteral("/im/nheko/Nheko/UnityLauncher"), + QStringLiteral("com.canonical.Unity.LauncherEntry"), + QStringLiteral("Update")); + message.setArguments({launcherId, properties}); + QDBusConnection::sessionBus().send(message); + } +} +#else +Dock::Dock(QObject *parent) + : QObject(parent) +{} +void +Dock::setUnreadCount(const int) +{} +#endif