Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions panels/notification/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ add_library(ds-notification-shared SHARED
${CMAKE_SOURCE_DIR}/panels/notification/common/dbaccessor.cpp
${CMAKE_SOURCE_DIR}/panels/notification/common/notifysetting.h
${CMAKE_SOURCE_DIR}/panels/notification/common/notifysetting.cpp
${CMAKE_SOURCE_DIR}/panels/notification/common/expiretimer.h
${CMAKE_SOURCE_DIR}/panels/notification/common/expiretimer.cpp
)

set_target_properties(ds-notification-shared PROPERTIES
Expand Down
5 changes: 5 additions & 0 deletions panels/notification/bubble/bubbleitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ qint64 BubbleItem::id() const
return m_entity.id();
}

const NotifyEntity &BubbleItem::entity() const
{
return m_entity;
}

uint BubbleItem::bubbleId() const
{
return m_entity.bubbleId();
Expand Down
1 change: 1 addition & 0 deletions panels/notification/bubble/bubbleitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

public:
void setEntity(const NotifyEntity &entity);
const NotifyEntity &entity() const;

public:
qint64 id() const;

Check warning on line 27 in panels/notification/bubble/bubbleitem.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'id' shadows outer function
uint bubbleId() const;
QString appName() const;
QString appIcon() const;
Expand Down
32 changes: 12 additions & 20 deletions panels/notification/bubble/bubblemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#include "bubblemodel.h"

#include <notifysetting.h>

Check warning on line 7 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <notifysetting.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "bubbleitem.h"
#include "expiretimer.h"

Check warning on line 10 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "expiretimer.h" not found.

#include <QTimer>

Check warning on line 12 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 13 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QImage>
#include <QTemporaryFile>
#include <QUrl>
Expand Down Expand Up @@ -82,6 +83,10 @@
beginInsertRows(QModelIndex(), 0, 0);
m_bubbles.prepend(bubble);
endInsertRows();

// A non-positive interval (Critical urgency or expireTimeout 0) means the
// bubble never expires on its own.
ExpireTimer::instance()->push(bubble->entity());
}

bool BubbleModel::isReplaceBubble(const BubbleItem *bubble) const
Expand All @@ -98,25 +103,12 @@
m_bubbles.replace(replaceIndex, bubble);
Q_EMIT dataChanged(index(replaceIndex), index(replaceIndex));

return oldBubble;
}

void BubbleModel::clear()
{
if (m_processPendingTimer) {
m_processPendingTimer->stop();
}
qDeleteAll(m_pendingBubbles);
m_pendingBubbles.clear();

if (m_bubbles.count() <= 0)
return;
beginResetModel();
qDeleteAll(m_bubbles);
m_bubbles.clear();
endResetModel();
// The replacement shares the bubble slot of the old bubble; ExpireTimer
// cancels the old countdown (transferring a hover block) and starts a new
// one, so just push it like insertBubble() does.
ExpireTimer::instance()->push(bubble->entity());

m_updateTimeTipTimer->stop();
return oldBubble;
}

QList<BubbleItem *> BubbleModel::items() const
Expand All @@ -133,7 +125,6 @@
auto bubble = m_bubbles.takeAt(index);
bubble->deleteLater();
endRemoveRows();

}

void BubbleModel::remove(const BubbleItem *bubble)
Expand Down Expand Up @@ -298,4 +289,5 @@
Q_EMIT dataChanged(index(0), index(m_bubbles.size() - 1), {BubbleModel::ContentRowCount});
}
}
}

} // notification
3 changes: 1 addition & 2 deletions panels/notification/bubble/bubblemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#pragma once

#include "dsglobal.h"
#include "notifyentity.h"

Check warning on line 8 in panels/notification/bubble/bubblemodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "notifyentity.h" not found.

#include <QAbstractListModel>

Check warning on line 10 in panels/notification/bubble/bubblemodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QAbstractListModel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QHash>

Check warning on line 11 in panels/notification/bubble/bubblemodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QHash> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QQueue>

Check warning on line 12 in panels/notification/bubble/bubblemodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQueue> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class QTimer;

Expand Down Expand Up @@ -49,7 +50,6 @@
Q_INVOKABLE void remove(int index);
void remove(const BubbleItem *bubble);
BubbleItem *removeById(qint64 id);
void clear();

BubbleItem *bubbleItem(int bubbleIndex) const;

Expand All @@ -68,7 +68,6 @@
void updateBubbleTimeTip();
void updateContentRowCount(int rowCount);

private:
QTimer *m_updateTimeTipTimer = nullptr;
QTimer *m_processPendingTimer = nullptr;
QList<BubbleItem *> m_bubbles;
Expand Down
3 changes: 2 additions & 1 deletion panels/notification/bubble/bubblepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "bubblepanel.h"
#include "bubbleitem.h"
#include "bubblemodel.h"
#include "dataaccessorproxy.h"

Check warning on line 8 in panels/notification/bubble/bubblepanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dataaccessorproxy.h" not found.
#include "expiretimer.h"
#include "pluginfactory.h"

#include <QTimer>
Expand Down Expand Up @@ -217,7 +218,7 @@

