Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 127a4e34 authored by Laurent Montel's avatar Laurent Montel 😁

continue to implement job

parent 4d6be054
......@@ -20,6 +20,8 @@
#include "grammarresultjob.h"
#include "grammalecteplugin_debug.h"
#include <QTemporaryFile>
GrammarResultJob::GrammarResultJob(QObject *parent)
: QObject(parent)
{
......@@ -34,12 +36,26 @@ GrammarResultJob::~GrammarResultJob()
void GrammarResultJob::start()
{
if (canStart()) {
QProcess *process = new QProcess(this);
process->setProgram(mPythonPath);
mProcess = new QProcess(this);
QTemporaryFile *file = nullptr;
file = new QTemporaryFile(this);
file->open();
file->setPermissions(QFile::ReadUser);
file->write(mText.toUtf8());
file->close();
mProcess->setProgram(mPythonPath);
//TODO add argument!!!
process->setArguments(QStringList() << mGrammarlecteCliPath << mArguments);
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &GrammarResultJob::slotFinished);
if (!process->waitForStarted()) {
mProcess->setArguments(QStringList() << mGrammarlecteCliPath << mArguments << file->fileName());
connect(mProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &GrammarResultJob::slotFinished);
connect(mProcess, QOverload<QProcess::ProcessError>::of(&QProcess::error),
this, &GrammarResultJob::receivedError);
connect(mProcess, &QProcess::readyReadStandardError, this, &GrammarResultJob::receivedStdErr);
connect(mProcess, &QProcess::readAllStandardOutput, this, &GrammarResultJob::receivedStandardOutput);
if (!mProcess->waitForStarted()) {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Impossible to start grammarresultjob";
Q_EMIT error();
deleteLater();
......@@ -51,9 +67,30 @@ void GrammarResultJob::start()
}
}
void GrammarResultJob::receivedStandardOutput()
{
mResult += QString::fromUtf8(mProcess->readAllStandardOutput());
}
void GrammarResultJob::receivedError()
{
//mLastError += mProcess->errorString();
}
void GrammarResultJob::receivedStdErr()
{
//mLastError += QLatin1String(mProcess->readAllStandardError());
}
void GrammarResultJob::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
//TODO emit signal
if (exitStatus != 0 || exitCode != 0) {
qDebug() << " ERROR :!!!!!!!!!!!!!!!!!!!!";
//TODO error !!!!!
} else {
Q_EMIT finished(mResult);
}
deleteLater();
}
QStringList GrammarResultJob::arguments() const
......
......@@ -52,10 +52,15 @@ Q_SIGNALS:
private:
void slotFinished(int exitCode, QProcess::ExitStatus exitStatus);
void receivedStdErr();
void receivedError();
void receivedStandardOutput();
QStringList mArguments;
QString mResult;
QString mText;
QString mPythonPath;
QString mGrammarlecteCliPath;
QProcess *mProcess = nullptr;
};
#endif // GRAMMARRESULTJOB_H
......@@ -18,9 +18,13 @@
*/
#include "grammalectewidget.h"
#include "grammarresultjob.h"
#include "grammalecteparser.h"
#include <QVBoxLayout>
#include <QTextEdit>
#include <QPushButton>
#include <QDebug>
#include <QJsonDocument>
#include "grammarresultwidget.h"
GrammalecteWidget::GrammalecteWidget(QWidget *parent)
......@@ -47,5 +51,18 @@ GrammalecteWidget::~GrammalecteWidget()
void GrammalecteWidget::slotCheckGrammar()
{
GrammarResultJob *job = new GrammarResultJob(this);
job->setPythonPath(QStringLiteral(""));
job->setGrammarlecteCliPath(QStringLiteral(""));
job->setArguments(QStringList() << QStringLiteral(""));
connect(job, &GrammarResultJob::finished, this, &GrammalecteWidget::slotResultFinished);
}
void GrammalecteWidget::slotResultFinished(const QString &result)
{
qDebug() << " result" << result;
GrammalecteParser parser;
const QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8());
const QJsonObject fields = doc.object();
mResultWidget->applyGrammarResult(parser.parseResult(fields));
}
......@@ -32,6 +32,7 @@ public:
private:
void slotCheckGrammar();
void slotResultFinished(const QString &result);
QTextEdit *mInput = nullptr;
GrammarResultWidget *mResultWidget = nullptr;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment