Commit f442b33a authored by Alexander Lohnau's avatar Alexander Lohnau 💬 Committed by Nate Graham

Utilize new KRunner features

This commit uses the new `runMatch` API from KRunner. Also it provides
the `RunnerManager` as a property to the QML frontend. This is required
to get the history suggestions.
parent 95f89143
......@@ -30,6 +30,7 @@ ListView {
id: listView
property alias queryString: resultModel.queryString
property alias runner: resultModel.runner
property alias runnerManager: resultModel.runnerManager
property alias runnerName: resultModel.runnerName
property alias runnerIcon: resultModel.runnerIcon
......
......@@ -25,6 +25,7 @@
#include "runnerresultsmodel.h"
#include <QIdentityProxyModel>
#include <KRunner/RunnerManager>
#include <KDescendantsProxyModel>
#include <KModelIndexProxyMapper>
......@@ -455,4 +456,9 @@ QMimeData *ResultsModel::getMimeData(const QModelIndex &idx) const
return d->resultsModel->mimeData({resultsIdx});
}
Plasma::RunnerManager* Milou::ResultsModel::runnerManager() const
{
return d->resultsModel->runnerManager();
}
#include "resultsmodel.moc"
......@@ -25,6 +25,7 @@
#include <QIcon>
#include <QSortFilterProxyModel>
#include <QScopedPointer>
#include <KRunner/RunnerManager>
#include "milou_export.h"
......@@ -63,6 +64,7 @@ class MILOU_EXPORT ResultsModel : public QSortFilterProxyModel
// FIXME rename to singleModeRunnerName or something
Q_PROPERTY(QString runnerName READ runnerName NOTIFY runnerChanged)
Q_PROPERTY(QIcon runnerIcon READ runnerIcon NOTIFY runnerChanged)
Q_PROPERTY(Plasma::RunnerManager* runnerManager READ runnerManager CONSTANT)
public:
explicit ResultsModel(QObject *parent = nullptr);
......@@ -120,6 +122,8 @@ public:
*/
Q_INVOKABLE QMimeData *getMimeData(const QModelIndex &idx) const;
Plasma::RunnerManager* runnerManager() const;
Q_SIGNALS:
/**
* This signal is emitted when a an InformationalMatch is run, and it is advised
......
......@@ -41,6 +41,7 @@ RunnerResultsModel::RunnerResultsModel(QObject *parent)
connect(m_manager, &RunnerManager::queryFinished, this, [this] {
setQuerying(false);
});
connect(m_manager, &RunnerManager::setSearchTerm, this, &RunnerResultsModel::queryStringChangeRequested);
m_resetTimer.setSingleShot(true);
m_resetTimer.setInterval(500);
......@@ -262,40 +263,16 @@ void RunnerResultsModel::clear()
bool RunnerResultsModel::run(const QModelIndex &idx)
{
Plasma::QueryMatch match = fetchMatch(idx);
if (!match.isValid()) {
return false;
}
if (match.type() == Plasma::QueryMatch::InformationalMatch) {
QString info = match.data().toString();
int editPos = info.length();
if (!info.isEmpty()) {
// FIXME: pretty lame way to decide if this is a query prototype
// Copied from kde4 krunner interface.cpp
if (!match.runner()) {
// lame way of checking to see if this is a Help Button generated match!
int index = info.indexOf(QStringLiteral(":q:"));
if (index != -1) {
editPos = index;
info.replace(QStringLiteral(":q:"), QString());
}
}
Q_EMIT queryStringChangeRequested(info, editPos);
return false;
}
if (match.isValid() && match.isEnabled()) {
return m_manager->runMatch(match);
}
m_manager->run(match);
return true;
return false;
}
bool RunnerResultsModel::runAction(const QModelIndex &idx, int actionNumber)
{
Plasma::QueryMatch match = fetchMatch(idx);
if (!match.isValid()) {
if (!match.isValid() || !match.isEnabled()) {
return false;
}
......@@ -304,10 +281,8 @@ bool RunnerResultsModel::runAction(const QModelIndex &idx, int actionNumber)
return false;
}
QAction *action = actions.at(actionNumber);
match.setSelectedAction(action);
m_manager->run(match);
return true;
match.setSelectedAction(actions.at(actionNumber));
return m_manager->runMatch(match);
}
int RunnerResultsModel::columnCount(const QModelIndex &parent) const
......@@ -472,3 +447,8 @@ QMimeData *RunnerResultsModel::mimeData(const QModelIndexList &indexes) const
return m_manager->mimeDataForMatch(match);
}
Plasma::RunnerManager *RunnerResultsModel::runnerManager() const
{
return m_manager;
}
......@@ -75,6 +75,8 @@ public:
QMimeData *mimeData(const QModelIndexList &indexes) const override;
Plasma::RunnerManager* runnerManager() const;
Q_SIGNALS:
void queryStringChangeRequested(const QString &queryString, int pos);
......
Markdown is supported
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