Add launcher badge to NeoChat showing the unread count
This commit is contained in:
@@ -14,11 +14,26 @@
|
|||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
#endif
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
bool useUnityCounter() {
|
||||||
|
static const auto Result = QDBusInterface(
|
||||||
|
"com.canonical.Unity",
|
||||||
|
"/").isValid();
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
RoomListModel::RoomListModel(QObject *parent)
|
RoomListModel::RoomListModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
@@ -26,6 +41,37 @@ RoomListModel::RoomListModel(QObject *parent)
|
|||||||
for (auto collapsedSection : collapsedSections) {
|
for (auto collapsedSection : collapsedSections) {
|
||||||
m_categoryVisibility[collapsedSection] = false;
|
m_categoryVisibility[collapsedSection] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
connect(this, &RoomListModel::notificationCountChanged, this, [this]() {
|
||||||
|
if (useUnityCounter()) {
|
||||||
|
// copied from Telegram desktop
|
||||||
|
const auto launcherUrl = "application://org.kde.neochat.desktop";
|
||||||
|
// Gnome requires that count is a 64bit integer
|
||||||
|
const qint64 counterSlice = std::min(m_notificationCount, 9999);
|
||||||
|
QVariantMap dbusUnityProperties;
|
||||||
|
|
||||||
|
if (counterSlice > 0) {
|
||||||
|
dbusUnityProperties["count"] = counterSlice;
|
||||||
|
dbusUnityProperties["count-visible"] = true;
|
||||||
|
} else {
|
||||||
|
dbusUnityProperties["count-visible"] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto signal = QDBusMessage::createSignal(
|
||||||
|
"/com/canonical/unity/launcherentry/org.kde.neochat",
|
||||||
|
"com.canonical.Unity.LauncherEntry",
|
||||||
|
"Update");
|
||||||
|
|
||||||
|
signal.setArguments({
|
||||||
|
launcherUrl,
|
||||||
|
dbusUnityProperties
|
||||||
|
});
|
||||||
|
|
||||||
|
QDBusConnection::sessionBus().send(signal);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomListModel::~RoomListModel() = default;
|
RoomListModel::~RoomListModel() = default;
|
||||||
@@ -182,6 +228,9 @@ void RoomListModel::refreshNotificationCount()
|
|||||||
for (auto room : qAsConst(m_rooms)) {
|
for (auto room : qAsConst(m_rooms)) {
|
||||||
count += room->notificationCount();
|
count += room->notificationCount();
|
||||||
}
|
}
|
||||||
|
if (m_notificationCount == count) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_notificationCount = count;
|
m_notificationCount = count;
|
||||||
Q_EMIT notificationCountChanged();
|
Q_EMIT notificationCountChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user