File indexing completed on 2025-01-19 03:51:29

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-09-24
0007  * Description : DNG Converter threads manager
0008  *
0009  * SPDX-FileCopyrightText: 2012      by Smit Mehta <smit dot meh at gmail dot com>
0010  * SPDX-FileCopyrightText: 2008-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 "dngconverterthread.h"
0017 
0018 // KDE includes
0019 
0020 #include <klocalizedstring.h>
0021 
0022 // Local includes
0023 
0024 #include "drawinfo.h"
0025 #include "drawdecoder.h"
0026 #include "dngconvertertask.h"
0027 #include "dmetadata.h"
0028 #include "digikam_debug.h"
0029 
0030 namespace DigikamGenericDNGConverterPlugin
0031 {
0032 
0033 class DNGConverterActionThread::Private
0034 {
0035 public:
0036 
0037     Private()
0038       : backupOriginalRawFile(false),
0039         compressLossLess     (true),
0040         updateFileDate       (false),
0041         previewMode          (DNGWriter::FULL_SIZE)
0042     {
0043     }
0044 
0045     bool backupOriginalRawFile;
0046     bool compressLossLess;
0047     bool updateFileDate;
0048     int  previewMode;
0049 };
0050 
0051 DNGConverterActionThread::DNGConverterActionThread(QObject* const parent)
0052     : ActionThreadBase(parent),
0053       d               (new Private)
0054 {
0055     qRegisterMetaType<DNGConverterActionData>();
0056 }
0057 
0058 DNGConverterActionThread::~DNGConverterActionThread()
0059 {
0060     // cancel the thread
0061 
0062     cancel();
0063 
0064     // wait for the thread to finish
0065 
0066     wait();
0067 
0068     delete d;
0069 }
0070 
0071 void DNGConverterActionThread::setBackupOriginalRawFile(bool b)
0072 {
0073     d->backupOriginalRawFile = b;
0074 }
0075 
0076 void DNGConverterActionThread::setCompressLossLess(bool b)
0077 {
0078     d->compressLossLess = b;
0079 }
0080 
0081 void DNGConverterActionThread::setUpdateFileDate(bool b)
0082 {
0083     d->updateFileDate = b;
0084 }
0085 
0086 void DNGConverterActionThread::setPreviewMode(int mode)
0087 {
0088     d->previewMode = mode;
0089 }
0090 
0091 void DNGConverterActionThread::processRawFile(const QUrl& url)
0092 {
0093     QList<QUrl> oneFile;
0094     oneFile.append(url);
0095     processRawFiles(oneFile);
0096 }
0097 
0098 void DNGConverterActionThread::identifyRawFile(const QUrl& url)
0099 {
0100     QList<QUrl> oneFile;
0101     oneFile.append(url);
0102     identifyRawFiles(oneFile);
0103 }
0104 
0105 void DNGConverterActionThread::identifyRawFiles(const QList<QUrl>& urlList)
0106 {
0107     ActionJobCollection collection;
0108 
0109     for (QList<QUrl>::const_iterator it = urlList.constBegin() ; it != urlList.constEnd() ; ++it)
0110     {
0111         DNGConverterTask* const t = new DNGConverterTask(this, *it, IDENTIFY);
0112         t->setBackupOriginalRawFile(d->backupOriginalRawFile);
0113         t->setCompressLossLess(d->compressLossLess);
0114         t->setUpdateFileDate(d->updateFileDate);
0115         t->setPreviewMode(d->previewMode);
0116 
0117         connect(t, SIGNAL(signalStarting(DigikamGenericDNGConverterPlugin::DNGConverterActionData)),
0118                 this, SIGNAL(signalStarting(DigikamGenericDNGConverterPlugin::DNGConverterActionData)));
0119 
0120         connect(t, SIGNAL(signalFinished(DigikamGenericDNGConverterPlugin::DNGConverterActionData)),
0121                 this, SIGNAL(signalFinished(DigikamGenericDNGConverterPlugin::DNGConverterActionData)));
0122 
0123         connect(this, SIGNAL(signalCancelDNGConverterTask()),
0124                 t, SLOT(slotCancel()), Qt::QueuedConnection);
0125 
0126         collection.insert(t, 0);
0127     }
0128 
0129     appendJobs(collection);
0130 }
0131 
0132 void DNGConverterActionThread::processRawFiles(const QList<QUrl>& urlList)
0133 {
0134     ActionJobCollection collection;
0135 
0136     for (QList<QUrl>::const_iterator it = urlList.constBegin() ; it != urlList.constEnd() ; ++it)
0137     {
0138         DNGConverterTask* const t = new DNGConverterTask(this, *it, PROCESS);
0139         t->setBackupOriginalRawFile(d->backupOriginalRawFile);
0140         t->setCompressLossLess(d->compressLossLess);
0141         t->setUpdateFileDate(d->updateFileDate);
0142         t->setPreviewMode(d->previewMode);
0143 
0144         connect(t, SIGNAL(signalStarting(DigikamGenericDNGConverterPlugin::DNGConverterActionData)),
0145                 this, SIGNAL(signalStarting(DigikamGenericDNGConverterPlugin::DNGConverterActionData)));
0146 
0147         connect(t, SIGNAL(signalFinished(DigikamGenericDNGConverterPlugin::DNGConverterActionData)),
0148                 this, SIGNAL(signalFinished(DigikamGenericDNGConverterPlugin::DNGConverterActionData)));
0149 
0150         connect(this, SIGNAL(signalCancelDNGConverterTask()),
0151                 t, SLOT(slotCancel()), Qt::QueuedConnection);
0152 
0153         collection.insert(t, 0);
0154     }
0155 
0156     appendJobs(collection);
0157 }
0158 
0159 void DNGConverterActionThread::cancel()
0160 {
0161     if (isRunning())
0162     {
0163         Q_EMIT signalCancelDNGConverterTask();
0164     }
0165 
0166     ActionThreadBase::cancel();
0167 }
0168 
0169 }  // namespace DigikamGenericDNGConverterPlugin
0170 
0171 #include "moc_dngconverterthread.cpp"