File indexing completed on 2025-01-19 03:51:24

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-10-13
0007  * Description : IPTC origin settings page.
0008  *
0009  * SPDX-FileCopyrightText: 2006-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 "iptcorigin.h"
0016 
0017 // Qt includes
0018 
0019 #include <QCheckBox>
0020 #include <QLabel>
0021 #include <QMap>
0022 #include <QPushButton>
0023 #include <QTimeEdit>
0024 #include <QGridLayout>
0025 #include <QApplication>
0026 #include <QStyle>
0027 #include <QComboBox>
0028 #include <QDateEdit>
0029 #include <QLineEdit>
0030 #include <QToolTip>
0031 
0032 // KDE includes
0033 
0034 #include <klocalizedstring.h>
0035 
0036 // Local includes
0037 
0038 #include "dlayoutbox.h"
0039 #include "squeezedcombobox.h"
0040 #include "metadatacheckbox.h"
0041 #include "timezonecombobox.h"
0042 #include "multivaluesedit.h"
0043 #include "countryselector.h"
0044 #include "dexpanderbox.h"
0045 
0046 namespace DigikamGenericMetadataEditPlugin
0047 {
0048 
0049 class Q_DECL_HIDDEN IPTCOrigin::Private
0050 {
0051 public:
0052 
0053     explicit Private()
0054       : dateCreatedCheck(nullptr),
0055         dateDigitalizedCheck(nullptr),
0056         timeCreatedCheck(nullptr),
0057         timeDigitalizedCheck(nullptr),
0058         syncEXIFDateCheck(nullptr),
0059         cityCheck(nullptr),
0060         sublocationCheck(nullptr),
0061         provinceCheck(nullptr),
0062         timeCreatedSel(nullptr),
0063         timeDigitalizedSel(nullptr),
0064         zoneCreatedSel(nullptr),
0065         zoneDigitalizedSel(nullptr),
0066         setTodayCreatedBtn(nullptr),
0067         setTodayDigitalizedBtn(nullptr),
0068         dateCreatedSel(nullptr),
0069         dateDigitalizedSel(nullptr),
0070         cityEdit(nullptr),
0071         sublocationEdit(nullptr),
0072         provinceEdit(nullptr),
0073         locationEdit(nullptr),
0074         countryCheck(nullptr),
0075         countryCB(nullptr)
0076     {
0077     }
0078 
0079     QCheckBox*                     dateCreatedCheck;
0080     QCheckBox*                     dateDigitalizedCheck;
0081     QCheckBox*                     timeCreatedCheck;
0082     QCheckBox*                     timeDigitalizedCheck;
0083     QCheckBox*                     syncEXIFDateCheck;
0084     QCheckBox*                     cityCheck;
0085     QCheckBox*                     sublocationCheck;
0086     QCheckBox*                     provinceCheck;
0087 
0088     QTimeEdit*                     timeCreatedSel;
0089     QTimeEdit*                     timeDigitalizedSel;
0090 
0091     TimeZoneComboBox*              zoneCreatedSel;
0092     TimeZoneComboBox*              zoneDigitalizedSel;
0093 
0094     QPushButton*                   setTodayCreatedBtn;
0095     QPushButton*                   setTodayDigitalizedBtn;
0096 
0097     QDateEdit*                     dateCreatedSel;
0098     QDateEdit*                     dateDigitalizedSel;
0099 
0100     QLineEdit*                     cityEdit;
0101     QLineEdit*                     sublocationEdit;
0102     QLineEdit*                     provinceEdit;
0103 
0104     MultiValuesEdit*               locationEdit;
0105 
0106     MetadataCheckBox*              countryCheck;
0107 
0108     CountrySelector*               countryCB;
0109 };
0110 
0111 IPTCOrigin::IPTCOrigin(QWidget* const parent)
0112     : MetadataEditPage(parent),
0113       d               (new Private)
0114 {
0115     QGridLayout* const grid = new QGridLayout(widget());
0116     QString dateFormat      = QLocale().dateFormat(QLocale::ShortFormat);
0117 
0118     if (!dateFormat.contains(QLatin1String("yyyy")))
0119     {
0120         dateFormat.replace(QLatin1String("yy"),
0121                            QLatin1String("yyyy"));
0122     }
0123 
0124     QString timeFormat = QLatin1String("hh:mm:ss");
0125 
0126     // --------------------------------------------------------
0127 
0128     d->dateDigitalizedCheck   = new QCheckBox(i18n("Digitization date"), this);
0129     d->timeDigitalizedCheck   = new QCheckBox(i18n("Digitization time"), this);
0130     d->zoneDigitalizedSel     = new TimeZoneComboBox(this);
0131 
0132     d->dateDigitalizedSel     = new QDateEdit(this);
0133     d->dateDigitalizedSel->setDisplayFormat(dateFormat);
0134 
0135     d->timeDigitalizedSel     = new QTimeEdit(this);
0136     d->timeDigitalizedSel->setDisplayFormat(timeFormat);
0137 
0138     d->setTodayDigitalizedBtn = new QPushButton();
0139     d->setTodayDigitalizedBtn->setIcon(QIcon::fromTheme(QLatin1String("view-calendar")));
0140     d->setTodayDigitalizedBtn->setWhatsThis(i18n("Set digitization date to today"));
0141 
0142     d->dateDigitalizedSel->setWhatsThis(i18n("Set here the creation date of "
0143                                              "digital representation."));
0144     d->timeDigitalizedSel->setWhatsThis(i18n("Set here the creation time of "
0145                                              "digital representation."));
0146     d->zoneDigitalizedSel->setWhatsThis(i18n("Set here the time zone of "
0147                                              "digital representation."));
0148 
0149     slotSetTodayDigitalized();
0150 
0151     // --------------------------------------------------------
0152 
0153     d->dateCreatedCheck   = new QCheckBox(i18n("Creation date"), this);
0154     d->timeCreatedCheck   = new QCheckBox(i18n("Creation time"), this);
0155     d->zoneCreatedSel     = new TimeZoneComboBox(this);
0156 
0157     d->dateCreatedSel     = new QDateEdit(this);
0158     d->dateCreatedSel->setDisplayFormat(dateFormat);
0159 
0160     d->timeCreatedSel     = new QTimeEdit(this);
0161     d->timeCreatedSel->setDisplayFormat(timeFormat);
0162 
0163     d->syncEXIFDateCheck  = new QCheckBox(i18n("Sync Exif creation date"), this);
0164 
0165     d->setTodayCreatedBtn = new QPushButton();
0166     d->setTodayCreatedBtn->setIcon(QIcon::fromTheme(QLatin1String("view-calendar")));
0167     d->setTodayCreatedBtn->setWhatsThis(i18n("Set creation date to today"));
0168 
0169     d->dateCreatedSel->setWhatsThis(i18n("Set here the creation date of "
0170                                          "intellectual content."));
0171     d->timeCreatedSel->setWhatsThis(i18n("Set here the creation time of "
0172                                          "intellectual content."));
0173     d->zoneCreatedSel->setWhatsThis(i18n("Set here the time zone of "
0174                                          "intellectual content."));
0175 
0176     slotSetTodayCreated();
0177 
0178     // --------------------------------------------------------
0179 
0180     d->locationEdit = new MultiValuesEdit(this, i18n("Location:"),
0181                           i18n("Set here the full country name referenced by the content."));
0182 
0183     // --------------------------------------------------------
0184 
0185     d->cityCheck = new QCheckBox(i18n("City:"), this);
0186     d->cityEdit  = new QLineEdit(this);
0187     d->cityEdit->setClearButtonEnabled(true);
0188     d->cityEdit->setMaxLength(32);
0189     d->cityEdit->setPlaceholderText(i18n("Set here the city of the content"));
0190     d->cityEdit->setWhatsThis(i18n("Set here the city of content origin. "
0191                                    "This field is limited to 32 characters."));
0192 
0193     // --------------------------------------------------------
0194 
0195     d->sublocationCheck = new QCheckBox(i18n("Sublocation:"), this);
0196     d->sublocationEdit  = new QLineEdit(this);
0197     d->sublocationEdit->setClearButtonEnabled(true);
0198     d->sublocationEdit->setMaxLength(32);
0199     d->sublocationEdit->setPlaceholderText(i18n("Set here the content location"));
0200     d->sublocationEdit->setWhatsThis(i18n("Set here the content location within city. "
0201                                           "This field is limited to 32 characters."));
0202 
0203     // --------------------------------------------------------
0204 
0205     d->provinceCheck = new QCheckBox(i18n("State/Province:"), this);
0206     d->provinceEdit  = new QLineEdit(this);
0207     d->provinceEdit->setClearButtonEnabled(true);
0208     d->provinceEdit->setMaxLength(32);
0209     d->provinceEdit->setPlaceholderText(i18n("Set here the Province or State of the content"));
0210     d->provinceEdit->setWhatsThis(i18n("Set here the Province or State of content origin. "
0211                                        "This field is limited to 32 characters."));
0212 
0213     // --------------------------------------------------------
0214 
0215     d->countryCheck = new MetadataCheckBox(i18n("Country:"), this);
0216     d->countryCB    = new CountrySelector(this);
0217     d->countryCB->setWhatsThis(i18n("Select here country name of content origin."));
0218 
0219     // Remove 2 last items for the list (separator + Unknown item)
0220 
0221     d->countryCB->removeItem(d->countryCB->count()-1);
0222     d->countryCB->removeItem(d->countryCB->count()-1);
0223 
0224     QStringList list;
0225 
0226     for (int i = 0 ; i < d->countryCB->count() ; ++i)
0227     {
0228         list.append(d->countryCB->itemText(i));
0229     }
0230 
0231     d->locationEdit->setData(list);
0232 
0233     // --------------------------------------------------------
0234 
0235     QLabel* const note = new QLabel(i18n("<b>Note: "
0236                  "<a href='https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model'>IPTC</a> "
0237                  "text tags are limited string sizes. Use contextual help for details. "
0238                  "Consider to use <a href='https://en.wikipedia.org/wiki/Extensible_Metadata_Platform'>XMP</a> instead.</b>"),
0239                  this);
0240     note->setOpenExternalLinks(true);
0241     note->setWordWrap(true);
0242     note->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0243 
0244     // --------------------------------------------------------
0245 
0246     grid->addWidget(d->dateDigitalizedCheck,                0, 0, 1, 2);
0247     grid->addWidget(d->timeDigitalizedCheck,                0, 2, 1, 2);
0248     grid->addWidget(d->dateDigitalizedSel,                  1, 0, 1, 2);
0249     grid->addWidget(d->timeDigitalizedSel,                  1, 2, 1, 1);
0250     grid->addWidget(d->zoneDigitalizedSel,                  1, 3, 1, 1);
0251     grid->addWidget(d->setTodayDigitalizedBtn,              1, 5, 1, 1);
0252     grid->addWidget(d->dateCreatedCheck,                    2, 0, 1, 2);
0253     grid->addWidget(d->timeCreatedCheck,                    2, 2, 1, 2);
0254     grid->addWidget(d->dateCreatedSel,                      3, 0, 1, 2);
0255     grid->addWidget(d->timeCreatedSel,                      3, 2, 1, 1);
0256     grid->addWidget(d->zoneCreatedSel,                      3, 3, 1, 1);
0257     grid->addWidget(d->setTodayCreatedBtn,                  3, 5, 1, 1);
0258     grid->addWidget(d->syncEXIFDateCheck,                   5, 0, 1, 6);
0259     grid->addWidget(d->locationEdit,                        6, 0, 1, 6);
0260     grid->addWidget(new DLineWidget(Qt::Horizontal, this),  7, 0, 1, 6);
0261     grid->addWidget(d->cityCheck,                           8, 0, 1, 1);
0262     grid->addWidget(d->cityEdit,                            8, 1, 1, 5);
0263     grid->addWidget(d->sublocationCheck,                    9, 0, 1, 1);
0264     grid->addWidget(d->sublocationEdit,                     9, 1, 1, 5);
0265     grid->addWidget(d->provinceCheck,                      10, 0, 1, 1);
0266     grid->addWidget(d->provinceEdit,                       10, 1, 1, 5);
0267     grid->addWidget(d->countryCheck,                       11, 0, 1, 1);
0268     grid->addWidget(d->countryCB,                          11, 1, 1, 5);
0269     grid->addWidget(note,                                  12, 0, 1, 6);
0270     grid->setColumnStretch(4, 10);
0271     grid->setRowStretch(13, 10);
0272 
0273     int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0274                        QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0275 
0276     grid->setContentsMargins(spacing, spacing, spacing, spacing);
0277     grid->setSpacing(spacing);
0278 
0279     // --------------------------------------------------------
0280 
0281     connect(d->dateCreatedCheck, SIGNAL(toggled(bool)),
0282             d->dateCreatedSel, SLOT(setEnabled(bool)));
0283 
0284     connect(d->dateDigitalizedCheck, SIGNAL(toggled(bool)),
0285             d->dateDigitalizedSel, SLOT(setEnabled(bool)));
0286 
0287     connect(d->timeCreatedCheck, SIGNAL(toggled(bool)),
0288             d->timeCreatedSel, SLOT(setEnabled(bool)));
0289 
0290     connect(d->timeDigitalizedCheck, SIGNAL(toggled(bool)),
0291             d->timeDigitalizedSel, SLOT(setEnabled(bool)));
0292 
0293     connect(d->timeCreatedCheck, SIGNAL(toggled(bool)),
0294             d->zoneCreatedSel, SLOT(setEnabled(bool)));
0295 
0296     connect(d->timeDigitalizedCheck, SIGNAL(toggled(bool)),
0297             d->zoneDigitalizedSel, SLOT(setEnabled(bool)));
0298 
0299     connect(d->dateCreatedCheck, SIGNAL(toggled(bool)),
0300             d->syncEXIFDateCheck, SLOT(setEnabled(bool)));
0301 
0302     connect(d->cityCheck, SIGNAL(toggled(bool)),
0303             d->cityEdit, SLOT(setEnabled(bool)));
0304 
0305     connect(d->sublocationCheck, SIGNAL(toggled(bool)),
0306             d->sublocationEdit, SLOT(setEnabled(bool)));
0307 
0308     connect(d->provinceCheck, SIGNAL(toggled(bool)),
0309             d->provinceEdit, SLOT(setEnabled(bool)));
0310 
0311     connect(d->countryCheck, SIGNAL(toggled(bool)),
0312             d->countryCB, SLOT(setEnabled(bool)));
0313 
0314     // --------------------------------------------------------
0315 
0316     connect(d->dateCreatedCheck, SIGNAL(toggled(bool)),
0317             this, SIGNAL(signalModified()));
0318 
0319     connect(d->dateDigitalizedCheck, SIGNAL(toggled(bool)),
0320             this, SIGNAL(signalModified()));
0321 
0322     connect(d->timeCreatedCheck, SIGNAL(toggled(bool)),
0323             this, SIGNAL(signalModified()));
0324 
0325     connect(d->timeDigitalizedCheck, SIGNAL(toggled(bool)),
0326             this, SIGNAL(signalModified()));
0327 
0328     connect(d->cityCheck, SIGNAL(toggled(bool)),
0329             this, SIGNAL(signalModified()));
0330 
0331     connect(d->sublocationCheck, SIGNAL(toggled(bool)),
0332             this, SIGNAL(signalModified()));
0333 
0334     connect(d->provinceCheck, SIGNAL(toggled(bool)),
0335             this, SIGNAL(signalModified()));
0336 
0337     connect(d->countryCheck, SIGNAL(toggled(bool)),
0338             this, SIGNAL(signalModified()));
0339 
0340     connect(d->locationEdit, SIGNAL(signalModified()),
0341             this, SIGNAL(signalModified()));
0342 
0343     // --------------------------------------------------------
0344 
0345     connect(d->dateCreatedSel, SIGNAL(dateChanged(QDate)),
0346             this, SIGNAL(signalModified()));
0347 
0348     connect(d->dateDigitalizedSel, SIGNAL(dateChanged(QDate)),
0349             this, SIGNAL(signalModified()));
0350 
0351     connect(d->timeCreatedSel, SIGNAL(timeChanged(QTime)),
0352             this, SIGNAL(signalModified()));
0353 
0354     connect(d->timeDigitalizedSel, SIGNAL(timeChanged(QTime)),
0355             this, SIGNAL(signalModified()));
0356 
0357     connect(d->zoneCreatedSel, SIGNAL(currentTextChanged(QString)),
0358             this, SIGNAL(signalModified()));
0359 
0360     connect(d->zoneDigitalizedSel, SIGNAL(currentTextChanged(QString)),
0361             this, SIGNAL(signalModified()));
0362 
0363     // --------------------------------------------------------
0364 
0365     connect(d->setTodayCreatedBtn, SIGNAL(clicked()),
0366             this, SLOT(slotSetTodayCreated()));
0367 
0368     connect(d->setTodayDigitalizedBtn, SIGNAL(clicked()),
0369             this, SLOT(slotSetTodayDigitalized()));
0370 
0371     // --------------------------------------------------------
0372 
0373     connect(d->countryCB, SIGNAL(activated(int)),
0374             this, SIGNAL(signalModified()));
0375 
0376     connect(d->cityEdit, SIGNAL(textChanged(QString)),
0377             this, SIGNAL(signalModified()));
0378 
0379     connect(d->cityEdit, SIGNAL(textChanged(QString)),
0380             this, SLOT(slotLineEditModified()));
0381 
0382     connect(d->sublocationEdit, SIGNAL(textChanged(QString)),
0383             this, SIGNAL(signalModified()));
0384 
0385     connect(d->sublocationEdit, SIGNAL(textChanged(QString)),
0386             this, SLOT(slotLineEditModified()));
0387 
0388     connect(d->provinceEdit, SIGNAL(textChanged(QString)),
0389             this, SIGNAL(signalModified()));
0390 
0391     connect(d->provinceEdit, SIGNAL(textChanged(QString)),
0392             this, SLOT(slotLineEditModified()));
0393 }
0394 
0395 IPTCOrigin::~IPTCOrigin()
0396 {
0397     delete d;
0398 }
0399 
0400 void IPTCOrigin::slotSetTodayCreated()
0401 {
0402     d->dateCreatedSel->setDate(QDate::currentDate());
0403     d->timeCreatedSel->setTime(QTime::currentTime());
0404     d->zoneCreatedSel->setToUTC();
0405 }
0406 
0407 void IPTCOrigin::slotSetTodayDigitalized()
0408 {
0409     d->dateDigitalizedSel->setDate(QDate::currentDate());
0410     d->timeDigitalizedSel->setTime(QTime::currentTime());
0411     d->zoneDigitalizedSel->setToUTC();
0412 }
0413 
0414 bool IPTCOrigin::syncEXIFDateIsChecked() const
0415 {
0416     return d->syncEXIFDateCheck->isChecked();
0417 }
0418 
0419 void IPTCOrigin::setCheckedSyncEXIFDate(bool c)
0420 {
0421     d->syncEXIFDateCheck->setChecked(c);
0422 }
0423 
0424 QDateTime IPTCOrigin::getIPTCCreationDate() const
0425 {
0426     return QDateTime(d->dateCreatedSel->date(), d->timeCreatedSel->time());
0427 }
0428 
0429 void IPTCOrigin::slotLineEditModified()
0430 {
0431     QLineEdit* const ledit = dynamic_cast<QLineEdit*>(sender());
0432 
0433     if (!ledit)
0434     {
0435         return;
0436     }
0437 
0438     QToolTip::showText(ledit->mapToGlobal(QPoint(0, (-1)*(ledit->height() + 16))),
0439                        i18np("%1 character left", "%1 characters left", ledit->maxLength() - ledit->text().size()),
0440                        ledit);
0441 }
0442 
0443 void IPTCOrigin::readMetadata(const DMetadata& meta)
0444 {
0445     blockSignals(true);
0446 
0447     QString     data;
0448     QStringList code, list;
0449     QDate       date;
0450     QTime       time;
0451     QString     dateStr, timeStr;
0452 
0453     dateStr = meta.getIptcTagString("Iptc.Application2.DateCreated", false);
0454     timeStr = meta.getIptcTagString("Iptc.Application2.TimeCreated", false);
0455 
0456     d->dateCreatedSel->setDate(QDate::currentDate());
0457     d->dateCreatedCheck->setChecked(false);
0458 
0459     if (!dateStr.isEmpty())
0460     {
0461         date = QDate::fromString(dateStr, Qt::ISODate);
0462 
0463         if (date.isValid())
0464         {
0465             d->dateCreatedSel->setDate(date);
0466             d->dateCreatedCheck->setChecked(true);
0467         }
0468     }
0469 
0470     d->dateCreatedSel->setEnabled(d->dateCreatedCheck->isChecked());
0471     d->syncEXIFDateCheck->setEnabled(d->dateCreatedCheck->isChecked());
0472 
0473     d->timeCreatedSel->setTime(QTime::currentTime());
0474     d->timeCreatedCheck->setChecked(false);
0475     d->zoneCreatedSel->setToUTC();
0476 
0477     if (!timeStr.isEmpty())
0478     {
0479         time = QTime::fromString(timeStr, Qt::ISODate);
0480 
0481         if (time.isValid())
0482         {
0483             d->timeCreatedSel->setTime(time);
0484             d->timeCreatedCheck->setChecked(true);
0485             d->zoneCreatedSel->setTimeZone(timeStr);
0486         }
0487     }
0488 
0489     d->timeCreatedSel->setEnabled(d->timeCreatedCheck->isChecked());
0490     d->zoneCreatedSel->setEnabled(d->timeCreatedCheck->isChecked());
0491 
0492     dateStr = meta.getIptcTagString("Iptc.Application2.DigitizationDate", false);
0493     timeStr = meta.getIptcTagString("Iptc.Application2.DigitizationTime", false);
0494 
0495     d->dateDigitalizedSel->setDate(QDate::currentDate());
0496     d->dateDigitalizedCheck->setChecked(false);
0497 
0498     if (!dateStr.isEmpty())
0499     {
0500         date = QDate::fromString(dateStr, Qt::ISODate);
0501 
0502         if (date.isValid())
0503         {
0504             d->dateDigitalizedSel->setDate(date);
0505             d->dateDigitalizedCheck->setChecked(true);
0506         }
0507     }
0508 
0509     d->dateDigitalizedSel->setEnabled(d->dateDigitalizedCheck->isChecked());
0510 
0511     d->timeDigitalizedSel->setTime(QTime::currentTime());
0512     d->timeDigitalizedCheck->setChecked(false);
0513     d->zoneDigitalizedSel->setToUTC();
0514 
0515     if (!timeStr.isEmpty())
0516     {
0517         time = QTime::fromString(timeStr, Qt::ISODate);
0518 
0519         if (time.isValid())
0520         {
0521             d->timeDigitalizedSel->setTime(time);
0522             d->timeDigitalizedCheck->setChecked(true);
0523             d->zoneDigitalizedSel->setTimeZone(timeStr);
0524         }
0525     }
0526 
0527     d->timeDigitalizedSel->setEnabled(d->timeDigitalizedCheck->isChecked());
0528     d->zoneDigitalizedSel->setEnabled(d->timeDigitalizedCheck->isChecked());
0529 
0530     code = meta.getIptcTagsStringList("Iptc.Application2.LocationCode", false);
0531 
0532     for (QStringList::Iterator it = code.begin(); it != code.end(); ++it)
0533     {
0534         QStringList lst = d->locationEdit->getData();
0535         QStringList::Iterator it2;
0536 
0537         for (it2 = lst.begin() ; it2 != lst.end() ; ++it2)
0538         {
0539             if ((*it2).left(3) == (*it))
0540             {
0541                 list.append(*it2);
0542                 break;
0543             }
0544         }
0545 
0546         if (it2 == lst.end())
0547         {
0548             d->locationEdit->setValid(false);
0549         }
0550     }
0551 
0552     d->locationEdit->setValues(list);
0553 
0554     d->cityEdit->clear();
0555     d->cityCheck->setChecked(false);
0556     data = meta.getIptcTagString("Iptc.Application2.City", false);
0557 
0558     if (!data.isNull())
0559     {
0560         d->cityEdit->setText(data);
0561         d->cityCheck->setChecked(true);
0562     }
0563 
0564     d->cityEdit->setEnabled(d->cityCheck->isChecked());
0565 
0566     d->sublocationEdit->clear();
0567     d->sublocationCheck->setChecked(false);
0568     data = meta.getIptcTagString("Iptc.Application2.SubLocation", false);
0569 
0570     if (!data.isNull())
0571     {
0572         d->sublocationEdit->setText(data);
0573         d->sublocationCheck->setChecked(true);
0574     }
0575 
0576     d->sublocationEdit->setEnabled(d->sublocationCheck->isChecked());
0577 
0578     d->provinceEdit->clear();
0579     d->provinceCheck->setChecked(false);
0580     data = meta.getIptcTagString("Iptc.Application2.ProvinceState", false);
0581 
0582     if (!data.isNull())
0583     {
0584         d->provinceEdit->setText(data);
0585         d->provinceCheck->setChecked(true);
0586     }
0587 
0588     d->provinceEdit->setEnabled(d->provinceCheck->isChecked());
0589 
0590     d->countryCB->setCurrentIndex(0);
0591     d->countryCheck->setChecked(false);
0592     data = meta.getIptcTagString("Iptc.Application2.CountryCode", false);
0593 
0594     if (!data.isNull())
0595     {
0596         int item = -1;
0597 
0598         for (int i = 0 ; i < d->countryCB->count() ; ++i)
0599         {
0600             if (d->countryCB->itemText(i).left(3) == data)
0601             {
0602                 item = i;
0603             }
0604         }
0605 
0606         if (item != -1)
0607         {
0608             d->countryCB->setCurrentIndex(item);
0609             d->countryCheck->setChecked(true);
0610         }
0611         else
0612         {
0613             d->countryCheck->setValid(false);
0614         }
0615     }
0616 
0617     d->countryCB->setEnabled(d->countryCheck->isChecked());
0618 
0619     blockSignals(false);
0620 }
0621 
0622 void IPTCOrigin::applyMetadata(const DMetadata& meta)
0623 {
0624     if (d->dateCreatedCheck->isChecked())
0625     {
0626         meta.setIptcTagString("Iptc.Application2.DateCreated", getIPTCCreationDate().toString(Qt::ISODate));
0627 
0628         if (syncEXIFDateIsChecked())
0629         {
0630             meta.setExifTagString("Exif.Image.DateTime",
0631                                   getIPTCCreationDate().toString(QLatin1String("yyyy:MM:dd hh:mm:ss")));
0632         }
0633     }
0634     else
0635     {
0636         meta.removeIptcTag("Iptc.Application2.DateCreated");
0637     }
0638 
0639     if (d->dateDigitalizedCheck->isChecked())
0640     {
0641         meta.setIptcTagString("Iptc.Application2.DigitizationDate", d->dateDigitalizedSel->date().toString(Qt::ISODate));
0642     }
0643     else
0644     {
0645         meta.removeIptcTag("Iptc.Application2.DigitizationDate");
0646     }
0647 
0648     if (d->timeCreatedCheck->isChecked())
0649     {
0650         meta.setIptcTagString("Iptc.Application2.TimeCreated", d->timeCreatedSel->time().toString(Qt::ISODate) +
0651                                                                d->zoneCreatedSel->getTimeZone());
0652     }
0653     else
0654     {
0655         meta.removeIptcTag("Iptc.Application2.TimeCreated");
0656     }
0657 
0658     if (d->timeDigitalizedCheck->isChecked())
0659     {
0660         meta.setIptcTagString("Iptc.Application2.DigitizationTime", d->timeDigitalizedSel->time().toString(Qt::ISODate) +
0661                                                                     d->zoneDigitalizedSel->getTimeZone());
0662     }
0663     else
0664     {
0665         meta.removeIptcTag("Iptc.Application2.DigitizationTime");
0666     }
0667 
0668     QStringList oldList, newList;
0669 
0670     if (d->locationEdit->getValues(oldList, newList))
0671     {
0672         QStringList oldCode, newCode, oldName, newName;
0673 
0674         for (QStringList::Iterator it = oldList.begin() ; it != oldList.end() ; ++it)
0675         {
0676             oldCode.append((*it).left(3));
0677             oldName.append((*it).mid(6));
0678         }
0679 
0680         for (QStringList::Iterator it2 = newList.begin() ; it2 != newList.end() ; ++it2)
0681         {
0682             newCode.append((*it2).left(3));
0683             newName.append((*it2).mid(6));
0684         }
0685 
0686         meta.setIptcTagsStringList("Iptc.Application2.LocationCode", 3, oldCode, newCode);
0687         meta.setIptcTagsStringList("Iptc.Application2.LocationName", 64, oldName, newName);
0688     }
0689     else
0690     {
0691         meta.removeIptcTag("Iptc.Application2.LocationCode");
0692         meta.removeIptcTag("Iptc.Application2.LocationName");
0693     }
0694 
0695     if (d->cityCheck->isChecked())
0696     {
0697         meta.setIptcTagString("Iptc.Application2.City", d->cityEdit->text());
0698     }
0699     else
0700     {
0701         meta.removeIptcTag("Iptc.Application2.City");
0702     }
0703 
0704     if (d->sublocationCheck->isChecked())
0705     {
0706         meta.setIptcTagString("Iptc.Application2.SubLocation", d->sublocationEdit->text());
0707     }
0708     else
0709     {
0710         meta.removeIptcTag("Iptc.Application2.SubLocation");
0711     }
0712 
0713     if (d->provinceCheck->isChecked())
0714     {
0715         meta.setIptcTagString("Iptc.Application2.ProvinceState", d->provinceEdit->text());
0716     }
0717     else
0718     {
0719         meta.removeIptcTag("Iptc.Application2.ProvinceState");
0720     }
0721 
0722     if      (d->countryCheck->isChecked())
0723     {
0724         QString countryName = d->countryCB->currentText().mid(6);
0725         QString countryCode = d->countryCB->currentText().left(3);
0726         meta.setIptcTagString("Iptc.Application2.CountryCode", countryCode);
0727         meta.setIptcTagString("Iptc.Application2.CountryName", countryName);
0728     }
0729     else if (d->countryCheck->isValid())
0730     {
0731         meta.removeIptcTag("Iptc.Application2.CountryCode");
0732         meta.removeIptcTag("Iptc.Application2.CountryName");
0733     }
0734 }
0735 
0736 } // namespace DigikamGenericMetadataEditPlugin
0737 
0738 #include "moc_iptcorigin.cpp"