2020-10-01 00:33:19 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2017-2020 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2018 Huzaifa Faruqui <huzaifafaruqui@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2019 Shubham Jangra <aryan100jangid@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2017-11-07 22:55:28 +00:00
|
|
|
|
|
|
|
#ifndef KPMCORE_EXTERNALCOMMANDHELPER_H
|
|
|
|
#define KPMCORE_EXTERNALCOMMANDHELPER_H
|
|
|
|
|
2018-08-03 19:37:24 +01:00
|
|
|
#include <memory>
|
2018-07-21 11:03:25 +01:00
|
|
|
#include <unordered_set>
|
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
#include <KAuth>
|
|
|
|
|
2018-03-19 10:33:20 +00:00
|
|
|
#include <QEventLoop>
|
2019-06-12 17:41:11 +01:00
|
|
|
#include <QString>
|
2017-11-07 22:55:28 +00:00
|
|
|
#include <QProcess>
|
2020-10-08 02:23:24 +01:00
|
|
|
#include <QDBusContext>
|
|
|
|
|
|
|
|
class QDBusServiceWatcher;
|
2017-11-07 22:55:28 +00:00
|
|
|
|
|
|
|
using namespace KAuth;
|
|
|
|
|
2020-10-08 02:23:24 +01:00
|
|
|
class ExternalCommandHelper : public QObject, public QDBusContext
|
2017-11-07 22:55:28 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-03-19 10:33:20 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand")
|
2017-11-07 22:55:28 +00:00
|
|
|
|
2018-01-24 15:22:42 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void progress(int);
|
2018-03-19 10:33:20 +00:00
|
|
|
void quit();
|
2018-01-24 15:22:42 +00:00
|
|
|
|
|
|
|
public:
|
2020-10-08 02:23:24 +01:00
|
|
|
ExternalCommandHelper();
|
2019-03-29 17:51:51 +00:00
|
|
|
bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size);
|
|
|
|
bool writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset);
|
2020-09-10 23:54:23 +01:00
|
|
|
bool createFile(const QString& filePath, const QByteArray& fileContents);
|
2018-01-24 15:22:42 +00:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
public Q_SLOTS:
|
2019-05-18 19:50:10 +01:00
|
|
|
Q_SCRIPTABLE QVariantMap start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode);
|
|
|
|
Q_SCRIPTABLE QVariantMap copyblocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize);
|
|
|
|
Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte);
|
2020-09-10 23:54:23 +01:00
|
|
|
Q_SCRIPTABLE bool createFile(const QByteArray& fileContents, const QString& filePath);
|
2019-05-18 19:50:10 +01:00
|
|
|
Q_SCRIPTABLE void exit();
|
2018-03-23 21:19:33 +00:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
private:
|
|
|
|
|
2020-10-08 02:23:24 +01:00
|
|
|
bool isCallerAuthorized();
|
|
|
|
|
|
|
|
void onReadOutput();
|
2018-03-19 10:33:20 +00:00
|
|
|
QProcess m_cmd;
|
2020-10-08 02:23:24 +01:00
|
|
|
QDBusServiceWatcher *m_serviceWatcher = nullptr;
|
2017-11-07 22:55:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|