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
3 changes: 3 additions & 0 deletions panels/notification/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ add_library(ds-notification-shared SHARED
${CMAKE_SOURCE_DIR}/panels/notification/common/notifyentity.cpp
${CMAKE_SOURCE_DIR}/panels/notification/common/dbaccessor.h
${CMAKE_SOURCE_DIR}/panels/notification/common/dbaccessor.cpp
${CMAKE_SOURCE_DIR}/panels/notification/common/notifysetting.h
${CMAKE_SOURCE_DIR}/panels/notification/common/notifysetting.cpp
)

set_target_properties(ds-notification-shared PROPERTIES
Expand All @@ -28,6 +30,7 @@ target_include_directories(ds-notification-shared PUBLIC
target_link_libraries(ds-notification-shared PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Sql
Dtk${DTK_VERSION_MAJOR}::Core
)

install(TARGETS ds-notification-shared DESTINATION "${LIB_INSTALL_DIR}")
Expand Down
40 changes: 28 additions & 12 deletions panels/notification/bubble/bubblemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "bubblemodel.h"

#include <notifysetting.h>

#include "bubbleitem.h"

#include <QTimer>
Expand All @@ -24,7 +27,11 @@
{
m_updateTimeTipTimer->setInterval(1000);
m_updateTimeTipTimer->setSingleShot(false);
BubbleMaxCount = NotifySetting::instance()->bubbleCount();

connect(m_updateTimeTipTimer, &QTimer::timeout, this, &BubbleModel::updateBubbleTimeTip);
connect(NotifySetting::instance(), &NotifySetting::contentRowCountChanged, this, &BubbleModel::updateContentRowCount);
connect(NotifySetting::instance(), &NotifySetting::bubbleCountChanged, this, &BubbleModel::updateBubbleCount);

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

View workflow job for this annotation

GitHub Actions / cppcheck

Virtual function 'rowCount' is called from constructor 'BubbleModel(QObject*parent=nullptr)' at line 34. Dynamic binding is not used.
}

BubbleModel::~BubbleModel()
Expand All @@ -48,13 +55,6 @@
m_bubbles.prepend(bubble);
endInsertRows();

connect(bubble, &BubbleItem::timeTipChanged, this, [this, bubble] {
const auto row = m_bubbles.indexOf(bubble);
if (row <= displayRowCount()) {
Q_EMIT dataChanged(index(row), index(row), {BubbleModel::TimeTip});
}
});

updateLevel();
}

Expand Down Expand Up @@ -192,6 +192,8 @@
return m_bubbles[row]->actions();
case BubbleModel::Urgency:
return m_bubbles[row]->urgency();
case BubbleModel::ContentRowCount:
return NotifySetting::instance()->contentRowCount();
default:
break;
}
Expand All @@ -214,6 +216,7 @@
mapRoleNames[BubbleModel::OverlayCount] = "overlayCount";
mapRoleNames[BubbleModel::DefaultAction] = "defaultAction";
mapRoleNames[BubbleModel::Actions] = "actions";
mapRoleNames[BubbleModel::ContentRowCount] = "contentRowCount";
return mapRoleNames;
}

Expand All @@ -227,7 +230,7 @@
return qMin(m_bubbles.count() - displayRowCount(), OverlayMaxCount);
}

void BubbleModel::setBubbleCount(int count)
void BubbleModel::updateBubbleCount(int count)
{
if (count == BubbleMaxCount)
return;
Expand All @@ -245,6 +248,7 @@

BubbleMaxCount = count;

layoutChanged();
updateLevel();
}

Expand Down Expand Up @@ -302,19 +306,31 @@
{
if (m_bubbles.isEmpty()) {
m_updateTimeTipTimer->stop();
return;
}

for (int i = 0; i < displayRowCount(); i++) {
auto item = m_bubbles.at(i);

for (auto item : m_bubbles) {
qint64 diff = QDateTime::currentMSecsSinceEpoch() - item->ctime();
diff /= 1000; // secs
QString timeTip;
if (diff >= 60) {
QString timeTip;
timeTip = tr("%1 minutes ago").arg(diff / 60);
item->setTimeTip(timeTip);
};
}

Q_EMIT dataChanged(index(0), index(m_bubbles.size() - 1), {BubbleModel::TimeTip});
}

void BubbleModel::updateContentRowCount(int rowCount)
{
if (m_contentRowCount == rowCount)
return;

m_contentRowCount = rowCount;

if (!m_bubbles.isEmpty()) {
Q_EMIT dataChanged(index(0), index(m_bubbles.size() - 1), {BubbleModel::ContentRowCount});
}
}
}
5 changes: 4 additions & 1 deletion panels/notification/bubble/bubblemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BubbleModel : public QAbstractListModel
DefaultAction,
Actions,
Urgency,
ContentRowCount
} BubbleRole;

