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 45654140 authored by Laurent Montel's avatar Laurent Montel 😁

improve job

parent 678fe516
......@@ -20,6 +20,10 @@
#include "languagetoolgetlistoflanguagejob.h"
#include "liblanguagetool_debug.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
LanguageToolGetListOfLanguageJob::LanguageToolGetListOfLanguageJob(QObject *parent)
: QObject(parent)
{
......@@ -44,9 +48,37 @@ void LanguageToolGetListOfLanguageJob::start()
deleteLater();
return;
}
//TODO
QNetworkRequest request(QUrl::fromUserInput(mUrl));
addRequestAttribute(request);
QNetworkReply *reply = mNetworkAccessManager->get(request);
connect(reply, &QNetworkReply::finished, this, &LanguageToolGetListOfLanguageJob::slotCheckListOfLanguagesFinished);
connect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &LanguageToolGetListOfLanguageJob::slotFinish);
}
void LanguageToolGetListOfLanguageJob::slotFinish(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError) {
qCWarning(LIBLANGUAGE_PLUGIN_LOG) << " Error reply - "<<reply->errorString();
Q_EMIT error(reply->errorString());
}
}
void LanguageToolGetListOfLanguageJob::slotCheckListOfLanguagesFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
if (reply) {
const QByteArray data = reply->readAll();
Q_EMIT finished(QString::fromUtf8(data));
}
deleteLater();
}
void LanguageToolGetListOfLanguageJob::addRequestAttribute(QNetworkRequest &request) const
{
request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded"));
}
QString LanguageToolGetListOfLanguageJob::listOfLanguagePath() const
{
return mListOfLanguagePath;
......
......@@ -20,9 +20,11 @@
#ifndef LANGUAGETOOLGETLISTOFLANGUAGEJOB_H
#define LANGUAGETOOLGETLISTOFLANGUAGEJOB_H
#include <QNetworkRequest>
#include <QObject>
#include "libkmaillanguagetool_export.h"
class QNetworkAccessManager;
class QNetworkReply;
class LIBKMAILLANGUAGETOOL_EXPORT LanguageToolGetListOfLanguageJob : public QObject
{
Q_OBJECT
......@@ -42,8 +44,15 @@ public:
Q_REQUIRED_RESULT QString url() const;
void setUrl(const QString &url);
Q_SIGNALS:
void finished(const QString &result);
void error(const QString &errorStr);
private:
Q_DISABLE_COPY(LanguageToolGetListOfLanguageJob)
void addRequestAttribute(QNetworkRequest &request) const;
void slotCheckListOfLanguagesFinished();
void slotFinish(QNetworkReply *reply);
QString mListOfLanguagePath;
QNetworkAccessManager *mNetworkAccessManager = 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