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

Save/load settings

parent 5b83b214
......@@ -33,7 +33,7 @@ LanguagetoolGrammarError::~LanguagetoolGrammarError()
void LanguagetoolGrammarError::parse(const QJsonObject &obj, int blockindex)
{
//TODO
//We use block id index based on 1 in API
mBlockId = blockindex + 1;
mError = obj[QStringLiteral("message")].toString();
mStart = obj[QStringLiteral("offset")].toInt(-1);
......
......@@ -19,13 +19,15 @@
#include "languagetoolmanager.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <QNetworkAccessManager>
LanguagetoolManager::LanguagetoolManager(QObject *parent)
: QObject(parent)
, mNetworkAccessManager(new QNetworkAccessManager(this))
{
loadSettings();
}
LanguagetoolManager::~LanguagetoolManager()
......@@ -46,17 +48,26 @@ QNetworkAccessManager *LanguagetoolManager::networkAccessManager() const
QString LanguagetoolManager::languageToolPath() const
{
return QStringLiteral("https://languagetool.org/api/v2/check");
return mLanguageToolPath;
}
void LanguagetoolManager::setLanguageToolPath(const QString &path)
{
mLanguageToolPath = path;
}
void LanguagetoolManager::loadSettings()
{
//TODO
KConfigGroup grp(KSharedConfig::openConfig(), "LanguageTool");
mLanguageToolPath = grp.readEntry(QStringLiteral("languagetoolpath"), QStringLiteral("https://languagetool.org/api/v2/check"));
mLanguage = grp.readEntry(QStringLiteral("language"), QStringLiteral("en"));
}
void LanguagetoolManager::saveSettings()
{
//TODO
KConfigGroup grp(KSharedConfig::openConfig(), "LanguageTool");
grp.writeEntry(QStringLiteral("languagetoolpath"), mLanguageToolPath);
grp.writeEntry(QStringLiteral("language"), mLanguage);
}
QString LanguagetoolManager::language() const
......
......@@ -32,7 +32,9 @@ public:
static LanguagetoolManager *self();
QNetworkAccessManager *networkAccessManager() const;
Q_REQUIRED_RESULT QString languageToolPath() const;
void setLanguageToolPath(const QString &path);
void loadSettings();
void saveSettings();
......@@ -42,6 +44,7 @@ public:
private:
QString mLanguage;
QString mLanguageToolPath;
QNetworkAccessManager *mNetworkAccessManager = nullptr;
};
......
......@@ -73,7 +73,7 @@ void LanguagetoolWidget::slotCheckGrammar()
job->setUrl(QStringLiteral("https://languagetool.org/api/v2/check"));
job->setNetworkAccessManager(mNetworkAccessManager);
job->setText(mInput->toPlainText());
job->setLanguage(QStringLiteral("fr"));
job->setLanguage(QStringLiteral("en"));
connect(job, &LanguagetoolResultJob::finished, this, &LanguagetoolWidget::slotResultFinished);
connect(job, &LanguagetoolResultJob::error, this, &LanguagetoolWidget::slotError);
job->start();
......
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