File indexing completed on 2022-11-29 13:02:28

0001 /*
0002     SPDX-FileCopyrightText: 2012, 2013, 2014 Ivan Cukic <ivan.cukic(at)kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef ACTIVITIES_ACTIVITIESMODEL_H
0008 #define ACTIVITIES_ACTIVITIESMODEL_H
0009 
0010 // Qt
0011 #include <QAbstractListModel>
0012 #include <QObject>
0013 
0014 // STL
0015 #include <memory>
0016 
0017 // Local
0018 #include "info.h"
0019 
0020 class QModelIndex;
0021 class QDBusPendingCallWatcher;
0022 
0023 namespace KActivities
0024 {
0025 class ActivitiesModelPrivate;
0026 
0027 /**
0028  * Data model that shows existing activities
0029  */
0030 class KACTIVITIES_EXPORT ActivitiesModel : public QAbstractListModel
0031 {
0032     Q_OBJECT
0033 
0034     Q_PROPERTY(QVector<Info::State> shownStates READ shownStates WRITE setShownStates NOTIFY shownStatesChanged)
0035 
0036 public:
0037     explicit ActivitiesModel(QObject *parent = nullptr);
0038 
0039     /**
0040      * Constructs the model and sets the shownStates
0041      */
0042     ActivitiesModel(QVector<Info::State> shownStates, QObject *parent = nullptr);
0043     ~ActivitiesModel() override;
0044 
0045     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0046 
0047     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0048 
0049     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0050 
0051     QHash<int, QByteArray> roleNames() const override;
0052 
0053     enum Roles {
0054         ActivityId = Qt::UserRole, ///< UUID of the activity
0055         ActivityName = Qt::UserRole + 1, ///< Activity name
0056         ActivityDescription = Qt::UserRole + 2, ///< Activity description
0057         ActivityIconSource = Qt::UserRole + 3, ///< Activity icon source name
0058         ActivityState = Qt::UserRole + 4, ///< The current state of the activity @see Info::State
0059         ActivityBackground = Qt::UserRole + 5, ///< Activity wallpaper (currently unsupported)
0060         ActivityIsCurrent = Qt::UserRole + 6, ///< Is this activity the current one current
0061 
0062         UserRole = Qt::UserRole + 32, ///< To be used by models that inherit this one
0063     };
0064 
0065 public Q_SLOTS:
0066     /**
0067      * The model can filter the list of activities based on their state.
0068      * This method sets which states should be shown.
0069      */
0070     void setShownStates(const QVector<Info::State> &shownStates);
0071 
0072     /**
0073      * The model can filter the list of activities based on their state.
0074      * This method returns which states are currently shown.
0075      */
0076     QVector<Info::State> shownStates() const;
0077 
0078 Q_SIGNALS:
0079     void shownStatesChanged(const QVector<Info::State> &state);
0080 
0081 private:
0082     friend class ActivitiesModelPrivate;
0083     ActivitiesModelPrivate *const d;
0084 };
0085 
0086 } // namespace KActivities
0087 
0088 #endif // ACTIVITIES_ACTIVITIESMODEL_H