7#include "languagetoolmanager.h"
10#include <KConfigGroup>
11#include <KSharedConfig>
13#include <QNetworkAccessManager>
14#include <QRandomGenerator>
17static const char myLanguageToolManagerGroupName[] =
"LanguageTool";
19using namespace TextGrammarCheck;
20LanguageToolManager::LanguageToolManager(
QObject *parent)
25 mNetworkAccessManager->setStrictTransportSecurityEnabled(
true);
26 mNetworkAccessManager->enableStrictTransportSecurityStore(
true);
30LanguageToolManager::~LanguageToolManager() =
default;
32LanguageToolManager *LanguageToolManager::self()
34 static LanguageToolManager s_self;
40 return mNetworkAccessManager;
43QString LanguageToolManager::languageToolCheckPath()
const
45 if (mLanguageToolPath.
isEmpty()) {
48 return mLanguageToolPath + QStringLiteral(
"/check");
51QString LanguageToolManager::languageToolLanguagesPath()
const
53 if (mLanguageToolPath.
isEmpty()) {
56 return convertToLanguagePath(mLanguageToolPath);
59QString LanguageToolManager::convertToLanguagePath(
const QString &path)
61 return path + QStringLiteral(
"/languages");
64QColor LanguageToolManager::grammarColorForError(
const QString &error)
72 mGrammarColor.
insert(error, col);
76QString LanguageToolManager::languageToolPath()
const
78 return mLanguageToolPath;
81void LanguageToolManager::setLanguageToolPath(
const QString &path)
83 mLanguageToolPath =
path;
86void LanguageToolManager::loadSettings()
89 mLanguageToolPath = grp.readEntry(QStringLiteral(
"languagetoolpath"), QStringLiteral(
"https://api.languagetoolplus.com/v2"));
90 if (mLanguageToolPath ==
"https://languagetool.org/api/v2"_L1) {
91 mLanguageToolPath = QStringLiteral(
"https://api.languagetoolplus.com/v2");
93 mLanguage = grp.readEntry(QStringLiteral(
"language"), QStringLiteral(
"en"));
94 mUseLocalInstance = grp.readEntry(QStringLiteral(
"useLocalInstance"),
false);
98void LanguageToolManager::saveSettings()
101 grp.writeEntry(QStringLiteral(
"languagetoolpath"), mLanguageToolPath);
102 grp.writeEntry(QStringLiteral(
"language"), mLanguage);
103 grp.writeEntry(QStringLiteral(
"useLocalInstance"), mUseLocalInstance);
106QString LanguageToolManager::language()
const
111void LanguageToolManager::setLanguage(
const QString &language)
113 mLanguage = language;
116bool LanguageToolManager::useLocalInstance()
const
118 return mUseLocalInstance;
121void LanguageToolManager::setUseLocalInstance(
bool useLocalInstance)
123 mUseLocalInstance = useLocalInstance;
126bool LanguageToolManager::allowToGetListOfLanguages()
const
128 return mUseLocalInstance;
131#include "moc_languagetoolmanager.cpp"
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString path(const QString &relativePath)
bool isValid() const const
iterator insert(const Key &key, const T &value)
T value(const Key &key) const const
QRandomGenerator * global()
bool isEmpty() const const