File indexing completed on 2025-01-05 03:57:19

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-06-29
0007  * Description : metadata template viewer.
0008  *
0009  * SPDX-FileCopyrightText: 2009-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 "templateviewer.h"
0016 
0017 // Qt includes
0018 
0019 #include <QGridLayout>
0020 #include <QUrl>
0021 #include <QIcon>
0022 
0023 // KDE includes
0024 
0025 #include <klocalizedstring.h>
0026 
0027 // Local includes
0028 
0029 #include "dlayoutbox.h"
0030 #include "itempropertiestxtlabel.h"
0031 #include "template.h"
0032 #include "templatemanager.h"
0033 #include "countryselector.h"
0034 
0035 namespace Digikam
0036 {
0037 
0038 class Q_DECL_HIDDEN TemplateViewer::Private
0039 {
0040 public:
0041 
0042     explicit Private()
0043       : names                       (nullptr),
0044         position                    (nullptr),
0045         credit                      (nullptr),
0046         copyright                   (nullptr),
0047         usages                      (nullptr),
0048         source                      (nullptr),
0049         instructions                (nullptr),
0050         namesList                   (nullptr),
0051         labelPosition               (nullptr),
0052         labelCredit                 (nullptr),
0053         labelCopyright              (nullptr),
0054         labelUsages                 (nullptr),
0055         labelSource                 (nullptr),
0056         labelInstructions           (nullptr),
0057         locationCountry             (nullptr),
0058         locationProvinceState       (nullptr),
0059         locationCity                (nullptr),
0060         locationSublocation         (nullptr),
0061         labelLocationCountry        (nullptr),
0062         labelLocationProvinceState  (nullptr),
0063         labelLocationCity           (nullptr),
0064         labelLocationSublocation    (nullptr),
0065         contactCity                 (nullptr),
0066         contactCountry              (nullptr),
0067         contactAddress              (nullptr),
0068         contactPostalCode           (nullptr),
0069         contactProvinceState        (nullptr),
0070         contactEmail                (nullptr),
0071         contactPhone                (nullptr),
0072         contactWebUrl               (nullptr),
0073         labelContactCity            (nullptr),
0074         labelContactCountry         (nullptr),
0075         labelContactAddress         (nullptr),
0076         labelContactPostalCode      (nullptr),
0077         labelContactProvinceState   (nullptr),
0078         labelContactPhone           (nullptr),
0079         labelContactEmail           (nullptr),
0080         labelContactWebUrl          (nullptr),
0081         subjectsList                (nullptr)
0082     {
0083     }
0084 
0085     /// IPTC Rights info.
0086     DTextLabelName*  names;
0087     DTextLabelName*  position;
0088     DTextLabelName*  credit;
0089     DTextLabelName*  copyright;
0090     DTextLabelName*  usages;
0091     DTextLabelName*  source;
0092     DTextLabelName*  instructions;
0093 
0094     DTextList*       namesList;
0095     DTextBrowser*    labelPosition;
0096     DTextBrowser*    labelCredit;
0097     DTextBrowser*    labelCopyright;
0098     DTextBrowser*    labelUsages;
0099     DTextBrowser*    labelSource;
0100     DTextBrowser*    labelInstructions;
0101 
0102     /// IPTC Location info.
0103     DTextLabelName*  locationCountry;
0104     DTextLabelName*  locationProvinceState;
0105     DTextLabelName*  locationCity;
0106     DTextLabelName*  locationSublocation;
0107 
0108     DTextBrowser*    labelLocationCountry;
0109     DTextBrowser*    labelLocationProvinceState;
0110     DTextBrowser*    labelLocationCity;
0111     DTextBrowser*    labelLocationSublocation;
0112 
0113     /// IPTC Contact info.
0114     DTextLabelName*  contactCity;
0115     DTextLabelName*  contactCountry;
0116     DTextLabelName*  contactAddress;
0117     DTextLabelName*  contactPostalCode;
0118     DTextLabelName*  contactProvinceState;
0119     DTextLabelName*  contactEmail;
0120     DTextLabelName*  contactPhone;
0121     DTextLabelName*  contactWebUrl;
0122 
0123     DTextBrowser*    labelContactCity;
0124     DTextBrowser*    labelContactCountry;
0125     DTextBrowser*    labelContactAddress;
0126     DTextBrowser*    labelContactPostalCode;
0127     DTextBrowser*    labelContactProvinceState;
0128     DTextBrowser*    labelContactPhone;
0129     QLabel*          labelContactEmail;
0130     QLabel*          labelContactWebUrl;
0131 
0132     /// IPTC Subjects info.
0133     DTextList*       subjectsList;
0134 };
0135 
0136 TemplateViewer::TemplateViewer(QWidget* const parent)
0137     : DExpanderBox(parent),
0138       d           (new Private)
0139 {
0140     setFrameStyle(QFrame::NoFrame);
0141 
0142     DVBox* const w1      = new DVBox(this);
0143     d->names             = new DTextLabelName(i18n("Names:"), w1);
0144     d->namesList         = new DTextList(QStringList(), w1);
0145     d->position          = new DTextLabelName(i18n("Position:"), w1);
0146     d->labelPosition     = new DTextBrowser(QString(), w1);
0147     d->credit            = new DTextLabelName(i18n("Credit:"), w1);
0148     d->labelCredit       = new DTextBrowser(QString(), w1);
0149     d->copyright         = new DTextLabelName(i18n("Copyright:"), w1);
0150     d->labelCopyright    = new DTextBrowser(QString(), w1);
0151     d->usages            = new DTextLabelName(i18n("Usages:"), w1);
0152     d->labelUsages       = new DTextBrowser(QString(), w1);
0153     d->source            = new DTextLabelName(i18nc("@label: template properties", "Source:"), w1);
0154     d->labelSource       = new DTextBrowser(QString(), w1);
0155     d->instructions      = new DTextLabelName(i18n("Instructions:"), w1);
0156     d->labelInstructions = new DTextBrowser(QString(), w1);
0157 
0158     d->names->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0159     d->position->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0160     d->credit->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0161     d->copyright->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0162     d->credit->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0163     d->usages->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0164     d->source->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0165     d->instructions->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0166 
0167     addItem(w1, QIcon::fromTheme(QLatin1String("flag")),
0168             i18n("Rights"), QLatin1String("Rights"), true);
0169 
0170     // ------------------------------------------------------------------
0171 
0172     DVBox* const w2               = new DVBox(this);
0173     d->locationCity               = new DTextLabelName(i18n("City:"), w2);
0174     d->labelLocationCity          = new DTextBrowser(QString(), w2);
0175     d->locationSublocation        = new DTextLabelName(i18n("Sublocation:"), w2);
0176     d->labelLocationSublocation   = new DTextBrowser(QString(), w2);
0177     d->locationProvinceState      = new DTextLabelName(i18n("State/Province:"), w2);
0178     d->labelLocationProvinceState = new DTextBrowser(QString(), w2);
0179     d->locationCountry            = new DTextLabelName(i18n("Country:"), w2);
0180     d->labelLocationCountry       = new DTextBrowser(QString(), w2);
0181 
0182     d->locationCity->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0183     d->locationSublocation->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0184     d->locationProvinceState->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0185     d->locationCountry->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0186 
0187     addItem(w2, QIcon::fromTheme(QLatin1String("globe")),
0188             i18n("Location"), QLatin1String("Location"), true);
0189 
0190     // ------------------------------------------------------------------
0191 
0192     DVBox* const w3              = new DVBox(this);
0193     d->contactAddress            = new DTextLabelName(i18nc("@label: template properties", "Address:"), w3);
0194     d->labelContactAddress       = new DTextBrowser(QString(), w3);
0195     d->contactPostalCode         = new DTextLabelName(i18n("Postal Code:"), w3);
0196     d->labelContactPostalCode    = new DTextBrowser(QString(), w3);
0197     d->contactCity               = new DTextLabelName(i18n("City:"), w3);
0198     d->labelContactCity          = new DTextBrowser(QString(), w3);
0199     d->contactProvinceState      = new DTextLabelName(i18n("State/Province:"), w3);
0200     d->labelContactProvinceState = new DTextBrowser(QString(), w3);
0201     d->contactCountry            = new DTextLabelName(i18n("Country:"), w3);
0202     d->labelContactCountry       = new DTextBrowser(QString(), w3);
0203     d->contactPhone              = new DTextLabelName(i18n("Phone:"), w3);
0204     d->labelContactPhone         = new DTextBrowser(QString(), w3);
0205     d->contactEmail              = new DTextLabelName(i18nc("@label: template properties", "Email:"), w3);
0206     d->labelContactEmail         = new QLabel(QString(), w3);
0207     d->contactWebUrl             = new DTextLabelName(i18n("URL:"), w3);
0208     d->labelContactWebUrl        = new QLabel(QString(), w3);
0209 
0210     d->labelContactEmail->setOpenExternalLinks(true);
0211     d->labelContactEmail->setTextFormat(Qt::RichText);
0212     d->labelContactEmail->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
0213 
0214     d->labelContactWebUrl->setOpenExternalLinks(true);
0215     d->labelContactWebUrl->setTextFormat(Qt::RichText);
0216     d->labelContactWebUrl->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
0217 
0218     d->contactAddress->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0219     d->contactPostalCode->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0220     d->contactCity->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0221     d->contactProvinceState->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0222     d->contactCountry->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0223     d->contactPhone->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0224     d->contactEmail->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0225     d->contactWebUrl->setAlignment(Qt::AlignLeft | Qt::AlignTop);
0226 
0227     addItem(w3, QIcon::fromTheme(QLatin1String("view-pim-contacts")),
0228             i18n("Contact"), QLatin1String("Contact"), true);
0229 
0230     // ------------------------------------------------------------------
0231 
0232     DVBox* const w4 = new DVBox(this);
0233     d->subjectsList = new DTextList(QStringList(), w4);
0234 
0235     addItem(w4, QIcon::fromTheme(QLatin1String("feed-subscribe")),
0236             i18n("Subjects"), QLatin1String("Subjects"), true);
0237 
0238     addStretch();
0239 }
0240 
0241 TemplateViewer::~TemplateViewer()
0242 {
0243     delete d;
0244 }
0245 
0246 void TemplateViewer::setTemplate(const Template& t)
0247 {
0248     d->namesList->clear();
0249     d->namesList->addItems(t.authors());
0250     d->labelPosition->setText(t.authorsPosition());
0251     d->labelCredit->setText(t.credit());
0252     d->labelCopyright->setText(t.copyright().value(QLatin1String("x-default")));
0253     d->labelUsages->setText(t.rightUsageTerms().value(QLatin1String("x-default")));
0254     d->labelSource->setText(t.source());
0255     d->labelInstructions->setText(t.instructions());
0256 
0257     d->labelLocationCity->setText(t.locationInfo().city);
0258     d->labelLocationSublocation->setText(t.locationInfo().location);
0259     d->labelLocationProvinceState->setText(t.locationInfo().provinceState);
0260     d->labelLocationCountry->setText(CountrySelector::countryForCode(t.locationInfo().countryCode));
0261 
0262     d->labelContactAddress->setText(t.contactInfo().address);
0263     d->labelContactPostalCode->setText(t.contactInfo().postalCode);
0264     d->labelContactProvinceState->setText(t.contactInfo().provinceState);
0265     d->labelContactCity->setText(t.contactInfo().city);
0266     d->labelContactCountry->setText(t.contactInfo().country);
0267     d->labelContactPhone->setText(t.contactInfo().phone);
0268     d->labelContactEmail->setText(QString::fromUtf8("<a href=\"mailto:%1\">%2</a>").arg(t.contactInfo().email).arg(t.contactInfo().email));
0269     d->labelContactWebUrl->setText(QString::fromUtf8("<a href=\"%1\">%2</a>").arg(t.contactInfo().webUrl).arg(t.contactInfo().webUrl));
0270 
0271     d->subjectsList->clear();
0272     d->subjectsList->addItems(t.IptcSubjects());
0273 }
0274 
0275 } // namespace Digikam
0276 
0277 #include "moc_templateviewer.cpp"