Taskbar badge highlight counter
Instead of the taskbar badge showing count for all notifications, only show the count for total highlights.
This commit is contained in:
committed by
Tobias Fella
parent
def46d90a8
commit
a18257ee17
@@ -36,13 +36,13 @@ RoomListModel::RoomListModel(QObject *parent)
|
|||||||
m_categoryVisibility[collapsedSection] = false;
|
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)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
// copied from Telegram desktop
|
// copied from Telegram desktop
|
||||||
const auto launcherUrl = "application://org.kde.neochat.desktop"_ls;
|
const auto launcherUrl = "application://org.kde.neochat.desktop"_ls;
|
||||||
// Gnome requires that count is a 64bit integer
|
// 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;
|
QVariantMap dbusUnityProperties;
|
||||||
|
|
||||||
if (counterSlice > 0) {
|
if (counterSlice > 0) {
|
||||||
@@ -59,7 +59,7 @@ RoomListModel::RoomListModel(QObject *parent)
|
|||||||
QDBusConnection::sessionBus().send(signal);
|
QDBusConnection::sessionBus().send(signal);
|
||||||
#endif // Q_OS_ANDROID
|
#endif // Q_OS_ANDROID
|
||||||
#else
|
#else
|
||||||
qGuiApp->setBadgeNumber(m_notificationCount);
|
qGuiApp->setBadgeNumber(m_highlightCount);
|
||||||
#endif // QT_VERSION_CHECK(6, 6, 0)
|
#endif // QT_VERSION_CHECK(6, 6, 0)
|
||||||
});
|
});
|
||||||
connect(&SpaceHierarchyCache::instance(), &SpaceHierarchyCache::spaceHierarchyChanged, this, [this]() {
|
connect(&SpaceHierarchyCache::instance(), &SpaceHierarchyCache::spaceHierarchyChanged, this, [this]() {
|
||||||
@@ -162,6 +162,9 @@ void RoomListModel::connectRoomSignals(NeoChatRoom *room)
|
|||||||
connect(room, &Room::notificationCountChanged, this, [this, room] {
|
connect(room, &Room::notificationCountChanged, this, [this, room] {
|
||||||
refresh(room);
|
refresh(room);
|
||||||
});
|
});
|
||||||
|
connect(room, &Room::highlightCountChanged, this, [this, room] {
|
||||||
|
refresh(room);
|
||||||
|
});
|
||||||
connect(room, &Room::avatarChanged, this, [this, room] {
|
connect(room, &Room::avatarChanged, this, [this, room] {
|
||||||
refresh(room, {AvatarRole});
|
refresh(room, {AvatarRole});
|
||||||
});
|
});
|
||||||
@@ -178,6 +181,7 @@ void RoomListModel::connectRoomSignals(NeoChatRoom *room)
|
|||||||
refresh(room, {LastEventRole, SubtitleTextRole});
|
refresh(room, {LastEventRole, SubtitleTextRole});
|
||||||
});
|
});
|
||||||
connect(room, &Room::unreadStatsChanged, this, &RoomListModel::refreshNotificationCount);
|
connect(room, &Room::unreadStatsChanged, this, &RoomListModel::refreshNotificationCount);
|
||||||
|
connect(room, &Room::highlightCountChanged, this, &RoomListModel::refreshHighlightCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RoomListModel::notificationCount() const
|
int RoomListModel::notificationCount() const
|
||||||
@@ -185,6 +189,11 @@ int RoomListModel::notificationCount() const
|
|||||||
return m_notificationCount;
|
return m_notificationCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RoomListModel::highlightCount() const
|
||||||
|
{
|
||||||
|
return m_highlightCount;
|
||||||
|
}
|
||||||
|
|
||||||
void RoomListModel::refreshNotificationCount()
|
void RoomListModel::refreshNotificationCount()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@@ -198,6 +207,19 @@ void RoomListModel::refreshNotificationCount()
|
|||||||
Q_EMIT notificationCountChanged();
|
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)
|
void RoomListModel::updateRoom(Room *room, Room *prev)
|
||||||
{
|
{
|
||||||
// There are two cases when this method is called:
|
// There are two cases when this method is called:
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public:
|
|||||||
void setConnection(Quotient::Connection *connection);
|
void setConnection(Quotient::Connection *connection);
|
||||||
|
|
||||||
[[nodiscard]] int notificationCount() const;
|
[[nodiscard]] int notificationCount() const;
|
||||||
|
[[nodiscard]] int highlightCount() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the given role value at the given index.
|
* @brief Get the given role value at the given index.
|
||||||
@@ -155,6 +156,7 @@ private Q_SLOTS:
|
|||||||
void deleteRoom(Quotient::Room *room);
|
void deleteRoom(Quotient::Room *room);
|
||||||
void refresh(NeoChatRoom *room, const QVector<int> &roles = {});
|
void refresh(NeoChatRoom *room, const QVector<int> &roles = {});
|
||||||
void refreshNotificationCount();
|
void refreshNotificationCount();
|
||||||
|
void refreshHighlightCount();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Quotient::Connection *m_connection = nullptr;
|
Quotient::Connection *m_connection = nullptr;
|
||||||
@@ -163,6 +165,7 @@ private:
|
|||||||
QMap<int, bool> m_categoryVisibility;
|
QMap<int, bool> m_categoryVisibility;
|
||||||
|
|
||||||
int m_notificationCount = 0;
|
int m_notificationCount = 0;
|
||||||
|
int m_highlightCount = 0;
|
||||||
QString m_activeSpaceId;
|
QString m_activeSpaceId;
|
||||||
|
|
||||||
void connectRoomSignals(NeoChatRoom *room);
|
void connectRoomSignals(NeoChatRoom *room);
|
||||||
@@ -170,6 +173,7 @@ private:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void connectionChanged();
|
void connectionChanged();
|
||||||
void notificationCountChanged();
|
void notificationCountChanged();
|
||||||
|
void highlightCountChanged();
|
||||||
|
|
||||||
void roomAdded(NeoChatRoom *_t1);
|
void roomAdded(NeoChatRoom *_t1);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user