File indexing completed on 2024-02-25 05:06:50

0001 /**
0002  * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef NOTIFICATIONSMODEL_H
0008 #define NOTIFICATIONSMODEL_H
0009 
0010 #include <QAbstractItemModel>
0011 #include <QAbstractListModel>
0012 #include <QList>
0013 #include <QPixmap>
0014 
0015 #include "dbusinterfaces.h"
0016 
0017 class KDECONNECTINTERFACES_EXPORT NotificationsModel : public QAbstractListModel
0018 {
0019     Q_OBJECT
0020     Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
0021     Q_PROPERTY(int count READ rowCount NOTIFY rowsChanged)
0022     Q_PROPERTY(bool isAnyDimissable READ isAnyDimissable NOTIFY anyDismissableChanged STORED false)
0023 
0024 public:
0025     enum ModelRoles {
0026         IconModelRole = Qt::DecorationRole,
0027         NameModelRole = Qt::DisplayRole,
0028         ContentModelRole = Qt::UserRole,
0029         AppNameModelRole = Qt::UserRole + 1,
0030         IdModelRole,
0031         DismissableModelRole,
0032         RepliableModelRole,
0033         IconPathModelRole,
0034         DbusInterfaceRole,
0035         TitleModelRole,
0036         TextModelRole
0037     };
0038 
0039     explicit NotificationsModel(QObject *parent = nullptr);
0040     ~NotificationsModel() override;
0041 
0042     QString deviceId() const;
0043     void setDeviceId(const QString &deviceId);
0044 
0045     QVariant data(const QModelIndex &index, int role) const override;
0046     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0047 
0048     NotificationDbusInterface *getNotification(const QModelIndex &index) const;
0049 
0050     Q_INVOKABLE bool isAnyDimissable() const;
0051     QHash<int, QByteArray> roleNames() const override;
0052 
0053 public Q_SLOTS:
0054     void dismissAll();
0055 
0056 private Q_SLOTS:
0057     void notificationAdded(const QString &id);
0058     void notificationRemoved(const QString &id);
0059     void notificationUpdated();
0060     void refreshNotificationList();
0061     void receivedNotifications(QDBusPendingCallWatcher *watcher);
0062     void clearNotifications();
0063 
0064 Q_SIGNALS:
0065     void deviceIdChanged(const QString &value);
0066     void anyDismissableChanged();
0067     void rowsChanged();
0068 
0069 private:
0070     DeviceNotificationsDbusInterface *m_dbusInterface;
0071     QList<NotificationDbusInterface *> m_notificationList;
0072     QString m_deviceId;
0073 };
0074 
0075 #endif // DEVICESMODEL_H