28 #include "subjectwidget.moc"
33 #include <QDomDocument>
34 #include <QDomElement>
36 #include <QGridLayout>
38 #include <QPushButton>
39 #include <QRadioButton>
44 #include <kcombobox.h>
48 #include <kiconloader.h>
49 #include <klineedit.h>
50 #include <klistwidget.h>
52 #include <kstandarddirs.h>
58 class SubjectWidget::Private
88 SubjectCodesMap subMap;
111 KListWidget* subjectsBox;
117 :
QWidget(parent), d(new Private)
122 KGlobal::dirs()->addResourceDir(
"iptcschema", KStandardDirs::installPath(
"data") +
124 QString path = KGlobal::dirs()->findResource(
"iptcschema",
"topicset.iptc-subjectcode.xml");
127 kDebug() <<
"Cannot load IPTC/NAA subject codes XML database";
132 QRegExp refDigitRx(
"^[0-9]{8}$");
144 "<b><a href='http://www.iptc.org/site/NewsCodes'>"
145 "reference code</a></b>"));
152 QLabel* customLabel =
new QLabel(i18n(
"Use custom definition"));
154 d->btnGroup->addButton(d->stdBtn, Private::STANDARD);
155 d->btnGroup->addButton(d->customBtn, Private::CUSTOM);
156 d->btnGroup->setExclusive(
true);
157 d->stdBtn->setChecked(
true);
160 it != d->subMap.end(); ++it)
161 d->refCB->addItem(it.key());
196 d->iprLabel =
new QLabel(i18nc(
"Information Provider Reference: "
197 "A name, registered with the IPTC/NAA, "
198 "identifying the provider that guarantees "
199 "the uniqueness of the UNO",
"I.P.R:"));
200 d->refLabel =
new QLabel(i18n(
"Reference:"));
201 d->nameLabel =
new QLabel(i18n(
"Name:"));
202 d->matterLabel =
new QLabel(i18n(
"Matter:"));
203 d->detailLabel =
new QLabel(i18n(
"Detail:"));
207 d->subjectsBox =
new KListWidget;
208 d->subjectsBox->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
210 d->addSubjectButton =
new QPushButton(i18n(
"&Add"));
211 d->delSubjectButton =
new QPushButton(i18n(
"&Delete"));
212 d->repSubjectButton =
new QPushButton(i18n(
"&Replace"));
213 d->addSubjectButton->setIcon(SmallIcon(
"list-add"));
214 d->delSubjectButton->setIcon(SmallIcon(
"edit-delete"));
215 d->repSubjectButton->setIcon(SmallIcon(
"view-refresh"));
216 d->delSubjectButton->setEnabled(
false);
217 d->repSubjectButton->setEnabled(
false);
230 optionsBoxLayout->
addWidget(d->stdBtn, 0, 0, 1, 1);
231 optionsBoxLayout->
addWidget(codeLink, 0, 1, 1, 2);
232 optionsBoxLayout->
addWidget(d->refCB, 0, 3, 1, 1);
233 optionsBoxLayout->
addWidget(d->customBtn, 1, 0, 1, 4);
234 optionsBoxLayout->
addWidget(customLabel, 1, 1, 1, 4);
235 optionsBoxLayout->
addWidget(d->iprLabel, 2, 0, 1, 1);
237 optionsBoxLayout->
addWidget(d->refLabel, 3, 0, 1, 1);
239 optionsBoxLayout->
addWidget(d->nameLabel, 4, 0, 1, 1);
241 optionsBoxLayout->
addWidget(d->matterLabel, 5, 0, 1, 1);
243 optionsBoxLayout->
addWidget(d->detailLabel, 6, 0, 1, 1);
247 optionsBoxLayout->
setSpacing(KDialog::spacingHint());
248 d->optionsBox->setLayout(optionsBoxLayout);
255 mainLayout->
addWidget(d->optionsBox, 1, 0, 1, 4);
256 mainLayout->
addWidget(d->subjectsBox, 2, 0, 5, 3);
257 mainLayout->
addWidget(d->addSubjectButton, 2, 3, 1, 1);
258 mainLayout->
addWidget(d->delSubjectButton, 3, 3, 1, 1);
259 mainLayout->
addWidget(d->repSubjectButton, 4, 3, 1, 1);
264 mainLayout->
setSpacing(KDialog::spacingHint());
269 connect(d->subjectsBox, SIGNAL(itemSelectionChanged()),
272 connect(d->addSubjectButton, SIGNAL(clicked()),
275 connect(d->delSubjectButton, SIGNAL(clicked()),
278 connect(d->repSubjectButton, SIGNAL(clicked()),
281 connect(d->btnGroup, SIGNAL(buttonReleased(
int)),
284 connect(d->refCB, SIGNAL(activated(
int)),
297 connect(d->addSubjectButton, SIGNAL(clicked()),
300 connect(d->delSubjectButton, SIGNAL(clicked()),
303 connect(d->repSubjectButton, SIGNAL(clicked()),
318 d->optionsBox->setEnabled(b);
319 d->subjectsBox->setEnabled(b);
320 d->addSubjectButton->setEnabled(b);
321 d->delSubjectButton->setEnabled(b);
322 d->repSubjectButton->setEnabled(b);
328 if (b == Private::CUSTOM)
330 d->refCB->setEnabled(
false);
339 d->refCB->setEnabled(
true);
351 QString key = d->refCB->currentText();
355 it != d->subMap.end(); ++it)
359 name = it.value().name;
360 matter = it.value().matter;
361 detail = it.value().detail;
389 d->subjectsBox->takeItem(d->subjectsBox->row(item));
396 if (newSubject.
isEmpty())
return;
398 if (!d->subjectsBox->selectedItems().isEmpty())
400 d->subjectsBox->selectedItems()[0]->setText(newSubject);
411 if (!d->subjectsBox->selectedItems().isEmpty())
413 QString subject = d->subjectsBox->selectedItems()[0]->text();
419 d->delSubjectButton->setEnabled(
true);
420 d->repSubjectButton->setEnabled(
true);
424 d->delSubjectButton->setEnabled(
false);
425 d->repSubjectButton->setEnabled(
false);
432 if (newSubject.
isEmpty())
return;
435 for (
int i = 0 ; i < d->subjectsBox->count(); i++)
438 if (newSubject == item->
text())
447 d->subjectsBox->insertItem(d->subjectsBox->count(), newSubject);
458 QFile xmlfile(url.toLocalFile());
460 if (!xmlfile.open(QIODevice::ReadOnly))
468 if (xmlDocElem.
tagName()!=
"NewsML")
472 !nbE1.
isNull(); nbE1 = nbE1.nextSibling())
475 if (newsItemElement.
isNull())
continue;
476 if (newsItemElement.
tagName() !=
"NewsItem")
continue;
479 !nbE2.
isNull(); nbE2 = nbE2.nextSibling())
482 if (topicSetElement.
isNull())
continue;
483 if (topicSetElement.
tagName() !=
"TopicSet")
continue;
486 !nbE3.
isNull(); nbE3 = nbE3.nextSibling())
489 if (topicElement.
isNull())
continue;
490 if (topicElement.
tagName() !=
"Topic")
continue;
494 !nbE4.
isNull(); nbE4 = nbE4.nextSibling())
497 if (topicSubElement.
isNull())
continue;
499 if (topicSubElement.
tagName() ==
"TopicType")
500 type = topicSubElement.
attribute(
"FormalName");
502 if (topicSubElement.
tagName() ==
"FormalName")
503 ref = topicSubElement.
text();
505 if (topicSubElement.
tagName() ==
"Description" &&
506 topicSubElement.
attribute(
"Variant") ==
"Name")
508 if (type ==
"Subject")
509 name = topicSubElement.
text();
510 else if (type ==
"SubjectMatter")
511 matter = topicSubElement.
text();
512 else if (type ==
"SubjectDetail")
513 detail = topicSubElement.
text();
517 d->subMap.insert(ref,
SubjectData(name, matter, detail));
525 it != d->subMap.end(); ++it)
530 keyPrefix = it.key().
left(3);
531 name = it.value().name;
534 it2 != d->subMap.end(); ++it2)
536 if (it2.key().startsWith(keyPrefix) &&
539 it2.value().name =
name;
548 it != d->subMap.end(); ++it)
553 keyPrefix = it.key().
left(5);
554 matter = it.value().matter;
557 it2 != d->subMap.end(); ++it2)
559 if (it2.key().startsWith(keyPrefix) &&
562 it2.value().matter = matter;
573 d->subjectsList = list;
576 d->subjectsBox->clear();
578 if (!d->subjectsList.isEmpty())
580 d->subjectsBox->insertItems(0, d->subjectsList);
592 for (
int i = 0 ; i < d->subjectsBox->count(); i++)
QString & append(QChar ch)
QString attribute(const QString &name, const QString &defValue) const
void setOpenExternalLinks(bool open)
QDomElement documentElement() const
void setFrameStyle(int style)
void setSpacing(int spacing)
QDomElement toElement() const
const char * name() const
void append(const T &value)
void setRowStretch(int row, int stretch)
void setMargin(int margin)
bool blockSignals(bool block)
bool setAlignment(QWidget *w, QFlags< Qt::AlignmentFlag > alignment)
QDomNode firstChild() const
void setColumnStretch(int column, int stretch)
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
QString left(int n) const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setWordWrap(bool on)
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)