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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-06-27
0007  * Description : a tool to export items to web services.
0008  *
0009  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2018      by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "wssettingspage.h"
0017 
0018 // Qt includes
0019 
0020 #include <QIcon>
0021 #include <QLabel>
0022 #include <QUrl>
0023 #include <QWidget>
0024 #include <QApplication>
0025 #include <QStyle>
0026 #include <QComboBox>
0027 #include <QCheckBox>
0028 #include <QSpinBox>
0029 #include <QGridLayout>
0030 #include <QGroupBox>
0031 
0032 // KDE includes
0033 
0034 #include <klocalizedstring.h>
0035 
0036 // Local includes
0037 
0038 #include "wswizard.h"
0039 #include "dfileselector.h"
0040 #include "filesaveconflictbox.h"
0041 #include "digikam_debug.h"
0042 
0043 namespace DigikamGenericUnifiedPlugin
0044 {
0045 
0046 class Q_DECL_HIDDEN WSSettingsPage::Private
0047 {
0048 public:
0049 
0050     explicit Private(QWizard* const dialog)
0051       : labelImagesResize(0),
0052         labelImagesFormat(0),
0053         labelImageCompression(0),
0054         imagesFormat(0),
0055         changeImagesProp(0),
0056         removeMetadata(0),
0057         imageCompression(0),
0058         imagesResize(0),
0059         wizard(0),
0060         iface(0),
0061         settings(0)
0062     {
0063         wizard = dynamic_cast<WSWizard*>(dialog);
0064 
0065         if (wizard)
0066         {
0067             settings = wizard->settings();
0068             iface    = wizard->iface();
0069         }
0070     }
0071 
0072     QLabel*         labelImagesResize;
0073     QLabel*         labelImagesFormat;
0074     QLabel*         labelImageCompression;
0075 
0076     QComboBox*      imagesFormat;
0077 
0078     QCheckBox*      changeImagesProp;
0079     QCheckBox*      removeMetadata;
0080 
0081     QSpinBox*       imageCompression;
0082     QSpinBox*       imagesResize;
0083 
0084     WSWizard*       wizard;
0085     DInfoInterface* iface;
0086     WSSettings*     settings;
0087 };
0088 
0089 WSSettingsPage::WSSettingsPage(QWizard* const dialog, const QString& title)
0090     : DWizardPage(dialog, title),
0091       d(new Private(dialog))
0092 {
0093     QWidget* const main = new QWidget(this);
0094 
0095     //---------------------------------------------
0096 
0097     d->changeImagesProp  = new QCheckBox(i18n("Adjust image properties"), main);
0098     d->changeImagesProp->setChecked(true);
0099     d->changeImagesProp->setWhatsThis(i18n("If you enable this option, "
0100                                            "all images to be sent can be "
0101                                            "resized and recompressed."));
0102 
0103     QGroupBox* const groupBox = new QGroupBox(i18n("Image Properties"), main);
0104     QGridLayout* const grid2  = new QGridLayout(groupBox);
0105 
0106     //---------------------------------------------
0107 
0108     d->imagesResize = new QSpinBox(groupBox);
0109     d->imagesResize->setRange(300, 4000);
0110     d->imagesResize->setSingleStep(1);
0111     d->imagesResize->setValue(1024);
0112     d->imagesResize->setSuffix(i18n(" px"));
0113     d->imagesResize->setWhatsThis(i18n("Select the length of the images that are to be sent. "
0114                                        "The aspect ratio is preserved."));
0115 
0116     d->labelImagesResize = new QLabel(i18n("Image Length:"), groupBox);
0117     d->labelImagesResize->setBuddy(d->imagesResize);
0118 
0119     //---------------------------------------------
0120 
0121     d->labelImagesFormat = new QLabel(groupBox);
0122     d->labelImagesFormat->setWordWrap(false);
0123     d->labelImagesFormat->setText(i18n("Image Format:"));
0124 
0125     d->imagesFormat  = new QComboBox(groupBox);
0126     d->imagesFormat->setEditable(false);
0127     d->imagesFormat->setWhatsThis(i18n("Select your preferred format to convert image."));
0128 
0129     QMap<WSSettings::ImageFormat, QString> map2                = WSSettings::imageFormatNames();
0130     QMap<WSSettings::ImageFormat, QString>::const_iterator it2 = map2.constBegin();
0131 
0132     while (it2 != map2.constEnd())
0133     {
0134         d->imagesFormat->addItem(it2.value(), (int)it2.key());
0135         ++it2;
0136     }
0137 
0138     d->labelImagesFormat->setBuddy(d->imagesFormat);
0139 
0140     // --------------------
0141 
0142     d->imageCompression = new QSpinBox(groupBox);
0143     d->imageCompression->setRange(1, 100);
0144     d->imageCompression->setSingleStep(1);
0145     d->imageCompression->setValue(75);
0146     QString whatsThis = i18n("<p>The new compression value of JPEG images to be sent:</p>");
0147     whatsThis         = whatsThis + i18n("<p><b>1</b>: very high compression<br/>"
0148                                          "<b>25</b>: high compression<br/>"
0149                                          "<b>50</b>: medium compression<br/>"
0150                                          "<b>75</b>: low compression (default value)<br/>"
0151                                          "<b>100</b>: no compression</p>");
0152 
0153     d->imageCompression->setWhatsThis(whatsThis);
0154 
0155     d->labelImageCompression = new QLabel(i18n("Image quality:"), this);
0156     d->labelImageCompression->setBuddy(d->imageCompression);
0157 
0158     // --------------------
0159 
0160     d->removeMetadata = new QCheckBox(i18n("Remove all metadata"), main);
0161     d->removeMetadata->setWhatsThis(i18n("If you enable this option, all metadata "
0162                                          "as Exif, Iptc, and Xmp will be removed."));
0163 
0164     // --------------------
0165 
0166     grid2->addWidget(d->labelImagesResize,     0, 0, 1, 1);
0167     grid2->addWidget(d->imagesResize,          0, 1, 1, 2);
0168     grid2->addWidget(d->labelImagesFormat,     1, 0, 1, 1);
0169     grid2->addWidget(d->imagesFormat,          1, 1, 1, 2);
0170     grid2->addWidget(d->labelImageCompression, 2, 0, 1, 1);
0171     grid2->addWidget(d->imageCompression,      2, 1, 1, 2);
0172     grid2->addWidget(d->removeMetadata,        3, 0, 1, 2);
0173     grid2->setRowStretch(4, 10);
0174     grid2->setColumnStretch(2, 10);
0175     grid2->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0176                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)));
0177     grid2->setAlignment(Qt::AlignTop);
0178 
0179     // --------------------
0180 
0181     QGridLayout* const grid = new QGridLayout(main);
0182     grid->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0183                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)));
0184     grid->addWidget(d->changeImagesProp,    0, 0, 1, 4);
0185     grid->addWidget(groupBox,               1, 0, 1, 4);
0186     grid->setRowStretch(2, 10);
0187     grid->setColumnStretch(3, 10);
0188 
0189     setPageWidget(main);
0190 
0191     /* We should use another icon here, because it's not for mail attachment.
0192      * Therefore, I comment this line.
0193      *
0194      * setLeftBottomPix(QIcon::fromTheme(QLatin1String("mail-attachment")));
0195      */
0196 
0197     //---------------------------------------------
0198 
0199     connect(d->imagesFormat, SIGNAL(activated(int)),
0200             this, SLOT(slotImagesFormatChanged(int)));
0201 
0202     connect(d->changeImagesProp, SIGNAL(toggled(bool)),
0203             groupBox, SLOT(setEnabled(bool)));
0204 }
0205 
0206 WSSettingsPage::~WSSettingsPage()
0207 {
0208     delete d;
0209 }
0210 
0211 void WSSettingsPage::slotImagesFormatChanged(int i)
0212 {
0213     if (i == WSSettings::JPEG)
0214     {
0215         d->imageCompression->setEnabled(true);
0216     }
0217     else
0218     {
0219         d->imageCompression->setEnabled(false);
0220     }
0221 }
0222 
0223 void WSSettingsPage::initializePage()
0224 {
0225     d->imagesResize->setValue(d->settings->imageSize);
0226     d->imagesFormat->setCurrentIndex((int)d->settings->imageFormat);
0227 
0228     d->changeImagesProp->setChecked(d->settings->imagesChangeProp);
0229 
0230     d->imageCompression->setValue(d->settings->imageCompression);
0231     d->removeMetadata->setChecked(d->settings->removeMetadata);
0232 
0233     slotImagesFormatChanged(d->imagesFormat->currentIndex());
0234 }
0235 
0236 bool WSSettingsPage::validatePage()
0237 {
0238     d->settings->imageSize         = d->imagesResize->value();
0239     d->settings->imageFormat       = WSSettings::ImageFormat(d->imagesFormat->currentIndex());
0240 
0241     d->settings->imagesChangeProp  = d->changeImagesProp->isChecked();
0242     d->settings->removeMetadata    = d->removeMetadata->isChecked();
0243 
0244     d->settings->imageCompression  = d->imageCompression->value();
0245 
0246     return true;
0247 }
0248 
0249 } // namespace DigikamGenericUnifiedPlugin
0250 
0251 #include "moc_wssettingspage.cpp"