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> | 29 | #include <QThread> | ||
30 | #include <QVariant> | 30 | #include <QVariant> | ||
31 | 31 | | |||
32 | #include <memory> | 32 | #include <memory> | ||
33 | 33 | | |||
34 | namespace KAuth { class ExecuteJob; } | 34 | namespace Auth { class PolkitQt1Backend; } | ||
35 | 35 | | |||
36 | class KJob; | | |||
37 | class Report; | 36 | class Report; | ||
38 | class CopySource; | 37 | class CopySource; | ||
39 | class CopyTarget; | 38 | class CopyTarget; | ||
40 | class QDBusInterface; | 39 | class QDBusInterface; | ||
41 | 40 | | |||
41 | class KJob; | ||||
42 | | ||||
42 | struct ExternalCommandPrivate; | 43 | struct ExternalCommandPrivate; | ||
43 | 44 | | |||
44 | class DBusThread : public QThread | 45 | class DBusThread : public QThread | ||
45 | { | 46 | { | ||
46 | Q_OBJECT | 47 | Q_OBJECT | ||
47 | // We register on DBus so the helper can monitor us and terminate if we | 48 | | ||
48 | // terminate. | 49 | private: | ||
49 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.applicationinterface") | | |||
50 | void run() override; | 50 | void run() override; | ||
51 | }; | 51 | }; | ||
52 | 52 | | |||
53 | /** An external command. | 53 | /** An external command. | ||
54 | 54 | | |||
55 | Runs an external command as a child process. | 55 | Runs an external command as a child process. | ||
56 | 56 | | |||
57 | @author Volker Lanz <vl@fidra.de> | 57 | @author Volker Lanz <vl@fidra.de> | ||
58 | @author Andrius Štikonas <andrius@stikonas.eu> | 58 | @author Andrius Štikonas <andrius@stikonas.eu> | ||
59 | */ | 59 | */ | ||
60 | class LIBKPMCORE_EXPORT ExternalCommand : public QObject | 60 | class LIBKPMCORE_EXPORT ExternalCommand : public QObject | ||
61 | { | 61 | { | ||
62 | Q_OBJECT | 62 | Q_OBJECT | ||
63 | // We register on DBus so the helper can monitor us and terminate if we terminate. | ||||
64 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.applicationinterface") | ||||
63 | Q_DISABLE_COPY(ExternalCommand) | 65 | Q_DISABLE_COPY(ExternalCommand) | ||
64 | 66 | | |||
65 | public: | 67 | public: | ||
66 | explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels); | 68 | 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); | 69 | explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels); | ||
68 | 70 | | |||
69 | ~ExternalCommand(); | 71 | ~ExternalCommand(); | ||
70 | 72 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 73 | public: | |||
120 | static void setParentWidget(QWidget *p) { | 122 | static void setParentWidget(QWidget *p) { | ||
121 | parent = p; | 123 | parent = p; | ||
122 | } | 124 | } | ||
123 | 125 | | |||
124 | Q_SIGNALS: | 126 | Q_SIGNALS: | ||
125 | void progress(int); | 127 | void progress(int); | ||
126 | void reportSignal(const QVariantMap&); | 128 | void reportSignal(const QVariantMap&); | ||
127 | 129 | | |||
130 | void newData(); | ||||
131 | | ||||
128 | public Q_SLOTS: | 132 | public Q_SLOTS: | ||
129 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | 133 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | ||
130 | 134 | | |||
135 | Q_SCRIPTABLE void emitNewData(int percent); | ||||
136 | Q_SCRIPTABLE void emitNewData(QString message); | ||||
137 | | ||||
131 | private: | 138 | private: | ||
132 | void setExitCode(int i); | 139 | void setExitCode(int i); | ||
133 | void onReadOutput(); | 140 | // void onReadOutput(); | ||
134 | 141 | | |||
135 | private: | 142 | private: | ||
136 | std::unique_ptr<ExternalCommandPrivate> d; | 143 | std::unique_ptr<ExternalCommandPrivate> d; | ||
137 | 144 | | |||
138 | // KAuth | 145 | // Authorize using Polkit backend | ||
139 | static KAuth::ExecuteJob *m_job; | 146 | static Auth::PolkitQt1Backend *m_authJob; | ||
140 | static bool helperStarted; | 147 | static bool helperStarted; | ||
141 | static QWidget *parent; | 148 | static QWidget *parent; | ||
142 | }; | 149 | }; | ||
143 | 150 | | |||
144 | #endif | 151 | #endif // KPMCORE_EXTERNALCOMMAND_H |