7#include "languagetoolupdatecombobox.h"
8#include "languagetoolcombobox.h"
9#include "languagetoolgetlistoflanguagejob.h"
10#include "languagetoollistoflanguagesparser.h"
11#include "languagetoolmanager.h"
12#include "textgrammarcheck_debug.h"
14#include <KLocalizedString>
17#include <QJsonDocument>
18using namespace TextGrammarCheck;
19LanguageToolUpdateComboBox::LanguageToolUpdateComboBox(
QObject *parent)
24LanguageToolUpdateComboBox::~LanguageToolUpdateComboBox() =
default;
26void LanguageToolUpdateComboBox::checkListOfLanguagesFromSpecificPath(
const QString &url)
28 auto job =
new LanguageToolGetListOfLanguageJob(
this);
30 job->setNetworkAccessManager(LanguageToolManager::self()->networkAccessManager());
31 connect(job, &LanguageToolGetListOfLanguageJob::finished,
this, &LanguageToolUpdateComboBox::slotGetLanguagesFinished);
32 connect(job, &LanguageToolGetListOfLanguageJob::error,
this, &LanguageToolUpdateComboBox::slotGetLanguagesError);
36void LanguageToolUpdateComboBox::firstRefreshListOfLanguages()
38 if (!mBListWasLoaded) {
39 checkListOfLanguagesFromSpecificPath(LanguageToolManager::self()->languageToolLanguagesPath());
41 mLanguageToolCombobox->setLanguage(LanguageToolManager::self()->language());
45void LanguageToolUpdateComboBox::refreshListOfLanguages()
47 if (LanguageToolManager::self()->allowToGetListOfLanguages()) {
48 checkListOfLanguagesFromSpecificPath(LanguageToolManager::self()->languageToolLanguagesPath());
52QWidget *LanguageToolUpdateComboBox::parentWidget()
const
57void LanguageToolUpdateComboBox::setParentWidget(
QWidget *parentWidget)
59 mParentWidget = parentWidget;
62LanguageToolComboBox *LanguageToolUpdateComboBox::languageToolCombobox()
const
64 return mLanguageToolCombobox;
67void LanguageToolUpdateComboBox::setLanguageToolCombobox(LanguageToolComboBox *languageToolCombobox)
69 mLanguageToolCombobox = languageToolCombobox;
72void LanguageToolUpdateComboBox::slotGetLanguagesError(
const QString &error)
74 qCWarning(TEXTGRAMMARCHECK_LOG) <<
"Error during loading languages from server : " <<
error;
76 i18n(
"An error occurred attempting to load the list of available languages:\n%1", error),
77 i18nc(
"@title:window",
"List of Languages"));
80void LanguageToolUpdateComboBox::slotGetLanguagesFinished(
const QString &result)
84 LanguageToolListOfLanguagesParser parser;
85 mLanguageToolCombobox->fillComboBox(parser.parseResult(fields));
86 mLanguageToolCombobox->setLanguage(LanguageToolManager::self()->language());
87 mBListWasLoaded =
true;
90#include "moc_languagetoolupdatecombobox.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QJsonArray array() const const
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QByteArray toUtf8() const const