File indexing completed on 2025-01-19 03:55:35

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-05-06
0007  * Description : abstract interface to image information.
0008  *               This class do not depend of digiKam database library
0009  *               to permit to re-use plugins with Showfoto.
0010  *
0011  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  * SPDX-FileCopyrightText: 2019-2020 by Minh Nghia Duong <minhnghiaduong997 at gmail dot com>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #ifndef DIGIKAM_DINFO_INTERFACE_H
0019 #define DIGIKAM_DINFO_INTERFACE_H
0020 
0021 // Qt includes
0022 
0023 #include <QMap>
0024 #include <QString>
0025 #include <QObject>
0026 #include <QVariant>
0027 #include <QUrl>
0028 #include <QSize>
0029 #include <QList>
0030 #include <QDateTime>
0031 #include <QDate>
0032 #include <QAbstractItemModel>
0033 
0034 // Local includes
0035 
0036 #include "digikam_export.h"
0037 #include "digikam_config.h"
0038 #include "captionvalues.h"
0039 #include "metaengine.h"
0040 
0041 #ifdef HAVE_GEOLOCATION
0042 #   include "gpsitemcontainer.h"
0043 #endif
0044 
0045 namespace Digikam
0046 {
0047 
0048 class DIGIKAM_EXPORT DInfoInterface : public QObject
0049 {
0050     Q_OBJECT
0051 
0052 public:
0053 
0054     typedef QMap<QString, QVariant> DInfoMap;       ///< Map of properties name and value.
0055     typedef QList<int>              DAlbumIDs;      ///< List of Album ids.
0056 
0057 public:
0058 
0059     explicit DInfoInterface(QObject* const parent);
0060     ~DInfoInterface() override;
0061 
0062 public:
0063 
0064     /// Slot to call when date time stamp from item is changed.
0065     Q_SLOT virtual void slotDateTimeForUrl(const QUrl& url,
0066                                            const QDateTime& dt,
0067                                            bool updModDate);
0068 
0069     /// Slot to call when something in metadata from item is changed.
0070     Q_SLOT virtual void slotMetadataChangedForUrl(const QUrl& url);
0071 
0072     Q_SIGNAL void signalAlbumItemsRecursiveCompleted(const QList<QUrl>& imageList);
0073 
0074     Q_SIGNAL void signalShortcutPressed(const QString& shortcut, int val);
0075 
0076 public:
0077 
0078     ///@{
0079     /// Low level items and albums methods
0080 
0081     virtual QList<QUrl> currentSelectedItems()                                      const;
0082     virtual QList<QUrl> currentAlbumItems()                                         const;
0083     virtual void        parseAlbumItemsRecursive();
0084 
0085     virtual QList<QUrl> albumItems(int)                                             const;
0086     virtual QList<QUrl> albumsItems(const DAlbumIDs&)                               const;
0087     virtual QList<QUrl> allAlbumItems()                                             const;
0088 
0089     virtual DInfoMap albumInfo(int)                                                 const;
0090     virtual void     setAlbumInfo(int, const DInfoMap&)                             const;
0091 
0092     virtual DInfoMap itemInfo(const QUrl&)                                          const;
0093     virtual void     setItemInfo(const QUrl&, const DInfoMap&);
0094 
0095     Q_SIGNAL void signalLastItemUrl(const QUrl&);
0096     ///@}
0097 
0098 public:
0099 
0100     ///@{
0101     /// Albums chooser view methods (to use items from albums before to process).
0102 
0103     virtual QWidget*  albumChooser(QWidget* const parent)                           const;
0104     virtual DAlbumIDs albumChooserItems()                                           const;
0105     virtual bool      supportAlbums()                                               const;
0106 
0107     Q_SIGNAL void signalAlbumChooserSelectionChanged();
0108     ///@}
0109 
0110 public:
0111 
0112     ///@{
0113     /// Album selector view methods (to upload items from an external place).
0114 
0115     virtual QWidget* uploadWidget(QWidget* const parent)                            const;
0116     virtual QUrl     uploadUrl()                                                    const;
0117 
0118     Q_SIGNAL void signalUploadUrlChanged();
0119 
0120     /// Url to upload new items without to use album selector.
0121     virtual QUrl     defaultUploadUrl()                                             const;
0122 
0123     Q_SIGNAL void signalImportedImage(const QUrl&);
0124     ///@}
0125 
0126 public:
0127 
0128     /// Return an instance of tag filter model if host application support this feature, else null pointer.
0129     virtual QAbstractItemModel* tagFilterModel();
0130 
0131 #ifdef HAVE_GEOLOCATION
0132 
0133     virtual QList<GPSItemContainer*> currentGPSItems()                              const;
0134 
0135 #endif
0136 
0137 public:
0138 
0139     /// Pass extra shortcut actions to widget and return prefixes of shortcuts
0140     virtual QMap<QString, QString> passShortcutActionsToWidget(QWidget* const)      const;
0141 
0142 public:
0143 
0144     /// Manipulate with item
0145     virtual void deleteImage(const QUrl& url);
0146 
0147 public:
0148 
0149     enum SetupPage
0150     {
0151         ExifToolPage = 0,
0152         ImageQualityPage
0153     };
0154 
0155     /// Open configuration dialog page.
0156     virtual void openSetupPage(SetupPage page);
0157 
0158     Q_SIGNAL void signalSetupChanged();
0159 
0160 public:
0161 
0162     bool forceAlbumSelection = false;
0163 };
0164 
0165 // -------------------------------------------------------------------------------------------------------------
0166 
0167 /**
0168  * DItemInfo is a class to get item information from host application (Showfoto or digiKam)
0169  * The interface is re-implemented in host and depend how item information must be retrieved
0170  * (from a database or by file metadata).
0171  * The easy way to use this container is given below:
0172  *
0173  *  // READ INFO FROM HOST ---------------------------------------------
0174  *
0175  *  QUrl                     itemUrl;                                   // The item url that you want to retrieve information.
0176  *  DInfoInterface*          hostIface;                                 // The host application interface instance.
0177  *
0178  *  DInfoInterface::DInfoMap info = hostIface->itemInfo(itemUrl);       // First stage is to get the information map from host application.
0179  *  DItemInfo item(info);                                               // Second stage, is to create the DIntenInfo instance for this item by url.
0180  *  QString   title       = item.name();                                // Now you can retrieve the title,
0181  *  QString   description = item.comment();                             // The comment,
0182  *  QDateTime time        = item.dateTime();                            // The time stamp, etc.
0183  *
0184  *  // WRITE INFO TO HOST ----------------------------------------------
0185  *
0186  *  QUrl                     itemUrl;                                   // The item url that you want to retrieve information.
0187  *  DInfoInterface*          hostIface;                                 // The host application interface instance.
0188  *
0189  *  DItemInfo item;                                                     // Create the DIntenInfo instance for this item with an empty internal info map.
0190  *  item.setRating(3);                                                  // Store rating to internal info map.
0191  *  item.setColorLabel(1);                                              // Store color label to internal info map.
0192  *  hostIface->setItemInfo(url, item.infoMap());                        // Update item information to host using internal info map.
0193  */
0194 
0195 class DIGIKAM_EXPORT DItemInfo
0196 {
0197 
0198 public:
0199 
0200     DItemInfo();
0201     explicit DItemInfo(const DInfoInterface::DInfoMap&);
0202     ~DItemInfo();
0203 
0204     DInfoInterface::DInfoMap infoMap() const;
0205 
0206 public:
0207 
0208     QString            name()                                                       const;
0209     QString            title()                                                      const;
0210     QString            comment()                                                    const;
0211     QSize              dimensions()                                                 const;
0212     QDateTime          dateTime()                                                   const;
0213     QStringList        tagsPath()                                                   const;
0214     QStringList        keywords()                                                   const;
0215 
0216     CaptionsMap        titles()                                                     const;
0217     void               setTitles(const CaptionsMap&);
0218     CaptionsMap        captions()                                                   const;
0219     void               setCaptions(const CaptionsMap&);
0220 
0221     MetaEngine::AltLangMap  copyrights()                                            const;
0222     void                    setCopyrights(const MetaEngine::AltLangMap& map);
0223     MetaEngine::AltLangMap  copyrightNotices()                                      const;
0224     void                    setCopyrightNotices(const MetaEngine::AltLangMap& map);
0225 
0226     int                albumId()                                                    const;
0227     int                orientation()                                                const;
0228     void               setOrientation(int);
0229     int                rating()                                                     const;
0230     void               setRating(int);
0231     int                colorLabel()                                                 const;
0232     void               setColorLabel(int);
0233     int                pickLabel()                                                  const;
0234     void               setPickLabel(int);
0235 
0236     double             latitude()                                                   const;
0237     double             longitude()                                                  const;
0238     double             altitude()                                                   const;
0239     qlonglong          fileSize()                                                   const;
0240     QStringList        creators()                                                   const;
0241     QString            credit()                                                     const;
0242     QString            rights()                                                     const;
0243     QString            source()                                                     const;
0244     QString            lens()                                                       const;
0245     QString            make()                                                       const;
0246     QString            model()                                                      const;
0247     QString            exposureTime()                                               const;
0248     QString            sensitivity()                                                const;
0249     QString            aperture()                                                   const;
0250     QString            focalLength()                                                const;
0251     QString            focalLength35mm()                                            const;
0252     QString            videoCodec()                                                 const;
0253 
0254     bool hasGeolocationInfo()                                                       const;
0255 
0256 private:
0257 
0258     QVariant parseInfoMap(const QString& key)                                       const;
0259 
0260 private:
0261 
0262     DInfoInterface::DInfoMap m_info;
0263 };
0264 
0265 // -----------------------------------------------------------------
0266 
0267 class DIGIKAM_EXPORT DAlbumInfo
0268 {
0269 
0270 public:
0271 
0272     explicit DAlbumInfo(const DInfoInterface::DInfoMap&);
0273     ~DAlbumInfo();
0274 
0275 public:
0276 
0277     QString title()                                                                 const;
0278     QString caption()                                                               const;
0279     QDate   date()                                                                  const;
0280     QString path()                                                                  const;
0281     QString albumPath()                                                             const;
0282 
0283 private:
0284 
0285     DInfoInterface::DInfoMap m_info;
0286 };
0287 
0288 } // namespace Digikam
0289 
0290 #endif // DIGIKAM_DINFO_INTERFACE_H