File indexing completed on 2025-01-19 03:56:58

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2004-05-16
0007  * Description : time adjust settings widget.
0008  *
0009  * SPDX-FileCopyrightText: 2012      by Smit Mehta <smit dot meh at gmail dot com>
0010  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2018      by Maik Qualmann <metzpinguin at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #include "timeadjustsettings.h"
0018 
0019 // Qt includes
0020 
0021 #include <QApplication>
0022 #include <QButtonGroup>
0023 #include <QCheckBox>
0024 #include <QGridLayout>
0025 #include <QLabel>
0026 #include <QPushButton>
0027 #include <QRadioButton>
0028 #include <QSpinBox>
0029 #include <QToolButton>
0030 #include <QDateTime>
0031 #include <QTimeEdit>
0032 #include <QComboBox>
0033 #include <QPointer>
0034 #include <QVBoxLayout>
0035 
0036 // KDE includes
0037 
0038 #include <klocalizedstring.h>
0039 
0040 // Local includes
0041 
0042 #include "dexpanderbox.h"
0043 #include "clockphotodialog.h"
0044 #include "dmetadata.h"
0045 #include "detbyclockphotobutton.h"
0046 
0047 namespace Digikam
0048 {
0049 
0050 class Q_DECL_HIDDEN TimeAdjustSettings::Private
0051 {
0052 
0053 public:
0054 
0055     explicit Private()
0056       : useSettingsBox          (nullptr),
0057         adjustSettingsBox       (nullptr),
0058         updateSettingsBox       (nullptr),
0059         useButtonGroup          (nullptr),
0060         useApplDateBtn          (nullptr),
0061         useFileDateBtn          (nullptr),
0062         useFileNameBtn          (nullptr),
0063         useMetaDateBtn          (nullptr),
0064         useCustomDateBtn        (nullptr),
0065         updIfAvailableCheck     (nullptr),
0066         updFileModDateCheck     (nullptr),
0067         updEXIFModDateCheck     (nullptr),
0068         updEXIFOriDateCheck     (nullptr),
0069         updEXIFDigDateCheck     (nullptr),
0070         updEXIFThmDateCheck     (nullptr),
0071         updIPTCDateCheck        (nullptr),
0072         updXMPVideoCheck        (nullptr),
0073         updXMPDateCheck         (nullptr),
0074         useFileDateTypeChooser  (nullptr),
0075         useMetaDateTypeChooser  (nullptr),
0076         adjTypeChooser          (nullptr),
0077         useApplDateLbl          (nullptr),
0078         adjDaysLabel            (nullptr),
0079         adjDaysInput            (nullptr),
0080         adjDetByClockPhotoBtn   (nullptr),
0081         useCustDateInput        (nullptr),
0082         useCustTimeInput        (nullptr),
0083         adjTimeInput            (nullptr),
0084         useCustomDateTodayBtn   (nullptr),
0085         settingsExpander        (nullptr)
0086     {
0087     }
0088 
0089     QWidget*               useSettingsBox;
0090     QWidget*               adjustSettingsBox;
0091     QWidget*               updateSettingsBox;
0092 
0093     QButtonGroup*          useButtonGroup;
0094 
0095     QRadioButton*          useApplDateBtn;
0096     QRadioButton*          useFileDateBtn;
0097     QRadioButton*          useFileNameBtn;
0098     QRadioButton*          useMetaDateBtn;
0099     QRadioButton*          useCustomDateBtn;
0100 
0101     QCheckBox*             updIfAvailableCheck;
0102     QCheckBox*             updFileModDateCheck;
0103     QCheckBox*             updEXIFModDateCheck;
0104     QCheckBox*             updEXIFOriDateCheck;
0105     QCheckBox*             updEXIFDigDateCheck;
0106     QCheckBox*             updEXIFThmDateCheck;
0107     QCheckBox*             updIPTCDateCheck;
0108     QCheckBox*             updXMPVideoCheck;
0109     QCheckBox*             updXMPDateCheck;
0110 
0111     QComboBox*             useFileDateTypeChooser;
0112     QComboBox*             useMetaDateTypeChooser;
0113     QComboBox*             adjTypeChooser;
0114 
0115     QLabel*                useApplDateLbl;
0116     QLabel*                adjDaysLabel;
0117 
0118     QSpinBox*              adjDaysInput;
0119 
0120     DetByClockPhotoButton* adjDetByClockPhotoBtn;
0121 
0122     QDateEdit*             useCustDateInput;
0123 
0124     QTimeEdit*             useCustTimeInput;
0125     QTimeEdit*             adjTimeInput;
0126 
0127     QToolButton*           useCustomDateTodayBtn;
0128 
0129     DExpanderBox*          settingsExpander;
0130 
0131     QUrl                   currentItemUrl;
0132 };
0133 
0134 TimeAdjustSettings::TimeAdjustSettings(QWidget* const parent, bool timeAdjustTool)
0135     : QScrollArea(parent),
0136       d          (new Private)
0137 {
0138     QWidget* const panel    = new QWidget(viewport());
0139     setWidget(panel);
0140     setWidgetResizable(true);
0141 
0142     d->settingsExpander     = new DExpanderBox(panel);
0143     d->settingsExpander->setObjectName(QLatin1String("Time Adjust Settings Expander"));
0144     QVBoxLayout* const vlay = new QVBoxLayout(panel);
0145     vlay->addWidget(d->settingsExpander);
0146 
0147     const int spacing       = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0148                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0149 
0150     // -- Settings View Used Timestamps ---------------------------------------------------------
0151 
0152     d->useSettingsBox              = new QWidget(d->settingsExpander);
0153     QGridLayout* const useGBLayout = new QGridLayout(d->useSettingsBox);
0154     d->useButtonGroup              = new QButtonGroup(d->useSettingsBox);
0155     d->useButtonGroup->setExclusive(true);
0156 
0157     QString appName = QApplication::applicationName();
0158 
0159     if      (appName == QLatin1String("digikam"))
0160     {
0161         appName = i18n("digiKam");
0162     }
0163     else if (appName == QLatin1String("showfoto"))
0164     {
0165         appName = i18n("Showfoto");
0166     }
0167 
0168     QString applDateLabelString = i18n("%1 timestamp", appName);
0169     d->useApplDateBtn           = new QRadioButton(d->useSettingsBox);
0170     d->useApplDateLbl           = new QLabel(applDateLabelString);
0171 
0172     d->useFileNameBtn           = new QRadioButton(d->useSettingsBox);
0173     QLabel* const fileNameLbl   = new QLabel(i18n("File name timestamp"), d->useSettingsBox);
0174 
0175     d->useFileDateBtn           = new QRadioButton(d->useSettingsBox);
0176     d->useFileDateTypeChooser   = new QComboBox(d->useSettingsBox);
0177     d->useFileDateTypeChooser->insertItem(TimeAdjustContainer::FILELASTMOD, i18n("File last modified"));
0178 
0179 /*
0180     // NOTE: not supported by Linux, although supported by Qt (read-only)
0181     d->useFileDateTypeChooser->insertItem(TimeAdjustContainer::FILECREATED, i18n("File created"));
0182 */
0183 
0184     d->useMetaDateBtn         = new QRadioButton(QString(), d->useSettingsBox);
0185     d->useMetaDateTypeChooser = new QComboBox(d->useSettingsBox);
0186     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::EXIFIPTCXMP,    i18n("EXIF/IPTC/XMP"));
0187     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::EXIFCREATED,    i18n("EXIF: created"));
0188     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::EXIFORIGINAL,   i18n("EXIF: original"));
0189     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::EXIFDIGITIZED,  i18n("EXIF: digitized"));
0190     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::IPTCCREATED,    i18n("IPTC: created"));
0191     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::XMPCREATED,     i18n("XMP: created"));
0192     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::FUZZYCREATED,   i18n("EXIF: created (fuzzy)"));
0193     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::FUZZYORIGINAL,  i18n("EXIF: original (fuzzy)"));
0194     d->useMetaDateTypeChooser->insertItem(TimeAdjustContainer::FUZZYDIGITIZED, i18n("EXIF: digitized (fuzzy)"));
0195 
0196     d->useCustomDateBtn       = new QRadioButton(d->useSettingsBox);
0197     d->useCustDateInput       = new QDateEdit(d->useSettingsBox);
0198     d->useCustDateInput->setDisplayFormat(QLatin1String("dd MMMM yyyy"));
0199     d->useCustDateInput->setCalendarPopup(true);
0200     d->useCustTimeInput       = new QTimeEdit(d->useSettingsBox);
0201     d->useCustTimeInput->setDisplayFormat(QLatin1String("hh:mm:ss"));
0202     d->useCustomDateTodayBtn  = new QToolButton(d->useSettingsBox);
0203     d->useCustomDateTodayBtn->setIcon(QIcon::fromTheme(QLatin1String("view-calendar")));
0204     d->useCustomDateTodayBtn->setToolTip(i18n("Reset to current date"));
0205 
0206     useGBLayout->addWidget(d->useApplDateBtn,         0, 0, 1, 1);
0207     useGBLayout->addWidget(d->useApplDateLbl,         0, 1, 1, 1);
0208     useGBLayout->addWidget(d->useFileNameBtn,         1, 0, 1, 1);
0209     useGBLayout->addWidget(fileNameLbl,               1, 1, 1, 1);
0210     useGBLayout->addWidget(d->useFileDateBtn,         2, 0, 1, 1);
0211     useGBLayout->addWidget(d->useFileDateTypeChooser, 2, 1, 1, 1);
0212     useGBLayout->addWidget(d->useMetaDateBtn,         3, 0, 1, 1);
0213     useGBLayout->addWidget(d->useMetaDateTypeChooser, 3, 1, 1, 1);
0214     useGBLayout->addWidget(d->useCustomDateBtn,       4, 0, 1, 1);
0215     useGBLayout->addWidget(d->useCustDateInput,       4, 1, 1, 1);
0216     useGBLayout->addWidget(d->useCustTimeInput,       4, 2, 1, 1);
0217     useGBLayout->addWidget(d->useCustomDateTodayBtn,  4, 3, 1, 1);
0218     useGBLayout->setContentsMargins(spacing, spacing, spacing, spacing);
0219     useGBLayout->setSpacing(spacing);
0220     useGBLayout->setColumnStretch(1, 1);
0221     useGBLayout->setColumnStretch(3, 1);
0222 
0223     d->useButtonGroup->addButton(d->useApplDateBtn,   0);
0224     d->useButtonGroup->addButton(d->useFileNameBtn,   1);
0225     d->useButtonGroup->addButton(d->useFileDateBtn,   2);
0226     d->useButtonGroup->addButton(d->useMetaDateBtn,   3);
0227     d->useButtonGroup->addButton(d->useCustomDateBtn, 4);
0228     d->useApplDateBtn->setChecked(true);
0229 
0230     // -- Settings View TimesStamp Adjustments ---------------------------------------------------
0231 
0232     d->adjustSettingsBox              = new QWidget(d->settingsExpander);
0233     QGridLayout* const adjustGBLayout = new QGridLayout(d->adjustSettingsBox);
0234 
0235     d->adjTypeChooser           = new QComboBox(d->adjustSettingsBox);
0236     d->adjTypeChooser->insertItem(TimeAdjustContainer::COPYVALUE, i18nc("copy timestamp as well",             "Copy value"));
0237     d->adjTypeChooser->insertItem(TimeAdjustContainer::ADDVALUE,  i18nc("add a fixed timestamp to date",      "Add"));
0238     d->adjTypeChooser->insertItem(TimeAdjustContainer::SUBVALUE,  i18nc("subtract a fixed timestamp to date", "Subtract"));
0239 
0240     if (timeAdjustTool)
0241     {
0242         d->adjTypeChooser->insertItem(TimeAdjustContainer::INTERVAL,  i18nc("interval time stamp to the next image", "Interval"));
0243     }
0244 
0245     d->adjDaysInput             = new QSpinBox(d->adjustSettingsBox);
0246     d->adjDaysInput->setRange(0, 9999);
0247     d->adjDaysInput->setSingleStep(1);
0248     d->adjDaysLabel             = new QLabel(i18nc("time adjust offset, days value label", "days"), d->adjustSettingsBox);
0249     d->adjTimeInput             = new QTimeEdit(d->adjustSettingsBox);
0250     d->adjTimeInput->setDisplayFormat(QLatin1String("hh:mm:ss"));
0251     d->adjDetByClockPhotoBtn    = new DetByClockPhotoButton(i18n("Determine difference from clock photo"));
0252     d->adjDetByClockPhotoBtn->setToolTip(i18n("Either click or drag'n drop a photo on the button to choose a clock photo"));
0253 
0254     adjustGBLayout->addWidget(d->adjTypeChooser,        0, 0, 1, 1);
0255     adjustGBLayout->addWidget(d->adjDaysInput,          0, 1, 1, 1);
0256     adjustGBLayout->addWidget(d->adjDaysLabel,          0, 2, 1, 1);
0257     adjustGBLayout->addWidget(d->adjTimeInput,          0, 3, 1, 1);
0258     adjustGBLayout->addWidget(d->adjDetByClockPhotoBtn, 1, 0, 1, 4);
0259     adjustGBLayout->setContentsMargins(spacing, spacing, spacing, spacing);
0260     adjustGBLayout->setSpacing(spacing);
0261     adjustGBLayout->setColumnStretch(0, 1);
0262     adjustGBLayout->setColumnStretch(1, 1);
0263     adjustGBLayout->setColumnStretch(3, 1);
0264 
0265     // -- Settings View Updated Timestamps -------------------------------------------------------
0266 
0267     d->updateSettingsBox              = new QWidget(d->settingsExpander);
0268     QGridLayout* const updateGBLayout = new QGridLayout(d->updateSettingsBox);
0269 
0270     d->updIfAvailableCheck      = new QCheckBox(i18n("Update only existing timestamps"), d->updateSettingsBox);
0271     d->updFileModDateCheck      = new QCheckBox(i18n("File last modified"),              d->updateSettingsBox);
0272     d->updEXIFModDateCheck      = new QCheckBox(i18n("EXIF: created"),                   d->updateSettingsBox);
0273     d->updEXIFOriDateCheck      = new QCheckBox(i18n("EXIF: original"),                  d->updateSettingsBox);
0274     d->updEXIFDigDateCheck      = new QCheckBox(i18n("EXIF: digitized"),                 d->updateSettingsBox);
0275     d->updEXIFThmDateCheck      = new QCheckBox(i18n("EXIF: Thumbnail"),                 d->updateSettingsBox);
0276     d->updIPTCDateCheck         = new QCheckBox(i18n("IPTC: created"),                   d->updateSettingsBox);
0277     d->updXMPVideoCheck         = new QCheckBox(i18n("XMP: Video"),                      d->updateSettingsBox);
0278     d->updXMPDateCheck          = new QCheckBox(i18n("XMP"),                             d->updateSettingsBox);
0279 
0280     updateGBLayout->addWidget(d->updIfAvailableCheck, 0, 0, 1, 2);
0281     updateGBLayout->addWidget(d->updEXIFOriDateCheck, 1, 0, 1, 1);
0282     updateGBLayout->addWidget(d->updEXIFModDateCheck, 1, 1, 1, 1);
0283     updateGBLayout->addWidget(d->updEXIFDigDateCheck, 2, 0, 1, 1);
0284     updateGBLayout->addWidget(d->updEXIFThmDateCheck, 2, 1, 1, 1);
0285     updateGBLayout->addWidget(d->updXMPDateCheck,     3, 0, 1, 1);
0286     updateGBLayout->addWidget(d->updXMPVideoCheck,    3, 1, 1, 1);
0287     updateGBLayout->addWidget(d->updIPTCDateCheck,    4, 0, 1, 1);
0288     updateGBLayout->addWidget(d->updFileModDateCheck, 4, 1, 1, 1);
0289     updateGBLayout->setContentsMargins(spacing, spacing, spacing, spacing);
0290     updateGBLayout->setSpacing(spacing);
0291     updateGBLayout->setColumnStretch(0, 1);
0292     updateGBLayout->setColumnStretch(1, 1);
0293 
0294     if (!DMetadata::supportXmp())
0295     {
0296         d->updXMPVideoCheck->setEnabled(false);
0297         d->updXMPDateCheck->setEnabled(false);
0298     }
0299 
0300     // -----------------------------------------------------------------------
0301 
0302     d->settingsExpander->addItem(d->useSettingsBox,    i18n("Timestamp Used"),        QLatin1String("timestampused"),        true);
0303     d->settingsExpander->addItem(d->adjustSettingsBox, i18n("Timestamp Adjustments"), QLatin1String("timestampadjustments"), true);
0304     d->settingsExpander->addItem(d->updateSettingsBox, i18n("Timestamp Updated"),     QLatin1String("timestampupdated"),     true);
0305     d->settingsExpander->addStretch();
0306     d->settingsExpander->setItemIcon(0, QIcon::fromTheme(QLatin1String("document-import")));
0307     d->settingsExpander->setItemIcon(1, QIcon::fromTheme(QLatin1String("document-edit")));
0308     d->settingsExpander->setItemIcon(2, QIcon::fromTheme(QLatin1String("document-export")));
0309 
0310     // -- Settings View Slots/Signals ----------------------------------------
0311 
0312 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
0313 
0314     connect(d->useButtonGroup, SIGNAL(idReleased(int)),
0315             this, SLOT(slotSrcTimestampChanged()));
0316 
0317 #else
0318 
0319     connect(d->useButtonGroup, SIGNAL(buttonReleased(int)),
0320             this, SLOT(slotSrcTimestampChanged()));
0321 
0322 #endif
0323 
0324     connect(d->useFileDateTypeChooser, SIGNAL(currentIndexChanged(int)),
0325             this, SLOT(slotSrcTimestampChanged()));
0326 
0327     connect(d->useMetaDateTypeChooser, SIGNAL(currentIndexChanged(int)),
0328             this, SLOT(slotSrcTimestampChanged()));
0329 
0330     connect(d->adjTypeChooser, SIGNAL(currentIndexChanged(int)),
0331             this, SLOT(slotAdjustmentTypeChanged()));
0332 
0333     connect(d->useCustomDateTodayBtn, SIGNAL(clicked()),
0334             this, SLOT(slotResetDateToCurrent()));
0335 
0336     connect(d->adjDetByClockPhotoBtn, SIGNAL(clicked()),
0337             this, SLOT(slotDetAdjustmentByClockPhotoDialog()));
0338 
0339     connect(d->adjDetByClockPhotoBtn, SIGNAL(signalClockPhotoDropped(QUrl)),
0340             this, SLOT(slotDetAdjustmentByClockPhotoUrl(QUrl)));
0341 
0342     connect(d->useCustDateInput, SIGNAL(editingFinished()),
0343             this, SIGNAL(signalSettingsChanged()));
0344 
0345     connect(d->useCustDateInput, SIGNAL(dateChanged(QDate)),
0346             this, SIGNAL(signalSettingsChangedTool()));
0347 
0348     connect(d->useCustTimeInput, SIGNAL(editingFinished()),
0349             this, SIGNAL(signalSettingsChanged()));
0350 
0351     connect(d->useCustTimeInput, SIGNAL(timeChanged(QTime)),
0352             this, SIGNAL(signalSettingsChangedTool()));
0353 
0354     connect(d->adjDaysInput, SIGNAL(valueChanged(int)),
0355             this, SIGNAL(signalSettingsChanged()));
0356 
0357     connect(d->adjTimeInput, SIGNAL(editingFinished()),
0358             this, SIGNAL(signalSettingsChanged()));
0359 
0360     connect(d->adjTimeInput, SIGNAL(timeChanged(QTime)),
0361             this, SIGNAL(signalSettingsChangedTool()));
0362 
0363     connect(d->updEXIFModDateCheck, SIGNAL(toggled(bool)),
0364             this, SIGNAL(signalSettingsChanged()));
0365 
0366     connect(d->updEXIFOriDateCheck, SIGNAL(toggled(bool)),
0367             this, SIGNAL(signalSettingsChanged()));
0368 
0369     connect(d->updEXIFDigDateCheck, SIGNAL(toggled(bool)),
0370             this, SIGNAL(signalSettingsChanged()));
0371 
0372     connect(d->updEXIFThmDateCheck, SIGNAL(toggled(bool)),
0373             this, SIGNAL(signalSettingsChanged()));
0374 
0375     connect(d->updXMPVideoCheck, SIGNAL(toggled(bool)),
0376             this, SIGNAL(signalSettingsChanged()));
0377 
0378     connect(d->updXMPDateCheck, SIGNAL(toggled(bool)),
0379             this, SIGNAL(signalSettingsChanged()));
0380 
0381     connect(d->updIPTCDateCheck, SIGNAL(toggled(bool)),
0382             this, SIGNAL(signalSettingsChanged()));
0383 
0384     connect(d->updFileModDateCheck, SIGNAL(toggled(bool)),
0385             this, SIGNAL(signalSettingsChanged()));
0386 
0387     connect(d->updIfAvailableCheck, SIGNAL(toggled(bool)),
0388             this, SIGNAL(signalSettingsChanged()));
0389 }
0390 
0391 TimeAdjustSettings::~TimeAdjustSettings()
0392 {
0393     delete d;
0394 }
0395 
0396 void TimeAdjustSettings::setSettings(const TimeAdjustContainer& settings)
0397 {
0398 /*
0399     d->settingsExpander->readSettings(group);
0400 */
0401     int useTimestampType = settings.dateSource;
0402 
0403     if      (useTimestampType == TimeAdjustContainer::APPDATE)
0404     {
0405           d->useApplDateBtn->setChecked(true);
0406     }
0407     else if (useTimestampType == TimeAdjustContainer::FILENAME)
0408     {
0409          d->useFileNameBtn->setChecked(true);
0410     }
0411     else if (useTimestampType == TimeAdjustContainer::FILEDATE)
0412     {
0413          d->useFileDateBtn->setChecked(true);
0414     }
0415     else if (useTimestampType == TimeAdjustContainer::METADATADATE)
0416     {
0417          d->useMetaDateBtn->setChecked(true);
0418     }
0419     else if (useTimestampType == TimeAdjustContainer::CUSTOMDATE)
0420     {
0421          d->useCustomDateBtn->setChecked(true);
0422     }
0423 
0424     d->useFileDateTypeChooser->setCurrentIndex(settings.fileDateSource);
0425     d->useMetaDateTypeChooser->setCurrentIndex(settings.metadataSource);
0426     d->useCustDateInput->setDateTime(settings.customDate);
0427     d->useCustTimeInput->setDateTime(settings.customTime);
0428 
0429     d->adjTypeChooser->setCurrentIndex(settings.adjustmentType);
0430     d->adjDaysInput->setValue(settings.adjustmentDays);
0431     d->adjTimeInput->setDateTime(settings.adjustmentTime);
0432 
0433     d->updIfAvailableCheck->setChecked(settings.updIfAvailable);
0434     d->updFileModDateCheck->setChecked(settings.updFileModDate);
0435     d->updEXIFModDateCheck->setChecked(settings.updEXIFModDate);
0436     d->updEXIFOriDateCheck->setChecked(settings.updEXIFOriDate);
0437     d->updEXIFDigDateCheck->setChecked(settings.updEXIFDigDate);
0438     d->updEXIFThmDateCheck->setChecked(settings.updEXIFThmDate);
0439     d->updIPTCDateCheck->setChecked(settings.updIPTCDate);
0440     d->updXMPVideoCheck->setChecked(settings.updXMPVideo);
0441     d->updXMPDateCheck->setChecked(settings.updXMPDate);
0442 
0443     slotSrcTimestampChanged();
0444     slotAdjustmentTypeChanged();
0445 }
0446 
0447 TimeAdjustContainer TimeAdjustSettings::settings() const
0448 {
0449     TimeAdjustContainer settings;
0450 
0451     settings.customDate     = d->useCustDateInput->dateTime();
0452     settings.customTime     = d->useCustTimeInput->dateTime();
0453 
0454     settings.adjustmentType = d->adjTypeChooser->currentIndex();
0455     settings.adjustmentDays = d->adjDaysInput->value();
0456     settings.adjustmentTime = d->adjTimeInput->dateTime();
0457 
0458     settings.updIfAvailable = d->updIfAvailableCheck->isChecked();
0459     settings.updFileModDate = d->updFileModDateCheck->isChecked();
0460     settings.updEXIFModDate = d->updEXIFModDateCheck->isChecked();
0461     settings.updEXIFOriDate = d->updEXIFOriDateCheck->isChecked();
0462     settings.updEXIFDigDate = d->updEXIFDigDateCheck->isChecked();
0463     settings.updEXIFThmDate = d->updEXIFThmDateCheck->isChecked();
0464     settings.updIPTCDate    = d->updIPTCDateCheck->isChecked();
0465     settings.updXMPVideo    = d->updXMPVideoCheck->isChecked();
0466     settings.updXMPDate     = d->updXMPDateCheck->isChecked();
0467     settings.dateSource     = TimeAdjustContainer::APPDATE;
0468 
0469     if (d->useFileNameBtn->isChecked())
0470     {
0471        settings.dateSource = TimeAdjustContainer::FILENAME;
0472     }
0473 
0474     if (d->useFileDateBtn->isChecked())
0475     {
0476        settings.dateSource = TimeAdjustContainer::FILEDATE;
0477     }
0478 
0479     if (d->useMetaDateBtn->isChecked())
0480     {
0481        settings.dateSource = TimeAdjustContainer::METADATADATE;
0482     }
0483 
0484     if (d->useCustomDateBtn->isChecked())
0485     {
0486        settings.dateSource = TimeAdjustContainer::CUSTOMDATE;
0487     }
0488 
0489     settings.metadataSource = d->useMetaDateTypeChooser->currentIndex();
0490     settings.fileDateSource = d->useFileDateTypeChooser->currentIndex();
0491 
0492     return settings;
0493 }
0494 
0495 void TimeAdjustSettings::detAdjustmentByClockPhotoUrl(const QUrl& url)
0496 {
0497     /**
0498      * When user press the clock photo button, a dialog is displayed and set the
0499      * results to the proper widgets.
0500      */
0501     QPointer<ClockPhotoDialog> dlg = new ClockPhotoDialog(this, url);
0502     const int result               = dlg->exec();
0503 
0504     if (result == QDialog::Accepted)
0505     {
0506         DeltaTime dvalues = dlg->deltaValues();
0507 
0508         if      (dvalues.isNull())
0509         {
0510             d->adjTypeChooser->setCurrentIndex(TimeAdjustContainer::COPYVALUE);
0511         }
0512         else if (dvalues.deltaNegative)
0513         {
0514             d->adjTypeChooser->setCurrentIndex(TimeAdjustContainer::SUBVALUE);
0515         }
0516         else
0517         {
0518             d->adjTypeChooser->setCurrentIndex(TimeAdjustContainer::ADDVALUE);
0519         }
0520 
0521         d->adjDaysInput->setValue(dvalues.deltaDays);
0522         QTime deltaTime;
0523         deltaTime.setHMS(dvalues.deltaHours, dvalues.deltaMinutes, dvalues.deltaSeconds);
0524         d->adjTimeInput->setTime(deltaTime);
0525 
0526         Q_EMIT signalSettingsChanged();
0527     }
0528 
0529     delete dlg;
0530 }
0531 
0532 void TimeAdjustSettings::slotSrcTimestampChanged()
0533 {
0534     d->useFileDateTypeChooser->setEnabled(false);
0535     d->useMetaDateTypeChooser->setEnabled(false);
0536     d->useCustDateInput->setEnabled(false);
0537     d->useCustTimeInput->setEnabled(false);
0538     d->useCustomDateTodayBtn->setEnabled(false);
0539 
0540     if      (d->useFileDateBtn->isChecked())
0541     {
0542         d->useFileDateTypeChooser->setEnabled(true);
0543     }
0544     else if (d->useMetaDateBtn->isChecked())
0545     {
0546         d->useMetaDateTypeChooser->setEnabled(true);
0547     }
0548     else if (d->useCustomDateBtn->isChecked())
0549     {
0550         d->useCustDateInput->setEnabled(true);
0551         d->useCustTimeInput->setEnabled(true);
0552         d->useCustomDateTodayBtn->setEnabled(true);
0553     }
0554 
0555     Q_EMIT signalSettingsChanged();
0556 }
0557 
0558 void TimeAdjustSettings::slotResetDateToCurrent()
0559 {
0560     QDateTime currentDateTime(QDateTime::currentDateTime());
0561     currentDateTime.setTimeSpec(Qt::UTC);
0562     d->useCustDateInput->setDateTime(currentDateTime);
0563     d->useCustTimeInput->setDateTime(currentDateTime);
0564 
0565     Q_EMIT signalSettingsChanged();
0566 }
0567 
0568 void TimeAdjustSettings::slotAdjustmentTypeChanged()
0569 {
0570     // If the addition or subtraction has been selected, enable the edit boxes to enter the adjustment length
0571 
0572     bool isAdjustment = (d->adjTypeChooser->currentIndex() > TimeAdjustContainer::COPYVALUE);
0573     d->adjDaysInput->setEnabled(isAdjustment);
0574     d->adjDaysLabel->setEnabled(isAdjustment);
0575     d->adjTimeInput->setEnabled(isAdjustment);
0576 
0577     Q_EMIT signalSettingsChanged();
0578 }
0579 
0580 void TimeAdjustSettings::slotDetAdjustmentByClockPhotoUrl(const QUrl& url)
0581 {
0582     //usually called when a photo is dropped onto the push button
0583 
0584     detAdjustmentByClockPhotoUrl(url);
0585 }
0586 
0587 void TimeAdjustSettings::slotDetAdjustmentByClockPhotoDialog()
0588 {
0589     detAdjustmentByClockPhotoUrl(d->currentItemUrl);
0590 }
0591 
0592 void TimeAdjustSettings::setCurrentItemUrl(const QUrl& url)
0593 {
0594     d->currentItemUrl = url;
0595 }
0596 
0597 } // namespace Digikam
0598 
0599 #include "moc_timeadjustsettings.cpp"