diff --git a/core/libs/tags/manager/tagpropwidget.cpp b/core/libs/tags/manager/tagpropwidget.cpp index 0decb96cec..87bc7ebbf9 100644 --- a/core/libs/tags/manager/tagpropwidget.cpp +++ b/core/libs/tags/manager/tagpropwidget.cpp @@ -1,453 +1,455 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2013-07-03 * Description : Tag Properties widget to display tag properties * when a tag or multiple tags are selected * * Copyright (C) 2013 by Veaceslav Munteanu * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "tagpropwidget.h" // Qt includes #include #include #include #include #include #include +#include #include // KDE includes #include #ifdef HAVE_KICONTHEMES # include #endif // Local includes #include "digikam_debug.h" #include "searchtextbar.h" #include "album.h" #include "albummanager.h" #include "tagsactionmngr.h" #include "syncjob.h" #include "dexpanderbox.h" #include "dlayoutbox.h" namespace Digikam { class Q_DECL_HIDDEN TagPropWidget::Private { public: explicit Private() { titleEdit = 0; iconButton = 0; resetIconButton = 0; saveButton = 0; discardButton = 0; topLabel = 0; keySeqWidget = 0; changed = false; } QLabel* topLabel; QString icon; QPushButton* iconButton; QPushButton* resetIconButton; QPushButton* saveButton; QPushButton* discardButton; QList selectedAlbums; KKeySequenceWidget* keySeqWidget; SearchTextBar* titleEdit; bool changed; }; TagPropWidget::TagPropWidget(QWidget* const parent) : QWidget(parent), d(new Private()) { const int spacing = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); const int cmargin = QApplication::style()->pixelMetric(QStyle::PM_DefaultChildMargin); QGridLayout* const grid = new QGridLayout(this); QLabel* const logo = new QLabel(this); logo->setPixmap(QIcon::fromTheme(QLatin1String("tag-properties")).pixmap(30,30)); d->topLabel = new QLabel(this); d->topLabel->setText(i18n("Tag Properties")); d->topLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); d->topLabel->setWordWrap(false); DLineWidget* const line = new DLineWidget(Qt::Horizontal, this); // -------------------------------------------------------- QLabel* const titleLabel = new QLabel(this); titleLabel->setText(i18n("&Title:")); titleLabel->setContentsMargins(cmargin, cmargin, cmargin, cmargin); titleLabel->setIndent(spacing); d->titleEdit = new SearchTextBar(this, QLatin1String("TagEditDlgTitleEdit"), i18n("Enter tag name here")); d->titleEdit->setCaseSensitive(false); titleLabel->setBuddy(d->titleEdit); QLabel* const tipLabel = new QLabel(this); tipLabel->setTextFormat(Qt::RichText); tipLabel->setWordWrap(true); tipLabel->setContentsMargins(cmargin, cmargin, cmargin, cmargin); tipLabel->setIndent(spacing); // ---------------------------------------------------------------------- QLabel* const iconTextLabel = new QLabel(this); iconTextLabel->setText(i18n("&Icon:")); iconTextLabel->setContentsMargins(cmargin, cmargin, cmargin, cmargin); iconTextLabel->setIndent(spacing); d->iconButton = new QPushButton(this); d->iconButton->setFixedSize(40, 40); iconTextLabel->setBuddy(d->iconButton); d->resetIconButton = new QPushButton(QIcon::fromTheme(QLatin1String("view-refresh")), i18n("Reset"), this); #ifndef HAVE_KICONTHEMES iconTextLabel->hide(); d->iconButton->hide(); d->resetIconButton->hide(); #endif // ---------------------------------------------------------------------- QLabel* const kscTextLabel = new QLabel(this); kscTextLabel->setText(i18n("&Shortcut:")); kscTextLabel->setContentsMargins(cmargin, cmargin, cmargin, cmargin); kscTextLabel->setIndent(spacing); d->keySeqWidget = new KKeySequenceWidget(this); kscTextLabel->setBuddy(d->keySeqWidget); d->keySeqWidget->setCheckActionCollections(TagsActionMngr::defaultManager()->actionCollections()); QLabel* const tipLabel2 = new QLabel(this); tipLabel2->setTextFormat(Qt::RichText); tipLabel2->setWordWrap(true); tipLabel2->setText(i18n("

Note: This shortcut can be used " "to assign or unassign tag to items.

