Commit 167bbb6d authored by Victor Nikulshin's avatar Victor Nikulshin Committed by Guillaume Roguez

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
parent e7221edf
[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
......
......@@ -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*/
......
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