/* SPDX-FileCopyrightText: 2010-2016 Ivan Cukic SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "controller.h" #include "consumer_p.h" #include "manager_p.h" #include "utils/dbusfuture_p.h" namespace KActivities { class ControllerPrivate { }; Controller::Controller(QObject *parent) : Consumer(parent) { } Controller::~Controller() = default; // clang-format off #define CREATE_SETTER(What) \ QFuture Controller::setActivity##What(const QString &id, \ const QString &value) \ { \ return Manager::isServiceRunning() \ ? DBusFuture::asyncCall( \ Manager::activities(), \ QString::fromLatin1("SetActivity" #What), id, value) \ : DBusFuture::fromVoid(); \ } // clang-format on CREATE_SETTER(Name) CREATE_SETTER(Description) CREATE_SETTER(Icon) #undef CREATE_SETTER QFuture Controller::setCurrentActivity(const QString &id) { // Q_ASSERT_X(activities().contains(id), "Controller::setCurrentActivity", // "You can not set a non-existent activity to be the current"); // return Manager::activities()->SetCurrentActivity(id); return Manager::isServiceRunning() ? DBusFuture::asyncCall(Manager::activities(), QStringLiteral("SetCurrentActivity"), id) : DBusFuture::fromValue(false); } QFuture Controller::addActivity(const QString &name) { Q_ASSERT_X(!name.isEmpty(), "Controller::addActivity", "The activity name can not be an empty string"); // return Manager::activities()->AddActivity(name); return Manager::isServiceRunning() ? DBusFuture::asyncCall(Manager::activities(), QStringLiteral("AddActivity"), name) : DBusFuture::fromValue(QString()); } QFuture Controller::removeActivity(const QString &id) { // Q_ASSERT_X(activities().contains(id), "Controller::removeActivity", // "You can not remove a non-existent activity"); // Manager::activities()->RemoveActivity(id); return Manager::isServiceRunning() ? DBusFuture::asyncCall(Manager::activities(), QStringLiteral("RemoveActivity"), id) : DBusFuture::fromVoid(); } QFuture Controller::stopActivity(const QString &id) { // Q_ASSERT_X(activities().contains(id), "Controller::stopActivity", // "You can not stop a non-existent activity"); // Manager::activities()->StopActivity(id); return Manager::isServiceRunning() ? DBusFuture::asyncCall(Manager::activities(), QStringLiteral("StopActivity"), id) : DBusFuture::fromVoid(); } QFuture Controller::startActivity(const QString &id) { // Q_ASSERT_X(activities().contains(id), "Controller::startActivity", // "You can not start an non-existent activity"); // Manager::activities()->StartActivity(id); return Manager::isServiceRunning() ? DBusFuture::asyncCall(Manager::activities(), QStringLiteral("StartActivity"), id) : DBusFuture::fromVoid(); } QFuture Controller::previousActivity() { return Manager::isServiceRunning() ? DBusFuture::asyncCall(Manager::activities(), QStringLiteral("PreviousActivity")) : DBusFuture::fromVoid(); } QFuture Controller::nextActivity() { return Manager::isServiceRunning() ? DBusFuture::asyncCall(Manager::activities(), QStringLiteral("NextActivity")) : DBusFuture::fromVoid(); } } // namespace KActivities #include "moc_controller.cpp"