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

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • kfile
knfotranslator.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
3  * *
4  * This library is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU Library General Public *
6  * License as published by the Free Software Foundation; either *
7  * version 2 of the License, or (at your option) any later version. *
8  * *
9  * This library is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12  * Library General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public License *
15  * along with this library; see the file COPYING.LIB. If not, write to *
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17  * Boston, MA 02110-1301, USA. *
18  *****************************************************************************/
19 
20 #include "knfotranslator_p.h"
21 #include <klocale.h>
22 #include <kstandarddirs.h>
23 
24 #include <kurl.h>
25 
26 #include <config-kio.h>
27 #ifndef KIO_NO_NEPOMUK
28 #define DISABLE_NEPOMUK_LEGACY
29 #include "property.h"
30 #endif
31 
32 struct TranslationItem {
33  const char* const key;
34  const char* const context;
35  const char* const value;
36 };
37 
38 // TODO: a lot of NFOs are missing yet
39 static const TranslationItem g_translations[] = {
40  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment", I18N_NOOP2_NOSTRIP("@label", "Comment") },
41  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated", I18N_NOOP2_NOSTRIP("@label creation date", "Created") },
42  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize", I18N_NOOP2_NOSTRIP("@label file content size", "Size") },
43  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#depends", I18N_NOOP2_NOSTRIP("@label file depends from", "Depends") },
44  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#description", I18N_NOOP2_NOSTRIP("@label", "Description") },
45  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#generator", I18N_NOOP2_NOSTRIP("@label Software used to generate content", "Generator") },
46  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#hasPart", I18N_NOOP2_NOSTRIP("@label see http://www.semanticdesktop.org/ontologies/2007/01/19/nie#hasPart", "Has Part") },
47  { "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") },
48  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf", I18N_NOOP2_NOSTRIP("@label parent directory", "Part of") },
49  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#keyword", I18N_NOOP2_NOSTRIP("@label", "Keyword") },
50  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified", I18N_NOOP2_NOSTRIP("@label modified date of file", "Modified") },
51  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType", I18N_NOOP2_NOSTRIP("@label", "MIME Type") },
52  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent", I18N_NOOP2_NOSTRIP("@label", "Content") },
53  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#relatedTo", I18N_NOOP2_NOSTRIP("@label", "Related To") },
54  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#subject", I18N_NOOP2_NOSTRIP("@label", "Subject") },
55  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title", I18N_NOOP2_NOSTRIP("@label music title", "Title") },
56  { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url", I18N_NOOP2_NOSTRIP("@label file URL", "Location") },
57  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator", I18N_NOOP2_NOSTRIP("@label", "Creator") },
58  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate", I18N_NOOP2_NOSTRIP("@label", "Average Bitrate") },
59  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#channels", I18N_NOOP2_NOSTRIP("@label", "Channels") },
60  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#characterCount", I18N_NOOP2_NOSTRIP("@label number of characters", "Characters") },
61  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#codec", I18N_NOOP2_NOSTRIP("@label", "Codec") },
62  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#colorDepth", I18N_NOOP2_NOSTRIP("@label", "Color Depth") },
63  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#duration", I18N_NOOP2_NOSTRIP("@label", "Duration") },
64  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName", I18N_NOOP2_NOSTRIP("@label", "Filename") },
65  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#hasHash", I18N_NOOP2_NOSTRIP("@label", "Hash") },
66  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height", I18N_NOOP2_NOSTRIP("@label", "Height") },
67  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#interlaceMode", I18N_NOOP2_NOSTRIP("@label", "Interlace Mode") },
68  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#lineCount", I18N_NOOP2_NOSTRIP("@label number of lines", "Lines") },
69  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#programmingLanguage", I18N_NOOP2_NOSTRIP("@label", "Programming Language") },
70  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#sampleRate", I18N_NOOP2_NOSTRIP("@label", "Sample Rate") },
71  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width", I18N_NOOP2_NOSTRIP("@label", "Width") },
72  { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#wordCount", I18N_NOOP2_NOSTRIP("@label number of words", "Words") },
73  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#apertureValue", I18N_NOOP2_NOSTRIP("@label EXIF aperture value", "Aperture") },
74  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureBiasValue", I18N_NOOP2_NOSTRIP("@label EXIF", "Exposure Bias Value") },
75  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime", I18N_NOOP2_NOSTRIP("@label EXIF", "Exposure Time") },
76  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash", I18N_NOOP2_NOSTRIP("@label EXIF", "Flash") },
77  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength", I18N_NOOP2_NOSTRIP("@label EXIF", "Focal Length") },
78  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLengthIn35mmFilm", I18N_NOOP2_NOSTRIP("@label EXIF", "Focal Length 35 mm") },
79  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings", I18N_NOOP2_NOSTRIP("@label EXIF", "ISO Speed Ratings") },
80  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make", I18N_NOOP2_NOSTRIP("@label EXIF", "Make") },
81  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode", I18N_NOOP2_NOSTRIP("@label EXIF", "Metering Mode") },
82  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model", I18N_NOOP2_NOSTRIP("@label EXIF", "Model") },
83  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation", I18N_NOOP2_NOSTRIP("@label EXIF", "Orientation") },
84  { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance", I18N_NOOP2_NOSTRIP("@label EXIF", "White Balance") },
85  { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#director", I18N_NOOP2_NOSTRIP("@label video director", "Director") },
86  { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#genre", I18N_NOOP2_NOSTRIP("@label music genre", "Genre") },
87  { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#musicAlbum", I18N_NOOP2_NOSTRIP("@label music album", "Album") },
88  { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#performer", I18N_NOOP2_NOSTRIP("@label", "Performer") },
89  { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#releaseDate", I18N_NOOP2_NOSTRIP("@label", "Release Date") },
90  { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#trackNumber", I18N_NOOP2_NOSTRIP("@label music track number", "Track") },
91  { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#created", I18N_NOOP2_NOSTRIP("@label resource created time", "Resource Created")},
92  { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#hasSubResource", I18N_NOOP2_NOSTRIP("@label", "Sub Resource")},
93  { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#lastModified", I18N_NOOP2_NOSTRIP("@label resource last modified", "Resource Modified")},
94  { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#numericRating", I18N_NOOP2_NOSTRIP("@label", "Numeric Rating")},
95  { "http://www.semanticdesktop.org/ontologies/2010/04/30/ndo#copiedFrom", I18N_NOOP2_NOSTRIP("@label", "Copied From")},
96  { "http://www.semanticdesktop.org/ontologies/2010/01/25/nuao#firstUsage", I18N_NOOP2_NOSTRIP("@label", "First Usage")},
97  { "http://www.semanticdesktop.org/ontologies/2010/01/25/nuao#lastUsage", I18N_NOOP2_NOSTRIP("@label", "Last Usage")},
98  { "http://www.semanticdesktop.org/ontologies/2010/01/25/nuao#usageCount", I18N_NOOP2_NOSTRIP("@label", "Usage Count")},
99  { "http://nepomuk.kde.org/ontologies/2010/11/29/kext#unixFileGroup", I18N_NOOP2_NOSTRIP("@label", "Unix File Group")},
100  { "http://nepomuk.kde.org/ontologies/2010/11/29/kext#unixFileMode", I18N_NOOP2_NOSTRIP("@label", "Unix File Mode")},
101  { "http://nepomuk.kde.org/ontologies/2010/11/29/kext#unixFileOwner", I18N_NOOP2_NOSTRIP("@label", "Unix File Owner")},
102  { "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", I18N_NOOP2_NOSTRIP("@label file type", "Type") },
103  { "translation.fuzzy", I18N_NOOP2_NOSTRIP("@label Number of fuzzy translations", "Fuzzy Translations") },
104  { "translation.last_translator", I18N_NOOP2_NOSTRIP("@label Name of last translator", "Last Translator") },
105  { "translation.obsolete", I18N_NOOP2_NOSTRIP("@label Number of obsolete translations", "Obsolete Translations") },
106  { "translation.source_date", I18N_NOOP2_NOSTRIP("@label", "Translation Source Date") },
107  { "translation.total", I18N_NOOP2_NOSTRIP("@label Number of total translations", "Total Translations") },
108  { "translation.translated", I18N_NOOP2_NOSTRIP("@label Number of translated strings", "Translated") },
109  { "translation.translation_date", I18N_NOOP2_NOSTRIP("@label", "Translation Date") },
110  { "translation.untranslated", I18N_NOOP2_NOSTRIP("@label Number of untranslated strings" , "Untranslated") },
111  { 0, 0, 0 } // mandatory last entry
112 };
113 
114 class KNfoTranslatorSingleton
115 {
116 public:
117  KNfoTranslator instance;
118 };
119 K_GLOBAL_STATIC(KNfoTranslatorSingleton, s_nfoTranslator)
120 
121 KNfoTranslator& KNfoTranslator::instance()
122 {
123  return s_nfoTranslator->instance;
124 }
125 
126 QString KNfoTranslator::translation(const KUrl& uri) const
127 {
128  const QString key = uri.url();
129  if (m_hash.contains(key)) {
130  return m_hash.value(key);
131  }
132 
133  // fallback if the URI is not translated
134 #ifndef KIO_NO_NEPOMUK
135  const QString label = Nepomuk::Types::Property(uri).label();
136 #else
137  QString label;
138  const int index = key.indexOf(QChar('#'));
139  if (index >= 0) {
140  label = key.right(key.size() - index - 1);
141  }
142 #endif
143  QString tunedLabel;
144  const int labelLength = label.length();
145  if (labelLength > 0) {
146  tunedLabel.reserve(labelLength);
147  tunedLabel = label[0].toUpper();
148  for (int i = 1; i < labelLength; ++i) {
149  if (label[i].isUpper() && !label[i - 1].isSpace() && !label[i - 1].isUpper()) {
150  tunedLabel += ' ';
151  tunedLabel += label[i].toLower();
152  } else {
153  tunedLabel += label[i];
154  }
155  }
156  }
157  return tunedLabel;
158 }
159 
160 KNfoTranslator::KNfoTranslator() :
161  m_hash()
162 {
163  const TranslationItem* item = &g_translations[0];
164  while (item->key != 0) {
165  m_hash.insert(item->key, i18nc(item->context, item->value));
166  ++item;
167  }
168 }
169 
170 KNfoTranslator::~KNfoTranslator()
171 {
172 }
kurl.h
KNfoTranslator::~KNfoTranslator
virtual ~KNfoTranslator()
Definition: knfotranslator.cpp:170
label
QString label(StandardShortcut id)
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
KNfoTranslator::KNfoTranslator
KNfoTranslator()
Definition: knfotranslator.cpp:160
KNfoTranslator
Returns translations for Nepomuk File Ontology URIs.
Definition: knfotranslator_p.h:33
QString
klocale.h
KUrl
i18nc
QString i18nc(const char *ctxt, const char *text)
I18N_NOOP2_NOSTRIP
#define I18N_NOOP2_NOSTRIP(ctxt, text)
g_translations
static const TranslationItem g_translations[]
Definition: knfotranslator.cpp:39
KNfoTranslator::translation
QString translation(const KUrl &uri) const
Definition: knfotranslator.cpp:126
KNfoTranslator::instance
static KNfoTranslator & instance()
Definition: knfotranslator.cpp:121
kstandarddirs.h
knfotranslator_p.h
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal