Plasma5Support

activityjob.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#include "activityjob.h"
8
9#include <KLocalizedString>
10#include <QDebug>
11#include <plasmaactivities/controller.h>
12
13#include <QDBusConnection>
14#include <QDBusMessage>
15
16ActivityJob::ActivityJob(KActivities::Controller *controller, const QString &id, const QString &operation, QMap<QString, QVariant> &parameters, QObject *parent)
17 : ServiceJob(parent->objectName(), operation, parameters, parent)
18 , m_activityController(controller)
19 , m_id(id)
20{
21}
22
23ActivityJob::~ActivityJob()
24{
25}
26
27void ActivityJob::start()
28{
29 const QString operation = operationName();
30 if (operation == QLatin1String("add")) {
31 // I wonder how well plasma will handle this...
32 QString name = parameters()[QStringLiteral("Name")].toString();
33 if (name.isEmpty()) {
34 name = i18n("unnamed");
35 }
36 const QString activityId = m_activityController->addActivity(name).result();
37 setResult(activityId);
38 return;
39 }
40 if (operation == QLatin1String("remove")) {
41 QString id = parameters()[QStringLiteral("Id")].toString();
42 m_activityController->removeActivity(id);
43 setResult(true);
44 return;
45 }
46
47 // m_id is needed for the rest
48 if (m_id.isEmpty()) {
49 setResult(false);
50 return;
51 }
52 if (operation == QLatin1String("setCurrent")) {
53 m_activityController->setCurrentActivity(m_id);
54 setResult(true);
55 return;
56 }
57 if (operation == QLatin1String("stop")) {
58 m_activityController->stopActivity(m_id);
59 setResult(true);
60 return;
61 }
62 if (operation == QLatin1String("start")) {
63 m_activityController->startActivity(m_id);
64 setResult(true);
65 return;
66 }
67 if (operation == QLatin1String("setName")) {
68 m_activityController->setActivityName(m_id, parameters()[QStringLiteral("Name")].toString());
69 setResult(true);
70 return;
71 }
72 if (operation == QLatin1String("setIcon")) {
73 m_activityController->setActivityIcon(m_id, parameters()[QStringLiteral("Icon")].toString());
74 setResult(true);
75 return;
76 }
77 if (operation == QLatin1String("toggleActivityManager")) {
78 QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"),
79 QStringLiteral("/PlasmaShell"),
80 QStringLiteral("org.kde.PlasmaShell"),
81 QStringLiteral("toggleActivityManager"));
83 setResult(true);
84 return;
85 }
86 setResult(false);
87}
QVariantMap parameters() const
void setResult(const QVariant &result)
Sets the result for an operation.
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
QString name(StandardAction id)
QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode, int timeout) const const
QDBusConnection sessionBus()
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.