Skip to content

Commit 63c8ab6

Browse files
committed
refact: extract notifyItem content for notification
Bubble and Center use same ui of notifyItem content. Task: https://pms.uniontech.com/task-view-366403.html
1 parent 8bb8dab commit 63c8ab6

24 files changed

+69
-392
lines changed

panels/notification/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ target_link_libraries(ds-notification-shared PUBLIC
3333
install(TARGETS ds-notification-shared DESTINATION "${LIB_INSTALL_DIR}")
3434
ds_install_package(PACKAGE org.deepin.ds.notification TARGET ds-notification)
3535

36+
add_subdirectory(plugin)
3637
add_subdirectory(bubble)
3738
add_subdirectory(center)
3839
add_subdirectory(osd)

panels/notification/bubble/bubbleitem.cpp

Lines changed: 22 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ BubbleItem::BubbleItem(const NotifyEntity &entity, QObject *parent)
172172
void BubbleItem::setEntity(const NotifyEntity &entity)
173173
{
174174
m_entity = entity;
175+
updateActions();
175176

176177
QVariantMap hints = entity.hints();
177178
if (hints.contains("urgency")) {
@@ -229,68 +230,36 @@ qint64 BubbleItem::ctime() const
229230
return m_entity.cTime();
230231
}
231232

232-
bool BubbleItem::hasDisplayAction() const
233+
QString BubbleItem::defaultAction() const
233234
{
234-
return displayActions().count() >= 2;
235+
return m_defaultAction;
235236
}
236237

237-
bool BubbleItem::hasDefaultAction() const
238+
QVariantList BubbleItem::actions() const
238239
{
239-
return defaultActionIdIndex() >= 0;
240+
return m_actions;
240241
}
241242

242-
QString BubbleItem::defaultActionText() const
243+
void BubbleItem::updateActions()
243244
{
244-
const auto index = defaultActionTextIndex();
245-
if (index < 0)
246-
return QString();
247-
248-
return m_entity.actions().at(index);
249-
}
250-
251-
QString BubbleItem::defaultActionId() const
252-
{
253-
const auto index = defaultActionIdIndex();
254-
if (index < 0)
255-
return QString();
256-
257-
return m_entity.actions().at(index);
258-
}
259-
260-
QString BubbleItem::firstActionText() const
261-
{
262-
if (!hasDisplayAction())
263-
return QString();
264-
265-
return displayActions().at(1);
266-
}
267-
268-
QString BubbleItem::firstActionId() const
269-
{
270-
if (!hasDisplayAction())
271-
return QString();
272-
273-
return displayActions().at(0);
274-
}
275-
276-
QStringList BubbleItem::actionTexts() const
277-
{
278-
QStringList res;
279-
const auto tmp = displayActions();
280-
for (int i = 3; i < tmp.count(); i += 2)
281-
res << tmp[i];
282-
283-
return res;
284-
}
245+
QStringList actions = m_entity.actions();
246+
const auto defaultIndex = actions.indexOf(QLatin1String("default"));
247+
if (defaultIndex >= 0) {
248+
actions.remove(defaultIndex, 2);
249+
m_defaultAction = QLatin1String("default");
250+
}
285251

286-
QStringList BubbleItem::actionIds() const
287-
{
288-
QStringList res;
289-
const auto tmp = displayActions();
290-
for (int i = 2; i < tmp.count(); i += 2)
291-
res << tmp[i];
252+
QVariantList array;
253+
for (int i = 0; i < actions.size(); i += 2) {
254+
const auto id = actions[i];
255+
const auto text = actions[i + 1];
256+
QVariantMap item;
257+
item["id"] = id;
258+
item["text"] = text;
259+
array.append(item);
260+
}
292261

293-
return res;
262+
m_actions = array;
294263
}
295264

296265
int BubbleItem::level() const
@@ -330,32 +299,6 @@ void BubbleItem::setEnablePreview(bool enable)
330299
m_enablePreview = enable;
331300
}
332301

333-
int BubbleItem::defaultActionIdIndex() const
334-
{
335-
return m_entity.actions().indexOf("default");
336-
}
337-
338-
int BubbleItem::defaultActionTextIndex() const
339-
{
340-
const auto index = defaultActionIdIndex();
341-
if (index >= 0)
342-
return index + 1;
343-
344-
return -1;
345-
}
346-
347-
QStringList BubbleItem::displayActions() const
348-
{
349-
const auto defaultIndex = defaultActionIdIndex();
350-
if (defaultIndex >= 0) {
351-
auto tmp = m_entity.actions();
352-
tmp.remove(defaultIndex, 1);
353-
return tmp;
354-
}
355-
356-
return m_entity.actions();
357-
}
358-
359302
QString BubbleItem::displayText() const
360303
{
361304
return m_enablePreview ? m_entity.body() : tr("1 new message");

panels/notification/bubble/bubbleitem.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,9 @@ class BubbleItem : public QObject
3434
QString bodyImagePath() const;
3535
qint64 ctime() const;
3636

37-
bool hasDisplayAction() const;
38-
bool hasDefaultAction() const;
39-
QString defaultActionText() const;
40-
QString defaultActionId() const;
41-
QString firstActionText() const;
42-
QString firstActionId() const;
43-
QStringList actionTexts() const;
44-
QStringList actionIds() const;
37+
QString defaultAction() const;
38+
QVariantList actions() const;
39+
void updateActions();
4540

4641
int level() const;
4742
void setLevel(int level);
@@ -57,19 +52,16 @@ class BubbleItem : public QObject
5752
void timeTipChanged();
5853

5954
private:
60-
int defaultActionIdIndex() const;
61-
int defaultActionTextIndex() const;
62-
QStringList displayActions() const;
6355
QString displayText() const;
6456

6557
private:
6658
NotifyEntity m_entity;
67-
68-
private:
6959
int m_level = 0;
7060
int m_urgency = NotifyEntity::Normal;
7161
QString m_timeTip;
7262
bool m_enablePreview = true;
63+
QVariantList m_actions;
64+
QString m_defaultAction;
7365
};
7466

7567
}

panels/notification/bubble/bubblemodel.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,10 @@ QVariant BubbleModel::data(const QModelIndex &index, int role) const
174174
return m_bubbles[row]->bodyImagePath();
175175
case BubbleModel::OverlayCount:
176176
return overlayCount();
177-
case BubbleModel::hasDefaultAction:
178-
return m_bubbles[row]->hasDefaultAction();
179-
case BubbleModel::hasDisplayAction:
180-
return m_bubbles[row]->hasDisplayAction();
181-
case BubbleModel::FirstActionText:
182-
return m_bubbles[row]->firstActionText();
183-
case BubbleModel::FirstActionId:
184-
return m_bubbles[row]->firstActionId();
185-
case BubbleModel::ActionTexts:
186-
return m_bubbles[row]->actionTexts();
187-
case BubbleModel::ActionIds:
188-
return m_bubbles[row]->actionIds();
177+
case BubbleModel::DefaultAction:
178+
return m_bubbles[row]->defaultAction();
179+
case BubbleModel::Actions:
180+
return m_bubbles[row]->actions();
189181
case BubbleModel::Urgency:
190182
return m_bubbles[row]->urgency();
191183
default:
@@ -207,12 +199,8 @@ QHash<int, QByteArray> BubbleModel::roleNames() const
207199
mapRoleNames[BubbleModel::Urgency] = "urgency";
208200
mapRoleNames[BubbleModel::BodyImagePath] = "bodyImagePath";
209201
mapRoleNames[BubbleModel::OverlayCount] = "overlayCount";
210-
mapRoleNames[BubbleModel::hasDefaultAction] = "hasDefaultAction";
211-
mapRoleNames[BubbleModel::hasDisplayAction] = "hasDisplayAction";
212-
mapRoleNames[BubbleModel::FirstActionText] = "firstActionText";
213-
mapRoleNames[BubbleModel::FirstActionId] = "firstActionId";
214-
mapRoleNames[BubbleModel::ActionTexts] = "actionTexts";
215-
mapRoleNames[BubbleModel::ActionIds] = "actionIds";
202+
mapRoleNames[BubbleModel::DefaultAction] = "defaultAction";
203+
mapRoleNames[BubbleModel::Actions] = "actions";
216204
return mapRoleNames;
217205
}
218206

panels/notification/bubble/bubblemodel.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@ class BubbleModel : public QAbstractListModel
2727
TimeTip,
2828
BodyImagePath,
2929
OverlayCount,
30-
hasDefaultAction,
31-
hasDisplayAction,
32-
FirstActionText,
33-
FirstActionId,
34-
DefaultActionId,
35-
ActionTexts,
36-
ActionIds,
30+
DefaultAction,
31+
Actions,
3732
Urgency,
3833
} BubbleRole;
3934

panels/notification/bubble/bubblepanel.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ BubbleModel *BubblePanel::bubbles() const
7878
return m_bubbles;
7979
}
8080

81-
void BubblePanel::invokeDefaultAction(int bubbleIndex)
82-
{
83-
auto bubble = bubbleItem(bubbleIndex);
84-
if (!bubble)
85-
return;
86-
87-
m_bubbles->remove(bubbleIndex);
88-
onActionInvoked(bubble->id(), bubble->bubbleId(), bubble->defaultActionId());
89-
}
90-
9181
void BubblePanel::invokeAction(int bubbleIndex, const QString &actionId)
9282
{
9383
auto bubble = bubbleItem(bubbleIndex);

panels/notification/bubble/bubblepanel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class BubblePanel : public DS_NAMESPACE::DPanel
4343
bool enabled() const;
4444

4545
public Q_SLOTS:
46-
void invokeDefaultAction(int bubbleIndex);
4746
void invokeAction(int bubbleIndex, const QString &actionId);
4847
void close(int bubbleIndex);
4948
void delayProcess(int bubbleIndex);

panels/notification/bubble/package/BubbleAction.qml

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)