Baloo Widgets

metadatafilter.cpp
1 /*
2  <one line to give the library's name and an idea of what it does.>
3  Copyright (C) 2012 Vishesh Handa <[email protected]>
4 
5  Adapted from KFileMetadataWidget
6  Copyright (C) 2008 by Sebastian Trueg <[email protected]>
7  Copyright (C) 2009-2010 by Peter Penz <[email protected]>
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 using namespace Baloo;
31 
32 MetadataFilter::MetadataFilter(QObject* parent): QObject(parent)
33 {
34  initMetaInformationSettings();
35 }
36 
37 MetadataFilter::~MetadataFilter()
38 {
39 
40 }
41 
42 void MetadataFilter::initMetaInformationSettings()
43 {
44  const int currentVersion = 11; // increase version, if the blacklist of disabled
45  // properties should be updated
46 
47  KConfig config(QStringLiteral("baloofileinformationrc"), KConfig::NoGlobals);
48  if (config.group("Misc").readEntry("version", 0) < currentVersion) {
49  // The resource file is read the first time. Assure
50  // that some meta information is disabled per default.
51 
52  // clear old info
53  config.deleteGroup("Show");
54  KConfigGroup settings = config.group("Show");
55 
56  static const char* const disabledProperties[] = {
57  "comment",
58  "contentSize",
59  "depends",
60  "lastModified",
61  "created",
62  "contentCreated",
63  "mimeType",
64  "url",
65  "channels",
66  "fileName",
67  "fileSize",
68  "kfileitem#owner",
69  "kfileitem#group",
70  "kfileitem#permissions",
71  "replayGainAlbumPeak",
72  "replayGainAlbumGain",
73  "replayGainTrackPeak",
74  "replayGainTrackGain",
75  "embeddedRating",
76  "lyrics",
77  "photoWhiteBalance",
78  "photoMeteringMode",
79  "photoSharpness",
80  "photoSaturation",
81  "photoPixelXDimension",
82  "photoPixelYDimension",
83  };
84 
85 
86  for (const auto property : disabledProperties) {
87  settings.writeEntry(property, false);
88  }
89 
90  // mark the group as initialized
91  config.group("Misc").writeEntry("version", currentVersion);
92  }
93 }
94 
95 QVariantMap MetadataFilter::filter(const QVariantMap& data)
96 {
97  if( data.isEmpty() )
98  return data;
99 
100  QVariantMap finalData(data);
101 
102  //
103  // Remove all items, that are marked as hidden in kmetainformationrc
104  KConfig config(QStringLiteral("baloofileinformationrc"), KConfig::NoGlobals);
105  KConfigGroup settings = config.group("Show");
106  QVariantMap::iterator it = finalData.begin();
107  while (it != finalData.end()) {
108  const QString uriString = it.key();
109  if (!settings.readEntry(uriString, true)) {
110  it = finalData.erase(it);
111  } else {
112  ++it;
113  }
114  }
115 
116  return finalData;
117 }
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KSharedConfigPtr config()
QVariant property(const char *name) const const
T readEntry(const QString &key, const T &aDefault) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 18 2021 23:07:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.