7#include "grammalecteresultjob.h"
8#include "textgrammarcheck_debug.h"
11#include <QTemporaryFile>
12using namespace TextGrammarCheck;
13GrammalecteResultJob::GrammalecteResultJob(
QObject *parent)
18GrammalecteResultJob::~GrammalecteResultJob() =
default;
20void GrammalecteResultJob::start()
23 mProcess =
new QProcess(
this);
25 auto file =
new QTemporaryFile(
this);
28 file->write(mText.toUtf8());
31 mProcess->setProgram(mPythonPath);
34 args << mGrammarlecteCliPath;
35 if (!mArguments.isEmpty()) {
36 args << QStringLiteral(
"-on") << mArguments;
38 args << QStringLiteral(
"-f") << file->fileName() << QStringLiteral(
"-j");
39 mProcess->setArguments(args);
46 if (!mProcess->waitForStarted()) {
47 qCWarning(TEXTGRAMMARCHECK_LOG) <<
"Impossible to start grammarresultjob";
48 Q_EMIT error(ErrorType::Unknown);
52 if (mErrorType != ErrorType::TextIsEmpty) {
59void GrammalecteResultJob::receivedStandardOutput()
64void GrammalecteResultJob::receivedError()
66 mLastError += mProcess->errorString();
69void GrammalecteResultJob::receivedStdErr()
71 mLastError += QLatin1StringView(mProcess->readAllStandardError());
76 if (exitStatus != 0 || exitCode != 0) {
77 qCWarning(TEXTGRAMMARCHECK_LOG) <<
"Error during running GrammarResultJob: " << mLastError;
84QStringList GrammalecteResultJob::arguments()
const
89void GrammalecteResultJob::setArguments(
const QStringList &arguments)
91 mArguments = arguments;
94QString GrammalecteResultJob::grammarlecteCliPath()
const
96 return mGrammarlecteCliPath;
99void GrammalecteResultJob::setGrammarlecteCliPath(
const QString &grammarlecteCliPath)
101 mGrammarlecteCliPath = grammarlecteCliPath;
104QString GrammalecteResultJob::pythonPath()
const
109void GrammalecteResultJob::setPythonPath(
const QString &pythonPath)
111 mPythonPath = pythonPath;
114static bool hasNotEmptyText(
const QString &text)
116 for (
int i = 0, total = text.
length(); i < total; ++i) {
124bool GrammalecteResultJob::canStart()
126 if (!hasNotEmptyText(mText)) {
127 mErrorType = ErrorType::TextIsEmpty;
130 if (mGrammarlecteCliPath.isEmpty()) {
131 mErrorType = ErrorType::GrammalecteMissing;
134 if (mPythonPath.isEmpty()) {
135 mErrorType = ErrorType::PythonPathMissing;
139 mErrorType = ErrorType::PythonPathNotExist;
143 mErrorType = ErrorType::GrammarlectCliNotExist;
149QString GrammalecteResultJob::text()
const
154void GrammalecteResultJob::setText(
const QString &text)
159#include "moc_grammalecteresultjob.cpp"
bool isSpace(char32_t ucs4)
bool exists() const const
void reserve(qsizetype size)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void errorOccurred(QProcess::ProcessError error)
void finished(int exitCode, QProcess::ExitStatus exitStatus)
void readyReadStandardError()
void readyReadStandardOutput()
const QChar at(qsizetype position) const const
QString fromUtf8(QByteArrayView str)
qsizetype length() const const