diff options
| author | Ismael Asensio <[email protected]> | 2020-06-22 12:33:29 +0000 |
|---|---|---|
| committer | Ismael Asensio <[email protected]> | 2020-06-22 12:33:29 +0000 |
| commit | f57ee4b64d924fca85c6ce0be659cd6235f959a9 (patch) | |
| tree | ab1c4e3141c473811311b995fd93b8e50284ddbd /src/search | |
| parent | aea6128fe66171a411172089dcba85c90b89953f (diff) | |
Expand DolphinQuery to support different Url schemes
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/dolphinquery.cpp | 44 | ||||
| -rw-r--r-- | src/search/dolphinquery.h | 12 | ||||
| -rw-r--r-- | src/search/dolphinsearchbox.cpp | 4 |
3 files changed, 43 insertions, 17 deletions
diff --git a/src/search/dolphinquery.cpp b/src/search/dolphinquery.cpp index ab107f43f..0581a02ec 100644 --- a/src/search/dolphinquery.cpp +++ b/src/search/dolphinquery.cpp @@ -27,6 +27,7 @@ #endif namespace { +#ifdef HAVE_BALOO /** Checks if a given term in the Baloo::Query::searchString() is a special search term * @return: the specific search token of the term, or an empty QString() if none is found */ @@ -67,20 +68,40 @@ namespace { } return textParts; } +#endif } -DolphinQuery DolphinQuery::fromBalooSearchUrl(const QUrl& searchUrl) + +DolphinQuery DolphinQuery::fromSearchUrl(const QUrl& searchUrl) { DolphinQuery model; model.m_searchUrl = searchUrl; + if (searchUrl.scheme() == QLatin1String("baloosearch")) { + model.parseBalooQuery(); + } + + return model; +} + +bool DolphinQuery::supportsScheme(const QString& urlScheme) +{ + static const QStringList supportedSchemes = { + QStringLiteral("baloosearch"), + }; + + return supportedSchemes.contains(urlScheme); +} + +void DolphinQuery::parseBalooQuery() +{ #ifdef HAVE_BALOO - const Baloo::Query query = Baloo::Query::fromSearchUrl(searchUrl); + const Baloo::Query query = Baloo::Query::fromSearchUrl(m_searchUrl); - model.m_includeFolder = query.includeFolder(); + m_includeFolder = query.includeFolder(); const QStringList types = query.types(); - model.m_fileType = types.isEmpty() ? QString() : types.first(); + m_fileType = types.isEmpty() ? QString() : types.first(); QStringList textParts; QString fileName; @@ -93,34 +114,33 @@ DolphinQuery DolphinQuery::fromBalooSearchUrl(const QUrl& searchUrl) if (token == QLatin1String("filename:")) { if (!value.isEmpty()) { fileName = value; - model.m_hasFileName = true; + m_hasFileName = true; } continue; } else if (!token.isEmpty()) { - model.m_searchTerms << token + value; + m_searchTerms << token + value; continue; } else if (subTerm == QLatin1String("AND") && subTerm != subTerms.at(0) && subTerm != subTerms.back()) { continue; } else if (!value.isEmpty()) { textParts << value; - model.m_hasContentSearch = true; + m_hasContentSearch = true; } } - if (model.m_hasFileName) { - if (model.m_hasContentSearch) { + if (m_hasFileName) { + if (m_hasContentSearch) { textParts << QStringLiteral("filename:\"%1\"").arg(fileName); } else { textParts << fileName; } } - model.m_searchText = textParts.join(QLatin1Char(' ')); - + m_searchText = textParts.join(QLatin1Char(' ')); #endif - return model; } + QUrl DolphinQuery::searchUrl() const { return m_searchUrl; diff --git a/src/search/dolphinquery.h b/src/search/dolphinquery.h index 544f246bc..5032621a9 100644 --- a/src/search/dolphinquery.h +++ b/src/search/dolphinquery.h @@ -32,9 +32,10 @@ class DolphinQuery { public: - /** Calls Baloo::Query::fromSearchUrl() with the given @p searchUrl - * and parses the result to extract its separate components */ - static DolphinQuery fromBalooSearchUrl(const QUrl& searchUrl); + /** Parses the components of @p searchUrl for the supported schemes */ + static DolphinQuery fromSearchUrl(const QUrl& searchUrl); + /** Checks whether the DolphinQuery supports the given @p urlScheme */ + static bool supportsScheme(const QString& urlScheme); /** @return the \a searchUrl passed to Baloo::Query::fromSearchUrl() */ QUrl searchUrl() const; @@ -54,6 +55,11 @@ public: bool hasFileName() const; private: + /** Calls Baloo::Query::fromSearchUrl() on the current searchUrl + * and parses the result to extract its separate components */ + void parseBalooQuery(); + +private: QUrl m_searchUrl; QString m_searchText; QString m_fileType; diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index f0d8c5416..239280280 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -146,8 +146,8 @@ QUrl DolphinSearchBox::urlForSearching() const void DolphinSearchBox::fromSearchUrl(const QUrl& url) { - if (url.scheme() == QLatin1String("baloosearch")) { - const DolphinQuery query = DolphinQuery::fromBalooSearchUrl(url); + if (DolphinQuery::supportsScheme(url.scheme())) { + const DolphinQuery query = DolphinQuery::fromSearchUrl(url); updateFromQuery(query); } else if (url.scheme() == QLatin1String("filenamesearch")) { const QUrlQuery query(url); |
