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-15
0007  * Description : IPTC subjects settings page.
0008  *
0009  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2009      by Andi Clemens <andi dot clemens at googlemail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "iptcsubjects.h"
0017 
0018 // Qt includes
0019 
0020 #include <QToolTip>
0021 
0022 // KDE includes
0023 
0024 #include <klocalizedstring.h>
0025 
0026 namespace DigikamGenericMetadataEditPlugin
0027 {
0028 
0029 IPTCSubjects::IPTCSubjects(QWidget* const parent)
0030     : SubjectWidget(parent, true)
0031 {
0032     m_iprDefault = QLatin1String("IPTC");
0033 
0034     // --------------------------------------------------------
0035 
0036     m_iprEdit->setText(m_iprDefault);
0037     m_iprEdit->setWhatsThis(i18n("Enter here the Informative Provider Reference. "
0038                                  "I.P.R is a name registered with the IPTC/NAA, identifying the "
0039                                  "provider that provides an indicator of the content. "
0040                                  "The default value for the I.P.R is \"IPTC\" if a standard Reference "
0041                                  "Code is used. This field is limited to 32 characters."));
0042 
0043     // --------------------------------------------------------
0044 
0045     m_refEdit->setWhatsThis(i18n("Enter here the Subject Reference Number. "
0046                                  "Provides a numeric code to indicate the Subject Name plus "
0047                                  "optional Subject Matter and Subject Detail Names in the "
0048                                  "language of the service. Subject Reference is a number "
0049                                  "from the range 01000000 to 17999999 and represent a "
0050                                  "language independent international reference to "
0051                                  "a Subject. A Subject is identified by its Reference Number "
0052                                  "and corresponding Names taken from a standard lists given "
0053                                  "by IPTC/NAA. If a standard reference code is used, these lists "
0054                                  "are the English language reference versions. "
0055                                  "This field is limited to 8 digit code."));
0056 
0057     // --------------------------------------------------------
0058 
0059     m_nameEdit->setWhatsThis(i18n("Enter here the Subject Name. English language is used "
0060                                   "if you selected a standard IPTC/NAA reference code. "
0061                                   "This field is limited to 64 characters."));
0062 
0063     // --------------------------------------------------------
0064 
0065     m_matterEdit->setWhatsThis(i18n("Enter here the Subject Matter Name. English language is used "
0066                                     "if you selected a standard IPTC/NAA reference code. "
0067                                     "This field is limited to 64 characters."));
0068 
0069     // --------------------------------------------------------
0070 
0071     m_detailEdit->setWhatsThis(i18n("Enter here the Subject Detail Name. English language is used "
0072                                     "if you selected a standard IPTC/NAA reference code. "
0073                                     "This field is limited to 64 characters."));
0074 
0075     m_note->setText(i18n("<b>Note: "
0076                  "<a href='https://en.wikipedia.org/wiki/IPTC_Information_Interchange_Model'>IPTC</a> "
0077                  "text tags are limited string sizes. Use contextual help for details. "
0078                  "Consider to use <a href='https://en.wikipedia.org/wiki/Extensible_Metadata_Platform'>XMP</a> instead.</b>"));
0079 
0080     m_subjectsCheck->setVisible(true);
0081     m_subjectsCheck->setEnabled(true);
0082 
0083     connect(m_iprEdit, SIGNAL(textChanged(QString)),
0084             this, SLOT(slotLineEditModified()));
0085 
0086     connect(m_refEdit, SIGNAL(textChanged(QString)),
0087             this, SLOT(slotLineEditModified()));
0088 
0089     connect(m_nameEdit, SIGNAL(textChanged()),
0090             this, SLOT(slotLineEditModified()));
0091 
0092     connect(m_matterEdit, SIGNAL(textChanged()),
0093             this, SLOT(slotLineEditModified()));
0094 
0095     connect(m_detailEdit, SIGNAL(textChanged()),
0096             this, SLOT(slotLineEditModified()));
0097 }
0098 
0099 IPTCSubjects::~IPTCSubjects()
0100 {
0101 }
0102 
0103 void IPTCSubjects::readMetadata(const DMetadata& meta)
0104 {
0105     setSubjectsList(meta.getIptcSubjects());
0106 }
0107 
0108 void IPTCSubjects::applyMetadata(const DMetadata& meta)
0109 {
0110     QStringList newSubjects = subjectsList();
0111 
0112     if (m_subjectsCheck->isChecked())
0113     {
0114         meta.setIptcSubjects(meta.getIptcSubjects(), newSubjects);
0115     }
0116     else
0117     {
0118         meta.setIptcSubjects(meta.getIptcSubjects(), QStringList());
0119     }
0120 }
0121 
0122 void IPTCSubjects::slotLineEditModified()
0123 {
0124     QLineEdit* const ledit = dynamic_cast<QLineEdit*>(sender());
0125 
0126     if (!ledit)
0127     {
0128         return;
0129     }
0130 
0131     QToolTip::showText(ledit->mapToGlobal(QPoint(0, (-1)*(ledit->height() + 16))),
0132                        i18np("%1 character left", "%1 characters left", ledit->maxLength() - ledit->text().size()),
0133                        ledit);
0134 }
0135 
0136 } // namespace DigikamGenericMetadataEditPlugin
0137 
0138 #include "moc_iptcsubjects.cpp"