")); tipLabel2->setContentsMargins(cmargin, cmargin, cmargin, cmargin); tipLabel2->setIndent(spacing); d->saveButton = new QPushButton(i18n("Save")); d->discardButton = new QPushButton(i18n("Discard")); // -------------------------------------------------------- grid->addWidget(logo, 0, 0, 1, 1); grid->addWidget(d->topLabel, 0, 1, 1, 4); grid->addWidget(line, 1, 0, 1, 4); grid->addWidget(tipLabel, 2, 0, 1, 4); grid->addWidget(titleLabel, 3, 0, 1, 1); grid->addWidget(d->titleEdit, 3, 1, 1, 3); grid->addWidget(iconTextLabel, 4, 0, 1, 1); grid->addWidget(d->iconButton, 4, 1, 1, 1); grid->addWidget(d->resetIconButton, 4, 2, 1, 1); grid->addWidget(kscTextLabel, 5, 0, 1, 1); grid->addWidget(d->keySeqWidget, 5, 1, 1, 3); grid->addWidget(tipLabel2, 6, 0, 1, 4); grid->addWidget(d->saveButton, 7, 0, 1, 1); grid->addWidget(d->discardButton, 7, 1, 1, 1); grid->setRowStretch(8, 10); grid->setColumnStretch(3, 10); grid->setContentsMargins(cmargin, cmargin, cmargin, cmargin); grid->setVerticalSpacing(spacing); adjustSize(); connect(d->iconButton, SIGNAL(clicked()), this, SLOT(slotIconChanged())); connect(d->titleEdit, SIGNAL(textEdited(QString)), this, SLOT(slotDataChanged())); connect(d->titleEdit, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed())); connect(d->resetIconButton, SIGNAL(clicked()), this, SLOT(slotIconResetClicked())); connect(d->keySeqWidget, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(slotDataChanged())); connect(d->saveButton, SIGNAL(clicked()), this, SLOT(slotSaveChanges())); connect(d->discardButton, SIGNAL(clicked()), this, SLOT(slotDiscardChanges())); enableItems(TagPropWidget::DisabledAll); } TagPropWidget::~TagPropWidget() { delete d; } void TagPropWidget::slotSelectionChanged(const QList& albums) { if (albums.isEmpty()) { enableItems(TagPropWidget::DisabledAll); return; } if (d->changed) { int rez = QMessageBox::question(this, qApp->applicationName(), i18n("Previous tags were changed. " "Save changes? ")); if (rez == QMessageBox::Yes) { slotSaveChanges(); } d->changed = false; } if (albums.size() == 1) { TAlbum* const album = dynamic_cast(albums.first()); if (!album) { return; } QString Seq = album->property(TagPropertyName::tagKeyboardShortcut()); d->selectedAlbums.clear(); d->selectedAlbums.append(album); d->titleEdit->setText(album->title()); d->icon = album->icon(); d->iconButton->setIcon(SyncJob::getTagThumbnail(album)); d->keySeqWidget->setKeySequence(Seq); if (album->isRoot()) enableItems(TagPropWidget::DisabledAll); else enableItems(TagPropWidget::EnabledAll); } else { d->selectedAlbums.clear(); bool containsRoot = false; QList::const_iterator it; for (it = albums.constBegin() ; it != albums.constEnd() ; ++it) { TAlbum* const temp = dynamic_cast(*it); if (temp) { d->selectedAlbums.append(temp); if (temp->isRoot()) containsRoot = true; } } d->titleEdit->clear(); d->icon.clear(); d->iconButton->setIcon(QIcon()); d->keySeqWidget->clearKeySequence(); if (containsRoot) enableItems(TagPropWidget::DisabledAll); else enableItems(TagPropWidget::IconOnly); } d->changed = false; } void TagPropWidget::slotFocusTitleEdit() { d->titleEdit->selectAll(); d->titleEdit->setFocus(); } void TagPropWidget::slotIconResetClicked() { if (d->icon.isEmpty() || d->icon == QLatin1String("tag")) { return; } d->changed = true; d->icon = QLatin1String("tag"); d->iconButton->setIcon(QIcon::fromTheme(d->icon)); } void TagPropWidget::slotIconChanged() { #ifdef HAVE_KICONTHEMES - d->changed = true; - KIconDialog dlg(this); - dlg.setup(KIconLoader::NoGroup, KIconLoader::Application, false, 20, false, false, false); - QString icon = dlg.openDialog(); + QPointer dlg = new KIconDialog(this); + dlg->setup(KIconLoader::NoGroup, KIconLoader::Application, false, 20, false, false, false); + QString icon = dlg->openDialog(); + delete dlg; if (icon.isEmpty() || icon == d->icon) { return; } - d->icon = icon; + d->icon = icon; + d->changed = true; d->iconButton->setIcon(QIcon::fromTheme(d->icon)); #endif } void TagPropWidget::slotDataChanged() { d->changed = true; } void TagPropWidget::slotSaveChanges() { if (d->selectedAlbums.size() == 1) { QString title = d->titleEdit->text(); TAlbum* const tag = d->selectedAlbums.first(); QString icon = d->icon; QKeySequence ks = d->keySeqWidget->keySequence(); if (tag && tag->title() != title) { QString errMsg; if (!AlbumManager::instance()->renameTAlbum(tag, title, errMsg)) { QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(), errMsg); } } if (tag && tag->icon() != icon) { QString errMsg; if (!AlbumManager::instance()->updateTAlbumIcon(tag, icon, 0, errMsg)) { QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(), errMsg); } } if (tag && tag->property(TagPropertyName::tagKeyboardShortcut()) != ks.toString()) { TagsActionMngr::defaultManager()->updateTagShortcut(tag->id(), ks); } } else { QList::iterator it; for (it = d->selectedAlbums.begin() ; it != d->selectedAlbums.end() ; ++it) { TAlbum* const tag = *it; if (tag && tag->icon() != d->icon) { QString errMsg; if (!AlbumManager::instance()->updateTAlbumIcon(tag, d->icon, 0, errMsg)) { QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(), errMsg); } } } } d->changed = false; } void TagPropWidget::slotDiscardChanges() { if (d->selectedAlbums.size() == 1) { TAlbum* const album = d->selectedAlbums.first(); QString Seq = album->property(TagPropertyName::tagKeyboardShortcut()); d->titleEdit->setText(album->title()); d->icon = album->icon(); d->iconButton->setIcon(SyncJob::getTagThumbnail(album)); d->keySeqWidget->setKeySequence(Seq); } else { d->icon.clear(); } d->changed = false; } void TagPropWidget::slotReturnPressed() { slotSaveChanges(); emit signalTitleEditReady(); } void TagPropWidget::enableItems(TagPropWidget::ItemsEnable value) { bool val = false; bool iconEnable = false; if (value == TagPropWidget::DisabledAll) { val = false; iconEnable = false; } if (value == TagPropWidget::EnabledAll) { val = true; iconEnable = true; } if (value == TagPropWidget::IconOnly) { val = false; iconEnable = true; } d->titleEdit->setEnabled(val); d->keySeqWidget->setEnabled(val); d->resetIconButton->setEnabled(iconEnable); d->iconButton->setEnabled(iconEnable); d->saveButton->setEnabled(iconEnable); d->discardButton->setEnabled(iconEnable); } } // namespace Digikam diff --git a/core/libs/tags/widgets/tageditdlg.cpp b/core/libs/tags/widgets/tageditdlg.cpp index 48975103e0..dc56f7b478 100644 --- a/core/libs/tags/widgets/tageditdlg.cpp +++ b/core/libs/tags/widgets/tageditdlg.cpp @@ -1,561 +1,562 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2004-07-01 * Description : dialog to edit and create digiKam Tags * * Copyright (C) 2004-2005 by Renchi Raju * Copyright (C) 2006-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "tageditdlg.h" // Qt includes #include #include #include #include #include #include #include #include #include #include // KDE includes #include #include #ifdef HAVE_KICONTHEMES # include #endif // Local includes #include "album.h" #include "syncjob.h" #include "searchtextbar.h" #include "tagsactionmngr.h" #include "coredbconstants.h" #include "digikam_debug.h" #include "dxmlguiwindow.h" #include "dexpanderbox.h" #include "dlayoutbox.h" namespace Digikam { class Q_DECL_HIDDEN TagsListCreationErrorDialog : public QDialog { public: TagsListCreationErrorDialog(QWidget* const parent, const QMap& errMap); ~TagsListCreationErrorDialog() {}; }; // ------------------------------------------------------------------------------ class Q_DECL_HIDDEN TagEditDlg::Private { public: explicit Private() { titleEdit = 0; iconButton = 0; resetIconButton = 0; buttons = 0; mainRootAlbum = 0; topLabel = 0; keySeqWidget = 0; create = false; } bool create; QLabel* topLabel; QString icon; QPushButton* iconButton; QPushButton* resetIconButton; QDialogButtonBox* buttons; KKeySequenceWidget* keySeqWidget; TAlbum* mainRootAlbum; SearchTextBar* titleEdit; }; TagEditDlg::TagEditDlg(QWidget* const parent, TAlbum* const album, bool create) : QDialog(parent), d(new Private) { setModal(true); d->buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); d->buttons->button(QDialogButtonBox::Ok)->setDefault(true); if (create) { setWindowTitle(i18n("New Tag")); } else { setWindowTitle(i18n("Edit Tag")); } d->mainRootAlbum = album; d->create = create; QWidget* const page = new QWidget(this); // -------------------------------------------------------- QGridLayout* const grid = new QGridLayout(page); QLabel* const logo = new QLabel(page); logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(48,48))); d->topLabel = new QLabel(page); d->topLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); d->topLabel->setWordWrap(false); DLineWidget* const line = new DLineWidget(Qt::Horizontal, page); // -------------------------------------------------------- QLabel* const titleLabel = new QLabel(page); titleLabel->setText(i18n("&Title:")); d->titleEdit = new SearchTextBar(page, QLatin1String("TagEditDlgTitleEdit"), i18n("Enter tag name here...")); d->titleEdit->setCaseSensitive(false); titleLabel->setBuddy(d->titleEdit); QLabel* const tipLabel = new QLabel(page); tipLabel->setTextFormat(Qt::RichText); tipLabel->setWordWrap(true); tipLabel->setText(i18n("

