- /** 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;
- /** @return the user text part of the query, to be shown in the searchbar */
- QString text() const;
- /** @return the first of Baloo::Query::types(), or an empty string */
- QString type() const;
- /** @return a list of the search terms of the Baloo::Query that act as a filter,
- * such as \"rating>= <i>value<i>\" or \"modified>= <i>date<i>\"*/
- QStringList searchTerms() const;
- /** @return Baloo::Query::includeFolder(), that is, the initial directory
- * for the query or an empty string if its a global search" */
- QString includeFolder() const;
- /** @return whether the query includes search in file content */
- bool hasContentSearch() const;
- /** @return whether the query includes a filter by fileName */
- bool hasFileName() const;
+ /**
+ * @brief Automagically constructs a DolphinQuery based on the given @p url.
+ * @param url In the most usual case @p url is considered the search path and the DolphinQuery object is initialized based on saved user preferences.
+ * However, if the @p url has query information encoded in itself, which is supposed to be the case if the QUrl::scheme() of the @p url is
+ * "baloosearch", "tags", or "filenamesearch", this constructor retrieves all the information from the @p url and initializes the DolphinQuery
+ * with it.
+ * @param backupSearchPath The last non-search location the user was on.
+ * A DolphinQuery object should always be fully constructible from the main @p url parameter. However, the data encoded in @url
+ * might not contain any search path, for example because the constructed DolphinQuery object is supposed to search "everywhere".
+ * This is fine until this DolphinQuery object is switched to search in a specific location instead. In that case, this
+ * @p backupSearchPath will become the new searchPath() of this DolphinQuery.
+ */
+ explicit DolphinQuery(const QUrl &url, const QUrl &backupSearchPath);
+
+ /**
+ * @returns a representation of this DolphinQuery as a QUrl. This QUrl can be opened in Dolphin to trigger a search that is identical to the conditions
+ * provided by this DolphinQuery object.
+ */
+ QUrl toUrl() const;
+
+ void setSearchLocations(SearchLocations searchLocations);
+ inline SearchLocations searchLocations() const
+ {
+ return m_searchLocations;
+ };
+
+ /**
+ * Set this query to search in @p searchPath. However, if @a searchLocations() is set to "Everywhere", @p searchPath is effectively ignored because it is
+ * assumed that searching everywhere also includes @p searchPath.
+ */
+ void setSearchPath(const QUrl &searchPath);
+ /**
+ * @returns in which specific directory this query will search if the search location is not set to "Everywhere". When searching "Everywhere" this url is
+ * ignored completely.
+ */
+ inline QUrl searchPath() const
+ {
+ return m_searchPath;
+ };
+
+ /**
+ * Set whether search results should match the search term with their names or contain it in their file contents.
+ */
+ void setSearchThrough(SearchThrough searchThrough);
+ inline SearchThrough searchThrough() const
+ {
+ return m_searchThrough;
+ };
+
+ /**
+ * Set the search tool or backend that will be used to @p searchTool.
+ */
+ inline void setSearchTool(SearchTool searchTool)
+ {
+ m_searchTool = searchTool;
+ // We do not remove any search parameters here, even if the new search tool does not support them. This is an attempt to avoid that we unnecessarily
+ // throw away configuration data. Non-applicable search parameters will be lost when exporting this DolphinQuery to a URL,
+ // but such an export won't happen if the changed DolphinQuery is not a valid search e.g. because the searchTerm().isEmpty() and every other search
+ // parameter is not supported by the new search tool.
+ };
+ /** @returns the search tool to be used for this search. */
+ inline SearchTool searchTool() const
+ {
+ return m_searchTool;
+ };
+
+ /**
+ * Sets the search text the user entered into the search field to @p searchTerm.
+ */
+ inline void setSearchTerm(const QString &searchTerm)
+ {
+ m_searchTerm = searchTerm;
+ };
+ /** @return the search text the user entered into the search field. */
+ inline QString searchTerm() const
+ {
+ return m_searchTerm;
+ };
+
+ /**
+ * Sets the type every search result should have.
+ */
+ inline void setFileType(const KFileMetaData::Type::Type &fileType)
+ {
+ m_fileType = fileType;
+ };
+ /**
+ * @return the requested file type this search will be restricted to.
+ */
+ inline KFileMetaData::Type::Type fileType() const
+ {
+ return m_fileType;
+ };
+
+ /**
+ * Sets the date since when every search result needs to have been modified.
+ */
+ inline void setModifiedSinceDate(const QDate &modifiedLaterThanDate)
+ {
+ m_modifiedSinceDate = modifiedLaterThanDate;
+ };
+ /**
+ * @return the date since when every search result needs to have been modified.
+ */
+ inline QDate modifiedSinceDate() const
+ {
+ return m_modifiedSinceDate;
+ };
+
+ /**
+ * @param minimumRating the minimum rating value every search result needs to at least have to be considered a valid result of this query.
+ * Values <= 0 mean no restriction. 1 is half a star, 2 one full star, etc. 10 is typically the maximum in KDE software.
+ */
+ inline void setMinimumRating(int minimumRating)
+ {
+ m_minimumRating = minimumRating;
+ };
+ /**
+ * @returns the minimum rating every search result is requested to have.
+ * @see setMinimumRating().
+ */
+ inline int minimumRating() const
+ {
+ return m_minimumRating;
+ };
+
+ /**
+ * @param requiredTags All the tags every search result is required to have.
+ */
+ inline void setRequiredTags(const QStringList &requiredTags)
+ {
+ m_requiredTags = requiredTags;
+ };
+ /**
+ * @returns all the tags every search result is required to have.
+ */
+ inline QStringList requiredTags() const
+ {
+ return m_requiredTags;
+ };
+
+ bool operator==(const DolphinQuery &) const = default;
+
+ /**
+ * @returns a title to be used in user-facing situations to represent this DolphinQuery, such as "Query Results from 'importantFile'".
+ */
+ QString title() const;