explicit BubbleModel(QObject *parent = nullptr);
Expand All @@ -58,7 +59,6 @@ class BubbleModel : public QAbstractListModel

int displayRowCount() const;
int overlayCount() const;
void setBubbleCount(int count);

qint64 delayRemovedBubble() const;
void setDelayRemovedBubble(qint64 newDelayRemovedBubble);
Expand All @@ -67,14 +67,17 @@ class BubbleModel : public QAbstractListModel
void delayRemovedBubbleChanged();

private:
void updateBubbleCount(int count);
int replaceBubbleIndex(const BubbleItem *bubble) const;
void updateLevel();
void updateBubbleTimeTip();
void updateContentRowCount(int rowCount);

private:
QTimer *m_updateTimeTipTimer = nullptr;
QList<BubbleItem *> m_bubbles;
int BubbleMaxCount{3};
int m_contentRowCount{6};
const int OverlayMaxCount{2};
QList<qint64> m_delayBubbles;
qint64 m_delayRemovedBubble{-1};
Expand Down
26 changes: 2 additions & 24 deletions panels/notification/bubble/bubblepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
#include "bubblemodel.h"
#include "pluginfactory.h"
#include "bubbleitem.h"
#include "dbaccessor.h"

#include <QLoggingCategory>
#include <QQueue>

#include <DConfig>

#include <appletbridge.h>

#include "dbaccessor.h"

namespace notification {
Q_DECLARE_LOGGING_CATEGORY(notifyLog)
}
Expand All @@ -31,9 +28,7 @@ BubblePanel::BubblePanel(QObject *parent)

BubblePanel::~BubblePanel()
{
if (m_setting) {
m_setting->deleteLater();
}

}

bool BubblePanel::load()
Expand All @@ -55,13 +50,6 @@ bool BubblePanel::init()

connect(m_notificationServer, SIGNAL(notificationStateChanged(qint64, int)), this, SLOT(onNotificationStateChanged(qint64, int)));

m_setting = Dtk::Core::DConfig::create("org.deepin.dde.shell", "org.deepin.dde.shell.notification");
QObject::connect(m_setting, &Dtk::Core::DConfig::valueChanged, this, [this](const QString &key) {
if (key == "bubbleCount") {
updateMaxBubbleCount();
}
});
updateMaxBubbleCount();
connect(m_bubbles, &BubbleModel::rowsInserted, this, &BubblePanel::onBubbleCountChanged);
connect(m_bubbles, &BubbleModel::rowsRemoved, this, &BubblePanel::onBubbleCountChanged);

Expand Down Expand Up @@ -182,16 +170,6 @@ BubbleItem *BubblePanel::bubbleItem(int index)
return m_bubbles->items().at(index);
}

void BubblePanel::updateMaxBubbleCount()
{
const auto count = m_setting->value("bubbleCount", 3).toInt();
if (count < 1) {
qWarning(notifyLog) << "Invalid settings of bubbleCount:" << count << ", it should be greater than 0";
return;
}
m_bubbles->setBubbleCount(count);
}

D_APPLET_CLASS(BubblePanel)

bool BubblePanel::enabled() const
Expand Down
11 changes: 0 additions & 11 deletions panels/notification/bubble/bubblepanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@

#include <QQuickItem>

namespace Dtk
{
namespace Core
{
class DConfig;
}
}

