Cleanup ExternalCommand interface:
* Remove a separate constructor for copyblocks. * Remove kauthThread and finished() signal.
This commit is contained in:
parent
39d3592c23
commit
2cef3f6ec6
|
@ -1,7 +1,7 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2015 by Teo Mrnjavac <teo@kde.org> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -26,7 +26,6 @@
|
|||
#include <QStringList>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QThread>
|
||||
#include <QUuid>
|
||||
|
||||
#include <KAuth>
|
||||
|
@ -38,8 +37,6 @@
|
|||
CoreBackendManager::CoreBackendManager() :
|
||||
m_Backend(nullptr)
|
||||
{
|
||||
m_KAuthThread = new QThread();
|
||||
kauthThread()->start();
|
||||
}
|
||||
|
||||
CoreBackendManager* CoreBackendManager::self()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -26,7 +27,6 @@
|
|||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
class QThread;
|
||||
class QString;
|
||||
class QStringList;
|
||||
class KPluginMetaData;
|
||||
|
@ -81,13 +81,6 @@ public:
|
|||
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
|
||||
*/
|
||||
|
@ -110,7 +103,6 @@ private:
|
|||
|
||||
private:
|
||||
CoreBackend *m_Backend;
|
||||
QThread *m_KAuthThread;
|
||||
KAuth::ExecuteJob *m_job;
|
||||
|
||||
QString m_Uuid;
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "util/report.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008, 2009, 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -42,10 +42,10 @@ Job::Job() :
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -39,28 +39,7 @@
|
|||
#include <KAuth>
|
||||
#include <KLocalizedString>
|
||||
|
||||
|
||||
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
|
||||
|
@ -77,7 +56,7 @@ bool ExternalCommand::copyBlocks()
|
|||
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;
|
||||
|
||||
|
@ -90,7 +69,6 @@ bool ExternalCommand::copyBlocks()
|
|||
QDBusPendingReply<bool> reply = *watcher;
|
||||
rval = reply.argumentAt<0>();
|
||||
}
|
||||
emit finished();
|
||||
setExitCode(!rval);
|
||||
};
|
||||
|
||||
|
@ -190,15 +168,14 @@ bool ExternalCommand::start(int timeout)
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -49,10 +50,9 @@ class LIBKPMCORE_EXPORT ExternalCommand : public QObject
|
|||
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 */
|
||||
|
||||
|
@ -86,7 +86,6 @@ public:
|
|||
|
||||
Q_SIGNALS:
|
||||
void progress(int);
|
||||
void finished();
|
||||
void reportSignal(const QVariantMap&);
|
||||
|
||||
public Q_SLOTS:
|
||||
|
@ -110,8 +109,6 @@ private:
|
|||
int m_ExitCode;
|
||||
QByteArray m_Output;
|
||||
QByteArray m_Input;
|
||||
CopySource *m_Source;
|
||||
CopyTarget *m_Target;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2017 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* Copyright (C) 2017-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
|
Loading…
Reference in New Issue