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        : 2006-10-12
0007  * Description : IPTC credits 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 "iptccredits.h"
0016 
0017 // Qt includes
0018 
0019 #include <QCheckBox>
0020 #include <QLabel>
0021 #include <QPushButton>
0022 #include <QGridLayout>
0023 #include <QApplication>
0024 #include <QStyle>
0025 #include <QLineEdit>
0026 #include <QToolTip>
0027 
0028 // KDE includes
0029 
0030 #include <klocalizedstring.h>
0031 
0032 // Local includes
0033 
0034 #include "multistringsedit.h"
0035 #include "dtextedit.h"
0036 
0037 namespace DigikamGenericMetadataEditPlugin
0038 {
0039 
0040 class Q_DECL_HIDDEN IPTCCredits::Private
0041 {
0042 public:
0043 
0044     explicit Private()
0045       : copyrightCheck   (nullptr),
0046         creditCheck      (nullptr),
0047         sourceCheck      (nullptr),
0048         copyrightEdit    (nullptr),
0049         creditEdit       (nullptr),
0050         sourceEdit       (nullptr),
0051         bylineEdit       (nullptr),
0052         bylineTitleEdit  (nullptr),
0053         contactEdit      (nullptr)
0054     {
0055     }
0056 
0057     QCheckBox*        copyrightCheck;
0058     QCheckBox*        creditCheck;
0059     QCheckBox*        sourceCheck;
0060 
0061     DPlainTextEdit*  copyrightEdit;
0062     DPlainTextEdit*  creditEdit;
0063     DPlainTextEdit*  sourceEdit;
0064 
0065     MultiStringsEdit* bylineEdit;
0066     MultiStringsEdit* bylineTitleEdit;
0067     MultiStringsEdit* contactEdit;
0068 };
0069 
0070 IPTCCredits::IPTCCredits(QWidget* const parent)
0071     : MetadataEditPage(parent),
0072       d               (new Private)
0073 {
0074     QGridLayout* const grid = new QGridLayout(widget());
0075 
0076     // --------------------------------------------------------
0077 
0078     d->copyrightCheck = new QCheckBox(i18n("Copyright:"), this);
0079     d->copyrightEdit  = new DPlainTextEdit(this);
0080     d->copyrightEdit->setMaxLength(128);
0081     d->copyrightEdit->setPlaceholderText(i18n("Set here the copyright notice."));
0082     d->copyrightEdit->setWhatsThis(i18n("Set here the necessary copyright notice. This field is limited "
0083                                         "to 128 characters."));
0084 
0085     // --------------------------------------------------------
0086 
0087     d->bylineEdit  = new MultiStringsEdit(this, i18n("Byline:"),
0088                                           i18n("Set here the name of content creator."),
0089                                           32);
0090 
0091     // --------------------------------------------------------
0092 
0093     d->bylineTitleEdit  = new MultiStringsEdit(this, i18n("Byline Title:"),
0094                                                i18n("Set here the title of content creator."),
0095                                                32);
0096 
0097     // --------------------------------------------------------
0098 
0099     d->creditCheck = new QCheckBox(i18n("Credit:"), this);
0100     d->creditEdit  = new DPlainTextEdit(this);
0101     d->creditEdit->setMaxLength(32);
0102     d->creditEdit->setPlaceholderText(i18n("Set here the content provider."));
0103     d->creditEdit->setWhatsThis(i18n("Set here the content provider. "
0104                                      "This field is limited to 32 characters."));
0105 
0106     // --------------------------------------------------------
0107 
0108     d->sourceCheck = new QCheckBox(i18nc("original owner of content", "Source:"), this);
0109     d->sourceEdit  = new DPlainTextEdit(this);
0110     d->sourceEdit->setMaxLength(32);
0111     d->sourceEdit->setPlaceholderText(i18n("Set here the content owner."));
0112     d->sourceEdit->setWhatsThis(i18n("Set here the original owner of content. "
0113                                      "This field is limited to 32 characters."));
0114 
0115     // --------------------------------------------------------
0116 
0117     d->contactEdit  = new MultiStringsEdit(this, i18n("Contact:"),
0118                                            i18n("Set here the person or organization to contact."),
0119                                            128);
0120 
0121     // --------------------------------------------------------
0122 
0123     QLabel* const note = new QLabel(i18n("<b>Note: "
0124                  "<a href='https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model'>IPTC</a> "
0125                  "text tags are limited string sizes. Use contextual help for details. "
0126                  "Consider to use <a href='https://en.wikipedia.org/wiki/Extensible_Metadata_Platform'>XMP</a> instead.</b>"),
0127                  this);
0128     note->setOpenExternalLinks(true);
0129     note->setWordWrap(true);
0130     note->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0131 
0132     // --------------------------------------------------------
0133 
0134     grid->addWidget(d->bylineEdit,      0, 0, 1, 3);
0135     grid->addWidget(d->bylineTitleEdit, 1, 0, 1, 3);
0136     grid->addWidget(d->contactEdit,     2, 0, 1, 3);
0137     grid->addWidget(d->creditCheck,     3, 0, 1, 3);
0138     grid->addWidget(d->creditEdit,      4, 0, 1, 3);
0139     grid->addWidget(d->sourceCheck,     5, 0, 1, 3);
0140     grid->addWidget(d->sourceEdit,      6, 0, 1, 3);
0141     grid->addWidget(d->copyrightCheck,  7, 0, 1, 3);
0142     grid->addWidget(d->copyrightEdit,   8, 0, 1, 3);
0143     grid->addWidget(note,               9, 0, 1, 3);
0144     grid->setColumnStretch(2, 10);
0145     grid->setRowStretch(10, 10);
0146 
0147     int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0148                        QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0149 
0150     grid->setContentsMargins(spacing, spacing, spacing, spacing);
0151     grid->setSpacing(spacing);
0152 
0153     // --------------------------------------------------------
0154 
0155     connect(d->copyrightCheck, SIGNAL(toggled(bool)),
0156             d->copyrightEdit, SLOT(setEnabled(bool)));
0157 
0158     connect(d->creditCheck, SIGNAL(toggled(bool)),
0159             d->creditEdit, SLOT(setEnabled(bool)));
0160 
0161     connect(d->sourceCheck, SIGNAL(toggled(bool)),
0162             d->sourceEdit, SLOT(setEnabled(bool)));
0163 
0164     // --------------------------------------------------------
0165 
0166     connect(d->copyrightCheck, SIGNAL(toggled(bool)),
0167             this, SIGNAL(signalModified()));
0168 
0169     connect(d->bylineEdit, SIGNAL(signalModified()),
0170             this, SIGNAL(signalModified()));
0171 
0172     connect(d->bylineTitleEdit, SIGNAL(signalModified()),
0173             this, SIGNAL(signalModified()));
0174 
0175     connect(d->creditCheck, SIGNAL(toggled(bool)),
0176             this, SIGNAL(signalModified()));
0177 
0178     connect(d->sourceCheck, SIGNAL(toggled(bool)),
0179             this, SIGNAL(signalModified()));
0180 
0181     connect(d->contactEdit, SIGNAL(signalModified()),
0182             this, SIGNAL(signalModified()));
0183 
0184     // --------------------------------------------------------
0185 
0186     connect(d->copyrightEdit, SIGNAL(textChanged()),
0187             this, SIGNAL(signalModified()));
0188 
0189     connect(d->creditEdit, SIGNAL(textChanged()),
0190             this, SIGNAL(signalModified()));
0191 
0192     connect(d->sourceEdit, SIGNAL(textChanged()),
0193             this, SIGNAL(signalModified()));
0194 }
0195 
0196 IPTCCredits::~IPTCCredits()
0197 {
0198     delete d;
0199 }
0200 
0201 void IPTCCredits::readMetadata(const DMetadata& meta)
0202 {
0203     blockSignals(true);
0204 
0205     QString     data;
0206     QStringList list;
0207 
0208     d->copyrightEdit->clear();
0209     d->copyrightCheck->setChecked(false);
0210     data = meta.getIptcTagString("Iptc.Application2.Copyright", false);
0211 
0212     if (!data.isNull())
0213     {
0214         d->copyrightEdit->setText(data);
0215         d->copyrightCheck->setChecked(true);
0216     }
0217 
0218     d->copyrightEdit->setEnabled(d->copyrightCheck->isChecked());
0219 
0220     list = meta.getIptcTagsStringList("Iptc.Application2.Byline", false);
0221     d->bylineEdit->setValues(list);
0222 
0223     list = meta.getIptcTagsStringList("Iptc.Application2.BylineTitle", false);
0224     d->bylineTitleEdit->setValues(list);
0225 
0226     d->creditEdit->clear();
0227     d->creditCheck->setChecked(false);
0228     data = meta.getIptcTagString("Iptc.Application2.Credit", false);
0229 
0230     if (!data.isNull())
0231     {
0232         d->creditEdit->setText(data);
0233         d->creditCheck->setChecked(true);
0234     }
0235 
0236     d->creditEdit->setEnabled(d->creditCheck->isChecked());
0237 
0238     d->sourceEdit->clear();
0239     d->sourceCheck->setChecked(false);
0240     data = meta.getIptcTagString("Iptc.Application2.Source", false);
0241 
0242     if (!data.isNull())
0243     {
0244         d->sourceEdit->setText(data);
0245         d->sourceCheck->setChecked(true);
0246     }
0247 
0248     d->sourceEdit->setEnabled(d->sourceCheck->isChecked());
0249 
0250     list = meta.getIptcTagsStringList("Iptc.Application2.Contact", false);
0251     d->contactEdit->setValues(list);
0252 
0253     blockSignals(false);
0254 }
0255 
0256 void IPTCCredits::applyMetadata(const DMetadata& meta)
0257 {
0258     QStringList oldList, newList;
0259 
0260     if (d->copyrightCheck->isChecked())
0261         meta.setIptcTagString("Iptc.Application2.Copyright", d->copyrightEdit->text());
0262     else
0263         meta.removeIptcTag("Iptc.Application2.Copyright");
0264 
0265     if (d->bylineEdit->getValues(oldList, newList))
0266         meta.setIptcTagsStringList("Iptc.Application2.Byline", 32, oldList, newList);
0267     else
0268         meta.removeIptcTag("Iptc.Application2.Byline");
0269 
0270     if (d->bylineTitleEdit->getValues(oldList, newList))
0271         meta.setIptcTagsStringList("Iptc.Application2.BylineTitle", 32, oldList, newList);
0272     else
0273         meta.removeIptcTag("Iptc.Application2.BylineTitle");
0274 
0275     if (d->creditCheck->isChecked())
0276         meta.setIptcTagString("Iptc.Application2.Credit", d->creditEdit->text());
0277     else
0278         meta.removeIptcTag("Iptc.Application2.Credit");
0279 
0280     if (d->sourceCheck->isChecked())
0281         meta.setIptcTagString("Iptc.Application2.Source", d->sourceEdit->text());
0282     else
0283         meta.removeIptcTag("Iptc.Application2.Source");
0284 
0285     if (d->contactEdit->getValues(oldList, newList))
0286         meta.setIptcTagsStringList("Iptc.Application2.Contact", 128, oldList, newList);
0287     else
0288         meta.removeIptcTag("Iptc.Application2.Contact");
0289 }
0290 
0291 } // namespace DigikamGenericMetadataEditPlugin
0292 
0293 #include "moc_iptccredits.cpp"