File indexing completed on 2025-01-19 03:53:37
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-04-21 0007 * Description : Handling access to one item and associated data - History 0008 * 0009 * SPDX-FileCopyrightText: 2005 by Renchi Raju <renchi dot raju at gmail dot com> 0010 * SPDX-FileCopyrightText: 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0011 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0012 * SPDX-FileCopyrightText: 2013 by Michael G. Hansen <mike at mghansen dot de> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #include "iteminfo_p.h" 0019 0020 namespace Digikam 0021 { 0022 0023 DImageHistory ItemInfo::imageHistory() const 0024 { 0025 if (!m_data) 0026 { 0027 return DImageHistory(); 0028 } 0029 0030 ImageHistoryEntry entry = CoreDbAccess().db()->getItemHistory(m_data->id); 0031 0032 return DImageHistory::fromXml(entry.history); 0033 } 0034 0035 void ItemInfo::setItemHistory(const DImageHistory& history) 0036 { 0037 if (!m_data) 0038 { 0039 return; 0040 } 0041 0042 CoreDbAccess().db()->setItemHistory(m_data->id, history.toXml()); 0043 } 0044 0045 bool ItemInfo::hasImageHistory() const 0046 { 0047 if (!m_data) 0048 { 0049 return false; 0050 } 0051 0052 return CoreDbAccess().db()->hasImageHistory(m_data->id); 0053 } 0054 0055 QString ItemInfo::uuid() const 0056 { 0057 if (!m_data) 0058 { 0059 return QString(); 0060 } 0061 0062 return CoreDbAccess().db()->getImageUuid(m_data->id); 0063 } 0064 0065 void ItemInfo::setUuid(const QString& uuid) 0066 { 0067 if (!m_data) 0068 { 0069 return; 0070 } 0071 0072 CoreDbAccess().db()->setImageUuid(m_data->id, uuid); 0073 } 0074 0075 HistoryImageId ItemInfo::historyImageId() const 0076 { 0077 if (!m_data) 0078 { 0079 return HistoryImageId(); 0080 } 0081 0082 HistoryImageId id(uuid()); 0083 id.setCreationDate(dateTime()); 0084 id.setFileName(name()); 0085 id.setPathOnDisk(filePath()); 0086 0087 if (CoreDbAccess().db()->isUniqueHashV2()) 0088 { 0089 ItemScanInfo info = CoreDbAccess().db()->getItemScanInfo(m_data->id); 0090 id.setUniqueHash(info.uniqueHash, info.fileSize); 0091 } 0092 0093 return id; 0094 } 0095 0096 0097 bool ItemInfo::hasDerivedImages() const 0098 { 0099 if (!m_data) 0100 { 0101 return false; 0102 } 0103 0104 return CoreDbAccess().db()->hasImagesRelatingTo(m_data->id, DatabaseRelation::DerivedFrom); 0105 } 0106 0107 bool ItemInfo::hasAncestorImages() const 0108 { 0109 if (!m_data) 0110 { 0111 return false; 0112 } 0113 0114 return CoreDbAccess().db()->hasImagesRelatedFrom(m_data->id, DatabaseRelation::DerivedFrom); 0115 } 0116 0117 QList<ItemInfo> ItemInfo::derivedImages() const 0118 { 0119 if (!m_data) 0120 { 0121 return QList<ItemInfo>(); 0122 } 0123 0124 return ItemInfoList(CoreDbAccess().db()->getImagesRelatingTo(m_data->id, DatabaseRelation::DerivedFrom)); 0125 } 0126 0127 QList<ItemInfo> ItemInfo::ancestorImages() const 0128 { 0129 if (!m_data) 0130 { 0131 return QList<ItemInfo>(); 0132 } 0133 0134 return ItemInfoList(CoreDbAccess().db()->getImagesRelatedFrom(m_data->id, DatabaseRelation::DerivedFrom)); 0135 } 0136 0137 QList<QPair<qlonglong, qlonglong> > ItemInfo::relationCloud() const 0138 { 0139 if (!m_data) 0140 { 0141 return QList<QPair<qlonglong, qlonglong> >(); 0142 } 0143 0144 return CoreDbAccess().db()->getRelationCloud(m_data->id, DatabaseRelation::DerivedFrom); 0145 } 0146 0147 void ItemInfo::markDerivedFrom(const ItemInfo& ancestor) 0148 { 0149 if (!m_data || ancestor.isNull()) 0150 { 0151 return; 0152 } 0153 0154 CoreDbAccess().db()->addImageRelation(m_data->id, ancestor.id(), DatabaseRelation::DerivedFrom); 0155 } 0156 0157 } // namespace Digikam