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>
|
2020-10-09 20:41:41 +01:00
|
|
|
SPDX-FileCopyrightText: 2020 David Edmundson <kde@davidedmundson.co.uk>
|
2020-10-01 00:33:19 +01:00
|
|
|
|
|
|
|
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>
|
|
|
|
|
2022-02-06 21:01:05 +00:00
|
|
|
#include <QDBusContext>
|
2018-03-19 10:33:20 +00:00
|
|
|
#include <QEventLoop>
|
2022-02-06 21:01:05 +00:00
|
|
|
#include <QFile>
|
2017-11-07 22:55:28 +00:00
|
|
|
#include <QProcess>
|
2022-02-06 21:01:05 +00:00
|
|
|
#include <QString>
|
2020-10-08 02:23:24 +01:00
|
|
|
|
|
|
|
class QDBusServiceWatcher;
|
2022-02-15 19:06:12 +00:00
|
|
|
constexpr qint64 MiB = 1 << 20;
|
2017-11-07 22:55:28 +00:00
|
|
|
|
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:
|
2020-10-11 23:46:20 +01:00
|
|
|
Q_SCRIPTABLE void progress(int);
|
|
|
|
Q_SCRIPTABLE void report(QString);
|
2018-01-24 15:22:42 +00:00
|
|
|
|
|
|
|
public:
|
2020-10-08 02:23:24 +01:00
|
|
|
ExternalCommandHelper();
|
2022-02-06 21:06:23 +00:00
|
|
|
bool readData(QFile& device, QByteArray& buffer, const qint64 offset, const qint64 size);
|
2022-02-06 21:01:05 +00:00
|
|
|
bool writeData(QFile& device, const QByteArray& buffer, const qint64 offset);
|
2018-01-24 15:22:42 +00:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
public Q_SLOTS:
|
2020-10-11 22:45:13 +01:00
|
|
|
Q_SCRIPTABLE QVariantMap RunCommand(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode);
|
2022-02-05 14:05:50 +00:00
|
|
|
Q_SCRIPTABLE QVariantMap CopyFileData(const QString& sourceDevice, const qint64 sourceOffset, const qint64 sourceLength,
|
2020-11-29 23:14:08 +00:00
|
|
|
const QString& targetDevice, const qint64 targetOffset, const qint64 blockSize);
|
|
|
|
Q_SCRIPTABLE QByteArray ReadData(const QString& device, const qint64 offset, const qint64 length);
|
2020-11-29 13:08:53 +00:00
|
|
|
Q_SCRIPTABLE bool WriteData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetOffset);
|
2022-02-20 19:42:25 +00:00
|
|
|
Q_SCRIPTABLE bool WriteFstab(const QByteArray& fileContents);
|
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();
|
|
|
|
QDBusServiceWatcher *m_serviceWatcher = nullptr;
|
2017-11-07 22:55:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|