Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommand.h
Show All 19 Lines | |||||
20 | #define KPMCORE_EXTERNALCOMMAND_H | 20 | #define KPMCORE_EXTERNALCOMMAND_H | ||
21 | 21 | | |||
22 | #include "util/libpartitionmanagerexport.h" | 22 | #include "util/libpartitionmanagerexport.h" | ||
23 | 23 | | |||
24 | #include <QDebug> | 24 | #include <QDebug> | ||
25 | #include <QProcess> | 25 | #include <QProcess> | ||
26 | #include <QString> | 26 | #include <QString> | ||
27 | #include <QStringList> | 27 | #include <QStringList> | ||
28 | #include <QtGlobal> | | |||
29 | #include <QThread> | 28 | #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; | ||||
38 | | ||||
39 | class KJob; | ||||
40 | class QDBusInterface; | 40 | class QDBusInterface; | ||
41 | 41 | | |||
42 | struct ExternalCommandPrivate; | 42 | struct ExternalCommandPrivate; | ||
43 | 43 | | |||
44 | class DBusThread : public QThread | 44 | class DBusThread : public QThread | ||
45 | { | 45 | { | ||
46 | Q_OBJECT | 46 | Q_OBJECT | ||
47 | // We register on DBus so the helper can monitor us and terminate if we | 47 | // 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") | 48 | Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.applicationinterface") | ||
49 | | ||||
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> | ||
Show All 39 Lines | 71 | public: | |||
97 | /**< @return the command output */ | 97 | /**< @return the command output */ | ||
98 | const QString output() const; | 98 | const QString output() const; | ||
99 | /**< @return the command output */ | 99 | /**< @return the command output */ | ||
100 | const QByteArray& rawOutput() const; | 100 | const QByteArray& rawOutput() const; | ||
101 | 101 | | |||
102 | /**< @return pointer to the Report or nullptr */ | 102 | /**< @return pointer to the Report or nullptr */ | ||
103 | Report* report(); | 103 | Report* report(); | ||
104 | 104 | | |||
105 | void emitReport(const QVariantMap& report) { emit reportSignal(report); } | | |||
106 | | ||||
107 | /**< Dummy function for QTimer when needed. */ | 105 | /**< Dummy function for QTimer when needed. */ | ||
108 | void quit(); | 106 | void quit(); | ||
109 | 107 | | |||
110 | // KAuth | | |||
111 | /**< start ExternalCommand Helper */ | 108 | /**< start ExternalCommand Helper */ | ||
112 | bool startHelper(); | 109 | bool startHelper(); | ||
113 | 110 | | |||
114 | /**< stop ExternalCommand Helper */ | 111 | /**< stop ExternalCommand Helper */ | ||
115 | static void stopHelper(); | 112 | static void stopHelper(); | ||
116 | 113 | | |||
117 | /**< Sets a parent widget for the authentication dialog. | 114 | /**< Sets a parent widget for the authentication dialog. | ||
118 | * @param p parent widget | 115 | * @param p parent widget | ||
119 | */ | 116 | */ | ||
120 | static void setParentWidget(QWidget *p) { | 117 | static void setParentWidget(QWidget *p) { | ||
121 | parent = p; | 118 | parent = p; | ||
122 | } | 119 | } | ||
123 | 120 | | |||
124 | Q_SIGNALS: | 121 | Q_SIGNALS: | ||
125 | void progress(int); | 122 | void progress(int); | ||
126 | void reportSignal(const QVariantMap&); | 123 | void reportSignal(const QVariantMap&); | ||
127 | 124 | | |||
128 | public Q_SLOTS: | 125 | public Q_SLOTS: | ||
129 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | 126 | void emitProgress(KJob*, unsigned long percent) { emit progress(percent); } | ||
127 | void emitReport(const QVariantMap& report) { emit reportSignal(report); } | ||||
130 | 128 | | |||
131 | private: | 129 | private: | ||
132 | void setExitCode(int i); | 130 | void setExitCode(int i); | ||
133 | void onReadOutput(); | 131 | // void onReadOutput(); | ||
134 | 132 | | |||
135 | private: | 133 | private: | ||
136 | std::unique_ptr<ExternalCommandPrivate> d; | 134 | std::unique_ptr<ExternalCommandPrivate> d; | ||
137 | 135 | | |||
138 | // KAuth | 136 | // Use Polkit Authorization backend for authorizing actions | ||
139 | static KAuth::ExecuteJob *m_job; | 137 | static Auth::PolkitQt1Backend *m_authJob; | ||
140 | static bool helperStarted; | 138 | static bool helperStarted; | ||
141 | static QWidget *parent; | 139 | static QWidget *parent; | ||
140 | | ||||
142 | }; | 141 | }; | ||
143 | 142 | | |||
144 | #endif | 143 | #endif |