1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/*
SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de>
SPDX-FileCopyrightText: 2009 Niko Sams <niko.sams@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "plasmoidexecutionjob.h"
#include "executeplasmoidplugin.h"
#include <QFileInfo>
#include <QDir>
#include <KLocalizedString>
#include <KConfigGroup>
#include <interfaces/ilaunchconfiguration.h>
#include <outputview/outputmodel.h>
#include <outputview/outputdelegate.h>
#include <util/commandexecutor.h>
#include <util/path.h>
#include <interfaces/iproject.h>
#include <project/projectmodel.h>
#include <QStandardPaths>
using namespace KDevelop;
PlasmoidExecutionJob::PlasmoidExecutionJob(ExecutePlasmoidPlugin* iface, ILaunchConfiguration* cfg)
: OutputJob( iface )
{
QString identifier = cfg->config().readEntry("PlasmoidIdentifier", "");
Q_ASSERT(!identifier.isEmpty());
setToolTitle(i18n("Plasmoid Viewer"));
setCapabilities(Killable);
setStandardToolView( IOutputView::RunView );
setBehaviours(IOutputView::AllowUserClose | IOutputView::AutoScroll );
setObjectName(QLatin1String("plasmoidviewer ")+identifier);
setDelegate(new OutputDelegate);
m_process = new CommandExecutor(executable(cfg), this);
m_process->setArguments( arguments(cfg) );
m_process->setWorkingDirectory(workingDirectory(cfg));
auto* model = new OutputModel(QUrl::fromLocalFile(m_process->workingDirectory()), this);
model->setFilteringStrategy(OutputModel::CompilerFilter);
setModel( model );
connect(m_process, &CommandExecutor::receivedStandardError, model,
&OutputModel::appendLines );
connect(m_process, &CommandExecutor::receivedStandardOutput, model,
&OutputModel::appendLines );
connect( m_process, &CommandExecutor::failed, this, &PlasmoidExecutionJob::slotFailed );
connect( m_process, &CommandExecutor::completed, this, &PlasmoidExecutionJob::slotCompleted );
}
void PlasmoidExecutionJob::start()
{
startOutput();
model()->appendLine(m_process->workingDirectory() + QLatin1String("> ") + m_process->command() + QLatin1Char(' ') + m_process->arguments().join(QLatin1Char(' ')));
m_process->start();
}
bool PlasmoidExecutionJob::doKill()
{
m_process->kill();
model()->appendLine( i18n("** Killed **") );
return true;
}
OutputModel* PlasmoidExecutionJob::model()
{
return qobject_cast<OutputModel*>( OutputJob::model() );
}
void PlasmoidExecutionJob::slotCompleted(int code)
{
if( code != 0 ) {
setError( FailedShownError );
model()->appendLine( i18n("*** Failed ***") );
} else {
model()->appendLine( i18n("*** Finished ***") );
}
emitResult();
}
void PlasmoidExecutionJob::slotFailed(QProcess::ProcessError error)
{
setError(error);
// FIXME need more detail
setErrorText(i18n("Plasmoid failed to execute on %1", m_process->workingDirectory()));
model()->appendLine( i18n("*** Failed ***") );
emitResult();
}
QString PlasmoidExecutionJob::executable(ILaunchConfiguration*)
{
return QStandardPaths::findExecutable(QStringLiteral("plasmoidviewer"));
}
QStringList PlasmoidExecutionJob::arguments(ILaunchConfiguration* cfg)
{
QStringList arguments = cfg->config().readEntry("Arguments", QStringList());
if(workingDirectory(cfg) == QDir::tempPath()) {
QString identifier = cfg->config().readEntry("PlasmoidIdentifier", "");
arguments += QStringLiteral("-a");
arguments += identifier;
} else {
arguments += { QStringLiteral("-a"), QStringLiteral(".") };
}
return arguments;
}
QString PlasmoidExecutionJob::workingDirectory(ILaunchConfiguration* cfg)
{
QString workingDirectory;
IProject* p = cfg->project();
if(p) {
QString identifier = cfg->config().readEntry("PlasmoidIdentifier", "");
QString possiblePath = Path(p->path(), identifier).toLocalFile();
if(QFileInfo(possiblePath).isDir()) {
workingDirectory = possiblePath;
}
}
if(workingDirectory.isEmpty())
{
workingDirectory = QDir::tempPath();
}
return workingDirectory;
}
#include "moc_plasmoidexecutionjob.cpp"
|