| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2013-2018 CSSlayer <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 |
* |
| 6 |
*/ |
| 7 |
#include "processrunner.h" |
| 8 |
#include "guicommon.h" |
| 9 |
#include "log.h" |
| 10 |
#include <QDebug> |
| 11 |
#include <QProcess> |
| 12 |
#include <QTemporaryFile> |
| 13 |
#include <fcitx-utils/i18n.h> |
| 14 |
#include <fcitx-utils/standardpaths.h> |
| 15 |
|
| 16 |
namespace fcitx { |
| 17 |
|
| 18 |
ProcessRunner::ProcessRunner(const QString &bin, const QStringList &args, |
| 19 |
const QString &file, QObject *parent) |
| 20 |
: PipelineJob(parent), bin_(bin), args_(args), file_(file) { |
| 21 |
connect(&process_, |
| 22 |
qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, |
| 23 |
&ProcessRunner::processFinished); |
| 24 |
} |
| 25 |
|
| 26 |
void ProcessRunner::start() { |
| 27 |
if (process_.state() != QProcess::NotRunning) { |
| 28 |
process_.kill(); |
| 29 |
} |
| 30 |
|
| 31 |
qCDebug(dictmanager) << bin_ << args_; |
| 32 |
|
| 33 |
process_.start(bin_, args_); |
| 34 |
process_.closeReadChannel(QProcess::StandardError); |
| 35 |
process_.closeReadChannel(QProcess::StandardOutput); |
| 36 |
} |
| 37 |
|
| 38 |
void ProcessRunner::abort() { process_.kill(); } |
| 39 |
|
| 40 |
void ProcessRunner::cleanUp() { QFile::remove(file_); } |
| 41 |
|
| 42 |
void ProcessRunner::processFinished(int exitCode, QProcess::ExitStatus status) { |
| 43 |
if (status == QProcess::CrashExit) { |
| 44 |
Q_EMIT message(QMessageBox::Critical, _("Converter crashed.")); |
| 45 |
Q_EMIT finished(false); |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
if (exitCode != 0) { |
| 50 |
Q_EMIT message(QMessageBox::Warning, _("Convert failed.")); |
| 51 |
Q_EMIT finished(false); |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
Q_EMIT finished(true); |
| 56 |
} |
| 57 |
|
| 58 |
} // namespace fcitx |