File indexing completed on 2025-01-05 03:59:54

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2016-05-03
0007  * Description : DNG convert settings for camera interface.
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText:      2016 by Maik Qualmann <metzpinguin at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "dngconvertsettings.h"
0017 
0018 // Qt includes
0019 
0020 #include <QApplication>
0021 #include <QVBoxLayout>
0022 #include <QHBoxLayout>
0023 #include <QCheckBox>
0024 #include <QLabel>
0025 #include <QStyle>
0026 
0027 // KDE includes
0028 
0029 #include <klocalizedstring.h>
0030 #include <kconfiggroup.h>
0031 
0032 // Local includes
0033 
0034 #include "dngsettings.h"
0035 #include "setup.h"
0036 
0037 namespace Digikam
0038 {
0039 
0040 class Q_DECL_HIDDEN DNGConvertSettings::Private
0041 {
0042 public:
0043 
0044     explicit Private()
0045         : convertDng  (nullptr),
0046           dngLink     (nullptr),
0047           dngSettings (nullptr)
0048     {
0049     }
0050 
0051     QCheckBox*   convertDng;
0052     QLabel*      dngLink;
0053     DNGSettings* dngSettings;
0054 };
0055 
0056 DNGConvertSettings::DNGConvertSettings(QWidget* const parent)
0057     : QWidget(parent),
0058       d      (new Private)
0059 {
0060     const int spacing           = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0061                                        QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0062 
0063     QVBoxLayout* const mainVlay = new QVBoxLayout(this);
0064     QHBoxLayout* const convHlay = new QHBoxLayout;
0065 
0066     d->convertDng               = new QCheckBox(i18nc("@option:check", "Convert RAW images to"), this);
0067     d->dngSettings              = new DNGSettings(this);
0068 
0069     d->dngLink                  = new QLabel(this);
0070     d->dngLink->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
0071     d->dngLink->setOpenExternalLinks(true);
0072     d->dngLink->setWordWrap(false);
0073     d->dngLink->setText(QString::fromUtf8("<p><a href='https://en.wikipedia.org/wiki/Digital_Negative_(file_format)'>%1</a></p>")
0074                         .arg(i18nc("@label", "DNG container")));
0075 
0076     convHlay->addWidget(d->convertDng);
0077     convHlay->addWidget(d->dngLink);
0078     convHlay->addStretch(10);
0079     convHlay->setContentsMargins(spacing, spacing, spacing, spacing);
0080     convHlay->setSpacing(0);
0081 
0082     mainVlay->addLayout(convHlay);
0083     mainVlay->addWidget(d->dngSettings);
0084     mainVlay->setContentsMargins(QMargins());
0085     mainVlay->setSpacing(0);
0086 
0087     setWhatsThis(i18nc("@info", "Set here all options to convert RAW images to DNG container automatically "
0088                                 "as they are downloaded."));
0089     d->convertDng->setWhatsThis(i18nc("@info", "Enable this option to convert RAW images to DNG container automatically."));
0090 
0091     setLayout(mainVlay);
0092 
0093     // ---------------------------------------------------------------------------------------
0094 
0095     connect(d->convertDng, SIGNAL(toggled(bool)),
0096             d->dngSettings, SLOT(setEnabled(bool)));
0097 
0098     connect(d->convertDng, SIGNAL(toggled(bool)),
0099             this, SIGNAL(signalDownloadNameChanged()));
0100 
0101     connect(d->dngSettings, SIGNAL(signalSetupExifTool()),
0102             this, SLOT(slotSetupExifTool()));
0103 }
0104 
0105 DNGConvertSettings::~DNGConvertSettings()
0106 {
0107     delete d;
0108 }
0109 
0110 void DNGConvertSettings::readSettings(KConfigGroup& group)
0111 {
0112     d->dngSettings->setBackupOriginalRawFile(group.readEntry(QLatin1String("BackupOriginalRawFile"), false));
0113     d->dngSettings->setCompressLossLess(group.readEntry(QLatin1String("CompressLossLess"),           true));
0114     d->dngSettings->setPreviewMode(group.readEntry(QLatin1String("PreviewMode"),                     (int)DNGWriter::FULL_SIZE));
0115     d->convertDng->setChecked(group.readEntry(QLatin1String("ConvertDng"),                           false));
0116 
0117     d->dngSettings->setEnabled(d->convertDng->isChecked());
0118 }
0119 
0120 void DNGConvertSettings::saveSettings(KConfigGroup& group)
0121 {
0122     group.writeEntry(QLatin1String("BackupOriginalRawFile"), d->dngSettings->backupOriginalRawFile());
0123     group.writeEntry(QLatin1String("CompressLossLess"),      d->dngSettings->compressLossLess());
0124     group.writeEntry(QLatin1String("PreviewMode"),           d->dngSettings->previewMode());
0125     group.writeEntry(QLatin1String("ConvertDng"),            d->convertDng->isChecked());
0126 }
0127 
0128 void DNGConvertSettings::settings(DownloadSettings* const settings)
0129 {
0130     settings->backupRaw   = d->dngSettings->backupOriginalRawFile();
0131     settings->compressDng = d->dngSettings->compressLossLess();
0132     settings->previewMode = d->dngSettings->previewMode();
0133     settings->convertDng  = d->convertDng->isChecked();
0134 }
0135 
0136 void DNGConvertSettings::slotSetupExifTool()
0137 {
0138     if (Setup::execExifTool(nullptr))
0139     {
0140         d->dngSettings->slotSetupChanged();
0141     }
0142 }
0143 
0144 } // namespace Digikam
0145 
0146 #include "moc_dngconvertsettings.cpp"