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 @@ -91,6 +91,11 @@ int BubbleItem::urgency() const
return m_urgency;
}

int BubbleItem::timeout() const
{
return m_entity.timeout();
}

QString BubbleItem::bodyImagePath() const
{
return m_entity.bodyIcon();
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 @@ -32,6 +32,7 @@ class BubbleItem : public QObject
uint replacesId() const;
bool isReplace() const;
int urgency() const;
int timeout() const;
QString bodyImagePath() const;
qint64 ctime() const;

Expand Down
40 changes: 38 additions & 2 deletions panels/notification/bubble/bubblemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace notification {

static const int BlockItemTimeout = 1000;

BubbleModel::BubbleModel(QObject *parent)
: QAbstractListModel(parent)
, m_updateTimeTipTimer(new QTimer(this))
Expand All @@ -41,6 +43,9 @@
m_processPendingTimer->start();
}
});
connect(&m_expireTimer, &ExpireTimer::expired, this, [this](qint64 id, const QVariant &data) {
Q_EMIT bubbleExpired(id, data.toUInt());
});

connect(NotifySetting::instance(), &NotifySetting::contentRowCountChanged, this, &BubbleModel::updateContentRowCount);
connect(NotifySetting::instance(), &NotifySetting::bubbleCountChanged, this, &BubbleModel::updateBubbleCount);
Expand Down Expand Up @@ -82,6 +87,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.
m_expireTimer.start(bubble->id(), effectiveTimeout(bubble->urgency(), bubble->timeout()), bubble->bubbleId());
}

bool BubbleModel::isReplaceBubble(const BubbleItem *bubble) const
Expand All @@ -95,9 +104,17 @@
const auto replaceIndex = replaceBubbleIndex(bubble);
const auto oldBubble = m_bubbles[replaceIndex];

m_expireTimer.stop(oldBubble->id());

m_bubbles.replace(replaceIndex, bubble);
Q_EMIT dataChanged(index(replaceIndex), index(replaceIndex));

m_expireTimer.start(bubble->id(), effectiveTimeout(bubble->urgency(), bubble->timeout()), bubble->bubbleId());

// If the replaced bubble was the hovered one, keep blocking the new one.
if (m_blockedId == oldBubble->id())
m_expireTimer.pause(bubble->id());

return oldBubble;
}

Expand All @@ -109,6 +126,9 @@
qDeleteAll(m_pendingBubbles);
m_pendingBubbles.clear();

m_blockedId = NotifyEntity::InvalidId;
m_expireTimer.clear();

if (m_bubbles.count() <= 0)
return;
beginResetModel();
Expand All @@ -129,11 +149,12 @@
if (index < 0 || index >= m_bubbles.size())
return;

beginRemoveRows(QModelIndex(), index, index);
auto bubble = m_bubbles.takeAt(index);
m_expireTimer.stop(bubble->id());

beginRemoveRows(QModelIndex(), index, index);
bubble->deleteLater();
endRemoveRows();

}

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

void BubbleModel::setBlockedId(qint64 id)

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

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setBlockedId' is never used.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样的话,进入了暂存区域的通知没有超时的机制了,

{
if (id == m_blockedId)
return;

if (m_blockedId != NotifyEntity::InvalidId)
m_expireTimer.resume(m_blockedId, BlockItemTimeout);

m_blockedId = id;

if (id != NotifyEntity::InvalidId)
m_expireTimer.pause(id);
}

} // notification
13 changes: 12 additions & 1 deletion panels/notification/bubble/bubblemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

#pragma once

#include "dsglobal.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsglobal.h" not found.
#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 "expiretimer.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "expiretimer.h" not found.

#include <QAbstractListModel>

Check warning on line 11 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 12 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 13 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 @@ -38,6 +40,10 @@
explicit BubbleModel(QObject *parent = nullptr);
~BubbleModel() override;

Q_SIGNALS:
// Emitted when a bubble reaches its expire timeout and should be closed.
void bubbleExpired(qint64 id, uint bubbleId);

public:
void push(BubbleItem *bubble);

Expand All @@ -51,6 +57,10 @@
BubbleItem *removeById(qint64 id);
void clear();

// Pause/resume the expire timer of the hovered bubble so hovering
// keeps the bubble on screen (0 clears the blocked bubble).
void setBlockedId(qint64 id);

BubbleItem *bubbleItem(int bubbleIndex) const;

int rowCount(const QModelIndex &parent) const override;
Expand All @@ -68,11 +78,12 @@
void updateBubbleTimeTip();
void updateContentRowCount(int rowCount);

private:
QTimer *m_updateTimeTipTimer = nullptr;
QTimer *m_processPendingTimer = nullptr;
ExpireTimer m_expireTimer;
QList<BubbleItem *> m_bubbles;
QQueue<BubbleItem *> m_pendingBubbles;
qint64 m_blockedId = NotifyEntity::InvalidId;
int m_maxKeep{5};
int m_contentRowCount{6};
};
Expand Down
10 changes: 9 additions & 1 deletion panels/notification/bubble/bubblepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ bool BubblePanel::init()

