mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: implement KSwitchLanguageDialog
note that it does not change the locale language (yet), nor does is affect it. it changes the translation language(s) - two different things! Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c44da5428f
commit
b8c4f73865
2 changed files with 56 additions and 2 deletions
|
@ -43,7 +43,9 @@ KSwitchLanguageDialog::KSwitchLanguageDialog(QWidget *parent)
|
|||
m_dialogwidget(nullptr),
|
||||
m_dialoglayout(nullptr),
|
||||
m_languagelabel(nullptr),
|
||||
m_languageedit(nullptr)
|
||||
m_languageedit(nullptr),
|
||||
m_languagebox(nullptr),
|
||||
m_languageline(nullptr)
|
||||
{
|
||||
setCaption(i18n("Switch Application Language"));
|
||||
setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Default);
|
||||
|
@ -52,14 +54,56 @@ KSwitchLanguageDialog::KSwitchLanguageDialog(QWidget *parent)
|
|||
connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
|
||||
connect(this, SIGNAL(defaultClicked()), SLOT(slotDefault()));
|
||||
|
||||
foreach (const QString &language, KLocale::installedLanguages()) {
|
||||
QString languagelang;
|
||||
QString languagecntry;
|
||||
QString languagemod;
|
||||
QString languagechar;
|
||||
KLocale::splitLocale(language, languagelang, languagecntry, languagemod, languagechar);
|
||||
if (languagecntry.isEmpty()) {
|
||||
const QString languagetext = KGlobal::locale()->languageCodeToName(languagelang);
|
||||
m_languagesmap.insert(languagetext, language);
|
||||
} else {
|
||||
const QString languagetext = QString::fromLatin1("%1 - %2").arg(
|
||||
KGlobal::locale()->languageCodeToName(languagelang),
|
||||
KGlobal::locale()->countryCodeToName(languagecntry)
|
||||
);
|
||||
m_languagesmap.insert(languagetext, language);
|
||||
}
|
||||
}
|
||||
|
||||
m_dialogwidget = new QWidget(this);
|
||||
m_dialoglayout = new QVBoxLayout(m_dialogwidget);
|
||||
m_languagelabel = new QLabel(m_dialogwidget);
|
||||
m_languagelabel->setText(i18n("Please choose the language which should be used for this application:"));
|
||||
m_dialoglayout->addWidget(m_languagelabel);
|
||||
m_languageedit = new KEditListWidget(m_dialogwidget);
|
||||
m_languagebox = new KComboBox(m_languageedit);
|
||||
// TODO: not having a line editor is not an option, KComboBox creates one and things get ugly.
|
||||
// instead of using the convenient KEditListWidget bake a custom UI for this
|
||||
m_languageline = new KLineEdit(m_languagebox);
|
||||
m_languagebox->setLineEdit(m_languageline);
|
||||
m_languagebox->addItems(m_languagesmap.keys());
|
||||
m_languageedit->setCustomEditor(KEditListWidget::CustomEditor(m_languagebox));
|
||||
m_dialoglayout->addWidget(m_languageedit);
|
||||
setMainWidget(m_dialogwidget);
|
||||
|
||||
KConfigGroup localegroup(KGlobal::config(), "Locale");
|
||||
const QStringList configtranslations = localegroup.readEntry("Translations", QStringList());
|
||||
QStringList translationslist;
|
||||
foreach (const QString &translation, configtranslations) {
|
||||
const QString translationstext = m_languagesmap.key(translation);
|
||||
if (translationstext.isEmpty()) {
|
||||
// language may be uninstalled, what then?
|
||||
kWarning() << "Invalid translation entry" << translation;
|
||||
continue;
|
||||
}
|
||||
translationslist.append(translationstext);
|
||||
}
|
||||
translationslist.sort();
|
||||
|
||||
m_languageedit->insertStringList(translationslist);
|
||||
m_languageline->setReadOnly(true);
|
||||
}
|
||||
|
||||
KSwitchLanguageDialog::~KSwitchLanguageDialog()
|
||||
|
@ -71,7 +115,10 @@ void KSwitchLanguageDialog::slotOk()
|
|||
KConfigGroup localegroup(KGlobal::config(), "Locale");
|
||||
const QStringList oldtranslations = localegroup.readEntry("Translations", QStringList());
|
||||
|
||||
const QStringList newtranslations = QStringList(); // TODO:
|
||||
QStringList newtranslations;
|
||||
foreach (const QString &item, m_languageedit->items()) {
|
||||
newtranslations.append(m_languagesmap.value(item));
|
||||
}
|
||||
if (oldtranslations != newtranslations) {
|
||||
localegroup.writeEntry("Translations", newtranslations);
|
||||
localegroup.sync();
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "kdialog.h"
|
||||
#include "keditlistwidget.h"
|
||||
#include "kcombobox.h"
|
||||
#include "klineedit.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
|
@ -43,12 +45,17 @@ public:
|
|||
private Q_SLOTS:
|
||||
void slotOk();
|
||||
void slotDefault();
|
||||
void slotAdded(const QString &languagetext);
|
||||
void slotRemoved(const QString &languagetext);
|
||||
|
||||
private:
|
||||
QWidget* m_dialogwidget;
|
||||
QVBoxLayout* m_dialoglayout;
|
||||
QLabel* m_languagelabel;
|
||||
KEditListWidget* m_languageedit;
|
||||
KComboBox* m_languagebox;
|
||||
KLineEdit* m_languageline;
|
||||
QMap<QString, QString> m_languagesmap;
|
||||
};
|
||||
|
||||
#endif // KSWITCHLANGUAGEDIALOG_H
|
||||
|
|
Loading…
Add table
Reference in a new issue