File indexing completed on 2024-04-21 08:28:58

0001 /*
0002     SPDX-FileCopyrightText: 2010 Peter Penz <peter.penz@gmx.at>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef _BALOO_FILEMETADATAPROVIDER_H
0008 #define _BALOO_FILEMETADATAPROVIDER_H
0009 
0010 #include <QObject>
0011 #include <QString>
0012 #include <QVariant>
0013 
0014 #include <KFileItem>
0015 
0016 namespace Baloo
0017 {
0018 class FileMetaDataProviderPrivate;
0019 
0020 /**
0021  * @brief Provides the data for the MetaDataWidget.
0022  *
0023  * The default implementation provides all meta data
0024  * that are available due to Baloo. If custom
0025  * meta data should be added, the method KFileMetaDataProvider::loadData()
0026  * must be overwritten.
0027  *
0028  * @see FileMetaDataWidget
0029  */
0030 class FileMetaDataProvider : public QObject
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     explicit FileMetaDataProvider(QObject *parent = nullptr);
0036     ~FileMetaDataProvider() override;
0037 
0038     /**
0039      * Sets the items, where the meta data should be
0040      * requested. The loading of the meta data is done
0041      * asynchronously. The signal loadingFinished() is
0042      * emitted, as soon as the loading has been finished.
0043      * The meta data can be retrieved by
0044      * KFileMetaDataProvider::data() afterwards. The label for
0045      * each item can be retrieved by KFileMetaDataProvider::label().
0046      */
0047     void setItems(const KFileItemList &items);
0048     KFileItemList items() const;
0049 
0050     /**
0051      * If set to true, data such as the comment, tag or rating cannot be changed by the user.
0052      * Per default read-only is disabled. The method readOnlyChanged() can be overwritten
0053      * to react on the change.
0054      */
0055     void setReadOnly(bool readOnly);
0056     bool isReadOnly() const;
0057 
0058     /**
0059      * @return Translated string for the label of the meta data represented
0060      *         by \p metaDataUri. If no custom translation is provided, the
0061      *         base implementation must be invoked.
0062      */
0063     virtual QString label(const QString &metaDataLabel) const;
0064 
0065     /**
0066      * Meta data items are sorted alphabetically by their translated
0067      * label per default. However it is possible to provide an internal
0068      * prefix to the label, so that specific items are grouped together.
0069      * For example it makes sense that the meta data for 'width' and 'height'
0070      * of an image are shown below each other. By adding a common prefix,
0071      * a grouping is done.
0072      * @return Returns the name of the group the meta data indicated
0073      *         by \p label belongs to. Per default an empty string
0074      *         is returned.
0075      */
0076     virtual QString group(const QString &label) const;
0077 
0078     /**
0079      * @return Meta data for the items that have been set by
0080      *         KFileMetaDataProvider::setItems(). The method should
0081      *         be invoked after the signal loadingFinished() has
0082      *         been received (otherwise no data will be returned).
0083      */
0084     QVariantMap data() const;
0085 
0086 Q_SIGNALS:
0087     /**
0088      * Emitted once per KFileMetaDataProvider::setItems()
0089      * after data loading is finished.
0090      */
0091     void loadingFinished();
0092 
0093 private:
0094     FileMetaDataProviderPrivate *d;
0095 };
0096 
0097 }
0098 #endif