From 167bbb6d6a78bd7c8ce747b9fe71ab7925d2ef04 Mon Sep 17 00:00:00 2001 From: Victor Nikulshin <viktor.nikulshin@savoirfairelinux.com> Date: Wed, 15 Mar 2017 20:44:27 +0000 Subject: [PATCH] Call Ring ID accepted as command line argument Allows gnome-ring to accept as the first command-line argument and automatically call a target RingID in the form of 'ring' URI scheme: "ring:[0-9a-z]{40}". It is possible to use filename and URI parsing capabilities of GTK applications to extract RingID from command-line argument if it is provided. This patch implements the 'open' hook of the GTK-application, as recommended by GTK documentation, to correctly communicate data between multiple running instance of the application. By doing this, the following behavior is achieved: 1. If gnome-ring is not yet running and it is invoked with a command-line argument, a new application instance will be initialized and will start a new call at once. 2. If gnome-ring is already running, the 'open' event with the RingID will be dispatched to the primary application instance and make it start a new call. = Testing the patch Apply the patch, recompile gnome-ring and execute it with the command-line argument in the Ring URI-scheme format: gnome-ring 'ring:0000000000000000000000000000000000000000' = Expected behaviour The main application window will appear and automatically start a call to the destination RingID. [GR: fix ci msg line lenght (limit to 72)] [GR: fix naked raw ptr and build warnings] Change-Id: I109f118fb4765e764dc399486091e456ef19117e Tuleap: #1539 --- gnome-ring.desktop | 2 +- src/ring_client.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gnome-ring.desktop b/gnome-ring.desktop index 12d44186..92688e12 100644 --- a/gnome-ring.desktop +++ b/gnome-ring.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Name=Ring Comment=Ring is a secured and distributed communication software. -Exec=gnome-ring +Exec=gnome-ring %u Icon=ring StartupNotify=true Terminal=false diff --git a/src/ring_client.cpp b/src/ring_client.cpp index 9bc3470f..28f48b06 100644 --- a/src/ring_client.cpp +++ b/src/ring_client.cpp @@ -21,6 +21,7 @@ // system #include <memory> +#include <regex> // GTK+ related #include <gtk/gtk.h> @@ -66,6 +67,7 @@ #include "utils/files.h" #include "revision.h" #include "utils/accounts.h" +#include "utils/calling.h" #if HAVE_APPINDICATOR #include <libappindicator/app-indicator.h> @@ -387,6 +389,25 @@ ring_client_activate(GApplication *app) } } +static void +ring_client_open(GApplication *app, GFile **file, gint /*arg3*/, const gchar* /*arg4*/) +{ + ring_client_activate(app); + + if (strcmp(g_file_get_uri_scheme(*file), "ring") == 0) { + const char * call_id = g_file_get_basename(*file); + std::regex format {"^[[:xdigit:]]{40}$"}; + + if (std::regex_match(call_id, format)) { + auto cm = std::unique_ptr<TemporaryContactMethod>(new TemporaryContactMethod); + cm->setUri(URI(QString::fromStdString(call_id))); + + place_new_call(cm.get()); + cm.release(); + } + } +} + #if USE_LIBNM static void @@ -686,6 +707,7 @@ ring_client_class_init(RingClientClass *klass) { G_APPLICATION_CLASS(klass)->startup = ring_client_startup; G_APPLICATION_CLASS(klass)->activate = ring_client_activate; + G_APPLICATION_CLASS(klass)->open = ring_client_open; G_APPLICATION_CLASS(klass)->shutdown = ring_client_shutdown; } @@ -694,6 +716,7 @@ ring_client_new(int argc, char *argv[]) { RingClient *client = (RingClient *)g_object_new(ring_client_get_type(), "application-id", RING_CLIENT_APP_ID, + "flags", G_APPLICATION_HANDLES_OPEN , NULL); /* copy the cmd line args before they get processed by the GApplication*/ -- GitLab