File indexing completed on 2025-01-05 03:55:17

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-06-02
0007  * Description : class holding properties of referenced files used in non-dest. editing
0008  *
0009  * SPDX-FileCopyrightText: 2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_HISTORY_IMAGE_ID_H
0017 #define DIGIKAM_HISTORY_IMAGE_ID_H
0018 
0019 // Qt includes
0020 
0021 #include <QDateTime>
0022 #include <QMetaType>
0023 #include <QString>
0024 
0025 // Local includes
0026 
0027 #include "digikam_export.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 class DIGIKAM_EXPORT HistoryImageId
0033 {
0034 public:
0035 
0036     enum Type
0037     {
0038         InvalidType    = 0,
0039 
0040         /**
0041          * The original file (typically created by a camera)
0042          */
0043         Original       = 1 << 0,
0044 
0045         /**
0046          * A file created during the editing the history,
0047          * between the original file and the current file.
0048          */
0049         Intermediate   = 1 << 1,
0050 
0051         /**
0052          * When a file is created from multiple files, there can be no direct
0053          * original (panorama) but multiple sources, or one direct original
0054          * and some other, additional source files.
0055          * To record source files outside of the direct history, this type is used.
0056          */
0057         Source         = 1 << 2,
0058 
0059         /**
0060          * The "current" file. This is a special entry: It refers to the file from
0061          * which this history was read. It need not be written to the file,
0062          * because it describes the file itself. There is typically
0063          * exactly one current entry if the history is associated with an image;
0064          * there can be no current entry.
0065          */
0066         Current        = 1 << 3
0067     };
0068 
0069     /**
0070      * Note: In this class, the Type is used as a simple enum,
0071      * but it is also prepared for usage as flags.
0072      */
0073     Q_DECLARE_FLAGS(Types, Type)
0074 
0075 public:
0076 
0077     /// Creates an invalid HistoryImageId
0078     HistoryImageId();
0079 
0080     /// Creates an id with the given UUID and type
0081     explicit HistoryImageId(const QString& uuid, Type type = Current);
0082 
0083     /// A valid id needs at least a valid type and a UUID or a filename
0084     bool isValid()                                  const;
0085 
0086     Type type()                                     const;
0087 
0088     bool isOriginalFile()                           const
0089     {
0090         return (type() == Original);
0091     }
0092 
0093     bool isSourceFile()                             const
0094     {
0095         return (type() == Source);
0096     }
0097 
0098     bool isIntermediateFile()                       const
0099     {
0100         return (type() == Intermediate);
0101     }
0102 
0103     bool isCurrentFile()                            const
0104     {
0105         return (type() == Current);
0106     }
0107 
0108     bool operator==(const HistoryImageId& other)    const;
0109 
0110     void setType(HistoryImageId::Type type);
0111     void setUuid(const QString& uuid);
0112     void setFileName(const QString& fileName);
0113     void setCreationDate(const QDateTime& creationDate);
0114     void setPathOnDisk(const QString& filePath);
0115     void setPath(const QString& path);
0116     void setUniqueHash(const QString& uniqueHash, qlonglong fileSize);
0117 
0118     bool hasFileOnDisk()                            const;
0119 
0120     /// If a file on disk is referenced: Returns the path, without filename, with a trailing slash
0121     QString path()                                  const;
0122 
0123     /// If a file on disk is referenced: Returns the full file path (folder + filename)
0124     QString filePath()                              const;
0125 
0126     bool hasFileName()                              const;
0127 
0128     /// If a file on disk is referenced: Returns the file name (without folder)
0129     QString fileName()                              const;
0130 
0131     bool      hasUuid()                             const;
0132     QString   uuid()                                const;
0133     bool      hasCreationDate()                     const;
0134     QDateTime creationDate()                        const;
0135     bool      hasUniqueHashIdentifier()             const;
0136     QString   uniqueHash()                          const;
0137     qlonglong fileSize()                            const;
0138     QString   originalUuid()                        const;
0139 
0140 public:
0141 
0142     /// Type of this History Image Id
0143     Type      m_type;
0144 
0145     /**
0146      * A unique identifier for the referred file. This id shall be changed each time
0147      * the image is edited.
0148      */
0149     QString   m_uuid;
0150 
0151     /// The filename of the referred file
0152     QString   m_fileName;
0153 
0154     /// The creationDate of the original image
0155     QDateTime m_creationDate;
0156 
0157     /// The path of the referred file (NOTE: without file name!, including trailing slash)
0158     QString   m_filePath;
0159 
0160     /// The uniqueHash of the referred file
0161     QString   m_uniqueHash;
0162 
0163     /// The file size of the referred file
0164     qlonglong m_fileSize;
0165 
0166     /**
0167      * A unique identifier designating the _original image_ from which the referred
0168      * image was created. Typically, this is a RAW or JPEG created by the camera in
0169      * the moment of taking the photograph.
0170      */
0171     QString   m_originalUUID;
0172 };
0173 
0174 } // namespace Digikam
0175 
0176 Q_DECLARE_METATYPE(Digikam::HistoryImageId)
0177 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::HistoryImageId::Types)
0178 
0179 #endif // DIGIKAM_HISTORY_IMAGE_ID_H