namespace notification {

class NotifyEntity;
Expand Down Expand Up @@ -68,15 +60,12 @@ private Q_SLOTS:

BubbleItem *bubbleItem(int index);

void updateMaxBubbleCount();

private:
bool m_visible = false;
BubbleModel *m_bubbles = nullptr;
DS_NAMESPACE::DAppletProxy *m_notificationServer = nullptr;
DataAccessor *m_accessor = nullptr;
bool m_enabled = true;
Dtk::Core::DConfig *m_setting = nullptr;
};

}
1 change: 1 addition & 0 deletions panels/notification/bubble/package/NormalBubble.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NotifyItemContent {
content: bubble.body
strongInteractive: bubble.urgency === 2
contentIcon: bubble.bodyImagePath
contentRowCount: bubble.contentRowCount
onRemove: function () {
console.log("remove notify", bubble.appName)
Applet.close(bubble.index)
Expand Down
1 change: 1 addition & 0 deletions panels/notification/center/NormalNotify.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ NotifyItem {
closeVisible: root.hovered || root.activeFocus
strongInteractive: root.strongInteractive
contentIcon: root.contentIcon
contentRowCount: root.contentRowCount

onRemove: function () {
root.state = "removing"
Expand Down
1 change: 1 addition & 0 deletions panels/notification/center/NotifyStaging.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FocusScope {
content: model.content
strongInteractive: model.strongInteractive
contentIcon: model.contentIcon
contentRowCount: model.contentRowCount

onRemove: function () {
console.log("remove overlap", model.id)
Expand Down
2 changes: 2 additions & 0 deletions panels/notification/center/NotifyViewDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ DelegateChooser {
content: model.content
strongInteractive: model.strongInteractive
contentIcon: model.contentIcon
contentRowCount: model.contentRowCount
property string defaultAction: model.defaultAction

function invokeAction(actionId) {
Expand Down Expand Up @@ -139,6 +140,7 @@ DelegateChooser {
content: model.content
strongInteractive: model.strongInteractive
contentIcon: model.contentIcon
contentRowCount: model.contentRowCount

Loader {
anchors.fill: parent
Expand Down
1 change: 1 addition & 0 deletions panels/notification/center/OverlapNotify.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ NotifyItem {
closeVisible: root.hovered || root.activeFocus
strongInteractive: root.strongInteractive
contentIcon: root.contentIcon
contentRowCount: root.contentRowCount

onRemove: function () {
root.state = "removing"
Expand Down
18 changes: 17 additions & 1 deletion panels/notification/center/notifymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "notifyentity.h"
#include "notifyitem.h"
#include "notifyaccessor.h"
#include "notifysetting.h"

namespace notification {
Q_DECLARE_LOGGING_CATEGORY(notifyLog)
Expand All @@ -22,6 +23,7 @@ NotifyModel::NotifyModel(QObject *parent)
{
connect(m_accessor, &NotifyAccessor::entityReceived, this, &NotifyModel::doEntityReceived);
connect(this, &NotifyModel::countChanged, this, &NotifyModel::onCountChanged);
connect(NotifySetting::instance(), &NotifySetting::contentRowCountChanged, this, &NotifyModel::updateContentRowCount);

updateCollapseStatus();

Expand Down Expand Up @@ -391,6 +393,17 @@ void NotifyModel::updateCollapseStatus()
setCollapse(!existGroup);
}

void NotifyModel::updateContentRowCount(int rowCount)
{
if (m_contentRowCount == rowCount)
return;
m_contentRowCount = rowCount;

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

bool NotifyModel::greaterNotify(const AppNotifyItem *item1, const AppNotifyItem *item2) const
{
const auto entity1 = greaterNotifyEntity(item1);
Expand Down Expand Up @@ -706,6 +719,8 @@ QVariant NotifyModel::data(const QModelIndex &index, int role) const
if (auto item = dynamic_cast<OverlapAppNotifyItem *>(notify)) {
return item->count();
}
} else if (role == NotifyRole::NotifyContentRowCount) {
return NotifySetting::instance()->contentRowCount();
}
return QVariant::fromValue(notify);
}
Expand Down Expand Up @@ -759,7 +774,8 @@ QHash<int, QByteArray> NotifyModel::roleNames() const
{NotifyPinned, "pinned"},
{NotifyStrongInteractive, "strongInteractive"},
{NotifyContentIcon, "contentIcon"},
{NotifyOverlapCount, "overlapCount"}};
{NotifyOverlapCount, "overlapCount"},
{NotifyContentRowCount, "contentRowCount"}};
return roles;
}

Expand Down
5 changes: 4 additions & 1 deletion panels/notification/center/notifymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class NotifyModel : public QAbstractListModel
NotifyPinned,
NotifyStrongInteractive,
NotifyContentIcon,
NotifyOverlapCount
NotifyOverlapCount,
NotifyContentRowCount
};
NotifyModel(QObject *parent = nullptr);

Expand Down Expand Up @@ -93,11 +94,13 @@ private slots:
void trayUpdateGroupLastEntity(const NotifyEntity &entity);
void trayUpdateGroupLastEntity(const QString &appName);
void updateCollapseStatus();
void updateContentRowCount(int rowCount);

private:
QList<AppNotifyItem *> m_appNotifies;
QPointer<NotifyAccessor> m_accessor;
int m_refreshTimer = -1;
bool m_collapse = false;
int m_contentRowCount = 6;
};
}
Loading
Loading