2
<one line to give the library's name and an idea of what it does.>
3
Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
5
Adapated from KFileMetadataWidget
6
Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org>
7
Copyright (C) 2009-2010 by Peter Penz <peter.penz@gmx.at>
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
#include "metadatafilter.h"
28
#include <KConfigGroup>
30
#include <Nepomuk2/Types/Property>
31
#include <Nepomuk2/Variant>
33
#include <Soprano/Vocabulary/RDF>
34
#include <Soprano/Vocabulary/NAO>
36
using namespace Soprano::Vocabulary;
40
MetadataFilter::MetadataFilter(QObject* parent): QObject(parent)
42
initMetaInformationSettings();
45
MetadataFilter::~MetadataFilter()
50
void MetadataFilter::initMetaInformationSettings()
52
const int currentVersion = 4; // increase version, if the blacklist of disabled
53
// properties should be updated
55
KConfig config("kmetainformationrc", KConfig::NoGlobals);
56
if (config.group("Misc").readEntry("version", 0) < currentVersion) {
57
// The resource file is read the first time. Assure
58
// that some meta information is disabled per default.
61
config.deleteGroup("Show");
62
KConfigGroup settings = config.group("Show");
64
static const char* const disabledProperties[] = {
65
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#comment",
66
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentSize",
67
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#depends",
68
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf",
69
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#lastModified",
70
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#created",
71
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated",
72
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType",
73
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent",
74
"http://www.semanticdesktop.org/ontologies/2007/01/19/nie#url",
75
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#averageBitrate",
76
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#channels",
77
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName",
78
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileSize",
79
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#apertureValue",
80
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureBiasValue",
81
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#exposureTime",
82
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#flash",
83
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLength",
84
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#focalLengthIn35mmFilm",
85
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#isoSpeedRatings",
86
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#make",
87
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#meteringMode",
88
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#model",
89
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation",
90
"http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#whiteBalance",
91
"http://www.semanticdesktop.org/ontologies/2007/08/15/nao#modified",
92
"http://www.semanticdesktop.org/ontologies/2007/08/15/nao#lastModified",
93
"http://www.semanticdesktop.org/ontologies/2007/08/15/nao#created",
94
"http://www.semanticdesktop.org/ontologies/2007/08/15/nao#annotation",
95
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
97
"kfileitem#permissions",
98
0 // mandatory last entry
101
for (int i = 0; disabledProperties[i] != 0; ++i) {
102
settings.writeEntry(disabledProperties[i], false);
105
// mark the group as initialized
106
config.group("Misc").writeEntry("version", currentVersion);
110
QHash<QUrl, Variant> MetadataFilter::filter(const QHash<QUrl, Nepomuk2::Variant>& data)
115
QList<QUrl> types = data.value( RDF::type() ).toUrlList();
118
// Special filtering for certain types
121
if( types.contains( NAO::Tag() ) ) {
122
QHash<QUrl, Variant> finalData;
124
if( data.contains(NAO::identifier()) )
125
finalData.insert( NAO::identifier(), data.value(NAO::identifier()) );
126
if( data.contains(NAO::prefLabel()) )
127
finalData.insert( NAO::prefLabel(), data.value(NAO::prefLabel()) );
132
QHash<QUrl, Variant> finalData( data );
135
// Remove all the meta-properties
137
finalData.remove( RDF::type() );
139
finalData.remove( NAO::lastModified() );
140
finalData.remove( NAO::created() );
141
finalData.remove( NAO::userVisible() );
144
// Remove all items, that are marked as hidden in kmetainformationrc
145
KConfig config("kmetainformationrc", KConfig::NoGlobals);
146
KConfigGroup settings = config.group("Show");
147
QHash<QUrl, Variant>::iterator it = finalData.begin();
148
while (it != finalData.end()) {
149
const QString uriString = it.key().toString();
150
if (!settings.readEntry(uriString, true) || !Types::Property(it.key()).userVisible()) {
151
it = finalData.erase(it);
b'\\ No newline at end of file'