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

Allow to select language

parent e63a4cab
......@@ -19,11 +19,13 @@
#include "languagetoolconfigwidgettest.h"
#include "languagetoolconfigwidget.h"
#include "languagetoolcombobox.h"
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QTest>
#include <QVBoxLayout>
QTEST_MAIN(LanguageToolConfigWidgetTest)
LanguageToolConfigWidgetTest::LanguageToolConfigWidgetTest(QObject *parent)
: QObject(parent)
......@@ -53,4 +55,11 @@ void LanguageToolConfigWidgetTest::shouldHaveDefaultValue()
QVERIFY(mInstancePath);
QVERIFY(mInstancePath->text().isEmpty());
QVERIFY(!mInstancePath->isEnabled());
QLabel *languageLabel = w.findChild<QLabel *>(QStringLiteral("languageLabel"));
QVERIFY(languageLabel);
QVERIFY(!languageLabel->text().isEmpty());
LanguageToolComboBox *mLanguageToolCombobox = w.findChild<LanguageToolComboBox *>(QStringLiteral("languagecombobox"));
QVERIFY(mLanguageToolCombobox);
}
......@@ -18,14 +18,35 @@
*/
#include "languagetoolcombobox.h"
#include <KLocalizedString>
LanguageToolComboBox::LanguageToolComboBox(QWidget *parent)
: QComboBox(parent)
{
fillComboBox();
}
LanguageToolComboBox::~LanguageToolComboBox()
{
}
void LanguageToolComboBox::fillComboBox()
{
//TODO add more
addItem(i18n("French"), QStringLiteral("fr"));
addItem(i18n("English"), QStringLiteral("en"));
}
void LanguageToolComboBox::setLanguage(const QString &str)
{
const int pos = findData(str);
if (pos != -1) {
setCurrentIndex(pos);
}
}
QString LanguageToolComboBox::language() const
{
return currentData().toString();
}
......@@ -28,10 +28,12 @@ class LIBKMAILLANGUAGETOOL_EXPORT LanguageToolComboBox : public QComboBox
public:
explicit LanguageToolComboBox(QWidget *parent = nullptr);
~LanguageToolComboBox();
void setLanguage(const QString &str);
Q_REQUIRED_RESULT QString language() const;
private:
enum LanguageName {
LanguageNameRole = Qt::UserRole + 1
};
void fillComboBox();
};
#endif // LANGUAGETOOLCOMBOBOX_H
......@@ -19,6 +19,7 @@
#include "languagetoolconfigwidget.h"
#include "languagetoolmanager.h"
#include "languagetoolcombobox.h"
#include <KLocalizedString>
#include <QVBoxLayout>
......@@ -53,6 +54,16 @@ LanguageToolConfigWidget::LanguageToolConfigWidget(QWidget *parent)
instancePathLabel->setEnabled(b);
mInstancePath->setEnabled(b);}
);
QLabel *languageLabel = new QLabel(i18n("Language:"), this);
languageLabel->setObjectName(QStringLiteral("languageLabel"));
mainLayout->addWidget(languageLabel);
mLanguageToolCombobox = new LanguageToolComboBox(this);
mLanguageToolCombobox->setObjectName(QStringLiteral("languagecombobox"));
mainLayout->addWidget(mLanguageToolCombobox);
mainLayout->addStretch(1);
loadSettings();
}
......@@ -66,10 +77,12 @@ void LanguageToolConfigWidget::loadSettings()
{
mUseLocalInstance->setChecked(LanguageToolManager::self()->useLocalInstance());
mInstancePath->setText(LanguageToolManager::self()->languageToolPath());
mLanguageToolCombobox->setLanguage(LanguageToolManager::self()->language());
}
void LanguageToolConfigWidget::saveSettings()
{
LanguageToolManager::self()->setUseLocalInstance(mUseLocalInstance->isChecked());
LanguageToolManager::self()->setLanguageToolPath(mInstancePath->text());
LanguageToolManager::self()->setLanguage(mLanguageToolCombobox->language());
}
......@@ -24,6 +24,7 @@
#include "libkmaillanguagetool_export.h"
class QCheckBox;
class QLineEdit;
class LanguageToolComboBox;
class LIBKMAILLANGUAGETOOL_EXPORT LanguageToolConfigWidget : public QWidget
{
Q_OBJECT
......@@ -36,6 +37,7 @@ private:
Q_DISABLE_COPY(LanguageToolConfigWidget)
QCheckBox *mUseLocalInstance = nullptr;
QLineEdit *mInstancePath = nullptr;
LanguageToolComboBox *mLanguageToolCombobox = nullptr;
};
#endif // LANGUAGETOOLCONFIGWIDGET_H
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