diff options
author | Robert Griebl <robert.griebl@qt.io> | 2022-08-18 22:17:40 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2022-09-16 13:15:05 +0200 |
commit | ff7a6b71093d5b7c007eee0af998daffcc0504e1 (patch) | |
tree | 821ecb2c4723dd88d15bc7ea0442341469df2b11 /src/tools/controller/controller.cpp | |
parent | 22929f522153d66187e4cb930b71a11c0b4166c6 (diff) | |
download | qtapplicationmanager-ff7a6b71093d5b7c007eee0af998daffcc0504e1.tar.gz |
Intents: allow intent injection via DBus when in developmentMode
This makes testing and debugging Intents a lot easier, especially
since you can even fake the requesting application id.
Change-Id: Ie5d46bd2e3a9962ca533bf75d7262c20f95d42b6
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Diffstat (limited to 'src/tools/controller/controller.cpp')
-rw-r--r-- | src/tools/controller/controller.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/tools/controller/controller.cpp b/src/tools/controller/controller.cpp index 2fade30d..f7a5bc87 100644 --- a/src/tools/controller/controller.cpp +++ b/src/tools/controller/controller.cpp @@ -131,6 +131,7 @@ enum Command { ListInstallationLocations, ShowInstallationLocation, ListInstances, + InjectIntentRequest, }; // REMEMBER to update the completion file util/bash/appman-prompt, if you apply changes below! @@ -154,6 +155,7 @@ static struct { { ListInstallationLocations, "list-installation-locations", "List all installaton locations." }, { ShowInstallationLocation, "show-installation-location", "Show details for installation location." }, { ListInstances, "list-instances", "List all named application manager instances." }, + { InjectIntentRequest, "inject-intent-request", "Inject an intent request for testing." }, }; static Command command(QCommandLineParser &clp) @@ -188,6 +190,10 @@ static void cancelInstallationTask(bool all, const QString &taskId) Q_DECL_NOEXC static void listInstallationLocations() Q_DECL_NOEXCEPT_EXPR(false); static void showInstallationLocation(bool asJson = false) Q_DECL_NOEXCEPT_EXPR(false); static void listInstances() Q_DECL_NOEXCEPT_EXPR(false); +static void injectIntentRequest(const QString &intentId, bool isBroadcast, + const QString &applicationId, const QString &requestingApplicationId, + const QString &jsonParameters) Q_DECL_NOEXCEPT_EXPR(false); + class ThrowingApplication : public QCoreApplication // clazy:exclude=missing-qobject-macro { @@ -470,6 +476,32 @@ int main(int argc, char *argv[]) clp.process(a); a.runLater(listInstances); break; + + case InjectIntentRequest: + clp.addPositionalArgument(qSL("intent-id"), qSL("The id of the intent.")); + clp.addPositionalArgument(qSL("parameters"), qSL("The optional parameters for this request."), qSL("[json-parameters]")); + clp.addOption({ qSL("requesting-application-id"), qSL("Fake the requesting application id."), qSL("id"), qSL(":sysui:") }); + clp.addOption({ qSL("application-id"), qSL("Specify the handling application id."), qSL("id") }); + clp.addOption({ qSL("broadcast"), qSL("Create a broadcast request.") }); + clp.process(a); + + bool isBroadcast = clp.isSet(qSL("broadcast")); + QString appId = clp.value(qSL("application-id")); + QString requestingAppId = clp.value(qSL("requesting-application-id")); + + if (!appId.isEmpty() && isBroadcast) + throw Exception("You cannot use --application-id and --broadcast at the same time."); + + if (clp.positionalArguments().size() > 3) + clp.showHelp(1); + + QString jsonParams; + if (clp.positionalArguments().size() == 3) + jsonParams = clp.positionalArguments().at(2); + + a.runLater(std::bind(injectIntentRequest, clp.positionalArguments().at(1), + isBroadcast, requestingAppId, appId, jsonParams)); + break; } int result = a.exec(); @@ -912,3 +944,31 @@ void listInstances() } qApp->quit(); } + +void injectIntentRequest(const QString &intentId, bool isBroadcast, + const QString &requestingApplicationId, const QString &applicationId, + const QString &jsonParameters) Q_DECL_NOEXCEPT_EXPR(false) +{ + dbus.connectToManager(); + + if (isBroadcast) { + auto reply = dbus.manager()->broadcastIntentRequestAs(requestingApplicationId, + intentId, + jsonParameters); + reply.waitForFinished(); + if (reply.isError()) + throw Exception(Error::IO, "failed to call broadcastIntentRequest via DBus: %1").arg(reply.error().message()); + } else { + auto reply = dbus.manager()->sendIntentRequestAs(requestingApplicationId, + intentId, + applicationId, + jsonParameters); + reply.waitForFinished(); + if (reply.isError()) + throw Exception(Error::IO, "failed to call sendIntentRequest via DBus: %1").arg(reply.error().message()); + const auto jsonResult = reply.value(); + fprintf(stdout, "%s\n", qPrintable(jsonResult)); + } + + qApp->quit(); +} |