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.
|
|
|
|
*/
|
|
|
|
|
2008-05-02 20:46:05 +02:00
|
|
|
#ifndef QUERYMATCH_H
|
|
|
|
#define QUERYMATCH_H
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-05-12 23:55:32 +02:00
|
|
|
#include <QtCore/QSharedDataPointer>
|
2008-05-09 05:49:11 +02:00
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
2007-12-10 19:04:45 +01:00
|
|
|
class QIcon;
|
|
|
|
class QVariant;
|
|
|
|
class QString;
|
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-05-01 20:40:10 +02:00
|
|
|
class RunnerContext;
|
2007-11-02 03:34:46 +01:00
|
|
|
class AbstractRunner;
|
|
|
|
|
2008-05-06 20:43:55 +02:00
|
|
|
/**
|
|
|
|
* @short A match returned by an AbstractRunner in response to a given
|
|
|
|
* RunnerContext.
|
|
|
|
*/
|
|
|
|
|
2008-05-02 20:46:05 +02:00
|
|
|
class PLASMA_EXPORT QueryMatch
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
public:
|
2008-02-18 00:02:46 +01:00
|
|
|
/**
|
|
|
|
* The type of match. Value is important here as it is used for sorting
|
|
|
|
*/
|
2008-05-09 05:49:11 +02:00
|
|
|
enum Type { NoMatch = 0 /**< Null match */,
|
|
|
|
CompletionMatch = 10 /**< Possible completion for the data of the query */,
|
2008-05-01 09:51:59 +02:00
|
|
|
PossibleMatch = 30 /**< Something that may match the query */,
|
2008-02-18 00:02:46 +01:00
|
|
|
InformationalMatch = 50 /**< A purely informational, non-actionable match,
|
|
|
|
such as the answer to a question or calculation*/,
|
2008-03-18 02:39:52 +01:00
|
|
|
HelperMatch = 70 /**< A match that represents an action not directly related
|
|
|
|
to activating the given search term, such as a search
|
|
|
|
in an external tool or a command learning trigger. Helper
|
|
|
|
matches tend to be generic to the query and should not
|
|
|
|
be autoactivated just because the user hits "Enter"
|
|
|
|
while typing. They must be explicitly selected to
|
|
|
|
be activated, but unlike InformationalMatch cause
|
|
|
|
an action to be triggered. */,
|
|
|
|
ExactMatch = 100 /**< An exact match to the query */};
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-05-01 09:51:59 +02:00
|
|
|
|
2008-02-19 04:59:21 +01:00
|
|
|
/**
|
2008-05-01 20:40:10 +02:00
|
|
|
* Constructs a PossibleMatch associated with a given RunnerContext
|
2008-02-19 04:59:21 +01:00
|
|
|
* and runner.
|
|
|
|
*
|
2008-05-01 20:40:10 +02:00
|
|
|
* @arg search the RunnerContext this match belongs to
|
2008-02-19 04:59:21 +01:00
|
|
|
* @arg runner the runner this match belongs to
|
|
|
|
*/
|
2008-05-02 20:46:05 +02:00
|
|
|
explicit QueryMatch(AbstractRunner *runner);
|
2008-05-09 05:49:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor
|
|
|
|
*/
|
|
|
|
QueryMatch(const QueryMatch &other);
|
|
|
|
|
2008-05-02 20:46:05 +02:00
|
|
|
~QueryMatch();
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-05-09 06:32:54 +02:00
|
|
|
bool isValid() const;
|
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
/**
|
|
|
|
* Sets the type of match this action represents.
|
|
|
|
*/
|
|
|
|
void setType(Type type);
|
|
|
|
|
|
|
|
/**
|
2008-02-19 04:59:21 +01:00
|
|
|
* The type of action this is. Defaults to PossibleMatch.
|
2007-11-02 03:34:46 +01:00
|
|
|
*/
|
|
|
|
Type type() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the relevance of this action for the search
|
|
|
|
* it was created for.
|
|
|
|
*
|
|
|
|
* @param relevance a number between 0 and 1.
|
|
|
|
*/
|
|
|
|
void setRelevance(qreal relevance);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The relevance of this action to the search. By default,
|
|
|
|
* the relevance is 1.
|
|
|
|
*
|
|
|
|
* @return a number between 0 and 1
|
|
|
|
*/
|
|
|
|
qreal relevance() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The runner associated with this action
|
|
|
|
*/
|
|
|
|
AbstractRunner* runner() const;
|
|
|
|
|
2008-05-06 20:43:55 +02:00
|
|
|
/**
|
|
|
|
* A string that can be used as an ID for this match,
|
|
|
|
* even between different queries. It is based in part
|
|
|
|
* on the source of the match (the AbstractRunner) and
|
|
|
|
* distinguishing information provided by the runner,
|
|
|
|
* ensuring global uniqueness as well as consistency
|
|
|
|
* between query matches.
|
|
|
|
*/
|
|
|
|
QString id() const;
|
2007-12-02 08:11:50 +01:00
|
|
|
|
|
|
|
QString text() const;
|
2008-02-19 12:24:42 +01:00
|
|
|
QString subtext() const;
|
2007-12-02 08:11:50 +01:00
|
|
|
QVariant data() const;
|
|
|
|
QIcon icon() const;
|
|
|
|
bool isEnabled() const;
|
|
|
|
|
2008-05-02 20:46:05 +02:00
|
|
|
bool operator<(const QueryMatch& other) const;
|
2008-05-09 05:49:11 +02:00
|
|
|
QueryMatch& operator=(const QueryMatch &other);
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-05-09 05:49:11 +02:00
|
|
|
/**
|
|
|
|
* Requests this match to activae using the given context
|
|
|
|
*
|
|
|
|
* @param context the context to use in conjunction with this run
|
|
|
|
*/
|
|
|
|
void run(const RunnerContext &context) const;
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-05-06 20:43:55 +02:00
|
|
|
/**
|
|
|
|
* Sets data to be used internally by the associated
|
2008-05-08 00:27:51 +02:00
|
|
|
* AbstractRunner.
|
|
|
|
*
|
|
|
|
* When set, it is also used to form
|
|
|
|
* part of the id() for this match. If that is innapropriate
|
|
|
|
* as an id, the runner may generate its own id and set that
|
|
|
|
* with setId(const QString&) directly after calling setData
|
2008-05-06 20:43:55 +02:00
|
|
|
*/
|
|
|
|
void setData(const QVariant& data);
|
|
|
|
|
2008-05-08 00:27:51 +02:00
|
|
|
/**
|
|
|
|
* Sets the id for this match; useful if the id does not
|
|
|
|
* match data().toString(). The id must be unique to all
|
|
|
|
* matches from this runner, and should remain constant
|
|
|
|
* for the same query for best results.
|
|
|
|
*
|
|
|
|
* @param id the new identifying string to use to refer
|
|
|
|
* to this entry
|
|
|
|
*/
|
|
|
|
void setId(const QString &id);
|
|
|
|
|
2008-05-06 20:43:55 +02:00
|
|
|
void setText(const QString& text);
|
|
|
|
void setSubtext(const QString& text);
|
|
|
|
void setIcon(const QIcon& icon);
|
|
|
|
void setEnabled(bool enable);
|
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
private:
|
|
|
|
class Private;
|
2008-05-09 05:49:11 +02:00
|
|
|
QSharedDataPointer<Private> d;
|
2007-11-02 03:34:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|