dolphin: implement case-sensitivity option for filenamesearch slave

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-06-04 05:20:45 +03:00
parent 12b862ccf5
commit 2dca510dc2
5 changed files with 31 additions and 16 deletions

View file

@ -14,6 +14,10 @@
<label>Literal</label> <label>Literal</label>
<default>false</default> <default>false</default>
</entry> </entry>
<entry name="CaseSensitive" type="Bool">
<label>Case-sensitive</label>
<default>false</default>
</entry>
<entry name="What" type="String"> <entry name="What" type="String">
<label>What</label> <label>What</label>
<default>FileName</default> <default>FileName</default>

View file

@ -54,6 +54,7 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
m_fromHereButton(0), m_fromHereButton(0),
m_everywhereButton(0), m_everywhereButton(0),
m_literalBox(0), m_literalBox(0),
m_caseSensitiveBox(0),
m_facetsToggleButton(0), m_facetsToggleButton(0),
m_facetsWidget(0), m_facetsWidget(0),
m_searchPath(), m_searchPath(),
@ -119,6 +120,10 @@ KUrl DolphinSearchBox::urlForSearching() const
url.addQueryItem("literal", "yes"); url.addQueryItem("literal", "yes");
} }
if (m_caseSensitiveBox->isChecked()) {
url.addQueryItem("caseSensitive", "yes");
}
if (!m_facetsWidget->types().isEmpty()) { if (!m_facetsWidget->types().isEmpty()) {
url.addQueryItem("checkType", m_facetsWidget->types()); url.addQueryItem("checkType", m_facetsWidget->types());
} }
@ -144,6 +149,7 @@ void DolphinSearchBox::fromSearchUrl(const KUrl& url)
setSearchPath(url.queryItemValue("url")); setSearchPath(url.queryItemValue("url"));
m_contentButton->setChecked(url.queryItemValue("checkContent") == "yes"); m_contentButton->setChecked(url.queryItemValue("checkContent") == "yes");
m_literalBox->setChecked(url.queryItemValue("literal") == "yes"); m_literalBox->setChecked(url.queryItemValue("literal") == "yes");
m_caseSensitiveBox->setChecked(url.queryItemValue("caseSensitive") == "yes");
} else { } else {
setText(QString()); setText(QString());
setSearchPath(url); setSearchPath(url);
@ -290,6 +296,7 @@ void DolphinSearchBox::loadSettings()
} }
m_literalBox->setChecked(SearchSettings::literal()); m_literalBox->setChecked(SearchSettings::literal());
m_caseSensitiveBox->setChecked(SearchSettings::caseSensitive());
m_facetsWidget->setVisible(SearchSettings::showFacetsWidget()); m_facetsWidget->setVisible(SearchSettings::showFacetsWidget());
} }
@ -299,6 +306,7 @@ void DolphinSearchBox::saveSettings()
SearchSettings::setLocation(m_fromHereButton->isChecked() ? "FromHere" : "Everywhere"); SearchSettings::setLocation(m_fromHereButton->isChecked() ? "FromHere" : "Everywhere");
SearchSettings::setWhat(m_fileNameButton->isChecked() ? "FileName" : "Content"); SearchSettings::setWhat(m_fileNameButton->isChecked() ? "FileName" : "Content");
SearchSettings::setLiteral(m_literalBox->isChecked()); SearchSettings::setLiteral(m_literalBox->isChecked());
SearchSettings::setCaseSensitive(m_caseSensitiveBox->isChecked());
SearchSettings::setShowFacetsWidget(m_facetsToggleButton->isChecked()); SearchSettings::setShowFacetsWidget(m_facetsToggleButton->isChecked());
SearchSettings::self()->writeConfig(); SearchSettings::self()->writeConfig();
} }
@ -370,6 +378,12 @@ void DolphinSearchBox::init()
m_literalBox->setToolTip(i18nc("@info:tooltip", "Escape the regular expression sequence")); m_literalBox->setToolTip(i18nc("@info:tooltip", "Escape the regular expression sequence"));
connect(m_literalBox, SIGNAL(stateChanged(int)), this, SLOT(slotConfigurationChanged())); 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 // Create "Facets" widgets
m_facetsToggleButton = new QToolButton(this); m_facetsToggleButton = new QToolButton(this);
m_facetsToggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); m_facetsToggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
@ -391,6 +405,7 @@ void DolphinSearchBox::init()
optionsLayout->addWidget(m_everywhereButton); optionsLayout->addWidget(m_everywhereButton);
optionsLayout->addWidget(m_separator); optionsLayout->addWidget(m_separator);
optionsLayout->addWidget(m_literalBox); optionsLayout->addWidget(m_literalBox);
optionsLayout->addWidget(m_caseSensitiveBox);
optionsLayout->addStretch(1); optionsLayout->addStretch(1);
optionsLayout->addWidget(m_facetsToggleButton); optionsLayout->addWidget(m_facetsToggleButton);

