From 1dbc0e3c88ba271ba35bc3f82e7864c4f35e1236 Mon Sep 17 00:00:00 2001 From: Fabien Proriol Date: Sun, 25 May 2025 12:13:31 +0200 Subject: Initial Commit --- src/lib/xdgnotificationactions.cpp | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/lib/xdgnotificationactions.cpp (limited to 'src/lib/xdgnotificationactions.cpp') diff --git a/src/lib/xdgnotificationactions.cpp b/src/lib/xdgnotificationactions.cpp new file mode 100644 index 0000000..afa7c19 --- /dev/null +++ b/src/lib/xdgnotificationactions.cpp @@ -0,0 +1,63 @@ +#include "xdgnotificationactions.h" +#include + +xdg::NotificationActions::NotificationActions(QObject *parent) + : QAbstractListModel(parent) +{ + +} + +QStringList xdg::NotificationActions::actionslist() const +{ + return m_actionslist; +} + +void xdg::NotificationActions::setActionslist(const QStringList &newActionslist) +{ + if(newActionslist.count() % 2 != 0) + { + qWarning() << "Error in actionlist:" << newActionslist; + } + + if (m_actionslist == newActionslist) + return; + m_actionslist = newActionslist; + + beginResetModel(); + m_actions.clear(); + for(int i = 0; i < newActionslist.count() / 2; i++) + { + m_actions.append(QPair(newActionslist[i * 2], newActionslist[(i * 2) + 1])); + } + endResetModel(); + + emit actionslistChanged(); +} + +int xdg::NotificationActions::rowCount(const QModelIndex &parent) const +{ + return m_actions.count(); +} + +QVariant xdg::NotificationActions::data(const QModelIndex &index, int role) const +{ + if(index.row() > m_actions.count()) + return QVariant(); + + switch(role) { + case Qt::DisplayRole: + case TextRole: + return m_actions[index.row()].second; + case KeyRole: + return m_actions[index.row()].first; + } + return QVariant(); +} + +QHash xdg::NotificationActions::roleNames() const +{ + QHash roles = QAbstractItemModel::roleNames(); + roles[KeyRole] = "key"; + roles[TextRole] = "actionText"; + return roles; +} -- cgit v1.2.3