diff --git a/src/backend/corebackendmanager.cpp b/src/backend/corebackendmanager.cpp index 195bbf6..04cc7b2 100644 --- a/src/backend/corebackendmanager.cpp +++ b/src/backend/corebackendmanager.cpp @@ -1,131 +1,128 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * Copyright (C) 2015 by Teo Mrnjavac * - * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2016-2018 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "backend/corebackendmanager.h" #include "backend/corebackend.h" #include #include #include #include #include #include -#include #include #include #include #include #include #include CoreBackendManager::CoreBackendManager() : m_Backend(nullptr) { - m_KAuthThread = new QThread(); - kauthThread()->start(); } CoreBackendManager* CoreBackendManager::self() { static CoreBackendManager* instance = nullptr; if (instance == nullptr) instance = new CoreBackendManager; return instance; } QVector CoreBackendManager::list() const { auto filter = [&](const KPluginMetaData &metaData) { return metaData.serviceTypes().contains(QStringLiteral("PartitionManager/Plugin")) && metaData.category().contains(QStringLiteral("BackendPlugin")); }; // find backend plugins in standard path (e.g. /usr/lib64/qt5/plugins) using filter from above return KPluginLoader::findPlugins(QString(), filter); } void CoreBackendManager::startExternalCommandHelper() { KAuth::Action action = KAuth::Action(QStringLiteral("org.kde.kpmcore.externalcommand.init")); action.setHelperId(QStringLiteral("org.kde.kpmcore.externalcommand")); action.setTimeout(10 * 24 * 3600 * 1000); // 10 days QVariantMap arguments; m_Uuid = QUuid::createUuid().toString(); arguments.insert(QStringLiteral("callerUuid"), Uuid()); action.setArguments(arguments); m_job = action.execute(); job()->start(); QEventLoop loop; auto exitLoop = [&] () {loop.exit();}; auto conn = QObject::connect(job(), &KAuth::ExecuteJob::newData, exitLoop); loop.exec(); QObject::disconnect(conn); } void CoreBackendManager::stopExternalCommandHelper() { QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus()); if (iface.isValid()) iface.call(QStringLiteral("exit"), CoreBackendManager::self()->Uuid()); } KAuth::ExecuteJob* CoreBackendManager::job() { return m_job; } bool CoreBackendManager::load(const QString& name) { if (backend()) unload(); KPluginLoader loader(name); KPluginFactory* factory = loader.factory(); if (factory != nullptr) { m_Backend = factory->create(nullptr); QString id = loader.metaData().toVariantMap().value(QStringLiteral("MetaData")) .toMap().value(QStringLiteral("KPlugin")).toMap().value(QStringLiteral("Id")).toString(); QString version = loader.metaData().toVariantMap().value(QStringLiteral("MetaData")) .toMap().value(QStringLiteral("KPlugin")).toMap().value(QStringLiteral("Version")).toString(); if (id.isEmpty()) return false; backend()->setId(id); backend()->setVersion(version); qDebug() << "Loaded backend plugin: " << backend()->id(); startExternalCommandHelper(); return true; } qWarning() << "Could not load plugin for core backend " << name << ": " << loader.errorString(); return false; } void CoreBackendManager::unload() { delete m_Backend; m_Backend = nullptr; } diff --git a/src/backend/corebackendmanager.h b/src/backend/corebackendmanager.h index d6b843a..a754252 100644 --- a/src/backend/corebackendmanager.h +++ b/src/backend/corebackendmanager.h @@ -1,119 +1,111 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * + * Copyright (C) 2018 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(KPMCORE_COREBACKENDMANAGER_H) #define KPMCORE_COREBACKENDMANAGER_H #include "util/libpartitionmanagerexport.h" #include #include #include -class QThread; class QString; class QStringList; class KPluginMetaData; class CoreBackend; /** * The backend manager class. * * This is basically a singleton class to give the application access to the currently * selected backend and also to manage the available backend plugins. * @author Volker Lanz */ class LIBKPMCORE_EXPORT CoreBackendManager { private: CoreBackendManager(); public: /** * @return pointer to ourselves */ static CoreBackendManager* self(); /** * @return the name of the default backend plugin */ static QString defaultBackendName() { return QStringLiteral("pmsfdiskbackendplugin"); } /** * @return a list of available backend plugins */ QVector list() const; /** * Loads the given backend plugin into the application. * @param name the name of the plugin to load * @return true on success */ bool load(const QString& name); /** * Unload the current plugin. */ void unload(); /** * @return a pointer to the currently loaded backend */ CoreBackend* backend() { return m_Backend; } - /** - * @return a pointer to the thread where ExternalCommand will start KAuth job - */ - QThread* kauthThread() { - return m_KAuthThread; - } - /** * @return a pointer to the currently loaded backend */ QString& Uuid() { return m_Uuid; } /** * @return a pointer to the KAuth job */ KAuth::ExecuteJob* job(); /** * stop ExternalCommand Helper */ static void stopExternalCommandHelper(); private: void startExternalCommandHelper(); private: CoreBackend *m_Backend; - QThread *m_KAuthThread; KAuth::ExecuteJob *m_job; QString m_Uuid; }; #endif diff --git a/src/jobs/checkfilesystemjob.cpp b/src/jobs/checkfilesystemjob.cpp index 55110f2..7b7cd92 100644 --- a/src/jobs/checkfilesystemjob.cpp +++ b/src/jobs/checkfilesystemjob.cpp @@ -1,59 +1,58 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "jobs/checkfilesystemjob.h" #include "core/partition.h" #include "fs/filesystem.h" #include "util/report.h" #include -#include #include /** Creates a new CheckFileSystemJob @param p the Partition whose FileSystem is to be checked */ CheckFileSystemJob::CheckFileSystemJob(Partition& p) : Job(), m_Partition(p) { } bool CheckFileSystemJob::run(Report& parent) { Report* report = jobStarted(parent); // if we cannot check, assume everything is fine bool rval = true; if (partition().fileSystem().supportCheck() == FileSystem::cmdSupportFileSystem) rval = partition().fileSystem().check(*report, partition().deviceNode()); jobFinished(*report, rval); return rval; } QString CheckFileSystemJob::description() const { return xi18nc("@info:progress", "Check file system on partition %1", partition().deviceNode()); } diff --git a/src/jobs/job.cpp b/src/jobs/job.cpp index 453521b..8ba23ae 100644 --- a/src/jobs/job.cpp +++ b/src/jobs/job.cpp @@ -1,163 +1,163 @@ /************************************************************************* * Copyright (C) 2008, 2009, 2010 by Volker Lanz * - * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2016-2018 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "jobs/job.h" #include "core/device.h" #include "core/copysource.h" #include "core/copytarget.h" #include "core/copysourcedevice.h" #include "core/copytargetdevice.h" #include "util/externalcommand.h" #include "util/report.h" #include #include #include #include Job::Job() : m_Report(nullptr), m_Status(Pending) { } bool Job::copyBlocks(Report& report, CopyTarget& target, CopySource& source) { m_Report = &report; - ExternalCommand copyCmd(source, target, QProcess::SeparateChannels); + ExternalCommand copyCmd; connect(©Cmd, &ExternalCommand::progress, this, &Job::progress, Qt::QueuedConnection); connect(©Cmd, &ExternalCommand::reportSignal, this, &Job::updateReport, Qt::QueuedConnection); - if (copyCmd.startCopyBlocks() && copyCmd.exitCode() == 0) { + if (copyCmd.copyBlocks(source, target)) { return true; } return false; } bool Job::rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource& origSource) { if (!origSource.overlaps(origTarget)) { report.line() << xi18nc("@info:progress", "Source and target for copying do not overlap: Rollback is not required."); return true; } try { CopySourceDevice& csd = dynamic_cast(origSource); CopyTargetDevice& ctd = dynamic_cast(origTarget); // default: use values as if we were copying from front to back. qint64 undoSourceFirstByte = origTarget.firstByte(); qint64 undoSourceLastByte = origTarget.firstByte() + origTarget.bytesWritten() - 1; qint64 undoTargetFirstByte = origSource.firstByte(); qint64 undoTargetLastByte = origSource.firstByte() + origTarget.bytesWritten() - 1; if (origTarget.firstByte() > origSource.firstByte()) { // we were copying from back to front undoSourceFirstByte = origTarget.firstByte() + origSource.length() - origTarget.bytesWritten(); undoSourceLastByte = origTarget.firstByte() + origSource.length() - 1; undoTargetFirstByte = origSource.lastByte() - origTarget.bytesWritten() + 1; undoTargetLastByte = origSource.lastByte(); } report.line() << xi18nc("@info:progress", "Rollback from: First byte: %1, last byte: %2.", undoSourceFirstByte, undoSourceLastByte); report.line() << xi18nc("@info:progress", "Rollback to: First byte: %1, last byte: %2.", undoTargetFirstByte, undoTargetLastByte); CopySourceDevice undoSource(ctd.device(), undoSourceFirstByte, undoSourceLastByte); if (!undoSource.open()) { report.line() << xi18nc("@info:progress", "Could not open device %1 to rollback copying.", ctd.device().deviceNode()); return false; } CopyTargetDevice undoTarget(csd.device(), undoTargetFirstByte, undoTargetLastByte); if (!undoTarget.open()) { report.line() << xi18nc("@info:progress", "Could not open device %1 to rollback copying.", csd.device().deviceNode()); return false; } return copyBlocks(report, undoTarget, undoSource); } catch (...) { report.line() << xi18nc("@info:progress", "Rollback failed: Source or target are not devices."); } return false; } void Job::emitProgress(int i) { emit progress(i); } void Job::updateReport(const QVariantMap& reportString) { m_Report->line() << reportString[QStringLiteral("report")].toString(); } Report* Job::jobStarted(Report& parent) { emit started(); return parent.newChild(xi18nc("@info:progress", "Job: %1", description())); } void Job::jobFinished(Report& report, bool b) { setStatus(b ? Success : Error); emit progress(numSteps()); emit finished(); report.setStatus(xi18nc("@info:progress job status (error, warning, ...)", "%1: %2", description(), statusText())); } /** @return the Job's current status icon */ QString Job::statusIcon() const { static const QString icons[] = { QStringLiteral("dialog-information"), QStringLiteral("dialog-ok"), QStringLiteral("dialog-error") }; Q_ASSERT(status() >= 0 && static_cast(status()) < sizeof(icons) / sizeof(icons[0])); if (status() < 0 || static_cast(status()) >= sizeof(icons) / sizeof(icons[0])) return QString(); return icons[status()]; } /** @return the Job's current status text */ QString Job::statusText() const { static const QString s[] = { xi18nc("@info:progress job", "Pending"), xi18nc("@info:progress job", "Success"), xi18nc("@info:progress job", "Error") }; Q_ASSERT(status() >= 0 && static_cast(status()) < sizeof(s) / sizeof(s[0])); if (status() < 0 || static_cast(status()) >= sizeof(s) / sizeof(s[0])) return QString(); return s[status()]; } diff --git a/src/util/externalcommand.cpp b/src/util/externalcommand.cpp index 533cde1..8cfe5b3 100644 --- a/src/util/externalcommand.cpp +++ b/src/util/externalcommand.cpp @@ -1,259 +1,236 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * - * Copyright (C) 2016 by Andrius Štikonas * + * Copyright (C) 2016-2018 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #include "backend/corebackendmanager.h" #include "core/device.h" #include "core/copysource.h" #include "core/copytarget.h" #include "core/copysourcedevice.h" #include "core/copytargetdevice.h" #include "util/externalcommand.h" #include "util/report.h" #include #include #include #include #include #include #include #include #include #include #include #include - -ExternalCommand::ExternalCommand(CopySource& source, CopyTarget& target,const QProcess::ProcessChannelMode processChannelMode) : - m_ExitCode(-1), - m_Source(&source), - m_Target(&target) -{ - setup(processChannelMode); -} - -/** Starts copyBlocks command. -*/ -bool ExternalCommand::startCopyBlocks() -{ - this->moveToThread(CoreBackendManager::self()->kauthThread()); - QTimer::singleShot(0, this, &ExternalCommand::copyBlocks); - QEventLoop loop; - connect(this, &ExternalCommand::finished, &loop, &QEventLoop::quit); - loop.exec(); - return true; -} - -bool ExternalCommand::copyBlocks() +bool ExternalCommand::copyBlocks(CopySource& source, CopyTarget& target) { bool rval = true; const qint64 blockSize = 10 * 1024 * 1024; // number of bytes per block to copy if (!QDBusConnection::systemBus().isConnected()) { qWarning() << "Could not connect to DBus system bus"; return false; } // TODO KF6:Use new signal-slot syntax connect(CoreBackendManager::self()->job(), SIGNAL(percent(KJob*, unsigned long)), this, SLOT(emitProgress(KJob*, unsigned long))); connect(CoreBackendManager::self()->job(), &KAuth::ExecuteJob::newData, this, &ExternalCommand::emitReport); QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus()); iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days if (iface.isValid()) { - QDBusPendingCall pcall= iface.asyncCall(QStringLiteral("copyblocks"), CoreBackendManager::self()->Uuid(), m_Source->path(), m_Source->firstByte(), m_Source->length(), m_Target->path(), m_Target->firstByte(), blockSize); + QDBusPendingCall pcall= iface.asyncCall(QStringLiteral("copyblocks"), CoreBackendManager::self()->Uuid(), source.path(), source.firstByte(), source.length(), target.path(), target.firstByte(), blockSize); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); QEventLoop loop; auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) { loop.exit(); if (watcher->isError()) { qWarning() << watcher->error(); } else { QDBusPendingReply reply = *watcher; rval = reply.argumentAt<0>(); } - emit finished(); setExitCode(!rval); }; connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop); loop.exec(); } return rval; } /** Creates a new ExternalCommand instance without Report. @param cmd the command to run @param args the arguments to pass to the command */ ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) : m_Report(nullptr), m_Command(cmd), m_Args(args), m_ExitCode(-1), m_Output() { setup(processChannelMode); } /** Creates a new ExternalCommand instance with Report. @param report the Report to write output to. @param cmd the command to run @param args the arguments to pass to the command */ ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) : m_Report(report.newChild()), m_Command(cmd), m_Args(args), m_ExitCode(-1), m_Output() { setup(processChannelMode); } void ExternalCommand::setup(const QProcess::ProcessChannelMode processChannelMode) { arguments.insert(QStringLiteral("environment"), QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1")); arguments.insert(QStringLiteral("processChannelMode"), processChannelMode); // connect(this, qOverload(&QProcess::finished), this, &ExternalCommand::onFinished); // connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput); } /** Executes the external command. @param timeout timeout to wait for the process to start @return true on success */ bool ExternalCommand::start(int timeout) { Q_UNUSED(timeout) if (report()) { report()->setCommand(xi18nc("@info:status", "Command: %1 %2", command(), args().join(QStringLiteral(" ")))); } QString cmd = QStandardPaths::findExecutable(command()); if (cmd.isEmpty()) cmd = QStandardPaths::findExecutable(command(), { QStringLiteral("/sbin/"), QStringLiteral("/usr/sbin/"), QStringLiteral("/usr/local/sbin/") }); if (!QDBusConnection::systemBus().isConnected()) { qWarning() << "Could not connect to DBus system bus"; return false; } QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"), QStringLiteral("/Helper"), QStringLiteral("org.kde.kpmcore.externalcommand"), QDBusConnection::systemBus()); iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days bool rval = false; if (iface.isValid()) { QDBusPendingCall pcall = iface.asyncCall(QStringLiteral("start"), CoreBackendManager::self()->Uuid(), cmd, args(), m_Input, QStringList()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); QEventLoop loop; auto exitLoop = [&] (QDBusPendingCallWatcher *watcher) { loop.exit(); if (watcher->isError()) qWarning() << watcher->error(); else { QDBusPendingReply reply = *watcher; m_Output = reply.value()[QStringLiteral("output")].toByteArray(); setExitCode(reply.value()[QStringLiteral("exitCode")].toInt()); + rval = true; } - - emit finished(); - rval = true; }; connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop); loop.exec(); } + return rval; } bool ExternalCommand::write(const QByteArray& input) { m_Input = input; return true; } /** Waits for the external command to finish. @param timeout timeout to wait until the process finishes. @return true on success */ bool ExternalCommand::waitFor(int timeout) { // closeWriteChannel(); /* if (!waitForFinished(timeout)) { if (report()) report()->line() << xi18nc("@info:status", "(Command timeout while running)"); return false; }*/ // onReadOutput(); Q_UNUSED(timeout) return true; } /** Runs the command. @param timeout timeout to use for waiting when starting and when waiting for the process to finish @return true on success */ bool ExternalCommand::run(int timeout) { return start(timeout) && waitFor(timeout)/* && exitStatus() == 0*/; } void ExternalCommand::onReadOutput() { // const QByteArray s = readAllStandardOutput(); // // if(m_Output.length() > 10*1024*1024) { // prevent memory overflow for badly corrupted file systems // if (report()) // report()->line() << xi18nc("@info:status", "(Command is printing too much output)"); // return; // } // // m_Output += s; // // if (report()) // *report() << QString::fromLocal8Bit(s); } void ExternalCommand::onFinished(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) setExitCode(exitCode); } diff --git a/src/util/externalcommand.h b/src/util/externalcommand.h index 01b02bf..cf9e41e 100644 --- a/src/util/externalcommand.h +++ b/src/util/externalcommand.h @@ -1,117 +1,114 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * + * Copyright (C) 2016-2018 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(KPMCORE_EXTERNALCOMMAND_H) #define KPMCORE_EXTERNALCOMMAND_H #include "util/libpartitionmanagerexport.h" #include "core/copysourcedevice.h" #include "core/copytargetfile.h" #include #include #include #include #include #include #include class Report; /** An external command. Runs an external command as a child process. @author Volker Lanz @author Andrius Štikonas */ class LIBKPMCORE_EXPORT ExternalCommand : public QObject { Q_OBJECT Q_DISABLE_COPY(ExternalCommand) public: 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(CopySource& source, CopyTarget& target, QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels); public: - bool copyBlocks(); + 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 */ const QStringList& args() const { return m_Args; } /**< @return the arguments */ void setArgs(const QStringList& args) { m_Args = args; } /**< @param args the new arguments */ bool write(const QByteArray& input); /**< @param input the input for the program */ bool startCopyBlocks(); bool start(int timeout = 30000); bool waitFor(int timeout = 30000); bool run(int timeout = 30000); int exitCode() const { return m_ExitCode; /**< @return the exit code */ } const QString output() const { return QString::fromLocal8Bit(m_Output); /**< @return the command output */ } const QByteArray& rawOutput() const { return m_Output; /**< @return the command output */ } Report* report() { return m_Report; /**< @return pointer to the Report or nullptr */ } void emitReport(const QVariantMap& report) { emit reportSignal(report); } Q_SIGNALS: void progress(int); - void finished(); void reportSignal(const QVariantMap&); public Q_SLOTS: void emitProgress(KJob*, unsigned long percent) { emit progress(percent); }; protected: void setExitCode(int i) { m_ExitCode = i; } void setup(const QProcess::ProcessChannelMode processChannelMode); void onFinished(int exitCode, QProcess::ExitStatus exitStatus); void onReadOutput(); private: QVariantMap arguments; Report *m_Report; QString m_Command; QStringList m_Args; int m_ExitCode; QByteArray m_Output; QByteArray m_Input; - CopySource *m_Source; - CopyTarget *m_Target; }; #endif diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h index caf0935..0a7590f 100644 --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -1,60 +1,60 @@ /************************************************************************* - * Copyright (C) 2017 by Andrius Štikonas * + * Copyright (C) 2017-2018 by Andrius Štikonas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #ifndef KPMCORE_EXTERNALCOMMANDHELPER_H #define KPMCORE_EXTERNALCOMMANDHELPER_H #include #include #include #include using namespace KAuth; class ExternalCommandHelper : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") Q_SIGNALS: void progress(int); void quit(); public: bool readData(const QString& sourceDevice, QByteArray& buffer, qint64 offset, qint64 size); bool writeData(const QString& targetDevice, const QByteArray& buffer, qint64 offset); public Q_SLOTS: ActionReply init(const QVariantMap& args); Q_SCRIPTABLE QVariantMap start(const QString& Uuid, const QString& command, const QStringList& arguments, const QByteArray& input, const QStringList& environment); Q_SCRIPTABLE bool copyblocks(const QString& Uuid, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize); Q_SCRIPTABLE void exit(const QString& Uuid); private: void onReadOutput(); bool isCallerAuthorized(const QString& Uuid); QEventLoop m_loop; QString m_callerUuid; QString m_command; QString m_sourceDevice; QProcess m_cmd; // QByteArray output; }; #endif