View file

@ -161,6 +161,7 @@ private:
QToolButton* m_fromHereButton; QToolButton* m_fromHereButton;
QToolButton* m_everywhereButton; QToolButton* m_everywhereButton;
QCheckBox* m_literalBox; QCheckBox* m_literalBox;
QCheckBox* m_caseSensitiveBox;
QToolButton* m_facetsToggleButton; QToolButton* m_facetsToggleButton;
DolphinFacetsWidget* m_facetsWidget; DolphinFacetsWidget* m_facetsWidget;

View file

@ -34,9 +34,7 @@
FileNameSearchProtocol::FileNameSearchProtocol( const QByteArray &app ) : FileNameSearchProtocol::FileNameSearchProtocol( const QByteArray &app ) :
SlaveBase("search", app), SlaveBase("search", app),
m_checkContent(""), m_regExp(nullptr)
m_checkType(""),
m_regExp(0)
{ {
} }
@ -77,18 +75,18 @@ void FileNameSearchProtocol::listDir(const KUrl &url)
return; return;
} }
m_checkContent = url.queryItemValue("checkContent"); bool checkContent = (url.queryItemValue("checkContent") == QLatin1String("yes"));
m_literal = url.queryItemValue("literal"); bool literal = (url.queryItemValue("literal") == QLatin1String("yes"));
m_checkType = url.queryItemValue("checkType"); bool caseSensitive = (url.queryItemValue("caseSensitive") == QLatin1String("yes"));
QString checkType = url.queryItemValue("checkType");
QString search = url.queryItemValue("search"); QString search = url.queryItemValue("search");
if (!search.isEmpty() && m_literal == "yes") { if (!search.isEmpty() && literal) {
search = QRegExp::escape(search); search = QRegExp::escape(search);
} }
if (!search.isEmpty()) { 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 // Get all items of the directory
@ -109,16 +107,16 @@ void FileNameSearchProtocol::listDir(const KUrl &url)
bool addItem = false; bool addItem = false;
if (!m_regExp || item.name().contains(*m_regExp)) { if (!m_regExp || item.name().contains(*m_regExp)) {
addItem = true; addItem = true;
if (!m_checkType.isEmpty()) { if (!checkType.isEmpty()) {
addItem = false; addItem = false;
const KSharedPtr<KMimeType> mime = item.mimeTypePtr(); const KSharedPtr<KMimeType> mime = item.mimeTypePtr();
foreach (const QString &t, m_checkType.split(";")) { foreach (const QString &t, checkType.split(";")) {
if (mime->is(t)) { if (mime->is(t)) {
addItem = true; 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()); addItem = contentContainsPattern(item.url());
} }

View file

@ -54,9 +54,6 @@ private:
void cleanup(); void cleanup();
QString m_checkContent;
QString m_literal;
QString m_checkType;
QRegExp* m_regExp; QRegExp* m_regExp;
}; };