7#include "languagetoolresultjob.h"
8#include "textgrammarcheck_debug.h"
10#include <QNetworkAccessManager>
11#include <QNetworkReply>
12using namespace TextGrammarCheck;
13LanguageToolResultJob::LanguageToolResultJob(
QObject *parent)
18LanguageToolResultJob::~LanguageToolResultJob() =
default;
20static bool hasNotEmptyText(
const QString &text)
22 for (
int i = 0; i < text.
length(); ++i) {
30bool LanguageToolResultJob::canStart()
const
32 return canStartError() == LanguageToolResultJob::JobError::NotError;
35LanguageToolResultJob::JobError LanguageToolResultJob::canStartError()
const
37 if (!mNetworkAccessManager) {
38 return LanguageToolResultJob::JobError::NetworkManagerNotDefined;
40 if (!hasNotEmptyText(mText)) {
41 return LanguageToolResultJob::JobError::EmptyText;
44 return LanguageToolResultJob::JobError::UrlNotDefined;
46 if (mLanguage.isEmpty()) {
47 return LanguageToolResultJob::JobError::LanguageNotDefined;
49 return LanguageToolResultJob::JobError::NotError;
52void LanguageToolResultJob::start()
54 const LanguageToolResultJob::JobError errorType = canStartError();
56 case LanguageToolResultJob::JobError::EmptyText:
58 case LanguageToolResultJob::JobError::UrlNotDefined:
59 case LanguageToolResultJob::JobError::NetworkManagerNotDefined:
60 case LanguageToolResultJob::JobError::LanguageNotDefined:
61 qCWarning(TEXTGRAMMARCHECK_LOG) <<
"Impossible to start language tool";
63 case LanguageToolResultJob::JobError::NotError:
67 addRequestAttribute(request);
68 const QByteArray ba =
"text=" + mText.toUtf8() +
"&language=" + mLanguage.toLatin1();
69 QNetworkReply *reply = mNetworkAccessManager->post(request, ba);
74void LanguageToolResultJob::slotFinish(QNetworkReply *reply)
77 qCWarning(TEXTGRAMMARCHECK_LOG) <<
" Error reply - " << reply->
errorString();
82void LanguageToolResultJob::slotCheckGrammarFinished()
86 const QByteArray data = reply->
readAll();
93void LanguageToolResultJob::addRequestAttribute(QNetworkRequest &request)
const
98QString LanguageToolResultJob::language()
const
103void LanguageToolResultJob::setLanguage(
const QString &language)
105 mLanguage = language;
108QString LanguageToolResultJob::url()
const
113void LanguageToolResultJob::setUrl(
const QString &url)
118QStringList LanguageToolResultJob::arguments()
const
123void LanguageToolResultJob::setArguments(
const QStringList &arguments)
125 mArguments = arguments;
128QNetworkAccessManager *LanguageToolResultJob::networkAccessManager()
const
130 return mNetworkAccessManager;
133void LanguageToolResultJob::setNetworkAccessManager(QNetworkAccessManager *networkAccessManager)
135 mNetworkAccessManager = networkAccessManager;
138QString LanguageToolResultJob::text()
const
143void LanguageToolResultJob::setText(
const QString &text)
148#include "moc_languagetoolresultjob.cpp"
bool isSpace(char32_t ucs4)
QString errorString() const const
void finished(QNetworkReply *reply)
NetworkError error() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QObject * sender() const const
const QChar at(qsizetype position) const const
QString fromUtf8(QByteArrayView str)
qsizetype length() const const