Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommandhelper.h
1 | /************************************************************************* | 1 | /************************************************************************* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2017-2018 by Andrius Štikonas <andrius@stikonas.eu> * | 2 | * Copyright (C) 2017-2018 by Andrius Štikonas <andrius@stikonas.eu> * | ||
3 | * Copyright (C) 2019 by Shubham <shubham.jangra@kdemail.net> * | ||||
3 | * * | 4 | * * | ||
4 | * This program is free software; you can redistribute it and/or * | 5 | * This program is free software; you can redistribute it and/or * | ||
5 | * modify it under the terms of the GNU General Public License as * | 6 | * modify it under the terms of the GNU General Public License as * | ||
6 | * published by the Free Software Foundation; either version 3 of * | 7 | * published by the Free Software Foundation; either version 3 of * | ||
7 | * the License, or (at your option) any later version. * | 8 | * the License, or (at your option) any later version. * | ||
8 | * * | 9 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | 10 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
12 | * GNU General Public License for more details. * | 13 | * GNU General Public License for more details. * | ||
13 | * * | 14 | * * | ||
14 | * You should have received a copy of the GNU General Public License * | 15 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | ||
16 | *************************************************************************/ | 17 | *************************************************************************/ | ||
17 | 18 | | |||
18 | #ifndef KPMCORE_EXTERNALCOMMANDHELPER_H | 19 | #ifndef KPMCORE_EXTERNALCOMMANDHELPER_H | ||
19 | #define KPMCORE_EXTERNALCOMMANDHELPER_H | 20 | #define KPMCORE_EXTERNALCOMMANDHELPER_H | ||
20 | 21 | | |||
21 | #include <memory> | 22 | #include <memory> | ||
22 | #include <unordered_set> | 23 | #include <unordered_set> | ||
23 | 24 | | |||
24 | #include <KAuth> | | |||
25 | | ||||
26 | #include <QEventLoop> | 25 | #include <QEventLoop> | ||
27 | #include <QString> | | |||
28 | #include <QProcess> | 26 | #include <QProcess> | ||
29 | 27 | #include <QString> | |||
30 | using namespace KAuth; | 28 | #include <QVariant> | ||
31 | 29 | | |||
32 | class ExternalCommandHelper : public QObject | 30 | class ExternalCommandHelper : public QObject | ||
33 | { | 31 | { | ||
34 | Q_OBJECT | 32 | Q_OBJECT | ||
35 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") | 33 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") | ||
36 | 34 | | |||
37 | Q_SIGNALS: | 35 | Q_SIGNALS: | ||
38 | void progress(int); | 36 | void progress(int percent); | ||
39 | void quit(); | 37 | void reportProgress(const QVariantMap &progress); | ||
40 | 38 | | |||
41 | public: | 39 | public: | ||
42 | bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size); | 40 | bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size); | ||
43 | bool writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset); | 41 | bool writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset); | ||
44 | 42 | | |||
45 | public Q_SLOTS: | 43 | public Q_SLOTS: | ||
46 | ActionReply init(const QVariantMap& args); | 44 | Q_SCRIPTABLE QVariantMap init(QVariantMap reply); | ||
47 | Q_SCRIPTABLE QVariantMap start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode); | 45 | Q_SCRIPTABLE QVariantMap start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode); | ||
48 | Q_SCRIPTABLE QVariantMap copyblocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize); | 46 | Q_SCRIPTABLE QVariantMap copyblocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize); | ||
49 | Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte); | 47 | Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte); | ||
50 | Q_SCRIPTABLE void exit(); | 48 | Q_SCRIPTABLE void exit(); | ||
51 | 49 | | |||
52 | private: | 50 | private: | ||
53 | void onReadOutput(); | | |||
54 | | ||||
55 | std::unique_ptr<QEventLoop> m_loop; | 51 | std::unique_ptr<QEventLoop> m_loop; | ||
56 | QProcess m_cmd; | 52 | QProcess m_cmd; | ||
53 | | ||||
57 | // QByteArray output; | 54 | // QByteArray output; | ||
55 | // void onReadOutput(); | ||||
58 | }; | 56 | }; | ||
59 | 57 | | |||
60 | #endif | 58 | #endif // KPMCORE_EXTERNALCOMMANDHELPER_H |