Commit e305ef45 authored by Tristan Matthews's avatar Tristan Matthews

* #9490: separate show_account_dialog and account update logic

parent bec7dd15
......@@ -325,9 +325,10 @@ gboolean account_is_IAX(const account_t *account)
account_t *create_default_account()
{
account_t *account = g_new0(account_t, 1);
account->properties = dbus_get_account_details("");
account->accountID = g_strdup("new"); // FIXME: maybe replace with NULL?
account->properties = dbus_get_account_details("");
sflphone_fill_codec_list_per_account(account);
initialize_credential_information(account);
return account;
}
......@@ -337,6 +338,7 @@ account_t *create_account_with_ID(const gchar *ID)
account->accountID = g_strdup(ID);
account->properties = dbus_get_account_details(ID);
sflphone_fill_codec_list_per_account(account);
initialize_credential_information(account);
return account;
}
......
......@@ -78,7 +78,8 @@ sflphone_notify_voice_mail(const gchar* accountID , guint count)
DEBUG("sflphone_notify_voice_mail begin");
if (g_ascii_strcasecmp(id, current_id) != 0 || account_list_get_size() == 0)
if (g_ascii_strcasecmp(id, current_id) != 0 ||
account_list_get_size() == 0)
return;
// Set the number of voice messages for the current account
......
......@@ -1234,7 +1234,45 @@ static void update_account_from_basic_tab(account_t *account)
g_free(proto);
}
void show_account_window(account_t *account)
void update_account_from_dialog(GtkWidget *dialog, account_t *account)
{
if (!dialog)
return;
const gboolean IS_IP2IP = account_is_IP2IP(account);
if (!IS_IP2IP)
update_account_from_basic_tab(account);
// Get current protocol for this account
gchar *current_protocol;
if (protocol_combo)
current_protocol = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(protocol_combo));
else
current_protocol = g_strdup("SIP");
if (g_strcmp0(current_protocol, "SIP") == 0) {
if (!IS_IP2IP) {
DEBUG("Config: Get new credentials");
account->credential_information = get_new_credential();
if (account->credential_information)
dbus_set_credentials(account);
}
}
/** @todo Verify if it's the best condition to check */
if (g_strcmp0(account->accountID, "new") == 0)
dbus_add_account(account);
else
dbus_set_account_details(account);
// propagate changes to the daemon
codec_list_update_to_daemon(account);
g_free(current_protocol);
gtk_widget_destroy(dialog);
}
GtkWidget *show_account_window(const account_t *account)
{
// First we reset
reset();
......@@ -1269,13 +1307,6 @@ void show_account_window(account_t *account)
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), audiocodecs_tab, gtk_label_new(_("Audio")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), audiocodecs_tab);
// Get current protocol for this account
gchar *current_protocol;
if (protocol_combo)
current_protocol = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(protocol_combo));
else
current_protocol = g_strdup("SIP");
// Do not need advanced or security one for the IP2IP account
if (!IS_IP2IP) {
/* Advanced */
......@@ -1284,7 +1315,6 @@ void show_account_window(account_t *account)
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), advanced_tab);
/* Security */
initialize_credential_information(account);
security_tab = create_security_tab(account);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), security_tab, gtk_label_new(_("Security")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), security_tab);
......@@ -1307,32 +1337,9 @@ void show_account_window(account_t *account)
// If anything but "Apply" button is pressed
if (response != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy(dialog);
return;
}
if (!IS_IP2IP)
update_account_from_basic_tab(account);
/** @todo Verify if it's the best condition to check */
if (g_strcmp0(account->accountID, "new") == 0)
dbus_add_account(account);
else
dbus_set_account_details(account);
if (g_strcmp0(current_protocol, "SIP") == 0) {
if (!IS_IP2IP) {
DEBUG("Config: Get new credentials");
account->credential_information = get_new_credential();
if (account->credential_information)
dbus_set_credentials(account);
}
return NULL;
} else {
return dialog;
}
// propagate changes to the daemon
codec_list_update_to_daemon(account);
g_free(current_protocol);
gtk_widget_destroy(dialog);
}
......@@ -40,8 +40,15 @@
/**
* Display the main account widget
* @param a The account you want to display
* @return The dialog with the pertinent account information
*/
void show_account_window(account_t *a);
GtkWidget *show_account_window(const account_t *a);
/*
* @param dialog The dialog the account will be update from
* @param a The account you want to display
*/
void update_account_from_dialog(GtkWidget *dialog, account_t *a);
/**
* Resets local cache of account pointers */
......
......@@ -91,24 +91,30 @@ static void delete_account_cb(gpointer data)
g_free(selected_accountID);
}
static void
run_account_dialog(const gchar *selected_accountID)
{
account_t *selected_account = account_list_get_by_id(selected_accountID);
GtkWidget *dialog = show_account_window(selected_account);
update_account_from_dialog(dialog, selected_account);
}
static void row_activated_cb(GtkTreeView *view,
GtkTreePath *path UNUSED,
GtkTreeViewColumn *col UNUSED,
gpointer user_data UNUSED)
{
gchar *selected_accountID = get_selected_accountID(view);
RETURN_IF_NULL(selected_accountID, "No selected account in edit action");
DEBUG("%s: Selected accountID=%s\n", __PRETTY_FUNCTION__, selected_accountID);
show_account_window(account_list_get_by_id(selected_accountID));
RETURN_IF_NULL(selected_accountID, "No selected account ID");
run_account_dialog(selected_accountID);
g_free(selected_accountID);
}
static void edit_account_cb(GtkButton *button UNUSED, gpointer data)
{
gchar *selected_accountID = get_selected_accountID(data);
RETURN_IF_NULL(selected_accountID, "No selected account in edit action");
DEBUG("%s: Selected accountID=%s\n", __PRETTY_FUNCTION__, selected_accountID);
show_account_window(account_list_get_by_id(selected_accountID));
RETURN_IF_NULL(selected_accountID, "No selected account ID");
run_account_dialog(selected_accountID);
g_free(selected_accountID);
}
......@@ -116,7 +122,7 @@ static void add_account_cb(void)
{
account_t *new_account = create_default_account();
account_list_add(new_account);
show_account_window(new_account);
run_account_dialog(new_account->accountID);
}
static void account_store_add(GtkTreeIter *iter, account_t *account)
......@@ -241,22 +247,22 @@ enable_account_cb(GtkCellRendererToggle *rend UNUSED, gchar* path,
GtkTreeIter iter;
gtk_tree_model_get_iter(model, &iter, tree_path);
gboolean enable;
gchar * id;
gchar *id;
gtk_tree_model_get(model, &iter, COLUMN_ACCOUNT_ACTIVE, &enable,
COLUMN_ACCOUNT_ID, &id, -1);
account_t *account = account_list_get_by_id(id);
g_assert(account);
enable = !enable;
DEBUG("Account is %d enabled", enable);
// Store value
gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_ACCOUNT_ACTIVE,
enable, -1);
// Modify account state
const gchar * registration_state = enable ? "true" : "false";
DEBUG("Account is enabled: %s", registration_state);
DEBUG("Replacing registration state with %s", registration_state);
account_replace(account, ACCOUNT_ENABLED, registration_state);
dbus_send_register(account->accountID, enable);
}
......@@ -445,8 +451,7 @@ create_account_list()
GtkTreeView * tree_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(account_store)));
GtkTreeSelection *tree_selection = gtk_tree_view_get_selection(tree_view);
g_signal_connect(G_OBJECT(tree_selection), "changed",
G_CALLBACK(select_account_cb),
account_store);
G_CALLBACK(select_account_cb), NULL);
GtkCellRenderer *renderer = gtk_cell_renderer_toggle_new();
GtkTreeViewColumn *tree_view_column =
......
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