• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

knfotranslator.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at>                      *
00003  *                                                                           *
00004  * This library is free software; you can redistribute it and/or             *
00005  * modify it under the terms of the GNU Library General Public               *
00006  * License as published by the Free Software Foundation; either              *
00007  * version 2 of the License, or (at your option) any later version.          *
00008  *                                                                           *
00009  * This library is distributed in the hope that it will be useful,           *
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00012  * Library General Public License for more details.                          *
00013  *                                                                           *
00014  * You should have received a copy of the GNU Library General Public License *
00015  * along with this library; see the file COPYING.LIB.  If not, write to      *
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
00017  * Boston, MA 02110-1301, USA.                                               *
00018  *****************************************************************************/
00019 
00020 #include "knfotranslator_p.h"
00021 #include <klocale.h>
00022 #include <kstandarddirs.h>
00023 
00024 #include <kurl.h>
00025 
00026 #include <config-kio.h>
00027 #ifndef KIO_NO_NEPOMUK
00028 #define DISABLE_NEPOMUK_LEGACY
00029 #include "property.h"
00030 #endif
00031 
00032 struct TranslationItem {
00033     const char* const key;
00034     const char* const context;
00035     const char* const value;
00036 };
00037 
00038 // TODO: a lot of NFOs are missing yet
00039 static const TranslationItem g_translations[] = {    
00040     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment", I18N_NOOP2_NOSTRIP("@label", "Comment") },
00041     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated", I18N_NOOP2_NOSTRIP("@label creation date", "Created") },
00042     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize", I18N_NOOP2_NOSTRIP("@label file content size", "Size") },
00043     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#depends", I18N_NOOP2_NOSTRIP("@label file depends from", "Depends") },
00044     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#generator", I18N_NOOP2_NOSTRIP("@label Software used to generate content", "Generator") },
00045     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#hasLogicalPart", I18N_NOOP2_NOSTRIP("@label see http://www.semanticdesktop.org/ontologies/2007/01/19/nie#hasLogicalPart", "Has Logical Part") },
00046     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf", I18N_NOOP2_NOSTRIP("@label parent directory", "Part of") },
00047     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#keyword", I18N_NOOP2_NOSTRIP("@label", "Keyword") },
00048     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified", I18N_NOOP2_NOSTRIP("@label modified date of file", "Modified") },
00049     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType", I18N_NOOP2_NOSTRIP("@label", "MIME Type") },
00050     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent", I18N_NOOP2_NOSTRIP("@label", "Content") },
00051     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#subject", I18N_NOOP2_NOSTRIP("@label", "Subject") },
00052     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title", I18N_NOOP2_NOSTRIP("@label music title", "Title") },
00053     { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url", I18N_NOOP2_NOSTRIP("@label file URL", "Location") },
00054     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator", I18N_NOOP2_NOSTRIP("@label", "Creator") },
00055     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate", I18N_NOOP2_NOSTRIP("@label", "Average Bitrate") },
00056     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#channels", I18N_NOOP2_NOSTRIP("@label", "Channels") },
00057     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#characterCount", I18N_NOOP2_NOSTRIP("@label number of characters", "Characters") },
00058     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#codec",  I18N_NOOP2_NOSTRIP("@label", "Codec") },
00059     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#colorDepth", I18N_NOOP2_NOSTRIP("@label", "Color Depth") },
00060     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#duration", I18N_NOOP2_NOSTRIP("@label", "Duration") },
00061     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName", I18N_NOOP2_NOSTRIP("@label", "Filename") },
00062     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height", I18N_NOOP2_NOSTRIP("@label", "Height") },
00063     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#interlaceMode", I18N_NOOP2_NOSTRIP("@label", "Interlace Mode") },
00064     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#lineCount", I18N_NOOP2_NOSTRIP("@label number of lines", "Lines") },
00065     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#programmingLanguage", I18N_NOOP2_NOSTRIP("@label", "Programming Language") },
00066     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#sampleRate", I18N_NOOP2_NOSTRIP("@label", "Sample Rate") },
00067     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width", I18N_NOOP2_NOSTRIP("@label", "Width") },
00068     { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#wordCount", I18N_NOOP2_NOSTRIP("@label number of words", "Words") },
00069     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#apertureValue", I18N_NOOP2_NOSTRIP("@label EXIF aperture value", "Aperture") },
00070     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureBiasValue", I18N_NOOP2_NOSTRIP("@label EXIF", "Exposure Bias Value") },
00071     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime", I18N_NOOP2_NOSTRIP("@label EXIF", "Exposure Time") },
00072     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash", I18N_NOOP2_NOSTRIP("@label EXIF", "Flash") },
00073     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength", I18N_NOOP2_NOSTRIP("@label EXIF", "Focal Length") },
00074     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLengthIn35mmFilm", I18N_NOOP2_NOSTRIP("@label EXIF", "Focal Length 35 mm") },
00075     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings", I18N_NOOP2_NOSTRIP("@label EXIF", "ISO Speed Ratings") },
00076     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make", I18N_NOOP2_NOSTRIP("@label EXIF", "Make") },
00077     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode", I18N_NOOP2_NOSTRIP("@label EXIF", "Metering Mode") },
00078     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model", I18N_NOOP2_NOSTRIP("@label EXIF", "Model") },
00079     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation", I18N_NOOP2_NOSTRIP("@label EXIF", "Orientation") },
00080     { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance", I18N_NOOP2_NOSTRIP("@label EXIF", "White Balance") },
00081     { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#genre",  I18N_NOOP2_NOSTRIP("@label music genre", "Genre") },
00082     { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#musicAlbum", I18N_NOOP2_NOSTRIP("@label music album", "Album") },
00083     { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#performer", I18N_NOOP2_NOSTRIP("@label", "Performer") },
00084     { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#trackNumber", I18N_NOOP2_NOSTRIP("@label music track number", "Track") },
00085     { "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", I18N_NOOP2_NOSTRIP("@label file type", "Type") },
00086     { "translation.fuzzy", I18N_NOOP2_NOSTRIP("@label Number of fuzzy translations", "Fuzzy Translations") },
00087     { "translation.last_translator", I18N_NOOP2_NOSTRIP("@label Name of last translator", "Last Translator") },
00088     { "translation.obsolete", I18N_NOOP2_NOSTRIP("@label Number of obsolete translations", "Obsolete Translations") },
00089     { "translation.source_date", I18N_NOOP2_NOSTRIP("@label", "Translation Source Date") },
00090     { "translation.total", I18N_NOOP2_NOSTRIP("@label Number of total translations", "Total Translations") },
00091     { "translation.translated", I18N_NOOP2_NOSTRIP("@label Number of translated strings", "Translated") },
00092     { "translation.translation_date", I18N_NOOP2_NOSTRIP("@label", "Translation Date") },
00093     { "translation.untranslated", I18N_NOOP2_NOSTRIP("@label Number of untranslated strings" , "Untranslated") },
00094     { 0, 0, 0 } // mandatory last entry
00095 };
00096 
00097 class KNfoTranslatorSingleton
00098 {
00099 public:
00100     KNfoTranslator instance;
00101 };
00102 K_GLOBAL_STATIC(KNfoTranslatorSingleton, s_nfoTranslator)
00103 
00104 KNfoTranslator& KNfoTranslator::instance()
00105 {
00106     return s_nfoTranslator->instance;
00107 }
00108 
00109 QString KNfoTranslator::translation(const KUrl& uri) const
00110 {
00111     const QString key = uri.url();
00112     if (m_hash.contains(key)) {
00113         return m_hash.value(key);
00114     }
00115 
00116     // fallback if the URI is not translated
00117 #ifndef KIO_NO_NEPOMUK
00118     const QString label = Nepomuk::Types::Property(uri).label();
00119 #else
00120     QString label;
00121     const int index = key.indexOf(QChar('#'));
00122     if (index >= 0) {
00123         label = key.right(key.size() - index - 1);
00124     }
00125 #endif
00126     QString tunedLabel;
00127     const int labelLength = label.length();
00128     if (labelLength > 0) {
00129         tunedLabel.reserve(labelLength);
00130         tunedLabel = label[0].toUpper();
00131         for (int i = 1; i < labelLength; ++i) {
00132             if (label[i].isUpper() && !label[i - 1].isSpace() && !label[i - 1].isUpper()) {
00133                 tunedLabel += ' ';
00134                 tunedLabel += label[i].toLower();
00135             } else {
00136                 tunedLabel += label[i];
00137             }
00138         }
00139     }
00140     return tunedLabel;
00141 }
00142 
00143 KNfoTranslator::KNfoTranslator() :
00144     m_hash()
00145 {
00146     const TranslationItem* item = &g_translations[0];
00147     while (item->key != 0) {
00148         m_hash.insert(item->key, i18nc(item->context, item->value));
00149         ++item;
00150     }
00151 }
00152 
00153 KNfoTranslator::~KNfoTranslator()
00154 {
00155 }

KIO

Skip menu "KIO"
  • 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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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