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; | | |||
38 | class CopySource; | 36 | class CopySource; | ||
39 | class CopyTarget; | 37 | class CopyTarget; | ||
38 | class Report; | ||||
39 | | ||||
40 | class KJob; | ||||
40 | class QDBusInterface; | 41 | class QDBusInterface; | ||
41 | 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 | // We register on DBus so the helper can monitor us and terminate if we terminate. | ||
48 | // terminate. | | |||
49 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.applicationinterface") | 49 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.applicationinterface") | ||
50 | | ||||
50 | void run() override; | 51 | void run() override; | ||
51 | }; | 52 | }; | ||
52 | 53 | | |||
53 | /** An external command. | 54 | /** An external command. | ||
54 | 55 | | |||
55 | Runs an external command as a child process. | 56 | Runs an external command as a child process. | ||
56 | 57 | | |||
57 | @author Volker Lanz <vl@fidra.de> | 58 | @author Volker Lanz <vl@fidra.de> | ||
Show All 39 Lines | 72 | public: | |||
97 | /**< @return the command output */ | 98 | /**< @return the command output */ | ||
98 | const QString output() const; | 99 | const QString output() const; | ||
99 | /**< @return the command output */ | 100 | /**< @return the command output */ | ||
100 | const QByteArray& rawOutput() const; | 101 | const QByteArray& rawOutput() const; | ||
101 | 102 | | |||
102 | /**< @return pointer to the Report or nullptr */ | 103 | /**< @return pointer to the Report or nullptr */ | ||
103 | Report* report(); | 104 | Report* report(); | ||
104 | 105 | | |||
105 | void emitReport(const QVariantMap& report) { emit reportSignal(report); } | 106 | /**< Dummy function for QTimer */ | ||
106 | | ||||
107 | /**< Dummy function for QTimer when needed. */ | | |||
108 | void quit(); | 107 | void quit(); | ||
109 | 108 | | |||
110 | // KAuth | | |||
111 | /**< start ExternalCommand Helper */ | 109 | /**< start ExternalCommand Helper */ | ||
112 | bool startHelper(); | 110 | bool startHelper(); | ||
113 | 111 | | |||
114 | /**< stop ExternalCommand Helper */ | 112 | /**< stop ExternalCommand Helper */ | ||
115 | static void stopHelper(); | 113 | static void stopHelper(); | ||
116 | 114 | | |||
117 | /**< Sets a parent widget for the authentication dialog. | 115 | /**< Sets a parent widget for the authentication dialog. | ||
118 | * @param p parent widget | 116 | * @param p parent widget | ||
119 | */ | 117 | */ | ||
120 | static void setParentWidget(QWidget *p) { | 118 | static void setParentWidget(QWidget *p) { | ||
121 | parent = p; | 119 | parent = p; | ||
122 | } | 120 | } | ||
123 | 121 | | |||
124 | Q_SIGNALS: | 122 | Q_SIGNALS: | ||
125 | void progress(int); | 123 | void progress(int); | ||
126 | void reportSignal(const QVariantMap&); | 124 | void reportSignal(const QVariantMap&); | ||
127 | 125 | | |||
128 | public Q_SLOTS: | 126 | public Q_SLOTS: | ||
129 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | 127 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | ||
128 | void emitReport(const QVariantMap& report) { emit reportSignal(report); } | ||||
130 | 129 | | |||
131 | private: | 130 | private: | ||
132 | void setExitCode(int i); | 131 | void setExitCode(int i); | ||
133 | void onReadOutput(); | 132 | // void onReadOutput(); | ||
134 | 133 | | |||
135 | private: | 134 | private: | ||
136 | std::unique_ptr<ExternalCommandPrivate> d; | 135 | std::unique_ptr<ExternalCommandPrivate> d; | ||
137 | 136 | | |||
138 | // KAuth | 137 | // Use Polkit Authorization backend for authorizing actions | ||
139 | static KAuth::ExecuteJob *m_job; | 138 | static Auth::PolkitQt1Backend *m_authJob; | ||
140 | static bool helperStarted; | 139 | static bool helperStarted; | ||
141 | static QWidget *parent; | 140 | static QWidget *parent; | ||
142 | }; | 141 | }; | ||
143 | 142 | | |||
144 | #endif | 143 | #endif // KPMCORE_EXTERNALCOMMAND_H |