• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

klettres

langutils.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2007 Pino Toscano <pino@kde.org>
00003     Copyright 2007-2008 Anne-Marie Mahfouf <annma@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 //project headers
00021 #include "langutils.h"
00022 #include "prefs.h"
00023 
00024 #include <QDir>
00025 
00026 #include <KDebug>
00027 #include <KGlobal>
00028 #include <KLocale>
00029 #include <KStandardDirs>
00030 
00031 bool LangUtils::hasSpecialChars(const QString& lang)
00032 {
00033     if (lang== "cs"
00034         || lang== "da"
00035         || lang== "sk"
00036         || lang== "es"
00037         || lang== "de"
00038         || lang== "hu"
00039         || lang== "nds")
00040         return true;
00041     return false;
00042 }
00043 
00044 QStringList LangUtils::getLanguages()
00045 {
00046     QStringList m_languages;
00047     m_languages.clear();
00048     //the program scans in klettres/data/ to see what languages data is found
00049     QStringList mdirs = KGlobal::dirs()->findDirs("data", "klettres/");
00050     //if (mdirs.isEmpty()) return NULL;
00051     for (QStringList::const_iterator it =mdirs.begin(); it !=mdirs.end(); ++it ) {
00052         QDir dir(*it);
00053         m_languages += dir.entryList(QDir::Dirs, QDir::Name);
00054         m_languages.removeAll(".");
00055         m_languages.removeAll("..");
00056     }
00057     m_languages.removeAll("pics");
00058     m_languages.removeAll("data");
00059     m_languages.removeAll("icons");
00060     m_languages.sort();
00061     
00062     //find duplicated entries in KDEDIR and KDEHOME
00063     QStringList temp_languages;
00064     for (int i=0;  i<m_languages.count(); i++)  {
00065         if (m_languages.count(m_languages[i])>1)  {
00066             temp_languages.append(m_languages[i]);
00067             m_languages.removeAll(m_languages[i]);
00068         }
00069         for (int i=0;  i<temp_languages.count(); i++)  {
00070             if (i%2==0)
00071             m_languages.append(temp_languages[i]);//append 1 of the 2 instances found
00072         }
00073         temp_languages.clear();
00074     }
00075     //TODO TEST in FRENCH
00076     m_languages.sort();
00077     kDebug() <<m_languages;
00078     return m_languages;
00079 }
00080 
00081 QStringList LangUtils::getLanguagesNames(QStringList languagesList)
00082 {
00083     //we look in $KDEDIR/share/locale/all_languages from /kdelibs/kdecore/all_languages
00084     //to find the name of the country
00085     //corresponding to the code and the language the user set
00086     QStringList languagesNames;
00087     KConfig entry(KStandardDirs::locate("locale", "all_languages"));
00088 
00089     foreach(const QString &language, languagesList) {
00090         if (language == "hi-ro")
00091             languagesNames.append(i18n("Romanized Hindi"));
00092         else if (language == "lug_UG")
00093             languagesNames.append(i18n("Luganda"));
00094         else
00095         {
00096             KConfigGroup group = entry.group(language);
00097         QString languageName = group.readEntry("Name");
00098         if (languageName.isEmpty()) {
00099         languageName = i18n("None");
00100         }
00101         languagesNames.append(languageName);
00102         }
00103     }
00104     //never sort m_languageNames as it's m_languages translated
00105     return languagesNames;
00106 }
00107 
00108 void LangUtils::writeLangConfig()
00109 {
00110     //write the present languages in config so they cannot be downloaded
00111     KConfigGroup config(KGlobal::config(), "KNewStuffStatus");
00112     QStringList m_languages = getLanguages();
00113     for (int i=0;  i<m_languages.count(); i++)  {
00114         QString tmp = m_languages[i];
00115         if (!config.readEntry(tmp, QString()).isEmpty())
00116             config.writeEntry(tmp, QDate::currentDate().toString());
00117     }
00118     config.sync();
00119 }
00120 
00121 

klettres

Skip menu "klettres"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal