1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2007-10-24
7 * Description : XMP workflow status settings page.
8 *
9 * Copyright (C) 2007-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) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * ============================================================ */
22
23 #include "xmpstatus.h"
24
25 // Qt includes
26
27 #include <QCheckBox>
28 #include <QGridLayout>
29 #include <QApplication>
30 #include <QStyle>
31 #include <QLineEdit>
32 #include <QPlainTextEdit>
33
34 // KDE includes
35
36 #include <klocalizedstring.h>
37
38 // Local includes
39
40 #include "altlangstringedit.h"
41 #include "multistringsedit.h"
42
43 namespace DigikamGenericMetadataEditPlugin
44 {
45
46 class Q_DECL_HIDDEN XMPStatus::Private
47 {
48 public:
49
Private()50 explicit Private()
51 : nicknameCheck (nullptr),
52 specialInstructionCheck(nullptr),
53 nicknameEdit (nullptr),
54 specialInstructionEdit (nullptr),
55 identifiersEdit (nullptr),
56 objectNameEdit (nullptr)
57 {
58 }
59
60 QCheckBox* nicknameCheck;
61 QCheckBox* specialInstructionCheck;
62
63 QLineEdit* nicknameEdit;
64
65 QPlainTextEdit* specialInstructionEdit;
66
67 MultiStringsEdit* identifiersEdit;
68
69 AltLangStringsEdit* objectNameEdit;
70 };
71
XMPStatus(QWidget * const parent)72 XMPStatus::XMPStatus(QWidget* const parent)
73 : QWidget(parent),
74 d (new Private)
75 {
76 QGridLayout* const grid = new QGridLayout(this);
77
78 // --------------------------------------------------------
79
80 d->objectNameEdit = new AltLangStringsEdit(this, i18nc("short title for the content", "Title:"),
81 i18n("Set here a shorthand reference for the content."));
82
83 // --------------------------------------------------------
84
85 d->nicknameCheck = new QCheckBox(i18n("Nickname:"), this);
86 d->nicknameEdit = new QLineEdit(this);
87 d->nicknameEdit->setClearButtonEnabled(true);
88 d->nicknameEdit->setWhatsThis(i18n("A short informal name for the resource."));
89
90 // --------------------------------------------------------
91
92 d->identifiersEdit = new MultiStringsEdit(this, i18n("Identifiers:"),
93 i18n("Set here the strings that identify content that recurs."));
94
95 // --------------------------------------------------------
96
97 d->specialInstructionCheck = new QCheckBox(i18n("Special Instructions:"), this);
98 d->specialInstructionEdit = new QPlainTextEdit(this);
99 d->specialInstructionEdit->setWhatsThis(i18n("Enter the editorial usage instructions."));
100
101 // --------------------------------------------------------
102
103 grid->addWidget(d->objectNameEdit, 0, 0, 1, 3);
104 grid->addWidget(d->nicknameCheck, 1, 0, 1, 1);
105 grid->addWidget(d->nicknameEdit, 1, 1, 1, 2);
106 grid->addWidget(d->identifiersEdit, 2, 0, 1, 3);
107 grid->addWidget(d->specialInstructionCheck, 3, 0, 1, 3);
108 grid->addWidget(d->specialInstructionEdit, 4, 0, 1, 3);
109 grid->setRowStretch(5, 10);
110 grid->setColumnStretch(2, 10);
111 grid->setContentsMargins(QMargins());
112 grid->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
113
114 // --------------------------------------------------------
115
116 connect(d->specialInstructionCheck, SIGNAL(toggled(bool)),
117 d->specialInstructionEdit, SLOT(setEnabled(bool)));
118
119 connect(d->nicknameCheck, SIGNAL(toggled(bool)),
120 d->nicknameEdit, SLOT(setEnabled(bool)));
121
122 connect(d->identifiersEdit, SIGNAL(signalModified()),
123 this, SIGNAL(signalModified()));
124
125 // --------------------------------------------------------
126
127 connect(d->objectNameEdit, SIGNAL(signalToggled(bool)),
128 this, SIGNAL(signalModified()));
129
130 connect(d->nicknameCheck, SIGNAL(toggled(bool)),
131 this, SIGNAL(signalModified()));
132
133 connect(d->specialInstructionCheck, SIGNAL(toggled(bool)),
134 this, SIGNAL(signalModified()));
135
136 // --------------------------------------------------------
137
138 connect(d->objectNameEdit, SIGNAL(signalModified()),
139 this, SIGNAL(signalModified()));
140
141 connect(d->nicknameEdit, SIGNAL(textChanged(QString)),
142 this, SIGNAL(signalModified()));
143
144 connect(d->specialInstructionEdit, SIGNAL(textChanged()),
145 this, SIGNAL(signalModified()));
146 }
147
~XMPStatus()148 XMPStatus::~XMPStatus()
149 {
150 delete d;
151 }
152
readMetadata(const DMetadata & meta)153 void XMPStatus::readMetadata(const DMetadata& meta)
154 {
155 blockSignals(true);
156
157 QString data;
158 QStringList list;
159 DMetadata::AltLangMap map;
160
161 d->objectNameEdit->setValues(map);
162 d->objectNameEdit->setValid(false);
163 map = meta.getXmpTagStringListLangAlt("Xmp.dc.title", false);
164
165 if (!map.isEmpty())
166 {
167 d->objectNameEdit->setValues(map);
168 d->objectNameEdit->setValid(true);
169 }
170
171 d->nicknameEdit->clear();
172 d->nicknameCheck->setChecked(false);
173 data = meta.getXmpTagString("Xmp.xmp.Nickname", false);
174
175 if (!data.isNull())
176 {
177 d->nicknameEdit->setText(data);
178 d->nicknameCheck->setChecked(true);
179 }
180
181 d->nicknameEdit->setEnabled(d->nicknameCheck->isChecked());
182
183 list = meta.getXmpTagStringSeq("Xmp.xmp.Identifier", false);
184 d->identifiersEdit->setValues(list);
185
186 d->specialInstructionEdit->clear();
187 d->specialInstructionCheck->setChecked(false);
188 data = meta.getXmpTagString("Xmp.photoshop.Instructions", false);
189
190 if (!data.isNull())
191 {
192 d->specialInstructionEdit->setPlainText(data);
193 d->specialInstructionCheck->setChecked(true);
194 }
195
196 d->specialInstructionEdit->setEnabled(d->specialInstructionCheck->isChecked());
197
198 blockSignals(false);
199 }
200
applyMetadata(const DMetadata & meta)201 void XMPStatus::applyMetadata(const DMetadata& meta)
202 {
203 QStringList oldList, newList;
204
205 DMetadata::AltLangMap oldAltLangMap, newAltLangMap;
206
207 if (d->objectNameEdit->getValues(oldAltLangMap, newAltLangMap))
208 {
209 meta.setXmpTagStringListLangAlt("Xmp.dc.title", newAltLangMap);
210 }
211 else if (d->objectNameEdit->isValid())
212 {
213 meta.removeXmpTag("Xmp.dc.title");
214 }
215
216 if (d->nicknameCheck->isChecked())
217 {
218 meta.setXmpTagString("Xmp.xmp.Nickname", d->nicknameEdit->text());
219 }
220 else
221 {
222 meta.removeXmpTag("Xmp.xmp.Nickname");
223 }
224
225 if (d->identifiersEdit->getValues(oldList, newList))
226 {
227 meta.setXmpTagStringSeq("Xmp.xmp.Identifier", newList);
228 }
229 else
230 {
231 meta.removeXmpTag("Xmp.xmp.Identifier");
232 }
233
234 if (d->specialInstructionCheck->isChecked())
235 {
236 meta.setXmpTagString("Xmp.photoshop.Instructions", d->specialInstructionEdit->toPlainText());
237 }
238 else
239 {
240 meta.removeXmpTag("Xmp.photoshop.Instructions");
241 }
242 }
243
244 } // namespace DigikamGenericMetadataEditPlugin
245