Open notification action is supported

pull/15/head
reionwong 4 years ago
parent 1bfda3c8d3
commit 6f9f8406c0

@ -54,6 +54,8 @@ QVariant NotificationsModel::data(const QModelIndex &index, int role) const
return notification.body;
case NotificationsModel::IconNameRole:
return notification.appIcon;
case NotificationsModel::HasDefaultActionRole:
return notification.actions.contains("default");
default:
break;
}
@ -111,6 +113,22 @@ void NotificationsModel::close(uint id)
}
}
void NotificationsModel::invokeDefaultAction(uint notificationId)
{
const int row = rowOfNotification(notificationId);
if (row == -1) {
return;
}
const Notification &notification = m_notifications.at(row);
if (!notification.actions.contains("default")) {
return;
}
NotificationServer::self()->InvokeAction(notificationId, "default");
}
int NotificationsModel::rowOfNotification(uint id) const
{
auto it = std::find_if(m_notifications.constBegin(), m_notifications.constEnd(), [id](const Notification &item) {

@ -27,6 +27,7 @@ public:
UpdatedRole,
BodyRole,
IconNameRole,
HasDefaultActionRole
};
Q_ENUM(Roles)
@ -38,6 +39,7 @@ public:
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void close(uint id);
Q_INVOKABLE void invokeDefaultAction(uint id);
int rowOfNotification(uint id) const;
void removeRows(const QVector<int> &rows);

@ -60,10 +60,17 @@ Window {
id: _mouseArea
z: 999
anchors.fill: parent
onClicked: notificationsModel.close(model.notificationId)
hoverEnabled: true
onEntered: timer.stop()
onExited: timer.restart()
onClicked: {
if (model.hasDefaultAction) {
notificationsModel.invokeDefaultAction(model.notificationId)
}
notificationsModel.close(model.notificationId)
}
}
RowLayout {
@ -125,7 +132,29 @@ Window {
height: 24
source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark" : "light") + "/close.svg"
sourceSize: Qt.size(width, height)
visible: _mouseArea.containsMouse
visible: _mouseArea.containsMouse || _closeBtnArea.containsMouse
z: 9999
Rectangle {
property color hoveredColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 2)
: Qt.darker(FishUI.Theme.backgroundColor, 1.2)
property color pressedColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 1.5)
: Qt.darker(FishUI.Theme.backgroundColor, 1.3)
z: -1
anchors.fill: parent
color: _closeBtnArea.pressed ? pressedColor : _closeBtnArea.containsMouse ? hoveredColor : "transparent"
radius: height / 2
}
MouseArea {
id: _closeBtnArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
notificationsModel.close(model.notificationId)
}
}
}
Timer {

Loading…
Cancel
Save