2 * klanguagebuttonhelper.cpp - Methods that help filling the KLanguageButton with data.
4 * Copyright (c) 2003 Gunnar Schmi Dt <gunnar@schmi-dt.de>
6 * Requires the Qt widget libraries, available at no cost at
7 * http://www.trolltech.com/
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "klanguagebuttonhelper.h"
28 #include <kstandarddirs.h>
29 #include <ksimpleconfig.h>
30 #include "klanguagebutton.h"
32 QString
languageName (QString languageCode
) {
33 QString filename
= KGlobal::dirs()->findResource("locale",
34 languageCode
+ QString::fromLatin1("/entry.desktop"));
36 KSimpleConfig
entry(filename
);
37 entry
.setGroup(QString::fromLatin1("KCM Locale"));
38 return entry
.readEntry(QString::fromLatin1("Name"), i18n("without name"));
41 void loadLanguageList(KLanguageButton
*combo
)
42 // This function was taken from kdebase/kcontrol/kdm/kdm-appear.cpp
44 QStringList langlist
= KGlobal::dirs()->findAllResources("locale",
45 QString::fromLatin1("*/entry.desktop"));
47 for ( QStringList::ConstIterator it
= langlist
.begin();
48 it
!= langlist
.end(); ++it
)
50 QString fpath
= (*it
).left((*it
).length() - 14);
51 int index
= fpath
.lastIndexOf('/');
52 QString nid
= fpath
.mid(index
+ 1);
54 KSimpleConfig
entry(*it
);
55 entry
.setGroup(QString::fromLatin1("KCM Locale"));
56 QString name
= entry
.readEntry(QString::fromLatin1("Name"), i18n("without name"));
57 combo
->insertLanguage(nid
, name
, QString::fromLatin1("l10n/"), QString());
60 if (KGlobal::locale())
61 combo
->setCurrentItem (KGlobal::locale()->language());
63 combo
->setCurrentItem (KLocale::defaultLanguage());