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

0001 /*
0002     SPDX-FileCopyrightText: 2010-2016 Ivan Cukic <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 #include "consumer.h"
0008 #include "consumer_p.h"
0009 #include "manager_p.h"
0010 
0011 namespace KActivities
0012 {
0013 ConsumerPrivate::ConsumerPrivate()
0014     : cache(ActivitiesCache::self())
0015 {
0016 }
0017 
0018 void ConsumerPrivate::setServiceStatus(Consumer::ServiceStatus status)
0019 {
0020     Q_EMIT serviceStatusChanged(status);
0021 }
0022 
0023 Consumer::Consumer(QObject *parent)
0024     : QObject(parent)
0025     , d(new ConsumerPrivate())
0026 {
0027     connect(d->cache.get(), &KActivities::ActivitiesCache::currentActivityChanged, this, &Consumer::currentActivityChanged);
0028     connect(d->cache.get(), &KActivities::ActivitiesCache::activityAdded, this, &Consumer::activityAdded);
0029     connect(d->cache.get(), &KActivities::ActivitiesCache::activityRemoved, this, &Consumer::activityRemoved);
0030     connect(d->cache.get(), &KActivities::ActivitiesCache::serviceStatusChanged, this, &Consumer::serviceStatusChanged);
0031 
0032     connect(d->cache.get(), &ActivitiesCache::activityListChanged, this, [=]() {
0033         Q_EMIT activitiesChanged(activities());
0034     });
0035     connect(d->cache.get(), &ActivitiesCache::runningActivityListChanged, this, [=]() {
0036         Q_EMIT runningActivitiesChanged(runningActivities());
0037     });
0038 
0039     // connect(d->cache.get(), SIGNAL(activityStateChanged(QString,int)),
0040     //         this, SIGNAL(activityStateChanged(QString,int)));
0041 }
0042 
0043 Consumer::~Consumer() = default;
0044 
0045 QString Consumer::currentActivity() const
0046 {
0047     return d->cache->m_currentActivity;
0048 }
0049 
0050 QStringList Consumer::activities(Info::State state) const
0051 {
0052     QStringList result;
0053 
0054     result.reserve(d->cache->m_activities.size());
0055 
0056     for (const auto &info : std::as_const(d->cache->m_activities)) {
0057         if (info.state == state) {
0058             result << info.id;
0059         }
0060     }
0061 
0062     return result;
0063 }
0064 
0065 QStringList Consumer::activities() const
0066 {
0067     QStringList result;
0068 
0069     result.reserve(d->cache->m_activities.size());
0070 
0071     for (const auto &info : std::as_const(d->cache->m_activities)) {
0072         result << info.id;
0073     }
0074 
0075     return result;
0076 }
0077 
0078 QStringList Consumer::runningActivities() const
0079 {
0080     QStringList result;
0081 
0082     result.reserve(d->cache->m_activities.size());
0083 
0084     for (const auto &info : std::as_const(d->cache->m_activities)) {
0085         if (info.state == Info::Running || info.state == Info::Stopping) {
0086             result << info.id;
0087         }
0088     }
0089 
0090     return result;
0091 }
0092 
0093 Consumer::ServiceStatus Consumer::serviceStatus()
0094 {
0095     return d->cache->m_status;
0096 }
0097 
0098 } // namespace KActivities