1 /***************************************************************************
2 * Copyright (C) 2019 by Ismael Asensio <isma.af@mgmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinquery.h"
22 #include <config-baloo.h>
24 #include <Baloo/Query>
28 /** Checks if a given term in the Baloo::Query::searchString() is a special search term.
29 * This is a copy of `DolphinFacetsWidget::isRatingTerm()` method.
31 bool isSearchTerm(const QString
& term
)
33 static const QLatin1String searchTokens
[] {
34 QLatin1String("modified>="),
35 QLatin1String("rating>=")
38 for (const auto &searchToken
: searchTokens
) {
39 if (term
.startsWith(searchToken
)) {
47 DolphinQuery
DolphinQuery::fromBalooSearchUrl(const QUrl
& searchUrl
)
50 model
.m_searchUrl
= searchUrl
;
53 const Baloo::Query query
= Baloo::Query::fromSearchUrl(searchUrl
);
55 model
.m_includeFolder
= query
.includeFolder();
57 model
.m_searchText
= query
.searchString();
59 const QStringList types
= query
.types();
60 model
.m_fileType
= types
.isEmpty() ? QString() : types
.first();
62 const QStringList subTerms
= query
.searchString().split(' ', QString::SkipEmptyParts
);
63 foreach (const QString
& subTerm
, subTerms
) {
64 if (subTerm
.startsWith(QLatin1String("filename:"))) {
65 const QString value
= subTerm
.mid(9);
66 model
.m_searchText
= value
;
67 } else if (isSearchTerm(subTerm
)) {
68 model
.m_searchTerms
<< subTerm
;
75 QUrl
DolphinQuery::searchUrl() const
80 QString
DolphinQuery::text() const
85 QString
DolphinQuery::type() const
90 QStringList
DolphinQuery::searchTerms() const
95 QString
DolphinQuery::includeFolder() const
97 return m_includeFolder
;