diff --git a/KF5DBusRunnerConfig.cmake.in b/KF5DBusRunnerConfig.cmake.in new file mode 100644 --- /dev/null +++ b/KF5DBusRunnerConfig.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +find_dependency(Qt5Core "@REQUIRED_QT_VERSION@") + +include("${CMAKE_CURRENT_LIST_DIR}/KF5DBusRunnerTargets.cmake") +@PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -13,9 +13,7 @@ ) set(demoapp_SRCS testremoterunner.cpp) -qt5_add_dbus_adaptor(demoapp_SRCS "../src/data/org.kde.krunner1.xml" testremoterunner.h TestRemoteRunner) add_executable(testremoterunner ${demoapp_SRCS}) target_link_libraries(testremoterunner - Qt5::DBus - KF5::Runner + KF5::DBusRunner ) diff --git a/autotests/testremoterunner.h b/autotests/testremoterunner.h --- a/autotests/testremoterunner.h +++ b/autotests/testremoterunner.h @@ -1,16 +1,33 @@ +/* + * Copyright (C) 2017 David Edmundson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + #pragma once -#include -#include "../src/dbusutils_p.h" +#include -class TestRemoteRunner : public QObject +class TestRemoteRunner : public KDBusRunner::AbstractRunner { Q_OBJECT public: TestRemoteRunner(); -public Q_SLOTS: - RemoteActions Actions(); - RemoteMatches Match(const QString &searchTerm); - void Run(const QString &id, const QString &actionId); +public: + KDBusRunner::Actions actions() override; + void startMatching(const QString &searchTerm) override; + void run(const QString &id, const QString &actionId) override; }; diff --git a/autotests/testremoterunner.cpp b/autotests/testremoterunner.cpp --- a/autotests/testremoterunner.cpp +++ b/autotests/testremoterunner.cpp @@ -17,54 +17,43 @@ */ #include -#include - #include #include "testremoterunner.h" -#include "krunner1adaptor.h" //Test DBus runner, if the search term contains "foo" it returns a match, otherwise nothing //Run prints a line to stdout TestRemoteRunner::TestRemoteRunner() + : KDBusRunner::AbstractRunner(QStringLiteral("/dave"), QStringLiteral("net.dave")) { - new Krunner1Adaptor(this); - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - QDBusConnection::sessionBus().registerService(QStringLiteral("net.dave")); - QDBusConnection::sessionBus().registerObject(QStringLiteral("/dave"), this); } -RemoteMatches TestRemoteRunner::Match(const QString& searchTerm) +void TestRemoteRunner::startMatching(const QString& searchTerm) { - RemoteMatches ms; if (searchTerm.contains(QLatin1String("foo"))) { - RemoteMatch m; - m.id = QStringLiteral("id1"); - m.text = QStringLiteral("Match 1"); - m.iconName = QStringLiteral("icon1"); - m.type = Plasma::QueryMatch::ExactMatch; - m.relevance = 0.8; - ms << m; + addMatches({{ + QStringLiteral("id1"), + QStringLiteral("Match 1"), + QStringLiteral("icon1"), + KDBusRunner::QueryMatch::ExactMatch, + 0.8, + {} + }}); } - return ms; - + finishMatching(); } -RemoteActions TestRemoteRunner::Actions() +KDBusRunner::Actions TestRemoteRunner::actions() { - RemoteAction action; - action.id = QStringLiteral("action1"); - action.text = QStringLiteral("Action 1"); - action.iconName = QStringLiteral("document-browser"); - - return RemoteActions({action}); + return {{ + QStringLiteral("action1"), + QStringLiteral("Action 1"), + QStringLiteral("document-browser") + }}; } -void TestRemoteRunner::Run(const QString &id, const QString &actionId) +void TestRemoteRunner::run(const QString &id, const QString &actionId) { std::cout << "Running:" << qPrintable(id) << ":" << qPrintable(actionId) << std::endl; std::cout.flush(); @@ -74,5 +63,6 @@ { QCoreApplication app(argc, argv); TestRemoteRunner r; + r.setEnabled(); app.exec(); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(declarative) +add_subdirectory(dbusrunner) set (KF5Runner_SRCS abstractrunner.cpp diff --git a/src/dbusrunner/CMakeLists.txt b/src/dbusrunner/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/dbusrunner/CMakeLists.txt @@ -0,0 +1,81 @@ +set (KF5DBusRunner_SRCS + abstractrunner_p.cpp + abstractrunner.cpp + dbusadaptor.cpp +) + +ecm_qt_declare_logging_category(KF5DBusRunner_SRCS HEADER kdbusrunner_debug.h IDENTIFIER KDBUSRUNNER CATEGORY_NAME org.kde.kdbusrunner) + +add_library(KF5DBusRunner ${KF5DBusRunner_SRCS}) + +generate_export_header(KF5DBusRunner BASE_NAME KDBusRunner) +add_library(KF5::DBusRunner ALIAS KF5DBusRunner) + +target_include_directories(KF5DBusRunner INTERFACE "$") +target_include_directories(KF5DBusRunner PUBLIC "$") + + +target_link_libraries(KF5DBusRunner + PUBLIC + Qt5::Core + PRIVATE + Qt5::DBus +) + +set_target_properties(KF5DBusRunner + PROPERTIES VERSION ${KRUNNER_VERSION_STRING} + SOVERSION 5 + EXPORT_NAME "DBusRunner" +) + +ecm_generate_headers(KDBusRunner_CamelCase_HEADERS + HEADER_NAMES + AbstractRunner + Action + QueryMatch + + PREFIX KDBusRunner + REQUIRED_HEADERS KDBusRunner_HEADERS +) + +# Install files + +install(TARGETS KF5DBusRunner + EXPORT KF5DBusRunnerTargets + ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) + +install(FILES ${KDBusRunner_CamelCase_HEADERS} + DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KDBusRunner/KDBusRunner + COMPONENT Devel) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/kdbusrunner_export.h + ${KDBusRunner_HEADERS} + DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KDBusRunner/kdbusrunner + COMPONENT Devel) + +if(BUILD_QCH) + ecm_add_qch( + KF5DBusRunner_QCH + NAME KDBusRunner + BASE_NAME KF5DBusRunner + VERSION ${KF5_VERSION} + ORG_DOMAIN org.kde + SOURCES # using only public headers, to cover only public API + ${KDBusRunner_HEADERS} + LINK_QCHS + Qt5Core_QCH + BLANK_MACROS + KDBUSRUNNER_EXPORT + KDBUSRUNNER_DEPRECATED + KDBUSRUNNER_DEPRECATED_EXPORT + TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} + QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} + COMPONENT Devel + ) +endif() + +include(ECMGeneratePriFile) +ecm_generate_pri_file(BASE_NAME KDBusRunner LIB_NAME KF5DBusRunner DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KF5_INCLUDE_INSTALL_DIR}/KDBusRunner) +install(FILES ${PRI_FILENAME} + DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/dbusrunner/abstractrunner.h b/src/dbusrunner/abstractrunner.h new file mode 100644 --- /dev/null +++ b/src/dbusrunner/abstractrunner.h @@ -0,0 +1,168 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#pragma once + +#include "kdbusrunner_export.h" + +#include "querymatch.h" +#include "action.h" + +#include + +namespace KDBusRunner +{ + +/** + * @class AbstractRunner abstractrunner.h + * + * @short An abstract base class for KRunner D-Bus plugins + * + * Example: + * @code +#include + +class MyRunner : public KDBusRunner::AbstractRunner +{ + Q_OBJECT + +public: + MyRunner(); + +public: + KDBusRunner::Actions actions() override; + void startMatching(const QString &queryTerm) override; + void run(const QString &id, const QString &actionId) override; +}; + * @endcode + * + * The implementation of the D-Bus runner class: + * @code +MyRunner::MyRunner() + : KDBusRunner::AbstractRunner(QStringLiteral("/myrunner"), QStringLiteral("org.example.myrunner")) +{ +} + +void MyRunner::startMatching(const QString& searchTerm) +{ + if (searchTerm.contains(QLatin1String("my"))) { + addMatches({{ + QStringLiteral("matchid"), + QStringLiteral("My Match"), + QStringLiteral("fooicon"), + KDBusRunner::QueryMatch::ExactMatch, + 0.8, + {} + }}); + } + finishMatching(); +} + +KDBusRunner::Actions MyRunner::actions() +{ + return {{ + QStringLiteral("action1"), + QStringLiteral("Open container"), + QStringLiteral("document-browser") + }}; +} + +void MyRunner::run(const QString &id, const QString &actionId) +{ + // do actionId with id +} + * @endcode + * + * Now the class just needs to be instantiated and activated by enabling it: + * @code +void activateRunner() +{ + auto r = new MyRunner(parent); + r->setEnabled(); +} + * @endcode + * + * The desktop file would get the matching entries: + * @code +X-Plasma-API=DBus +X-Plasma-DBusRunner-Service=org.example.myrunner +X-Plasma-DBusRunner-Path=/myrunner + * @endcode + */ +class KDBUSRUNNER_EXPORT AbstractRunner : public QObject +{ + Q_OBJECT + +public: + /** + * @param dBusObjectPath D-Bus object path to register the runner object at + * @param dBusServiceName D-Bus service name to register, if empty none will be registered + * @param parent optional QObject parent taking ownership + */ + explicit AbstractRunner(const QString& dBusObjectPath, const QString& dBusServiceName = QString(), QObject* parent = nullptr); + ~AbstractRunner() override; + +public: // API to implement + /** + * Returns a list of descriptions for additional actions possible + * on the matched object. + * + * Default implementation returns an empty list. + * + * @return list of action descriptions + */ + virtual Actions actions(); // TODO: const? async ever needed? + + /** + * Starts the matching. + * For sync processing addMatches() and finishMatching() can be called directly + * in the implementation of this method. + */ + virtual void startMatching(const QString &queryTerm) = 0; + + /** + * Called whenever an exact or possible match associated with this + * runner is triggered. + * + * @param id The context in which the match is triggered, i.e. for which + * the match was created. + * @param actionId The actual match to run/execute. + */ + virtual void run(const QString &id, const QString &actionId) = 0; + + bool isMatching() const; + + bool isEnabled() const; + + void virtual_hook(int id, void *data); +public Q_SLOTS: + void addMatches(const QueryMatches& matches); + void cancelMatching(); + void finishMatching(); // TODO: or use bool done/moreToCome flag in addMatches? + + void setEnabled(bool enabled = true); + + +Q_SIGNALS: + void matchingCancelled(); + +private: + const QScopedPointer d; +}; + +} diff --git a/src/dbusrunner/abstractrunner.cpp b/src/dbusrunner/abstractrunner.cpp new file mode 100644 --- /dev/null +++ b/src/dbusrunner/abstractrunner.cpp @@ -0,0 +1,66 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#include "abstractrunner.h" +#include "abstractrunner_p.h" + +using namespace KDBusRunner; + +AbstractRunner::AbstractRunner(const QString& dBusObjectPath, const QString& dBusServiceName, QObject* parent) + : QObject(parent) + , d(new AbstractRunnerPrivate(dBusObjectPath, dBusServiceName, this)) +{ +} + +AbstractRunner::~AbstractRunner() = default; + + +void AbstractRunner::setEnabled(bool enabled) +{ + d->setEnabled(enabled); +} + +bool AbstractRunner::isEnabled() const +{ + return d->isEnabled(); +} + +void AbstractRunner::addMatches(const QueryMatches& matches) +{ + d->addMatches(matches); +} + +void AbstractRunner::cancelMatching() +{ + d->cancelMatching(); +} + +void AbstractRunner::finishMatching() +{ + d->finishMatching(); +} + +bool AbstractRunner::isMatching() const +{ + return d->isMatching(); +} + +Actions AbstractRunner::actions() +{ + return {}; +} diff --git a/src/dbusrunner/abstractrunner_p.h b/src/dbusrunner/abstractrunner_p.h new file mode 100644 --- /dev/null +++ b/src/dbusrunner/abstractrunner_p.h @@ -0,0 +1,65 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#pragma once + +#include "abstractrunner.h" +// Qt +#include +#include + +namespace KDBusRunner +{ + +class AbstractRunnerPrivate : public QObject, protected QDBusContext +{ + Q_OBJECT + +public: + explicit AbstractRunnerPrivate(const QString& dBusObjectPath, const QString& dBusServiceName, + AbstractRunner* parent); + ~AbstractRunnerPrivate() override; + +public: + Actions actions(); + QueryMatches match(const QString &queryTerm); + void run(const QString &id, const QString &actionId); + + void addMatches(const QueryMatches& matches); + void cancelMatching(); + void finishMatching(); + bool isMatching() const; + + void setEnabled(bool enabled); + bool isEnabled() const; + +private: + AbstractRunner * const q; + + QString mDBusObjectPath; + QString mDBusServiceName; + + QDBusMessage mLastMatchDBusMessage; + QueryMatches mMatches; +}; + +inline bool AbstractRunnerPrivate::isMatching() const { return mLastMatchDBusMessage.type() == QDBusMessage::MethodCallMessage; } + +inline void AbstractRunnerPrivate::addMatches(const QueryMatches& matches) { mMatches += matches; } + +} diff --git a/src/dbusrunner/abstractrunner_p.cpp b/src/dbusrunner/abstractrunner_p.cpp new file mode 100644 --- /dev/null +++ b/src/dbusrunner/abstractrunner_p.cpp @@ -0,0 +1,180 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#include "abstractrunner_p.h" + +// lib +#include "dbusadaptor_p.h" +// Qr +#include +#include +#include + +using namespace KDBusRunner; + + +inline QDBusArgument &operator<<(QDBusArgument &argument, const QueryMatch &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, QueryMatch &match) +{ + argument.beginStructure(); + argument >> match.id; + argument >> match.text; + argument >> match.iconName; + uint type; + argument >> type; + match.type = static_cast(type); + argument >> match.relevance; + argument >> match.properties; + argument.endStructure(); + + return argument; +} + +inline QDBusArgument &operator<< (QDBusArgument &argument, const Action &action) +{ + argument.beginStructure(); + argument << action.id; + argument << action.text; + argument << action.iconName; + argument.endStructure(); + return argument; +} + +inline const QDBusArgument &operator>>(const QDBusArgument &argument, Action &action) { + argument.beginStructure(); + argument >> action.id; + argument >> action.text; + argument >> action.iconName; + argument.endStructure(); + return argument; +} + + +AbstractRunnerPrivate::AbstractRunnerPrivate(const QString& dBusObjectPath, const QString& dBusServiceName, + AbstractRunner* parent) + : QObject(parent) + , q(parent) + , mDBusObjectPath(dBusObjectPath) + , mDBusServiceName(dBusServiceName) +{ + new DBusRunner1Adaptor(this); + + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); +} + +AbstractRunnerPrivate::~AbstractRunnerPrivate() = default; + +void AbstractRunnerPrivate::setEnabled(bool enabled) +{ + const bool isCurrentlyEnabled = isEnabled(); + if (enabled == isCurrentlyEnabled) { + return; + } + + if (enabled) { + QDBusConnection::sessionBus().registerObject(mDBusObjectPath, this); + if (!mDBusServiceName.isEmpty()) { + QDBusConnection::sessionBus().registerService(mDBusServiceName); + } + } else { + cancelMatching(); + if (!mDBusServiceName.isEmpty()) { + QDBusConnection::sessionBus().unregisterService(mDBusServiceName); + } + QDBusConnection::sessionBus().unregisterObject(mDBusObjectPath); + } +} + +bool AbstractRunnerPrivate::isEnabled() const +{ + return (QDBusConnection::sessionBus().objectRegisteredAt(mDBusObjectPath) == this); +} + +Actions AbstractRunnerPrivate::actions() +{ + return q->actions(); +} + +void AbstractRunnerPrivate::cancelMatching() +{ + if (!isMatching()) { + return; + } + + mMatches.clear(); + QDBusConnection::sessionBus().send(mLastMatchDBusMessage.createReply(QVariantList())); + + emit q->matchingCancelled(); +} + +void AbstractRunnerPrivate::finishMatching() +{ + if (!isMatching()) { + return; + } + + QDBusConnection::sessionBus().send(mLastMatchDBusMessage.createReply(QVariant::fromValue(mMatches))); + + mLastMatchDBusMessage = QDBusMessage(); + mMatches.clear(); +} + +QueryMatches AbstractRunnerPrivate::match(const QString& queryTerm) +{ + // new match request while old still processed? cancel + cancelMatching(); + + // prepare new round of matching + mMatches.clear(); + + // trigger match collection + q->startMatching(queryTerm); + + QueryMatches result; + + // not yet finished sync? + if (isMatching()) { + setDelayedReply(true); + mLastMatchDBusMessage = message(); + } else { + result = mMatches; + mMatches.clear(); + } + + return result; +} + +void AbstractRunnerPrivate::run(const QString& id, const QString& actionId) +{ + q->run(id, actionId); +} diff --git a/src/dbusrunner/action.h b/src/dbusrunner/action.h new file mode 100644 --- /dev/null +++ b/src/dbusrunner/action.h @@ -0,0 +1,47 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#pragma once + +#include "kdbusrunner_export.h" + +#include +#include + +namespace KDBusRunner +{ + +/** + * @class Action action.h + * + * @short An action for KRunner D-Bus plugins + */ +struct KDBUSRUNNER_EXPORT Action +{ + QString id; + QString text; + QString iconName; +}; + +typedef QVector Actions; + +} + +Q_DECLARE_TYPEINFO(KDBusRunner::Action, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(KDBusRunner::Action); +Q_DECLARE_METATYPE(KDBusRunner::Actions); diff --git a/src/dbusrunner/dbusadaptor.cpp b/src/dbusrunner/dbusadaptor.cpp new file mode 100644 --- /dev/null +++ b/src/dbusrunner/dbusadaptor.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#include "dbusadaptor_p.h" + + +using namespace KDBusRunner; + +DBusRunner1Adaptor::DBusRunner1Adaptor(AbstractRunnerPrivate* parent) + : QDBusAbstractAdaptor(parent) +{ +} + +DBusRunner1Adaptor::~DBusRunner1Adaptor() = default; + +KDBusRunner::QueryMatches DBusRunner1Adaptor::Match(const QString &query) +{ + return parent()->match(query); +} + +void DBusRunner1Adaptor::Run(const QString &matchId, const QString &actionId) +{ + parent()->run(matchId, actionId); +} + +KDBusRunner::Actions DBusRunner1Adaptor::Actions() +{ + return parent()->actions(); +} diff --git a/src/dbusrunner/dbusadaptor_p.h b/src/dbusrunner/dbusadaptor_p.h new file mode 100644 --- /dev/null +++ b/src/dbusrunner/dbusadaptor_p.h @@ -0,0 +1,62 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#pragma once + +#include "abstractrunner_p.h" +// Qt +#include + +namespace KDBusRunner +{ + +/* + * Adaptor class for interface org.kde.krunner1 + */ +class DBusRunner1Adaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.krunner1") + Q_CLASSINFO("D-Bus Introspection", "" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + explicit DBusRunner1Adaptor(AbstractRunnerPrivate* parent); + ~DBusRunner1Adaptor() override; + + inline AbstractRunnerPrivate* parent() const { return static_cast(QObject::parent()); } + +public Q_SLOTS: + KDBusRunner::QueryMatches Match(const QString &query); + void Run(const QString &matchId, const QString &actionId); + KDBusRunner::Actions Actions(); +}; + +} diff --git a/src/dbusrunner/querymatch.h b/src/dbusrunner/querymatch.h new file mode 100644 --- /dev/null +++ b/src/dbusrunner/querymatch.h @@ -0,0 +1,100 @@ +/* + * Copyright 2018 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#pragma once + +#include "kdbusrunner_export.h" + +#include +#include +#include + +namespace KDBusRunner +{ + +/** + * @class QueryMatch querymatch.h + * + * @short A match returned by an AbstractRunner in response to a given query. + */ +struct KDBUSRUNNER_EXPORT QueryMatch +{ + /** + * The type of match. Value is important here as it is used for sorting + * @internal Needs to match KRunner::QueryMatch::Type. + */ + enum Type : quint32 { + NoMatch = 0, /**< Null match */ + CompletionMatch = 10, /**< Possible completion for the data of the query */ + PossibleMatch = 30, /**< Something that may match the query */ + InformationalMatch = 50, /**< A purely informational, non-actionable match, + such as the answer to a question or calculation*/ + HelperMatch = 70, /**< A match that represents an action not directly related + to activating the given search term, such as a search + in an external tool or a command learning trigger. Helper + matches tend to be generic to the query and should not + be autoactivated just because the user hits "Enter" + while typing. They must be explicitly selected to + be activated, but unlike InformationalMatch cause + an action to be triggered. */ + ExactMatch = 100 /**< An exact match to the query */ + }; + + QueryMatch() : type(NoMatch), relevance(0) {} + QueryMatch(const QString& id, const QString& text, const QString& iconName, + QueryMatch::Type type, qreal relevance, const QVariantMap& properties) + : id(id), text(text), iconName(iconName), + type(type), relevance(relevance), properties(properties) + {} + + //sssuda{sv} + /** + * A string that can be used as an ID for this match, + * even between different queries. It is based in part + * on the source of the match (the AbstractRunner) and + * distinguishing information provided by the runner, + * ensuring global uniqueness as well as consistency + * between query matches. + */ + QString id; + /** + * The title text for this match + */ + QString text; + /** + * The name of the icon for this match + */ + QString iconName; + /** + * The type of match + */ + Type type; + /** + * The relevance of this action to the search. A number between 0 and 1. + */ + qreal relevance; + QVariantMap properties; +}; + +typedef QVector QueryMatches; + +} + +Q_DECLARE_TYPEINFO(KDBusRunner::QueryMatch, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(KDBusRunner::QueryMatch); +Q_DECLARE_METATYPE(KDBusRunner::QueryMatches); diff --git a/src/querymatch.h b/src/querymatch.h --- a/src/querymatch.h +++ b/src/querymatch.h @@ -50,6 +50,7 @@ public: /** * The type of match. Value is important here as it is used for sorting + * @internal Needs to match KDBusRunner::QueryMatch::Type. */ enum Type { NoMatch = 0, /**< Null match */