Skip to content
Merged
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
31 changes: 0 additions & 31 deletions panels/notification/bubble/bubblemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@
qDeleteAll(m_bubbles);
m_bubbles.clear();
endResetModel();
m_delayBubbles.clear();
m_delayRemovedBubble = NotifyEntity::InvalidId;

updateLevel();
m_updateTimeTipTimer->stop();
Expand Down Expand Up @@ -125,18 +123,10 @@
}
}

BubbleItem *BubbleModel::removeById(qint64 id)

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

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'removeById' is never used.
{
if (id == m_delayRemovedBubble) {
// Delayed remove
if (!m_delayBubbles.contains(id)) {
m_delayBubbles.append(id);
}
return nullptr;
}
for (const auto &item : m_bubbles) {
if (item->id() == id) {

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

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
m_delayBubbles.removeAll(id);
remove(m_bubbles.indexOf(item));
return item;
}
Expand Down Expand Up @@ -252,28 +242,7 @@
updateLevel();
}

qint64 BubbleModel::delayRemovedBubble() const
{
return m_delayRemovedBubble;
}

void BubbleModel::setDelayRemovedBubble(qint64 newDelayRemovedBubble)
{
if (m_delayRemovedBubble == newDelayRemovedBubble)
return;
const auto oldDelayRemovedBubble = m_delayRemovedBubble;
if (m_delayBubbles.contains(oldDelayRemovedBubble)) {
// Remove last delayed bubble.
QTimer::singleShot(DelayRemovBubbleTime, this, [this, oldDelayRemovedBubble]() {
removeById(oldDelayRemovedBubble);
});
}

m_delayRemovedBubble = newDelayRemovedBubble;
emit delayRemovedBubbleChanged();
}

void BubbleModel::clearInvalidBubbles()

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

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'clearInvalidBubbles' is never used.
{
for (int i = m_bubbles.count() - 1; i >= 0; i--) {
auto bubble = m_bubbles.at(i);
Expand Down
10 changes: 0 additions & 10 deletions panels/notification/bubble/bubblemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class BubbleItem;
class BubbleModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(qint64 delayRemovedBubble READ delayRemovedBubble WRITE setDelayRemovedBubble NOTIFY delayRemovedBubbleChanged FINAL)
public:
enum {
AppName = Qt::UserRole + 1,
Expand Down Expand Up @@ -61,14 +60,8 @@ class BubbleModel : public QAbstractListModel
int displayRowCount() const;
int overlayCount() const;

qint64 delayRemovedBubble() const;
void setDelayRemovedBubble(qint64 newDelayRemovedBubble);

void clearInvalidBubbles();

signals:
void delayRemovedBubbleChanged();

private:
void updateBubbleCount(int count);
int replaceBubbleIndex(const BubbleItem *bubble) const;
Expand All @@ -82,9 +75,6 @@ class BubbleModel : public QAbstractListModel
int BubbleMaxCount{3};
int m_contentRowCount{6};
const int OverlayMaxCount{2};
QList<qint64> m_delayBubbles;
qint64 m_delayRemovedBubble{NotifyEntity::InvalidId};
const int DelayRemovBubbleTime{1000};
};

}
4 changes: 4 additions & 0 deletions panels/notification/bubble/bubblepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
setVisible(!isEmpty && enabled());
}

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

#include "bubblepanel.moc"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "bubblepanel.moc" not found.
3 changes: 2 additions & 1 deletion panels/notification/bubble/bubblepanel.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 @@ -39,6 +39,7 @@ public Q_SLOTS:
void close(int bubbleIndex, int reason);
void delayProcess(int bubbleIndex);
void setEnabled(bool newEnabled);
void setHoveredId(qint64 id);

Q_SIGNALS:
void visibleChanged();
Expand Down
8 changes: 0 additions & 8 deletions panels/notification/bubble/package/Bubble.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ Control {
id: control
height: loader.height
property var bubble
onHoveredChanged: function () {
if (control.hovered) {
Applet.bubbles.delayRemovedBubble = bubble.id
} else {
Applet.bubbles.delayRemovedBubble = 0
}
}

Loader {
id: loader
width: control.width
Expand Down
18 changes: 18 additions & 0 deletions panels/notification/bubble/package/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,23 @@ Window {
width: 360
bubble: model
}

HoverHandler {
onPointChanged: {
const local = point.position
let hoveredItem = bubbleView.itemAt(local.x, local.y)
if (hoveredItem && hoveredItem.bubble) {
Applet.setHoveredId(hoveredItem.bubble.id)
} else {
Applet.setHoveredId(0)
}
}

onHoveredChanged: {
if (!hovered) {
Applet.setHoveredId(0)
}
}
}
}
}
33 changes: 32 additions & 1 deletion panels/notification/server/notificationmanager.cpp
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 @@ -37,6 +37,7 @@ namespace notification {

static const uint NoReplacesId = 0;
static const int DefaultTimeOutMSecs = 5000;
static const int BlockItemTimeout = 1000;
static const QString NotificationsDBusService = "org.freedesktop.Notifications";
static const QString NotificationsDBusPath = "/org/freedesktop/Notifications";
static const QString DDENotifyDBusServer = "org.deepin.dde.Notification1";
Expand Down Expand Up @@ -347,6 +348,30 @@ QVariant NotificationManager::GetSystemInfo(uint configItem)
return m_setting->systemValue(static_cast<NotificationSetting::SystemConfigItem>(configItem));
}

void NotificationManager::setBlockClosedId(qint64 id)
{
if (id == m_blockClosedId) {
return;
}

if(m_blockClosedId != NotifyEntity::InvalidId) {
auto findIter = std::find_if(m_pendingTimeoutEntities.begin(), m_pendingTimeoutEntities.end(), [this](const NotifyEntity &entity) {
return entity.id() == m_blockClosedId;
});

const auto current = QDateTime::currentMSecsSinceEpoch();
if (findIter != m_pendingTimeoutEntities.end()) {
if (current > findIter.key() - BlockItemTimeout) {
qDebug(notifyLog) << "Delay close bubble id:" << m_blockClosedId << "for the new block bubble id:" << id;
m_pendingTimeoutEntities.insert(current + BlockItemTimeout, findIter.value());
m_pendingTimeoutEntities.erase(findIter);
}
}
}
m_blockClosedId = id;
onHandingPendingEntities();
}

bool NotificationManager::isDoNotDisturb() const
{
if (!m_setting->systemValue(NotificationSetting::DNDMode).toBool())
Expand Down Expand Up @@ -673,6 +698,12 @@ void NotificationManager::onHandingPendingEntities()
continue;
}

if (item.id() == m_blockClosedId) {
qDebug(notifyLog) << "bubble id:" << item.bubbleId() << "entity id:" << item.id();
m_pendingTimeoutEntities.insert(current, item);
continue;
}

qDebug(notifyLog) << "Expired for the notification " << item.id() << item.appName();
notificationClosed(item.id(), item.bubbleId(), NotifyEntity::Expired);
}
Expand Down
4 changes: 3 additions & 1 deletion panels/notification/server/notificationmanager.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 @@ -65,6 +65,7 @@ public Q_SLOTS:
void SetSystemInfo(uint configItem, const QVariant &value);
QVariant GetSystemInfo(uint configItem);

void setBlockClosedId(qint64 id);
private:
bool isDoNotDisturb() const;
bool recordNotification(NotifyEntity &entity);
Expand Down Expand Up @@ -97,6 +98,7 @@ private slots:
QStringList m_systemApps;
QMap<QString, QVariant> m_appNamesMap;
int m_cleanupDays = 7;
qint64 m_blockClosedId = 0;
};

} // notification
7 changes: 6 additions & 1 deletion panels/notification/server/notifyserverapplet.cpp
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 @@ -104,6 +104,11 @@ void NotifyServerApplet::removeExpiredNotifications()
m_manager->removeExpiredNotifications();
}

void NotifyServerApplet::setBlockClosedId(qint64 id)
{
m_manager->setBlockClosedId(id);
}

D_APPLET_CLASS(NotifyServerApplet)

}
Expand Down
3 changes: 2 additions & 1 deletion panels/notification/server/notifyserverapplet.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 @@ -31,6 +31,7 @@ public Q_SLOTS:
void removeNotifications(const QString &appName);
void removeNotifications();
void removeExpiredNotifications();
void setBlockClosedId(qint64 id);

private:
NotificationManager *m_manager = nullptr;
Expand Down
Loading