1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2010-06-02
 * Description : class holding properties of referenced files used in non-dest. editing
 *
 * SPDX-FileCopyrightText: 2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 * SPDX-FileCopyrightText: 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#pragma once

// Qt includes

#include <QDateTime>
#include <QMetaType>
#include <QString>

// Local includes

#include "digikam_export.h"

namespace Digikam
{

class DIGIKAM_EXPORT HistoryImageId
{
public:

    enum Type
    {
        InvalidType    = 0,

        /**
         * The original file (typically created by a camera)
         */
        Original       = 1 << 0,

        /**
         * A file created during the editing the history,
         * between the original file and the current file.
         */
        Intermediate   = 1 << 1,

        /**
         * When a file is created from multiple files, there can be no direct
         * original (panorama) but multiple sources, or one direct original
         * and some other, additional source files.
         * To record source files outside of the direct history, this type is used.
         */
        Source         = 1 << 2,

        /**
         * The "current" file. This is a special entry: It refers to the file from
         * which this history was read. It need not be written to the file,
         * because it describes the file itself. There is typically
         * exactly one current entry if the history is associated with an image;
         * there can be no current entry.
         */
        Current        = 1 << 3
    };

    /**
     * Note: In this class, the Type is used as a simple enum,
     * but it is also prepared for usage as flags.
     */
    Q_DECLARE_FLAGS(Types, Type)

public:

    /// Creates an invalid HistoryImageId
    HistoryImageId() = default;

    /// Creates an id with the given UUID and type
    explicit HistoryImageId(const QString& uuid, Type type = Current);

    /// A valid id needs at least a valid type and a UUID or a filename
    bool isValid()                                  const;

    Type type()                                     const;

    bool isOriginalFile()                           const
    {
        return (type() == Original);
    }

    bool isSourceFile()                             const
    {
        return (type() == Source);
    }

    bool isIntermediateFile()                       const
    {
        return (type() == Intermediate);
    }

    bool isCurrentFile()                            const
    {
        return (type() == Current);
    }

    bool operator==(const HistoryImageId& other)    const;

    void setType(HistoryImageId::Type type);
    void setUuid(const QString& uuid);
    void setFileName(const QString& fileName);
    void setCreationDate(const QDateTime& creationDate);
    void setPathOnDisk(const QString& filePath);
    void setPath(const QString& path);
    void setUniqueHash(const QString& uniqueHash, qlonglong fileSize);

    bool hasFileOnDisk()                            const;

    /// If a file on disk is referenced: Returns the path, without filename, with a trailing slash
    QString path()                                  const;<--- Function 'path()' should return member 'm_filePath' by const reference.

    /// If a file on disk is referenced: Returns the full file path (folder + filename)
    QString filePath()                              const;

    bool hasFileName()                              const;

    /// If a file on disk is referenced: Returns the file name (without folder)
    QString fileName()                              const;<--- Function 'fileName()' should return member 'm_fileName' by const reference.

    bool      hasUuid()                             const;
    QString   uuid()                                const;<--- Function 'uuid()' should return member 'm_uuid' by const reference.
    bool      hasCreationDate()                     const;
    QDateTime creationDate()                        const;
    bool      hasUniqueHashIdentifier()             const;
    QString   uniqueHash()                          const;<--- Function 'uniqueHash()' should return member 'm_uniqueHash' by const reference.
    qlonglong fileSize()                            const;
    QString   originalUuid()                        const;<--- Function 'originalUuid()' should return member 'm_originalUUID' by const reference.

public:

    /// Type of this History Image Id
    Type      m_type        = InvalidType;

    /**
     * A unique identifier for the referred file. This id shall be changed each time
     * the image is edited.
     */
    QString   m_uuid;

    /// The filename of the referred file
    QString   m_fileName;

    /// The creationDate of the original image
    QDateTime m_creationDate;

    /// The path of the referred file (NOTE: without file name!, including trailing slash)
    QString   m_filePath;

    /// The uniqueHash of the referred file
    QString   m_uniqueHash;

    /// The file size of the referred file
    qlonglong m_fileSize    = 0;

    /**
     * A unique identifier designating the _original image_ from which the referred
     * image was created. Typically, this is a RAW or JPEG created by the camera in
     * the moment of taking the photograph.
     */
    QString   m_originalUUID;
};

} // namespace Digikam

Q_DECLARE_METATYPE(Digikam::HistoryImageId)
Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::HistoryImageId::Types)