void BubblePanel::setHoveredId(qint64 id)
{
QMetaObject::invokeMethod(m_notificationServer, "setBlockClosedId", Qt::DirectConnection, Q_ARG(qint64, id));
ExpireTimer::instance()->setBlockId(id);
}
}

Expand Down
52 changes: 42 additions & 10 deletions panels/notification/center/notifystagingmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QLoggingCategory>

#include "dataaccessorproxy.h"
#include "expiretimer.h"
#include "notifyaccessor.h"
#include "notifyentity.h"
#include "notifyitem.h"
Expand All @@ -25,6 +26,13 @@ NotifyStagingModel::NotifyStagingModel(QObject *parent)
connect(NotifyAccessor::instance(), &NotifyAccessor::stagingEntityReceived, this, &NotifyStagingModel::doEntityReceived);
connect(NotifyAccessor::instance(), &NotifyAccessor::stagingEntityClosed, this, &NotifyStagingModel::onEntityClosed);
connect(NotifySetting::instance(), &NotifySetting::contentRowCountChanged, this, &NotifyStagingModel::updateContentRowCount);
// No direct reaction to ExpireTimer::expired here: the server is the single
// owner of the close on expiry (it listens to expired itself and marks the
// notification processed), and this model drops its row via the resulting
// stagingEntityClosed. Reacting locally would remove + refill while the
// server-side close is still queued on the worker thread, so the just-expired
// notification would still read as NotProcessed and be re-inserted with a
// fresh countdown.
}

void NotifyStagingModel::close()
Expand Down Expand Up @@ -63,6 +71,10 @@ void NotifyStagingModel::push(const NotifyEntity &entity)
updateOverlapCount(count);
}

// A non-positive interval (Critical urgency or expireTimeout 0) means the
// notification never expires on its own.
ExpireTimer::instance()->push(entity);

if (m_refreshTimer < 0) {
m_refreshTimer = startTimer(std::chrono::milliseconds(1000));
}
Expand Down Expand Up @@ -146,6 +158,7 @@ void NotifyStagingModel::remove(qint64 id)
auto notify = new AppNotifyItem(newEntity);
m_appNotifies.insert(insertedIndex, notify);
endInsertRows();
ExpireTimer::instance()->push(newEntity);
}
}
updateOverlapCount(entities.size());
Expand All @@ -169,8 +182,10 @@ void NotifyStagingModel::open()

const auto count = std::min(static_cast<int>(entities.size()), BubbleMaxCount);
for (int i = 0; i < count; i++) {
auto notify = new AppNotifyItem(entities.at(i));
const auto &entity = entities.at(i);
auto notify = new AppNotifyItem(entity);
m_appNotifies << notify;
ExpireTimer::instance()->push(entity);
}
updateOverlapCount(entities.size());

Expand Down Expand Up @@ -246,17 +261,33 @@ NotifyEntity NotifyStagingModel::notifyById(qint64 id) const
return {};
}

void NotifyStagingModel::replace(const NotifyEntity &entity)
int NotifyStagingModel::rowByBubbleId(uint bubbleId) const
{
for (int i = 0; i < m_appNotifies.size(); i++) {
auto item = m_appNotifies[i];
if (item->id() == entity.bubbleId()) {
item->setEntity(entity);
const auto index = this->index(i, 0, {});
dataChanged(index, index);
break;
}
if (m_appNotifies[i]->entity().bubbleId() == bubbleId)
return i;
}
return -1;
}

void NotifyStagingModel::replace(const NotifyEntity &entity)
{
// A replacement keeps the same bubble id as the replaced notification, so
// it is matched by bubble id, exactly like BubbleModel::replaceBubbleIndex:
// a replacement may carry a fresh entity id (marked-processed then re-added)
// or the original entity id (replaceEntity), so the entity id alone is not
// a reliable key.
const int row = rowByBubbleId(entity.bubbleId());
if (row < 0)
return;

auto item = m_appNotifies[row];
// push() handles the replacement internally: it cancels the old countdown
// of the same bubble slot and starts the new one.
item->setEntity(entity);
ExpireTimer::instance()->push(entity);
const auto index = this->index(row, 0, {});
dataChanged(index, index);
}

QHash<int, QByteArray> NotifyStagingModel::roleNames() const
Expand Down Expand Up @@ -299,12 +330,13 @@ int NotifyStagingModel::overlapCount() const
void NotifyStagingModel::doEntityReceived(qint64 id)
{
qDebug(notifyLog) << "Receive entity" << id;

auto entity = m_accessor->fetchEntity(id);
if (!entity.isValid()) {
qWarning(notifyLog) << "Received invalid entity:" << id << ", appName:" << entity.appName();
return;
}
if (entity.isReplace() && notifyById(id).isValid()) {
if (entity.isReplace() && rowByBubbleId(entity.bubbleId()) >= 0) {
replace(entity);
} else {
push(entity);
Expand Down
3 changes: 2 additions & 1 deletion panels/notification/center/notifystagingmodel.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -64,6 +64,7 @@ private slots:
void remove(qint64 id);
void updateTime();
NotifyEntity notifyById(qint64 id) const;
int rowByBubbleId(uint bubbleId) const;

private:
QList<AppNotifyItem *> m_appNotifies;
Expand Down
Loading
Loading