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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-10-24
0007  * Description : XMP workflow status 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 "xmpstatus.h"
0016 
0017 // Qt includes
0018 
0019 #include <QCheckBox>
0020 #include <QGridLayout>
0021 #include <QApplication>
0022 #include <QStyle>
0023 #include <QLineEdit>
0024 
0025 // KDE includes
0026 
0027 #include <klocalizedstring.h>
0028 
0029 // Local includes
0030 
0031 #include "altlangstringedit.h"
0032 #include "multistringsedit.h"
0033 #include "dtextedit.h"
0034 
0035 namespace DigikamGenericMetadataEditPlugin
0036 {
0037 
0038 class Q_DECL_HIDDEN XMPStatus::Private
0039 {
0040 public:
0041 
0042     explicit Private()
0043       : nicknameCheck          (nullptr),
0044         specialInstructionCheck(nullptr),
0045         nicknameEdit           (nullptr),
0046         specialInstructionEdit (nullptr),
0047         identifiersEdit        (nullptr),
0048         objectNameEdit         (nullptr)
0049     {
0050     }
0051 
0052     QCheckBox*           nicknameCheck;
0053     QCheckBox*           specialInstructionCheck;
0054 
0055     DTextEdit*           nicknameEdit;
0056 
0057     DPlainTextEdit*      specialInstructionEdit;
0058 
0059     MultiStringsEdit*    identifiersEdit;
0060 
0061     AltLangStringsEdit*  objectNameEdit;
0062 };
0063 
0064 XMPStatus::XMPStatus(QWidget* const parent)
0065     : MetadataEditPage(parent),
0066       d               (new Private)
0067 {
0068     QGridLayout* const grid  = new QGridLayout(widget());
0069 
0070     // --------------------------------------------------------
0071 
0072     d->objectNameEdit  = new AltLangStringsEdit(this, i18nc("short title for the content", "Title:"),
0073                                                 i18n("Set here a shorthand reference for the content."));
0074 
0075     // --------------------------------------------------------
0076 
0077     d->nicknameCheck = new QCheckBox(i18n("Nickname:"), this);
0078     d->nicknameEdit  = new DTextEdit(this);
0079     d->nicknameEdit->setLinesVisible(1);
0080     d->nicknameEdit->setPlaceholderText(i18n("Set here a short informal name"));
0081     d->nicknameEdit->setWhatsThis(i18n("A short informal name for the resource."));
0082 
0083     // --------------------------------------------------------
0084 
0085     d->identifiersEdit = new MultiStringsEdit(this, i18n("Identifiers:"),
0086                              i18n("Set here the strings that identify content that recurs."));
0087 
0088     // --------------------------------------------------------
0089 
0090     d->specialInstructionCheck = new QCheckBox(i18n("Special Instructions:"), this);
0091     d->specialInstructionEdit  = new DPlainTextEdit(this);
0092     d->specialInstructionEdit->setLinesVisible(4);
0093     d->specialInstructionEdit->setPlaceholderText(i18n("Set here the editorial usage instructions"));
0094     d->specialInstructionEdit->setWhatsThis(i18n("Enter the editorial usage instructions."));
0095 
0096     // --------------------------------------------------------
0097 
0098     grid->addWidget(d->objectNameEdit,          0, 0, 1, 3);
0099     grid->addWidget(d->nicknameCheck,           1, 0, 1, 1);
0100     grid->addWidget(d->nicknameEdit,            1, 1, 1, 2);
0101     grid->addWidget(d->identifiersEdit,         2, 0, 1, 3);
0102     grid->addWidget(d->specialInstructionCheck, 3, 0, 1, 3);
0103     grid->addWidget(d->specialInstructionEdit,  4, 0, 1, 3);
0104     grid->setRowStretch(5, 10);
0105     grid->setColumnStretch(2, 10);
0106 
0107     int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0108                        QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0109 
0110     grid->setContentsMargins(spacing, spacing, spacing, spacing);
0111     grid->setSpacing(spacing);
0112 
0113     // --------------------------------------------------------
0114 
0115     connect(d->specialInstructionCheck, SIGNAL(toggled(bool)),
0116             d->specialInstructionEdit, SLOT(setEnabled(bool)));
0117 
0118     connect(d->nicknameCheck, SIGNAL(toggled(bool)),
0119             d->nicknameEdit, SLOT(setEnabled(bool)));
0120 
0121     connect(d->identifiersEdit, SIGNAL(signalModified()),
0122             this, SIGNAL(signalModified()));
0123 
0124     // --------------------------------------------------------
0125 
0126     connect(d->objectNameEdit, SIGNAL(signalToggled(bool)),
0127             this, SIGNAL(signalModified()));
0128 
0129     connect(d->nicknameCheck, SIGNAL(toggled(bool)),
0130             this, SIGNAL(signalModified()));
0131 
0132     connect(d->specialInstructionCheck, SIGNAL(toggled(bool)),
0133             this, SIGNAL(signalModified()));
0134 
0135     // --------------------------------------------------------
0136 
0137     connect(d->objectNameEdit, SIGNAL(signalModified()),
0138             this, SIGNAL(signalModified()));
0139 
0140     connect(d->nicknameEdit, SIGNAL(textChanged()),
0141             this, SIGNAL(signalModified()));
0142 
0143     connect(d->specialInstructionEdit, SIGNAL(textChanged()),
0144             this, SIGNAL(signalModified()));
0145 }
0146 
0147 XMPStatus::~XMPStatus()
0148 {
0149     delete d;
0150 }
0151 
0152 void XMPStatus::readMetadata(const DMetadata& meta)
0153 {
0154     blockSignals(true);
0155 
0156     QString            data;
0157     QStringList        list;
0158     DMetadata::AltLangMap map;
0159 
0160     d->objectNameEdit->setValues(map);
0161     d->objectNameEdit->setValid(false);
0162     map = meta.getXmpTagStringListLangAlt("Xmp.dc.title", false);
0163 
0164     if (!map.isEmpty())
0165     {
0166         d->objectNameEdit->setValues(map);
0167         d->objectNameEdit->setValid(true);
0168     }
0169 
0170     d->nicknameEdit->clear();
0171     d->nicknameCheck->setChecked(false);
0172     data = meta.getXmpTagString("Xmp.xmp.Nickname", false);
0173 
0174     if (!data.isNull())
0175     {
0176         d->nicknameEdit->setText(data);
0177         d->nicknameCheck->setChecked(true);
0178     }
0179 
0180     d->nicknameEdit->setEnabled(d->nicknameCheck->isChecked());
0181 
0182     list = meta.getXmpTagStringSeq("Xmp.xmp.Identifier", false);
0183     d->identifiersEdit->setValues(list);
0184 
0185     d->specialInstructionEdit->clear();
0186     d->specialInstructionCheck->setChecked(false);
0187     data = meta.getXmpTagString("Xmp.photoshop.Instructions", false);
0188 
0189     if (!data.isNull())
0190     {
0191         d->specialInstructionEdit->setPlainText(data);
0192         d->specialInstructionCheck->setChecked(true);
0193     }
0194 
0195     d->specialInstructionEdit->setEnabled(d->specialInstructionCheck->isChecked());
0196 
0197     blockSignals(false);
0198 }
0199 
0200 void XMPStatus::applyMetadata(const DMetadata& meta)
0201 {
0202     QStringList oldList, newList;
0203 
0204     DMetadata::AltLangMap oldAltLangMap, newAltLangMap;
0205 
0206     if      (d->objectNameEdit->getValues(oldAltLangMap, newAltLangMap))
0207     {
0208         meta.setXmpTagStringListLangAlt("Xmp.dc.title", newAltLangMap);
0209     }
0210     else if (d->objectNameEdit->isValid())
0211     {
0212         meta.removeXmpTag("Xmp.dc.title");
0213     }
0214 
0215     if (d->nicknameCheck->isChecked())
0216     {
0217         meta.setXmpTagString("Xmp.xmp.Nickname", d->nicknameEdit->text());
0218     }
0219     else
0220     {
0221         meta.removeXmpTag("Xmp.xmp.Nickname");
0222     }
0223 
0224     if (d->identifiersEdit->getValues(oldList, newList))
0225     {
0226         meta.setXmpTagStringSeq("Xmp.xmp.Identifier", newList);
0227     }
0228     else
0229     {
0230         meta.removeXmpTag("Xmp.xmp.Identifier");
0231     }
0232 
0233     if (d->specialInstructionCheck->isChecked())
0234     {
0235         meta.setXmpTagString("Xmp.photoshop.Instructions", d->specialInstructionEdit->toPlainText());
0236     }
0237     else
0238     {
0239         meta.removeXmpTag("Xmp.photoshop.Instructions");
0240     }
0241 }
0242 
0243 } // namespace DigikamGenericMetadataEditPlugin
0244 
0245 #include "moc_xmpstatus.cpp"