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