~ubuntu-branches/ubuntu/raring/nepomuk-widgets/raring-proposed

« back to all changes in this revision

Viewing changes to ui/metadatafilter.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2012-11-20 13:16:59 UTC
  • Revision ID: package-import@ubuntu.com-20121120131659-o1ohtb1k8803vr7p
Tags: upstream-4.9.80
ImportĀ upstreamĀ versionĀ 4.9.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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>
 
4
 
 
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>
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
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
 
22
*/
 
23
 
 
24
 
 
25
#include "metadatafilter.h"
 
26
 
 
27
#include <KConfig>
 
28
#include <KConfigGroup>
 
29
 
 
30
#include <Nepomuk2/Types/Property>
 
31
#include <Nepomuk2/Variant>
 
32
 
 
33
#include <Soprano/Vocabulary/RDF>
 
34
#include <Soprano/Vocabulary/NAO>
 
35
 
 
36
using namespace Soprano::Vocabulary;
 
37
 
 
38
namespace Nepomuk2 {
 
39
 
 
40
MetadataFilter::MetadataFilter(QObject* parent): QObject(parent)
 
41
{
 
42
    initMetaInformationSettings();
 
43
}
 
44
 
 
45
MetadataFilter::~MetadataFilter()
 
46
{
 
47
 
 
48
}
 
49
 
 
50
void MetadataFilter::initMetaInformationSettings()
 
51
{
 
52
    const int currentVersion = 4; // increase version, if the blacklist of disabled
 
53
    // properties should be updated
 
54
 
 
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.
 
59
 
 
60
        // clear old info
 
61
        config.deleteGroup("Show");
 
62
        KConfigGroup settings = config.group("Show");
 
63
 
 
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",
 
96
            "kfileitem#owner",
 
97
            "kfileitem#permissions",
 
98
            0 // mandatory last entry
 
99
        };
 
100
 
 
101
        for (int i = 0; disabledProperties[i] != 0; ++i) {
 
102
            settings.writeEntry(disabledProperties[i], false);
 
103
        }
 
104
 
 
105
        // mark the group as initialized
 
106
        config.group("Misc").writeEntry("version", currentVersion);
 
107
    }
 
108
}
 
109
 
 
110
QHash<QUrl, Variant> MetadataFilter::filter(const QHash<QUrl, Nepomuk2::Variant>& data)
 
111
{
 
112
    if( data.isEmpty() )
 
113
        return data;
 
114
 
 
115
    QList<QUrl> types = data.value( RDF::type() ).toUrlList();
 
116
 
 
117
    //
 
118
    // Special filtering for certain types
 
119
    //
 
120
 
 
121
    if( types.contains( NAO::Tag() ) ) {
 
122
        QHash<QUrl, Variant> finalData;
 
123
 
 
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()) );
 
128
 
 
129
        return finalData;
 
130
    }
 
131
 
 
132
    QHash<QUrl, Variant> finalData( data );
 
133
 
 
134
    //
 
135
    // Remove all the meta-properties
 
136
    //
 
137
    finalData.remove( RDF::type() );
 
138
 
 
139
    finalData.remove( NAO::lastModified() );
 
140
    finalData.remove( NAO::created() );
 
141
    finalData.remove( NAO::userVisible() );
 
142
 
 
143
    //
 
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);
 
152
        } else {
 
153
            ++it;
 
154
        }
 
155
    }
 
156
 
 
157
    return finalData;
 
158
}
 
159
 
 
160
}
 
 
b'\\ No newline at end of file'