plasma: const-ify Plasma::RunnerContext arguments

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-18 00:16:31 +03:00
parent 7683b1d29e
commit b2a66f5a72
2 changed files with 156 additions and 161 deletions

View file

@ -258,7 +258,7 @@ RunnerContext::RunnerContext(QObject *parent)
}
//copy ctor
RunnerContext::RunnerContext(RunnerContext &other, QObject *parent)
RunnerContext::RunnerContext(const RunnerContext &other, QObject *parent)
: QObject(parent)
{
LOCK_FOR_READ(other.d)
@ -406,7 +406,7 @@ bool RunnerContext::addMatch(const QString &term, const QueryMatch &match)
return true;
}
bool RunnerContext::removeMatches(const QStringList matchIdList)
bool RunnerContext::removeMatches(const QStringList &matchIdList)
{
if (!isValid()) {
return false;
@ -443,13 +443,13 @@ bool RunnerContext::removeMatches(const QStringList matchIdList)
return true;
}
bool RunnerContext::removeMatch(const QString matchId)
bool RunnerContext::removeMatch(const QString &matchId)
{
if (!isValid()) {
return false;
}
LOCK_FOR_READ(d)
const QueryMatch* match = d->matchesById.value(matchId, 0);
const QueryMatch* match = d->matchesById.value(matchId, nullptr);
UNLOCK(d)
if (!match) {
return false;
@ -505,14 +505,14 @@ QList<QueryMatch> RunnerContext::matches() const
QueryMatch RunnerContext::match(const QString &id) const
{
LOCK_FOR_READ(d)
const QueryMatch *match = d->matchesById.value(id, 0);
const QueryMatch *match = d->matchesById.value(id, nullptr);
UNLOCK(d)
if (match) {
return *match;
}
return QueryMatch(0);
return QueryMatch(nullptr);
}
void RunnerContext::run(const QueryMatch &match)

View file

@ -47,181 +47,176 @@ class PLASMA_EXPORT RunnerContext : public QObject
{
Q_OBJECT
public:
enum Type {
None = 0,
UnknownType = 1,
Directory = 2,
File = 4,
NetworkLocation = 8,
Executable = 16,
ShellCommand = 32,
Help = 64,
FileSystem = Directory | File | Executable | ShellCommand
};
public:
enum Type {
None = 0,
UnknownType = 1,
Directory = 2,
File = 4,
NetworkLocation = 8,
Executable = 16,
ShellCommand = 32,
Help = 64,
FileSystem = Directory | File | Executable | ShellCommand
};
Q_DECLARE_FLAGS(Types, Type)
Q_DECLARE_FLAGS(Types, Type)
explicit RunnerContext(QObject *parent = nullptr);
explicit RunnerContext(QObject *parent = 0);
/**
* Copy constructor
*/
RunnerContext(const RunnerContext &other, QObject *parent = nullptr);
/**
* Copy constructor
*/
RunnerContext(RunnerContext &other, QObject *parent = 0);
/**
* Assignment operator
* @since 4.4
*/
RunnerContext &operator=(const RunnerContext &other);
/**
* Assignment operator
* @since 4.4
*/
RunnerContext &operator=(const RunnerContext &other);
~RunnerContext();
~RunnerContext();
/**
* Resets the search term for this object.
* This removes all current matches in the process and
* turns off single runner query mode.
*/
void reset();
/**
* Resets the search term for this object.
* This removes all current matches in the process and
* turns off single runner query mode.
*/
void reset();
/**
* Sets the query term for this object and attempts to determine
* the type of the search.
*/
void setQuery(const QString &term);
/**
* Sets the query term for this object and attempts to determine
* the type of the search.
*/
void setQuery(const QString &term);
/**
* @return the current search query term.
*/
QString query() const;
/**
* @return the current search query term.
*/
QString query() const;
/**
* The type of item the search term might refer to.
* @see Type
*/
Type type() 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
* the mimetype of the object being referred to by the search
* string.
*/
QString mimeType() const;
/**
* The mimetype that the search term refers to, if discoverable.
*
* @return QString() if the mimetype can not be determined, otherwise
* the mimetype of the object being referred to by the search
* string.
*/
QString mimeType() const;
/**
* @returns true if this context is no longer valid and therefore
* matching using it should abort. Most useful as an optimization technique
* inside of AbstractRunner subclasses in the match method, e.g.:
*
* while (.. a possibly large iteration) {
* if (!context.isValid()) {
* return;
* }
*
* ... some processing ...
* }
*
* While not required to be used within runners, it provies a nice way
* to avoid unnecessary processing in runners that may run for an extended
* period (as measured in 10s of ms) and therefore improve the user experience.
* @since 4.2.3
*/
bool isValid() const;
/**
* @returns true if this context is no longer valid and therefore
* matching using it should abort. Most useful as an optimization technique
* inside of AbstractRunner subclasses in the match method, e.g.:
*
* while (.. a possibly large iteration) {
* if (!context.isValid()) {
* return;
* }
*
* ... some processing ...
* }
*
* While not required to be used within runners, it provies a nice way
* to avoid unnecessary processing in runners that may run for an extended
* period (as measured in 10s of ms) and therefore improve the user experience.
* @since 4.2.3
*/
bool isValid() const;
/**
* Appends lists of matches to the list of matches.
*
* This method is thread safe and causes the matchesChanged() signal to be emitted.
*
* @return true if matches were added, false if matches were e.g. outdated
*/
bool addMatches(const QString &term, const QList<QueryMatch> &matches);
/**
* Appends lists of matches to the list of matches.
*
* This method is thread safe and causes the matchesChanged() signal to be emitted.
*
* @return true if matches were added, false if matches were e.g. outdated
*/
// trueg: what do we need the term for? It is stored in the context anyway! Plus: matches() does not have a term parameter!
// plus: it is Q_UNUSED
bool addMatches(const QString &term, const QList<QueryMatch> &matches);
/**
* Appends a match to the existing list of matches.
*
* If you are going to be adding multiple matches, use addMatches instead.
*
* @param term the search term that this match was generated for.
* @param match the match to add
*
* @return true if the match was added, false otherwise.
*/
bool addMatch(const QString &term, const QueryMatch &match);
/**
* Appends a match to the existing list of matches.
*
* If you are going to be adding multiple matches, use addMatches instead.
*
* @param term the search term that this match was generated for.
* @param match the match to add
*
* @return true if the match was added, false otherwise.
*/
// trueg: what do we need the term for? It is stored in the context anyway! Plus: matches() does not have a term parameter!
// plus: it is Q_UNUSED
bool addMatch(const QString &term, const QueryMatch &match);
/**
* Removes a match from the existing list of matches.
*
* If you are going to be removing multiple matches, use removeMatches instead.
*
* @param matchId the id of match to remove
*
* @return true if the match was removed, false otherwise.
* @since 4.4
*/
bool removeMatch(const QString &matchId);
/**
* Removes a match from the existing list of matches.
*
* If you are going to be removing multiple matches, use removeMatches instead.
*
* @param matchId the id of match to remove
*
* @return true if the match was removed, false otherwise.
* @since 4.4
*/
bool removeMatch(const QString matchId);
/**
* Removes lists of matches from the existing list of matches.
*
* This method is thread safe and causes the matchesChanged() signal to be emitted.
*
* @param matchIdList the list of matches id to remove
*
* @return true if at least one match was removed, false otherwise.
* @since 4.4
*/
bool removeMatches(const QStringList &matchIdList);
/**
* Removes lists of matches from the existing list of matches.
*
* This method is thread safe and causes the matchesChanged() signal to be emitted.
*
* @param matchIdList the list of matches id to remove
*
* @return true if at least one match was removed, false otherwise.
* @since 4.4
*/
bool removeMatches(const QStringList matchIdList);
/**
* Removes lists of matches from a given AbstractRunner
*
* This method is thread safe and causes the matchesChanged() signal to be emitted.
*
* @param runner the AbstractRunner from which to remove matches
*
* @return true if at least one match was removed, false otherwise.
* @since 4.10
*/
bool removeMatches(AbstractRunner *runner);
/**
* Removes lists of matches from a given AbstractRunner
*
* This method is thread safe and causes the matchesChanged() signal to be emitted.
*
* @param runner the AbstractRunner from which to remove matches
*
* @return true if at least one match was removed, false otherwise.
* @since 4.10
*/
bool removeMatches(AbstractRunner *runner);
/**
* Retrieves all available matches for the current search term.
*
* @return a list of matches
*/
QList<QueryMatch> matches() const;
/**
* Retrieves all available matches for the current search term.
*
* @return a list of matches
*/
QList<QueryMatch> matches() const;
/**
* 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;
/**
* 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;
/**
* Run a match using the information from this context
*
* The context will also keep track of the number of times the match was
* launched to sort future matches according to user habits
*
* @param match the match to run
*/
void run(const QueryMatch &match);
/**
* Run a match using the information from this context
*
* The context will also keep track of the number of times the match was
* launched to sort future matches according to user habits
*
* @param match the match to run
*/
void run(const QueryMatch &match);
Q_SIGNALS:
void matchesChanged();
Q_SIGNALS:
void matchesChanged();
private:
QExplicitlySharedDataPointer<RunnerContextPrivate> d;
private:
QExplicitlySharedDataPointer<RunnerContextPrivate> d;
};
}