File indexing completed on 2024-05-05 13:06:54

0001 /*
0002     SPDX-FileCopyrightText: 2012-2013 Vishesh Handa <me@vhanda.in>
0003 
0004     Adapted from KFileMetadataWidget
0005     SPDX-FileCopyrightText: 2008 Sebastian Trueg <trueg@kde.org>
0006     SPDX-FileCopyrightText: 2009-2010 Peter Penz <peter.penz@gmx.at>
0007 
0008     SPDX-License-Identifier: LGPL-2.1-or-later
0009 */
0010 
0011 #ifndef _BALOO_FILE_METADATAWIDGET_H
0012 #define _BALOO_FILE_METADATAWIDGET_H
0013 
0014 #include "widgets_export.h"
0015 
0016 #include <KFileItem>
0017 
0018 #include <QLocale>
0019 #include <QUrl>
0020 #include <QWidget>
0021 
0022 #include <memory>
0023 
0024 namespace Baloo
0025 {
0026 class FileMetaDataWidgetPrivate;
0027 
0028 /**
0029  * Modify format of date display
0030  */
0031 enum class DateFormats {
0032     LongFormat = QLocale::LongFormat, ///< @see QLocale::LongFormat
0033     ShortFormat = QLocale::ShortFormat, ///< @see QLocale::ShortFormat
0034 };
0035 
0036 enum class ConfigurationMode {
0037     ReStart = 0, /**< Switch into configuration mode. The selection is
0038                   *  initialized with the current configuration.
0039                   *  In case the widget is in configuration mode already,
0040                   *  the changes are discarded, and the mode is kept.
0041                   */
0042     Accept, /**< Save any changes, switch to regular mode */
0043     Cancel, /**< Discard any changes, switch to regular mode */
0044 };
0045 
0046 class BALOO_WIDGETS_EXPORT FileMetaDataWidget : public QWidget
0047 {
0048     Q_OBJECT
0049     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
0050     Q_PROPERTY(DateFormats dateFormat READ dateFormat WRITE setDateFormat)
0051 
0052 public:
0053     explicit FileMetaDataWidget(QWidget *parent = nullptr);
0054     ~FileMetaDataWidget() override;
0055 
0056     /**
0057      * Sets the items for which the meta data should be shown.
0058      * The signal metaDataRequestFinished() will be emitted,
0059      * as soon as the meta data for the items has been received.
0060      */
0061     void setItems(const KFileItemList &items);
0062     KFileItemList items() const;
0063 
0064     /**
0065      * If set to true, data such as the comment, tag or rating cannot be
0066      * changed by the user. Per default read-only is disabled.
0067      */
0068     void setReadOnly(bool readOnly);
0069     bool isReadOnly() const;
0070 
0071     /**
0072      * Set date display format.
0073      * Per Default format is Long = @see QLocale::LongFormat
0074      */
0075     void setDateFormat(const DateFormats format);
0076     DateFormats dateFormat() const;
0077 
0078     /** @see QWidget::sizeHint() */
0079     QSize sizeHint() const override;
0080 
0081     /**
0082      * Switch between regular (view) and configuration mode.
0083      * @since 19.08.00
0084      */
0085     void setConfigurationMode(ConfigurationMode mode);
0086 
0087 Q_SIGNALS:
0088     /**
0089      * Is emitted, if a meta data represents an URL that has
0090      * been clicked by the user.
0091      */
0092     void urlActivated(const QUrl &url);
0093 
0094     /**
0095      * Is emitted after the meta data has been received for the items
0096      * set by KFileMetaDataWidget::setItems().
0097      * @since 4.6
0098      */
0099     void metaDataRequestFinished(const KFileItemList &items);
0100 
0101 private:
0102     friend class FileMetaDataWidgetPrivate;
0103     std::unique_ptr<FileMetaDataWidgetPrivate> const d;
0104 
0105     Q_PRIVATE_SLOT(d, void slotLoadingFinished())
0106 };
0107 
0108 }
0109 Q_DECLARE_METATYPE(Baloo::DateFormats)
0110 
0111 #endif // _BALOO_FILE_METADATAWIDGET_H