Commit bfa1ee49 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Port deprecated KRunner singleRunnerMode methods

The SourcesModel is deprecated anyways, that is why
I have just added the deprecation macros from KRunner
around the usages.
parent d1babfb4
......@@ -16,6 +16,7 @@
#include <KDescendantsProxyModel>
#include <KModelIndexProxyMapper>
#include <KRunner/AbstractRunner>
#include <cmath>
using namespace Milou;
......@@ -292,7 +293,7 @@ public:
ResultsModel *q;
QString runner;
QPointer<Plasma::AbstractRunner> runner = nullptr;
RunnerResultsModel *resultsModel;
SortProxyModel *sortModel;
......@@ -319,7 +320,6 @@ ResultsModel::ResultsModel(QObject *parent)
{
connect(d->resultsModel, &RunnerResultsModel::queryStringChanged, this, &ResultsModel::queryStringChanged);
connect(d->resultsModel, &RunnerResultsModel::queryingChanged, this, &ResultsModel::queryingChanged);
connect(d->resultsModel, &RunnerResultsModel::runnerChanged, this, &ResultsModel::runnerChanged);
connect(d->resultsModel, &RunnerResultsModel::queryStringChangeRequested, this, &ResultsModel::queryStringChangeRequested);
connect(d->resultsModel, &RunnerResultsModel::queryStringChanged, d->sortModel, &SortProxyModel::setQueryString);
......@@ -357,7 +357,7 @@ QString ResultsModel::queryString() const
void ResultsModel::setQueryString(const QString &queryString)
{
d->resultsModel->setQueryString(queryString);
d->resultsModel->setQueryString(queryString, runner());
}
int ResultsModel::limit() const
......@@ -382,22 +382,30 @@ bool ResultsModel::querying() const
QString ResultsModel::runner() const
{
return d->resultsModel->runner();
return d->runner ? d->runner->id() : QString();
}
void ResultsModel::setRunner(const QString &runner)
void ResultsModel::setRunner(const QString &runnerId)
{
d->resultsModel->setRunner(runner);
if (runnerId == runner()) {
return;
}
if (runnerId.isEmpty()) {
d->runner = nullptr;
} else {
d->runner = runnerManager()->runner(runnerId);
}
Q_EMIT runnerChanged();
}
QString ResultsModel::runnerName() const
{
return d->resultsModel->runnerName();
return d->runner ? d->runner->name() : QString();
}
QIcon ResultsModel::runnerIcon() const
{
return d->resultsModel->runnerIcon();
return d->runner ? d->runner->icon() : QIcon();
}
QHash<int, QByteArray> ResultsModel::roleNames() const
......
......@@ -167,19 +167,21 @@ QString RunnerResultsModel::queryString() const
return m_queryString;
}
void RunnerResultsModel::setQueryString(const QString &queryString)
void RunnerResultsModel::setQueryString(const QString &queryString, const QString &runner)
{
if (m_queryString.trimmed() == queryString.trimmed()) {
// If our query and runner are the same we don't need to query again
if (m_queryString.trimmed() == queryString.trimmed() && m_prevRunner == runner) {
return;
}
m_prevRunner = runner;
m_queryString = queryString;
m_hasMatches = false;
if (queryString.isEmpty()) {
clear();
} else if (!queryString.trimmed().isEmpty()) {
m_resetTimer.start();
m_manager->launchQuery(queryString, m_runner);
m_manager->launchQuery(queryString, runner);
setQuerying(true);
}
Q_EMIT queryStringChanged(queryString);
......@@ -198,39 +200,6 @@ void RunnerResultsModel::setQuerying(bool querying)
}
}
QString RunnerResultsModel::runner() const
{
return m_runner;
}
void RunnerResultsModel::setRunner(const QString &runner)
{
if (m_runner == runner) {
return;
}
m_runner = runner;
m_manager->setSingleModeRunnerId(runner);
m_manager->setSingleMode(!runner.isEmpty());
Q_EMIT runnerChanged();
}
QString RunnerResultsModel::runnerName() const
{
if (auto *singleRunner = m_manager->singleModeRunner()) {
return singleRunner->name();
}
return QString();
}
QIcon RunnerResultsModel::runnerIcon() const
{
if (auto *singleRunner = m_manager->singleModeRunner()) {
return singleRunner->icon();
}
return QIcon();
}
void RunnerResultsModel::clear()
{
m_manager->reset();
......
......@@ -31,19 +31,12 @@ public:
~RunnerResultsModel() override;
QString queryString() const;
void setQueryString(const QString &queryString);
void setQueryString(const QString &queryString, const QString &runner);
Q_SIGNAL void queryStringChanged(const QString &queryString);
bool querying() const;
Q_SIGNAL void queryingChanged();
QString runner() const;
void setRunner(const QString &runner);
Q_SIGNAL void runnerChanged();
QString runnerName() const;
QIcon runnerIcon() const;
/**
* Clears the model content and resets the runner context, i.e. no new items will appear.
*/
......@@ -79,7 +72,7 @@ private:
QString m_queryString;
bool m_querying = false;
QString m_runner;
QString m_prevRunner;
QTimer m_resetTimer;
bool m_hasMatches = false;
......
......@@ -153,6 +153,7 @@ int SourcesModel::queryLimit() const
return m_queryLimit;
}
#if KRUNNER_BUILD_DEPRECATED_SINCE(5, 81)
QString SourcesModel::runner() const
{
return m_runner;
......@@ -189,6 +190,7 @@ QIcon SourcesModel::runnerIcon() const
return singleRunner->icon();
}
#endif
void SourcesModel::setQueryLimit(int limit)
{
......
......@@ -24,10 +24,11 @@ class MILOU_EXPORT SourcesModel : public QAbstractListModel
Q_OBJECT
Q_PROPERTY(QString queryString READ queryString WRITE setQueryString)
Q_PROPERTY(int queryLimit READ queryLimit WRITE setQueryLimit)
#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 81)
Q_PROPERTY(QString runner READ runner WRITE setRunner NOTIFY runnerChanged)
Q_PROPERTY(QString runnerName READ runnerName NOTIFY runnerChanged)
Q_PROPERTY(QIcon runnerIcon READ runnerIcon NOTIFY runnerChanged)
#endif
public:
explicit SourcesModel(QObject *parent = nullptr);
......@@ -50,11 +51,13 @@ public:
return false;
}
#if KRUNNER_ENABLE_DEPRECATED_SINCE(5, 81)
QString runner() const;
void setRunner(const QString &runner);
QString runnerName() const;
QIcon runnerIcon() const;
#endif
QString queryString() const;
int queryLimit() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment