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        : 2007-11-10
0007  * Description : IPTC workflow status properties settings page.
0008  *
0009  * SPDX-FileCopyrightText: 2007-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 "iptcproperties.h"
0016 
0017 // Qt includes
0018 
0019 #include <QCheckBox>
0020 #include <QLabel>
0021 #include <QPushButton>
0022 #include <QTimeEdit>
0023 #include <QGridLayout>
0024 #include <QLineEdit>
0025 #include <QComboBox>
0026 #include <QDateEdit>
0027 #include <QApplication>
0028 #include <QStyle>
0029 #include <QToolTip>
0030 
0031 // KDE includes
0032 
0033 #include <klocalizedstring.h>
0034 
0035 // Local includes
0036 
0037 #include "dlayoutbox.h"
0038 #include "metadatacheckbox.h"
0039 #include "timezonecombobox.h"
0040 #include "objectattributesedit.h"
0041 #include "dexpanderbox.h"
0042 #include "dtextedit.h"
0043 
0044 namespace DigikamGenericMetadataEditPlugin
0045 {
0046 
0047 class Q_DECL_HIDDEN IPTCProperties::Private
0048 {
0049 public:
0050 
0051     explicit Private()
0052     {
0053         dateReleasedSel     = nullptr;
0054         dateExpiredSel      = nullptr;
0055         timeReleasedSel     = nullptr;
0056         timeExpiredSel      = nullptr;
0057         zoneReleasedSel     = nullptr;
0058         zoneExpiredSel      = nullptr;
0059         dateReleasedCheck   = nullptr;
0060         dateExpiredCheck    = nullptr;
0061         timeReleasedCheck   = nullptr;
0062         timeExpiredCheck    = nullptr;
0063         setTodayReleasedBtn = nullptr;
0064         setTodayExpiredBtn  = nullptr;
0065         priorityCB          = nullptr;
0066         priorityCheck       = nullptr;
0067         objectCycleCB       = nullptr;
0068         objectTypeCB        = nullptr;
0069         objectCycleCheck    = nullptr;
0070         objectTypeCheck     = nullptr;
0071         objectAttribute     = nullptr;
0072         languageBtn         = nullptr;
0073         languageCheck       = nullptr;
0074         originalTransCheck  = nullptr;
0075         originalTransEdit   = nullptr;
0076         objectTypeDescEdit  = nullptr;
0077     }
0078 
0079     QCheckBox*                     dateReleasedCheck;
0080     QCheckBox*                     timeReleasedCheck;
0081     QCheckBox*                     dateExpiredCheck;
0082     QCheckBox*                     timeExpiredCheck;
0083     QCheckBox*                     originalTransCheck;
0084 
0085     QTimeEdit*                     timeReleasedSel;
0086     QTimeEdit*                     timeExpiredSel;
0087 
0088     TimeZoneComboBox*              zoneReleasedSel;
0089     TimeZoneComboBox*              zoneExpiredSel;
0090 
0091     QPushButton*                   setTodayReleasedBtn;
0092     QPushButton*                   setTodayExpiredBtn;
0093 
0094     QComboBox*                     priorityCB;
0095     QComboBox*                     objectCycleCB;
0096     QComboBox*                     objectTypeCB;
0097 
0098     DPlainTextEdit*               objectTypeDescEdit;
0099     DPlainTextEdit*               originalTransEdit;
0100 
0101     QComboBox*                     languageBtn;
0102 
0103     QDateEdit*                     dateReleasedSel;
0104     QDateEdit*                     dateExpiredSel;
0105 
0106     MetadataCheckBox*              priorityCheck;
0107     MetadataCheckBox*              objectCycleCheck;
0108     MetadataCheckBox*              objectTypeCheck;
0109     MetadataCheckBox*              languageCheck;
0110 
0111     ObjectAttributesEdit*          objectAttribute;
0112 };
0113 
0114 IPTCProperties::IPTCProperties(QWidget* const parent)
0115     : MetadataEditPage(parent),
0116       d               (new Private)
0117 {
0118     QGridLayout* const grid = new QGridLayout(widget());
0119     QString dateFormat      = QLocale().dateFormat(QLocale::ShortFormat);
0120 
0121     if (!dateFormat.contains(QLatin1String("yyyy")))
0122     {
0123         dateFormat.replace(QLatin1String("yy"),
0124                            QLatin1String("yyyy"));
0125     }
0126 
0127     QString timeFormat = QLatin1String("hh:mm:ss");
0128 
0129     // --------------------------------------------------------
0130 
0131     d->dateReleasedCheck   = new QCheckBox(i18n("Release date"), this);
0132     d->timeReleasedCheck   = new QCheckBox(i18n("Release time"), this);
0133     d->zoneReleasedSel     = new TimeZoneComboBox(this);
0134 
0135     d->dateReleasedSel     = new QDateEdit(this);
0136     d->dateReleasedSel->setDisplayFormat(dateFormat);
0137 
0138     d->timeReleasedSel     = new QTimeEdit(this);
0139     d->timeReleasedSel->setDisplayFormat(timeFormat);
0140 
0141     d->setTodayReleasedBtn = new QPushButton();
0142     d->setTodayReleasedBtn->setIcon(QIcon::fromTheme(QLatin1String("view-calendar")));
0143     d->setTodayReleasedBtn->setWhatsThis(i18n("Set release date to today"));
0144 
0145     d->dateReleasedSel->setWhatsThis(i18n("Set here the earliest intended usable date of "
0146                                           "intellectual content."));
0147     d->timeReleasedSel->setWhatsThis(i18n("Set here the earliest intended usable time of "
0148                                           "intellectual content."));
0149     d->zoneReleasedSel->setWhatsThis(i18n("Set here the earliest intended usable time zone of "
0150                                           "intellectual content."));
0151 
0152     slotSetTodayReleased();
0153 
0154     // --------------------------------------------------------
0155 
0156     d->dateExpiredCheck   = new QCheckBox(i18n("Expiration date"), this);
0157     d->timeExpiredCheck   = new QCheckBox(i18n("Expiration time"), this);
0158     d->zoneExpiredSel     = new TimeZoneComboBox(this);
0159 
0160     d->dateExpiredSel     = new QDateEdit(this);
0161     d->dateExpiredSel->setDisplayFormat(dateFormat);
0162 
0163     d->timeExpiredSel     = new QTimeEdit(this);
0164     d->timeExpiredSel->setDisplayFormat(timeFormat);
0165 
0166     d->setTodayExpiredBtn = new QPushButton();
0167     d->setTodayExpiredBtn->setIcon(QIcon::fromTheme(QLatin1String("view-calendar")));
0168     d->setTodayExpiredBtn->setWhatsThis(i18n("Set expiration date to today"));
0169 
0170     d->dateExpiredSel->setWhatsThis(i18n("Set here the latest intended usable date of "
0171                                          "intellectual content."));
0172     d->timeExpiredSel->setWhatsThis(i18n("Set here the latest intended usable time of "
0173                                          "intellectual content."));
0174     d->zoneExpiredSel->setWhatsThis(i18n("Set here the latest intended usable time zone of "
0175                                          "intellectual content."));
0176 
0177     slotSetTodayExpired();
0178 
0179     // --------------------------------------------------------
0180 
0181     d->languageCheck = new MetadataCheckBox(i18n("Language:"), this);
0182     d->languageBtn   = new QComboBox(this);
0183 
0184     DMetadata::CountryCodeMap map = DMetadata::countryCodeMap();
0185 
0186     for (DMetadata::CountryCodeMap::Iterator it = map.begin() ; it != map.end() ; ++it)
0187     {
0188         d->languageBtn->addItem(QString::fromUtf8("%1 - %2").arg(it.key()).arg(it.value()), it.key());
0189     }
0190 
0191     d->languageBtn->setWhatsThis(i18n("Select here the language of content."));
0192 
0193     // --------------------------------------------------------
0194 
0195     d->priorityCheck = new MetadataCheckBox(i18n("Priority:"), this);
0196     d->priorityCB    = new QComboBox(this);
0197     d->priorityCB->insertItem(0, i18nc("editorial urgency of content", "0: None"));
0198     d->priorityCB->insertItem(1, i18nc("editorial urgency of content", "1: High"));
0199     d->priorityCB->insertItem(2, QLatin1String("2"));
0200     d->priorityCB->insertItem(3, QLatin1String("3"));
0201     d->priorityCB->insertItem(4, QLatin1String("4"));
0202     d->priorityCB->insertItem(5, i18nc("editorial urgency of content", "5: Normal"));
0203     d->priorityCB->insertItem(6, QLatin1String("6"));
0204     d->priorityCB->insertItem(7, QLatin1String("7"));
0205     d->priorityCB->insertItem(8, i18nc("editorial urgency of content", "8: Low"));
0206     d->priorityCB->insertItem(9, i18nc("editorial urgency of content", "9: User-defined"));
0207     d->priorityCB->setWhatsThis(i18n("Select here the editorial urgency of content."));
0208 
0209     // --------------------------------------------------------
0210 
0211     d->objectCycleCheck = new MetadataCheckBox(i18n("Cycle:"), this);
0212     d->objectCycleCB    = new QComboBox(this);
0213     d->objectCycleCB->insertItem(0, i18nc("@item: object cycle", "Morning"));
0214     d->objectCycleCB->insertItem(1, i18nc("@item: object cycle", "Afternoon"));
0215     d->objectCycleCB->insertItem(2, i18nc("@item: object cycle", "Evening"));
0216     d->objectCycleCB->setWhatsThis(i18nc("@info", "Select here the editorial cycle of content."));
0217 
0218     // --------------------------------------------------------
0219 
0220     d->objectTypeCheck    = new MetadataCheckBox(i18n("Type:"), this);
0221     d->objectTypeCB       = new QComboBox(this);
0222     d->objectTypeDescEdit = new DPlainTextEdit(this);
0223     d->objectTypeDescEdit->setPlaceholderText(i18n("Set here the content type"));
0224     d->objectTypeDescEdit->setMaxLength(64);
0225     d->objectTypeDescEdit->setLinesVisible(1);
0226     d->objectTypeCB->insertItem(0, i18n("News"));
0227     d->objectTypeCB->insertItem(1, i18n("Data"));
0228     d->objectTypeCB->insertItem(2, i18n("Advisory"));
0229     d->objectTypeCB->setWhatsThis(i18n("Select here the editorial type of content."));
0230     d->objectTypeDescEdit->setWhatsThis(i18n("Set here the editorial type description of content. "
0231                                              "This field is limited to 64 characters."));
0232 
0233     // --------------------------------------------------------
0234 
0235     d->objectAttribute    = new ObjectAttributesEdit(this, 64);
0236 
0237     // --------------------------------------------------------
0238 
0239     d->originalTransCheck = new QCheckBox(i18n("Reference:"), this);
0240     d->originalTransEdit  = new DPlainTextEdit(this);
0241     d->originalTransEdit->setLinesVisible(1);
0242     d->originalTransEdit->setPlaceholderText(i18n("Set here the content reference"));
0243     d->originalTransEdit->setMaxLength(32);
0244     d->originalTransEdit->setWhatsThis(i18n("Set here the original content transmission "
0245                                             "reference. This field is limited to 32 characters."));
0246 
0247     // --------------------------------------------------------
0248 
0249     QLabel* const note = new QLabel(i18n("<b>Note: "
0250                  "<a href='https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model'>IPTC</a> "
0251                  "text tags are limited string sizes. Use contextual help for details. "
0252                  "Consider to use <a href='https://en.wikipedia.org/wiki/Extensible_Metadata_Platform'>XMP</a> instead.</b>"),
0253                  this);
0254     note->setOpenExternalLinks(true);
0255     note->setWordWrap(true);
0256     note->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0257 
0258     // --------------------------------------------------------
0259 
0260     grid->addWidget(d->dateReleasedCheck,                   0, 0, 1, 2);
0261     grid->addWidget(d->timeReleasedCheck,                   0, 2, 1, 2);
0262     grid->addWidget(d->dateReleasedSel,                     1, 0, 1, 2);
0263     grid->addWidget(d->timeReleasedSel,                     1, 2, 1, 1);
0264     grid->addWidget(d->zoneReleasedSel,                     1, 3, 1, 1);
0265     grid->addWidget(d->setTodayReleasedBtn,                 1, 5, 1, 1);
0266     grid->addWidget(d->dateExpiredCheck,                    2, 0, 1, 2);
0267     grid->addWidget(d->timeExpiredCheck,                    2, 2, 1, 2);
0268     grid->addWidget(d->dateExpiredSel,                      3, 0, 1, 2);
0269     grid->addWidget(d->timeExpiredSel,                      3, 2, 1, 1);
0270     grid->addWidget(d->zoneExpiredSel,                      3, 3, 1, 1);
0271     grid->addWidget(d->setTodayExpiredBtn,                  3, 5, 1, 1);
0272     grid->addWidget(new DLineWidget(Qt::Horizontal, this),  4, 0, 1, 6);
0273     grid->addWidget(d->languageCheck,                       5, 0, 1, 1);
0274     grid->addWidget(d->languageBtn,                         5, 1, 1, 1);
0275     grid->addWidget(d->priorityCheck,                       6, 0, 1, 1);
0276     grid->addWidget(d->priorityCB,                          6, 1, 1, 1);
0277     grid->addWidget(d->objectCycleCheck,                    7, 0, 1, 1);
0278     grid->addWidget(d->objectCycleCB,                       7, 1, 1, 1);
0279     grid->addWidget(d->objectTypeCheck,                     8, 0, 1, 1);
0280     grid->addWidget(d->objectTypeCB,                        8, 1, 1, 1);
0281     grid->addWidget(d->objectTypeDescEdit,                  8, 2, 1, 4);
0282     grid->addWidget(new DLineWidget(Qt::Horizontal, this),  9, 0, 1, 6);
0283     grid->addWidget(d->objectAttribute,                    10, 0, 1, 6);
0284     grid->addWidget(new DLineWidget(Qt::Horizontal, this), 11, 0, 1, 6);
0285     grid->addWidget(d->originalTransCheck,                 12, 0, 1, 1);
0286     grid->addWidget(d->originalTransEdit,                  12, 1, 1, 5);
0287     grid->addWidget(note,                                  13, 0, 1, 6);
0288     grid->setColumnStretch(4, 10);
0289     grid->setRowStretch(14, 10);
0290 
0291     int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0292                        QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0293 
0294     grid->setContentsMargins(spacing, spacing, spacing, spacing);
0295     grid->setSpacing(spacing);
0296 
0297     // --------------------------------------------------------
0298 
0299     connect(d->dateReleasedCheck, SIGNAL(toggled(bool)),
0300             d->dateReleasedSel, SLOT(setEnabled(bool)));
0301 
0302     connect(d->dateExpiredCheck, SIGNAL(toggled(bool)),
0303             d->dateExpiredSel, SLOT(setEnabled(bool)));
0304 
0305     connect(d->timeReleasedCheck, SIGNAL(toggled(bool)),
0306             d->timeReleasedSel, SLOT(setEnabled(bool)));
0307 
0308     connect(d->timeExpiredCheck, SIGNAL(toggled(bool)),
0309             d->timeExpiredSel, SLOT(setEnabled(bool)));
0310 
0311     connect(d->timeReleasedCheck, SIGNAL(toggled(bool)),
0312             d->zoneReleasedSel, SLOT(setEnabled(bool)));
0313 
0314     connect(d->timeExpiredCheck, SIGNAL(toggled(bool)),
0315             d->zoneExpiredSel, SLOT(setEnabled(bool)));
0316 
0317     connect(d->languageCheck, SIGNAL(toggled(bool)),
0318             d->languageBtn, SLOT(setEnabled(bool)));
0319 
0320     connect(d->priorityCheck, SIGNAL(toggled(bool)),
0321             d->priorityCB, SLOT(setEnabled(bool)));
0322 
0323     connect(d->objectCycleCheck, SIGNAL(toggled(bool)),
0324             d->objectCycleCB, SLOT(setEnabled(bool)));
0325 
0326     connect(d->objectTypeCheck, SIGNAL(toggled(bool)),
0327             d->objectTypeCB, SLOT(setEnabled(bool)));
0328 
0329     connect(d->objectTypeCheck, SIGNAL(toggled(bool)),
0330             d->objectTypeDescEdit, SLOT(setEnabled(bool)));
0331 
0332     connect(d->originalTransCheck, SIGNAL(toggled(bool)),
0333             d->originalTransEdit, SLOT(setEnabled(bool)));
0334 
0335     // --------------------------------------------------------
0336 
0337     connect(d->dateReleasedCheck, SIGNAL(toggled(bool)),
0338             this, SIGNAL(signalModified()));
0339 
0340     connect(d->dateExpiredCheck, SIGNAL(toggled(bool)),
0341             this, SIGNAL(signalModified()));
0342 
0343     connect(d->timeReleasedCheck, SIGNAL(toggled(bool)),
0344             this, SIGNAL(signalModified()));
0345 
0346     connect(d->timeExpiredCheck, SIGNAL(toggled(bool)),
0347             this, SIGNAL(signalModified()));
0348 
0349     connect(d->languageCheck, SIGNAL(toggled(bool)),
0350             this, SIGNAL(signalModified()));
0351 
0352     connect(d->priorityCheck, SIGNAL(toggled(bool)),
0353             this, SIGNAL(signalModified()));
0354 
0355     connect(d->objectCycleCheck, SIGNAL(toggled(bool)),
0356             this, SIGNAL(signalModified()));
0357 
0358     connect(d->objectTypeCheck, SIGNAL(toggled(bool)),
0359             this, SIGNAL(signalModified()));
0360 
0361     connect(d->objectAttribute, SIGNAL(signalModified()),
0362             this, SIGNAL(signalModified()));
0363 
0364     connect(d->originalTransCheck, SIGNAL(toggled(bool)),
0365             this, SIGNAL(signalModified()));
0366 
0367     // --------------------------------------------------------
0368 
0369     connect(d->dateReleasedSel, SIGNAL(dateChanged(QDate)),
0370             this, SIGNAL(signalModified()));
0371 
0372     connect(d->dateExpiredSel, SIGNAL(dateChanged(QDate)),
0373             this, SIGNAL(signalModified()));
0374 
0375     connect(d->timeReleasedSel, SIGNAL(timeChanged(QTime)),
0376             this, SIGNAL(signalModified()));
0377 
0378     connect(d->timeExpiredSel, SIGNAL(timeChanged(QTime)),
0379             this, SIGNAL(signalModified()));
0380 
0381     connect(d->zoneReleasedSel, SIGNAL(currentTextChanged(QString)),
0382             this, SIGNAL(signalModified()));
0383 
0384     connect(d->zoneExpiredSel, SIGNAL(currentTextChanged(QString)),
0385             this, SIGNAL(signalModified()));
0386 
0387     // --------------------------------------------------------
0388 
0389     connect(d->setTodayReleasedBtn, SIGNAL(clicked()),
0390             this, SLOT(slotSetTodayReleased()));
0391 
0392     connect(d->setTodayExpiredBtn, SIGNAL(clicked()),
0393             this, SLOT(slotSetTodayExpired()));
0394 
0395     // --------------------------------------------------------
0396 
0397     connect(d->languageBtn, SIGNAL(activated(int)),
0398             this, SIGNAL(signalModified()));
0399 
0400     connect(d->priorityCB, SIGNAL(activated(int)),
0401             this, SIGNAL(signalModified()));
0402 
0403     connect(d->objectCycleCB, SIGNAL(activated(int)),
0404             this, SIGNAL(signalModified()));
0405 
0406     connect(d->objectTypeCB, SIGNAL(activated(int)),
0407             this, SIGNAL(signalModified()));
0408 
0409     connect(d->objectTypeDescEdit, SIGNAL(textChanged()),
0410             this, SIGNAL(signalModified()));
0411 
0412     connect(d->originalTransEdit, SIGNAL(textChanged()),
0413             this, SIGNAL(signalModified()));
0414 }
0415 
0416 IPTCProperties::~IPTCProperties()
0417 {
0418     delete d;
0419 }
0420 
0421 void IPTCProperties::slotSetTodayReleased()
0422 {
0423     d->dateReleasedSel->setDate(QDate::currentDate());
0424     d->timeReleasedSel->setTime(QTime::currentTime());
0425     d->zoneReleasedSel->setToUTC();
0426 }
0427 
0428 void IPTCProperties::slotSetTodayExpired()
0429 {
0430     d->dateExpiredSel->setDate(QDate::currentDate());
0431     d->timeExpiredSel->setTime(QTime::currentTime());
0432     d->zoneExpiredSel->setToUTC();
0433 }
0434 
0435 void IPTCProperties::readMetadata(const DMetadata& meta)
0436 {
0437     blockSignals(true);
0438 
0439     QString     data;
0440     QStringList list;
0441     QDate       date;
0442     QTime       time;
0443     QString     dateStr, timeStr;
0444 
0445     dateStr = meta.getIptcTagString("Iptc.Application2.ReleaseDate", false);
0446     timeStr = meta.getIptcTagString("Iptc.Application2.ReleaseTime", false);
0447 
0448     d->dateReleasedSel->setDate(QDate::currentDate());
0449     d->dateReleasedCheck->setChecked(false);
0450 
0451     if (!dateStr.isEmpty())
0452     {
0453         date = QDate::fromString(dateStr, Qt::ISODate);
0454 
0455         if (date.isValid())
0456         {
0457             d->dateReleasedSel->setDate(date);
0458             d->dateReleasedCheck->setChecked(true);
0459         }
0460     }
0461 
0462     d->dateReleasedSel->setEnabled(d->dateReleasedCheck->isChecked());
0463 
0464     d->timeReleasedSel->setTime(QTime::currentTime());
0465     d->timeReleasedCheck->setChecked(false);
0466     d->zoneReleasedSel->setToUTC();
0467 
0468     if (!timeStr.isEmpty())
0469     {
0470         time = QTime::fromString(timeStr, Qt::ISODate);
0471 
0472         if (time.isValid())
0473         {
0474             d->timeReleasedSel->setTime(time);
0475             d->timeReleasedCheck->setChecked(true);
0476             d->zoneReleasedSel->setTimeZone(timeStr);
0477         }
0478     }
0479 
0480     d->timeReleasedSel->setEnabled(d->timeReleasedCheck->isChecked());
0481     d->zoneReleasedSel->setEnabled(d->timeReleasedCheck->isChecked());
0482 
0483     dateStr = meta.getIptcTagString("Iptc.Application2.ExpirationDate", false);
0484     timeStr = meta.getIptcTagString("Iptc.Application2.ExpirationTime", false);
0485 
0486     d->dateExpiredSel->setDate(QDate::currentDate());
0487     d->dateExpiredCheck->setChecked(false);
0488 
0489     if (!dateStr.isEmpty())
0490     {
0491         date = QDate::fromString(dateStr, Qt::ISODate);
0492 
0493         if (date.isValid())
0494         {
0495             d->dateExpiredSel->setDate(date);
0496             d->dateExpiredCheck->setChecked(true);
0497         }
0498     }
0499 
0500     d->dateExpiredSel->setEnabled(d->dateExpiredCheck->isChecked());
0501 
0502     d->timeExpiredSel->setTime(QTime::currentTime());
0503     d->timeExpiredCheck->setChecked(false);
0504     d->zoneExpiredSel->setToUTC();
0505 
0506     if (!timeStr.isEmpty())
0507     {
0508         time = QTime::fromString(timeStr, Qt::ISODate);
0509 
0510         if (time.isValid())
0511         {
0512             d->timeExpiredSel->setTime(time);
0513             d->timeExpiredCheck->setChecked(true);
0514             d->zoneExpiredSel->setTimeZone(timeStr);
0515         }
0516     }
0517 
0518     d->timeExpiredSel->setEnabled(d->timeExpiredCheck->isChecked());
0519     d->zoneExpiredSel->setEnabled(d->timeExpiredCheck->isChecked());
0520 
0521     d->languageCheck->setChecked(false);
0522     data = meta.getIptcTagString("Iptc.Application2.Language", false);
0523 
0524     if (!data.isNull())
0525     {
0526         int index = d->languageBtn->findData(data);
0527         if (index != -1)
0528         {
0529             d->languageBtn->setCurrentIndex(index);
0530             d->languageCheck->setChecked(true);
0531         }
0532         else
0533         {
0534             d->languageCheck->setValid(false);
0535         }
0536     }
0537 
0538     d->languageBtn->setEnabled(d->languageCheck->isChecked());
0539 
0540     d->priorityCB->setCurrentIndex(0);
0541     d->priorityCheck->setChecked(false);
0542     data = meta.getIptcTagString("Iptc.Application2.Urgency", false);
0543 
0544     if (!data.isNull())
0545     {
0546         const int val = data.toInt();
0547 
0548         if (val >= 0 && val <= 9)
0549         {
0550             d->priorityCB->setCurrentIndex(val);
0551             d->priorityCheck->setChecked(true);
0552         }
0553         else
0554         {
0555             d->priorityCheck->setValid(false);
0556         }
0557     }
0558 
0559     d->priorityCB->setEnabled(d->priorityCheck->isChecked());
0560 
0561     d->objectCycleCB->setCurrentIndex(0);
0562     d->objectCycleCheck->setChecked(false);
0563     data = meta.getIptcTagString("Iptc.Application2.ObjectCycle", false);
0564 
0565     if (!data.isNull())
0566     {
0567         if (data == QLatin1String("a"))
0568         {
0569             d->objectCycleCB->setCurrentIndex(0);
0570             d->objectCycleCheck->setChecked(true);
0571         }
0572         else if (data == QLatin1String("b"))
0573         {
0574             d->objectCycleCB->setCurrentIndex(1);
0575             d->objectCycleCheck->setChecked(true);
0576         }
0577         else if (data == QLatin1String("c"))
0578         {
0579             d->objectCycleCB->setCurrentIndex(2);
0580             d->objectCycleCheck->setChecked(true);
0581         }
0582         else
0583             d->objectCycleCheck->setValid(false);
0584     }
0585 
0586     d->objectCycleCB->setEnabled(d->objectCycleCheck->isChecked());
0587 
0588     d->objectTypeCB->setCurrentIndex(0);
0589     d->objectTypeDescEdit->clear();
0590     d->objectTypeCheck->setChecked(false);
0591     data = meta.getIptcTagString("Iptc.Application2.ObjectType", false);
0592 
0593     if (!data.isNull())
0594     {
0595         QString typeSec = data.section(QLatin1Char(':'), 0, 0);
0596 
0597         if (!typeSec.isEmpty())
0598         {
0599             int type = typeSec.toInt()-1;
0600 
0601             if (type >= 0 && type < 3)
0602             {
0603                 d->objectTypeCB->setCurrentIndex(type);
0604                 d->objectTypeDescEdit->setText(data.section(QLatin1Char(':'), -1));
0605                 d->objectTypeCheck->setChecked(true);
0606             }
0607             else
0608             {
0609                 d->objectTypeCheck->setValid(false);
0610             }
0611         }
0612     }
0613 
0614     d->objectTypeCB->setEnabled(d->objectTypeCheck->isChecked());
0615     d->objectTypeDescEdit->setEnabled(d->objectTypeCheck->isChecked());
0616 
0617     list = meta.getIptcTagsStringList("Iptc.Application2.ObjectAttribute", false);
0618     d->objectAttribute->setValues(list);
0619 
0620     d->originalTransEdit->clear();
0621     d->originalTransCheck->setChecked(false);
0622     data = meta.getIptcTagString("Iptc.Application2.TransmissionReference", false);
0623 
0624     if (!data.isNull())
0625     {
0626         d->originalTransEdit->setText(data);
0627         d->originalTransCheck->setChecked(true);
0628     }
0629 
0630     d->originalTransEdit->setEnabled(d->originalTransCheck->isChecked());
0631 
0632     blockSignals(false);
0633 }
0634 
0635 void IPTCProperties::applyMetadata(const DMetadata& meta)
0636 {
0637     if (d->dateReleasedCheck->isChecked())
0638     {
0639         meta.setIptcTagString("Iptc.Application2.ReleaseDate",
0640                                     d->dateReleasedSel->date().toString(Qt::ISODate));
0641     }
0642     else
0643     {
0644         meta.removeIptcTag("Iptc.Application2.ReleaseDate");
0645     }
0646 
0647     if (d->dateExpiredCheck->isChecked())
0648     {
0649         meta.setIptcTagString("Iptc.Application2.ExpirationDate",
0650                                     d->dateExpiredSel->date().toString(Qt::ISODate));
0651     }
0652     else
0653     {
0654         meta.removeIptcTag("Iptc.Application2.ExpirationDate");
0655     }
0656 
0657     if (d->timeReleasedCheck->isChecked())
0658     {
0659         meta.setIptcTagString("Iptc.Application2.ReleaseTime",
0660                                     d->timeReleasedSel->time().toString(Qt::ISODate) +
0661                                     d->zoneReleasedSel->getTimeZone());
0662     }
0663     else
0664     {
0665         meta.removeIptcTag("Iptc.Application2.ReleaseTime");
0666     }
0667 
0668     if (d->timeExpiredCheck->isChecked())
0669     {
0670         meta.setIptcTagString("Iptc.Application2.ExpirationTime",
0671                                     d->timeExpiredSel->time().toString(Qt::ISODate) +
0672                                     d->zoneExpiredSel->getTimeZone());
0673     }
0674     else
0675     {
0676         meta.removeIptcTag("Iptc.Application2.ExpirationTime");
0677     }
0678 
0679     if (d->languageCheck->isChecked())
0680     {
0681         meta.setIptcTagString("Iptc.Application2.Language", d->languageBtn->currentData().toString());
0682     }
0683     else if (d->languageCheck->isValid())
0684     {
0685         meta.removeIptcTag("Iptc.Application2.Language");
0686     }
0687 
0688     if (d->priorityCheck->isChecked())
0689     {
0690         meta.setIptcTagString("Iptc.Application2.Urgency", QString::number(d->priorityCB->currentIndex()));
0691     }
0692     else if (d->priorityCheck->isValid())
0693     {
0694         meta.removeIptcTag("Iptc.Application2.Urgency");
0695     }
0696 
0697     if (d->objectCycleCheck->isChecked())
0698     {
0699         switch (d->objectCycleCB->currentIndex())
0700         {
0701             case(0):
0702                 meta.setIptcTagString("Iptc.Application2.ObjectCycle", QLatin1String("a"));
0703                 break;
0704 
0705             case(1):
0706                 meta.setIptcTagString("Iptc.Application2.ObjectCycle", QLatin1String("b"));
0707                 break;
0708 
0709             case(2):
0710                 meta.setIptcTagString("Iptc.Application2.ObjectCycle", QLatin1String("c"));
0711                 break;
0712         }
0713     }
0714     else if (d->objectCycleCheck->isValid())
0715     {
0716         meta.removeIptcTag("Iptc.Application2.ObjectCycle");
0717     }
0718 
0719     if (d->objectTypeCheck->isChecked())
0720     {
0721         QString objectType;
0722         objectType = QString().asprintf("%2d", d->objectTypeCB->currentIndex()+1);
0723         objectType.append(QString::fromUtf8(":%1").arg(d->objectTypeDescEdit->text()));
0724         meta.setIptcTagString("Iptc.Application2.ObjectType", objectType);
0725     }
0726     else if (d->objectTypeCheck->isValid())
0727     {
0728         meta.removeIptcTag("Iptc.Application2.ObjectType");
0729     }
0730 
0731     QStringList oldList, newList;
0732 
0733     if (d->objectAttribute->getValues(oldList, newList))
0734         meta.setIptcTagsStringList("Iptc.Application2.ObjectAttribute", 64, oldList, newList);
0735     else if (d->objectAttribute->isValid())
0736         meta.removeIptcTag("Iptc.Application2.ObjectAttribute");
0737 
0738     if (d->originalTransCheck->isChecked())
0739         meta.setIptcTagString("Iptc.Application2.TransmissionReference", d->originalTransEdit->text());
0740     else
0741         meta.removeIptcTag("Iptc.Application2.TransmissionReference");
0742 }
0743 
0744 } // namespace DigikamGenericMetadataEditPlugin
0745 
0746 #include "moc_iptcproperties.cpp"