]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge branch 'release/21.04'
authorIsmael Asensio <isma.af@gmail.com>
Thu, 13 May 2021 13:09:42 +0000 (15:09 +0200)
committerIsmael Asensio <isma.af@gmail.com>
Thu, 13 May 2021 13:09:42 +0000 (15:09 +0200)
1  2 
src/search/dolphinfacetswidget.cpp

index d52d146a8d76aa7f3bb6b1d35e6a98c4ff1d1906,e8a43101fe2e4b171c7ac49c01acf3c6e84d7e5c..db53d595fa4ec707b83aa1aba4e02ae3f1f8c678
@@@ -8,6 -8,7 +8,7 @@@
  #include "dolphinfacetswidget.h"
  
  #include <KLocalizedString>
+ #include <KProtocolInfo>
  
  #include <QComboBox>
  #include <QDate>
@@@ -53,12 -54,6 +54,12 @@@ DolphinFacetsWidget::DolphinFacetsWidge
      m_ratingSelector->addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "Highest Rating"), 5);
      initComboBox(m_ratingSelector);
  
 +    m_clearTagsAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-clear-all")), i18nc("@action:inmenu", "Clear Selection"), this);
 +    connect(m_clearTagsAction, &QAction::triggered, this, [this]() {
 +        resetSearchTags();
 +        Q_EMIT facetChanged();
 +    });
 +
      m_tagsSelector = new QToolButton(this);
      m_tagsSelector->setIcon(QIcon::fromTheme(QStringLiteral("tag")));
      m_tagsSelector->setMenu(new QMenu(this));
@@@ -103,7 -98,9 +104,7 @@@ void DolphinFacetsWidget::resetSearchTe
      m_dateSelector->setCurrentIndex(0);
      m_ratingSelector->setCurrentIndex(0);
  
 -    m_searchTags = QStringList();
 -    updateTagsSelector();
 -    updateTagsMenu();
 +    resetSearchTags();
  }
  
  QStringList DolphinFacetsWidget::searchTerms() const
@@@ -222,13 -219,6 +223,13 @@@ void DolphinFacetsWidget::removeSearchT
      updateTagsSelector();
  }
  
 +void DolphinFacetsWidget::resetSearchTags()
 +{
 +    m_searchTags = QStringList();
 +    updateTagsSelector();
 +    updateTagsMenu();
 +}
 +
  void DolphinFacetsWidget::initComboBox(QComboBox* combo)
  {
      combo->setFrame(false);
@@@ -251,19 -241,19 +252,21 @@@ void DolphinFacetsWidget::updateTagsSel
      }
  
      m_tagsSelector->setEnabled(isEnabled() && (hasListedTags || hasSelectedTags));
 +    m_clearTagsAction->setEnabled(hasSelectedTags);
  }
  
  void DolphinFacetsWidget::updateTagsMenu()
  {
      updateTagsMenuItems({}, {});
-     m_tagsLister.openUrl(QUrl(QStringLiteral("tags:/")), KCoreDirLister::OpenUrlFlag::Reload);
+     if (KProtocolInfo::isKnownProtocol(QStringLiteral("tags"))) {
+         m_tagsLister.openUrl(QUrl(QStringLiteral("tags:/")), KCoreDirLister::OpenUrlFlag::Reload);
+     }
  }
  
  void DolphinFacetsWidget::updateTagsMenuItems(const QUrl&, const KFileItemList& items)
  {
 -    m_tagsSelector->menu()->clear();
 +    QMenu *tagsMenu = m_tagsSelector->menu();
 +    tagsMenu->clear();
  
      QStringList allTags = QStringList(m_searchTags);
      for (const KFileItem &item: items) {
      const bool onlyOneTag = allTags.count() == 1;
  
      for (const QString& tagName : qAsConst(allTags)) {
 -        QAction* action = m_tagsSelector->menu()->addAction(QIcon::fromTheme(QStringLiteral("tag")), tagName);
 +        QAction *action = tagsMenu->addAction(QIcon::fromTheme(QStringLiteral("tag")), tagName);
          action->setCheckable(true);
          action->setChecked(m_searchTags.contains(tagName));
  
          });
      }
  
 +    if (allTags.count() > 1) {
 +        tagsMenu->addSeparator();
 +        tagsMenu->addAction(m_clearTagsAction);
 +    }
 +
      updateTagsSelector();
  }