2021-07-05 09:55:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Purism SPC
|
|
|
|
*
|
|
|
|
* This file is part of Calls.
|
|
|
|
*
|
|
|
|
* Calls is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calls is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define G_LOG_DOMAIN "CallsSipAccountWidget"
|
|
|
|
|
|
|
|
#include "calls-sip-account-widget.h"
|
|
|
|
#include "calls-sip-provider.h"
|
|
|
|
#include "calls-sip-origin.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Section:calls-sip-account-widget
|
|
|
|
* short_description: A #GtkWidget to edit or add SIP accounts
|
|
|
|
* @Title: CallsSipAccountWidget
|
|
|
|
*
|
|
|
|
* This #GtkWidget allows the user to add a new or edit an existing SIP account.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_PROVIDER,
|
|
|
|
PROP_ORIGIN,
|
|
|
|
PROP_LAST_PROP
|
|
|
|
};
|
|
|
|
static GParamSpec *props[PROP_LAST_PROP];
|
|
|
|
|
|
|
|
|
|
|
|
struct _CallsSipAccountWidget {
|
|
|
|
GtkBox parent;
|
|
|
|
|
|
|
|
/* Header bar */
|
|
|
|
GtkWidget *header_add;
|
|
|
|
GtkSpinner *spinner_add;
|
|
|
|
GtkWidget *header_edit;
|
|
|
|
GtkSpinner *spinner_edit;
|
|
|
|
GtkWidget *login_btn;
|
|
|
|
GtkWidget *apply_btn;
|
|
|
|
GtkWidget *delete_btn;
|
|
|
|
|
|
|
|
/* widgets for editing account credentials */
|
|
|
|
GtkEntry *host;
|
|
|
|
GtkEntry *display_name;
|
|
|
|
GtkEntry *user;
|
|
|
|
GtkEntry *password;
|
|
|
|
GtkEntry *port;
|
2021-07-26 03:43:23 +00:00
|
|
|
char *last_port;
|
2021-07-05 09:55:44 +00:00
|
|
|
HdyComboRow *protocol;
|
|
|
|
GListStore *protocols_store; /* bound model for protocol HdyComboRow */
|
2021-10-21 09:17:40 +00:00
|
|
|
GtkSwitch *tel_switch;
|
2022-05-24 08:00:02 +00:00
|
|
|
GtkSwitch *auto_connect_switch;
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
CallsSipProvider *provider;
|
|
|
|
CallsSipOrigin *origin; /* nullable to add a new account */
|
|
|
|
|
|
|
|
/* misc */
|
|
|
|
gboolean connecting;
|
2021-07-26 03:43:23 +00:00
|
|
|
gboolean port_self_change;
|
2021-07-05 09:55:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (CallsSipAccountWidget, calls_sip_account_widget, GTK_TYPE_BOX)
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_form_valid (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
|
|
|
|
/* TODO perform some sanity checks */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_form_filled (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
|
|
|
|
return
|
2022-04-24 10:24:55 +00:00
|
|
|
g_strcmp0 (gtk_entry_get_text (self->host), "") != 0 &&
|
|
|
|
g_strcmp0 (gtk_entry_get_text (self->user), "") != 0 &&
|
|
|
|
g_strcmp0 (gtk_entry_get_text (self->password), "") != 0 &&
|
|
|
|
g_strcmp0 (gtk_entry_get_text (self->port), "") != 0;
|
2021-07-05 09:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-08-27 14:41:27 +00:00
|
|
|
on_user_changed (CallsSipAccountWidget *self)
|
2021-07-05 09:55:44 +00:00
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (self->login_btn,
|
|
|
|
is_form_filled (self) &&
|
|
|
|
is_form_valid (self));
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (self->apply_btn,
|
|
|
|
is_form_filled (self) &&
|
|
|
|
is_form_valid (self));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-27 19:17:27 +00:00
|
|
|
static void
|
|
|
|
set_password_visibility (CallsSipAccountWidget *self, gboolean visible)
|
|
|
|
{
|
2022-04-24 10:24:55 +00:00
|
|
|
const char *icon_name;
|
2022-02-27 19:17:27 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
g_assert (GTK_IS_ENTRY (self->password));
|
2022-02-27 19:17:27 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
icon_name = visible ?
|
|
|
|
"view-conceal-symbolic" :
|
|
|
|
"view-reveal-symbolic";
|
2022-02-27 19:17:27 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
gtk_entry_set_visibility (self->password, visible);
|
|
|
|
gtk_entry_set_icon_from_icon_name (self->password, GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
icon_name);
|
2022-02-27 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2022-04-24 10:24:55 +00:00
|
|
|
on_password_visibility_changed (CallsSipAccountWidget *self,
|
|
|
|
GtkEntryIconPosition icon_pos,
|
|
|
|
GdkEvent *event,
|
|
|
|
GtkEntry *entry)
|
2022-02-27 19:17:27 +00:00
|
|
|
{
|
2022-04-24 10:24:55 +00:00
|
|
|
gboolean visible;
|
2022-02-27 19:17:27 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
g_assert (GTK_IS_ENTRY (entry));
|
|
|
|
g_assert (icon_pos == GTK_ENTRY_ICON_SECONDARY);
|
2022-02-27 19:17:27 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
visible = !gtk_entry_get_visibility (entry);
|
|
|
|
set_password_visibility (self, visible);
|
2022-02-27 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 03:43:23 +00:00
|
|
|
/*
|
|
|
|
* Stop "insert-text" signal emission if any undesired port
|
|
|
|
* value occurs
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
on_port_entry_insert_text (CallsSipAccountWidget *self,
|
|
|
|
char *new_text,
|
|
|
|
int new_text_length,
|
|
|
|
gpointer position,
|
|
|
|
GtkEntry *entry)
|
|
|
|
{
|
|
|
|
size_t digit_end, len;
|
|
|
|
int *pos;
|
|
|
|
|
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
g_assert (GTK_IS_ENTRY (entry));
|
|
|
|
|
|
|
|
if (!new_text || !*new_text || self->port_self_change)
|
|
|
|
return;
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
pos = (int *) position;
|
2021-07-26 03:43:23 +00:00
|
|
|
g_object_set_data (G_OBJECT (entry), "old-pos", GINT_TO_POINTER (*pos));
|
|
|
|
|
|
|
|
if (new_text_length == -1)
|
|
|
|
len = strlen (new_text);
|
|
|
|
else
|
|
|
|
len = new_text_length;
|
|
|
|
|
|
|
|
digit_end = strspn (new_text, "1234567890");
|
|
|
|
|
|
|
|
/* If user inserted something other than a digit,
|
|
|
|
* stop inserting the text and warn the user.
|
|
|
|
*/
|
|
|
|
if (digit_end != len) {
|
|
|
|
g_signal_stop_emission_by_name (entry, "insert-text");
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (entry));
|
|
|
|
} else {
|
|
|
|
g_free (self->last_port);
|
|
|
|
self->last_port = g_strdup (gtk_entry_get_text (entry));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
update_port_cursor_position (GtkEntry *entry)
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry), "old-pos"));
|
|
|
|
gtk_editable_set_position (GTK_EDITABLE (entry), pos);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2021-08-27 16:32:37 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
get_port (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
int port = 0;
|
|
|
|
|
|
|
|
text = gtk_entry_get_text (self->port);
|
2022-04-24 10:24:55 +00:00
|
|
|
port = (int) g_ascii_strtod (text, NULL);
|
2021-08-27 16:32:37 +00:00
|
|
|
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 03:43:23 +00:00
|
|
|
static void
|
|
|
|
on_port_entry_after_insert_text (CallsSipAccountWidget *self,
|
|
|
|
char *new_text,
|
|
|
|
int new_text_length,
|
|
|
|
gpointer position,
|
|
|
|
GtkEntry *entry)
|
|
|
|
{
|
2021-08-27 16:32:37 +00:00
|
|
|
int port = get_port (self);
|
2021-07-26 03:43:23 +00:00
|
|
|
|
|
|
|
/* Reset to the old value if new port number is invalid */
|
|
|
|
if ((port < 0 || port > 65535) && self->last_port) {
|
|
|
|
self->port_self_change = TRUE;
|
|
|
|
gtk_entry_set_text (entry, self->last_port);
|
|
|
|
g_idle_add (G_SOURCE_FUNC (update_port_cursor_position), entry);
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (entry));
|
|
|
|
self->port_self_change = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-05 09:55:44 +00:00
|
|
|
static void
|
|
|
|
update_header (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
|
|
|
|
if (self->origin) {
|
|
|
|
gtk_widget_show (self->header_edit);
|
|
|
|
gtk_widget_hide (self->header_add);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
gtk_widget_show (self->header_add);
|
|
|
|
gtk_widget_hide (self->header_edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->connecting) {
|
|
|
|
gtk_spinner_start (self->spinner_add);
|
|
|
|
gtk_spinner_start (self->spinner_edit);
|
|
|
|
} else {
|
|
|
|
gtk_spinner_stop (self->spinner_add);
|
|
|
|
gtk_spinner_stop (self->spinner_edit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_protocol (CallsSipAccountWidget *self,
|
|
|
|
const char *protocol,
|
|
|
|
guint *index)
|
|
|
|
{
|
|
|
|
guint len;
|
2022-04-24 10:24:55 +00:00
|
|
|
|
2021-07-05 09:55:44 +00:00
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
|
|
|
|
len = g_list_model_get_n_items (G_LIST_MODEL (self->protocols_store));
|
|
|
|
for (guint i = 0; i < len; i++) {
|
|
|
|
g_autoptr (HdyValueObject) obj =
|
|
|
|
g_list_model_get_item (G_LIST_MODEL (self->protocols_store), i);
|
|
|
|
const char *prot = hdy_value_object_get_string (obj);
|
|
|
|
|
|
|
|
if (g_strcmp0 (protocol, prot) == 0) {
|
|
|
|
if (index)
|
|
|
|
*index = i;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-09 15:46:52 +00:00
|
|
|
g_warning ("Could not find protocol '%s'", protocol);
|
2021-07-05 09:55:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_form (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
|
|
|
|
gtk_entry_set_text (self->host, "");
|
|
|
|
gtk_entry_set_text (self->display_name, "");
|
|
|
|
gtk_entry_set_text (self->user, "");
|
|
|
|
gtk_entry_set_text (self->password, "");
|
|
|
|
gtk_entry_set_text (self->port, "0");
|
|
|
|
hdy_combo_row_set_selected_index (self->protocol, 0);
|
2021-10-21 09:17:40 +00:00
|
|
|
gtk_switch_set_state (self->tel_switch, FALSE);
|
2022-05-24 08:00:02 +00:00
|
|
|
gtk_switch_set_state (self->auto_connect_switch, TRUE);
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
self->origin = NULL;
|
|
|
|
|
|
|
|
update_header (self);
|
|
|
|
|
|
|
|
if (gtk_widget_get_can_focus (GTK_WIDGET (self->host)))
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (self->host));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
edit_form (CallsSipAccountWidget *self,
|
|
|
|
CallsSipOrigin *origin)
|
|
|
|
{
|
|
|
|
g_autofree char *host = NULL;
|
|
|
|
g_autofree char *display_name = NULL;
|
|
|
|
g_autofree char *user = NULL;
|
|
|
|
g_autofree char *password = NULL;
|
|
|
|
g_autofree char *port_str = NULL;
|
|
|
|
g_autofree char *protocol = NULL;
|
|
|
|
gint port;
|
|
|
|
guint protocol_index;
|
2021-10-21 09:17:40 +00:00
|
|
|
gboolean can_tel;
|
2022-05-24 08:00:02 +00:00
|
|
|
gboolean auto_connect;
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
g_assert (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
|
|
|
|
if (!origin) {
|
|
|
|
clear_form (self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (CALLS_IS_SIP_ORIGIN (origin));
|
|
|
|
|
|
|
|
self->origin = origin;
|
|
|
|
|
|
|
|
g_object_get (origin,
|
|
|
|
"host", &host,
|
|
|
|
"display-name", &display_name,
|
|
|
|
"user", &user,
|
|
|
|
"password", &password,
|
|
|
|
"port", &port,
|
|
|
|
"transport-protocol", &protocol,
|
2021-10-21 09:17:40 +00:00
|
|
|
"can-tel", &can_tel,
|
2022-05-24 08:00:02 +00:00
|
|
|
"auto-connect", &auto_connect,
|
2021-07-05 09:55:44 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
port_str = g_strdup_printf ("%d", port);
|
|
|
|
|
|
|
|
/* The following should always succeed,
|
|
|
|
TODO inform user in the error case
|
|
|
|
related issue #275 https://source.puri.sm/Librem5/calls/-/issues/275
|
2022-04-24 10:24:55 +00:00
|
|
|
*/
|
2021-07-05 09:55:44 +00:00
|
|
|
if (!find_protocol (self, protocol, &protocol_index))
|
|
|
|
protocol_index = 0;
|
|
|
|
|
|
|
|
/* set UI elements */
|
|
|
|
gtk_entry_set_text (self->host, host);
|
|
|
|
gtk_entry_set_text (self->display_name, display_name ?: "");
|
|
|
|
gtk_entry_set_text (self->user, user);
|
|
|
|
gtk_entry_set_text (self->password, password);
|
2022-02-27 19:17:27 +00:00
|
|
|
set_password_visibility (self, FALSE);
|
2021-07-05 09:55:44 +00:00
|
|
|
gtk_entry_set_text (self->port, port_str);
|
|
|
|
hdy_combo_row_set_selected_index (self->protocol, protocol_index);
|
2021-10-21 09:17:40 +00:00
|
|
|
gtk_switch_set_state (self->tel_switch, can_tel);
|
2022-05-24 08:00:02 +00:00
|
|
|
gtk_switch_set_state (self->auto_connect_switch, auto_connect);
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (self->apply_btn, FALSE);
|
|
|
|
|
|
|
|
update_header (self);
|
|
|
|
|
|
|
|
if (gtk_widget_get_can_focus (GTK_WIDGET (self->host)))
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (self->host));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-26 19:52:36 +00:00
|
|
|
static const char *
|
|
|
|
get_selected_protocol (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_autoptr (HdyValueObject) obj = NULL;
|
|
|
|
const char *protocol = NULL;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if ((i = hdy_combo_row_get_selected_index (self->protocol)) != -1) {
|
|
|
|
obj = g_list_model_get_item (G_LIST_MODEL (self->protocols_store), i);
|
|
|
|
protocol = hdy_value_object_get_string (obj);
|
|
|
|
}
|
|
|
|
return protocol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-05 09:55:44 +00:00
|
|
|
static void
|
|
|
|
on_login_clicked (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
CallsSipOrigin *origin;
|
2022-01-27 14:28:35 +00:00
|
|
|
g_autofree char *id = g_uuid_string_random ();
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
g_debug ("Logging into newly created account");
|
|
|
|
|
|
|
|
origin = calls_sip_provider_add_origin (self->provider,
|
2022-01-27 14:28:35 +00:00
|
|
|
id,
|
2021-07-05 09:55:44 +00:00
|
|
|
gtk_entry_get_text (GTK_ENTRY (self->host)),
|
|
|
|
gtk_entry_get_text (GTK_ENTRY (self->user)),
|
|
|
|
gtk_entry_get_text (GTK_ENTRY (self->password)),
|
|
|
|
gtk_entry_get_text (GTK_ENTRY (self->display_name)),
|
2021-08-26 19:52:36 +00:00
|
|
|
get_selected_protocol (self),
|
2021-08-27 16:32:37 +00:00
|
|
|
get_port (self),
|
2021-07-08 15:27:09 +00:00
|
|
|
TRUE);
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
self->origin = origin;
|
|
|
|
update_header (self);
|
2021-07-12 23:17:38 +00:00
|
|
|
g_signal_emit_by_name (self->provider, "widget-edit-done");
|
2021-07-05 09:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_delete_clicked (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_debug ("Deleting account");
|
|
|
|
|
|
|
|
calls_sip_provider_remove_origin (self->provider, self->origin);
|
|
|
|
self->origin = NULL;
|
|
|
|
|
|
|
|
update_header (self);
|
2021-07-12 23:17:38 +00:00
|
|
|
g_signal_emit_by_name (self->provider, "widget-edit-done");
|
2021-07-05 09:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_apply_clicked (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_debug ("Applying changes to the account");
|
|
|
|
|
|
|
|
calls_sip_origin_set_credentials (self->origin,
|
|
|
|
gtk_entry_get_text (self->host),
|
|
|
|
gtk_entry_get_text (self->user),
|
|
|
|
gtk_entry_get_text (self->password),
|
|
|
|
gtk_entry_get_text (self->display_name),
|
2021-08-26 19:52:36 +00:00
|
|
|
get_selected_protocol (self),
|
2021-08-27 16:32:37 +00:00
|
|
|
get_port (self),
|
2021-10-21 09:17:40 +00:00
|
|
|
gtk_switch_get_state (self->tel_switch),
|
2022-05-24 08:00:02 +00:00
|
|
|
gtk_switch_get_state (self->auto_connect_switch));
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
update_header (self);
|
2021-08-27 08:10:23 +00:00
|
|
|
calls_sip_provider_save_accounts_to_disk (self->provider);
|
2021-07-12 23:17:38 +00:00
|
|
|
g_signal_emit_by_name (self->provider, "widget-edit-done");
|
2021-07-05 09:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_sip_account_widget_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsSipAccountWidget *self = CALLS_SIP_ACCOUNT_WIDGET (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_PROVIDER:
|
|
|
|
self->provider = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ORIGIN:
|
|
|
|
calls_sip_account_widget_set_origin (self, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_sip_account_widget_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsSipAccountWidget *self = CALLS_SIP_ACCOUNT_WIDGET (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_ORIGIN:
|
|
|
|
g_value_set_object (value, calls_sip_account_widget_get_origin (self));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_sip_account_widget_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CallsSipAccountWidget *self = CALLS_SIP_ACCOUNT_WIDGET (object);
|
|
|
|
|
2021-07-26 03:43:23 +00:00
|
|
|
g_clear_pointer (&self->last_port, g_free);
|
2021-07-05 09:55:44 +00:00
|
|
|
g_clear_object (&self->protocols_store);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (calls_sip_account_widget_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_sip_account_widget_class_init (CallsSipAccountWidgetClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->set_property = calls_sip_account_widget_set_property;
|
|
|
|
object_class->get_property = calls_sip_account_widget_get_property;
|
|
|
|
object_class->dispose = calls_sip_account_widget_dispose;
|
|
|
|
|
|
|
|
props[PROP_PROVIDER] =
|
|
|
|
g_param_spec_object ("provider",
|
|
|
|
"Provider",
|
|
|
|
"The SIP provider",
|
|
|
|
CALLS_TYPE_SIP_PROVIDER,
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
props[PROP_ORIGIN] =
|
|
|
|
g_param_spec_object ("origin",
|
|
|
|
"Origin",
|
|
|
|
"The origin to edit",
|
|
|
|
CALLS_TYPE_SIP_ORIGIN,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/sip-account-widget.ui");
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, header_add);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, spinner_add);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, header_edit);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, spinner_edit);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, login_btn);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, apply_btn);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, host);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, display_name);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, user);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, password);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, port);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, protocol);
|
2021-10-21 09:17:40 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, tel_switch);
|
2022-05-24 08:00:02 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsSipAccountWidget, auto_connect_switch);
|
2021-07-05 09:55:44 +00:00
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_login_clicked);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_delete_clicked);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_apply_clicked);
|
2021-08-27 14:41:27 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_user_changed);
|
2022-02-27 19:17:27 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_password_visibility_changed);
|
2021-07-26 03:43:23 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_port_entry_insert_text);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_port_entry_after_insert_text);
|
2021-07-05 09:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_sip_account_widget_init (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
HdyValueObject *obj;
|
|
|
|
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
|
|
|
|
|
|
|
self->protocols_store = g_list_store_new (HDY_TYPE_VALUE_OBJECT);
|
|
|
|
|
|
|
|
obj = hdy_value_object_new_string ("UDP");
|
|
|
|
g_list_store_insert (self->protocols_store, 0, obj);
|
|
|
|
g_clear_object (&obj);
|
|
|
|
|
|
|
|
obj = hdy_value_object_new_string ("TCP");
|
|
|
|
g_list_store_insert (self->protocols_store, 1, obj);
|
|
|
|
g_clear_object (&obj);
|
|
|
|
|
|
|
|
obj = hdy_value_object_new_string ("TLS");
|
|
|
|
g_list_store_insert (self->protocols_store, 2, obj);
|
|
|
|
g_clear_object (&obj);
|
|
|
|
|
|
|
|
hdy_combo_row_bind_name_model (self->protocol,
|
|
|
|
G_LIST_MODEL (self->protocols_store),
|
|
|
|
(HdyComboRowGetNameFunc) hdy_value_object_dup_string,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CallsSipAccountWidget *
|
|
|
|
calls_sip_account_widget_new (CallsSipProvider *provider)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_SIP_PROVIDER (provider), NULL);
|
|
|
|
|
|
|
|
return g_object_new (CALLS_TYPE_SIP_ACCOUNT_WIDGET,
|
|
|
|
"provider", provider,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CallsSipOrigin *
|
|
|
|
calls_sip_account_widget_get_origin (CallsSipAccountWidget *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_SIP_ACCOUNT_WIDGET (self), NULL);
|
|
|
|
|
|
|
|
return self->origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
calls_sip_account_widget_set_origin (CallsSipAccountWidget *self,
|
|
|
|
CallsSipOrigin *origin)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CALLS_IS_SIP_ACCOUNT_WIDGET (self));
|
|
|
|
g_return_if_fail (!origin || CALLS_IS_SIP_ORIGIN (origin));
|
|
|
|
|
|
|
|
edit_form (self, origin);
|
|
|
|
}
|