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 const QStringList types
= query
.types();
58 model
.m_fileType
= types
.isEmpty() ? QString() : types
.first();
60 QStringList textParts
;
62 const QStringList subTerms
= query
.searchString().split(' ', QString::SkipEmptyParts
);
63 foreach (const QString
& subTerm
, subTerms
) {
65 if (subTerm
.startsWith(QLatin1String("filename:"))) {
66 value
= subTerm
.mid(9);
67 } else if (isSearchTerm(subTerm
)) {
68 model
.m_searchTerms
<< subTerm
;
70 } else if (subTerm
== QLatin1String("AND") && subTerm
!= subTerms
.at(0) && subTerm
!= subTerms
.back()) {
76 if (!value
.isEmpty() && value
.at(0) == QLatin1Char('"')) {
79 if (!value
.isEmpty() && value
.back() == QLatin1Char('"')) {
80 value
= value
.mid(0, value
.size() - 1);
82 if (!value
.isEmpty()) {
87 model
.m_searchText
= textParts
.join(QLatin1Char(' '));
93 QUrl
DolphinQuery::searchUrl() const
98 QString
DolphinQuery::text() const
103 QString
DolphinQuery::type() const
108 QStringList
DolphinQuery::searchTerms() const
110 return m_searchTerms
;
113 QString
DolphinQuery::includeFolder() const
115 return m_includeFolder
;