7#include "translatorconfigurelistswidget.h"
8#include "translator/misc/translatorutil.h"
9#include "translator/translatorengineloader.h"
10#include "translatorconfigurecombowidget.h"
11#include "translatorconfigurelanguagelistwidget.h"
12#include "translatorconfigurelistswidget.h"
13#include <KConfigGroup>
14#include <KLocalizedString>
15#include <KSharedConfig>
18using namespace TextTranslator;
19class Q_DECL_HIDDEN TextTranslator::TranslatorConfigureListsWidget::TranslatorConfigureListsWidgetPrivate
23 : mEngineConfigureComboWidget(new TranslatorConfigureComboWidget(parent))
28 bool mLanguageListLoaded =
false;
29 TranslatorConfigureComboWidget *
const mEngineConfigureComboWidget;
34TranslatorConfigureListsWidget::TranslatorConfigureListsWidget(
QWidget *parent)
36 , d(new TranslatorConfigureListsWidgetPrivate(this))
39 mainLayout->setObjectName(QStringLiteral(
"mainLayout"));
40 d->mEngineConfigureComboWidget->setObjectName(QStringLiteral(
"mEngineConfigureComboWidget"));
41 connect(d->mEngineConfigureComboWidget,
42 &TranslatorConfigureComboWidget::configureChanged,
44 &TranslatorConfigureListsWidget::slotEngineSettingsChanged);
48 hboxLayout->setContentsMargins({});
49 mainLayout->addLayout(hboxLayout);
52 label->setObjectName(QStringLiteral(
"label"));
53 hboxLayout->addWidget(label);
54 hboxLayout->addWidget(d->mEngineConfigureComboWidget);
55 hboxLayout->addStretch(0);
58 hLanguageListboxLayout->
setObjectName(QStringLiteral(
"hLanguageListboxLayout"));
59 hLanguageListboxLayout->setContentsMargins({});
60 mainLayout->addLayout(hLanguageListboxLayout);
62 d->mFromLanguageWidget->setObjectName(QStringLiteral(
"mFromLanguageWidget"));
63 d->mToLanguageWidget->setObjectName(QStringLiteral(
"mToLanguageWidget"));
64 hLanguageListboxLayout->addWidget(d->mFromLanguageWidget);
65 hLanguageListboxLayout->addWidget(d->mToLanguageWidget);
67 connect(d->mEngineConfigureComboWidget, &TranslatorConfigureComboWidget::engineChanged,
this, &TranslatorConfigureListsWidget::slotEngineChanged);
70TranslatorConfigureListsWidget::~TranslatorConfigureListsWidget() =
default;
72void TranslatorConfigureListsWidget::save()
75 groupTranslate.writeEntry(QStringLiteral(
"From"), d->mFromLanguageWidget->selectedLanguages());
76 groupTranslate.writeEntry(QStringLiteral(
"To"), d->mToLanguageWidget->selectedLanguages());
77 d->mEngineConfigureComboWidget->save();
80void TranslatorConfigureListsWidget::load()
82 d->mEngineConfigureComboWidget->load();
85void TranslatorConfigureListsWidget::slotEngineSettingsChanged(
const QString &engineName)
87 slotEngineChanged(engineName);
90void TranslatorConfigureListsWidget::loadLanguagesList()
93 const auto fromLanguages = groupTranslate.readEntry(QStringLiteral(
"From"),
QStringList());
94 const auto toLanguages = groupTranslate.readEntry(QStringLiteral(
"To"),
QStringList());
95 d->mFromLanguageWidget->setSelectedLanguages(fromLanguages);
96 d->mToLanguageWidget->setSelectedLanguages(toLanguages);
103 TranslatorUtil translatorUtil;
104 while (i.hasNext()) {
106 const QString languageCode = TranslatorUtil::languageCode(i.key());
107 d->mFromLanguageWidget->addItem(i.value(), languageCode);
111 while (toLangIt.hasNext()) {
113 const QString languageCode = TranslatorUtil::languageCode(toLangIt.key());
114 d->mToLanguageWidget->addItem(toLangIt.value(), languageCode);
121 TranslatorUtil translatorUtil;
122 while (i.hasNext()) {
124 const QString languageCode = TranslatorUtil::languageCode(i.key());
125 d->mFromLanguageWidget->addItem(i.value(), languageCode);
126 if ((i.key() != TranslatorUtil::automatic)) {
127 d->mToLanguageWidget->addItem(i.value(), languageCode);
132void TranslatorConfigureListsWidget::slotEngineChanged(
const QString &engine)
135 TextTranslator::TranslatorEngineLoader::self()->supportedFromLanguages(engine);
138 if (!d->mLanguageListLoaded) {
139 fillLanguages(listFromLanguage);
141 d->mLanguageListLoaded =
true;
143 const QStringList fromLanguages = d->mFromLanguageWidget->selectedLanguages();
144 const QStringList toLanguages = d->mToLanguageWidget->selectedLanguages();
146 d->mFromLanguageWidget->clear();
147 d->mToLanguageWidget->clear();
148 if (listFromLanguage != listToLanguage) {
149 fillFromToLanguages(listFromLanguage, listToLanguage);
151 fillLanguages(listFromLanguage);
155 d->mFromLanguageWidget->setSelectedLanguages(fromLanguages);
156 d->mToLanguageWidget->setSelectedLanguages(toLanguages);
160#include "moc_translatorconfigurelistswidget.cpp"
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
The TranslatorConfigureLanguageListWidget class.
The TranslatorConfigureListsWidget class.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
void setObjectName(QAnyStringView name)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)