To create new tags, you can use the following rules:

" "

  • '/' can be used to create a tags hierarchy.
    " "Ex.: \"Country/City/Paris\"
  • " "
  • ',' can be used to create more than one tags hierarchy at the same time.
    " "Ex.: \"City/Paris, Monument/Notre-Dame\"
  • " "
  • If a tag hierarchy starts with '/', root tag album is used as parent.

" )); if (d->create) { AlbumList tList = AlbumManager::instance()->allTAlbums(); for (AlbumList::const_iterator it = tList.constBegin(); it != tList.constEnd(); ++it) { TAlbum* const tag = static_cast(*it); if (tag && !tag->isInternalTag()) { d->titleEdit->completerModel()->addItem(tag->tagPath()); } } } else { d->titleEdit->setText(d->mainRootAlbum->title()); tipLabel->hide(); } // -------------------------------------------------------- QLabel* const iconTextLabel = new QLabel(page); iconTextLabel->setText(i18n("&Icon:")); d->iconButton = new QPushButton(page); d->iconButton->setFixedSize(40, 40); d->iconButton->setIcon(SyncJob::getTagThumbnail(album)); iconTextLabel->setBuddy(d->iconButton); // In create mode, by default assign the icon of the parent (if not root) to this new tag. d->icon = album->icon(); d->resetIconButton = new QPushButton(QIcon::fromTheme(QLatin1String("view-refresh")), i18n("Reset"), page); if (create) { d->resetIconButton->hide(); } #ifndef HAVE_KICONTHEMES iconTextLabel->hide(); d->iconButton->hide(); d->resetIconButton->hide(); #endif // -------------------------------------------------------- QLabel* const kscTextLabel = new QLabel(page); kscTextLabel->setText(i18n("&Shortcut:")); d->keySeqWidget = new KKeySequenceWidget(page); kscTextLabel->setBuddy(d->keySeqWidget); if (!create) { QString Seq = album->property(TagPropertyName::tagKeyboardShortcut()); d->keySeqWidget->setKeySequence(Seq); } else { // Do not inherit tag shortcut, it creates a conflict shortcut, see bug 309558. d->keySeqWidget->setCheckActionCollections(TagsActionMngr::defaultManager()->actionCollections()); } QLabel* const tipLabel2 = new QLabel(page); tipLabel2->setTextFormat(Qt::RichText); tipLabel2->setWordWrap(true); tipLabel2->setText(i18n("

