File indexing completed on 2024-12-22 05:13:39

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 "controller.h"
0008 #include "consumer_p.h"
0009 #include "manager_p.h"
0010 
0011 #include "utils/dbusfuture_p.h"
0012 
0013 namespace KActivities
0014 {
0015 class ControllerPrivate
0016 {
0017 };
0018 
0019 Controller::Controller(QObject *parent)
0020     : Consumer(parent)
0021 {
0022 }
0023 
0024 Controller::~Controller() = default;
0025 
0026 // clang-format off
0027 #define CREATE_SETTER(What)                                                    \
0028     QFuture<void> Controller::setActivity##What(const QString &id,             \
0029                                                 const QString &value)          \
0030     {                                                                          \
0031         return Manager::isServiceRunning()                                     \
0032                    ? DBusFuture::asyncCall<void>(                              \
0033                          Manager::activities(),                                \
0034                          QString::fromLatin1("SetActivity" #What), id, value)  \
0035                    : DBusFuture::fromVoid();                                   \
0036     }
0037 // clang-format on
0038 
0039 CREATE_SETTER(Name)
0040 CREATE_SETTER(Description)
0041 CREATE_SETTER(Icon)
0042 
0043 #undef CREATE_SETTER
0044 
0045 QFuture<bool> Controller::setCurrentActivity(const QString &id)
0046 {
0047     // Q_ASSERT_X(activities().contains(id), "Controller::setCurrentActivity",
0048     //            "You can not set a non-existent activity to be the current");
0049 
0050     // return Manager::activities()->SetCurrentActivity(id);
0051     return Manager::isServiceRunning() ? DBusFuture::asyncCall<bool>(Manager::activities(), QStringLiteral("SetCurrentActivity"), id)
0052                                        : DBusFuture::fromValue(false);
0053 }
0054 
0055 QFuture<QString> Controller::addActivity(const QString &name)
0056 {
0057     Q_ASSERT_X(!name.isEmpty(), "Controller::addActivity", "The activity name can not be an empty string");
0058 
0059     // return Manager::activities()->AddActivity(name);
0060     return Manager::isServiceRunning() ? DBusFuture::asyncCall<QString>(Manager::activities(), QStringLiteral("AddActivity"), name)
0061                                        : DBusFuture::fromValue(QString());
0062 }
0063 
0064 QFuture<void> Controller::removeActivity(const QString &id)
0065 {
0066     // Q_ASSERT_X(activities().contains(id), "Controller::removeActivity",
0067     //            "You can not remove a non-existent activity");
0068 
0069     // Manager::activities()->RemoveActivity(id);
0070     return Manager::isServiceRunning() ? DBusFuture::asyncCall<void>(Manager::activities(), QStringLiteral("RemoveActivity"), id) : DBusFuture::fromVoid();
0071 }
0072 
0073 QFuture<void> Controller::stopActivity(const QString &id)
0074 {
0075     // Q_ASSERT_X(activities().contains(id), "Controller::stopActivity",
0076     //            "You can not stop a non-existent activity");
0077 
0078     // Manager::activities()->StopActivity(id);
0079     return Manager::isServiceRunning() ? DBusFuture::asyncCall<void>(Manager::activities(), QStringLiteral("StopActivity"), id) : DBusFuture::fromVoid();
0080 }
0081 
0082 QFuture<void> Controller::startActivity(const QString &id)
0083 {
0084     // Q_ASSERT_X(activities().contains(id), "Controller::startActivity",
0085     //            "You can not start an non-existent activity");
0086 
0087     // Manager::activities()->StartActivity(id);
0088     return Manager::isServiceRunning() ? DBusFuture::asyncCall<void>(Manager::activities(), QStringLiteral("StartActivity"), id) : DBusFuture::fromVoid();
0089 }
0090 
0091 QFuture<void> Controller::previousActivity()
0092 {
0093     return Manager::isServiceRunning() ? DBusFuture::asyncCall<void>(Manager::activities(), QStringLiteral("PreviousActivity")) : DBusFuture::fromVoid();
0094 }
0095 
0096 QFuture<void> Controller::nextActivity()
0097 {
0098     return Manager::isServiceRunning() ? DBusFuture::asyncCall<void>(Manager::activities(), QStringLiteral("NextActivity")) : DBusFuture::fromVoid();
0099 }
0100 
0101 } // namespace KActivities
0102 
0103 #include "moc_controller.cpp"