File indexing completed on 2024-05-05 16:08:25

0001 /*****************************************************************************
0002  * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at>                      *
0003  *                                                                           *
0004  * This library is free software; you can redistribute it and/or             *
0005  * modify it under the terms of the GNU Library General Public               *
0006  * License as published by the Free Software Foundation; either              *
0007  * version 2 of the License, or (at your option) any later version.          *
0008  *                                                                           *
0009  * This library is distributed in the hope that it will be useful,           *
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
0012  * Library General Public License for more details.                          *
0013  *                                                                           *
0014  * You should have received a copy of the GNU Library General Public License *
0015  * along with this library; see the file COPYING.LIB.  If not, write to      *
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
0017  * Boston, MA 02110-1301, USA.                                               *
0018  *****************************************************************************/
0019 
0020 #ifndef KFILEMETADATAMODEL_H
0021 #define KFILEMETADATAMODEL_H
0022 
0023 #include <QHash>
0024 #include <QObject>
0025 #include <QString>
0026 
0027 #include <config-kdelibs4support.h>
0028 #if ! KIO_NO_NEPOMUK
0029 #define DISABLE_NEPOMUK_LEGACY
0030 #include <variant.h>
0031 #endif
0032 
0033 class KFileItemList;
0034 class QUrl;
0035 class QWidget;
0036 
0037 /**
0038  * @brief Provides the data for the KMetaDataWidget.
0039  *
0040  * The default implementation provides all meta data
0041  * that are available due to Strigi and Nepomuk. If custom
0042  * meta data should be added, the method KFileMetaDataProvider::loadData()
0043  * must be overwritten.
0044  *
0045  * @see KFileMetaDataWidget
0046  */
0047 class KFileMetaDataProvider : public QObject
0048 {
0049     Q_OBJECT
0050 
0051 public:
0052     KDELIBS4SUPPORT_DEPRECATED explicit KFileMetaDataProvider(QObject *parent = 0);
0053     virtual ~KFileMetaDataProvider();
0054 
0055     /**
0056      * Sets the items, where the meta data should be
0057      * requested. The loading of the meta data is done
0058      * asynchronously. The signal loadingFinished() is
0059      * emitted, as soon as the loading has been finished.
0060      * The meta data can be retrieved by
0061      * KFileMetaDataProvider::data() afterwards. The label for
0062      * each item can be retrieved by KFileMetaDataProvider::label().
0063      */
0064     void setItems(const KFileItemList &items);
0065     KFileItemList items() const;
0066 
0067     /**
0068      * If set to true, data such as the comment, tag or rating cannot be changed by the user.
0069      * Per default read-only is disabled. The method readOnlyChanged() can be overwritten
0070      * to react on the change.
0071      */
0072     void setReadOnly(bool readOnly);
0073     bool isReadOnly() const;
0074 
0075     /**
0076      * @return Translated string for the label of the meta data represented
0077      *         by \p metaDataUri. If no custom translation is provided, the
0078      *         base implementation must be invoked.
0079      */
0080     virtual QString label(const QUrl &metaDataUri) const;
0081 
0082     /**
0083      * Meta data items are sorted alphabetically by their translated
0084      * label per default. However it is possible to provide an internal
0085      * prefix to the label, so that specific items are grouped together.
0086      * For example it makes sense that the meta data for 'width' and 'height'
0087      * of an image are shown below each other. By adding a common prefix,
0088      * a grouping is done.
0089      * @return Returns the name of the group the meta data indicated
0090      *         by \p metaDataUri belongs to. Per default an empty string
0091      *         is returned.
0092      */
0093     virtual QString group(const QUrl &metaDataUri) const;
0094 
0095 #if ! KIO_NO_NEPOMUK
0096     /**
0097      * @return Meta data for the items that have been set by
0098      *         KFileMetaDataProvider::setItems(). The method should
0099      *         be invoked after the signal loadingFinished() has
0100      *         been received (otherwise no data will be returned).
0101      */
0102     virtual QHash<QUrl, Nepomuk::Variant> data() const;
0103 
0104     /**
0105      * @return Factory method that returns a widget that should be used
0106      *         to show the meta data represented by \p metaDataUri. If
0107      *         no custom value widget is used for the given URI, the base
0108      *         implementation must be invoked. Per default an instance
0109      *         of QLabel will be returned.
0110      */
0111     virtual QWidget *createValueWidget(const QUrl &metaDataUri,
0112                                        const Nepomuk::Variant &value,
0113                                        QWidget *parent) const;
0114 #endif
0115 
0116 Q_SIGNALS:
0117     /**
0118      * Is emitted after the loading triggered by KFileMetaDataProvider::setItems()
0119      * has been finished.
0120      */
0121     void loadingFinished();
0122 
0123     void urlActivated(const QUrl &url);
0124 
0125     void dataChangeStarted();
0126     void dataChangeFinished();
0127 
0128 private:
0129     class Private;
0130     Private *const d;
0131 
0132     Q_PRIVATE_SLOT(d, void slotLoadingFinished())
0133     Q_PRIVATE_SLOT(d, void slotRatingChanged(unsigned int rating))
0134     Q_PRIVATE_SLOT(d, void slotTagsChanged(const QList<Nepomuk::Tag> &tags))
0135     Q_PRIVATE_SLOT(d, void slotCommentChanged(const QString &comment))
0136     Q_PRIVATE_SLOT(d, void slotTagClicked(const Nepomuk::Tag &tag))
0137     Q_PRIVATE_SLOT(d, void slotLinkActivated(const QString &))
0138 
0139     friend class KLoadMetaDataThread; // invokes KMetaDataObject::loadData()
0140 };
0141 
0142 #endif