File indexing completed on 2025-01-19 03:56:03

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2020-11-28
0007  * Description : ExifTool process stream parser.
0008  *
0009  * SPDX-FileCopyrightText: 2020-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "exiftoolparser_p.h"
0016 
0017 namespace Digikam
0018 {
0019 
0020 ExifToolParser::ExifToolParser(QObject* const parent, bool async)
0021     : QObject(parent),
0022       d      (new Private(this))
0023 {
0024     // For handling the unit-test tools.
0025 
0026     if (!ExifToolProcess::isCreated())
0027     {
0028         QEventLoop loop;
0029         ExifToolThread* const exifToolThread = new ExifToolThread(qApp);
0030 
0031         connect(exifToolThread, &ExifToolThread::exifToolProcessStarted,
0032                 &loop, &QEventLoop::quit);
0033 
0034         exifToolThread->start();
0035         loop.exec();
0036     }
0037 
0038     // Get ExifTool process instance.
0039 
0040     d->proc  = ExifToolProcess::instance();
0041     d->async = async;
0042 
0043     if (d->async)
0044     {
0045         connect(d->proc, &ExifToolProcess::signalExifToolResult,
0046                 this, &ExifToolParser::slotExifToolResult,
0047                 Qt::QueuedConnection);
0048     }
0049 }
0050 
0051 ExifToolParser::~ExifToolParser()
0052 {
0053     delete d;
0054 }
0055 
0056 void ExifToolParser::setExifToolProgram(const QString& path)
0057 {
0058     d->proc->setExifToolProgram(path);
0059 }
0060 
0061 QString ExifToolParser::currentPath() const
0062 {
0063     return d->currentPath;
0064 }
0065 
0066 ExifToolParser::ExifToolData ExifToolParser::currentData() const
0067 {
0068     return d->exifToolData;
0069 }
0070 
0071 QString ExifToolParser::currentErrorString() const
0072 {
0073     if (!d->errorString.isEmpty())
0074     {
0075         return d->errorString;
0076     }
0077 
0078     return d->proc->exifToolErrorString();
0079 }
0080 
0081 bool ExifToolParser::exifToolAvailable() const
0082 {
0083     bool ret = d->proc->exifToolAvailable();
0084 
0085     qCDebug(DIGIKAM_METAENGINE_LOG) << "Check ExifTool availability:" << ret;
0086 
0087     return ret;
0088 }
0089 
0090 MetaEngine::TagsMap ExifToolParser::tagsDbToOrderedMap(const ExifToolData& tagsDb)
0091 {
0092     QString name;
0093     QString desc;
0094     MetaEngine::TagsMap map;
0095     QStringList keys = tagsDb.keys();
0096     keys.sort();
0097 
0098     Q_FOREACH (const QString& tag, keys)
0099     {
0100         /**
0101          * Tag are formatted like this:
0102          *
0103          * EXIF.IFD0.Image.XResolution
0104          * EXIF.IFD0.Image.YCbCrCoefficients
0105          * EXIF.IFD0.Image.YCbCrPositioning
0106          * EXIF.IFD0.Image.YCbCrSubSampling
0107          * EXIF.IFD0.Image.YClipPathUnits
0108          * EXIF.IFD0.Image.YPosition
0109          * EXIF.IFD0.Image.YResolution
0110          * FITS.FITS.Image.Author
0111          * FITS.FITS.Image.Background
0112          * FITS.FITS.Image.CreateDate
0113          * FITS.FITS.Image.Instrument
0114          * FITS.FITS.Image.Object
0115          * FITS.FITS.Image.ObservationDate
0116          */
0117         ExifToolParser::ExifToolData::const_iterator it = tagsDb.find(tag);
0118 
0119         if (it != tagsDb.constEnd())
0120         {
0121             name = tag.section(QLatin1Char('.'), -1);
0122             desc = it.value()[0].toString();
0123 
0124             map.insert(tag, QStringList() << name
0125                                           << QString()  // title.
0126                                           << desc);
0127         }
0128     }
0129 
0130     return map;
0131 }
0132 
0133 } // namespace Digikam
0134 
0135 #include "moc_exiftoolparser.cpp"