From a18257ee17925389cfcd9981ab72d861bdb467bc Mon Sep 17 00:00:00 2001 From: Akseli Lahtinen Date: Sun, 10 Sep 2023 20:57:39 +0000 Subject: [PATCH] Taskbar badge highlight counter Instead of the taskbar badge showing count for all notifications, only show the count for total highlights. --- src/models/roomlistmodel.cpp | 28 +++++++++++++++++++++++++--- src/models/roomlistmodel.h | 4 ++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index 4c5171a72..bb250103c 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -36,13 +36,13 @@ RoomListModel::RoomListModel(QObject *parent) m_categoryVisibility[collapsedSection] = false; } - connect(this, &RoomListModel::notificationCountChanged, this, [this]() { + connect(this, &RoomListModel::highlightCountChanged, this, [this]() { #if QT_VERSION < QT_VERSION_CHECK(6, 6, 0) #ifndef Q_OS_ANDROID // copied from Telegram desktop const auto launcherUrl = "application://org.kde.neochat.desktop"_ls; // Gnome requires that count is a 64bit integer - const qint64 counterSlice = std::min(m_notificationCount, 9999); + const qint64 counterSlice = std::min(m_highlightCount, 9999); QVariantMap dbusUnityProperties; if (counterSlice > 0) { @@ -59,7 +59,7 @@ RoomListModel::RoomListModel(QObject *parent) QDBusConnection::sessionBus().send(signal); #endif // Q_OS_ANDROID #else - qGuiApp->setBadgeNumber(m_notificationCount); + qGuiApp->setBadgeNumber(m_highlightCount); #endif // QT_VERSION_CHECK(6, 6, 0) }); connect(&SpaceHierarchyCache::instance(), &SpaceHierarchyCache::spaceHierarchyChanged, this, [this]() { @@ -162,6 +162,9 @@ void RoomListModel::connectRoomSignals(NeoChatRoom *room) connect(room, &Room::notificationCountChanged, this, [this, room] { refresh(room); }); + connect(room, &Room::highlightCountChanged, this, [this, room] { + refresh(room); + }); connect(room, &Room::avatarChanged, this, [this, room] { refresh(room, {AvatarRole}); }); @@ -178,6 +181,7 @@ void RoomListModel::connectRoomSignals(NeoChatRoom *room) refresh(room, {LastEventRole, SubtitleTextRole}); }); connect(room, &Room::unreadStatsChanged, this, &RoomListModel::refreshNotificationCount); + connect(room, &Room::highlightCountChanged, this, &RoomListModel::refreshHighlightCount); } int RoomListModel::notificationCount() const @@ -185,6 +189,11 @@ int RoomListModel::notificationCount() const return m_notificationCount; } +int RoomListModel::highlightCount() const +{ + return m_highlightCount; +} + void RoomListModel::refreshNotificationCount() { int count = 0; @@ -198,6 +207,19 @@ void RoomListModel::refreshNotificationCount() Q_EMIT notificationCountChanged(); } +void RoomListModel::refreshHighlightCount() +{ + int count = 0; + for (auto room : std::as_const(m_rooms)) { + count += room->highlightCount(); + } + if (m_highlightCount == count) { + return; + } + m_highlightCount = count; + Q_EMIT highlightCountChanged(); +} + void RoomListModel::updateRoom(Room *room, Room *prev) { // There are two cases when this method is called: diff --git a/src/models/roomlistmodel.h b/src/models/roomlistmodel.h index c675442c0..c085ec3e1 100644 --- a/src/models/roomlistmodel.h +++ b/src/models/roomlistmodel.h @@ -85,6 +85,7 @@ public: void setConnection(Quotient::Connection *connection); [[nodiscard]] int notificationCount() const; + [[nodiscard]] int highlightCount() const; /** * @brief Get the given role value at the given index. @@ -155,6 +156,7 @@ private Q_SLOTS: void deleteRoom(Quotient::Room *room); void refresh(NeoChatRoom *room, const QVector &roles = {}); void refreshNotificationCount(); + void refreshHighlightCount(); private: Quotient::Connection *m_connection = nullptr; @@ -163,6 +165,7 @@ private: QMap m_categoryVisibility; int m_notificationCount = 0; + int m_highlightCount = 0; QString m_activeSpaceId; void connectRoomSignals(NeoChatRoom *room); @@ -170,6 +173,7 @@ private: Q_SIGNALS: void connectionChanged(); void notificationCountChanged(); + void highlightCountChanged(); void roomAdded(NeoChatRoom *_t1); };