d-pointerize ExternalCommand class.
This commit is contained in:
parent
9e107c8136
commit
221d7aded6
|
@ -15,9 +15,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#if !defined(KPMCORE_CAPACITY_H)
|
#ifndef KPMCORE_CAPACITY_H
|
||||||
|
|
||||||
#define KPMCORE_CAPACITY_H
|
#define KPMCORE_CAPACITY_H
|
||||||
|
|
||||||
#include "util/libpartitionmanagerexport.h"
|
#include "util/libpartitionmanagerexport.h"
|
||||||
|
|
||||||
class Partition;
|
class Partition;
|
||||||
|
@ -40,7 +40,7 @@ public:
|
||||||
/** Type of capacity to print */
|
/** Type of capacity to print */
|
||||||
enum class Type { Used, Available, Total };
|
enum class Type { Used, Available, Total };
|
||||||
/** Flags for printing */
|
/** Flags for printing */
|
||||||
enum Flag { NoFlags = 0, AppendUnit = 1, AppendBytes = 2 };
|
enum class Flag { NoFlags = 0, AppendUnit = 1, AppendBytes = 2 };
|
||||||
Q_DECLARE_FLAGS(Flags, Flag)
|
Q_DECLARE_FLAGS(Flags, Flag)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -40,17 +40,31 @@
|
||||||
#include <KJob>
|
#include <KJob>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
|
struct ExternalCommandPrivate
|
||||||
|
{
|
||||||
|
QVariantMap arguments;
|
||||||
|
|
||||||
|
Report *m_Report;
|
||||||
|
QString m_Command;
|
||||||
|
QStringList m_Args;
|
||||||
|
int m_ExitCode;
|
||||||
|
QByteArray m_Output;
|
||||||
|
QByteArray m_Input;
|
||||||
|
};
|
||||||
|
|
||||||
/** Creates a new ExternalCommand instance without Report.
|
/** Creates a new ExternalCommand instance without Report.
|
||||||
@param cmd the command to run
|
@param cmd the command to run
|
||||||
@param args the arguments to pass to the command
|
@param args the arguments to pass to the command
|
||||||
*/
|
*/
|
||||||
ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) :
|
ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) :
|
||||||
m_Report(nullptr),
|
d(std::make_unique<ExternalCommandPrivate>())
|
||||||
m_Command(cmd),
|
|
||||||
m_Args(args),
|
|
||||||
m_ExitCode(-1),
|
|
||||||
m_Output()
|
|
||||||
{
|
{
|
||||||
|
d->m_Report = nullptr;
|
||||||
|
d->m_Command = cmd;
|
||||||
|
d->m_Args = args;
|
||||||
|
d->m_ExitCode = -1;
|
||||||
|
d->m_Output = QByteArray();
|
||||||
|
|
||||||
setup(processChannelMode);
|
setup(processChannelMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,19 +74,25 @@ ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args, co
|
||||||
@param args the arguments to pass to the command
|
@param args the arguments to pass to the command
|
||||||
*/
|
*/
|
||||||
ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) :
|
ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) :
|
||||||
m_Report(report.newChild()),
|
d(std::make_unique<ExternalCommandPrivate>())
|
||||||
m_Command(cmd),
|
|
||||||
m_Args(args),
|
|
||||||
m_ExitCode(-1),
|
|
||||||
m_Output()
|
|
||||||
{
|
{
|
||||||
|
d->m_Report = report.newChild();
|
||||||
|
d->m_Command = cmd;
|
||||||
|
d->m_Args = args;
|
||||||
|
d->m_ExitCode = -1;
|
||||||
|
d->m_Output = QByteArray();
|
||||||
|
|
||||||
setup(processChannelMode);
|
setup(processChannelMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExternalCommand::~ExternalCommand()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void ExternalCommand::setup(const QProcess::ProcessChannelMode processChannelMode)
|
void ExternalCommand::setup(const QProcess::ProcessChannelMode processChannelMode)
|
||||||
{
|
{
|
||||||
arguments.insert(QStringLiteral("environment"), QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1"));
|
d->arguments.insert(QStringLiteral("environment"), QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1"));
|
||||||
arguments.insert(QStringLiteral("processChannelMode"), processChannelMode);
|
d->arguments.insert(QStringLiteral("processChannelMode"), processChannelMode);
|
||||||
|
|
||||||
// connect(this, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &ExternalCommand::onFinished);
|
// connect(this, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &ExternalCommand::onFinished);
|
||||||
// connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput);
|
// connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput);
|
||||||
|
@ -112,7 +132,7 @@ bool ExternalCommand::start(int timeout)
|
||||||
CoreBackendManager::self()->Uuid(),
|
CoreBackendManager::self()->Uuid(),
|
||||||
cmd,
|
cmd,
|
||||||
args(),
|
args(),
|
||||||
m_Input,
|
d->m_Input,
|
||||||
QStringList());
|
QStringList());
|
||||||
|
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
|
||||||
|
@ -127,7 +147,7 @@ bool ExternalCommand::start(int timeout)
|
||||||
else {
|
else {
|
||||||
QDBusPendingReply<QVariantMap> reply = *watcher;
|
QDBusPendingReply<QVariantMap> reply = *watcher;
|
||||||
|
|
||||||
m_Output = reply.value()[QStringLiteral("output")].toByteArray();
|
d->m_Output = reply.value()[QStringLiteral("output")].toByteArray();
|
||||||
setExitCode(reply.value()[QStringLiteral("exitCode")].toInt());
|
setExitCode(reply.value()[QStringLiteral("exitCode")].toInt());
|
||||||
rval = true;
|
rval = true;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +208,7 @@ bool ExternalCommand::copyBlocks(CopySource& source, CopyTarget& target)
|
||||||
|
|
||||||
bool ExternalCommand::write(const QByteArray& input)
|
bool ExternalCommand::write(const QByteArray& input)
|
||||||
{
|
{
|
||||||
m_Input = input;
|
d->m_Input = input;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,3 +261,53 @@ void ExternalCommand::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
Q_UNUSED(exitStatus)
|
Q_UNUSED(exitStatus)
|
||||||
setExitCode(exitCode);
|
setExitCode(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExternalCommand::setCommand(const QString& cmd)
|
||||||
|
{
|
||||||
|
d->m_Command = cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& ExternalCommand::command() const
|
||||||
|
{
|
||||||
|
return d->m_Command;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QStringList& ExternalCommand::args() const
|
||||||
|
{
|
||||||
|
return d->m_Args;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExternalCommand::addArg(const QString& s)
|
||||||
|
{
|
||||||
|
d->m_Args << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExternalCommand::setArgs(const QStringList& args)
|
||||||
|
{
|
||||||
|
d->m_Args = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ExternalCommand::exitCode() const
|
||||||
|
{
|
||||||
|
return d->m_ExitCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString ExternalCommand::output() const
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit(d->m_Output);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QByteArray& ExternalCommand::rawOutput() const
|
||||||
|
{
|
||||||
|
return d->m_Output;
|
||||||
|
}
|
||||||
|
|
||||||
|
Report* ExternalCommand::report()
|
||||||
|
{
|
||||||
|
return d->m_Report;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExternalCommand::setExitCode(int i)
|
||||||
|
{
|
||||||
|
d->m_ExitCode = i;
|
||||||
|
}
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#if !defined(KPMCORE_EXTERNALCOMMAND_H)
|
#ifndef KPMCORE_EXTERNALCOMMAND_H
|
||||||
|
|
||||||
#define KPMCORE_EXTERNALCOMMAND_H
|
#define KPMCORE_EXTERNALCOMMAND_H
|
||||||
|
|
||||||
#include "util/libpartitionmanagerexport.h"
|
#include "util/libpartitionmanagerexport.h"
|
||||||
|
@ -31,8 +30,11 @@
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class KJob;
|
class KJob;
|
||||||
class Report;
|
class Report;
|
||||||
|
struct ExternalCommandPrivate;
|
||||||
|
|
||||||
/** An external command.
|
/** An external command.
|
||||||
|
|
||||||
|
@ -50,14 +52,24 @@ public:
|
||||||
explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels);
|
explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels);
|
||||||
explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels);
|
explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels);
|
||||||
|
|
||||||
|
~ExternalCommand();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool copyBlocks(CopySource& source, CopyTarget& target);
|
bool copyBlocks(CopySource& source, CopyTarget& target);
|
||||||
void setCommand(const QString& cmd) { m_Command = cmd; } /**< @param cmd the command to run */
|
|
||||||
const QString& command() const { return m_Command; } /**< @return the command to run */
|
|
||||||
|
|
||||||
void addArg(const QString& s) { m_Args << s; } /**< @param s the argument to add */
|
/**< @param cmd the command to run */
|
||||||
const QStringList& args() const { return m_Args; } /**< @return the arguments */
|
void setCommand(const QString& cmd);
|
||||||
void setArgs(const QStringList& args) { m_Args = args; } /**< @param args the new arguments */
|
/**< @return the command to run */
|
||||||
|
const QString& command() const;
|
||||||
|
|
||||||
|
/**< @return the arguments */
|
||||||
|
const QStringList& args() const;
|
||||||
|
|
||||||
|
/**< @param s the argument to add */
|
||||||
|
void addArg(const QString& s);
|
||||||
|
/**< @param args the new arguments */
|
||||||
|
void setArgs(const QStringList& args);
|
||||||
|
|
||||||
bool write(const QByteArray& input); /**< @param input the input for the program */
|
bool write(const QByteArray& input); /**< @param input the input for the program */
|
||||||
|
|
||||||
bool startCopyBlocks();
|
bool startCopyBlocks();
|
||||||
|
@ -65,21 +77,16 @@ public:
|
||||||
bool waitFor(int timeout = 30000);
|
bool waitFor(int timeout = 30000);
|
||||||
bool run(int timeout = 30000);
|
bool run(int timeout = 30000);
|
||||||
|
|
||||||
int exitCode() const {
|
/**< @return the exit code */
|
||||||
return m_ExitCode; /**< @return the exit code */
|
int exitCode() const;
|
||||||
}
|
|
||||||
|
|
||||||
const QString output() const {
|
/**< @return the command output */
|
||||||
return QString::fromLocal8Bit(m_Output); /**< @return the command output */
|
const QString output() const;
|
||||||
}
|
/**< @return the command output */
|
||||||
|
const QByteArray& rawOutput() const;
|
||||||
|
|
||||||
const QByteArray& rawOutput() const {
|
/**< @return pointer to the Report or nullptr */
|
||||||
return m_Output; /**< @return the command output */
|
Report* report();
|
||||||
}
|
|
||||||
|
|
||||||
Report* report() {
|
|
||||||
return m_Report; /**< @return pointer to the Report or nullptr */
|
|
||||||
}
|
|
||||||
|
|
||||||
void emitReport(const QVariantMap& report) { emit reportSignal(report); }
|
void emitReport(const QVariantMap& report) { emit reportSignal(report); }
|
||||||
|
|
||||||
|
@ -91,23 +98,14 @@ public Q_SLOTS:
|
||||||
void emitProgress(KJob*, unsigned long percent) { emit progress(percent); };
|
void emitProgress(KJob*, unsigned long percent) { emit progress(percent); };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setExitCode(int i) {
|
void setExitCode(int i);
|
||||||
m_ExitCode = i;
|
|
||||||
}
|
|
||||||
void setup(const QProcess::ProcessChannelMode processChannelMode);
|
void setup(const QProcess::ProcessChannelMode processChannelMode);
|
||||||
|
|
||||||
void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
void onReadOutput();
|
void onReadOutput();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariantMap arguments;
|
std::unique_ptr<ExternalCommandPrivate> d;
|
||||||
|
|
||||||
Report *m_Report;
|
|
||||||
QString m_Command;
|
|
||||||
QStringList m_Args;
|
|
||||||
int m_ExitCode;
|
|
||||||
QByteArray m_Output;
|
|
||||||
QByteArray m_Input;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,15 +15,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
// #include "libpartitionmanager_export.h"
|
#ifndef LIBKPMCORE_EXPORT
|
||||||
|
|
||||||
#if !defined(KPMCORE_LIBPARTITIONMANAGEREXPORT_H)
|
|
||||||
#define KPMCORE_LIBPARTITIONMANAGEREXPORT_H
|
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#if !defined(LIBKPMCORE_EXPORT)
|
|
||||||
#define LIBKPMCORE_EXPORT Q_DECL_EXPORT
|
#define LIBKPMCORE_EXPORT Q_DECL_EXPORT
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue