From 2dca510dc2d5dd8de27c85c8d65ccecadb7103ac Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 4 Jun 2024 05:20:45 +0300 Subject: [PATCH] dolphin: implement case-sensitivity option for filenamesearch slave Signed-off-by: Ivailo Monev --- .../src/search/dolphin_searchsettings.kcfg | 4 ++++ dolphin/src/search/dolphinsearchbox.cpp | 17 +++++++++++++- dolphin/src/search/dolphinsearchbox.h | 1 + dolphin/src/search/filenamesearchprotocol.cpp | 22 +++++++++---------- dolphin/src/search/filenamesearchprotocol.h | 3 --- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/dolphin/src/search/dolphin_searchsettings.kcfg b/dolphin/src/search/dolphin_searchsettings.kcfg index f8b3bb75..7ee212b6 100644 --- a/dolphin/src/search/dolphin_searchsettings.kcfg +++ b/dolphin/src/search/dolphin_searchsettings.kcfg @@ -14,6 +14,10 @@ false + + + false + FileName diff --git a/dolphin/src/search/dolphinsearchbox.cpp b/dolphin/src/search/dolphinsearchbox.cpp index 0ffc1611..de87de91 100644 --- a/dolphin/src/search/dolphinsearchbox.cpp +++ b/dolphin/src/search/dolphinsearchbox.cpp @@ -54,6 +54,7 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) : m_fromHereButton(0), m_everywhereButton(0), m_literalBox(0), + m_caseSensitiveBox(0), m_facetsToggleButton(0), m_facetsWidget(0), m_searchPath(), @@ -115,10 +116,14 @@ KUrl DolphinSearchBox::urlForSearching() const url.addQueryItem("checkContent", "yes"); } - if(m_literalBox->isChecked()) { + if (m_literalBox->isChecked()) { url.addQueryItem("literal", "yes"); } + if (m_caseSensitiveBox->isChecked()) { + url.addQueryItem("caseSensitive", "yes"); + } + if (!m_facetsWidget->types().isEmpty()) { url.addQueryItem("checkType", m_facetsWidget->types()); } @@ -144,6 +149,7 @@ void DolphinSearchBox::fromSearchUrl(const KUrl& url) setSearchPath(url.queryItemValue("url")); m_contentButton->setChecked(url.queryItemValue("checkContent") == "yes"); m_literalBox->setChecked(url.queryItemValue("literal") == "yes"); + m_caseSensitiveBox->setChecked(url.queryItemValue("caseSensitive") == "yes"); } else { setText(QString()); setSearchPath(url); @@ -290,6 +296,7 @@ void DolphinSearchBox::loadSettings() } m_literalBox->setChecked(SearchSettings::literal()); + m_caseSensitiveBox->setChecked(SearchSettings::caseSensitive()); m_facetsWidget->setVisible(SearchSettings::showFacetsWidget()); } @@ -299,6 +306,7 @@ void DolphinSearchBox::saveSettings() SearchSettings::setLocation(m_fromHereButton->isChecked() ? "FromHere" : "Everywhere"); SearchSettings::setWhat(m_fileNameButton->isChecked() ? "FileName" : "Content"); SearchSettings::setLiteral(m_literalBox->isChecked()); + SearchSettings::setCaseSensitive(m_caseSensitiveBox->isChecked()); SearchSettings::setShowFacetsWidget(m_facetsToggleButton->isChecked()); SearchSettings::self()->writeConfig(); } @@ -370,6 +378,12 @@ void DolphinSearchBox::init() m_literalBox->setToolTip(i18nc("@info:tooltip", "Escape the regular expression sequence")); connect(m_literalBox, SIGNAL(stateChanged(int)), this, SLOT(slotConfigurationChanged())); + // Create "Case Sensitive" widget + m_caseSensitiveBox = new QCheckBox(this); + m_caseSensitiveBox->setText(i18nc("action:button", "Case-sensitive")); + m_caseSensitiveBox->setToolTip(i18nc("@info:tooltip", "Do not ignore the case of the pattern")); + connect(m_caseSensitiveBox, SIGNAL(stateChanged(int)), this, SLOT(slotConfigurationChanged())); + // Create "Facets" widgets m_facetsToggleButton = new QToolButton(this); m_facetsToggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); @@ -391,6 +405,7 @@ void DolphinSearchBox::init() optionsLayout->addWidget(m_everywhereButton); optionsLayout->addWidget(m_separator); optionsLayout->addWidget(m_literalBox); + optionsLayout->addWidget(m_caseSensitiveBox); optionsLayout->addStretch(1); optionsLayout->addWidget(m_facetsToggleButton); diff --git a/dolphin/src/search/dolphinsearchbox.h b/dolphin/src/search/dolphinsearchbox.h index cb40d974..472ba7ba 100644 --- a/dolphin/src/search/dolphinsearchbox.h +++ b/dolphin/src/search/dolphinsearchbox.h @@ -161,6 +161,7 @@ private: QToolButton* m_fromHereButton; QToolButton* m_everywhereButton; QCheckBox* m_literalBox; + QCheckBox* m_caseSensitiveBox; QToolButton* m_facetsToggleButton; DolphinFacetsWidget* m_facetsWidget; diff --git a/dolphin/src/search/filenamesearchprotocol.cpp b/dolphin/src/search/filenamesearchprotocol.cpp index 8eb92e3a..2116ef08 100644 --- a/dolphin/src/search/filenamesearchprotocol.cpp +++ b/dolphin/src/search/filenamesearchprotocol.cpp @@ -34,9 +34,7 @@ FileNameSearchProtocol::FileNameSearchProtocol( const QByteArray &app ) : SlaveBase("search", app), - m_checkContent(""), - m_checkType(""), - m_regExp(0) + m_regExp(nullptr) { } @@ -77,18 +75,18 @@ void FileNameSearchProtocol::listDir(const KUrl &url) return; } - m_checkContent = url.queryItemValue("checkContent"); - m_literal = url.queryItemValue("literal"); - m_checkType = url.queryItemValue("checkType"); - + bool checkContent = (url.queryItemValue("checkContent") == QLatin1String("yes")); + bool literal = (url.queryItemValue("literal") == QLatin1String("yes")); + bool caseSensitive = (url.queryItemValue("caseSensitive") == QLatin1String("yes")); + QString checkType = url.queryItemValue("checkType"); QString search = url.queryItemValue("search"); - if (!search.isEmpty() && m_literal == "yes") { + if (!search.isEmpty() && literal) { search = QRegExp::escape(search); } if (!search.isEmpty()) { - m_regExp = new QRegExp(search, Qt::CaseInsensitive); + m_regExp = new QRegExp(search, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); } // Get all items of the directory @@ -109,16 +107,16 @@ void FileNameSearchProtocol::listDir(const KUrl &url) bool addItem = false; if (!m_regExp || item.name().contains(*m_regExp)) { addItem = true; - if (!m_checkType.isEmpty()) { + if (!checkType.isEmpty()) { addItem = false; const KSharedPtr mime = item.mimeTypePtr(); - foreach (const QString &t, m_checkType.split(";")) { + foreach (const QString &t, checkType.split(";")) { if (mime->is(t)) { addItem = true; } } } - } else if (!m_checkContent.isEmpty() && item.mimeTypePtr()->is(QLatin1String("text/plain"))) { + } else if (checkContent && item.mimeTypePtr()->is(QLatin1String("text/plain"))) { addItem = contentContainsPattern(item.url()); } diff --git a/dolphin/src/search/filenamesearchprotocol.h b/dolphin/src/search/filenamesearchprotocol.h index 4361b178..45d0b8a8 100644 --- a/dolphin/src/search/filenamesearchprotocol.h +++ b/dolphin/src/search/filenamesearchprotocol.h @@ -54,9 +54,6 @@ private: void cleanup(); - QString m_checkContent; - QString m_literal; - QString m_checkType; QRegExp* m_regExp; };