File indexing completed on 2025-01-19 03:59:45

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2015-07-03
0007  * Description : dialog to edit and create digiKam xmp namespaces
0008  *
0009  * SPDX-FileCopyrightText: 2015 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "namespaceeditdlg.h"
0016 
0017 // Qt includes
0018 
0019 #include <QGridLayout>
0020 #include <QLabel>
0021 #include <QDialogButtonBox>
0022 #include <QPushButton>
0023 #include <QApplication>
0024 #include <QStyle>
0025 #include <QPointer>
0026 #include <QLineEdit>
0027 #include <QCheckBox>
0028 #include <QStandardPaths>
0029 #include <QSpinBox>
0030 #include <QDebug>
0031 #include <QComboBox>
0032 #include <QGroupBox>
0033 
0034 // KDE includes
0035 
0036 #include <klocalizedstring.h>
0037 
0038 // Local includes
0039 
0040 #include "digikam_debug.h"
0041 #include "digikam_globals.h"
0042 #include "dxmlguiwindow.h"
0043 
0044 namespace Digikam
0045 {
0046 
0047 class Q_DECL_HIDDEN NamespaceEditDlg::Private
0048 {
0049 public:
0050 
0051     explicit Private()
0052       : buttons             (nullptr),
0053         create              (0),
0054         topLabel            (nullptr),
0055         logo                (nullptr),
0056         gridLayout          (nullptr),
0057         page                (nullptr),
0058         subspaceCombo       (nullptr),           ///< NamespaceEntry variables
0059         specialOptsCombo    (nullptr),
0060         altSpecialOptsCombo (nullptr),
0061         namespaceName       (nullptr),
0062         alternativeName     (nullptr),
0063         nameSpaceSeparator  (nullptr),
0064         isPath              (nullptr),
0065         ratingMappings      (nullptr),
0066         zeroStars           (nullptr),
0067         oneStar             (nullptr),
0068         twoStars            (nullptr),
0069         threeStars          (nullptr),
0070         fourStars           (nullptr),
0071         fiveStars           (nullptr),
0072         tagTipLabel         (nullptr),           ///< Labels
0073         ratingTipLabel      (nullptr),
0074         commentTipLabel     (nullptr),
0075         subspaceLabel       (nullptr),
0076         titleLabel          (nullptr),
0077         specialOptsLabel    (nullptr),
0078         alternativeNameLabel(nullptr),
0079         altspecialOptsLabel (nullptr),
0080         isTagLabel          (nullptr),
0081         separatorLabel      (nullptr),
0082         tipLabel2           (nullptr),
0083         nsType              (NamespaceEntry::TAGS)
0084     {
0085     }
0086 
0087     QDialogButtonBox*               buttons;
0088     bool                            create;
0089     QLabel*                         topLabel;
0090     QLabel*                         logo;
0091     QGridLayout*                    gridLayout;
0092     QWidget*                        page;
0093 
0094     /// NamespaceEntry variables
0095     QComboBox*                      subspaceCombo;
0096     QComboBox*                      specialOptsCombo;
0097     QComboBox*                      altSpecialOptsCombo;
0098     QLineEdit*                      namespaceName;
0099     QLineEdit*                      alternativeName;
0100     QLineEdit*                      nameSpaceSeparator;
0101     QCheckBox*                      isPath;
0102     QGroupBox*                      ratingMappings;
0103 
0104     QSpinBox*                       zeroStars;
0105     QSpinBox*                       oneStar;
0106     QSpinBox*                       twoStars;
0107     QSpinBox*                       threeStars;
0108     QSpinBox*                       fourStars;
0109     QSpinBox*                       fiveStars;
0110 
0111     /// Labels
0112     QLabel*                         tagTipLabel;
0113     QLabel*                         ratingTipLabel;
0114     QLabel*                         commentTipLabel;
0115     QLabel*                         subspaceLabel;
0116     QLabel*                         titleLabel;
0117     QLabel*                         specialOptsLabel;
0118     QLabel*                         alternativeNameLabel;
0119     QLabel*                         altspecialOptsLabel;
0120     QLabel*                         isTagLabel;
0121     QLabel*                         separatorLabel;
0122 
0123     QLabel*                         tipLabel2;
0124 
0125     NamespaceEntry::NamespaceType   nsType;
0126 };
0127 
0128 NamespaceEditDlg::NamespaceEditDlg(bool create,
0129                                    NamespaceEntry& entry,
0130                                    QWidget* const parent)
0131     : QDialog(parent),
0132       d      (new Private())
0133 {
0134     setModal(true);
0135 
0136     d->buttons = new QDialogButtonBox(QDialogButtonBox::Help |
0137                                       QDialogButtonBox::Ok   |
0138                                       QDialogButtonBox::Cancel, this);
0139 
0140     d->buttons->button(QDialogButtonBox::Ok)->setDefault(true);
0141 
0142     if (create)
0143     {
0144         setWindowTitle(i18nc("@title:window", "New XMP Namespace"));
0145     }
0146     else
0147     {
0148         setWindowTitle(i18nc("@title:window", "Edit XMP Namespace"));
0149     }
0150 
0151     d->create = create;
0152     d->nsType = entry.nsType;
0153 
0154     setupTagGui(entry);
0155 
0156     // --- NOTE: use dynamic binding as slots below are virtual method which can be re-implemented in derived classes.
0157 
0158     connect(d->buttons->button(QDialogButtonBox::Ok), &QPushButton::clicked,
0159             this, &NamespaceEditDlg::accept);
0160 
0161     connect(d->buttons->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
0162             this, &NamespaceEditDlg::reject);
0163 
0164     connect(d->buttons->button(QDialogButtonBox::Help), &QPushButton::clicked,
0165             this, &NamespaceEditDlg::slotHelp);
0166 
0167     // --------------------------------------------------------
0168 
0169     if (!d->create)
0170     {
0171         populateFields(entry);
0172     }
0173 
0174     setType(entry.nsType);
0175 
0176     if (entry.isDefault)
0177     {
0178         makeReadOnly();
0179     }
0180 
0181     qCDebug(DIGIKAM_GENERAL_LOG) << "Entry type" << entry.nsType
0182                                  << "subspace" << entry.subspace
0183                                  << entry.isDefault;
0184     adjustSize();
0185 }
0186 
0187 NamespaceEditDlg::~NamespaceEditDlg()
0188 {
0189     delete d;
0190 }
0191 
0192 bool NamespaceEditDlg::create(QWidget* const parent, NamespaceEntry& entry)
0193 {
0194     QPointer<NamespaceEditDlg> dlg = new NamespaceEditDlg(true,entry,parent);
0195 
0196     qCDebug(DIGIKAM_GENERAL_LOG) << "Name before save: " << entry.namespaceName;
0197     bool valRet                    = dlg->exec();
0198 
0199     if (valRet == QDialog::Accepted)
0200     {
0201         dlg->saveData(entry);
0202     }
0203 
0204     qCDebug(DIGIKAM_GENERAL_LOG) << "Name after save: " << entry.namespaceName;
0205     delete dlg;
0206 
0207     return valRet;
0208 }
0209 
0210 bool NamespaceEditDlg::edit(QWidget* const parent, NamespaceEntry& entry)
0211 {
0212     QPointer<NamespaceEditDlg> dlg = new NamespaceEditDlg(false, entry, parent);
0213 
0214     qCDebug(DIGIKAM_GENERAL_LOG) << "Name before save: " << entry.namespaceName;
0215     bool valRet                    = dlg->exec();
0216 
0217     if (valRet == QDialog::Accepted && !entry.isDefault)
0218     {
0219         dlg->saveData(entry);
0220     }
0221 
0222     qCDebug(DIGIKAM_GENERAL_LOG) << "Name before save: " << entry.namespaceName;
0223     delete dlg;
0224 
0225     return valRet;
0226 }
0227 
0228 void NamespaceEditDlg::setupTagGui(NamespaceEntry& entry)
0229 {
0230     d->page          = new QWidget(this);
0231     d->gridLayout    = new QGridLayout(d->page);
0232     d->logo          = new QLabel(d->page);
0233     d->logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(48,48)));
0234 
0235     d->topLabel      = new QLabel(d->page);
0236     d->topLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
0237     d->topLabel->setWordWrap(false);
0238     d->topLabel->setText(i18n("Add metadata namespace"));
0239 
0240     d->subspaceCombo = new QComboBox(this);
0241     d->subspaceLabel = new QLabel(d->page);
0242     d->subspaceLabel->setText(i18n("Metadata Subspace"));
0243 
0244     d->subspaceCombo->addItem(QLatin1String("EXIF"), (int)NamespaceEntry::EXIF);
0245     d->subspaceCombo->addItem(QLatin1String("IPTC"), (int)NamespaceEntry::IPTC);
0246     d->subspaceCombo->addItem(QLatin1String("XMP"),  (int)NamespaceEntry::XMP);
0247     d->subspaceCombo->setCurrentIndex((int)entry.subspace);
0248 
0249     qCDebug(DIGIKAM_GENERAL_LOG) << "Entry subspace" << (int)entry.subspace;
0250 
0251     // -------------------Tag Elements---------------------------------
0252 
0253     d->titleLabel    = new QLabel(d->page);
0254     d->titleLabel->setText(i18nc("@label: namespace name", "Name:"));
0255     d->namespaceName = new QLineEdit(this);
0256 
0257     //----------------- Tip Labels --------------------------------------
0258 
0259     d->tagTipLabel   = new QLabel(d->page);
0260     d->tagTipLabel->setTextFormat(Qt::RichText);
0261     d->tagTipLabel->setWordWrap(true);
0262     d->tagTipLabel->setText(i18n("<p>To create new namespaces, you need to specify parameters:</p>"
0263                                  "<p><ul><li>Namespace name with dots.<br/>"
0264                                  "Ex.: <i>\"Xmp.digiKam.TagsList\"</i></li>"
0265                                  "<li>Separator parameter, used by tag paths <br/>"
0266                                  "Ex.: \"City/Paris\" or \"City|Paris\"</li>"
0267                                  "<li>Specify if only keyword or the whole path must be written.</li></ul></p>"
0268     ));
0269 
0270     d->ratingTipLabel   = new QLabel(d->page);
0271     d->ratingTipLabel->setTextFormat(Qt::RichText);
0272     d->ratingTipLabel->setWordWrap(true);
0273     d->ratingTipLabel->setText(i18n("<p>To create new rating namespaces, you need to specify parameters:</p>"
0274                                     "<p><ul><li>Namespace name with dots.<br/>"
0275                                     "Ex.: <i>\"Xmp.xmp.Rating\"</i></li>"
0276                                     "<li>Rating mappings, if namespace need other values than 0-5 <br/>"
0277                                     "Ex.: Microsoft uses 0 1 25 50 75 99</li>"
0278                                     "<li>Select the correct namespace option from list.</li></ul></p>"
0279     ));
0280 
0281     d->commentTipLabel   = new QLabel(d->page);
0282     d->commentTipLabel->setTextFormat(Qt::RichText);
0283     d->commentTipLabel->setWordWrap(true);
0284     d->commentTipLabel->setText(i18n("<p>To create new comment namespaces, you need to specify parameters:</p>"
0285                                      "<p><ul><li>Namespace name with dots.<br/>"
0286                                      "Ex.: <i>\"Xmp.xmp.Comment\"</i></li>"
0287                                      "<li>Select the correct namespace option from list.</li></ul></p>"
0288     ));
0289 
0290     // -------------------------------------------------------
0291 
0292     d->specialOptsLabel = new QLabel(d->page);
0293     d->specialOptsLabel->setText(i18n("Special Options"));
0294     d->specialOptsCombo = new QComboBox(d->page);
0295 
0296     d->specialOptsCombo->addItem(QLatin1String("NO_OPTS"), (int)NamespaceEntry::NO_OPTS);
0297 
0298     if (entry.nsType == NamespaceEntry::TITLE)
0299     {
0300         d->specialOptsCombo->addItem(QLatin1String("COMMENT_ALTLANGLIST"), NamespaceEntry::COMMENT_ATLLANGLIST);
0301         d->specialOptsCombo->addItem(QLatin1String("COMMENT_XMP"),         NamespaceEntry::COMMENT_XMP);
0302     }
0303 
0304     if (entry.nsType == NamespaceEntry::COMMENT)
0305     {
0306         d->specialOptsCombo->addItem(QLatin1String("COMMENT_ALTLANG"),     NamespaceEntry::COMMENT_ALTLANG);
0307         d->specialOptsCombo->addItem(QLatin1String("COMMENT_ALTLANGLIST"), NamespaceEntry::COMMENT_ATLLANGLIST);
0308         d->specialOptsCombo->addItem(QLatin1String("COMMENT_XMP"),         NamespaceEntry::COMMENT_XMP);
0309         d->specialOptsCombo->addItem(QLatin1String("COMMENT_JPEG"),        NamespaceEntry::COMMENT_JPEG);
0310     }
0311 
0312     if (entry.nsType == NamespaceEntry::TAGS)
0313     {
0314         d->specialOptsCombo->addItem(QLatin1String("TAG_XMPBAG"), NamespaceEntry::TAG_XMPBAG);
0315         d->specialOptsCombo->addItem(QLatin1String("TAG_XMPSEQ"), NamespaceEntry::TAG_XMPSEQ);
0316         d->specialOptsCombo->addItem(QLatin1String("TAG_ACDSEE"), NamespaceEntry::TAG_ACDSEE);
0317     }
0318 
0319     d->alternativeNameLabel = new QLabel(d->page);
0320     d->alternativeNameLabel->setText(i18n("Alternative name"));
0321     d->alternativeName      = new QLineEdit(d->page);
0322 
0323     d->altspecialOptsLabel  = new QLabel(d->page);
0324     d->altspecialOptsLabel->setText(i18n("Alternative special options"));
0325 
0326     d->altSpecialOptsCombo  = new QComboBox(d->page);
0327 
0328     d->altSpecialOptsCombo->addItem(QLatin1String("NO_OPTS"), (int)NamespaceEntry::NO_OPTS);
0329 
0330     if (entry.nsType == NamespaceEntry::TITLE)
0331     {
0332         d->altSpecialOptsCombo->addItem(QLatin1String("COMMENT_ALTLANGLIST"), NamespaceEntry::COMMENT_ATLLANGLIST);
0333         d->altSpecialOptsCombo->addItem(QLatin1String("COMMENT_XMP"),         NamespaceEntry::COMMENT_XMP);
0334     }
0335 
0336     if (entry.nsType == NamespaceEntry::COMMENT)
0337     {
0338         d->altSpecialOptsCombo->addItem(QLatin1String("COMMENT_ALTLANG"),     NamespaceEntry::COMMENT_ALTLANG);
0339         d->altSpecialOptsCombo->addItem(QLatin1String("COMMENT_ALTLANGLIST"), NamespaceEntry::COMMENT_ATLLANGLIST);
0340         d->altSpecialOptsCombo->addItem(QLatin1String("COMMENT_XMP"),         NamespaceEntry::COMMENT_XMP);
0341         d->altSpecialOptsCombo->addItem(QLatin1String("COMMENT_JPEG"),        NamespaceEntry::COMMENT_JPEG);
0342     }
0343 
0344     if (entry.nsType == NamespaceEntry::TAGS)
0345     {
0346         d->altSpecialOptsCombo->addItem(QLatin1String("TAG_XMPBAG"), NamespaceEntry::TAG_XMPBAG);
0347         d->altSpecialOptsCombo->addItem(QLatin1String("TAG_XMPSEQ"), NamespaceEntry::TAG_XMPSEQ);
0348         d->altSpecialOptsCombo->addItem(QLatin1String("TAG_ACDSEE"), NamespaceEntry::TAG_ACDSEE);
0349     }
0350 
0351     // --------------------------------------------------------
0352 
0353     d->separatorLabel     = new QLabel(d->page);
0354     d->separatorLabel->setText(i18n("Separator:"));
0355     d->nameSpaceSeparator = new QLineEdit(this);
0356 
0357     // --------------------------------------------------------
0358 
0359     d->isTagLabel = new QLabel(d->page);
0360     d->isTagLabel->setText(i18n("Set Tags Path:"));
0361     d->isPath     = new QCheckBox(this);
0362 
0363     d->tipLabel2  = new QLabel(d->page);
0364     d->tipLabel2->setTextFormat(Qt::RichText);
0365     d->tipLabel2->setWordWrap(true);
0366     QPalette sample_palette;
0367     sample_palette.setColor(QPalette::Window, QColor(255, 51, 51, 150));
0368     sample_palette.setColor(QPalette::WindowText, Qt::black);
0369 
0370     d->tipLabel2->setAutoFillBackground(true);
0371     d->tipLabel2->setPalette(sample_palette);
0372     d->tipLabel2->hide();
0373 
0374     // ----------------------Rating Elements----------------------------------
0375 
0376     d->ratingMappings                       = new QGroupBox(this);
0377     d->ratingMappings->setFlat(true);
0378     QGridLayout* const ratingMappingsLayout = new QGridLayout(d->ratingMappings);
0379     QLabel* const ratingLabel               = new QLabel(d->page);
0380     ratingLabel->setText(i18n("Rating Mapping:"));
0381 
0382     d->zeroStars  = new QSpinBox(this);
0383     d->zeroStars->setValue(0);
0384 
0385     d->oneStar    = new QSpinBox(this);
0386     d->oneStar->setValue(1);
0387 
0388     d->twoStars   = new QSpinBox(this);
0389     d->twoStars->setValue(2);
0390 
0391     d->threeStars = new QSpinBox(this);
0392     d->threeStars->setValue(3);
0393 
0394     d->fourStars  = new QSpinBox(this);
0395     d->fourStars->setValue(4);
0396 
0397     d->fiveStars  = new QSpinBox(this);
0398     d->fiveStars->setValue(5);
0399 
0400     const int spacing = qMin(style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0401                              style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0402     const int cmargin = qMin(style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
0403                              qMin(style()->pixelMetric(QStyle::PM_LayoutTopMargin),
0404                                   qMin(style()->pixelMetric(QStyle::PM_LayoutRightMargin),
0405                                        style()->pixelMetric(QStyle::PM_LayoutBottomMargin))));
0406 
0407     ratingMappingsLayout->addWidget(ratingLabel,            0, 0, 1, 2);
0408 
0409     ratingMappingsLayout->addWidget(d->zeroStars,           1, 0, 1, 1);
0410     ratingMappingsLayout->addWidget(d->oneStar,             1, 1, 1, 1);
0411     ratingMappingsLayout->addWidget(d->twoStars,            1, 2, 1, 1);
0412     ratingMappingsLayout->addWidget(d->threeStars,          1, 3, 1, 1);
0413     ratingMappingsLayout->addWidget(d->fourStars,           1, 4, 1, 1);
0414     ratingMappingsLayout->addWidget(d->fiveStars,           1, 5, 1, 1);
0415 
0416     d->gridLayout->addWidget(d->logo,                       0, 0, 1, 2);
0417     d->gridLayout->addWidget(d->topLabel,                   0, 1, 1, 4);
0418     d->gridLayout->addWidget(d->tagTipLabel,                1, 0, 1, 6);
0419     d->gridLayout->addWidget(d->ratingTipLabel,             2, 0, 1, 6);
0420     d->gridLayout->addWidget(d->commentTipLabel,            3, 0, 1, 6);
0421 
0422     d->gridLayout->addWidget(d->subspaceLabel,              5, 0, 1, 2);
0423     d->gridLayout->addWidget(d->subspaceCombo,              5, 2, 1, 4);
0424 
0425     d->gridLayout->addWidget(d->titleLabel,                 6, 0, 1, 2);
0426     d->gridLayout->addWidget(d->namespaceName,              6, 2, 1, 4);
0427     d->gridLayout->addWidget(d->specialOptsLabel,           7, 0, 1, 2);
0428     d->gridLayout->addWidget(d->specialOptsCombo,           7, 2, 1, 4);
0429 
0430     d->gridLayout->addWidget(d->alternativeNameLabel,       8, 0, 1, 2);
0431     d->gridLayout->addWidget(d->alternativeName,            8, 2, 1, 4);
0432     d->gridLayout->addWidget(d->altspecialOptsLabel,        9, 0, 1, 2);
0433     d->gridLayout->addWidget(d->altSpecialOptsCombo,        9, 2, 1, 4);
0434 
0435     d->gridLayout->addWidget(d->separatorLabel,            10, 0, 1, 2);
0436     d->gridLayout->addWidget(d->nameSpaceSeparator,        10, 2, 1, 4);
0437     d->gridLayout->addWidget(d->isTagLabel,                11, 0, 1, 2);
0438     d->gridLayout->addWidget(d->isPath,                    11, 2, 1, 3);
0439 
0440     d->gridLayout->addWidget(d->ratingMappings,            12, 0, 2, 6);
0441     d->gridLayout->addWidget(d->tipLabel2,                 14, 0, 1, 6);
0442 
0443     d->gridLayout->setContentsMargins(cmargin, cmargin, cmargin, cmargin);
0444     d->gridLayout->setSpacing(spacing);
0445 
0446     QVBoxLayout* const vbx = new QVBoxLayout(this);
0447     vbx->addWidget(d->page);
0448     vbx->addWidget(d->buttons);
0449 }
0450 
0451 void NamespaceEditDlg::populateFields(NamespaceEntry& entry)
0452 {
0453     d->namespaceName->setText(entry.namespaceName);
0454     d->nameSpaceSeparator->setText(entry.separator);
0455 
0456     if (entry.tagPaths == NamespaceEntry::TAGPATH)
0457     {
0458         d->isPath->setChecked(true);
0459     }
0460     else
0461     {
0462         d->isPath->setChecked(false);
0463     }
0464 
0465     d->alternativeName->setText(entry.alternativeName);
0466     d->specialOptsCombo->setCurrentIndex(d->specialOptsCombo->findData(entry.specialOpts));
0467     d->altSpecialOptsCombo->setCurrentIndex(d->altSpecialOptsCombo->findData(entry.secondNameOpts));
0468 
0469     if (entry.convertRatio.size() == 6)
0470     {
0471         d->zeroStars->setValue(entry.convertRatio.at(0));
0472         d->oneStar->setValue(entry.convertRatio.at(1));
0473         d->twoStars->setValue(entry.convertRatio.at(2));
0474         d->threeStars->setValue(entry.convertRatio.at(3));
0475         d->fourStars->setValue(entry.convertRatio.at(4));
0476         d->fiveStars->setValue(entry.convertRatio.at(5));
0477     }
0478 }
0479 
0480 void NamespaceEditDlg::setType(NamespaceEntry::NamespaceType type)
0481 {
0482     switch (type)
0483     {
0484         case NamespaceEntry::TAGS:
0485             qCDebug(DIGIKAM_GENERAL_LOG) << "Setting up tags";
0486             d->ratingTipLabel->hide();
0487             d->commentTipLabel->hide();
0488             d->ratingMappings->hide();
0489 
0490             // disable IPTC and EXIF for tags
0491 
0492             d->subspaceCombo->setItemData(0, 0, Qt::UserRole -1);
0493             d->subspaceCombo->setItemData(1, 0, Qt::UserRole -1);
0494             break;
0495 
0496         case NamespaceEntry::TITLE:
0497             d->tagTipLabel->hide();
0498             d->ratingTipLabel->hide();
0499             d->isPath->hide();
0500             d->isTagLabel->hide();
0501             d->separatorLabel->hide();
0502             d->nameSpaceSeparator->hide();
0503             d->ratingMappings->hide();
0504             break;
0505 
0506         case NamespaceEntry::RATING:
0507             d->tagTipLabel->hide();
0508             d->commentTipLabel->hide();
0509             d->isPath->hide();
0510             d->isTagLabel->hide();
0511             d->separatorLabel->hide();
0512             d->nameSpaceSeparator->hide();
0513             break;
0514 
0515         case NamespaceEntry::COMMENT:
0516             d->tagTipLabel->hide();
0517             d->ratingTipLabel->hide();
0518             d->isPath->hide();
0519             d->isTagLabel->hide();
0520             d->separatorLabel->hide();
0521             d->nameSpaceSeparator->hide();
0522             d->ratingMappings->hide();
0523             break;
0524 
0525         case NamespaceEntry::COLORLABEL:
0526             d->tagTipLabel->hide();
0527             d->ratingTipLabel->hide();
0528             d->isPath->hide();
0529             d->isTagLabel->hide();
0530             d->separatorLabel->hide();
0531             d->nameSpaceSeparator->hide();
0532             d->ratingMappings->hide();
0533             break;
0534 
0535         default:
0536             break;
0537     }
0538 }
0539 
0540 void NamespaceEditDlg::makeReadOnly()
0541 {
0542     QString txt = i18n("This is a default namespace. Default namespaces can only be disabled");
0543     d->tipLabel2->setText(txt);
0544     d->tipLabel2->show();
0545 
0546     d->subspaceCombo->setDisabled(true);
0547     d->specialOptsCombo->setDisabled(true);
0548     d->altSpecialOptsCombo->setDisabled(true);
0549     d->namespaceName->setDisabled(true);
0550     d->alternativeName->setDisabled(true);
0551     d->nameSpaceSeparator->setDisabled(true);
0552     d->isPath->setDisabled(true);
0553     d->ratingMappings->setDisabled(true);
0554 
0555 
0556     d->zeroStars->setDisabled(true);
0557     d->oneStar->setDisabled(true);
0558     d->twoStars->setDisabled(true);
0559     d->threeStars->setDisabled(true);
0560     d->fourStars->setDisabled(true);
0561     d->fiveStars->setDisabled(true);
0562 }
0563 
0564 bool NamespaceEditDlg::validifyCheck(QString& errMsg)
0565 {
0566     // bool result = true; NOT USED
0567 
0568     if (d->namespaceName->text().isEmpty())
0569     {
0570         errMsg = i18n("The namespace name is required");
0571         return false;
0572     }
0573 
0574     switch (d->subspaceCombo->currentData().toInt())
0575     {
0576         case NamespaceEntry::EXIF:
0577 
0578             if (d->namespaceName->text().split(QLatin1Char('.')).first() != QLatin1String("Exif"))
0579             {
0580                 errMsg = i18n("EXIF namespace name must start with \"Exif\".");
0581                 return false;
0582             }
0583 
0584             if (!d->alternativeName->text().isEmpty() &&
0585                 (d->alternativeName->text().split(QLatin1Char('.')).first() != QLatin1String("Exif")))
0586             {
0587                 errMsg = i18n("EXIF alternative namespace name must start with \"Exif\".");
0588                 return false;
0589             }
0590 
0591             break;
0592 
0593         case NamespaceEntry::IPTC:
0594 
0595             if (d->namespaceName->text().split(QLatin1Char('.')).first() != QLatin1String("Iptc"))
0596             {
0597                 errMsg = i18n("IPTC namespace name must start with \"Iptc\".");
0598                 return false;
0599             }
0600 
0601             if (!d->alternativeName->text().isEmpty() &&
0602                 (d->alternativeName->text().split(QLatin1Char('.')).first() != QLatin1String("Iptc")))
0603             {
0604                 errMsg = i18n("IPTC alternative namespace name must start with \"Iptc\".");
0605                 return false;
0606             }
0607 
0608             break;
0609 
0610         case NamespaceEntry::XMP:
0611 
0612             if (d->namespaceName->text().split(QLatin1Char('.')).first() != QLatin1String("Xmp"))
0613             {
0614                 errMsg = i18n("XMP namespace name must start with \"Xmp\".");
0615                 return false;
0616             }
0617 
0618             if (!d->alternativeName->text().isEmpty() &&
0619                 (d->alternativeName->text().split(QLatin1Char('.')).first() != QLatin1String("Xmp")))
0620             {
0621                 errMsg = i18n("XMP alternative namespace name must start with \"Xmp\".");
0622                 return false;
0623             }
0624 
0625             break;
0626 
0627         default:
0628             break;
0629     }
0630 
0631     switch (d->nsType)
0632     {
0633         case NamespaceEntry::TAGS:
0634 
0635             if (d->nameSpaceSeparator->text().isEmpty())
0636             {
0637                 errMsg = i18n("Tag Path separator is required");
0638                 return false;
0639             }
0640 
0641             if (d->nameSpaceSeparator->text().size() > 1)
0642             {
0643                 errMsg = i18n("Only one character is now supported as tag path separator");
0644                 return false;
0645             }
0646 
0647             break;
0648 
0649        case NamespaceEntry::TITLE:
0650             break;
0651 
0652        case NamespaceEntry::RATING:
0653             break;
0654 
0655         case NamespaceEntry::COMMENT:
0656             break;
0657 
0658         case NamespaceEntry::COLORLABEL:
0659             break;
0660 
0661         default:
0662             break;
0663     }
0664 
0665     return true;
0666 }
0667 
0668 void NamespaceEditDlg::saveData(NamespaceEntry& entry)
0669 {
0670     entry.namespaceName = d->namespaceName->text();
0671     entry.separator     = d->nameSpaceSeparator->text();
0672 
0673     if (d->isPath->isChecked())
0674     {
0675         entry.tagPaths = NamespaceEntry::TAGPATH;
0676     }
0677     else
0678     {
0679         entry.tagPaths = NamespaceEntry::TAG;
0680     }
0681 
0682     entry.alternativeName = d->alternativeName->text();
0683     entry.specialOpts     = (NamespaceEntry::SpecialOptions)d->specialOptsCombo->currentData().toInt();
0684     entry.secondNameOpts  = (NamespaceEntry::SpecialOptions)d->altSpecialOptsCombo->currentData().toInt();
0685     entry.subspace        = (NamespaceEntry::NsSubspace)d->subspaceCombo->currentData().toInt();
0686 
0687     entry.convertRatio.clear();
0688     entry.convertRatio.append(d->zeroStars->value());
0689     entry.convertRatio.append(d->oneStar->value());
0690     entry.convertRatio.append(d->twoStars->value());
0691     entry.convertRatio.append(d->threeStars->value());
0692     entry.convertRatio.append(d->fourStars->value());
0693     entry.convertRatio.append(d->fiveStars->value());
0694 }
0695 
0696 void NamespaceEditDlg::accept()
0697 {
0698     QString errMsg;
0699 
0700     if (validifyCheck(errMsg))
0701     {
0702         QDialog::accept();
0703     }
0704     else
0705     {
0706         d->tipLabel2->setText(errMsg);
0707         d->tipLabel2->show();
0708     }
0709 }
0710 
0711 void NamespaceEditDlg::slotHelp()
0712 {
0713     openOnlineDocumentation(QLatin1String("setup_application"), QLatin1String("metadata_settings"), QLatin1String("metadata-advanced"));
0714 }
0715 
0716 } // namespace Digikam
0717 
0718 #include "moc_namespaceeditdlg.cpp"