[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/kcontrol/kxkb
From: Andriy Rysin <arysin () gmail ! com>
Date: 2007-11-01 0:31:04
Message-ID: 1193877064.462650.17407.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 731562 by rysin:
fix some i18n issues
M +0 -1 TODO
M +71 -52 kcmlayout.cpp
M +2 -1 kcmlayout.h
M +3 -11 kxkbconfig.cpp
M +2 -2 kxkbcore.cpp
M +1 -1 kxkbwidget.cpp
M +1 -1 rules.cpp
M +5 -1 x11helper.cpp
M +16 -6 xklavier_adaptor.cpp
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/TODO #731561:731562
@@ -1,5 +1,4 @@
KDE Shortcut
- i18n (kde + libxklavier)
Plasma Applet - make icon work, check conflict with kxkb
Improve component
XkbOptions radiobuttons for exclusive group
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/kcmlayout.cpp #731561:731562
@@ -62,8 +62,41 @@
K_EXPORT_PLUGIN(KeyboardLayoutFactory("kxkb"))
-static inline QString i18n(const QString& str) { return i18n( \
str.toUtf8().constData() ); } +static
+bool localeAwareLessThan(const QString &s1, const QString &s2)
+{
+ return QString::localeAwareCompare(s1, s2) < 0;
+}
+// sort by locale-aware value string
+static QList<QString> getKeysSortedByVaue(const QHash<QString, QString>& map)
+{
+ QList<QString> outList;
+
+ QMap<QString, QString> reverseMap;
+ // we have to add nums as translations can be dups and them reverse map will \
miss items + int i=0;
+ QString fmt("%1%2");
+ foreach (QString str, map.keys())
+ reverseMap.insert(fmt.arg(map[str], i++), str);
+
+ QList<QString> values = reverseMap.keys();
+ qSort(values.begin(), values.end(), localeAwareLessThan);
+
+ foreach (QString value, values)
+ outList << reverseMap[value];
+/*
+ int diff = map.keys().count() - reverseMap.keys().count();
+ if( diff > 0 ) {
+ kDebug() << "original keys" << map.keys().count() << "reverse map" << \
reverseMap.keys().count() + << "- translation encoding must have been \
messed up - padding layouts..."; + for(int i=0; i<diff; i++)
+ reverseMap.insert(QString("%1%2").arg("nocrash", i), "nocrash");
+ }
+*/
+ return outList;
+}
+
enum {
LAYOUT_COLUMN_FLAG = 0,
LAYOUT_COLUMN_NAME = 1,
@@ -77,7 +110,6 @@
enum { TAB_LAYOUTS=0, TAB_OPTIONS=1, TAB_XKB=2 };
enum { BTN_XKB_ENABLE=0, BTN_XKB_INDICATOR=1, BTN_XKB_DISABLE=2 };
-static const QString DEFAULT_VARIANT_NAME("<default>");
class SrcLayoutModel: public QAbstractTableModel {
public:
@@ -90,14 +122,9 @@
QVariant data(const QModelIndex& index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
- void setRules(XkbRules* rules) { m_rules = rules;
- QHash<QString, QString> layouts = m_rules->layouts();
- QList<QString> keys = layouts.keys();
- // sort by i18n string
- QMap<QString, QString> map;
- foreach (QString str, keys)
- map.insert(i18n(layouts[str]), str);
- m_layoutKeys = map.values();
+ void setRules(XkbRules* rules) {
+ m_rules = rules;
+ m_layoutKeys = getKeysSortedByVaue( m_rules->layouts() );
}
QString getLayoutAt(int row) { return m_layoutKeys[row]; }
@@ -137,7 +164,7 @@
}
} else if (role == Qt::DisplayRole) {
switch(col) {
- case LAYOUT_COLUMN_NAME: return i18n(layouts[layout]);
+ case LAYOUT_COLUMN_NAME: return layouts[layout];
case LAYOUT_COLUMN_MAP: return layout;
break;
default: ;
@@ -198,7 +225,7 @@
}
} else if (role == Qt::DisplayRole) {
switch(col) {
- case LAYOUT_COLUMN_NAME: return i18n(layouts[lu.layout]);
+ case LAYOUT_COLUMN_NAME: return layouts[lu.layout];
case LAYOUT_COLUMN_MAP: return lu.layout;
case LAYOUT_COLUMN_VARIANT: return lu.variant;
case LAYOUT_COLUMN_DISPLAY_NAME: return lu.getDisplayName();
@@ -337,14 +364,15 @@
LayoutConfig::LayoutConfig(QWidget *parent, const QVariantList &)
: KCModule(KeyboardLayoutFactory::componentData(), parent),
+ DEFAULT_VARIANT_NAME(i18nc("Default variant", "Default")),
m_rules(NULL),
m_srcModel(NULL),
m_dstModel(NULL),
m_xkbOptModel(NULL)
{
-// KGlobal::locale()->insertCatalog("desktop_kdebase"); // to translate languages
-// kDebug() << "i18n" << i18n("France");
-
+//kDebug() << "Qt locale" << QLocale::system().name();
+//kDebug() << "KDE locale" << KGlobal::locale()->language() << \
KGlobal::locale()->country(); +//kDebug() << "OS locale" << setlocale(LC_ALL, NULL);
//Read rules - we _must_ read _before_ creating UIs
loadRules();
@@ -439,12 +467,8 @@
void LayoutConfig::initUI()
{
QString modelName = m_rules->models()[m_kxkbConfig.m_model];
- if( modelName.isEmpty() )
- modelName = DEFAULT_MODEL;
+ widget->comboModel->setCurrentIndex( widget->comboModel->findText(modelName) );
- QString modelName_ = i18n(modelName);
- widget->comboModel->setCurrentIndex( widget->comboModel->findText(modelName_) );
-
m_dstModel->reset();
widget->dstTableView->update();
@@ -682,7 +706,7 @@
return;
QModelIndexList selected = selectionModel->selectedRows();
- kDebug() << "removing" << selected;
+// kDebug() << "removing" << selected;
m_kxkbConfig.m_layouts.removeAt(selected[0].row());
m_dstModel->reset();
@@ -709,11 +733,11 @@
int row = selected[0].row();
int new_row = row + shift;
- if( new_row >= 0 && new_row < GROUP_LIMIT )
+ if( new_row >= 0 && new_row <= m_kxkbConfig.m_layouts.count()-1 ) {
m_kxkbConfig.m_layouts.move(row, new_row);
-
- m_dstModel->reset();
- widget->dstTableView->update();
+ m_dstModel->reset();
+ widget->dstTableView->update();
+ }
}
void LayoutConfig::moveUp()
@@ -792,28 +816,29 @@
return;
}
- QString kbdLayout = m_kxkbConfig.m_layouts[row].layout;
+ QString kbdLayout = m_kxkbConfig.m_layouts[row].layout;
- QList<XkbVariant> vars = m_rules->getAvailableVariants(kbdLayout);
- kDebug() << "layout " << kbdLayout << " has " << vars.count() << " variants";
+ QList<XkbVariant> vars = m_rules->getAvailableVariants(kbdLayout);
+ kDebug() << "layout " << kbdLayout << " has " << vars.count() << " variants";
- if( vars.count() > 0 ) {
+ if( vars.count() > 0 ) {
// vars.prepend(DEFAULT_VARIANT_NAME);
// widget->comboVariant->addItems(vars);
- widget->comboVariant->addItem(DEFAULT_VARIANT_NAME, "");
- for(int ii=0; ii<vars.count(); ii++) {
- widget->comboVariant->addItem(vars[ii].description, vars[ii].name);
- }
- QString variant = m_kxkbConfig.m_layouts[row].variant;
- if( variant != NULL && variant.isEmpty() == false ) {
- int idx = widget->comboVariant->findData(variant);
- widget->comboVariant->setCurrentIndex(idx);
- }
- else {
- widget->comboVariant->setCurrentIndex(0);
- }
+ widget->comboVariant->addItem(DEFAULT_VARIANT_NAME, "");
+ for(int ii=0; ii<vars.count(); ii++) {
+ widget->comboVariant->addItem(vars[ii].description, vars[ii].name);
+ widget->comboVariant->setItemData(widget->comboVariant->count()-1, \
vars[ii].description, Qt::ToolTipRole ); + }
+ QString variant = m_kxkbConfig.m_layouts[row].variant;
+ if( variant != NULL && variant.isEmpty() == false ) {
+ int idx = widget->comboVariant->findData(variant);
+ widget->comboVariant->setCurrentIndex(idx);
}
- updateDisplayName();
+ else {
+ widget->comboVariant->setCurrentIndex(0);
+ }
+ }
+ updateDisplayName();
}
void LayoutConfig::makeOptionsTab()
@@ -901,18 +926,12 @@
void LayoutConfig::refreshRulesUI()
{
-// QStringList modelsList;
widget->comboModel->clear();
- QHashIterator<QString, QString> it(m_rules->models());
- while (it.hasNext()) {
-// modelsList.append(i18n(it.next().value()));
- const QString key = it.next().key();
- widget->comboModel->addItem(i18n(m_rules->models()[key]), key);
+ QList<QString> sortedModels = getKeysSortedByVaue( m_rules->models() );
+ foreach( QString model, sortedModels ) {
+ widget->comboModel->addItem( m_rules->models()[model], model);
+ widget->comboModel->setItemData( widget->comboModel->count()-1, \
m_rules->models()[model], Qt::ToolTipRole ); }
-// modelsList.sort();
-// TODO: sort
-
-// widget->comboModel->addItems(modelsList);
widget->comboModel->setCurrentIndex(0);
//TODO: reset options and xkb options
}
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/kcmlayout.h #731561:731562
@@ -73,7 +73,8 @@
void changed();
private:
- Ui_LayoutConfigWidget* widget;
+ const QString DEFAULT_VARIANT_NAME;
+ Ui_LayoutConfigWidget* widget;
XkbRules *m_rules;
KxkbConfig m_kxkbConfig;
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/kxkbconfig.cpp #731561:731562
@@ -99,26 +99,18 @@
kDebug() << " added layout " << layoutUnit.toPair();
}
- kDebug() << "Found " << m_layouts.count() << " layouts, default is " << \
m_layouts[getDefaultLayout()].toPair(); +// kDebug() << "Found " << m_layouts.count() \
<< " layouts, default is " << m_layouts[getDefaultLayout()].toPair();
QStringList displayNamesList;
displayNamesList = config.readEntry("DisplayNames", displayNamesList);
int i=0;
for(QStringList::ConstIterator it = displayNamesList.begin(); it != \
displayNamesList.end() ; ++it) {
-// QStringList displayNamePair = (*it).split(':');
-// if( displayNamePair.count() == 2 ) {
-// LayoutUnit layoutUnit( displayNamePair[0] );
-// if( m_layouts.contains( layoutUnit ) ) {
if( i < m_layouts.count() ) {
m_layouts[i].setDisplayName(*it);
i++;
}
-// }
}
-// m_showSingle = config.readEntry("ShowSingle", false);
-// m_showFlag = config.readEntry("ShowFlag", true);
-
QString layoutOwner = config.readEntry("SwitchMode", "Global");
if( layoutOwner == "WinClass" ) {
@@ -159,7 +151,7 @@
}
}
#else
- m_stickySwitching = false; //TODO: so far we can't do sticky with xkb \
switching... + m_stickySwitching = false; //TODO: so far we can't do sticky \
with xkb switching groups... #endif
return true;
@@ -279,7 +271,7 @@
}
-QString LayoutUnit::getDefaultDisplayName(const QString& layout, const QString& \
variant) +QString LayoutUnit::getDefaultDisplayName(const QString& layout, const \
QString& /*variant*/) {
return layout.left(MAX_LABEL_LEN);
// if( layoutUnit.variant.isEmpty() )
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/kxkbcore.cpp #731561:731562
@@ -356,7 +356,7 @@
else if (id == KxkbWidget::CONFIG_MENU_ID)
{
QStringList lst;
- lst<< "keyboard_layout";
+ lst << "keyboard_layout";
QProcess::startDetached("kcmshell4",lst);
}
else if (id == KxkbWidget::HELP_MENU_ID)
@@ -365,7 +365,7 @@
}
else
{
- emit quit();
+// emit quit();
}
}
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/kxkbwidget.cpp #731561:731562
@@ -91,7 +91,7 @@
// const QPixmap pix = iconeffect.apply(layoutPixmap, KIcon::Small, \
KIcon::DefaultState);
QString layoutString = rules.layouts()[layoutName];
- QString fullName = i18n( layoutString.toUtf8().constData() );
+ QString fullName = layoutString;
if( variantName.isEmpty() == false )
fullName += " (" + variantName + ')';
// menu->insertItem(pix, fullName, START_MENU_ID + cnt, m_menuStartIndex + cnt);
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/rules.cpp #731561:731562
@@ -103,7 +103,7 @@
return;
}
- m_layouts= rules->layouts;
+ m_layouts = rules->layouts;
if( layoutsOnly == false ) {
m_models = rules->models;
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/x11helper.cpp #731561:731562
@@ -126,11 +126,15 @@
return NULL;
}
+ // try to translate layout names by countries in desktop_kdebase
+ // this is poor man's translation as it's good only for layout names and only \
those which match country names + \
KGlobal::locale()->insertCatalog("desktop_kdebase"); +
RulesInfo* rulesInfo = new RulesInfo();
for (int i = 0; i < xkbRules->layouts.num_desc; ++i) {
QString layoutName(xkbRules->layouts.desc[i].name);
- rulesInfo->layouts.insert( layoutName, xkbRules->layouts.desc[i].desc );
+ rulesInfo->layouts.insert( layoutName, i18nc("Name", \
xkbRules->layouts.desc[i].desc) ); }
if( layoutsOnly == true ) {
--- trunk/KDE/kdebase/workspace/kcontrol/kxkb/xklavier_adaptor.cpp #731561:731562
@@ -29,6 +29,7 @@
#include "xklavier_adaptor.h"
+#define KDE_TRANSLATE 1
#define VERBOSE 0
class XKlavierAdaptorPriv {
@@ -61,7 +62,12 @@
kError() << "XKlavier engine cannot be initialized!" << endl;
return; // throw
}
-
+
+#if KDE_TRANSLATE == 1
+ // try to translate layout names by countries in desktop_kdebase if translations \
are missing from x.org + // this is poor man's translation as it's good only for \
layout names and only those which match country names + \
KGlobal::locale()->insertCatalog("desktop_kdebase"); +#endif
}
QHash<QString, QString> XKlavierAdaptor::getModels() { return priv->m_models; }
@@ -105,6 +111,9 @@
{
QString layout = QString::fromUtf8(configItem->name);
QString desc = QString::fromUtf8(configItem->description);
+#if KDE_TRANSLATE == 1
+ desc = i18nc("Name", desc.toUtf8().constData());
+#endif
#if VERBOSE == 1
kDebug() << "layout: " << layout << " - " << desc;
@@ -161,19 +170,20 @@
{
if( priv->engine == NULL )
return;
+
+ const char* currLocale = setlocale(LOCALE_CATEGORY, NULL);
QString locale = KGlobal::locale()->language();
if( locale.indexOf('_') == -1 ) { // TODO: do we have to do this?
QString country = KGlobal::locale()->country();
if( ! country.isEmpty() ) {
locale += "_";
- locale += country;
+ locale += country.toUpper();
}
}
// locale = "uk_UA"; // testing
+// locale = "en_US";
locale += ".UTF-8";
-
- const char* currLocale = setlocale(LOCALE_CATEGORY, NULL);
kDebug() << "Setting LC_ALL for libxklavier: " << locale;
const char* newLocale = setlocale(LOCALE_CATEGORY, locale.toLatin1());
@@ -193,13 +203,13 @@
xkl_config_registry_foreach_layout(priv->config, processLayout, userData);
-// kDebug() << priv->m_layouts.count() << "layouts total";
-
if( ! layoutsOnly ) {
xkl_config_registry_foreach_model(priv->config, processModel, userData);
xkl_config_registry_foreach_option_group(priv->config, processOptionGroup, \
userData); }
+ kDebug() << priv->m_layouts.count() << "total layouts" << priv->m_models.count() \
<< "models"; +
setlocale(LOCALE_CATEGORY, currLocale);
g_object_unref(priv->config);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic