1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2009-06-29
7  * Description : metadata template viewer.
8  *
9  * Copyright (C) 2009-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "templateviewer.h"
25 
26 // Qt includes
27 
28 #include <QGridLayout>
29 #include <QUrl>
30 #include <QIcon>
31 
32 // KDE includes
33 
34 #include <klocalizedstring.h>
35 
36 // Local includes
37 
38 #include "dlayoutbox.h"
39 #include "itempropertiestxtlabel.h"
40 #include "template.h"
41 #include "templatemanager.h"
42 #include "countryselector.h"
43 
44 namespace Digikam
45 {
46 
47 class Q_DECL_HIDDEN TemplateViewer::Private
48 {
49 public:
50 
Private()51     explicit Private()
52       : names                       (nullptr),
53         position                    (nullptr),
54         credit                      (nullptr),
55         copyright                   (nullptr),
56         usages                      (nullptr),
57         source                      (nullptr),
58         instructions                (nullptr),
59         namesList                   (nullptr),
60         labelPosition               (nullptr),
61         labelCredit                 (nullptr),
62         labelCopyright              (nullptr),
63         labelUsages                 (nullptr),
64         labelSource                 (nullptr),
65         labelInstructions           (nullptr),
66         locationCountry             (nullptr),
67         locationProvinceState       (nullptr),
68         locationCity                (nullptr),
69         locationSublocation         (nullptr),
70         labelLocationCountry        (nullptr),
71         labelLocationProvinceState  (nullptr),
72         labelLocationCity           (nullptr),
73         labelLocationSublocation    (nullptr),
74         contactCity                 (nullptr),
75         contactCountry              (nullptr),
76         contactAddress              (nullptr),
77         contactPostalCode           (nullptr),
78         contactProvinceState        (nullptr),
79         contactEmail                (nullptr),
80         contactPhone                (nullptr),
81         contactWebUrl               (nullptr),
82         labelContactCity            (nullptr),
83         labelContactCountry         (nullptr),
84         labelContactAddress         (nullptr),
85         labelContactPostalCode      (nullptr),
86         labelContactProvinceState   (nullptr),
87         labelContactPhone           (nullptr),
88         labelContactEmail           (nullptr),
89         labelContactWebUrl          (nullptr),
90         subjectsList                (nullptr)
91     {
92     }
93 
94     /// IPTC Rights info.
95     DTextLabelName*  names;
96     DTextLabelName*  position;
97     DTextLabelName*  credit;
98     DTextLabelName*  copyright;
99     DTextLabelName*  usages;
100     DTextLabelName*  source;
101     DTextLabelName*  instructions;
102 
103     DTextList*       namesList;
104     DTextBrowser*    labelPosition;
105     DTextBrowser*    labelCredit;
106     DTextBrowser*    labelCopyright;
107     DTextBrowser*    labelUsages;
108     DTextBrowser*    labelSource;
109     DTextBrowser*    labelInstructions;
110 
111     /// IPTC Location info.
112     DTextLabelName*  locationCountry;
113     DTextLabelName*  locationProvinceState;
114     DTextLabelName*  locationCity;
115     DTextLabelName*  locationSublocation;
116 
117     DTextBrowser*    labelLocationCountry;
118     DTextBrowser*    labelLocationProvinceState;
119     DTextBrowser*    labelLocationCity;
120     DTextBrowser*    labelLocationSublocation;
121 
122     /// IPTC Contact info.
123     DTextLabelName*  contactCity;
124     DTextLabelName*  contactCountry;
125     DTextLabelName*  contactAddress;
126     DTextLabelName*  contactPostalCode;
127     DTextLabelName*  contactProvinceState;
128     DTextLabelName*  contactEmail;
129     DTextLabelName*  contactPhone;
130     DTextLabelName*  contactWebUrl;
131 
132     DTextBrowser*    labelContactCity;
133     DTextBrowser*    labelContactCountry;
134     DTextBrowser*    labelContactAddress;
135     DTextBrowser*    labelContactPostalCode;
136     DTextBrowser*    labelContactProvinceState;
137     DTextBrowser*    labelContactPhone;
138     DTextLabelValue* labelContactEmail;
139     DTextLabelValue* labelContactWebUrl;
140 
141     /// IPTC Subjects info.
142     DTextList*      subjectsList;
143 };
144 
TemplateViewer(QWidget * const parent)145 TemplateViewer::TemplateViewer(QWidget* const parent)
146     : DExpanderBox(parent),
147       d           (new Private)
148 {
149     setFrameStyle(QFrame::NoFrame);
150 
151     DVBox* const w1      = new DVBox(this);
152     d->names             = new DTextLabelName(i18n("Names:"), w1);
153     d->namesList         = new DTextList(QStringList(), w1);
154     d->position          = new DTextLabelName(i18n("Position:"), w1);
155     d->labelPosition     = new DTextBrowser(QString(), w1);
156     d->credit            = new DTextLabelName(i18n("Credit:"), w1);
157     d->labelCredit       = new DTextBrowser(QString(), w1);
158     d->copyright         = new DTextLabelName(i18n("Copyright:"), w1);
159     d->labelCopyright    = new DTextBrowser(QString(), w1);
160     d->usages            = new DTextLabelName(i18n("Usages:"), w1);
161     d->labelUsages       = new DTextBrowser(QString(), w1);
162     d->source            = new DTextLabelName(i18nc("@label: template properties", "Source:"), w1);
163     d->labelSource       = new DTextBrowser(QString(), w1);
164     d->instructions      = new DTextLabelName(i18n("Instructions:"), w1);
165     d->labelInstructions = new DTextBrowser(QString(), w1);
166 
167     d->names->setAlignment(Qt::AlignLeft | Qt::AlignTop);
168     d->position->setAlignment(Qt::AlignLeft | Qt::AlignTop);
169     d->credit->setAlignment(Qt::AlignLeft | Qt::AlignTop);
170     d->copyright->setAlignment(Qt::AlignLeft | Qt::AlignTop);
171     d->credit->setAlignment(Qt::AlignLeft | Qt::AlignTop);
172     d->usages->setAlignment(Qt::AlignLeft | Qt::AlignTop);
173     d->source->setAlignment(Qt::AlignLeft | Qt::AlignTop);
174     d->instructions->setAlignment(Qt::AlignLeft | Qt::AlignTop);
175 
176     addItem(w1, QIcon::fromTheme(QLatin1String("flag")),
177             i18n("Rights"), QLatin1String("Rights"), true);
178 
179     // ------------------------------------------------------------------
180 
181     DVBox* const w2               = new DVBox(this);
182     d->locationCity               = new DTextLabelName(i18n("City:"), w2);
183     d->labelLocationCity          = new DTextBrowser(QString(), w2);
184     d->locationSublocation        = new DTextLabelName(i18n("Sublocation:"), w2);
185     d->labelLocationSublocation   = new DTextBrowser(QString(), w2);
186     d->locationProvinceState      = new DTextLabelName(i18n("State/Province:"), w2);
187     d->labelLocationProvinceState = new DTextBrowser(QString(), w2);
188     d->locationCountry            = new DTextLabelName(i18n("Country:"), w2);
189     d->labelLocationCountry       = new DTextBrowser(QString(), w2);
190 
191     d->locationCity->setAlignment(Qt::AlignLeft | Qt::AlignTop);
192     d->locationSublocation->setAlignment(Qt::AlignLeft | Qt::AlignTop);
193     d->locationProvinceState->setAlignment(Qt::AlignLeft | Qt::AlignTop);
194     d->locationCountry->setAlignment(Qt::AlignLeft | Qt::AlignTop);
195 
196     addItem(w2, QIcon::fromTheme(QLatin1String("globe")),
197             i18n("Location"), QLatin1String("Location"), true);
198 
199     // ------------------------------------------------------------------
200 
201     DVBox* const w3              = new DVBox(this);
202     d->contactAddress            = new DTextLabelName(i18nc("@label: template properties", "Address:"), w3);
203     d->labelContactAddress       = new DTextBrowser(QString(), w3);
204     d->contactPostalCode         = new DTextLabelName(i18n("Postal Code:"), w3);
205     d->labelContactPostalCode    = new DTextBrowser(QString(), w3);
206     d->contactCity               = new DTextLabelName(i18n("City:"), w3);
207     d->labelContactCity          = new DTextBrowser(QString(), w3);
208     d->contactProvinceState      = new DTextLabelName(i18n("State/Province:"), w3);
209     d->labelContactProvinceState = new DTextBrowser(QString(), w3);
210     d->contactCountry            = new DTextLabelName(i18n("Country:"), w3);
211     d->labelContactCountry       = new DTextBrowser(QString(), w3);
212     d->contactPhone              = new DTextLabelName(i18n("Phone:"), w3);
213     d->labelContactPhone         = new DTextBrowser(QString(), w3);
214     d->contactEmail              = new DTextLabelName(i18nc("@label: template properties", "Email:"), w3);
215     d->labelContactEmail         = new DTextLabelValue(QString(), w3);
216     d->contactWebUrl             = new DTextLabelName(i18n("URL:"), w3);
217     d->labelContactWebUrl        = new DTextLabelValue(QString(), w3);
218 
219     d->labelContactEmail->setOpenExternalLinks(true);
220     d->labelContactEmail->setTextFormat(Qt::RichText);
221     d->labelContactEmail->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
222 
223     d->labelContactWebUrl->setOpenExternalLinks(true);
224     d->labelContactWebUrl->setTextFormat(Qt::RichText);
225     d->labelContactWebUrl->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
226 
227     d->contactAddress->setAlignment(Qt::AlignLeft | Qt::AlignTop);
228     d->contactPostalCode->setAlignment(Qt::AlignLeft | Qt::AlignTop);
229     d->contactCity->setAlignment(Qt::AlignLeft | Qt::AlignTop);
230     d->contactProvinceState->setAlignment(Qt::AlignLeft | Qt::AlignTop);
231     d->contactCountry->setAlignment(Qt::AlignLeft | Qt::AlignTop);
232     d->contactPhone->setAlignment(Qt::AlignLeft | Qt::AlignTop);
233     d->contactEmail->setAlignment(Qt::AlignLeft | Qt::AlignTop);
234     d->contactWebUrl->setAlignment(Qt::AlignLeft | Qt::AlignTop);
235 
236     addItem(w3, QIcon::fromTheme(QLatin1String("view-pim-contacts")),
237             i18n("Contact"), QLatin1String("Contact"), true);
238 
239     // ------------------------------------------------------------------
240 
241     DVBox* const w4 = new DVBox(this);
242     d->subjectsList = new DTextList(QStringList(), w4);
243 
244     addItem(w4, QIcon::fromTheme(QLatin1String("feed-subscribe")),
245             i18n("Subjects"), QLatin1String("Subjects"), true);
246 
247     addStretch();
248 }
249 
~TemplateViewer()250 TemplateViewer::~TemplateViewer()
251 {
252     delete d;
253 }
254 
setTemplate(const Template & t)255 void TemplateViewer::setTemplate(const Template& t)
256 {
257     d->namesList->clear();
258     d->namesList->addItems(t.authors());
259     d->labelPosition->setText(t.authorsPosition());
260     d->labelCredit->setText(t.credit());
261     d->labelCopyright->setText(t.copyright().value(QLatin1String("x-default")));
262     d->labelUsages->setText(t.rightUsageTerms().value(QLatin1String("x-default")));
263     d->labelSource->setText(t.source());
264     d->labelInstructions->setText(t.instructions());
265 
266     d->labelLocationCity->setText(t.locationInfo().city);
267     d->labelLocationSublocation->setText(t.locationInfo().location);
268     d->labelLocationProvinceState->setText(t.locationInfo().provinceState);
269     d->labelLocationCountry->setText(CountrySelector::countryForCode(t.locationInfo().countryCode));
270 
271     d->labelContactAddress->setText(t.contactInfo().address);
272     d->labelContactPostalCode->setText(t.contactInfo().postalCode);
273     d->labelContactProvinceState->setText(t.contactInfo().provinceState);
274     d->labelContactCity->setText(t.contactInfo().city);
275     d->labelContactCountry->setText(t.contactInfo().country);
276     d->labelContactPhone->setText(t.contactInfo().phone);
277     d->labelContactEmail->setAdjustedText(QString::fromUtf8("<a href=\"mailto:%1\">%2</a>").arg(t.contactInfo().email).arg(t.contactInfo().email));
278     d->labelContactWebUrl->setAdjustedText(QString::fromUtf8("<a href=\"%1\">%2</a>").arg(t.contactInfo().webUrl).arg(t.contactInfo().webUrl));
279 
280     d->subjectsList->clear();
281     d->subjectsList->addItems(t.IptcSubjects());
282 }
283 
284 } // namespace Digikam
285