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

KNewStuff

ktranslatable.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KNewStuff2.
00003     Copyright (c) 2006, 2007 Josef Spillner <spillner@kde.org>
00004     Copyright (c) 2008 Jeremy Whiting <jeremy@scitools.com>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #include "ktranslatable.h"
00020 
00021 #include <kglobal.h>
00022 #include <klocale.h>
00023 
00024 #include <QtCore/QMutableStringListIterator>
00025 
00026 using namespace KNS;
00027 
00028 KTranslatable::KTranslatable()
00029         : d(0)
00030 {
00031 }
00032 
00033 KTranslatable::KTranslatable(const KTranslatable& other)
00034         : d(0)
00035 {
00036     m_strings = other.m_strings;
00037 }
00038 
00039 KTranslatable& KTranslatable::operator=(const KTranslatable & other)
00040 {
00041     if (this == &other) {
00042         return *this;
00043     }
00044     m_strings = other.m_strings;
00045     return *this;
00046 }
00047 
00048 KTranslatable::~KTranslatable()
00049 {
00050 //    delete d;
00051 }
00052 
00053 KTranslatable::KTranslatable(const QString& string)
00054         : d(0)
00055 {
00056     m_strings[QString()] = string;
00057 }
00058 
00059 void KTranslatable::addString(const QString& lang, const QString& string)
00060 {
00061     m_strings[lang] = string;
00062 }
00063 
00064 QString KTranslatable::representation() const
00065 {
00066     if (m_strings.isEmpty()) return QString();
00067 
00068     const QStringList langs = KGlobal::locale()->languageList();
00069     for (QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it)
00070         if (m_strings.contains(*it)) return m_strings[*it];
00071 
00072     if (m_strings.contains(QString())) return m_strings[QString()];
00073     // NOTE: this could be the source of crashes I've seen occasionally
00074     else return *(m_strings.begin());
00075 }
00076 
00077 QString KTranslatable::language() const
00078 {
00079     if (m_strings.isEmpty()) return QString();
00080 
00081     const QStringList langs = KGlobal::locale()->languageList();
00082     for (QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it)
00083         if (m_strings.contains(*it)) return (*it);
00084 
00085     if (m_strings.contains(QString())) return QString();
00086     else return m_strings.begin().key();
00087 }
00088 
00089 QString KTranslatable::translated(const QString& lang) const
00090 {
00091     if (m_strings.contains(lang))
00092         return m_strings[lang];
00093     return QString();
00094 }
00095 
00096 QStringList KTranslatable::languages() const
00097 {
00098     return m_strings.keys();
00099 }
00100 
00101 QStringList KTranslatable::strings() const
00102 {
00103     return m_strings.values();
00104 }
00105 
00106 QMap<QString, QString> KTranslatable::stringmap() const
00107 {
00108     return m_strings;
00109 }
00110 
00111 bool KTranslatable::isTranslated() const
00112 {
00113     return m_strings.count() > 1;
00114 }
00115 
00116 bool KTranslatable::isEmpty() const
00117 {
00118     return m_strings.isEmpty();
00119 }
00120 

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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