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 : 2012-12-24 0007 * Description : DNG Converter thread 0008 * 0009 * SPDX-FileCopyrightText: 2012 by Smit Mehta <smit dot meh at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "dngconvertertask.h" 0016 0017 // Qt includes 0018 0019 #include <QFileInfo> 0020 0021 // KDE includes 0022 0023 #include <klocalizedstring.h> 0024 0025 // Local includes 0026 0027 #include "drawinfo.h" 0028 #include "drawdecoder.h" 0029 #include "dmetadata.h" 0030 #include "digikam_debug.h" 0031 0032 namespace DigikamGenericDNGConverterPlugin 0033 { 0034 0035 class DNGConverterTask::Private 0036 { 0037 public: 0038 0039 Private() 0040 : backupOriginalRawFile(false), 0041 compressLossLess (true), 0042 updateFileDate (false), 0043 cancel (false), 0044 previewMode (DNGWriter::FULL_SIZE), 0045 action (NONE) 0046 { 0047 } 0048 0049 bool backupOriginalRawFile; 0050 bool compressLossLess; 0051 bool updateFileDate; 0052 bool cancel; 0053 0054 int previewMode; 0055 0056 QUrl url; 0057 DNGConverterAction action; 0058 0059 DNGWriter dngProcessor; 0060 }; 0061 0062 DNGConverterTask::DNGConverterTask(QObject* const parent, const QUrl& fileUrl, const DNGConverterAction& action) 0063 : ActionJob(parent), 0064 d (new Private) 0065 { 0066 d->url = fileUrl; 0067 d->action = action; 0068 } 0069 0070 DNGConverterTask::~DNGConverterTask() 0071 { 0072 slotCancel(); 0073 delete d; 0074 } 0075 0076 void DNGConverterTask::setBackupOriginalRawFile(bool b) 0077 { 0078 d->backupOriginalRawFile = b; 0079 } 0080 0081 void DNGConverterTask::setCompressLossLess(bool b) 0082 { 0083 d->compressLossLess = b; 0084 } 0085 0086 void DNGConverterTask::setUpdateFileDate(bool b) 0087 { 0088 d->updateFileDate = b; 0089 } 0090 0091 void DNGConverterTask::setPreviewMode(int mode) 0092 { 0093 d->previewMode = mode; 0094 } 0095 0096 void DNGConverterTask::run() 0097 { 0098 if (d->cancel) 0099 { 0100 return; 0101 } 0102 0103 switch (d->action) 0104 { 0105 case IDENTIFY: 0106 { 0107 // Identify Camera model. 0108 0109 DRawInfo info; 0110 DRawDecoder::rawFileIdentify(info, d->url.toLocalFile()); 0111 0112 QString identify = i18n("Cannot identify Raw image"); 0113 0114 if (info.isDecodable) 0115 { 0116 identify = info.make + QLatin1String("-") + info.model; 0117 } 0118 0119 DNGConverterActionData ad; 0120 ad.action = d->action; 0121 ad.fileUrl = d->url; 0122 ad.message = identify; 0123 ad.result = DNGWriter::PROCESS_COMPLETE; 0124 Q_EMIT signalFinished(ad); 0125 break; 0126 } 0127 0128 case PROCESS: 0129 { 0130 DNGConverterActionData ad1; 0131 ad1.action = PROCESS; 0132 ad1.fileUrl = d->url; 0133 ad1.starting = true; 0134 Q_EMIT signalStarting(ad1); 0135 0136 QString destPath; 0137 0138 QFileInfo fi(d->url.toLocalFile()); 0139 destPath = fi.absolutePath() + QLatin1String("/.digikam-dngconverter-tmp-") + 0140 QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch()) + QString(d->url.fileName()); 0141 0142 d->dngProcessor.reset(); 0143 d->dngProcessor.setInputFile(d->url.toLocalFile()); 0144 d->dngProcessor.setOutputFile(destPath); 0145 d->dngProcessor.setBackupOriginalRawFile(d->backupOriginalRawFile); 0146 d->dngProcessor.setCompressLossLess(d->compressLossLess); 0147 d->dngProcessor.setUpdateFileDate(d->updateFileDate); 0148 d->dngProcessor.setPreviewMode(d->previewMode); 0149 int ret = d->dngProcessor.convert(); 0150 0151 DNGConverterActionData ad2; 0152 ad2.action = PROCESS; 0153 ad2.fileUrl = d->url; 0154 ad2.destPath = destPath; 0155 ad2.result = ret; 0156 Q_EMIT signalFinished(ad2); 0157 break; 0158 } 0159 0160 default: 0161 { 0162 qCCritical(DIGIKAM_DPLUGIN_GENERIC_LOG) << "Unknown action specified"; 0163 break; 0164 } 0165 } 0166 0167 Q_EMIT signalDone(); 0168 } 0169 0170 void DNGConverterTask::slotCancel() 0171 { 0172 d->cancel = true; 0173 d->dngProcessor.cancel(); 0174 } 0175 0176 } // namespace DigikamGenericDNGConverterPlugin 0177 0178 0179 #include "moc_dngconvertertask.cpp"