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

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 envelope 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 "iptcenvelope.h"
0016 
0017 // Qt includes
0018 
0019 #include <QCheckBox>
0020 #include <QLabel>
0021 #include <QPushButton>
0022 #include <QTimeEdit>
0023 #include <QGridLayout>
0024 #include <QDateEdit>
0025 #include <QApplication>
0026 #include <QStyle>
0027 #include <QComboBox>
0028 #include <QLineEdit>
0029 #include <QToolTip>
0030 
0031 // KDE includes
0032 
0033 #include <klocalizedstring.h>
0034 
0035 // Local includes
0036 
0037 #include "squeezedcombobox.h"
0038 #include "metadatacheckbox.h"
0039 #include "timezonecombobox.h"
0040 #include "dtextedit.h"
0041 #include "dlayoutbox.h"
0042 
0043 namespace DigikamGenericMetadataEditPlugin
0044 {
0045 
0046 class Q_DECL_HIDDEN IPTCEnvelope::Private
0047 {
0048 public:
0049 
0050     explicit Private()
0051     {
0052         unoIDCheck       = nullptr;
0053         unoIDEdit        = nullptr;
0054         destinationNote  = nullptr;
0055         destinationCheck = nullptr;
0056         destinationEdit  = nullptr;
0057         serviceIDCheck   = nullptr;
0058         serviceIDEdit    = nullptr;
0059         productIDCheck   = nullptr;
0060         productIDEdit    = nullptr;
0061         envelopeIDCheck  = nullptr;
0062         envelopeIDEdit   = nullptr;
0063         priorityCB       = nullptr;
0064         priorityCheck    = nullptr;
0065         dateSentSel      = nullptr;
0066         timeSentSel      = nullptr;
0067         zoneSentSel      = nullptr;
0068         dateSentCheck    = nullptr;
0069         timeSentCheck    = nullptr;
0070         setTodaySentBtn  = nullptr;
0071         formatCB         = nullptr;
0072         formatCheck      = nullptr;
0073 
0074         // Map : "file format - version"  ==> description
0075 
0076         fileFormatMap.insert( QLatin1String("00-00"), i18n("No ObjectData") );
0077         fileFormatMap.insert( QLatin1String("01-01"), i18n("IPTC-NAA Digital Newsphoto Parameter Record (version 1)") );
0078         fileFormatMap.insert( QLatin1String("01-02"), i18n("IPTC-NAA Digital Newsphoto Parameter Record (version 2)") );
0079         fileFormatMap.insert( QLatin1String("01-03"), i18n("IPTC-NAA Digital Newsphoto Parameter Record (version 3)") );
0080         fileFormatMap.insert( QLatin1String("01-04"), i18n("IPTC-NAA Digital Newsphoto Parameter Record (version 4)") );
0081         fileFormatMap.insert( QLatin1String("02-04"), i18n("IPTC7901 Recommended Message Format") );
0082         fileFormatMap.insert( QLatin1String("03-01"), i18n("Tagged Image File Format (version 5.0)") );
0083         fileFormatMap.insert( QLatin1String("03-02"), i18n("Tagged Image File Format (version 6.0)") );
0084         fileFormatMap.insert( QLatin1String("04-01"), i18n("Illustrator") );
0085         fileFormatMap.insert( QLatin1String("05-01"), i18n("AppleSingle") );
0086         fileFormatMap.insert( QLatin1String("06-01"), i18n("NAA 89-3 (ANPA 1312)") );
0087         fileFormatMap.insert( QLatin1String("07-01"), i18n("MacBinary II") );
0088         fileFormatMap.insert( QLatin1String("08-01"), i18n("IPTC Unstructured Character Oriented File Format") );
0089         fileFormatMap.insert( QLatin1String("09-01"), i18n("United Press International ANPA 1312 variant") );
0090         fileFormatMap.insert( QLatin1String("10-01"), i18n("United Press International Down-Load Message") );
0091         fileFormatMap.insert( QLatin1String("11-01"), i18n("JPEG File Interchange") );
0092         fileFormatMap.insert( QLatin1String("12-01"), i18n("Photo-CD Image-Pac") );
0093         fileFormatMap.insert( QLatin1String("13-01"), i18n("Microsoft Bit Mapped Graphics File [*.BMP]") );
0094         fileFormatMap.insert( QLatin1String("14-01"), i18n("Digital Audio File [*.WAV]") );
0095         fileFormatMap.insert( QLatin1String("15-01"), i18n("Audio plus Moving Video [*.AVI]") );
0096         fileFormatMap.insert( QLatin1String("16-01"), i18n("PC DOS/Windows Executable Files [*.COM][*.EXE]") );
0097         fileFormatMap.insert( QLatin1String("17-01"), i18n("Compressed Binary File [*.ZIP]") );
0098         fileFormatMap.insert( QLatin1String("18-01"), i18n("Audio Interchange File Format AIFF") );
0099         fileFormatMap.insert( QLatin1String("19-01"), i18n("RIFF Wave (Microsoft Corporation)") );
0100         fileFormatMap.insert( QLatin1String("20-01"), i18n("Freehand (version 3.1)") );
0101         fileFormatMap.insert( QLatin1String("20-02"), i18n("Freehand (version 4.0)") );
0102         fileFormatMap.insert( QLatin1String("20-03"), i18n("Freehand (version 5.0)") );
0103         fileFormatMap.insert( QLatin1String("20-04"), i18n("Freehand (version 5.5)") );
0104         fileFormatMap.insert( QLatin1String("21-01"), i18n("Hypertext Markup Language \"HTML\"") );
0105         fileFormatMap.insert( QLatin1String("22-01"), i18n("MPEG 2 Audio Layer 2 (Musicom), ISO/IEC") );
0106         fileFormatMap.insert( QLatin1String("23-01"), i18n("MPEG 2 Audio Layer 3, ISO/IEC") );
0107         fileFormatMap.insert( QLatin1String("24-01"), i18n("Portable Document File [*.PDF] Adobe") );
0108         fileFormatMap.insert( QLatin1String("25-01"), i18n("News Industry Text Format") );
0109         fileFormatMap.insert( QLatin1String("26-01"), i18n("Tape Archive [*.TAR]") );
0110         fileFormatMap.insert( QLatin1String("27-01"), i18n("Tidningarnas Telegrambyra NITF version (TTNITF DTD)") );
0111         fileFormatMap.insert( QLatin1String("28-01"), i18n("Ritzaus Bureau NITF version (RBNITF DTD)") );
0112         fileFormatMap.insert( QLatin1String("29-01"), i18n("Corel Draw [*.CDR]") );
0113     }
0114 
0115     typedef QMap<QString, QString> FileFormatMap;
0116 
0117     FileFormatMap                  fileFormatMap;
0118 
0119     QTimeEdit*                     timeSentSel;
0120 
0121     TimeZoneComboBox*              zoneSentSel;
0122 
0123     QComboBox*                     priorityCB;
0124 
0125     QCheckBox*                     unoIDCheck;
0126     QCheckBox*                     destinationCheck;
0127     QCheckBox*                     serviceIDCheck;
0128     QCheckBox*                     productIDCheck;
0129     QCheckBox*                     envelopeIDCheck;
0130     QCheckBox*                     dateSentCheck;
0131     QCheckBox*                     timeSentCheck;
0132 
0133     QPushButton*                   setTodaySentBtn;
0134 
0135     QLineEdit*                     unoIDEdit;
0136     QLineEdit*                     envelopeIDEdit;
0137     QLineEdit*                     serviceIDEdit;
0138     QLineEdit*                     productIDEdit;
0139 
0140     QDateEdit*                     dateSentSel;
0141 
0142     QLabel*                        destinationNote;
0143     DPlainTextEdit*                destinationEdit;
0144 
0145     MetadataCheckBox*              priorityCheck;
0146     MetadataCheckBox*              formatCheck;
0147 
0148     SqueezedComboBox*              formatCB;
0149 };
0150 
0151 IPTCEnvelope::IPTCEnvelope(QWidget* const parent)
0152     : MetadataEditPage(parent),
0153       d               (new Private)
0154 {
0155     QGridLayout* const grid = new QGridLayout(widget());
0156     QString dateFormat      = QLocale().dateFormat(QLocale::ShortFormat);
0157 
0158     if (!dateFormat.contains(QLatin1String("yyyy")))
0159     {
0160         dateFormat.replace(QLatin1String("yy"),
0161                            QLatin1String("yyyy"));
0162     }
0163 
0164     QString timeFormat = QLatin1String("hh:mm:ss");
0165 
0166     // --------------------------------------------------------
0167 
0168     DHBox* const destHeader = new DHBox(this);
0169     d->destinationCheck     = new QCheckBox(i18n("Destination:"), destHeader);
0170     d->destinationNote      = new QLabel(destHeader);
0171     destHeader->setStretchFactor(d->destinationCheck, 10);
0172 
0173     d->destinationEdit      = new DPlainTextEdit(this);
0174     d->destinationEdit->setMaxLength(1024);
0175     d->destinationEdit->setPlaceholderText(i18n("Set here the envelope destination"));
0176     d->destinationEdit->setWhatsThis(i18n("Enter the envelope destination. "
0177                                           "This field is limited to 1024 characters."));
0178 
0179     // --------------------------------------------------------
0180 
0181     d->unoIDCheck = new QCheckBox(i18n("U.N.O ID:"), this);
0182     d->unoIDEdit  = new QLineEdit(this);
0183     d->unoIDEdit->setClearButtonEnabled(true);
0184     d->unoIDEdit->setMaxLength(80);
0185     d->unoIDEdit->setPlaceholderText(i18n("Set here the Unique Name of Object identifier"));
0186     d->unoIDEdit->setWhatsThis(i18n("Set here the Unique Name of Object identifier. "
0187                                     "This field is limited to 80 characters."));
0188 
0189     // --------------------------------------------------------
0190 
0191     d->productIDCheck = new QCheckBox(i18n("Product ID:"), this);
0192     d->productIDEdit  = new QLineEdit(this);
0193     d->productIDEdit->setClearButtonEnabled(true);
0194     d->productIDEdit->setMaxLength(32);
0195     d->productIDEdit->setPlaceholderText(i18n("Set here the product identifier"));
0196     d->productIDEdit->setWhatsThis(i18n("Set here the product identifier. "
0197                                          "This field is limited to 32 characters."));
0198 
0199     // --------------------------------------------------------
0200 
0201     d->serviceIDCheck = new QCheckBox(i18n("Service ID:"), this);
0202     d->serviceIDEdit  = new QLineEdit(this);
0203     d->serviceIDEdit->setClearButtonEnabled(true);
0204     d->serviceIDEdit->setMaxLength(10);
0205     d->serviceIDEdit->setPlaceholderText(i18n("Set here the service identifier"));
0206     d->serviceIDEdit->setWhatsThis(i18n("Set here the service identifier. "
0207                                          "This field is limited to 10 characters."));
0208 
0209     // --------------------------------------------------------
0210 
0211     d->envelopeIDCheck = new QCheckBox(i18n("Envelope ID:"), this);
0212     d->envelopeIDEdit  = new QLineEdit(this);
0213     d->envelopeIDEdit->setClearButtonEnabled(true);
0214     d->envelopeIDEdit->setMaxLength(8);
0215     d->envelopeIDEdit->setPlaceholderText(i18n("Set here the envelope identifier"));
0216     d->envelopeIDEdit->setWhatsThis(i18n("Set here the envelope identifier. "
0217                                          "This field is limited to 8 characters."));
0218 
0219     // --------------------------------------------------------
0220 
0221     d->priorityCheck = new MetadataCheckBox(i18n("Priority:"), this);
0222     d->priorityCB    = new QComboBox(this);
0223     d->priorityCB->insertItem(0, i18nc("priority for the envelope",    "0: None"));
0224     d->priorityCB->insertItem(1, i18nc("priority for the envelope",    "1: High"));
0225     d->priorityCB->insertItem(2, QLatin1String("2"));
0226     d->priorityCB->insertItem(3, QLatin1String("3"));
0227     d->priorityCB->insertItem(4, QLatin1String("4"));
0228     d->priorityCB->insertItem(5, i18nc("priority for the envelope",    "5: Normal"));
0229     d->priorityCB->insertItem(6, QLatin1String("6"));
0230     d->priorityCB->insertItem(7, QLatin1String("7"));
0231     d->priorityCB->insertItem(8, i18nc("priority for the envelope",    "8: Low"));
0232     d->priorityCB->insertItem(9, i18nc("editorial urgency of content", "9: User-defined"));
0233     d->priorityCB->setWhatsThis(i18n("Select here the envelope priority."));
0234 
0235     // --------------------------------------------------------
0236 
0237     d->formatCheck = new MetadataCheckBox(i18n("Format:"), this);
0238     d->formatCB    = new SqueezedComboBox(this);
0239 
0240     int index = 0;
0241 
0242     for (Private::FileFormatMap::Iterator it = d->fileFormatMap.begin() ;
0243          it != d->fileFormatMap.end() ; ++it)
0244     {
0245         d->formatCB->insertSqueezedItem(it.value(), index);
0246         index++;
0247     }
0248 
0249     d->formatCB->model()->sort(0);
0250     d->formatCB->setWhatsThis(i18n("Select here envelope file format."));
0251 
0252     // --------------------------------------------------------
0253 
0254     d->dateSentCheck   = new QCheckBox(i18n("Sent date:"), this);
0255     d->timeSentCheck   = new QCheckBox(i18n("Sent time:"), this);
0256     d->zoneSentSel     = new TimeZoneComboBox(this);
0257 
0258     d->dateSentSel     = new QDateEdit(this);
0259     d->dateSentSel->setDisplayFormat(dateFormat);
0260 
0261     d->timeSentSel     = new QTimeEdit(this);
0262     d->timeSentSel->setDisplayFormat(timeFormat);
0263 
0264     d->setTodaySentBtn = new QPushButton();
0265     d->setTodaySentBtn->setIcon(QIcon::fromTheme(QLatin1String("view-calendar")));
0266     d->setTodaySentBtn->setWhatsThis(i18n("Set envelope sent date to today"));
0267 
0268     d->dateSentSel->setWhatsThis(i18n("Set here the date when the service sent the material."));
0269     d->timeSentSel->setWhatsThis(i18n("Set here the time when the service sent the material."));
0270     d->zoneSentSel->setWhatsThis(i18n("Set here the time zone when the service sent the material."));
0271 
0272     slotSetTodaySent();
0273 
0274     // --------------------------------------------------------
0275 
0276     QLabel* const note = new QLabel(i18n("<b>Note: "
0277                  "<a href='https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model'>IPTC</a> "
0278                  "text tags are limited string sizes. Use contextual help for details. "
0279                  "Consider to use <a href='https://en.wikipedia.org/wiki/Extensible_Metadata_Platform'>XMP</a> instead.</b>"),
0280                  this);
0281     note->setOpenExternalLinks(true);
0282     note->setWordWrap(true);
0283     note->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0284 
0285     // --------------------------------------------------------
0286 
0287     grid->addWidget(destHeader,             0, 0, 1, 6);
0288     grid->addWidget(d->destinationEdit,     1, 0, 1, 6);
0289     grid->addWidget(d->unoIDCheck,          2, 0, 1, 1);
0290     grid->addWidget(d->unoIDEdit,           2, 1, 1, 5);
0291     grid->addWidget(d->productIDCheck,      3, 0, 1, 1);
0292     grid->addWidget(d->productIDEdit,       3, 1, 1, 5);
0293     grid->addWidget(d->serviceIDCheck,      4, 0, 1, 1);
0294     grid->addWidget(d->serviceIDEdit,       4, 1, 1, 5);
0295     grid->addWidget(d->envelopeIDCheck,     5, 0, 1, 1);
0296     grid->addWidget(d->envelopeIDEdit,      5, 1, 1, 5);
0297     grid->addWidget(d->priorityCheck,       6, 0, 1, 1);
0298     grid->addWidget(d->priorityCB,          6, 1, 1, 1);
0299     grid->addWidget(d->formatCheck,         7, 0, 1, 1);
0300     grid->addWidget(d->formatCB,            7, 1, 1, 5);
0301     grid->addWidget(d->dateSentCheck,       8, 0, 1, 2);
0302     grid->addWidget(d->timeSentCheck,       8, 2, 1, 2);
0303     grid->addWidget(d->dateSentSel,         9, 0, 1, 2);
0304     grid->addWidget(d->timeSentSel,         9, 2, 1, 1);
0305     grid->addWidget(d->zoneSentSel,         9, 3, 1, 1);
0306     grid->addWidget(d->setTodaySentBtn,     9, 5, 1, 1);
0307     grid->addWidget(note,                  10, 0, 1, 6);
0308     grid->setColumnStretch(4, 10);
0309     grid->setRowStretch(11, 10);
0310 
0311     int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0312                        QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0313 
0314     grid->setContentsMargins(spacing, spacing, spacing, spacing);
0315     grid->setSpacing(spacing);
0316 
0317     // --------------------------------------------------------
0318 
0319     connect(d->envelopeIDCheck, SIGNAL(toggled(bool)),
0320             d->envelopeIDEdit, SLOT(setEnabled(bool)));
0321 
0322     connect(d->destinationCheck, SIGNAL(toggled(bool)),
0323             d->destinationEdit, SLOT(setEnabled(bool)));
0324 
0325     connect(d->serviceIDCheck, SIGNAL(toggled(bool)),
0326             d->serviceIDEdit, SLOT(setEnabled(bool)));
0327 
0328     connect(d->productIDCheck, SIGNAL(toggled(bool)),
0329             d->productIDEdit, SLOT(setEnabled(bool)));
0330 
0331     connect(d->unoIDCheck, SIGNAL(toggled(bool)),
0332             d->unoIDEdit, SLOT(setEnabled(bool)));
0333 
0334     connect(d->priorityCheck, SIGNAL(toggled(bool)),
0335             d->priorityCB, SLOT(setEnabled(bool)));
0336 
0337     connect(d->formatCheck, SIGNAL(toggled(bool)),
0338             d->formatCB, SLOT(setEnabled(bool)));
0339 
0340     connect(d->dateSentCheck, SIGNAL(toggled(bool)),
0341             d->dateSentSel, SLOT(setEnabled(bool)));
0342 
0343     connect(d->timeSentCheck, SIGNAL(toggled(bool)),
0344             d->timeSentSel, SLOT(setEnabled(bool)));
0345 
0346     connect(d->timeSentCheck, SIGNAL(toggled(bool)),
0347             d->zoneSentSel, SLOT(setEnabled(bool)));
0348 
0349     // --------------------------------------------------------
0350 
0351     connect(d->envelopeIDCheck, SIGNAL(toggled(bool)),
0352             this, SIGNAL(signalModified()));
0353 
0354     connect(d->destinationCheck, SIGNAL(toggled(bool)),
0355             this, SIGNAL(signalModified()));
0356 
0357     connect(d->serviceIDCheck, SIGNAL(toggled(bool)),
0358             this, SIGNAL(signalModified()));
0359 
0360     connect(d->productIDCheck, SIGNAL(toggled(bool)),
0361             this, SIGNAL(signalModified()));
0362 
0363     connect(d->unoIDCheck, SIGNAL(toggled(bool)),
0364             this, SIGNAL(signalModified()));
0365 
0366     connect(d->priorityCheck, SIGNAL(toggled(bool)),
0367             this, SIGNAL(signalModified()));
0368 
0369     connect(d->formatCheck, SIGNAL(toggled(bool)),
0370             this, SIGNAL(signalModified()));
0371 
0372     connect(d->dateSentCheck, SIGNAL(toggled(bool)),
0373             this, SIGNAL(signalModified()));
0374 
0375     connect(d->timeSentCheck, SIGNAL(toggled(bool)),
0376             this, SIGNAL(signalModified()));
0377 
0378     // --------------------------------------------------------
0379 
0380     connect(d->envelopeIDEdit, SIGNAL(textChanged(QString)),
0381             this, SIGNAL(signalModified()));
0382 
0383     connect(d->envelopeIDEdit, SIGNAL(textChanged(QString)),
0384             this, SLOT(slotLineEditModified()));
0385 
0386     connect(d->destinationEdit, SIGNAL(textChanged()),
0387             this, SIGNAL(signalModified()));
0388 
0389     connect(d->serviceIDEdit, SIGNAL(textChanged(QString)),
0390             this, SIGNAL(signalModified()));
0391 
0392     connect(d->serviceIDEdit, SIGNAL(textChanged(QString)),
0393             this, SLOT(slotLineEditModified()));
0394 
0395     connect(d->productIDEdit, SIGNAL(textChanged(QString)),
0396             this, SIGNAL(signalModified()));
0397 
0398     connect(d->productIDEdit, SIGNAL(textChanged(QString)),
0399             this, SLOT(slotLineEditModified()));
0400 
0401     connect(d->unoIDEdit, SIGNAL(textChanged(QString)),
0402             this, SIGNAL(signalModified()));
0403 
0404     connect(d->unoIDEdit, SIGNAL(textChanged(QString)),
0405             this, SLOT(slotLineEditModified()));
0406 
0407     connect(d->priorityCB, SIGNAL(activated(int)),
0408             this, SIGNAL(signalModified()));
0409 
0410     connect(d->formatCB, SIGNAL(activated(int)),
0411             this, SIGNAL(signalModified()));
0412 
0413     connect(d->dateSentSel, SIGNAL(dateChanged(QDate)),
0414             this, SIGNAL(signalModified()));
0415 
0416     connect(d->timeSentSel, SIGNAL(timeChanged(QTime)),
0417             this, SIGNAL(signalModified()));
0418 
0419     connect(d->zoneSentSel, SIGNAL(currentTextChanged(QString)),
0420             this, SIGNAL(signalModified()));
0421 
0422     // --------------------------------------------------------
0423 
0424     connect(d->setTodaySentBtn, SIGNAL(clicked()),
0425             this, SLOT(slotSetTodaySent()));
0426 }
0427 
0428 IPTCEnvelope::~IPTCEnvelope()
0429 {
0430     delete d;
0431 }
0432 
0433 void IPTCEnvelope::slotSetTodaySent()
0434 {
0435     d->dateSentSel->setDate(QDate::currentDate());
0436     d->timeSentSel->setTime(QTime::currentTime());
0437     d->zoneSentSel->setToUTC();
0438 }
0439 
0440 void IPTCEnvelope::slotLineEditModified()
0441 {
0442     QLineEdit* const ledit = dynamic_cast<QLineEdit*>(sender());
0443 
0444     if (!ledit)
0445     {
0446         return;
0447     }
0448 
0449     QToolTip::showText(ledit->mapToGlobal(QPoint(0, (-1)*(ledit->height() + 16))),
0450                        i18np("%1 character left", "%1 characters left", ledit->maxLength() - ledit->text().size()),
0451                        ledit);
0452 }
0453 
0454 void IPTCEnvelope::readMetadata(const DMetadata& meta)
0455 {
0456     blockSignals(true);
0457 
0458     QString     data, format, version;
0459     QStringList list;
0460     QDate       date;
0461     QTime       time;
0462     QString     dateStr, timeStr;
0463 
0464     d->destinationEdit->clear();
0465     d->destinationCheck->setChecked(false);
0466     data = meta.getIptcTagString("Iptc.Envelope.Destination", false);
0467 
0468     if (!data.isNull())
0469     {
0470         d->destinationEdit->setPlainText(data);
0471         d->destinationCheck->setChecked(true);
0472     }
0473 
0474     d->destinationEdit->setEnabled(d->destinationCheck->isChecked());
0475 
0476     d->envelopeIDEdit->clear();
0477     d->envelopeIDCheck->setChecked(false);
0478     data = meta.getIptcTagString("Iptc.Envelope.EnvelopeNumber", false);
0479 
0480     if (!data.isNull())
0481     {
0482         d->envelopeIDEdit->setText(data);
0483         d->envelopeIDCheck->setChecked(true);
0484     }
0485 
0486     d->envelopeIDEdit->setEnabled(d->envelopeIDCheck->isChecked());
0487 
0488     d->serviceIDEdit->clear();
0489     d->serviceIDCheck->setChecked(false);
0490     data = meta.getIptcTagString("Iptc.Envelope.ServiceId", false);
0491 
0492     if (!data.isNull())
0493     {
0494         d->serviceIDEdit->setText(data);
0495         d->serviceIDCheck->setChecked(true);
0496     }
0497 
0498     d->serviceIDEdit->setEnabled(d->serviceIDCheck->isChecked());
0499 
0500     d->unoIDEdit->clear();
0501     d->unoIDCheck->setChecked(false);
0502     data = meta.getIptcTagString("Iptc.Envelope.UNO", false);
0503 
0504     if (!data.isNull())
0505     {
0506         d->unoIDEdit->setText(data);
0507         d->unoIDCheck->setChecked(true);
0508     }
0509 
0510     d->unoIDEdit->setEnabled(d->unoIDCheck->isChecked());
0511 
0512     d->productIDEdit->clear();
0513     d->productIDCheck->setChecked(false);
0514     data = meta.getIptcTagString("Iptc.Envelope.ProductId", false);
0515 
0516     if (!data.isNull())
0517     {
0518         d->productIDEdit->setText(data);
0519         d->productIDCheck->setChecked(true);
0520     }
0521 
0522     d->productIDEdit->setEnabled(d->productIDCheck->isChecked());
0523 
0524     d->priorityCB->setCurrentIndex(0);
0525     d->priorityCheck->setChecked(false);
0526     data = meta.getIptcTagString("Iptc.Envelope.EnvelopePriority", false);
0527 
0528     if (!data.isNull())
0529     {
0530         const int val = data.toInt();
0531 
0532         if (val >= 0 && val <= 9)
0533         {
0534             d->priorityCB->setCurrentIndex(val);
0535             d->priorityCheck->setChecked(true);
0536         }
0537         else
0538             d->priorityCheck->setValid(false);
0539     }
0540 
0541     d->priorityCB->setEnabled(d->priorityCheck->isChecked());
0542 
0543     d->formatCB->setCurrentIndex(0);
0544     d->formatCheck->setChecked(false);
0545     format  = meta.getIptcTagString("Iptc.Envelope.FileFormat", false);
0546     version = meta.getIptcTagString("Iptc.Envelope.FileVersion", false);
0547 
0548     if (!format.isNull())
0549     {
0550         if (!version.isNull())
0551         {
0552             if (format.size() == 1) format.prepend(QLatin1String("0"));
0553             if (version.size() == 1) version.prepend(QLatin1String("0"));
0554 
0555             QString key = QString::fromUtf8("%1-%2").arg(format).arg(version);
0556             int index = -1, i = 0;
0557 
0558             for (Private::FileFormatMap::Iterator it = d->fileFormatMap.begin();
0559                  it != d->fileFormatMap.end(); ++it)
0560             {
0561                 if (it.key() == key) index = i;
0562                 i++;
0563             }
0564 
0565             if (index != -1)
0566             {
0567                 d->formatCB->setCurrentIndex(index);
0568                 d->formatCheck->setChecked(true);
0569             }
0570             else
0571                 d->formatCheck->setValid(false);
0572         }
0573         else
0574             d->formatCheck->setValid(false);
0575     }
0576 
0577     d->formatCB->setEnabled(d->formatCheck->isChecked());
0578 
0579     dateStr = meta.getIptcTagString("Iptc.Envelope.DateSent", false);
0580     timeStr = meta.getIptcTagString("Iptc.Envelope.TimeSent", false);
0581 
0582     d->dateSentSel->setDate(QDate::currentDate());
0583     d->dateSentCheck->setChecked(false);
0584 
0585     if (!dateStr.isEmpty())
0586     {
0587         date = QDate::fromString(dateStr, Qt::ISODate);
0588         if (date.isValid())
0589         {
0590             d->dateSentSel->setDate(date);
0591             d->dateSentCheck->setChecked(true);
0592         }
0593     }
0594 
0595     d->dateSentSel->setEnabled(d->dateSentCheck->isChecked());
0596 
0597     d->timeSentSel->setTime(QTime::currentTime());
0598     d->timeSentCheck->setChecked(false);
0599     d->zoneSentSel->setToUTC();
0600 
0601     if (!timeStr.isEmpty())
0602     {
0603         time = QTime::fromString(timeStr, Qt::ISODate);
0604         if (time.isValid())
0605         {
0606             d->timeSentSel->setTime(time);
0607             d->timeSentCheck->setChecked(true);
0608             d->zoneSentSel->setTimeZone(timeStr);
0609        }
0610     }
0611 
0612     d->timeSentSel->setEnabled(d->timeSentCheck->isChecked());
0613     d->zoneSentSel->setEnabled(d->timeSentCheck->isChecked());
0614 
0615     blockSignals(false);
0616 }
0617 
0618 void IPTCEnvelope::applyMetadata(const DMetadata& meta)
0619 {
0620     if (d->destinationCheck->isChecked())
0621     {
0622         meta.setIptcTagString("Iptc.Envelope.Destination", d->destinationEdit->toPlainText());
0623     }
0624     else
0625     {
0626         meta.removeIptcTag("Iptc.Envelope.Destination");
0627     }
0628 
0629     if (d->envelopeIDCheck->isChecked())
0630     {
0631         meta.setIptcTagString("Iptc.Envelope.EnvelopeNumber", d->envelopeIDEdit->text());
0632     }
0633     else
0634     {
0635         meta.removeIptcTag("Iptc.Envelope.EnvelopeNumber");
0636     }
0637 
0638     if (d->serviceIDCheck->isChecked())
0639     {
0640         meta.setIptcTagString("Iptc.Envelope.ServiceId", d->serviceIDEdit->text());
0641     }
0642     else
0643     {
0644         meta.removeIptcTag("Iptc.Envelope.ServiceId");
0645     }
0646 
0647     if (d->unoIDCheck->isChecked())
0648     {
0649         meta.setIptcTagString("Iptc.Envelope.UNO", d->unoIDEdit->text());
0650     }
0651     else
0652     {
0653         meta.removeIptcTag("Iptc.Envelope.UNO");
0654     }
0655 
0656     if (d->productIDCheck->isChecked())
0657     {
0658         meta.setIptcTagString("Iptc.Envelope.ProductId", d->productIDEdit->text());
0659     }
0660     else
0661     {
0662         meta.removeIptcTag("Iptc.Envelope.ProductId");
0663     }
0664 
0665     if (d->priorityCheck->isChecked())
0666     {
0667         meta.setIptcTagString("Iptc.Envelope.EnvelopePriority", QString::number(d->priorityCB->currentIndex()));
0668     }
0669     else if (d->priorityCheck->isValid())
0670     {
0671         meta.removeIptcTag("Iptc.Envelope.EnvelopePriority");
0672     }
0673 
0674     if (d->formatCheck->isChecked())
0675     {
0676         QString key;
0677         int i = 0;
0678 
0679         for (Private::FileFormatMap::Iterator it = d->fileFormatMap.begin() ;
0680              it != d->fileFormatMap.end() ; ++it)
0681         {
0682             if (i == d->formatCB->currentIndex()) key = it.key();
0683             i++;
0684         }
0685 
0686         QString format  = key.section(QLatin1Char('-'), 0, 0);
0687         QString version = key.section(QLatin1Char('-'), -1);
0688         meta.setIptcTagString("Iptc.Envelope.FileFormat", format);
0689         meta.setIptcTagString("Iptc.Envelope.FileVersion", version);
0690     }
0691     else if (d->priorityCheck->isValid())
0692     {
0693         meta.removeIptcTag("Iptc.Envelope.FileFormat");
0694         meta.removeIptcTag("Iptc.Envelope.FileVersion");
0695     }
0696 
0697     if (d->dateSentCheck->isChecked())
0698     {
0699         meta.setIptcTagString("Iptc.Envelope.DateSent",
0700                                     d->dateSentSel->date().toString(Qt::ISODate));
0701     }
0702     else
0703     {
0704         meta.removeIptcTag("Iptc.Envelope.DateSent");
0705     }
0706 
0707     if (d->timeSentCheck->isChecked())
0708     {
0709         meta.setIptcTagString("Iptc.Envelope.TimeSent",
0710                                     d->timeSentSel->time().toString(Qt::ISODate) +
0711                                     d->zoneSentSel->getTimeZone());
0712     }
0713     else
0714     {
0715         meta.removeIptcTag("Iptc.Envelope.TimeSent");
0716     }
0717 }
0718 
0719 } // namespace DigikamGenericMetadataEditPlugin
0720 
0721 #include "moc_iptcenvelope.cpp"