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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-08-12
0007  * Description : advanced settings for camera interface.
0008  *
0009  * SPDX-FileCopyrightText: 2011-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 "advancedsettings.h"
0016 
0017 // Qt includes
0018 
0019 #include <QVBoxLayout>
0020 #include <QLabel>
0021 #include <QCheckBox>
0022 #include <QToolButton>
0023 #include <QApplication>
0024 #include <QStyle>
0025 #include <QComboBox>
0026 
0027 // KDE includes
0028 
0029 #include <kconfiggroup.h>
0030 #include <klocalizedstring.h>
0031 
0032 // Local includes
0033 
0034 #include "digikam_debug.h"
0035 #include "digikam_config.h"
0036 #include "dpluginloader.h"
0037 #include "templateselector.h"
0038 #include "ddatetimeedit.h"
0039 #include "setupversioning.h"
0040 #include "template.h"
0041 
0042 namespace Digikam
0043 {
0044 
0045 class Q_DECL_HIDDEN AdvancedSettings::Private
0046 {
0047 public:
0048 
0049     explicit Private()
0050         : formatLabel       (nullptr),
0051           autoRotateCheck   (nullptr),
0052           convertJpegCheck  (nullptr),
0053           fixDateTimeCheck  (nullptr),
0054           documentNameCheck (nullptr),
0055           losslessFormat    (nullptr),
0056           dateTimeEdit      (nullptr),
0057           templateSelector  (nullptr)
0058     {
0059     }
0060 
0061     QLabel*           formatLabel;
0062 
0063     QCheckBox*        autoRotateCheck;
0064     QCheckBox*        convertJpegCheck;
0065     QCheckBox*        fixDateTimeCheck;
0066     QCheckBox*        documentNameCheck;
0067 
0068     QComboBox*        losslessFormat;
0069 
0070     DDateTimeEdit*    dateTimeEdit;
0071 
0072     TemplateSelector* templateSelector;
0073 };
0074 
0075 AdvancedSettings::AdvancedSettings(QWidget* const parent)
0076     : QWidget(parent),
0077       d      (new Private)
0078 {
0079     const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0080                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0081 
0082     QVBoxLayout* const onFlyVlay = new QVBoxLayout(this);
0083     d->templateSelector          = new TemplateSelector(this);
0084     d->documentNameCheck         = new QCheckBox(i18nc("@option:check", "Write the document name to EXIF"), this);
0085     d->fixDateTimeCheck          = new QCheckBox(i18nc("@option:check", "Fix internal date && time"), this);
0086     d->dateTimeEdit              = new DDateTimeEdit(this, QLatin1String("datepicker"));
0087     d->autoRotateCheck           = new QCheckBox(i18nc("@option:check", "Auto-rotate/flip image"), this);
0088     d->convertJpegCheck          = new QCheckBox(i18nc("@option:check", "Convert to lossless file format"), this);
0089     DHBox* const hbox2           = new DHBox(this);
0090     d->formatLabel               = new QLabel(i18nc("@label", "New image format:"), hbox2);
0091     d->losslessFormat            = new QComboBox(hbox2);
0092     d->losslessFormat->addItem(i18nc("@label:listbox", "PNG"),         QLatin1String("PNG"));
0093     d->losslessFormat->addItem(i18nc("@label:listbox", "TIFF"),        QLatin1String("TIF"));
0094     d->losslessFormat->addItem(i18nc("@label:listbox", "PGF"),         QLatin1String("PGF"));
0095 
0096 #ifdef HAVE_JASPER
0097 
0098     d->losslessFormat->addItem(i18nc("@label:listbox", "JPEG-2000"),   QLatin1String("JP2"));
0099 
0100 #endif // HAVE_JASPER
0101 
0102 #ifdef HAVE_X265
0103 
0104     d->losslessFormat->addItem(i18nc("@label:listbox", "HEIF"),        QLatin1String("HEIF"));
0105 
0106 #endif // HAVE_X265
0107 
0108     bool hasJXLSupport = DPluginLoader::instance()->canExport(QLatin1String("JXL"));
0109 
0110     if (hasJXLSupport)
0111     {
0112         d->losslessFormat->addItem(i18nc("@label:listbox", "JPEG-XL"), QLatin1String("JXL"));
0113     }
0114 
0115     bool hasWEBPSupport = DPluginLoader::instance()->canExport(QLatin1String("WEBP"));
0116 
0117     if (hasWEBPSupport)
0118     {
0119         d->losslessFormat->addItem(i18nc("@label:listbox", "WEBP"),    QLatin1String("WEBP"));
0120     }
0121 
0122     bool hasAVIFSupport = DPluginLoader::instance()->canExport(QLatin1String("AVIF"));
0123 
0124     if (hasAVIFSupport)
0125     {
0126         d->losslessFormat->addItem(i18nc("@label:listbox", "AVIF"),    QLatin1String("AVIF"));
0127     }
0128 
0129     onFlyVlay->addWidget(d->templateSelector);
0130     onFlyVlay->addWidget(d->documentNameCheck);
0131     onFlyVlay->addWidget(d->fixDateTimeCheck);
0132     onFlyVlay->addWidget(d->dateTimeEdit);
0133     onFlyVlay->addWidget(d->autoRotateCheck);
0134     onFlyVlay->addWidget(d->convertJpegCheck);
0135     onFlyVlay->addWidget(hbox2);
0136     onFlyVlay->addStretch();
0137     onFlyVlay->setContentsMargins(spacing, spacing, spacing, spacing);
0138     onFlyVlay->setSpacing(spacing);
0139 
0140     setWhatsThis(i18nc("@info", "Set here all options to fix/transform JPEG files automatically "
0141                        "as they are downloaded."));
0142     d->autoRotateCheck->setWhatsThis(i18nc("@info", "Enable this option if you want images automatically "
0143                                            "rotated or flipped using Exif information provided by the camera."));
0144     d->templateSelector->setWhatsThis(i18nc("@info", "Select here which metadata template you want to apply "
0145                                             "to images."));
0146     d->documentNameCheck->setWhatsThis(i18nc("@info", "Enable this option to write the document name to the Exif metadata. "
0147                                              "The document name is the original file name of the imported file."));
0148     d->fixDateTimeCheck->setWhatsThis(i18nc("@info", "Enable this option to set date and time metadata "
0149                                             "tags to the right values if your camera does not set "
0150                                             "these tags correctly when pictures are taken. The values will "
0151                                             "be saved in the DateTimeDigitized and DateTimeCreated EXIF, XMP, and IPTC tags."));
0152     d->convertJpegCheck->setWhatsThis(i18nc("@info", "Enable this option to automatically convert "
0153                                             "all JPEG files to a lossless image format. Note: Image conversion can take a "
0154                                             "while on a slow computer."));
0155 
0156     QString formatHelp = xi18nc("@info:whatsthis",
0157                                 "<title>Preferred Lossless Image File Format</title>"
0158                                 "<para>Select the file format in which JPEG image will be converted to a "
0159                                 "lossless container with metadata support.</para>");
0160 
0161     SetupVersioning::losslessFormatToolTip(formatHelp, hasJXLSupport, hasWEBPSupport, hasAVIFSupport);
0162     d->losslessFormat->setWhatsThis(formatHelp);
0163 
0164     // ---------------------------------------------------------------------------------------
0165 
0166     connect(d->convertJpegCheck, SIGNAL(toggled(bool)),
0167             d->losslessFormat, SLOT(setEnabled(bool)));
0168 
0169     connect(d->convertJpegCheck, SIGNAL(toggled(bool)),
0170             d->formatLabel, SLOT(setEnabled(bool)));
0171 
0172     connect(d->convertJpegCheck, SIGNAL(toggled(bool)),
0173             this, SIGNAL(signalDownloadNameChanged()));
0174 
0175     connect(d->losslessFormat, SIGNAL(activated(int)),
0176             this, SIGNAL(signalDownloadNameChanged()));
0177 
0178     connect(d->fixDateTimeCheck, SIGNAL(toggled(bool)),
0179             d->dateTimeEdit, SLOT(setEnabled(bool)));
0180 }
0181 
0182 AdvancedSettings::~AdvancedSettings()
0183 {
0184     delete d;
0185 }
0186 
0187 void AdvancedSettings::readSettings(KConfigGroup& group)
0188 {
0189     d->autoRotateCheck->setChecked(group.readEntry(QLatin1String("AutoRotate"),         true));
0190     d->fixDateTimeCheck->setChecked(group.readEntry(QLatin1String("FixDateTime"),       false));
0191     d->documentNameCheck->setChecked(group.readEntry(QLatin1String("DocumentName"),     false));
0192     d->templateSelector->setTemplateIndex(group.readEntry(QLatin1String("Template"),    1));      // do not change
0193     d->convertJpegCheck->setChecked(group.readEntry(QLatin1String("ConvertJpeg"),       false));
0194     d->losslessFormat->setCurrentIndex(group.readEntry(QLatin1String("LossLessFormat"), 0));      // PNG by default
0195 
0196     d->dateTimeEdit->setEnabled(d->fixDateTimeCheck->isChecked());
0197     d->losslessFormat->setEnabled(d->convertJpegCheck->isChecked());
0198     d->formatLabel->setEnabled(d->convertJpegCheck->isChecked());
0199 }
0200 
0201 void AdvancedSettings::saveSettings(KConfigGroup& group)
0202 {
0203     group.writeEntry(QLatin1String("AutoRotate"),     d->autoRotateCheck->isChecked());
0204     group.writeEntry(QLatin1String("FixDateTime"),    d->fixDateTimeCheck->isChecked());
0205     group.writeEntry(QLatin1String("DocumentName"),   d->documentNameCheck->isChecked());
0206     group.writeEntry(QLatin1String("Template"),       d->templateSelector->getTemplateIndex());
0207     group.writeEntry(QLatin1String("ConvertJpeg"),    d->convertJpegCheck->isChecked());
0208     group.writeEntry(QLatin1String("LossLessFormat"), d->losslessFormat->currentIndex());
0209 }
0210 
0211 DownloadSettings AdvancedSettings::settings() const
0212 {
0213     DownloadSettings settings;
0214 
0215     settings.autoRotate     = d->autoRotateCheck->isChecked();
0216     settings.fixDateTime    = d->fixDateTimeCheck->isChecked();
0217     settings.convertJpeg    = d->convertJpegCheck->isChecked();
0218     settings.newDateTime    = d->dateTimeEdit->dateTime();
0219     settings.documentName   = d->documentNameCheck->isChecked();
0220     settings.losslessFormat = d->losslessFormat->itemData(d->losslessFormat->currentIndex()).toString();
0221     settings.templateTitle  = d->templateSelector->getTemplate().templateTitle();
0222 
0223     return settings;
0224 }
0225 
0226 } // namespace Digikam
0227 
0228 #include "moc_advancedsettings.cpp"