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 <aryan100jangid@gmail.com> * | ||||
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> | ||
27 | #include <QString> | ||||
28 | #include <QVariant> | ||||
29 | 29 | | |||
30 | using namespace KAuth; | 30 | #define HELPER_MAIN() \ | ||
31 | int main(int argc, char **argv) { ExternalCommandHelper helper; return helper.helperMain(argc, argv); } | ||||
31 | 32 | | |||
32 | class ExternalCommandHelper : public QObject | 33 | class ExternalCommandHelper : public QObject | ||
33 | { | 34 | { | ||
34 | Q_OBJECT | 35 | Q_OBJECT | ||
35 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") | 36 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") | ||
36 | 37 | | |||
37 | Q_SIGNALS: | | |||
38 | void progress(int); | | |||
39 | void quit(); | | |||
40 | | ||||
41 | public: | 38 | public: | ||
42 | bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size); | 39 | 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); | 40 | bool writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset); | ||
41 | void sendProgress(int percent); | ||||
42 | void sendProgress(QString message); | ||||
43 | int helperMain(int argc, char **argv); | ||||
44 | 44 | | |||
45 | public Q_SLOTS: | 45 | public Q_SLOTS: | ||
46 | ActionReply init(const QVariantMap& args); | | |||
47 | Q_SCRIPTABLE QVariantMap start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode); | 46 | 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); | 47 | 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); | 48 | Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte); | ||
50 | Q_SCRIPTABLE void exit(); | 49 | Q_SCRIPTABLE void exit(); | ||
51 | 50 | | |||
52 | private: | 51 | private: | ||
53 | void onReadOutput(); | | |||
54 | | ||||
55 | std::unique_ptr<QEventLoop> m_loop; | 52 | std::unique_ptr<QEventLoop> m_loop; | ||
56 | QProcess m_cmd; | 53 | QProcess m_cmd; | ||
54 | | ||||
57 | // QByteArray output; | 55 | // QByteArray output; | ||
56 | // void onReadOutput(); | ||||
58 | }; | 57 | }; | ||
59 | 58 | | |||
60 | #endif | 59 | #endif // KPMCORE_EXTERNALCOMMANDHELPER_H |