1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-12-13 16:07:36 +00:00

application: Reuse existing functions in app.dial action

For that we must move open_sip_uri() and open_tel_uri() up to avoid having to
add forward declarations.

Fixes #402
This commit is contained in:
Evangelos Ribeiro Tzaras 2022-02-12 23:47:47 +01:00
parent 006673a9e1
commit 6e7984cb5d

View file

@ -283,6 +283,51 @@ call_number (CallsApplication *self,
}
static void
open_sip_uri (CallsApplication *self,
const char *uri)
{
g_auto (GStrv) tokens = NULL;
g_assert (uri);
tokens = g_strsplit (uri, "///", 2);
if (g_strv_length (tokens) == 2) {
/* Remove "///" from "sip:///user@host" */
g_autofree char *dial_string = g_strconcat (tokens[0], tokens[1], NULL);
calls_main_window_dial (self->main_window, dial_string);
} else {
/* Dial the uri as it is */
calls_main_window_dial (self->main_window, uri);
}
}
static void
open_tel_uri (CallsApplication *self,
const char *uri)
{
const char *number = NULL;
g_debug ("Opening tel URI `%s'", uri);
number = &uri[4]; // tel:NUMBER
if (!number || !*number) {
g_autofree char *msg =
g_strdup_printf (_("Tried dialing invalid tel URI `%s'"), uri);
calls_message_source_emit_message (CALLS_MESSAGE_SOURCE (calls_manager_get_default ()),
"msg",
GTK_MESSAGE_WARNING);
g_warning ("Ignoring invalid tel URI `%s'", uri);
return;
}
call_number (self, number);
}
static void
dial_action (GSimpleAction *action,
GVariant *parameter,
@ -294,7 +339,13 @@ dial_action (GSimpleAction *action,
number = g_variant_get_string (parameter, NULL);
g_return_if_fail (number != NULL);
call_number (self, number);
if (g_str_has_prefix (number, "sip:") ||
g_str_has_prefix (number, "sips:"))
open_sip_uri (self, number);
else if (g_str_has_prefix (number, "tel:"))
open_tel_uri (self, number);
else
call_number (self, number);
}
static void
@ -514,51 +565,6 @@ start_proper (CallsApplication *self)
return TRUE;
}
static void
open_sip_uri (CallsApplication *self,
const char *uri)
{
char **tokens = NULL;
g_assert (uri);
tokens = g_strsplit (uri, "///", 2);
if (tokens) {
/* Remove "///" from "sip:///user@host" */
g_autofree char *dial_string = g_strconcat (tokens[0], tokens[1], NULL);
calls_main_window_dial (self->main_window, dial_string);
g_strfreev (tokens);
} else {
/* Dial the uri as it is */
calls_main_window_dial (self->main_window, uri);
}
}
static void
open_tel_uri (CallsApplication *self,
const char *uri)
{
const char *number = NULL;
g_debug ("Opening tel URI `%s'", uri);
number = &uri[4]; // tel:NUMBER
if (!number || !*number) {
g_autofree char *msg =
g_strdup_printf (_("Tried dialing invalid tel URI `%s'"), uri);
calls_message_source_emit_message (CALLS_MESSAGE_SOURCE (calls_manager_get_default ()),
"msg",
GTK_MESSAGE_WARNING);
g_warning ("Ignoring invalid tel URI `%s'", uri);
return;
}
call_number (self, number);
}
static void
activate (GApplication *application)
{