Plasma5Support

hotplugjob.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Viranch Mehta <viranch.mehta@gmail.com>
3 SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#include "hotplugjob.h"
9
10#include "deviceserviceaction.h"
11
12#include <KLocalizedString>
13#include <KService>
14#include <Solid/Device>
15
16#include <QDebug>
17#include <QStandardPaths>
18
19void HotplugJob::start()
20{
21 if (operationName() == QLatin1String("invokeAction")) {
22 const QString desktopFile = parameters()[QStringLiteral("predicate")].toString();
23 const QString filePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "solid/actions/" + desktopFile);
24
25 auto services = KService(filePath).actions();
26 if (services.size() < 1) {
27 qWarning() << "Failed to resolve hotplugjob action" << desktopFile << filePath;
28 setError(KJob::UserDefinedError);
29 setErrorText(i18nc("error; %1 is the desktop file name of the service", "Failed to resolve service action for %1.", desktopFile));
30 setResult(false); // calls emitResult internally.
31 return;
32 }
33 // Cannot be > 1, we only have one filePath, and < 1 was handled as error.
34 Q_ASSERT(services.size() == 1);
35
36 DeviceServiceAction action;
37 action.setService(services.takeFirst());
38
39 Solid::Device device(m_dest);
40 action.execute(device);
41 }
42
43 emitResult();
44}
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
QList< KServiceAction > actions() const
QVariantMap parameters() const
void setResult(const QVariant &result)
Sets the result for an operation.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
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.