7#include "grammalecteconfigwidget.h"
8#include "grammalectemanager.h"
9#include "grammalecteurlrequesterwidget.h"
11#include <KLocalizedString>
18#include <QStackedWidget>
23using namespace TextGrammarCheck;
24GrammalecteConfigWidget::GrammalecteConfigWidget(
QWidget *parent,
bool disableMessageBox)
26 , mDisableDialogBox(disableMessageBox)
29 mainLayout->setObjectName(QStringLiteral(
"mainlayout"));
30 mainLayout->setContentsMargins({});
33 mTab->setObjectName(QStringLiteral(
"mTab"));
34 mainLayout->addWidget(mTab);
35 mTab->addTab(addGeneralTab(),
i18n(
"General"));
36 mTab->addTab(addGrammarTab(),
i18n(
"Grammar Settings"));
38 loadGrammarSettings();
41GrammalecteConfigWidget::~GrammalecteConfigWidget()
46void GrammalecteConfigWidget::loadGrammarSettings()
48 auto job =
new GrammalecteGenerateConfigOptionJob(
this);
49 job->setPythonPath(mPythonPath->path());
50 job->setGrammarlecteCliPath(mGrammalectePath->path());
51 connect(job, &GrammalecteGenerateConfigOptionJob::finished,
this, &GrammalecteConfigWidget::slotGetSettingsFinished);
52 connect(job, &GrammalecteGenerateConfigOptionJob::error,
this, &GrammalecteConfigWidget::slotGetSettingsError);
56void GrammalecteConfigWidget::slotGetSettingsError()
59 if (!mDisableDialogBox) {
61 i18n(
"Impossible to get options. Please verify that you have grammalected installed."),
62 i18nc(
"@title:window",
"Error during Extracting Options"));
70 mListOptions.reserve(result.
count());
71 delete mGrammarTabWidget->
layout();
75 for (
const GrammalecteGenerateConfigOptionJob::Option &opt : result) {
76 auto box =
new QCheckBox(opt.description,
this);
77 box->setProperty(
"optionname", opt.optionName);
79 box->setChecked(opt.defaultValue);
81 box->setChecked(mSaveOptions.
contains(opt.optionName));
84 mListOptions.append(box);
88QWidget *GrammalecteConfigWidget::addGrammarTab()
91 mStackedWidget->
setObjectName(QStringLiteral(
"stackedwidget"));
96 mGrammarTabWidget =
new QWidget;
100 mScrollArea->
setWidget(mGrammarTabWidget);
104 mReloadSettingsWidget =
new QWidget;
105 mReloadSettingsWidget->
setObjectName(QStringLiteral(
"reloadwidget"));
106 mStackedWidget->
addWidget(mReloadSettingsWidget);
107 auto reloadSettingsLayout =
new QVBoxLayout(mReloadSettingsWidget);
108 reloadSettingsLayout->setObjectName(QStringLiteral(
"reloadSettingsLayout"));
110 reloadSettingsLayout->
addLayout(horizontallayout);
111 auto label =
new QLabel(
i18nc(
"@label:textbox",
"Press Button for Reloading Settings"),
this);
112 label->setObjectName(QStringLiteral(
"label"));
113 horizontallayout->addWidget(label);
116 buttonReloadSettings->setIcon(
QIcon::fromTheme(QStringLiteral(
"view-refresh")));
117 buttonReloadSettings->setObjectName(QStringLiteral(
"buttonReloadSettings"));
118 buttonReloadSettings->setToolTip(
i18nc(
"@info:tooltip",
"Reload Settings"));
119 horizontallayout->addWidget(buttonReloadSettings);
122 reloadSettingsLayout->addStretch(1);
123 return mStackedWidget;
126QWidget *GrammalecteConfigWidget::addGeneralTab()
129 w->setObjectName(QStringLiteral(
"general"));
131 lay->setObjectName(QStringLiteral(
"generallayout"));
133 mPythonPath =
new TextGrammarCheck::GrammalecteUrlRequesterWidget(
this);
135 lay->addRow(
i18n(
"Python Path:"), mPythonPath);
137 mGrammalectePath =
new TextGrammarCheck::GrammalecteUrlRequesterWidget(
this);
138 mGrammalectePath->
setObjectName(QStringLiteral(
"grammalectepath"));
139 mGrammalectePath->setPlaceholderText(
i18nc(
"@info:placeholder",
"Add full 'grammalecte-cli.py' path"));
141 lay->addRow(
i18n(
"Grammalecte Path:"), mGrammalectePath);
143 auto grammalecteInfoDownload =
new QLabel(
this);
144 grammalecteInfoDownload->setObjectName(QStringLiteral(
"grammalecteInfoDownload"));
146 grammalecteInfoDownload->setOpenExternalLinks(
true);
147 grammalecteInfoDownload->setText(
i18n(
"Grammalecte can be found <a href=\"https://grammalecte.net/#download\">here</a>. Download it and extract it."));
148 lay->addWidget(grammalecteInfoDownload);
153void GrammalecteConfigWidget::loadSettings()
155 mPythonPath->setPath(GrammalecteManager::self()->pythonPath());
156 mGrammalectePath->setPath(GrammalecteManager::self()->grammalectePath());
157 mSaveOptions = GrammalecteManager::self()->options();
160void GrammalecteConfigWidget::saveSettings()
163 for (
QCheckBox *checkBox : std::as_const(mListOptions)) {
164 if (checkBox->isChecked()) {
165 result += checkBox->property(
"optionname").toString();
168 GrammalecteManager::self()->setPythonPath(mPythonPath->path());
169 GrammalecteManager::self()->setGrammalectePath(mGrammalectePath->path());
170 GrammalecteManager::self()->setOptions(result);
171 GrammalecteManager::self()->saveSettings();
174#include "moc_grammalecteconfigwidget.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)
QString label(StandardShortcut id)
void addLayout(QLayout *layout, int stretch)
QIcon fromTheme(const QString &name)
qsizetype count() const const
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const