Baloo Widgets

metadatafilter.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Vishesh Handa <me@vhanda.in>
3
4 Adapted from KFileMetadataWidget
5 SPDX-FileCopyrightText: 2008 Sebastian Trueg <trueg@kde.org>
6 SPDX-FileCopyrightText: 2009-2010 Peter Penz <peter.penz@gmx.at>
7
8 SPDX-License-Identifier: LGPL-2.1-or-later
9*/
10
11#include "metadatafilter.h"
12
13#include <KConfig>
14#include <KConfigGroup>
15
16using namespace Baloo;
17
18MetadataFilter::MetadataFilter(QObject *parent)
19 : QObject(parent)
20{
21 initMetaInformationSettings();
22}
23
24MetadataFilter::~MetadataFilter() = default;
25
26void MetadataFilter::initMetaInformationSettings()
27{
28 const int currentVersion = 13; // increase version, if the blacklist of disabled
29 // properties should be updated
30
31 KConfig config(QStringLiteral("baloofileinformationrc"), KConfig::NoGlobals);
32 if (config.group(QStringLiteral("Misc")).readEntry("version", 0) < currentVersion) {
33 // The resource file is read the first time. Assure
34 // that some meta information is disabled per default.
35
36 // clear old info
37 config.deleteGroup(QStringLiteral("Show"));
38 KConfigGroup settings = config.group(QStringLiteral("Show"));
39
40 static const char *const disabledProperties[] = {
41 "width",
42 "height", // replaced by dimensions
43 "comment",
44 "contentSize",
45 "depends",
46 "lastModified",
47 "created",
48 "contentCreated",
49 "mimeType",
50 "url",
51 "channels",
52 "fileName",
53 "fileSize",
54 "kfileitem#owner",
55 "kfileitem#group",
56 "kfileitem#permissions",
57 "replayGainAlbumPeak",
58 "replayGainAlbumGain",
59 "replayGainTrackPeak",
60 "replayGainTrackGain",
61 "embeddedRating",
62 "lyrics",
63 "photoWhiteBalance",
64 "photoMeteringMode",
65 "photoSharpness",
66 "photoSaturation",
67 "photoPixelXDimension",
68 "photoPixelYDimension",
69 "photoGpsLongitude",
70 "photoGpsLatitude",
71 };
72
73 for (const auto property : disabledProperties) {
74 settings.writeEntry(property, false);
75 }
76
77 // mark the group as initialized
78 config.group(QStringLiteral("Misc")).writeEntry("version", currentVersion);
79 }
80}
81
82QVariantMap MetadataFilter::filter(const QVariantMap &data)
83{
84 if (data.isEmpty())
85 return data;
86
87 QVariantMap finalData(data);
88
89 //
90 // Remove all items, that are marked as hidden in kmetainformationrc
91 KConfig config(QStringLiteral("baloofileinformationrc"), KConfig::NoGlobals);
92 KConfigGroup settings = config.group(QStringLiteral("Show"));
93 QVariantMap::iterator it = finalData.begin();
94 while (it != finalData.end()) {
95 const QString uriString = it.key();
96 if (!settings.readEntry(uriString, true)) {
97 it = finalData.erase(it);
98 } else {
99 ++it;
100 }
101 }
102
103 return finalData;
104}
KConfigGroup group(const QString &group)
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
QVariant property(const char *name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.