Baloo Widgets

filemetadataprovider.h
1 /*
2  SPDX-FileCopyrightText: 2010 Peter Penz <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef _BALOO_FILEMETADATAPROVIDER_H
8 #define _BALOO_FILEMETADATAPROVIDER_H
9 
10 #include <QObject>
11 #include <QString>
12 #include <QVariant>
13 
14 #include <Baloo/IndexerConfig>
15 #include <KFileItem>
16 
17 namespace Baloo
18 {
19 /**
20  * @brief Provides the data for the MetaDataWidget.
21  *
22  * The default implementation provides all meta data
23  * that are available due to Baloo. If custom
24  * meta data should be added, the method KFileMetaDataProvider::loadData()
25  * must be overwritten.
26  *
27  * @see FileMetaDataWidget
28  */
30 {
31  Q_OBJECT
32 
33 public:
34  explicit FileMetaDataProvider(QObject *parent = nullptr);
35  ~FileMetaDataProvider() override;
36 
37  /**
38  * Sets the items, where the meta data should be
39  * requested. The loading of the meta data is done
40  * asynchronously. The signal loadingFinished() is
41  * emitted, as soon as the loading has been finished.
42  * The meta data can be retrieved by
43  * KFileMetaDataProvider::data() afterwards. The label for
44  * each item can be retrieved by KFileMetaDataProvider::label().
45  */
46  void setItems(const KFileItemList &items);
47  KFileItemList items() const;
48 
49  /**
50  * If set to true, data such as the comment, tag or rating cannot be changed by the user.
51  * Per default read-only is disabled. The method readOnlyChanged() can be overwritten
52  * to react on the change.
53  */
54  void setReadOnly(bool readOnly);
55  bool isReadOnly() const;
56 
57  /**
58  * @return Translated string for the label of the meta data represented
59  * by \p metaDataUri. If no custom translation is provided, the
60  * base implementation must be invoked.
61  */
62  virtual QString label(const QString &metaDataLabel) const;
63 
64  /**
65  * Meta data items are sorted alphabetically by their translated
66  * label per default. However it is possible to provide an internal
67  * prefix to the label, so that specific items are grouped together.
68  * For example it makes sense that the meta data for 'width' and 'height'
69  * of an image are shown below each other. By adding a common prefix,
70  * a grouping is done.
71  * @return Returns the name of the group the meta data indicated
72  * by \p label belongs to. Per default an empty string
73  * is returned.
74  */
75  virtual QString group(const QString &label) const;
76 
77  /**
78  * @return Meta data for the items that have been set by
79  * KFileMetaDataProvider::setItems(). The method should
80  * be invoked after the signal loadingFinished() has
81  * been received (otherwise no data will be returned).
82  */
83  QVariantMap data() const;
84 
85  /**
86  * Returns true if the items do not exist in the database and
87  * have just been indexed. This means, that we should not allow
88  * others to search through these items cause they do not exist
89  * in the database.
90  */
91  bool realTimeIndexing();
92 
93 Q_SIGNALS:
94  /**
95  * Emitted once per KFileMetaDataProvider::setItems()
96  * after data loading is finished.
97  */
98  void loadingFinished();
99 
100 private Q_SLOTS:
101  void slotFileFetchFinished(KJob *job);
102 
103 private:
104  void insertEditableData();
105 
106  void setFileItem();
107  void setFileItems();
108 
109  /**
110  * Insert intersection of common data of \p files
111  */
112  void insertCommonData(const QList<QVariantMap> &files);
113 
114  /**
115  * Insert basic data of a single file
116  */
117  void insertSingleFileBasicData();
118 
119  /**
120  * Insert basic data of a list of files
121  */
122  void insertFilesListBasicData();
123 
124  /**
125  * Checks for the existence of \p uri in \p allProperties, and accordingly
126  * inserts the total integer value of that property in m_data. On completion
127  * it removes \p uri from \p allProperties
128  */
129  void totalPropertyAndInsert(const QString &prop, const QList<QVariantMap> &resources, QSet<QString> &allProperties);
130 
131  /**
132  * @return The number of files and hidden files for the directory path.
133  */
134  static QPair<int, int> subDirectoriesCount(const QString &path);
135 
136  bool m_readOnly;
137 
138  /// Set to true when the file has been specially indexed and does not exist in the db
139  bool m_realTimeIndexing;
140  QList<KFileItem> m_fileItems;
141 
142  QVariantMap m_data;
143  Baloo::IndexerConfig m_config;
144 };
145 
146 }
147 #endif
Q_OBJECTQ_OBJECT
void loadingFinished()
Emitted once per KFileMetaDataProvider::setItems() after data loading is finished.
virtual QString label(const QString &metaDataLabel) const
virtual QString group(const QString &label) const
Meta data items are sorted alphabetically by their translated label per default.
Q_SLOTSQ_SLOTS
void setItems(const KFileItemList &items)
Sets the items, where the meta data should be requested.
Q_SIGNALSQ_SIGNALS
Provides the data for the MetaDataWidget.
bool realTimeIndexing()
Returns true if the items do not exist in the database and have just been indexed.
void setReadOnly(bool readOnly)
If set to true, data such as the comment, tag or rating cannot be changed by the user.
QObject * parent() const const
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.