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-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-02-11 07:04:20 +01:00
|
|
|
enum DataPolicy { Shared = 0,
|
|
|
|
SingleConsumer
|
|
|
|
};
|
2008-05-01 20:40:10 +02:00
|
|
|
|
|
|
|
explicit RunnerContext(QObject *parent = 0, DataPolicy policy = Shared);
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2008-02-11 07:04:20 +01:00
|
|
|
/**
|
2008-05-01 20:40:10 +02:00
|
|
|
* Constructs a RunnerContext with a DataPolicy of SingleConsumer that
|
2008-02-11 07:04:20 +01:00
|
|
|
* contains the search metadata (though none of the currently registered
|
2008-05-01 20:40:10 +02:00
|
|
|
* matches) from the passed in RunnerContext. Primarily useful for creating
|
|
|
|
* a thread-local copy of a Shared RunnerContext.
|
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-02 20:46:05 +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-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-05-02 20:46:05 +02:00
|
|
|
bool addMatch(const QString &term, QueryMatch *match);
|
2008-02-11 07:04:20 +01:00
|
|
|
|
|
|
|
/**
|
2008-05-01 20:40:10 +02:00
|
|
|
* Takes the matches from this RunnerContext and copies to them another.
|
|
|
|
* If successful, the matches are removed from this RunnerContext and
|
|
|
|
* ownership passed to the other RunnerContext
|
2008-02-11 07:04:20 +01:00
|
|
|
*
|
2008-05-01 20:40:10 +02:00
|
|
|
* @arg other the RunnerContext 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-05-01 20:40:10 +02:00
|
|
|
bool moveMatchesTo(RunnerContext &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-05-02 20:46:05 +02:00
|
|
|
QList<QueryMatch *> matches() const;
|
2007-11-02 03:34:46 +01:00
|
|
|
|
2007-12-02 08:11:50 +01:00
|
|
|
/**
|
2008-05-01 20:40:10 +02:00
|
|
|
* Removes all matches from this RunnerContext.
|
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;
|
2008-05-01 09:51:59 +02:00
|
|
|
QExplicitlySharedDataPointer<Private> 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
|