Commit b34a8847 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Introduce AbstractKRunnerPlugin for wrapping DBusRunner

It serves as a base classe for the upcoming history runner
as well as will see tabsrunner ported to use it
parent ac6cdaea
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.krunner1">
<!--
Returns a list of actions supported by this runner.
For example, a song match returned by a music player runner can be queued, added to the playlist, or played.
This should be constant
Structure is:
- ID
- Text
- IconName
-->
<method name="Actions">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="RemoteActions" />
<arg name="matches" type="a(sss)" direction="out">
</arg>
</method>
<!--
Execute an action
-->
<method name="Run">
<!--
The Unique ID from Match.
-->
<arg name="matchId" type="s" direction="in"/>
<!--
The action ID to run. For the default action this will be empty.
-->
<arg name="actionId" type="s" direction="in"/>
</method>
<!--
Fetch matching results for a given query.
Note: Multiple Match calls may be made with new queries before a call has returned
has returned.
-->
<method name="Match">
<arg name="query" type="s" direction="in"/>
<!--
Return a list of items that match the
Structure is:
- Id
- Text
- IconName
- Type (see PlasmaQuery::Type)
- Relevance
- Properties (VariantMap)
-->
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="RemoteMatches"/>
<arg name="matches" type="a(sssuda{sv})" direction="out"/>
</method>
</interface>
</node>
......@@ -8,6 +8,7 @@ set(HOST_SOURCES main.cpp
settings.cpp
mprisplugin.cpp
abstractbrowserplugin.cpp
abstractkrunnerplugin.cpp
kdeconnectplugin.cpp
downloadplugin.cpp
downloadjob.cpp
......@@ -21,6 +22,8 @@ qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.kde.plasma.browser_integration.Set
qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.mpris.MediaPlayer2.xml mprisplugin.h MPrisPlugin mprisroot MPrisRoot)
qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.mpris.MediaPlayer2.Player.xml mprisplugin.h MPrisPlugin mprisplayer MPrisPlayer)
qt5_add_dbus_adaptor(HOST_SOURCES ../dbus/org.kde.krunner1.xml abstractkrunnerplugin.h AbstractKRunnerPlugin)
add_executable(plasma-browser-integration-host ${HOST_SOURCES})
target_link_libraries(
plasma-browser-integration-host
......@@ -33,6 +36,7 @@ target_link_libraries(
KF5::I18n
KF5::KIOCore
KF5::PurposeWidgets
KF5::Runner
KF5::FileMetaData
)
......
/*
* Copyright (C) 2020 Kai Uwe Broulik <kde@broulik.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "abstractkrunnerplugin.h"
#include <QDBusConnection>
#include <QImage>
#include "krunner1adaptor.h"
AbstractKRunnerPlugin::AbstractKRunnerPlugin(const QString &objectPath,
const QString &subsystemId,
int protocolVersion,
QObject *parent)
: AbstractBrowserPlugin(subsystemId, protocolVersion, parent)
, m_objectPath(objectPath)
{
new Krunner1Adaptor(this);
qDBusRegisterMetaType<RemoteMatch>();
qDBusRegisterMetaType<RemoteMatches>();
qDBusRegisterMetaType<RemoteAction>();
qDBusRegisterMetaType<RemoteActions>();
qDBusRegisterMetaType<RemoteImage>();
}
bool AbstractKRunnerPlugin::onLoad()
{
return QDBusConnection::sessionBus().registerObject(m_objectPath, this);
}
bool AbstractKRunnerPlugin::onUnload()
{
QDBusConnection::sessionBus().unregisterObject(m_objectPath);
return true;
}
RemoteImage AbstractKRunnerPlugin::serializeImage(const QImage &image)
{
QImage convertedImage = image.convertToFormat(QImage::Format_RGBA8888);
RemoteImage remoteImage{
convertedImage.width(),
convertedImage.height(),
convertedImage.bytesPerLine(),
true, // hasAlpha
8, // bitsPerSample
4, // channels
QByteArray(reinterpret_cast<const char *>(convertedImage.constBits()),
convertedImage.sizeInBytes())
};
return remoteImage;
}
/*
* Copyright (C) 2020 Kai Uwe Broulik <kde@broulik.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "abstractbrowserplugin.h"
#include <QDBusContext>
// FIXME adaptor needs this, can we tell qt5_add_dbus_adaptor to add it to the generated file?
#include "dbusutils_p.h"
class AbstractKRunnerPlugin : public AbstractBrowserPlugin, protected QDBusContext
{
Q_OBJECT
protected:
AbstractKRunnerPlugin(const QString &objectPath,
const QString &subsystemId,
int protocolVersion,
QObject *parent);
static RemoteImage serializeImage(const QImage &image);
public:
bool onLoad() override;
bool onUnload() override;
// DBus API
virtual RemoteActions Actions() = 0;
virtual RemoteMatches Match(const QString &searchTerm) = 0;
virtual void Run(const QString &id, const QString &actionId) = 0;
private:
QString m_objectPath;
};
#pragma once
#include <QList>
#include <QString>
#include <QDBusArgument>
#include <QVariantMap>
#include <KRunner/QueryMatch>
struct RemoteMatch
{
//sssuda{sv}
QString id;
QString text;
QString iconName;
Plasma::QueryMatch::Type type = Plasma::QueryMatch::NoMatch;
qreal relevance = 0;
QVariantMap properties;
};
typedef QList<RemoteMatch> RemoteMatches;
struct RemoteAction
{
QString id;
QString text;
QString iconName;
};
typedef QList<RemoteAction> RemoteActions;
struct RemoteImage
{
//iiibiiay (matching notification spec image-data attribute)
int width;
int height;
int rowStride;
bool hasAlpha;
int bitsPerSample;
int channels;
QByteArray data;
};
inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteMatch &match) {
argument.beginStructure();
argument << match.id;
argument << match.text;
argument << match.iconName;
argument << match.type;
argument << match.relevance;
argument << match.properties;
argument.endStructure();
return argument;
}
inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteMatch &match) {
argument.beginStructure();
argument >> match.id;
argument >> match.text;
argument >> match.iconName;
uint type;
argument >> type;
match.type = static_cast<Plasma::QueryMatch::Type>(type);
argument >> match.relevance;
argument >> match.properties;
argument.endStructure();
return argument;
}
inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteAction &action)
{
argument.beginStructure();
argument << action.id;
argument << action.text;
argument << action.iconName;
argument.endStructure();
return argument;
}
inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteAction &action) {
argument.beginStructure();
argument >> action.id;
argument >> action.text;
argument >> action.iconName;
argument.endStructure();
return argument;
}
inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteImage &image) {
argument.beginStructure();
argument << image.width;
argument << image.height;
argument << image.rowStride;
argument << image.hasAlpha;
argument << image.bitsPerSample;
argument << image.channels;
argument << image.data;
argument.endStructure();
return argument;
}
inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteImage &image) {
argument.beginStructure();
argument >> image.width;
argument >> image.height;
argument >> image.rowStride;
argument >> image.hasAlpha;
argument >> image.bitsPerSample;
argument >> image.channels;
argument >> image.data;
argument.endStructure();
return argument;
}
Q_DECLARE_METATYPE(RemoteMatch)
Q_DECLARE_METATYPE(RemoteMatches)
Q_DECLARE_METATYPE(RemoteAction)
Q_DECLARE_METATYPE(RemoteActions)
Q_DECLARE_METATYPE(RemoteImage)
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