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

0001 /*
0002     SPDX-FileCopyrightText: 2016 Ivan Čukić <ivan.cukic(at)kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef ACTIVITIES_ACTIVITIESMODEL_P_H
0008 #define ACTIVITIES_ACTIVITIESMODEL_P_H
0009 
0010 #include "activitiesmodel.h"
0011 
0012 #include "consumer.h"
0013 
0014 #include "utils/qflatset.h"
0015 
0016 #include <QCollator>
0017 
0018 namespace KActivities
0019 {
0020 class ActivitiesModelPrivate : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     ActivitiesModelPrivate(ActivitiesModel *parent);
0025 
0026 public Q_SLOTS:
0027     void onActivityNameChanged(const QString &name);
0028     void onActivityDescriptionChanged(const QString &description);
0029     void onActivityIconChanged(const QString &icon);
0030     void onActivityStateChanged(KActivities::Info::State state);
0031 
0032     void replaceActivities(const QStringList &activities);
0033     void onActivityAdded(const QString &id, bool notifyClients = true);
0034     void onActivityRemoved(const QString &id);
0035     void onCurrentActivityChanged(const QString &id);
0036 
0037     void setServiceStatus(KActivities::Consumer::ServiceStatus status);
0038 
0039 public:
0040     KActivities::Consumer activities;
0041     QVector<Info::State> shownStates;
0042 
0043     typedef std::shared_ptr<Info> InfoPtr;
0044 
0045     struct InfoPtrComparator {
0046         bool operator()(const InfoPtr &left, const InfoPtr &right) const
0047         {
0048             QCollator c;
0049             c.setCaseSensitivity(Qt::CaseInsensitive);
0050             c.setNumericMode(true);
0051             int rc = c.compare(left->name(), right->name());
0052             if (rc == 0) {
0053                 return left->id() < right->id();
0054             }
0055             return rc < 0;
0056         }
0057     };
0058 
0059     QFlatSet<InfoPtr, InfoPtrComparator> knownActivities;
0060     QFlatSet<InfoPtr, InfoPtrComparator> shownActivities;
0061 
0062     InfoPtr registerActivity(const QString &id);
0063     void unregisterActivity(const QString &id);
0064     void showActivity(InfoPtr activityInfo, bool notifyClients);
0065     void hideActivity(const QString &id);
0066     void backgroundsUpdated(const QStringList &activities);
0067 
0068     InfoPtr findActivity(QObject *ptr) const;
0069 
0070     ActivitiesModel *const q;
0071 };
0072 
0073 } // namespace KActivities
0074 
0075 #endif // ACTIVITIES_ACTIVITIESMODEL_P_H