Pimcommon

activitiesbasemanager.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "activitiesbasemanager.h"
8#include "pimcommonactivities_debug.h"
9#include <PlasmaActivities/Consumer>
10using namespace PimCommonActivities;
11ActivitiesBaseManager::ActivitiesBaseManager(QObject *parent)
12 : QObject{parent}
13 , mActivitiesConsumer(new KActivities::Consumer(this))
14{
15 connect(mActivitiesConsumer, &KActivities::Consumer::currentActivityChanged, this, [this](const QString &activityId) {
16 qCDebug(PIMCOMMONACTIVITIES_LOG) << " switch to activity " << activityId;
17 Q_EMIT activitiesChanged();
18 });
19 connect(mActivitiesConsumer, &KActivities::Consumer::activityRemoved, this, [this](const QString &activityId) {
20 qCDebug(PIMCOMMONACTIVITIES_LOG) << " Activity removed " << activityId;
21 Q_EMIT activitiesChanged();
22 });
23 connect(mActivitiesConsumer, &KActivities::Consumer::serviceStatusChanged, this, &ActivitiesBaseManager::activitiesChanged);
24 if (mActivitiesConsumer->serviceStatus() != KActivities::Consumer::ServiceStatus::Running) {
25 qCWarning(PIMCOMMONACTIVITIES_LOG) << "Plasma activities is not running: " << mActivitiesConsumer->serviceStatus();
26 }
27}
28
29ActivitiesBaseManager::~ActivitiesBaseManager() = default;
30
31bool ActivitiesBaseManager::isInCurrentActivity(const QStringList &lst) const
32{
33 if (mActivitiesConsumer->serviceStatus() == KActivities::Consumer::ServiceStatus::Running) {
34 if (lst.contains(mActivitiesConsumer->currentActivity())) {
35 return true;
36 } else {
37 const QStringList activities = mActivitiesConsumer->activities();
38 auto index = std::find_if(activities.constBegin(), activities.constEnd(), [lst](const QString &str) {
39 return lst.contains(str);
40 });
41 // Account doesn't contains valid activities => show it.
42 if (index == activities.constEnd()) {
43 return true;
44 }
45 return false;
46 }
47 } else {
48 return true;
49 }
50}
51
52QString ActivitiesBaseManager::currentActivity() const
53{
54 return mActivitiesConsumer->currentActivity();
55}
56
57QDebug operator<<(QDebug d, const PimCommonActivities::ActivitiesBaseManager::ActivitySettings &t)
58{
59 d << "enabled: " << t.enabled;
60 d << "activities: " << t.activities;
61 return d;
62}
63#include "moc_activitiesbasemanager.cpp"
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
const_iterator constBegin() const const
const_iterator constEnd() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:39:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.