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-01 20:40:10 +02:00
|
|
|
#ifndef RUNNERCONTEXT_H
|
|
|
|
#define RUNNERCONTEXT_H
|
2007-11-02 03:34:46 +01:00
|
|
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
#include <QtCore/QObject>
|
2008-05-03 16:42:18 +02:00
|
|
|
#include <QtCore/QSharedDataPointer>
|
2007-11-02 03:34:46 +01:00
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
class KCompletion;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-05-02 20:46:05 +02:00
|
|
|
class QueryMatch;
|
2007-11-02 03:34:46 +01:00
|
|
|
class AbstractRunner;
|
2008-07-01 20:56:43 +02:00
|
|
|
class RunnerContextPrivate;
|
2007-11-02 03:34:46 +01:00
|
|
|
|
|
|
|
/**
|
2008-05-01 20:40:10 +02:00
|
|
|
* @short The RunnerContext class provides information related to a search,
|
2007-11-02 03:34:46 +01:00
|
|
|
* including the search term, metadata on the search term and collected
|
|
|
|
* matches.
|
|
|
|
*/
|
2008-05-01 20:40:10 +02:00
|
|
|
class PLASMA_EXPORT RunnerContext : public QObject
|
2007-11-02 03:34:46 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2008-05-01 09:51:59 +02:00
|
|
|
enum Type { None = 0,
|
|
|
|
UnknownType = 1,
|
|
|
|
Directory = 2,
|
|
|
|
File = 4,
|
|
|
|
NetworkLocation = 8,
|
|
|
|
Executable = 16,
|
|
|
|
ShellCommand = 32,
|
2008-05-01 19:56:28 +02:00
|
|
|
Help = 64,
|
|
|
|
FileSystem = Directory | File | Executable | ShellCommand
|
2007-11-02 03:34:46 +01:00
|
|
|
};
|
|
|
|
|
2008-05-01 09:51:59 +02:00
|
|
|
Q_DECLARE_FLAGS(Types, Type)
|
|
|
|
|
2008-05-09 05:49:11 +02:00
|
|
|
explicit RunnerContext(QObject *parent = 0);
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-02-11 07:04:20 +01:00
|
|
|
/**
|
2008-05-09 05:49:11 +02:00
|
|
|
* Copy constructor
|
2008-02-11 07:04:20 +01:00
|
|
|
*/
|
2008-05-01 20:40:10 +02:00
|
|
|
explicit RunnerContext(RunnerContext& other, QObject *parent = 0);
|
2008-05-01 09:51:59 +02:00
|
|
|
|
2008-05-01 20:40:10 +02:00
|
|
|
~RunnerContext();
|
2008-02-11 07:04:20 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2008-05-02 20:17:09 +02:00
|
|
|
* Sets the query term for this object and attempts to determine
|
2008-01-22 05:38:03 +01:00
|
|
|
* the type of the search.
|
2007-11-02 03:34:46 +01:00
|
|
|
*/
|
2008-05-02 20:17:09 +02:00
|
|
|
void setQuery(const QString& term);
|
2007-11-02 03:34:46 +01:00
|
|
|
|
|
|
|
/**
|
2008-05-02 20:17:09 +02:00
|
|
|
* @return the current search query term.
|
2007-11-02 03:34:46 +01:00
|
|
|
*/
|
2008-05-02 20:17:09 +02:00
|
|
|
QString query() const;
|
2007-11-02 03:34:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2008-05-01 09:51:59 +02:00
|
|
|
/**
|
2008-02-19 04:59:21 +01:00
|
|
|
* Appends lists of matches to the list of matches.
|
2008-05-01 20:40:10 +02:00
|
|
|
* The RunnerContext 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-05-09 05:49:11 +02:00
|
|
|
bool addMatches(const QString& term, const QList<QueryMatch> &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.
|
2008-05-01 20:40:10 +02:00
|
|
|
* The RunnerContext takes over ownership of the match on successful addition.
|
2008-02-11 07:04:20 +01:00
|
|
|
*
|
2008-05-09 05:49:11 +02:00
|
|
|
* If you are going to be adding multiple matches, 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-05-09 05:49:11 +02:00
|
|
|
bool addMatch(const QString &term, const QueryMatch &match);
|
2008-02-11 07:04:20 +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.
|
2008-05-12 06:53:42 +02:00
|
|
|
*
|
|
|
|
* @return a list of matches
|
2007-11-02 03:34:46 +01:00
|
|
|
*/
|
2008-05-09 05:49:11 +02:00
|
|
|
QList<QueryMatch> matches() const;
|
2007-12-02 08:11:50 +01:00
|
|
|
|
2008-05-12 06:53:42 +02:00
|
|
|
/**
|
|
|
|
* Retrieves a match by id.
|
|
|
|
*
|
|
|
|
* @param id the id of the match to return
|
|
|
|
* @return the match associated with this id, or an invalid QueryMatch object
|
|
|
|
* if the id does not eixst
|
|
|
|
*/
|
|
|
|
QueryMatch match(const QString &id) const;
|
|
|
|
|
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:
|
2008-07-01 20:56:43 +02:00
|
|
|
QExplicitlySharedDataPointer<RunnerContextPrivate> d;
|
2007-11-02 03:34:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-05-01 20:40:10 +02:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::RunnerContext::Types)
|
2008-05-01 09:51:59 +02:00
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
#endif
|