File indexing completed on 2025-03-09 03:52:42

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-09-09
0007  * Description : Hint data containers for the collection scanner
0008  *
0009  * SPDX-FileCopyrightText: 2008      by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "collectionscannerhints.h"
0017 
0018 // Qt includes
0019 
0020 #include <QHash>
0021 
0022 namespace Digikam
0023 {
0024 
0025 CollectionScannerHints::Album::Album()
0026     : albumRootId(0),
0027       albumId    (0)
0028 {
0029 }
0030 
0031 CollectionScannerHints::Album::Album(int albumRootId, int albumId)
0032     : albumRootId(albumRootId),
0033       albumId    (albumId)
0034 {
0035 }
0036 
0037 bool CollectionScannerHints::Album::isNull() const
0038 {
0039     return ((albumRootId == 0) ||
0040             (albumId     == 0));
0041 }
0042 
0043 bool CollectionScannerHints::Album::operator==(const Album& other) const
0044 {
0045     return ((albumRootId == other.albumRootId) ||
0046             (albumId     == other.albumId));
0047 }
0048 
0049 QT_HASH_TYPE CollectionScannerHints::Album::qHash() const
0050 {
0051     return (::qHash(albumRootId) ^ ::qHash(albumId));
0052 }
0053 
0054 CollectionScannerHints::DstPath::DstPath()
0055     : albumRootId(0)
0056 {
0057 }
0058 
0059 CollectionScannerHints::DstPath::DstPath(int albumRootId, const QString& relativePath)
0060     : albumRootId (albumRootId),
0061       relativePath(relativePath)
0062 {
0063 }
0064 
0065 bool CollectionScannerHints::DstPath::isNull() const
0066 {
0067     return ((albumRootId == 0) ||
0068             relativePath.isNull());
0069 }
0070 
0071 bool CollectionScannerHints::DstPath::operator==(const DstPath& other) const
0072 {
0073     return ((albumRootId  == other.albumRootId) ||
0074             (relativePath == other.relativePath));
0075 }
0076 
0077 QT_HASH_TYPE CollectionScannerHints::DstPath::qHash() const
0078 {
0079     return (::qHash(albumRootId) ^ ::qHash(relativePath));
0080 }
0081 
0082 CollectionScannerHints::Item::Item()
0083     : id(0)
0084 {
0085 }
0086 
0087 CollectionScannerHints::Item::Item(qlonglong id)
0088     : id(id)
0089 {
0090 }
0091 
0092 bool CollectionScannerHints::Item::isNull() const
0093 {
0094     return (id == 0);
0095 }
0096 
0097 bool CollectionScannerHints::Item::operator==(const Item& other) const
0098 {
0099     return (id == other.id);
0100 }
0101 
0102 QT_HASH_TYPE CollectionScannerHints::Item::qHash() const
0103 {
0104     return ::qHash(id);
0105 }
0106 
0107 // -----------------------------------------------------------------------------------
0108 
0109 AlbumCopyMoveHint::AlbumCopyMoveHint()
0110 {
0111 }
0112 
0113 AlbumCopyMoveHint::AlbumCopyMoveHint(int srcAlbumRootId,
0114                                      int srcAlbum,
0115                                      int dstAlbumRootId,
0116                                      const QString& dstRelativePath)
0117     : m_src(srcAlbumRootId, srcAlbum),
0118       m_dst(dstAlbumRootId, dstRelativePath)
0119 {
0120 }
0121 
0122 int AlbumCopyMoveHint::albumRootIdSrc() const
0123 {
0124     return m_src.albumRootId;
0125 }
0126 
0127 int AlbumCopyMoveHint::albumIdSrc() const
0128 {
0129     return m_src.albumId;
0130 }
0131 
0132 bool AlbumCopyMoveHint::isSrcAlbum(int albumRootId, int albumId) const
0133 {
0134     return ((m_src.albumRootId == albumRootId) &&
0135             (m_src.albumId     == albumId));
0136 }
0137 
0138 int AlbumCopyMoveHint::albumRootIdDst() const
0139 {
0140     return m_dst.albumRootId;
0141 }
0142 
0143 QString AlbumCopyMoveHint::relativePathDst() const
0144 {
0145     return m_dst.relativePath;
0146 }
0147 
0148 bool AlbumCopyMoveHint::isDstAlbum(int albumRootId, const QString& relativePath) const
0149 {
0150     return ((m_dst.albumRootId  == albumRootId) &&
0151             (m_dst.relativePath == relativePath));
0152 }
0153 
0154 QT_HASH_TYPE AlbumCopyMoveHint::qHash() const
0155 {
0156     return (::qHash(m_src.albumRootId) ^ ::qHash(m_src.albumId) ^
0157             ::qHash(m_dst.albumRootId) ^ ::qHash(m_dst.relativePath));
0158 }
0159 
0160 #ifdef HAVE_DBUS
0161 
0162 AlbumCopyMoveHint& AlbumCopyMoveHint::operator<<(const QDBusArgument& argument)
0163 {
0164     argument.beginStructure();
0165     argument >> m_src.albumRootId >> m_src.albumId
0166              >> m_dst.albumRootId >> m_dst.relativePath;
0167     argument.endStructure();
0168 
0169     return *this;
0170 }
0171 
0172 const AlbumCopyMoveHint& AlbumCopyMoveHint::operator>>(QDBusArgument& argument) const
0173 {
0174     argument.beginStructure();
0175     argument << m_src.albumRootId << m_src.albumId
0176              << m_dst.albumRootId << m_dst.relativePath;
0177     argument.endStructure();
0178 
0179     return *this;
0180 }
0181 
0182 #endif
0183 
0184 // -----------------------------------------------------------------------------------------
0185 
0186 ItemCopyMoveHint::ItemCopyMoveHint()
0187 {
0188 }
0189 
0190 ItemCopyMoveHint::ItemCopyMoveHint(const QList<qlonglong>& srcIds,
0191                                    int dstItemRootId,
0192                                    int dstAlbumId,
0193                                    const QStringList& dstNames)
0194     : m_srcIds  (srcIds),
0195       m_dst     (dstItemRootId, dstAlbumId),
0196       m_dstNames(dstNames)
0197 {
0198 }
0199 
0200 QList<qlonglong> ItemCopyMoveHint::srcIds() const
0201 {
0202     return m_srcIds;
0203 }
0204 
0205 bool ItemCopyMoveHint::isSrcId(qlonglong id) const
0206 {
0207     return m_srcIds.contains(id);
0208 }
0209 
0210 int ItemCopyMoveHint::albumRootIdDst() const
0211 {
0212     return m_dst.albumRootId;
0213 }
0214 
0215 int ItemCopyMoveHint::albumIdDst() const
0216 {
0217     return m_dst.albumId;
0218 }
0219 
0220 bool ItemCopyMoveHint::isDstAlbum(int albumRootId, int albumId) const
0221 {
0222     return ((m_dst.albumRootId == albumRootId) &&
0223             (m_dst.albumId     == albumId));
0224 }
0225 
0226 QStringList ItemCopyMoveHint::dstNames() const
0227 {
0228     return m_dstNames;
0229 }
0230 
0231 QString ItemCopyMoveHint::dstName(qlonglong id) const
0232 {
0233     if (m_dstNames.isEmpty())
0234     {
0235         return QString();
0236     }
0237 
0238     int index = m_srcIds.indexOf(id);
0239 
0240     return m_dstNames.at(index);
0241 }
0242 
0243 #ifdef HAVE_DBUS
0244 
0245 ItemCopyMoveHint& ItemCopyMoveHint::operator<<(const QDBusArgument& argument)
0246 {
0247     argument.beginStructure();
0248     argument >> m_srcIds
0249              >> m_dst.albumRootId >> m_dst.albumId
0250              >> m_dstNames;
0251     argument.endStructure();
0252 
0253     return *this;
0254 }
0255 
0256 const ItemCopyMoveHint& ItemCopyMoveHint::operator>>(QDBusArgument& argument) const
0257 {
0258     argument.beginStructure();
0259     argument << m_srcIds
0260              << m_dst.albumRootId << m_dst.albumId
0261              << m_dstNames;
0262     argument.endStructure();
0263 
0264     return *this;
0265 }
0266 
0267 #endif
0268 
0269 // ---------------------------------------------------------------------------------------
0270 
0271 ItemChangeHint::ItemChangeHint()
0272     : m_type(ItemModified)
0273 {
0274 }
0275 
0276 ItemChangeHint::ItemChangeHint(const QList<qlonglong>& ids, ChangeType type)
0277     : m_ids(ids),
0278       m_type(type)
0279 {
0280 }
0281 
0282 QList<qlonglong> ItemChangeHint::ids() const
0283 {
0284     return m_ids;
0285 }
0286 
0287 bool ItemChangeHint::isId(qlonglong id) const
0288 {
0289     return m_ids.contains(id);
0290 }
0291 
0292 ItemChangeHint::ChangeType ItemChangeHint::changeType() const
0293 {
0294     return m_type;
0295 }
0296 
0297 #ifdef HAVE_DBUS
0298 
0299 ItemChangeHint& ItemChangeHint::operator<<(const QDBusArgument& argument)
0300 {
0301     argument.beginStructure();
0302     int type;
0303     argument >> m_ids
0304              >> type;
0305     argument.endStructure();
0306     m_type = (ChangeType)type;
0307 
0308     return *this;
0309 }
0310 
0311 const ItemChangeHint& ItemChangeHint::operator>>(QDBusArgument& argument) const
0312 {
0313     argument.beginStructure();
0314     argument << m_ids
0315              << (int)m_type;
0316     argument.endStructure();
0317 
0318     return *this;
0319 }
0320 
0321 #endif
0322 
0323 // ---------------------------------------------------------------------------------------
0324 
0325 ItemMetadataAdjustmentHint::ItemMetadataAdjustmentHint()
0326     : m_id      (0),
0327       m_status  (AboutToEditMetadata),
0328       m_fileSize(0)
0329 {
0330 }
0331 
0332 ItemMetadataAdjustmentHint::ItemMetadataAdjustmentHint(qlonglong id, AdjustmentStatus status,
0333                                                        const QDateTime& modificationDateOnDisk, qlonglong fileSize)
0334     : m_id              (id),
0335       m_status          (status),
0336       m_modificationDate(modificationDateOnDisk),
0337       m_fileSize        (fileSize)
0338 {
0339 }
0340 
0341 qlonglong ItemMetadataAdjustmentHint::id()  const
0342 {
0343     return m_id;
0344 }
0345 
0346 ItemMetadataAdjustmentHint::AdjustmentStatus ItemMetadataAdjustmentHint::adjustmentStatus() const
0347 {
0348     return m_status;
0349 }
0350 
0351 QDateTime ItemMetadataAdjustmentHint::modificationDate() const
0352 {
0353     return m_modificationDate;
0354 }
0355 
0356 qlonglong ItemMetadataAdjustmentHint::fileSize() const
0357 {
0358     return m_fileSize;
0359 }
0360 
0361 #ifdef HAVE_DBUS
0362 
0363 ItemMetadataAdjustmentHint& ItemMetadataAdjustmentHint::operator<<(const QDBusArgument& argument)
0364 {
0365     argument.beginStructure();
0366     int status;
0367     argument >> m_id
0368              >> status
0369              >> m_modificationDate
0370              >> m_fileSize;
0371     argument.endStructure();
0372 
0373     return *this;
0374 }
0375 
0376 const ItemMetadataAdjustmentHint& ItemMetadataAdjustmentHint::operator>>(QDBusArgument& argument) const
0377 {
0378     argument.beginStructure();
0379     argument << m_id
0380              << (int)m_status
0381              << m_modificationDate
0382              << m_fileSize;
0383     argument.endStructure();
0384 
0385     return *this;
0386 }
0387 
0388 #endif
0389 
0390 } // namespace Digikam