1 /*****************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
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 version 2 as published by the Free Software Foundation. *
8 * This library is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
11 * Library General Public License for more details. *
13 * You should have received a copy of the GNU Library General Public License *
14 * along with this library; see the file COPYING.LIB. If not, write to *
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
16 * Boston, MA 02110-1301, USA. *
17 *****************************************************************************/
19 #include "nfotranslator.h"
21 #include <kstandarddirs.h>
25 struct TranslationTuple
{
26 const char* const key
;
27 const char* const value
;
30 // TODO: a lot of NFO's are missing yet
31 static const TranslationTuple g_translations
[] = {
32 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment", I18N_NOOP2("@label", "Comment") },
33 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated", I18N_NOOP2("@label creation date", "Created") },
34 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize", I18N_NOOP2("@label file content size", "Size") },
35 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf", I18N_NOOP2("@label parent directory", "Part of") },
36 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified", I18N_NOOP2("@label modified date of file", "Modified") },
37 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType", I18N_NOOP2("@label", "MIME Type") },
38 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title", I18N_NOOP2("@label music title", "Title") },
39 { "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url", I18N_NOOP2("@label file URL", "Location") },
40 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator", I18N_NOOP2("@label", "Creator") },
41 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate", I18N_NOOP2("@label", "Average Bitrate") },
42 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#channels", I18N_NOOP2("@label", "Channels") },
43 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#characterCount", I18N_NOOP2("@label number of characters", "Characters") },
44 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#codec", I18N_NOOP2("@label", "Codec") },
45 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#colorDepth", I18N_NOOP2("@label", "Color Depth") },
46 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName", I18N_NOOP2("@label", "File Name") },
47 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height", I18N_NOOP2("@label", "Height") },
48 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#interlaceMode", I18N_NOOP2("@label", "Interlace Mode") },
49 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#lineCount", I18N_NOOP2("@label number of lines", "Lines") },
50 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#sampleRate", I18N_NOOP2("@label", "Sample Rate") },
51 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width", I18N_NOOP2("@label", "Width") },
52 { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#wordCount", I18N_NOOP2("@label number of words", "Words") },
53 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#apertureValue", I18N_NOOP2("@label EXIF aperture value", "Aperture") },
54 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureBiasValue", I18N_NOOP2("@label EXIF", "Exposure Bias Value") },
55 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime", I18N_NOOP2("@label EXIF", "Exposure Time") },
56 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash", I18N_NOOP2("@label EXIF", "Flash") },
57 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength", I18N_NOOP2("@label EXIF", "Focal Length") },
58 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings", I18N_NOOP2("@label EXIF", "ISO Speed Ratings") },
59 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make", I18N_NOOP2("@label EXIF", "Make") },
60 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode", I18N_NOOP2("@label EXIF", "Metering Mode") },
61 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model", I18N_NOOP2("@label EXIF", "Model") },
62 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation", I18N_NOOP2("@label EXIF", "Orientation") },
63 { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance", I18N_NOOP2("@label", "White Balance") },
64 { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#genre", I18N_NOOP2("@label music genre", "Genre") },
65 { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#musicAlbum", I18N_NOOP2("@label music album", "Album") },
66 { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#trackNumber", I18N_NOOP2("@label music track number", "Track") },
67 { "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", I18N_NOOP2("@label file type", "Type") },
68 { 0, 0 } // mandatory last entry
71 class NfoTranslatorSingleton
74 NfoTranslator instance
;
76 K_GLOBAL_STATIC(NfoTranslatorSingleton
, s_nfoTranslator
)
78 NfoTranslator
& NfoTranslator::instance()
80 return s_nfoTranslator
->instance
;
83 QString
NfoTranslator::translation(const QUrl
& uri
) const
85 const QString key
= uri
.toString();
86 if (m_hash
.contains(key
)) {
87 return m_hash
.value(key
);
90 // fallback if the URI is not translated
92 const int index
= key
.indexOf(QChar('#'));
94 translation
= key
.right(key
.size() - index
- 1);
99 NfoTranslator::NfoTranslator() :
102 const TranslationTuple
* tuple
= &g_translations
[0];
103 while (tuple
->key
!= 0) {
104 m_hash
.insert(tuple
->key
, i18n(tuple
->value
));
109 NfoTranslator::~NfoTranslator()