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
39 changes: 19 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 @@ -41,6 +42,12 @@
m_processPendingTimer->start();
}
});
connect(ExpireTimer::instance(), &ExpireTimer::expired, this, [this](qint64 id, uint bubbleId) {
// A bubble that has been pushed off the display (overflow) is no longer
// in the model, but its countdown still finishes and the notification
// should still be closed.
Q_EMIT bubbleExpired(id, bubbleId);
});

connect(NotifySetting::instance(), &NotifySetting::contentRowCountChanged, this, &BubbleModel::updateContentRowCount);
connect(NotifySetting::instance(), &NotifySetting::bubbleCountChanged, this, &BubbleModel::updateBubbleCount);
Expand Down Expand Up @@ -82,6 +89,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 +109,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();
// 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());

if (m_bubbles.count() <= 0)
return;
beginResetModel();
qDeleteAll(m_bubbles);
m_bubbles.clear();
endResetModel();

m_updateTimeTipTimer->stop();
return oldBubble;
}

QList<BubbleItem *> BubbleModel::items() const
Expand All @@ -131,9 +129,9 @@

beginRemoveRows(QModelIndex(), index, index);
auto bubble = m_bubbles.takeAt(index);
ExpireTimer::instance()->remove(bubble->entity());
bubble->deleteLater();
endRemoveRows();

}

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

} // notification
7 changes: 5 additions & 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 @@ -38,6 +39,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 @@ -49,7 +54,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 +72,6 @@
void updateBubbleTimeTip();
void updateContentRowCount(int rowCount);

private:
QTimer *m_updateTimeTipTimer = nullptr;
QTimer *m_processPendingTimer = nullptr;
QList<BubbleItem *> m_bubbles;
Expand Down
11 changes: 10 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 @@ -53,6 +54,14 @@

connect(m_bubbles, &BubbleModel::rowsInserted, this, &BubblePanel::onBubbleCountChanged);
connect(m_bubbles, &BubbleModel::rowsRemoved, this, &BubblePanel::onBubbleCountChanged);
// ExpireTimer tracks the countdown of every shown bubble. When a bubble
// times out, tell the server so it moves the notification from the
// in-memory store to the center database; the server then emits
// NotificationStateChanged which closes the bubble through the normal flow.
connect(m_bubbles, &BubbleModel::bubbleExpired, this, [this](qint64 id, uint bubbleId) {
QMetaObject::invokeMethod(m_notificationServer, "notificationClosed", Qt::AutoConnection,
Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(uint, NotifyEntity::Expired));
});

return true;
}
Expand Down Expand Up @@ -217,7 +226,7 @@

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

Expand Down
23 changes: 22 additions & 1 deletion 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,11 @@ 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(ExpireTimer::instance(), &ExpireTimer::expired, this, [this](qint64 id, uint bubbleId) {

@18202781743 18202781743 Aug 13, 2026

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.

一个通知发送了expired后,会不会被通知横幅和暂存区都close一次呀,
是不是可以直接由ExpireTimer调用server的close呀,

Q_UNUSED(bubbleId)
closeNotify(id, NotifyEntity::Expired);
});
}

void NotifyStagingModel::close()
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.
ExpireTimer::instance()->push(entity);

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

const auto entity = notifyById(id);
if (entity.isValid())
ExpireTimer::instance()->remove(entity);

int row = -1;
for (int i = 0; i < m_appNotifies.size(); i++) {
auto item = m_appNotifies[i];
Expand Down Expand Up @@ -146,6 +160,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 @@ -172,6 +187,9 @@ void NotifyStagingModel::open()
auto notify = new AppNotifyItem(entities.at(i));
m_appNotifies << notify;
}
for (const auto &entity : entities) {
ExpireTimer::instance()->push(entity);
}
updateOverlapCount(entities.size());

endResetModel();
Expand Down Expand Up @@ -250,8 +268,11 @@ 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()) {
if (item->id() == entity.id()) {
// 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(i, 0, {});
dataChanged(index, index);
break;
Expand Down
Loading
Loading