2007-11-02 03:34:46 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SEARCHCONTEXT_H
|
|
|
|
#define SEARCHCONTEXT_H
|
|
|
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
class KCompletion;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-12-03 18:18:28 +01:00
|
|
|
class SearchMatch;
|
2007-11-02 03:34:46 +01:00
|
|
|
class AbstractRunner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @short The SearchContext class provides information related to a search,
|
|
|
|
* including the search term, metadata on the search term and collected
|
|
|
|
* matches.
|
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT SearchContext : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum Type { UnknownType = 0,
|
|
|
|
Directory,
|
|
|
|
File,
|
|
|
|
NetworkLocation,
|
|
|
|
Executable,
|
|
|
|
ShellCommand,
|
|
|
|
Help
|
|
|
|
};
|
|
|
|
|
2008-02-11 07:04:20 +01:00
|
|
|
enum DataPolicy { Shared = 0,
|
|
|
|
SingleConsumer
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit SearchContext(QObject *parent = 0, DataPolicy policy = Shared);
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-02-11 07:04:20 +01:00
|
|
|
/**
|
|
|
|
* Constructs a SearchContext with a DataPolicy of SingleConsumer that
|
|
|
|
* contains the search metadata (though none of the currently registered
|
|
|
|
* matches) from the passed in SearchContext. Primarily useful for creating
|
|
|
|
* a thread-local copy of a Shared SearchContext.
|
|
|
|
*/
|
2007-12-02 08:11:50 +01:00
|
|
|
SearchContext(QObject *parent, const SearchContext& other);
|
2008-02-11 07:04:20 +01:00
|
|
|
~SearchContext();
|
|
|
|
|
2007-12-02 08:11:50 +01:00
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
/**
|
2008-04-24 18:25:36 +02:00
|
|
|
* Resets the search term for this object.
|
|
|
|
* This removes all current matches in the process.
|
2008-01-22 05:38:03 +01:00
|
|
|
*/
|
2008-04-24 18:25:36 +02:00
|
|
|
void reset();
|
2008-01-22 05:38:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the search term for this object and attempts to determine
|
|
|
|
* the type of the search.
|
2007-11-02 03:34:46 +01:00
|
|
|
*/
|
|
|
|
void setSearchTerm(const QString&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the current search term.
|
|
|
|
*/
|
|
|
|
QString searchTerm() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of item the search term might refer to.
|
|
|
|
* @see Type
|
|
|
|
*/
|
|
|
|
Type type() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The mimetype that the search term refers to, if discoverable.
|
|
|
|
*
|
|
|
|
* @return QString() if the mimetype can not be determined, otherwise
|
2008-02-04 17:26:49 +01:00
|
|
|
* the mimetype of the object being referred to by the search
|
2007-11-02 03:34:46 +01:00
|
|
|
* string.
|
|
|
|
*/
|
2008-04-24 17:15:38 +02:00
|
|
|
QString mimeType() const;
|
2007-11-02 03:34:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return a completion object that can be used with UI elements
|
|
|
|
*/
|
|
|
|
KCompletion* completionObject() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an item to the completion object.
|
|
|
|
*/
|
|
|
|
void addStringCompletion(const QString& completion);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds multiple items to the completion object.
|
|
|
|
*/
|
|
|
|
void addStringCompletions(const QStringList& completions);
|
|
|
|
|
|
|
|
/**
|
2008-02-19 04:59:21 +01:00
|
|
|
* Appends lists of matches to the list of matches.
|
|
|
|
* The SearchContext takes over ownership of the matches on successful addition.
|
2007-11-02 03:34:46 +01:00
|
|
|
*
|
2008-02-19 04:59:21 +01:00
|
|
|
* This method is thread safe and causes the matchesChanged() signal to be emitted.
|
2008-02-11 07:04:20 +01:00
|
|
|
*
|
2008-02-19 04:59:21 +01:00
|
|
|
* @return true if matches were added, false if matches were e.g. outdated
|
2007-11-02 03:34:46 +01:00
|
|
|
*/
|
2008-02-19 04:59:21 +01:00
|
|
|
bool addMatches(const QString& term, const QList<SearchMatch *> &matches);
|
2007-11-02 03:34:46 +01:00
|
|
|
|
|
|
|
/**
|
2008-02-19 04:59:21 +01:00
|
|
|
* Appends a match to the existing list of matches.
|
|
|
|
* The SearchContext takes over ownership of the match on successful addition.
|
2008-02-11 07:04:20 +01:00
|
|
|
*
|
2008-02-19 04:59:21 +01:00
|
|
|
* If you are going to be adding multiple matches, it is better to use
|
|
|
|
* addMatches instead.
|
2008-02-11 07:04:20 +01:00
|
|
|
*
|
2008-02-19 04:59:21 +01:00
|
|
|
* @arg term the search term that this match was generated for
|
|
|
|
* @arg match the match to add
|
2008-02-11 07:04:20 +01:00
|
|
|
*
|
2008-02-19 04:59:21 +01:00
|
|
|
* @return true if the match was added, false otherwise.
|
2008-02-11 07:04:20 +01:00
|
|
|
*/
|
2008-02-19 04:59:21 +01:00
|
|
|
bool addMatch(const QString &term, SearchMatch *match);
|
2008-02-11 07:04:20 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-24 17:37:12 +02:00
|
|
|
* Takes the matches from this SearchContext and copies to them another.
|
2008-02-11 07:04:20 +01:00
|
|
|
* If successful, the matches are removed from this SearchContext and
|
|
|
|
* ownership passed to the other SearchContext
|
|
|
|
*
|
2008-04-24 17:37:12 +02:00
|
|
|
* @arg other the SearchContext to move this object's Matches to
|
2008-02-11 07:04:20 +01:00
|
|
|
* @return true if matches were added, false if matches were e.g. outdated
|
2007-12-02 08:11:50 +01:00
|
|
|
*/
|
2008-04-24 17:37:12 +02:00
|
|
|
bool moveMatchesTo(SearchContext &other);
|
2007-12-02 08:11:50 +01:00
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
/**
|
2008-02-19 04:59:21 +01:00
|
|
|
* Retrieves all available matches for the current search term.
|
2007-11-02 03:34:46 +01:00
|
|
|
*/
|
2008-02-19 04:59:21 +01:00
|
|
|
QList<SearchMatch *> matches() const;
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2007-12-02 08:11:50 +01:00
|
|
|
/**
|
|
|
|
* Determines type of query
|
|
|
|
*/
|
|
|
|
void determineType();
|
|
|
|
|
|
|
|
/**
|
2008-04-24 18:04:50 +02:00
|
|
|
* Removes all matches from this SearchContext.
|
2007-12-02 08:11:50 +01:00
|
|
|
*/
|
2008-04-24 18:04:50 +02:00
|
|
|
void removeAllMatches();
|
2007-12-02 08:11:50 +01:00
|
|
|
|
2007-12-03 20:01:01 +01:00
|
|
|
Q_SIGNALS:
|
2007-12-02 08:11:50 +01:00
|
|
|
void matchesChanged();
|
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
private:
|
|
|
|
class Private;
|
|
|
|
Private * const d;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|