File indexing completed on 2025-01-19 03:55:35

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-05-06
0007  * Description : abstract interface to image information.
0008  *               This class do not depend of digiKam database library
0009  *               to permit to re-use plugins with Showfoto.
0010  *
0011  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  * SPDX-FileCopyrightText: 2019-2020 by Minh Nghia Duong <minhnghiaduong997 at gmail dot com>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #include "dinfointerface.h"
0019 
0020 // Qt includes
0021 
0022 #include <QtGlobal>
0023 
0024 // Local includes
0025 
0026 #include "digikam_globals.h"
0027 #include "digikam_debug.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 DInfoInterface::DInfoInterface(QObject* const parent)
0033     : QObject(parent)
0034 {
0035 }
0036 
0037 DInfoInterface::~DInfoInterface()
0038 {
0039 }
0040 
0041 void DInfoInterface::slotDateTimeForUrl(const QUrl& /*url*/, const QDateTime& /*dt*/, bool /*updModDate*/)
0042 {
0043 }
0044 
0045 void DInfoInterface::slotMetadataChangedForUrl(const QUrl& /*url*/)
0046 {
0047 }
0048 
0049 void DInfoInterface::parseAlbumItemsRecursive()
0050 {
0051 }
0052 
0053 QList<QUrl> DInfoInterface::currentSelectedItems() const
0054 {
0055     return QList<QUrl>();
0056 }
0057 
0058 QList<QUrl> DInfoInterface::currentAlbumItems() const
0059 {
0060     return QList<QUrl>();
0061 }
0062 
0063 QList<QUrl> DInfoInterface::allAlbumItems() const
0064 {
0065     return QList<QUrl>();
0066 }
0067 
0068 DInfoInterface::DInfoMap DInfoInterface::itemInfo(const QUrl&) const
0069 {
0070     return DInfoMap();
0071 }
0072 
0073 void DInfoInterface::setItemInfo(const QUrl&, const DInfoMap&)
0074 {
0075     qCWarning(DIGIKAM_GENERAL_LOG) << "setItemInfo() not implemented in host interface";
0076 }
0077 
0078 QList<QUrl> DInfoInterface::albumItems(int) const
0079 {
0080     return QList<QUrl>();
0081 }
0082 
0083 QList<QUrl> DInfoInterface::albumsItems(const DAlbumIDs&) const
0084 {
0085     return QList<QUrl>();
0086 }
0087 
0088 DInfoInterface::DInfoMap DInfoInterface::albumInfo(int) const
0089 {
0090     return DInfoMap();
0091 }
0092 
0093 void DInfoInterface::setAlbumInfo(int, const DInfoMap&) const
0094 {
0095     qCWarning(DIGIKAM_GENERAL_LOG) << "setAlbumInfo() not implemented in host interface";
0096 }
0097 
0098 QWidget* DInfoInterface::albumChooser(QWidget* const) const
0099 {
0100     return nullptr;
0101 }
0102 
0103 DInfoInterface::DAlbumIDs DInfoInterface::albumChooserItems() const
0104 {
0105     return DAlbumIDs();
0106 }
0107 
0108 bool DInfoInterface::supportAlbums() const
0109 {
0110     return false;
0111 }
0112 
0113 QWidget* DInfoInterface::uploadWidget(QWidget* const) const
0114 {
0115     return nullptr;
0116 }
0117 
0118 QUrl DInfoInterface::uploadUrl() const
0119 {
0120     return QUrl();
0121 }
0122 
0123 QUrl DInfoInterface::defaultUploadUrl() const
0124 {
0125     return QUrl();
0126 }
0127 
0128 QAbstractItemModel* DInfoInterface::tagFilterModel()
0129 {
0130     return nullptr;
0131 }
0132 
0133 #ifdef HAVE_GEOLOCATION
0134 
0135 QList<GPSItemContainer*> DInfoInterface::currentGPSItems() const
0136 {
0137     return QList<GPSItemContainer*>();
0138 }
0139 
0140 #endif
0141 
0142 QMap<QString, QString> DInfoInterface::passShortcutActionsToWidget(QWidget* const) const
0143 {
0144     return QMap<QString, QString>();
0145 }
0146 
0147 void DInfoInterface::deleteImage(const QUrl&)
0148 {
0149 }
0150 
0151 void DInfoInterface::openSetupPage(SetupPage)
0152 {
0153 }
0154 
0155 // -----------------------------------------------------------------
0156 
0157 DItemInfo::DItemInfo()
0158 {
0159 }
0160 
0161 DItemInfo::DItemInfo(const DInfoInterface::DInfoMap& info)
0162     : m_info(info)
0163 {
0164 /*
0165     qCDebug(DIGIKAM_GENERAL_LOG) << m_info;
0166 */
0167 }
0168 
0169 DItemInfo::~DItemInfo()
0170 {
0171 }
0172 
0173 DInfoInterface::DInfoMap DItemInfo::infoMap() const
0174 {
0175     return m_info;
0176 }
0177 
0178 QVariant DItemInfo::parseInfoMap(const QString& key) const
0179 {
0180     QVariant ret;
0181     DInfoInterface::DInfoMap::const_iterator it = m_info.find(key);
0182 
0183     if (it != m_info.end())
0184     {
0185         ret = it.value();
0186     }
0187 
0188     return ret;
0189 }
0190 
0191 QString DItemInfo::name() const
0192 {
0193     QVariant val = parseInfoMap(QLatin1String("name"));
0194 
0195     return (!val.isNull() ? val.toString() : QString());
0196 }
0197 
0198 QString DItemInfo::comment() const
0199 {
0200     QVariant val = parseInfoMap(QLatin1String("comment"));
0201 
0202     return (!val.isNull() ? val.toString() : QString());
0203 }
0204 
0205 QString DItemInfo::title() const
0206 {
0207     QVariant val = parseInfoMap(QLatin1String("title"));
0208 
0209     return (!val.isNull() ? val.toString() : QString());
0210 }
0211 
0212 QSize DItemInfo::dimensions() const
0213 {
0214     QVariant val = parseInfoMap(QLatin1String("dimensions"));
0215 
0216     return (!val.isNull() ? val.toSize() : QSize());
0217 }
0218 
0219 QDateTime DItemInfo::dateTime() const
0220 {
0221     QVariant val = parseInfoMap(QLatin1String("datetime"));
0222 
0223     return (!val.isNull() ? val.toDateTime() : QDateTime());
0224 }
0225 
0226 QStringList DItemInfo::keywords() const
0227 {
0228     QVariant val = parseInfoMap(QLatin1String("keywords"));
0229 
0230     return (!val.isNull() ? val.toStringList() : QStringList());
0231 }
0232 
0233 QStringList DItemInfo::tagsPath() const
0234 {
0235     QVariant val = parseInfoMap(QLatin1String("tagspath"));
0236 
0237     return (!val.isNull() ? val.toStringList() : QStringList());
0238 }
0239 
0240 int DItemInfo::albumId() const
0241 {
0242     QVariant val = parseInfoMap(QLatin1String("albumid"));
0243 
0244     return (!val.isNull() ? val.toInt() : -1);
0245 }
0246 
0247 int DItemInfo::orientation() const
0248 {
0249     QVariant val = parseInfoMap(QLatin1String("orientation"));
0250 
0251     return (!val.isNull() ? val.toInt() : MetaEngine::ORIENTATION_UNSPECIFIED);
0252 }
0253 
0254 void DItemInfo::setOrientation(int val)
0255 {
0256     m_info.insert(QLatin1String("orientation"), val);
0257 }
0258 
0259 int DItemInfo::rating() const
0260 {
0261     QVariant val = parseInfoMap(QLatin1String("rating"));
0262 
0263     return (!val.isNull() ? val.toInt() : RatingMin);
0264 }
0265 
0266 void DItemInfo::setRating(int rating)
0267 {
0268     m_info.insert(QLatin1String("rating"), rating);
0269 }
0270 
0271 int DItemInfo::colorLabel() const
0272 {
0273     QVariant val = parseInfoMap(QLatin1String("colorlabel"));
0274 
0275     return (!val.isNull() ? val.toInt() : NoColorLabel);
0276 }
0277 
0278 void DItemInfo::setColorLabel(int color)
0279 {
0280     m_info.insert(QLatin1String("colorlabel"), color);
0281 }
0282 
0283 int DItemInfo::pickLabel() const
0284 {
0285     QVariant val = parseInfoMap(QLatin1String("picklabel"));
0286 
0287     return (!val.isNull() ? val.toInt() : NoPickLabel);
0288 }
0289 
0290 void DItemInfo::setPickLabel(int pick)
0291 {
0292     m_info.insert(QLatin1String("picklabel"), pick);
0293 }
0294 
0295 double DItemInfo::latitude() const
0296 {
0297     QVariant val = parseInfoMap(QLatin1String("latitude"));
0298 
0299     return (!val.isNull() ? val.toDouble() : qQNaN());
0300 }
0301 
0302 double DItemInfo::longitude() const
0303 {
0304     QVariant val = parseInfoMap(QLatin1String("longitude"));
0305 
0306     return (!val.isNull() ? val.toDouble() : qQNaN());
0307 }
0308 
0309 double DItemInfo::altitude() const
0310 {
0311     QVariant val = parseInfoMap(QLatin1String("altitude"));
0312 
0313     return (!val.isNull() ? val.toDouble() : qQNaN());
0314 }
0315 
0316 qlonglong DItemInfo::fileSize() const
0317 {
0318     QVariant val = parseInfoMap(QLatin1String("filesize"));
0319 
0320     return (!val.isNull() ? val.toLongLong() : 0);
0321 }
0322 
0323 QStringList DItemInfo::creators() const
0324 {
0325     QVariant val = parseInfoMap(QLatin1String("creators"));
0326 
0327     return (!val.isNull() ? val.toStringList() : QStringList());
0328 }
0329 
0330 QString DItemInfo::credit() const
0331 {
0332     QVariant val = parseInfoMap(QLatin1String("credit"));
0333 
0334     return (!val.isNull() ? val.toString() : QString());
0335 }
0336 
0337 QString DItemInfo::rights() const
0338 {
0339     QVariant val = parseInfoMap(QLatin1String("rights"));
0340 
0341     return (!val.isNull() ? val.toString() : QString());
0342 }
0343 
0344 QString DItemInfo::source() const
0345 {
0346     QVariant val = parseInfoMap(QLatin1String("source"));
0347 
0348     return (!val.isNull() ? val.toString() : QString());
0349 }
0350 
0351 QString DItemInfo::lens() const
0352 {
0353     QVariant val = parseInfoMap(QLatin1String("lens"));
0354 
0355     return (!val.isNull() ? val.toString() : QString());
0356 }
0357 
0358 QString DItemInfo::make() const
0359 {
0360     QVariant val = parseInfoMap(QLatin1String("make"));
0361 
0362     return (!val.isNull() ? val.toString() : QString());
0363 }
0364 
0365 QString DItemInfo::model() const
0366 {
0367     QVariant val = parseInfoMap(QLatin1String("model"));
0368 
0369     return (!val.isNull() ? val.toString() : QString());
0370 }
0371 
0372 QString DItemInfo::exposureTime() const
0373 {
0374     QVariant val = parseInfoMap(QLatin1String("exposuretime"));
0375 
0376     return (!val.isNull() ? val.toString() : QString());
0377 }
0378 
0379 QString DItemInfo::sensitivity() const
0380 {
0381     QVariant val = parseInfoMap(QLatin1String("sensitivity"));
0382 
0383     return (!val.isNull() ? val.toString() : QString());
0384 }
0385 
0386 QString DItemInfo::aperture() const
0387 {
0388     QVariant val = parseInfoMap(QLatin1String("aperture"));
0389 
0390     return (!val.isNull() ? val.toString() : QString());
0391 }
0392 
0393 QString DItemInfo::focalLength() const
0394 {
0395     QVariant val = parseInfoMap(QLatin1String("focallength"));
0396 
0397     return (!val.isNull() ? val.toString() : QString());
0398 }
0399 
0400 QString DItemInfo::focalLength35mm() const
0401 {
0402     QVariant val = parseInfoMap(QLatin1String("focalLength35mm"));
0403 
0404     return (!val.isNull() ? val.toString() : QString());
0405 }
0406 
0407 QString DItemInfo::videoCodec() const
0408 {
0409     QVariant val = parseInfoMap(QLatin1String("videocodec"));
0410 
0411     return (!val.isNull() ? val.toString() : QString());
0412 }
0413 
0414 bool DItemInfo::hasGeolocationInfo() const
0415 {
0416     // NOTE: GPS position without altitude is a valid geolocation.
0417 
0418     return (!qIsNaN(latitude()) && !qIsNaN(longitude()));
0419 }
0420 
0421 CaptionsMap DItemInfo::titles() const
0422 {
0423     QVariant val = parseInfoMap(QLatin1String("titles"));
0424 
0425     return (!val.isNull() ? qvariant_cast<CaptionsMap>(val) : CaptionsMap());
0426 }
0427 
0428 void DItemInfo::setTitles(const CaptionsMap& map)
0429 {
0430     m_info.insert(QLatin1String("titles"), QVariant::fromValue(map));
0431 }
0432 
0433 CaptionsMap DItemInfo::captions() const
0434 {
0435     QVariant val = parseInfoMap(QLatin1String("captions"));
0436 
0437     return (!val.isNull() ? qvariant_cast<CaptionsMap>(val) : CaptionsMap());
0438 }
0439 
0440 void DItemInfo::setCaptions(const CaptionsMap& map)
0441 {
0442     m_info.insert(QLatin1String("captions"), QVariant::fromValue(map));
0443 }
0444 
0445 MetaEngine::AltLangMap DItemInfo::copyrights() const
0446 {
0447     QVariant val = parseInfoMap(QLatin1String("copyrights"));
0448 
0449     return (!val.isNull() ? qvariant_cast<MetaEngine::AltLangMap>(val) : MetaEngine::AltLangMap());
0450 }
0451 
0452 void DItemInfo::setCopyrights(const MetaEngine::AltLangMap& map)
0453 {
0454     m_info.insert(QLatin1String("copyrights"), QVariant::fromValue(map));
0455 }
0456 
0457 MetaEngine::AltLangMap DItemInfo::copyrightNotices() const
0458 {
0459     QVariant val = parseInfoMap(QLatin1String("copyrightnotices"));
0460 
0461     return (!val.isNull() ? qvariant_cast<MetaEngine::AltLangMap>(val) : MetaEngine::AltLangMap());
0462 }
0463 
0464 void DItemInfo::setCopyrightNotices(const MetaEngine::AltLangMap& map)
0465 {
0466     m_info.insert(QLatin1String("copyrightnotices"), QVariant::fromValue(map));
0467 }
0468 
0469 // -----------------------------------------------------------------
0470 
0471 DAlbumInfo::DAlbumInfo(const DInfoInterface::DInfoMap& info)
0472     : m_info(info)
0473 {
0474 }
0475 
0476 DAlbumInfo::~DAlbumInfo()
0477 {
0478 }
0479 
0480 QString DAlbumInfo::title() const
0481 {
0482     QString ret;
0483     DInfoInterface::DInfoMap::const_iterator it = m_info.find(QLatin1String("title"));
0484 
0485     if (it != m_info.end())
0486     {
0487         ret = it.value().toString();
0488     }
0489 
0490     return ret;
0491 }
0492 
0493 QString DAlbumInfo::caption() const
0494 {
0495     QString ret;
0496     DInfoInterface::DInfoMap::const_iterator it = m_info.find(QLatin1String("caption"));
0497 
0498     if (it != m_info.end())
0499     {
0500         ret = it.value().toString();
0501     }
0502 
0503     return ret;
0504 }
0505 
0506 QDate DAlbumInfo::date() const
0507 {
0508     QDate ret;
0509     DInfoInterface::DInfoMap::const_iterator it = m_info.find(QLatin1String("date"));
0510 
0511     if (it != m_info.end())
0512     {
0513         ret = it.value().toDate();
0514     }
0515 
0516     return ret;
0517 }
0518 
0519 QString DAlbumInfo::path() const
0520 {
0521     QString ret;
0522     DInfoInterface::DInfoMap::const_iterator it = m_info.find(QLatin1String("path"));
0523 
0524     if (it != m_info.end())
0525     {
0526         ret = it.value().toString();
0527     }
0528 
0529     return ret;
0530 }
0531 
0532 QString DAlbumInfo::albumPath() const
0533 {
0534     QString ret;
0535     DInfoInterface::DInfoMap::const_iterator it = m_info.find(QLatin1String("albumpath"));
0536 
0537     if (it != m_info.end())
0538     {
0539         ret = it.value().toString();
0540     }
0541 
0542     return ret;
0543 }
0544 
0545 } // namespace Digikam
0546 
0547 #include "moc_dinfointerface.cpp"