parley
editlanguagedialogpage.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "editlanguagedialogpage.h"
00023
00024 #include "languagesettings.h"
00025
00026 #include <keduvocdocument.h>
00027
00028 #include <KStandardDirs>
00029 #include <KLocale>
00030 #include <QLabel>
00031 #include <QtDBus>
00032
00037 EditLanguageDialogPage::EditLanguageDialogPage(KEduVocDocument* doc, int identifierIndex, QWidget * parent)
00038 : QWidget(parent)
00039 {
00040 m_doc = doc;
00041 m_identifierIndex = identifierIndex;
00042 setupUi(this);
00043
00044 initialize();
00045
00046 identifierNameLineEdit->setText(m_doc->identifier(m_identifierIndex).name());
00047
00048 connect(localeComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(localeChanged(const QString&)));
00049
00050 connect(iconComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(iconChanged(int)));
00051
00052 connect(identifierNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(languageNameChanged(const QString&)));
00053 }
00054
00055
00056 EditLanguageDialogPage::~EditLanguageDialogPage()
00057 {
00058 }
00059
00060
00061 void EditLanguageDialogPage::initialize()
00062 {
00063
00064 QStringList codes = KGlobal::locale()->allLanguagesList();
00065
00066
00067 QMap<QString, QString> languageCodeMap;
00068 foreach (QString code, codes){
00069 languageCodeMap[KGlobal::locale()->languageCodeToName(code)] = code;
00070 }
00071
00072 foreach ( QString language, languageCodeMap.keys() ) {
00073 localeComboBox->addItem( language, languageCodeMap.value(language) );
00074 }
00075
00076 localeComboBox->setCurrentIndex(localeComboBox->findData(
00077 m_doc->identifier(m_identifierIndex).locale()));
00078
00079
00080 LanguageSettings currentSettings(m_doc->identifier(m_identifierIndex).locale());
00081 currentSettings.readConfig();
00082 QString currentIcon = currentSettings.icon();
00083
00084 iconComboBox->addItem(i18n("No icon"));
00085
00086 QStringList countrylist = KGlobal::locale()->allCountriesList();
00087 countrylist.sort();
00088
00089 foreach(QString code, countrylist) {
00090 QString country = KGlobal::dirs()->findResource("locale",
00091 QString("l10n/%1/entry.desktop").arg(code));
00092 KConfig entry(country, KConfig::SimpleConfig);
00093 KConfigGroup group = entry.group("KCM Locale");
00094 QString name = group.readEntry("Name", i18n("without name"));
00095
00096 QString pixmap = country;
00097 pixmap.truncate(pixmap.lastIndexOf('/'));
00098 pixmap += "/flag.png";
00099
00100 iconComboBox->addItem(QIcon(pixmap), name, pixmap);
00101 }
00102
00103 iconComboBox->setCurrentIndex(iconComboBox->findData(currentIcon));
00104
00105
00106
00107
00108 QDBusInterface kxbk("org.kde.kxkb", "/kxkb", "org.kde.KXKB");
00109 QDBusReply<QStringList> reply = kxbk.call("getLayoutsList");
00110 if (reply.isValid()) {
00111 QStringList layouts = reply;
00112 layouts.prepend(QString());
00113 keyboardLayoutComboBox->clear();
00114 keyboardLayoutComboBox->addItems(layouts);
00115 keyboardLayoutComboBox->setEnabled(true);
00116
00117 LanguageSettings settings(m_doc->identifier(m_identifierIndex).locale());
00118 settings.readConfig();
00119
00120 if (!settings.keyboardLayout().isEmpty()) {
00121 keyboardLayoutComboBox->setCurrentIndex(keyboardLayoutComboBox->findText(settings.keyboardLayout()));
00122 } else {
00123 QDBusReply<QString> currentLayout = kxbk.call("getCurrentLayout");
00124 keyboardLayoutComboBox->setCurrentIndex(keyboardLayoutComboBox->findText(currentLayout));
00125 }
00126 } else {
00127 kDebug() << "kxkb dbus error";
00128 keyboardLayoutComboBox->setEnabled(false);
00129 }
00130 }
00131
00132
00133 void EditLanguageDialogPage::commitData()
00134 {
00135 QString locale = localeComboBox->itemData(localeComboBox->currentIndex()).toString();
00136
00137
00138 if (locale.isEmpty()) {
00139 locale = identifierNameLineEdit->text();
00140 }
00141 m_doc->identifier(m_identifierIndex).setLocale( locale );
00142 m_doc->identifier(m_identifierIndex).setName( identifierNameLineEdit->text() );
00143
00144 QString icon = iconComboBox->itemData(iconComboBox->currentIndex()).toString();
00145
00146 LanguageSettings settings(locale);
00147 settings.setIcon(icon);
00148 if ( keyboardLayoutComboBox->isEnabled() ) {
00149 settings.setKeyboardLayout( keyboardLayoutComboBox->currentText() );
00150 }
00151 settings.writeConfig();
00152 }
00153
00154 void EditLanguageDialogPage::iconChanged(int iconIndex)
00155 {
00156 emit iconSelected( iconComboBox->itemData(iconIndex).toString() );
00157 }
00158
00159 void EditLanguageDialogPage::localeChanged(const QString & locale)
00160 {
00161 identifierNameLineEdit->setText( locale );
00162 }
00163
00164 void EditLanguageDialogPage::languageNameChanged(const QString &)
00165 {
00166 }
00167
00168
00169 #include "editlanguagedialogpage.moc"