mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Unread messages count as an Unity compatible badge (#1085)
Co-authored-by: DeepBlueV7.X <nicolas.werner@hotmail.de>
This commit is contained in:
parent
163ef6ebdc
commit
0e02024084
5 changed files with 116 additions and 0 deletions
|
@ -354,6 +354,8 @@ set(SRC_FILES
|
||||||
# Generic notification stuff
|
# Generic notification stuff
|
||||||
src/notifications/Manager.cpp
|
src/notifications/Manager.cpp
|
||||||
|
|
||||||
|
src/dock/Dock.cpp
|
||||||
|
|
||||||
src/AvatarProvider.cpp
|
src/AvatarProvider.cpp
|
||||||
src/BlurhashProvider.cpp
|
src/BlurhashProvider.cpp
|
||||||
src/Cache.cpp
|
src/Cache.cpp
|
||||||
|
@ -551,6 +553,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
||||||
src/encryption/VerificationManager.h
|
src/encryption/VerificationManager.h
|
||||||
|
|
||||||
src/notifications/Manager.h
|
src/notifications/Manager.h
|
||||||
|
src/dock/Dock.h
|
||||||
|
|
||||||
src/AvatarProvider.h
|
src/AvatarProvider.h
|
||||||
src/BlurhashProvider.h
|
src/BlurhashProvider.h
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
#include "UsersModel.h"
|
#include "UsersModel.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
#include "dock/Dock.h"
|
||||||
#include "emoji/EmojiModel.h"
|
#include "emoji/EmojiModel.h"
|
||||||
#include "emoji/Provider.h"
|
#include "emoji/Provider.h"
|
||||||
#include "encryption/DeviceVerificationFlow.h"
|
#include "encryption/DeviceVerificationFlow.h"
|
||||||
|
@ -99,6 +100,8 @@ MainWindow::MainWindow(QWindow *parent)
|
||||||
SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
|
SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
|
||||||
|
|
||||||
trayIcon_->setVisible(userSettings_->tray());
|
trayIcon_->setVisible(userSettings_->tray());
|
||||||
|
dock_ = new Dock(this);
|
||||||
|
connect(chat_page_, SIGNAL(unreadMessages(int)), dock_, SLOT(setUnreadCount(int)));
|
||||||
|
|
||||||
// load cache on event loop
|
// load cache on event loop
|
||||||
QTimer::singleShot(0, this, [this] {
|
QTimer::singleShot(0, this, [this] {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
|
#include "dock/Dock.h"
|
||||||
|
|
||||||
#include "jdenticoninterface.h"
|
#include "jdenticoninterface.h"
|
||||||
|
|
||||||
|
@ -104,6 +105,7 @@ private:
|
||||||
QSharedPointer<UserSettings> userSettings_;
|
QSharedPointer<UserSettings> userSettings_;
|
||||||
//! Tray icon that shows the unread message count.
|
//! Tray icon that shows the unread message count.
|
||||||
TrayIcon *trayIcon_;
|
TrayIcon *trayIcon_;
|
||||||
|
Dock *dock_;
|
||||||
|
|
||||||
MxcImageProvider *imgProvider = nullptr;
|
MxcImageProvider *imgProvider = nullptr;
|
||||||
|
|
||||||
|
|
81
src/dock/Dock.cpp
Normal file
81
src/dock/Dock.cpp
Normal file
|
@ -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
|
27
src/dock/Dock.h
Normal file
27
src/dock/Dock.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <QObject>
|
||||||
|
#if defined(NHEKO_DBUS_SYS)
|
||||||
|
#include <QDBusServiceWatcher>
|
||||||
|
#include <QtDBus/QDBusArgument>
|
||||||
|
#include <QtDBus/QDBusInterface>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Dock : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Dock(QObject *parent = nullptr);
|
||||||
|
public slots:
|
||||||
|
void setUnreadCount(const int count);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if defined(NHEKO_DBUS_SYS)
|
||||||
|
void unitySetNotificationCount(const int count);
|
||||||
|
QDBusServiceWatcher *unityServiceWatcher = nullptr;
|
||||||
|
bool unityServiceAvailable = false;
|
||||||
|
#endif
|
||||||
|
};
|
Loading…
Reference in a new issue