Note: this shortcut can be used to assign or unassign tag to items.

")); // -------------------------------------------------------- const int spacing = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); const int cmargin = QApplication::style()->pixelMetric(QStyle::PM_DefaultChildMargin); grid->addWidget(logo, 0, 0, 1, 1); grid->addWidget(d->topLabel, 0, 1, 1, 4); grid->addWidget(line, 1, 0, 1, 4); grid->addWidget(tipLabel, 2, 0, 1, 4); grid->addWidget(titleLabel, 3, 0, 1, 1); grid->addWidget(d->titleEdit, 3, 1, 1, 3); grid->addWidget(iconTextLabel, 4, 0, 1, 1); grid->addWidget(d->iconButton, 4, 1, 1, 1); grid->addWidget(d->resetIconButton, 4, 2, 1, 1); grid->addWidget(kscTextLabel, 5, 0, 1, 1); grid->addWidget(d->keySeqWidget, 5, 1, 1, 3); grid->addWidget(tipLabel2, 6, 0, 1, 4); grid->setRowStretch(7, 10); grid->setColumnStretch(3, 10); grid->setContentsMargins(cmargin, cmargin, cmargin, cmargin); grid->setSpacing(spacing); QVBoxLayout* const vbx = new QVBoxLayout(this); vbx->addWidget(page); vbx->addWidget(d->buttons); setLayout(vbx); // -------------------------------------------------------- connect(d->iconButton, SIGNAL(clicked()), this, SLOT(slotIconChanged())); connect(d->resetIconButton, SIGNAL(clicked()), this, SLOT(slotIconResetClicked())); connect(d->titleEdit, SIGNAL(textChanged(QString)), this, SLOT(slotTitleChanged(QString))); connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); connect(d->buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), this, SLOT(slotHelp())); // -------------------------------------------------------- slotTitleChanged(d->titleEdit->text()); d->titleEdit->setFocus(); adjustSize(); } TagEditDlg::~TagEditDlg() { delete d; } QString TagEditDlg::title() const { return d->titleEdit->text(); } QString TagEditDlg::icon() const { return d->icon; } QKeySequence TagEditDlg::shortcut() const { return d->keySeqWidget->keySequence(); } void TagEditDlg::slotIconResetClicked() { d->icon = QLatin1String("tag"); d->iconButton->setIcon(QIcon::fromTheme(d->icon)); } void TagEditDlg::slotIconChanged() { #ifdef HAVE_KICONTHEMES - KIconDialog dlg(this); - dlg.setup(KIconLoader::NoGroup, KIconLoader::Application, false, 20, false, false, false); - QString icon = dlg.openDialog(); + QPointer dlg = new KIconDialog(this); + dlg->setup(KIconLoader::NoGroup, KIconLoader::Application, false, 20, false, false, false); + QString icon = dlg->openDialog(); + delete dlg; if (icon.isEmpty() || icon == d->icon) { return; } d->icon = icon; d->iconButton->setIcon(QIcon::fromTheme(d->icon)); #endif } void TagEditDlg::slotTitleChanged(const QString& newtitle) { QString tagName = d->mainRootAlbum->tagPath(); if (tagName.endsWith(QLatin1Char('/')) && !d->mainRootAlbum->isRoot()) { tagName.truncate(tagName.length()-1); } if (d->create) { if (d->titleEdit->text().startsWith(QLatin1Char('/'))) { d->topLabel->setText(i18n("Create New Tag")); } else { d->topLabel->setText(i18n("Create New Tag in
" "\"%1\"
", tagName)); } } else { d->topLabel->setText(i18n("Properties of Tag
" "\"%1\"
", tagName)); } QRegExp emptyTitle = QRegExp(QLatin1String("^\\s*$")); bool enable = (!emptyTitle.exactMatch(newtitle) && !newtitle.isEmpty()); d->buttons->button(QDialogButtonBox::Ok)->setEnabled(enable); } bool TagEditDlg::tagEdit(QWidget* const parent, TAlbum* const album, QString& title, QString& icon, QKeySequence& ks) { QPointer dlg = new TagEditDlg(parent, album); bool valRet = dlg->exec(); if (valRet == QDialog::Accepted) { title = dlg->title(); icon = dlg->icon(); ks = dlg->shortcut(); } delete dlg; return valRet; } bool TagEditDlg::tagCreate(QWidget* const parent, TAlbum* const album, QString& title, QString& icon, QKeySequence& ks) { QPointer dlg = new TagEditDlg(parent, album, true); bool valRet = dlg->exec(); if (valRet == QDialog::Accepted) { title = dlg->title(); icon = dlg->icon(); ks = dlg->shortcut(); } delete dlg; return valRet; } AlbumList TagEditDlg::createTAlbum(TAlbum* const mainRootAlbum, const QString& tagStr, const QString& icon, const QKeySequence& ks, QMap& errMap) { errMap.clear(); AlbumList createdTagsList; TAlbum* root = 0; // Check if new tags are include in a list of tags hierarchy separated by ','. // Ex: /Country/France/people,/City/France/Paris const QStringList tagsHierarchies = tagStr.split(QLatin1Char(','), QString::SkipEmptyParts); if (tagsHierarchies.isEmpty()) { return createdTagsList; } for (QStringList::const_iterator it = tagsHierarchies.constBegin(); it != tagsHierarchies.constEnd(); ++it) { QString hierarchy = (*it).trimmed(); if (!hierarchy.isEmpty()) { // Check if new tags is a hierarchy of tags separated by '/'. root = 0; if (hierarchy.startsWith(QLatin1Char('/')) || !mainRootAlbum) { root = AlbumManager::instance()->findTAlbum(0); } else { root = mainRootAlbum; } QStringList tagsList = hierarchy.split(QLatin1Char('/'), QString::SkipEmptyParts); qCDebug(DIGIKAM_GENERAL_LOG) << tagsList; if (!tagsList.isEmpty()) { for (QStringList::const_iterator it2 = tagsList.constBegin(); it2 != tagsList.constEnd(); ++it2) { QString tagPath, errMsg; QString tag = (*it2).trimmed(); if (root->isRoot()) { tagPath = QString::fromUtf8("/%1").arg(tag); } else { tagPath = QString::fromUtf8("%1/%2").arg(root->tagPath()).arg(tag); } qCDebug(DIGIKAM_GENERAL_LOG) << tag << " :: " << tagPath; if (!tag.isEmpty()) { // Tag already exist ? TAlbum* const album = AlbumManager::instance()->findTAlbum(tagPath); if (!album) { root = AlbumManager::instance()->createTAlbum(root, tag, icon, errMsg); } else { root = album; if (*it2 == tagsList.last()) { errMap.insert(tagPath, i18n("Tag name already exists")); } } if (root) { createdTagsList.append(root); } } // Sanity check if tag creation failed. if (!root) { errMap.insert(tagPath, errMsg); break; } } } } } // Assign the keyboard shortcut to the last tag created from the hierarchy. if (root && !ks.isEmpty()) { TagsActionMngr::defaultManager()->updateTagShortcut(root->id(), ks); } return createdTagsList; } void TagEditDlg::showtagsListCreationError(QWidget* const parent, const QMap& errMap) { if (!errMap.isEmpty()) { QPointer dlg = new TagsListCreationErrorDialog(parent, errMap); dlg->exec(); delete dlg; } } void TagEditDlg::slotHelp() { DXmlGuiWindow::openHandbook(); } // ------------------------------------------------------------------------------ TagsListCreationErrorDialog::TagsListCreationErrorDialog(QWidget* const parent, const QMap& errMap) : QDialog(parent) { setModal(true); setWindowTitle(i18n("Tag creation Error")); const int spacing = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); const int cmargin = QApplication::style()->pixelMetric(QStyle::PM_DefaultChildMargin); QDialogButtonBox* const buttons = new QDialogButtonBox(QDialogButtonBox::Ok, this); buttons->button(QDialogButtonBox::Ok)->setDefault(true); QWidget* const page = new QWidget(this); QVBoxLayout* const vLay = new QVBoxLayout(page); QLabel* const label = new QLabel(i18n("An error occurred during tag creation:"), page); QTreeWidget* const listView = new QTreeWidget(page); listView->setHeaderLabels(QStringList() << i18n("Tag Path") << i18n("Error")); listView->setRootIsDecorated(false); listView->setSelectionMode(QAbstractItemView::SingleSelection); listView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); vLay->addWidget(label); vLay->addWidget(listView); vLay->setContentsMargins(cmargin, cmargin, cmargin, cmargin); vLay->setSpacing(spacing); for (QMap::const_iterator it = errMap.constBegin(); it != errMap.constEnd(); ++it) { new QTreeWidgetItem(listView, QStringList() << it.key() << it.value()); } QVBoxLayout* const vbx = new QVBoxLayout(this); vbx->addWidget(page); vbx->addWidget(buttons); setLayout(vbx); connect(buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); adjustSize(); } } // namespace Digikam