Baloo Widgets

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

KDE's Doxygen guidelines are available online.