File indexing completed on 2025-01-05 03:51:26

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2015-07-18
0007  * Description : DNG Raw Converter batch tool.
0008  *
0009  * SPDX-FileCopyrightText: 2015-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 "converttodng.h"
0016 
0017 // Qt includes
0018 
0019 #include <QFileInfo>
0020 #include <QWidget>
0021 
0022 // KDE includes
0023 
0024 #include <klocalizedstring.h>
0025 
0026 // Local includes
0027 
0028 #include "dinfointerface.h"
0029 #include "dpluginbqm.h"
0030 
0031 namespace DigikamBqmConvertToDngPlugin
0032 {
0033 
0034 ConvertToDNG::ConvertToDNG(QObject* const parent)
0035     : BatchTool(QLatin1String("ConvertToDNG"), ConvertTool, parent),
0036       m_changeSettings(true)
0037 {
0038 }
0039 
0040 ConvertToDNG::~ConvertToDNG()
0041 {
0042 }
0043 
0044 BatchTool* ConvertToDNG::clone(QObject* const parent) const
0045 {
0046     return new ConvertToDNG(parent);
0047 }
0048 
0049 void ConvertToDNG::registerSettingsWidget()
0050 {
0051     DNGSettings* const DNGBox = new DNGSettings;
0052 
0053     connect(DNGBox, SIGNAL(signalSettingsChanged()),
0054             this, SLOT(slotSettingsChanged()));
0055 
0056     connect(DNGBox, SIGNAL(signalSetupExifTool()),
0057             this, SLOT(slotSetupExifTool()));
0058 
0059     m_settingsWidget = DNGBox;
0060 
0061     BatchTool::registerSettingsWidget();
0062 }
0063 
0064 BatchToolSettings ConvertToDNG::defaultSettings()
0065 {
0066     BatchToolSettings settings;
0067     settings.insert(QLatin1String("CompressLossLess"),      true);
0068     settings.insert(QLatin1String("PreviewMode"),           DNGWriter::FULL_SIZE);
0069     settings.insert(QLatin1String("BackupOriginalRawFile"), false);
0070 
0071     return settings;
0072 }
0073 
0074 void ConvertToDNG::slotAssignSettings2Widget()
0075 {
0076     m_changeSettings          = false;
0077     DNGSettings* const DNGBox = dynamic_cast<DNGSettings*>(m_settingsWidget);
0078 
0079     if (DNGBox)
0080     {
0081         DNGBox->setCompressLossLess(settings()[QLatin1String("CompressLossLess")].toBool());
0082         DNGBox->setPreviewMode(settings()[QLatin1String("PreviewMode")].toInt());
0083         DNGBox->setBackupOriginalRawFile(settings()[QLatin1String("BackupOriginalRawFile")].toBool());
0084     }
0085 
0086     m_changeSettings          = true;
0087 }
0088 
0089 void ConvertToDNG::slotSettingsChanged()
0090 {
0091     if (m_changeSettings)
0092     {
0093         BatchToolSettings settings;
0094         DNGSettings* const DNGBox = dynamic_cast<DNGSettings*>(m_settingsWidget);
0095 
0096         if (DNGBox)
0097         {
0098             settings.insert(QLatin1String("CompressLossLess"),      DNGBox->compressLossLess());
0099             settings.insert(QLatin1String("PreviewMode"),           DNGBox->previewMode());
0100             settings.insert(QLatin1String("BackupOriginalRawFile"), DNGBox->backupOriginalRawFile());
0101             BatchTool::slotSettingsChanged(settings);
0102         }
0103     }
0104 }
0105 
0106 void ConvertToDNG::slotSetupExifTool()
0107 {
0108     DInfoInterface* const iface = plugin()->infoIface();
0109 
0110     if (iface)
0111     {
0112         DNGSettings* const DNGBox = dynamic_cast<DNGSettings*>(m_settingsWidget);
0113 
0114         if (DNGBox)
0115         {
0116             connect(iface, SIGNAL(signalSetupChanged()),
0117                     DNGBox, SLOT(slotSetupChanged()));
0118         }
0119 
0120         iface->openSetupPage(DInfoInterface::ExifToolPage);
0121     }
0122 }
0123 
0124 QString ConvertToDNG::outputSuffix() const
0125 {
0126     return QLatin1String("dng");
0127 }
0128 
0129 void ConvertToDNG::cancel()
0130 {
0131     m_dngProcessor.cancel();
0132     BatchTool::cancel();
0133 }
0134 
0135 bool ConvertToDNG::toolOperations()
0136 {
0137     if (!isRawFile(inputUrl()))
0138     {
0139         return false;
0140     }
0141 
0142     m_dngProcessor.reset();
0143     m_dngProcessor.setInputFile(inputUrl().toLocalFile());
0144     m_dngProcessor.setOutputFile(outputUrl().toLocalFile());
0145     m_dngProcessor.setBackupOriginalRawFile(settings()[QLatin1String("BackupOriginalRawFile")].toBool());
0146     m_dngProcessor.setCompressLossLess(settings()[QLatin1String("CompressLossLess")].toBool());
0147     m_dngProcessor.setPreviewMode(settings()[QLatin1String("PreviewMode")].toInt());
0148 
0149     int ret = m_dngProcessor.convert();
0150 
0151     return (ret == DNGWriter::PROCESS_COMPLETE);
0152 }
0153 
0154 } // namespace DigikamBqmConvertToDngPlugin
0155 
0156 #include "moc_converttodng.cpp"