Commit dd28d9c6 authored by Alexandre Savard's avatar Alexandre Savard

[#3224] Regroup similar "if" statement in account config dialog

parent 45bc2499
......@@ -1231,251 +1231,252 @@ GtkWidget* create_codecs_configuration (account_t **a) {
void show_account_window (account_t * a) {
GtkWidget * notebook;
GtkWidget *tab, *codecs_tab, *ip_tab;
gint response;
account_t *currentAccount;
// In case the published address is same than local,
// we must resolve published address from interface name
gchar * local_interface;
gchar * published_address;
currentAccount = a;
if (currentAccount == NULL) {
currentAccount = g_new0(account_t, 1);
currentAccount->properties = dbus_account_details(NULL);
currentAccount->accountID = "new";
sflphone_fill_codec_list_per_account (&currentAccount);
DEBUG("Config: Account is NULL. Will fetch default values");
}
GtkWidget * notebook;
GtkWidget *tab, *codecs_tab, *ip_tab;
gint response;
account_t *currentAccount;
// In case the published address is same than local,
// we must resolve published address from interface name
gchar * local_interface;
gchar * published_address;
currentAccount = a;
if (currentAccount == NULL) {
currentAccount = g_new0(account_t, 1);
currentAccount->properties = dbus_account_details(NULL);
currentAccount->accountID = "new";
sflphone_fill_codec_list_per_account (&currentAccount);
DEBUG("Config: Account is NULL. Will fetch default values");
}
dialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Account settings"),
GTK_WINDOW(get_main_window()),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_APPLY,
GTK_RESPONSE_ACCEPT,
NULL));
dialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Account settings"),
GTK_WINDOW(get_main_window()),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_APPLY,
GTK_RESPONSE_ACCEPT,
NULL));
gtk_dialog_set_has_separator(dialog, FALSE);
gtk_container_set_border_width (GTK_CONTAINER(dialog), 0);
notebook = gtk_notebook_new();
gtk_box_pack_start(GTK_BOX (dialog->vbox), notebook, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(notebook), 10);
gtk_widget_show(notebook);
// We do not need the global settings for the IP2IP account
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
/* General Settings */
tab = create_basic_tab(&currentAccount);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Basic")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
g_signal_emit_by_name ((gpointer)protocolComboBox, "changed", NULL);
gtk_dialog_set_has_separator(dialog, FALSE);
gtk_container_set_border_width (GTK_CONTAINER(dialog), 0);
}
notebook = gtk_notebook_new();
gtk_box_pack_start(GTK_BOX (dialog->vbox), notebook, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(notebook), 10);
gtk_widget_show(notebook);
/* Codecs */
codecs_tab = create_codecs_configuration (&currentAccount);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), codecs_tab, gtk_label_new(_("Codecs")));
gtk_notebook_page_num (GTK_NOTEBOOK (notebook), codecs_tab);
// We do not need the global settings for the IP2IP account
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
// Get protocol
gchar *proto = "SIP";
proto = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(protocolComboBox));
/* General Settings */
tab = create_basic_tab(&currentAccount);
// Do not need advanced or security one for the IP2IP account
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Basic")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
g_signal_emit_by_name ((gpointer)protocolComboBox, "changed", NULL);
// Do not need advanced or Security tab for IAX either
if (strcmp(proto, "SIP") == 0) {
}
/* Advanced */
advanced_tab = create_advanced_tab(&currentAccount);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), advanced_tab, gtk_label_new(_("Advanced")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), advanced_tab);
/* Security */
security_tab = create_security_tab (&currentAccount);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), security_tab, gtk_label_new(_("Security")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook),security_tab);
}
}
else {
/* Codecs */
codecs_tab = create_codecs_configuration (&currentAccount);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), codecs_tab, gtk_label_new(_("Codecs")));
gtk_notebook_page_num (GTK_NOTEBOOK (notebook), codecs_tab);
/* Custom tab for the IP to IP profile */
ip_tab = create_direct_ip_calls_tab (&currentAccount);
gtk_notebook_prepend_page (GTK_NOTEBOOK (notebook), ip_tab, gtk_label_new(_("Network")));
gtk_notebook_page_num (GTK_NOTEBOOK (notebook), ip_tab);
}
gchar *proto = "SIP";
proto = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(protocolComboBox));
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook) , 0);
// Do not need these one for the IP2IP account
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
/**************/
/* Run dialog */
/**************/
response = gtk_dialog_run (GTK_DIALOG (dialog));
// If cancel button is pressed
if(response != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy (GTK_WIDGET(dialog));
return;
}
// If accept button is
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_RESOLVE_ONCE),
g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(entryResolveNameOnlyOnce)) ? "false": "true"));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_ALIAS),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryAlias))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_TYPE),
g_strdup(proto));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_HOSTNAME),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryHostname))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_USERNAME),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryUsername))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_PASSWORD),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryPassword))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_MAILBOX),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryMailbox))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_REGISTRATION_EXPIRE),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(expireSpinBox))));
}
// Do not need advanced or Security tab for IAX either
if (strcmp(proto, "SIP") == 0) {
/* Advanced */
advanced_tab = create_advanced_tab(&currentAccount);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), advanced_tab, gtk_label_new(_("Advanced")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), advanced_tab);
if (strcmp (proto, "SIP") == 0) {
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
/* Security */
security_tab = create_security_tab (&currentAccount);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), security_tab, gtk_label_new(_("Security")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook),security_tab);
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_ROUTE),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryRouteSet))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_USERAGENT),
g_strdup(gtk_entry_get_text (GTK_ENTRY(entryUseragent))));
}
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED),
g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useStunCheckBox)) ? "true":"false"));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER),
g_strdup(gtk_entry_get_text(GTK_ENTRY(stunServerEntry))));
g_hash_table_replace(currentAccount->properties, g_strdup(PUBLISHED_SAMEAS_LOCAL), g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton)) ? "true":"false"));
if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton))) {
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_PORT),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(publishedPortSpinBox))));
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_ADDRESS),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(publishedAddressEntry))));
}
else {
/* Custom tab for the IP to IP profile */
ip_tab = create_direct_ip_calls_tab (&currentAccount);
gtk_notebook_prepend_page (GTK_NOTEBOOK (notebook), ip_tab, gtk_label_new(_("Network")));
gtk_notebook_page_num (GTK_NOTEBOOK (notebook), ip_tab);
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_PORT),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
local_interface = g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo)));
published_address = dbus_get_address_from_interface_name(local_interface);
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_ADDRESS),
published_address);
}
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook) , 0);
// Run the dialog
response = gtk_dialog_run (GTK_DIALOG (dialog));
// If accept button is pressed
if(response == GTK_RESPONSE_ACCEPT)
{
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_RESOLVE_ONCE),
g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(entryResolveNameOnlyOnce)) ? "false": "true"));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_ALIAS),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryAlias))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_TYPE),
g_strdup(proto));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_HOSTNAME),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryHostname))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_USERNAME),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryUsername))));
if(strcmp(proto, "SIP") == 0) {
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_ROUTE),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryRouteSet))));
}
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_PASSWORD),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryPassword))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_MAILBOX),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(entryMailbox))));
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_REGISTRATION_EXPIRE),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(expireSpinBox))));
}
if (strcmp (proto, "SIP") == 0) {
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
g_hash_table_replace(currentAccount->properties,
g_strdup(ACCOUNT_USERAGENT),
g_strdup(gtk_entry_get_text (GTK_ENTRY(entryUseragent))));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_ENABLED),
g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useStunCheckBox)) ? "true":"false"));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SIP_STUN_SERVER),
g_strdup(gtk_entry_get_text(GTK_ENTRY(stunServerEntry))));
g_hash_table_replace(currentAccount->properties, g_strdup(PUBLISHED_SAMEAS_LOCAL), g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton)) ? "true":"false"));
if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton))) {
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_PORT),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(publishedPortSpinBox))));
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_ADDRESS),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(publishedAddressEntry))));
}
else {
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_PORT),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
local_interface = g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo)));
published_address = dbus_get_address_from_interface_name(local_interface);
g_hash_table_replace(currentAccount->properties,
g_strdup(PUBLISHED_ADDRESS),
published_address);
}
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(overrtp))) {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_DTMF_TYPE), g_strdup(OVERRTP));
}
else {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_DTMF_TYPE), g_strdup(SIPINFO));
}
gchar* keyExchange = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo));
if (g_strcasecmp(keyExchange, "ZRTP") == 0) {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true"));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(ZRTP));
}
else if(g_strcasecmp(keyExchange, "SDES") == 0) {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true"));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(SDES));
}
else {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("false"));
}
g_hash_table_replace(currentAccount->properties, g_strdup(TLS_ENABLE),
g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox)) ? "true":"false"));
}
g_hash_table_replace(currentAccount->properties,
g_strdup(LOCAL_INTERFACE),
g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo))));
g_hash_table_replace(currentAccount->properties,
g_strdup(LOCAL_PORT),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
}
/* Set new credentials if any */
DEBUG("Config: Setting credentials");
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
/* This hack is necessary because of the way the
* configuration file is made (.ini at that time).
* and deleting account per account is too much
* of a trouble.
*/
dbus_delete_all_credential(currentAccount);
GPtrArray * credential = getNewCredential(currentAccount->properties);
currentAccount->credential_information = credential;
if(currentAccount->credential_information != NULL) {
int i;
for(i = 0; i < currentAccount->credential_information->len; i++) {
dbus_set_credential(currentAccount, i);
}
dbus_set_number_of_credential(currentAccount, currentAccount->credential_information->len);
}
}
/** @todo Verify if it's the best condition to check */
if (g_strcasecmp(currentAccount->accountID, "new") == 0) {
dbus_add_account(currentAccount);
}
else {
dbus_set_account_details(currentAccount);
}
// Perpetuate changes to the deamon
codec_list_update_to_daemon (currentAccount);
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(overrtp))) {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_DTMF_TYPE), g_strdup(OVERRTP));
}
else {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_DTMF_TYPE), g_strdup(SIPINFO));
}
gchar* keyExchange = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(keyExchangeCombo));
if (g_strcasecmp(keyExchange, "ZRTP") == 0) {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true"));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(ZRTP));
}
else if(g_strcasecmp(keyExchange, "SDES") == 0) {
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true"));
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(SDES));
}
else {
DEBUG("IP to IP call\n");
// Direct IP calls config
// dbus_set_ip2ip_details (directIpCallsProperties);
g_hash_table_replace(currentAccount->properties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("false"));
}
g_hash_table_replace(currentAccount->properties, g_strdup(TLS_ENABLE),
g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox)) ? "true":"false"));
}
g_hash_table_replace(currentAccount->properties,
g_strdup(LOCAL_INTERFACE),
g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo))));
g_hash_table_replace(currentAccount->properties,
g_strdup(LOCAL_PORT),
g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
}
gtk_widget_destroy (GTK_WIDGET(dialog));
/* Set new credentials if any */
DEBUG("Config: Setting credentials");
if (g_strcasecmp (currentAccount->accountID, IP2IP) != 0) {
/* This hack is necessary because of the way the
* configuration file is made (.ini at that time).
* and deleting account per account is too much
* of a trouble.
*/
dbus_delete_all_credential(currentAccount);
GPtrArray * credential = getNewCredential(currentAccount->properties);
currentAccount->credential_information = credential;
if(currentAccount->credential_information != NULL) {
int i;
for(i = 0; i < currentAccount->credential_information->len; i++) {
dbus_set_credential(currentAccount, i);
}
dbus_set_number_of_credential(currentAccount, currentAccount->credential_information->len);
}
}
/** @todo Verify if it's the best condition to check */
if (g_strcasecmp(currentAccount->accountID, "new") == 0) {
dbus_add_account(currentAccount);
}
else {
dbus_set_account_details(currentAccount);
}
// Perpetuate changes to the deamon
codec_list_update_to_daemon (currentAccount);
gtk_widget_destroy (GTK_WIDGET(dialog));
}
......
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