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 - Containers 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 ImageCommonContainer ItemInfo::imageCommonContainer() const 0024 { 0025 if (!m_data) 0026 { 0027 return ImageCommonContainer(); 0028 } 0029 0030 ImageCommonContainer container; 0031 ItemScanner::fillCommonContainer(m_data->id, &container); 0032 0033 return container; 0034 } 0035 0036 ImageMetadataContainer ItemInfo::imageMetadataContainer() const 0037 { 0038 if (!m_data) 0039 { 0040 return ImageMetadataContainer(); 0041 } 0042 0043 ImageMetadataContainer container; 0044 const DatabaseFieldsHashRaw rawVideoMetadata = getDatabaseFieldsRaw(DatabaseFields::Set(DatabaseFields::ImageMetadataAll)); 0045 bool allFieldsNull = true; 0046 0047 for (DatabaseFields::ImageMetadataIterator it ; !it.atEnd() ; ++it) 0048 { 0049 const QVariant fieldValue = rawVideoMetadata.value(*it); 0050 0051 allFieldsNull &= fieldValue.isNull(); 0052 0053 if (!fieldValue.isNull()) 0054 { 0055 const MetadataInfo::Field mdField = DatabaseImageMetadataFieldsToMetadataInfoField(*it); 0056 const QString fieldString = DMetadata::valueToString(fieldValue, mdField); 0057 0058 switch (*it) 0059 { 0060 case DatabaseFields::Make: 0061 { 0062 container.make = fieldString; 0063 break; 0064 } 0065 0066 case DatabaseFields::Model: 0067 { 0068 container.model = fieldString; 0069 break; 0070 } 0071 0072 case DatabaseFields::Lens: 0073 { 0074 container.lens = fieldString; 0075 break; 0076 } 0077 0078 case DatabaseFields::Aperture: 0079 { 0080 container.aperture = fieldString; 0081 break; 0082 } 0083 0084 case DatabaseFields::FocalLength: 0085 { 0086 container.focalLength = fieldString; 0087 break; 0088 } 0089 0090 case DatabaseFields::FocalLength35: 0091 { 0092 container.focalLength35 = fieldString; 0093 break; 0094 } 0095 0096 case DatabaseFields::ExposureTime: 0097 { 0098 container.exposureTime = fieldString; 0099 break; 0100 } 0101 0102 case DatabaseFields::ExposureProgram: 0103 { 0104 container.exposureProgram = fieldString; 0105 break; 0106 } 0107 0108 case DatabaseFields::ExposureMode: 0109 { 0110 container.exposureMode = fieldString; 0111 break; 0112 } 0113 0114 case DatabaseFields::Sensitivity: 0115 { 0116 container.sensitivity = fieldString; 0117 break; 0118 } 0119 0120 case DatabaseFields::FlashMode: 0121 { 0122 container.flashMode = fieldString; 0123 break; 0124 } 0125 0126 case DatabaseFields::WhiteBalance: 0127 { 0128 container.whiteBalance = fieldString; 0129 break; 0130 } 0131 0132 case DatabaseFields::WhiteBalanceColorTemperature: 0133 { 0134 container.whiteBalanceColorTemperature = fieldString; 0135 break; 0136 } 0137 0138 case DatabaseFields::SubjectDistance: 0139 { 0140 container.subjectDistance = fieldString; 0141 break; 0142 } 0143 0144 case DatabaseFields::SubjectDistanceCategory: 0145 { 0146 container.subjectDistanceCategory = fieldString; 0147 break; 0148 } 0149 0150 default: 0151 { 0152 break; 0153 } 0154 } 0155 } 0156 } 0157 0158 // store whether we have at least one valid field 0159 0160 container.allFieldsNull = allFieldsNull; 0161 0162 return container; 0163 } 0164 0165 VideoMetadataContainer ItemInfo::videoMetadataContainer() const 0166 { 0167 if (!m_data) 0168 { 0169 return VideoMetadataContainer(); 0170 } 0171 0172 VideoMetadataContainer container; 0173 const DatabaseFieldsHashRaw rawVideoMetadata = getDatabaseFieldsRaw(DatabaseFields::Set(DatabaseFields::VideoMetadataAll)); 0174 bool allFieldsNull = true; 0175 0176 for (DatabaseFields::VideoMetadataIterator it ; !it.atEnd() ; ++it) 0177 { 0178 const QVariant fieldValue = rawVideoMetadata.value(*it); 0179 0180 allFieldsNull &= fieldValue.isNull(); 0181 0182 if (!fieldValue.isNull()) 0183 { 0184 const MetadataInfo::Field mdField = DatabaseVideoMetadataFieldsToMetadataInfoField(*it); 0185 const QString fieldString = DMetadata::valueToString(fieldValue, mdField); 0186 0187 switch (*it) 0188 { 0189 case DatabaseFields::AspectRatio: 0190 { 0191 container.aspectRatio = fieldString; 0192 break; 0193 } 0194 0195 case DatabaseFields::AudioBitRate: 0196 { 0197 container.audioBitRate = fieldString; 0198 break; 0199 } 0200 0201 case DatabaseFields::AudioChannelType: 0202 { 0203 container.audioChannelType = fieldString; 0204 break; 0205 } 0206 0207 case DatabaseFields::AudioCodec: 0208 { 0209 container.audioCodec = fieldString; 0210 break; 0211 } 0212 0213 case DatabaseFields::Duration: 0214 { 0215 container.duration = fieldString; 0216 break; 0217 } 0218 0219 case DatabaseFields::FrameRate: 0220 { 0221 container.frameRate = fieldString; 0222 break; 0223 } 0224 0225 case DatabaseFields::VideoCodec: 0226 { 0227 container.videoCodec = fieldString; 0228 break; 0229 } 0230 0231 default: 0232 { 0233 break; 0234 } 0235 } 0236 } 0237 } 0238 0239 // store whether we have at least one valid field 0240 0241 container.allFieldsNull = allFieldsNull; 0242 0243 return container; 0244 } 0245 0246 PhotoInfoContainer ItemInfo::photoInfoContainer() const 0247 { 0248 if (!m_data) 0249 { 0250 return PhotoInfoContainer(); 0251 } 0252 0253 ImageMetadataContainer meta = imageMetadataContainer(); 0254 PhotoInfoContainer photoInfo; 0255 0256 photoInfo.make = meta.make; 0257 photoInfo.model = meta.model; 0258 photoInfo.lens = meta.lens; 0259 photoInfo.exposureTime = meta.exposureTime; 0260 photoInfo.exposureMode = meta.exposureMode; 0261 photoInfo.exposureProgram = meta.exposureProgram; 0262 photoInfo.aperture = meta.aperture; 0263 photoInfo.focalLength = meta.focalLength; 0264 photoInfo.focalLength35mm = meta.focalLength35; 0265 photoInfo.sensitivity = meta.sensitivity; 0266 photoInfo.flash = meta.flashMode; 0267 photoInfo.whiteBalance = meta.whiteBalance; 0268 photoInfo.dateTime = dateTime(); 0269 0270 return photoInfo; 0271 } 0272 0273 VideoInfoContainer ItemInfo::videoInfoContainer() const 0274 { 0275 if (!m_data) 0276 { 0277 return VideoInfoContainer(); 0278 } 0279 0280 VideoMetadataContainer meta = videoMetadataContainer(); 0281 VideoInfoContainer videoInfo; 0282 0283 videoInfo.aspectRatio = meta.aspectRatio; 0284 videoInfo.audioBitRate = meta.audioBitRate; 0285 videoInfo.audioChannelType = meta.audioChannelType; 0286 videoInfo.audioCodec = meta.audioCodec; 0287 videoInfo.duration = meta.duration; 0288 videoInfo.frameRate = meta.frameRate; 0289 videoInfo.videoCodec = meta.videoCodec; 0290 0291 return videoInfo; 0292 } 0293 0294 Template ItemInfo::metadataTemplate() const 0295 { 0296 if (!m_data) 0297 { 0298 return Template(); 0299 } 0300 0301 Template t; 0302 0303 ItemCopyright ic = imageCopyright(); 0304 ic.fillTemplate(t); 0305 0306 ItemExtendedProperties ep = imageExtendedProperties(); 0307 t.setLocationInfo(ep.location()); 0308 t.setIptcSubjects(ep.subjectCode()); 0309 0310 return t; 0311 } 0312 0313 void ItemInfo::setMetadataTemplate(const Template& t) 0314 { 0315 if (!m_data) 0316 { 0317 return; 0318 } 0319 0320 removeMetadataTemplate(); 0321 0322 ItemCopyright ic = imageCopyright(); 0323 ic.setFromTemplate(t); 0324 0325 ItemExtendedProperties ep = imageExtendedProperties(); 0326 ep.setLocation(t.locationInfo()); 0327 ep.setSubjectCode(t.IptcSubjects()); 0328 } 0329 0330 void ItemInfo::removeMetadataTemplate() 0331 { 0332 if (!m_data) 0333 { 0334 return; 0335 } 0336 0337 ItemCopyright ic = imageCopyright(); 0338 ic.removeAll(); 0339 0340 ItemExtendedProperties ep = imageExtendedProperties(); 0341 ep.removeLocation(); 0342 ep.removeSubjectCode(); 0343 } 0344 0345 ItemComments ItemInfo::imageComments(const CoreDbAccess& access) const 0346 { 0347 if (!m_data) 0348 { 0349 return ItemComments(); 0350 } 0351 0352 return ItemComments(access, m_data->id); 0353 } 0354 0355 ItemCopyright ItemInfo::imageCopyright() const 0356 { 0357 if (!m_data) 0358 { 0359 return ItemCopyright(); 0360 } 0361 0362 return ItemCopyright(m_data->id); 0363 } 0364 0365 ItemExtendedProperties ItemInfo::imageExtendedProperties() const 0366 { 0367 if (!m_data) 0368 { 0369 return ItemExtendedProperties(); 0370 } 0371 0372 return ItemExtendedProperties(m_data->id); 0373 } 0374 0375 } // namespace Digikam