Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommand.h
1 | /************************************************************************* | 1 | /************************************************************************* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2008 by Volker Lanz <vl@fidra.de> * | 2 | * Copyright (C) 2008 by Volker Lanz <vl@fidra.de> * | ||
3 | * Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> * | 3 | * Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> * | ||
4 | * Copyright (C) 2019 by Shubham <aryan100jangid@gmail.com> * | ||||
4 | * * | 5 | * * | ||
5 | * This program is free software; you can redistribute it and/or * | 6 | * This program is free software; you can redistribute it and/or * | ||
6 | * modify it under the terms of the GNU General Public License as * | 7 | * modify it under the terms of the GNU General Public License as * | ||
7 | * published by the Free Software Foundation; either version 3 of * | 8 | * published by the Free Software Foundation; either version 3 of * | ||
8 | * the License, or (at your option) any later version. * | 9 | * the License, or (at your option) any later version. * | ||
9 | * * | 10 | * * | ||
10 | * This program is distributed in the hope that it will be useful, * | 11 | * This program is distributed in the hope that it will be useful, * | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
13 | * GNU General Public License for more details. * | 14 | * GNU General Public License for more details. * | ||
14 | * * | 15 | * * | ||
15 | * You should have received a copy of the GNU General Public License * | 16 | * You should have received a copy of the GNU General Public License * | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | ||
17 | *************************************************************************/ | 18 | *************************************************************************/ | ||
18 | 19 | | |||
19 | #ifndef KPMCORE_EXTERNALCOMMAND_H | 20 | #ifndef KPMCORE_EXTERNALCOMMAND_H | ||
20 | #define KPMCORE_EXTERNALCOMMAND_H | 21 | #define KPMCORE_EXTERNALCOMMAND_H | ||
21 | 22 | | |||
22 | #include "util/libpartitionmanagerexport.h" | 23 | #include "util/libpartitionmanagerexport.h" | ||
23 | 24 | | |||
24 | #include <QDebug> | 25 | #include <QDebug> | ||
25 | #include <QProcess> | 26 | #include <QProcess> | ||
26 | #include <QString> | 27 | #include <QString> | ||
27 | #include <QStringList> | 28 | #include <QStringList> | ||
28 | #include <QtGlobal> | | |||
29 | #include <QThread> | | |||
30 | #include <QVariant> | 29 | #include <QVariant> | ||
31 | 30 | | |||
32 | #include <memory> | 31 | #include <memory> | ||
33 | 32 | | |||
34 | namespace KAuth { class ExecuteJob; } | 33 | namespace Auth { class PolkitQt1Backend; } | ||
35 | 34 | | |||
36 | class KJob; | | |||
37 | class Report; | | |||
38 | class CopySource; | 35 | class CopySource; | ||
39 | class CopyTarget; | 36 | class CopyTarget; | ||
37 | class Report; | ||||
40 | class QDBusInterface; | 38 | class QDBusInterface; | ||
39 | class KJob; | ||||
41 | 40 | | |||
42 | struct ExternalCommandPrivate; | 41 | struct ExternalCommandPrivate; | ||
43 | 42 | | |||
44 | class DBusThread : public QThread | | |||
45 | { | | |||
46 | Q_OBJECT | | |||
47 | // We register on DBus so the helper can monitor us and terminate if we | | |||
48 | // terminate. | | |||
49 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.applicationinterface") | | |||
50 | void run() override; | | |||
51 | }; | | |||
52 | | ||||
53 | /** An external command. | 43 | /** An external command. | ||
54 | 44 | | |||
55 | Runs an external command as a child process. | 45 | Runs an external command as a child process. | ||
56 | 46 | | |||
57 | @author Volker Lanz <vl@fidra.de> | 47 | @author Volker Lanz <vl@fidra.de> | ||
58 | @author Andrius Štikonas <andrius@stikonas.eu> | 48 | @author Andrius Štikonas <andrius@stikonas.eu> | ||
59 | */ | 49 | */ | ||
60 | class LIBKPMCORE_EXPORT ExternalCommand : public QObject | 50 | class LIBKPMCORE_EXPORT ExternalCommand : public QObject | ||
61 | { | 51 | { | ||
62 | Q_OBJECT | 52 | Q_OBJECT | ||
53 | // We register on DBus so the helper can monitor us and terminate if we terminate. | ||||
54 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.applicationinterface") | ||||
63 | Q_DISABLE_COPY(ExternalCommand) | 55 | Q_DISABLE_COPY(ExternalCommand) | ||
64 | 56 | | |||
65 | public: | 57 | public: | ||
66 | explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels); | 58 | explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels); | ||
67 | explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels); | 59 | explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels); | ||
68 | 60 | | |||
69 | ~ExternalCommand(); | 61 | ~ExternalCommand(); | ||
70 | 62 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 63 | public: | |||
120 | static void setParentWidget(QWidget *p) { | 112 | static void setParentWidget(QWidget *p) { | ||
121 | parent = p; | 113 | parent = p; | ||
122 | } | 114 | } | ||
123 | 115 | | |||
124 | Q_SIGNALS: | 116 | Q_SIGNALS: | ||
125 | void progress(int); | 117 | void progress(int); | ||
126 | void reportSignal(const QVariantMap&); | 118 | void reportSignal(const QVariantMap&); | ||
127 | 119 | | |||
120 | void newData(); | ||||
121 | | ||||
128 | public Q_SLOTS: | 122 | public Q_SLOTS: | ||
129 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | 123 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | ||
130 | 124 | | |||
125 | Q_SCRIPTABLE void emitNewData(int percent); | ||||
126 | Q_SCRIPTABLE void emitNewData(QString message); | ||||
127 | | ||||
131 | private: | 128 | private: | ||
132 | void setExitCode(int i); | 129 | void setExitCode(int i); | ||
133 | void onReadOutput(); | 130 | // void onReadOutput(); | ||
134 | 131 | | |||
135 | private: | 132 | private: | ||
136 | std::unique_ptr<ExternalCommandPrivate> d; | 133 | std::unique_ptr<ExternalCommandPrivate> d; | ||
137 | 134 | | |||
138 | // KAuth | 135 | // Authorize using Polkit backend | ||
139 | static KAuth::ExecuteJob *m_job; | 136 | static Auth::PolkitQt1Backend *m_authJob; | ||
140 | static bool helperStarted; | 137 | static bool helperStarted; | ||
141 | static QWidget *parent; | 138 | static QWidget *parent; | ||
142 | }; | 139 | }; | ||
143 | 140 | | |||
144 | #endif | 141 | #endif // KPMCORE_EXTERNALCOMMAND_H |