]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinquery.h
Expand DolphinQuery to support different Url schemes
[dolphin.git] / src / search / dolphinquery.h
1 /***************************************************************************
2 * Copyright (C) 2019 by Ismael Asensio <isma.af@mgmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef DOLPHINQUERY_H
21 #define DOLPHINQUERY_H
22
23 #include "dolphin_export.h"
24
25 #include <QString>
26 #include <QUrl>
27
28 /**
29 * @brief Simple query model that parses a Baloo search Url and extracts its
30 * separate components to be displayed on dolphin search box.
31 */
32 class DolphinQuery
33 {
34 public:
35 /** Parses the components of @p searchUrl for the supported schemes */
36 static DolphinQuery fromSearchUrl(const QUrl& searchUrl);
37 /** Checks whether the DolphinQuery supports the given @p urlScheme */
38 static bool supportsScheme(const QString& urlScheme);
39
40 /** @return the \a searchUrl passed to Baloo::Query::fromSearchUrl() */
41 QUrl searchUrl() const;
42 /** @return the user text part of the query, to be shown in the searchbar */
43 QString text() const;
44 /** @return the first of Baloo::Query::types(), or an empty string */
45 QString type() const;
46 /** @return a list of the search terms of the Baloo::Query that act as a filter,
47 * such as \"rating>= <i>value<i>\" or \"modified>= <i>date<i>\"*/
48 QStringList searchTerms() const;
49 /** @return Baloo::Query::includeFolder(), that is, the initial directory
50 * for the query or an empty string if its a global search" */
51 QString includeFolder() const;
52 /** @return whether the query includes search in file content */
53 bool hasContentSearch() const;
54 /** @return whether the query includes a filter by fileName */
55 bool hasFileName() const;
56
57 private:
58 /** Calls Baloo::Query::fromSearchUrl() on the current searchUrl
59 * and parses the result to extract its separate components */
60 void parseBalooQuery();
61
62 private:
63 QUrl m_searchUrl;
64 QString m_searchText;
65 QString m_fileType;
66 QStringList m_searchTerms;
67 QString m_includeFolder;
68 bool m_hasContentSearch = false;
69 bool m_hasFileName = false;
70 };
71
72 #endif //DOLPHINQUERY_H