Baloo Widgets

metadatafilter.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Vishesh Handa <[email protected]>
3 
4  Adapted from KFileMetadataWidget
5  SPDX-FileCopyrightText: 2008 Sebastian Trueg <[email protected]>
6  SPDX-FileCopyrightText: 2009-2010 Peter Penz <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.1-or-later
9 */
10 
11 #include "metadatafilter.h"
12 
13 #include <KConfig>
14 #include <KConfigGroup>
15 
16 using namespace Baloo;
17 
18 MetadataFilter::MetadataFilter(QObject *parent)
19  : QObject(parent)
20 {
21  initMetaInformationSettings();
22 }
23 
24 MetadataFilter::~MetadataFilter() = default;
25 
26 void 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("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("Show");
38  KConfigGroup settings = config.group("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("Misc").writeEntry("version", currentVersion);
79  }
80 }
81 
82 QVariantMap 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("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 }
QString readEntry(const char *key, const char *aDefault=nullptr) const
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
KSharedConfigPtr config()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:13:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.