mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-12 07:37:35 +00:00
codestyle: application
This commit is contained in:
parent
e5dc3f06ce
commit
9a4debe87e
1 changed files with 119 additions and 144 deletions
|
@ -78,41 +78,35 @@ handle_local_options (GApplication *application,
|
|||
{
|
||||
gboolean ok;
|
||||
g_autoptr (GError) error = NULL;
|
||||
const gchar *arg;
|
||||
const char *arg;
|
||||
|
||||
g_debug ("Registering application");
|
||||
ok = g_application_register (application, NULL, &error);
|
||||
if (!ok)
|
||||
{
|
||||
if (!ok) {
|
||||
g_error ("Error registering application: %s",
|
||||
error->message);
|
||||
}
|
||||
|
||||
ok = g_variant_dict_lookup (options, "provider", "&s", &arg);
|
||||
if (ok)
|
||||
{
|
||||
if (ok) {
|
||||
g_action_group_activate_action (G_ACTION_GROUP (application),
|
||||
"set-provider-name",
|
||||
g_variant_new_string (arg));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
g_action_group_activate_action (G_ACTION_GROUP (application),
|
||||
"set-provider-name",
|
||||
g_variant_new_string (DEFAULT_PROVIDER_PLUGIN));
|
||||
}
|
||||
|
||||
ok = g_variant_dict_contains (options, "daemon");
|
||||
if (ok)
|
||||
{
|
||||
if (ok) {
|
||||
g_action_group_activate_action (G_ACTION_GROUP (application),
|
||||
"set-daemon",
|
||||
NULL);
|
||||
}
|
||||
|
||||
ok = g_variant_dict_lookup (options, "dial", "&s", &arg);
|
||||
if (ok)
|
||||
{
|
||||
if (ok) {
|
||||
g_action_group_activate_action (G_ACTION_GROUP (application),
|
||||
"dial",
|
||||
g_variant_new_string (arg));
|
||||
|
@ -127,15 +121,14 @@ set_provider_name_action (GSimpleAction *action,
|
|||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
const gchar *name;
|
||||
const char *name;
|
||||
|
||||
name = g_variant_get_string (parameter, NULL);
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
/* FIXME: allow to set a new provider, we need to make sure that the
|
||||
provider is unloaded correctly from the CallsManager */
|
||||
if (calls_manager_get_provider (calls_manager_get_default ()) != NULL)
|
||||
{
|
||||
if (calls_manager_get_provider (calls_manager_get_default ()) != NULL) {
|
||||
g_warning ("Cannot set provider name to `%s'"
|
||||
" because provider is already created",
|
||||
name);
|
||||
|
@ -154,8 +147,7 @@ set_daemon_action (GSimpleAction *action,
|
|||
{
|
||||
CallsApplication *self = CALLS_APPLICATION (user_data);
|
||||
|
||||
if (self->main_window)
|
||||
{
|
||||
if (self->main_window) {
|
||||
g_warning ("Cannot set application as a daemon"
|
||||
" because application is already started");
|
||||
return;
|
||||
|
@ -174,14 +166,13 @@ set_daemon_action (GSimpleAction *action,
|
|||
#define VISUAL_RE "[" VISUAL "]"
|
||||
|
||||
static gboolean
|
||||
check_dial_number (const gchar *number)
|
||||
check_dial_number (const char *number)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autoptr (GRegex) reject = g_regex_new (REJECT_RE, 0, 0, &error);
|
||||
gboolean matches;
|
||||
|
||||
if (!reject)
|
||||
{
|
||||
if (!reject) {
|
||||
g_warning ("Could not compile regex for"
|
||||
" dial number checking: %s",
|
||||
error->message);
|
||||
|
@ -194,15 +185,14 @@ check_dial_number (const gchar *number)
|
|||
}
|
||||
|
||||
|
||||
static gchar *
|
||||
extract_dial_string (const gchar *number)
|
||||
static char *
|
||||
extract_dial_string (const char *number)
|
||||
{
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autoptr (GRegex) replace_visual = g_regex_new (VISUAL_RE, 0, 0, &error);
|
||||
gchar *dial_string;
|
||||
char *dial_string;
|
||||
|
||||
if (!replace_visual)
|
||||
{
|
||||
if (!replace_visual) {
|
||||
g_warning ("Could not compile regex for"
|
||||
" dial number extracting: %s",
|
||||
error->message);
|
||||
|
@ -212,8 +202,7 @@ extract_dial_string (const gchar *number)
|
|||
dial_string = g_regex_replace_literal
|
||||
(replace_visual, number, -1, 0, "", 0, &error);
|
||||
|
||||
if (!dial_string)
|
||||
{
|
||||
if (!dial_string) {
|
||||
g_warning ("Error replacing visual separators"
|
||||
" in dial number: %s",
|
||||
error->message);
|
||||
|
@ -230,9 +219,9 @@ dial_action (GSimpleAction *action,
|
|||
gpointer user_data)
|
||||
{
|
||||
CallsApplication *self = CALLS_APPLICATION (user_data);
|
||||
const gchar *number;
|
||||
const char *number;
|
||||
gboolean number_ok;
|
||||
g_autofree gchar *dial_string = NULL;
|
||||
g_autofree char *dial_string = NULL;
|
||||
|
||||
number = g_variant_get_string (parameter, NULL);
|
||||
g_return_if_fail (number != NULL);
|
||||
|
@ -244,16 +233,14 @@ dial_action (GSimpleAction *action,
|
|||
}
|
||||
|
||||
number_ok = check_dial_number (number);
|
||||
if (!number_ok)
|
||||
{
|
||||
if (!number_ok) {
|
||||
g_warning ("Dial number `%s' is not a valid dial string",
|
||||
number);
|
||||
return;
|
||||
}
|
||||
|
||||
dial_string = extract_dial_string (number);
|
||||
if (!dial_string)
|
||||
{
|
||||
if (!dial_string) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -272,7 +259,7 @@ copy_number (GSimpleAction *action,
|
|||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
const gchar *number = g_variant_get_string (parameter, NULL);
|
||||
const char *number = g_variant_get_string (parameter, NULL);
|
||||
GtkClipboard *clipboard =
|
||||
gtk_clipboard_get_default (gdk_display_get_default ());
|
||||
|
||||
|
@ -358,8 +345,7 @@ start_proper (CallsApplication *self)
|
|||
{
|
||||
GtkApplication *gtk_app;
|
||||
|
||||
if (self->main_window)
|
||||
{
|
||||
if (self->main_window) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -392,22 +378,21 @@ start_proper (CallsApplication *self)
|
|||
|
||||
static void
|
||||
open_sip_uri (CallsApplication *self,
|
||||
const gchar *uri)
|
||||
const char *uri)
|
||||
{
|
||||
gchar **tokens = NULL;
|
||||
char **tokens = NULL;
|
||||
g_assert (uri);
|
||||
|
||||
tokens = g_strsplit (uri, "///", 2);
|
||||
|
||||
if (tokens) {
|
||||
/* Remove "///" from "sip:///user@host" */
|
||||
g_autofree gchar *dial_string = g_strconcat (tokens[0], tokens[1], NULL);
|
||||
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 {
|
||||
} else {
|
||||
/* Dial the uri as it is */
|
||||
calls_main_window_dial (self->main_window, uri);
|
||||
}
|
||||
|
@ -415,12 +400,12 @@ open_sip_uri (CallsApplication *self,
|
|||
|
||||
static void
|
||||
open_tel_uri (CallsApplication *self,
|
||||
const gchar *uri)
|
||||
const char *uri)
|
||||
{
|
||||
g_autoptr (EPhoneNumber) number = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autofree gchar *dial_str = NULL;
|
||||
g_autofree gchar *country_code = NULL;
|
||||
g_autofree char *dial_str = NULL;
|
||||
g_autofree char *country_code = NULL;
|
||||
|
||||
g_object_get (calls_manager_get_default (),
|
||||
"country-code", &country_code,
|
||||
|
@ -429,9 +414,8 @@ open_tel_uri (CallsApplication *self,
|
|||
g_debug ("Opening tel URI `%s'", uri);
|
||||
|
||||
number = e_phone_number_from_string (uri, country_code, &error);
|
||||
if (!number)
|
||||
{
|
||||
g_autofree gchar *msg =
|
||||
if (!number) {
|
||||
g_autofree char *msg =
|
||||
g_strdup_printf (_("Tried dialing unparsable tel URI `%s'"), uri);
|
||||
|
||||
g_signal_emit_by_name (calls_manager_get_default (),
|
||||
|
@ -457,28 +441,21 @@ activate (GApplication *application)
|
|||
|
||||
g_debug ("Activated");
|
||||
|
||||
if (self->main_window)
|
||||
{
|
||||
if (self->main_window) {
|
||||
present = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
gboolean ok = start_proper (self);
|
||||
if (!ok)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
present = !self->daemon;
|
||||
}
|
||||
|
||||
if (present || self->uri)
|
||||
{
|
||||
if (present || self->uri) {
|
||||
gtk_window_present (GTK_WINDOW (self->main_window));
|
||||
}
|
||||
|
||||
if (self->uri)
|
||||
{
|
||||
if (self->uri) {
|
||||
if (g_str_has_prefix (self->uri, "tel:"))
|
||||
open_tel_uri (self, self->uri);
|
||||
|
||||
|
@ -494,7 +471,7 @@ static void
|
|||
app_open (GApplication *application,
|
||||
GFile **files,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
const char *hint)
|
||||
{
|
||||
CallsApplication *self = CALLS_APPLICATION (application);
|
||||
|
||||
|
@ -505,16 +482,14 @@ app_open (GApplication *application,
|
|||
|
||||
if (g_file_has_uri_scheme (files[0], "tel") ||
|
||||
g_file_has_uri_scheme (files[0], "sip") ||
|
||||
g_file_has_uri_scheme (files[0], "sips"))
|
||||
{
|
||||
g_file_has_uri_scheme (files[0], "sips")) {
|
||||
|
||||
g_free (self->uri);
|
||||
self->uri = g_file_get_uri (files[0]);
|
||||
g_debug ("Opening %s", self->uri);
|
||||
|
||||
g_application_activate (application);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
g_autofree char *msg = NULL;
|
||||
g_autofree char *uri = NULL;
|
||||
|
||||
|
|
Loading…
Reference in a new issue