File indexing completed on 2024-05-05 05:38:28

0001 /*
0002     SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QAbstractListModel>
0010 #include <memory>
0011 
0012 #include "notificationmanager_export.h"
0013 #include "notifications.h"
0014 
0015 namespace NotificationManager
0016 {
0017 class JobsModelPrivate;
0018 
0019 /**
0020  * A model used for listing Job.
0021  */
0022 class NOTIFICATIONMANAGER_EXPORT JobsModel : public QAbstractListModel
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     ~JobsModel() override;
0028 
0029     using Ptr = std::shared_ptr<JobsModel>;
0030     static Ptr createJobsModel();
0031 
0032     /**
0033      * Registers the JobView service on DBus.
0034      *
0035      * @return true if succeeded, false otherwise.
0036      */
0037     bool init();
0038 
0039     /**
0040      * Whether the notification service could be registered
0041      */
0042     bool isValid() const;
0043 
0044     QVariant data(const QModelIndex &index, int role) const override;
0045     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0046     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0047     QHash<int, QByteArray> roleNames() const override;
0048 
0049     /**
0050      * @brief Close a job
0051      *
0052      * This removes the job from the model. This will not cancel the job!
0053      * Use @c kill if you want to cancel a job.
0054      */
0055     void close(const QModelIndex &idx);
0056     void expire(const QModelIndex &idx);
0057 
0058     /**
0059      * @brief Suspend a job
0060      */
0061     void suspend(const QModelIndex &idx);
0062     /**
0063      * @brief Resume a job
0064      */
0065     void resume(const QModelIndex &idx);
0066     /**
0067      * @brief Kill a job
0068      *
0069      * This cancels the job.
0070      */
0071     void kill(const QModelIndex &idx);
0072 
0073     void clear(Notifications::ClearFlags flags);
0074 
0075 Q_SIGNALS:
0076     void serviceOwnershipLost();
0077 
0078 private:
0079     JobsModel();
0080     Q_DISABLE_COPY(JobsModel)
0081 
0082     JobsModelPrivate *d;
0083 };
0084 
0085 } // namespace NotificationManager