matrixion/src/dock/Dock.cpp

93 lines
3.1 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dock/Dock.h"
2022-06-05 17:26:31 +03:00
#include <QApplication>
2022-06-05 17:26:31 +03:00
#include "Logging.h"
#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;
2022-06-05 17:26:31 +03:00
nhlog::ui()->info("Unity service available: {}", unityServiceAvailable);
});
connect(unityServiceWatcher,
&QDBusServiceWatcher::serviceUnregistered,
this,
[this](const QString &service) {
Q_UNUSED(service);
unityServiceAvailable = false;
2022-06-05 17:26:31 +03:00
nhlog::ui()->info("Unity service available: {}", unityServiceAvailable);
});
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()) {
2022-06-05 17:26:31 +03:00
nhlog::ui()->error("Failed to list dbus names");
return;
}
const QStringList &services = reply.value();
unityServiceAvailable = services.contains(QLatin1String("com.canonical.Unity"));
2022-06-05 17:26:31 +03:00
nhlog::ui()->info("Unity service available: {}", unityServiceAvailable);
});
}
void
Dock::setUnreadCount(const int count)
{
unitySetNotificationCount(count);
}
void
Dock::unitySetNotificationCount(const int count)
{
if (unityServiceAvailable) {
2022-06-05 17:26:31 +03:00
const QString launcherId =
QLatin1String("application://%1.desktop").arg(qApp->desktopFileName());
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)
2022-09-25 21:05:08 +03:00
{
}
void
2023-06-04 04:32:21 +03:00
Dock::setUnreadCount(const int count)
2022-09-25 21:05:08 +03:00
{
2023-06-04 04:32:21 +03:00
qGuiApp->setBadgeNumber(count);
2022-09-25 21:05:08 +03:00
}
#endif