connect(m_bubbles, &BubbleModel::rowsInserted, this, &BubblePanel::onBubbleCountChanged);
connect(m_bubbles, &BubbleModel::rowsRemoved, this, &BubblePanel::onBubbleCountChanged);
// The bubble model runs one expire timer per shown bubble. When a bubble
// times out, close it and notify the server so it moves the notification
// from the in-memory store to the center database and emits the signals.
connect(m_bubbles, &BubbleModel::bubbleExpired, this, [this](qint64 id, uint bubbleId) {
closeBubble(id);
QMetaObject::invokeMethod(m_notificationServer, "notificationClosed", Qt::DirectConnection,
Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(uint, NotifyEntity::Expired));
});

return true;
}
Expand Down Expand Up @@ -217,7 +225,7 @@ void BubblePanel::setEnabled(bool newEnabled)

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

Expand Down
22 changes: 21 additions & 1 deletion panels/notification/center/notifystagingmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ 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);

connect(&m_expireTimer, &ExpireTimer::expired, this, [this](qint64 id, const QVariant &) {
closeNotify(id, NotifyEntity::Expired);
});
}

void NotifyStagingModel::close()
{
qDebug(notifyLog) << "close";

m_expireTimer.clear();

beginResetModel();
qDeleteAll(m_appNotifies);
m_appNotifies.clear();
Expand Down Expand Up @@ -63,6 +69,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.
m_expireTimer.start(entity.id(), effectiveTimeout(entity.urgency(), entity.timeout()));

if (m_refreshTimer < 0) {
m_refreshTimer = startTimer(std::chrono::milliseconds(1000));
}
Expand Down Expand Up @@ -90,6 +100,8 @@ void NotifyStagingModel::remove(qint64 id)
{
qDebug(notifyLog) << "Remove notify by id" << id;

m_expireTimer.stop(id);

int row = -1;
for (int i = 0; i < m_appNotifies.size(); i++) {
auto item = m_appNotifies[i];
Expand Down Expand Up @@ -146,6 +158,7 @@ void NotifyStagingModel::remove(qint64 id)
auto notify = new AppNotifyItem(newEntity);
m_appNotifies.insert(insertedIndex, notify);
endInsertRows();
m_expireTimer.start(newEntity.id(), effectiveTimeout(newEntity.urgency(), newEntity.timeout()));
}
}
updateOverlapCount(entities.size());
Expand All @@ -155,6 +168,8 @@ void NotifyStagingModel::open()
{
qDebug(notifyLog) << "Open staging model";

m_expireTimer.clear();

auto entities = m_accessor->fetchEntities(DataAccessor::AllApp(), NotifyEntity::NotProcessed, BubbleMaxCount + OverlayMaxCount);

qDebug(notifyLog) << "Fetched staging size" << entities.size();
Expand All @@ -172,6 +187,9 @@ void NotifyStagingModel::open()
auto notify = new AppNotifyItem(entities.at(i));
m_appNotifies << notify;
}
for (const auto &entity : entities) {
m_expireTimer.start(entity.id(), effectiveTimeout(entity.urgency(), entity.timeout()));
}
updateOverlapCount(entities.size());

endResetModel();
Expand Down Expand Up @@ -251,7 +269,9 @@ void NotifyStagingModel::replace(const NotifyEntity &entity)
for (int i = 0; i < m_appNotifies.size(); i++) {
auto item = m_appNotifies[i];
if (item->id() == entity.bubbleId()) {
m_expireTimer.stop(entity.bubbleId());
item->setEntity(entity);
m_expireTimer.start(entity.id(), effectiveTimeout(entity.urgency(), entity.timeout()));
const auto index = this->index(i, 0, {});
dataChanged(index, index);
break;
Expand Down Expand Up @@ -333,9 +353,9 @@ void NotifyStagingModel::updateContentRowCount(int rowCount)
return;

m_contentRowCount = rowCount;

if (!m_appNotifies.isEmpty()) {
dataChanged(index(0), index(m_appNotifies.size() - 1), {NotifyRole::NotifyContentRowCount});
}
}

}
7 changes: 6 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 All @@ -9,7 +9,8 @@
#include <QtQml/qqml.h>

#include "notifyitem.h"
#include "dataaccessor.h"

Check warning on line 12 in panels/notification/center/notifystagingmodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dataaccessor.h" not found.
#include "expiretimer.h"

Check warning on line 13 in panels/notification/center/notifystagingmodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "expiretimer.h" not found.

namespace notifycenter {
/**
Expand Down Expand Up @@ -73,5 +74,9 @@
DataAccessor *m_accessor = nullptr;
int m_overlapCount = 0;
int m_contentRowCount = 6;
// Notifications shown in the staging area (notification center) need their
// own expire timeout because the bubble panel is disabled while the center
// window is open, so the bubble-side timers are not running.
ExpireTimer m_expireTimer;
};
}
Loading
Loading