From ef7f067d93c99610cba031a0f6a1666ef280dae1 Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandresavard@alexandresavard-desktop.(none)>
Date: Mon, 4 Jan 2010 14:19:34 -0500
Subject: [PATCH] [#2623] Load local interface in account configuration dialog

---
 .../src/config/accountconfigdialog.c                | 13 +++++++++++--
 .../src/config/preferencesdialog.c                  |  9 ++++++---
 sflphone-client-gnome/src/sflphone_const.h          |  1 +
 sflphone-common/src/dbus/configurationmanager.cpp   |  7 +++++++
 sflphone-common/src/managerimpl.cpp                 |  1 +
 5 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/sflphone-client-gnome/src/config/accountconfigdialog.c b/sflphone-client-gnome/src/config/accountconfigdialog.c
index 327f356ead..02b19959f8 100644
--- a/sflphone-client-gnome/src/config/accountconfigdialog.c
+++ b/sflphone-client-gnome/src/config/accountconfigdialog.c
@@ -757,6 +757,7 @@ GtkWidget * create_advanced_tab(account_t **a)
 	gchar * use_tls;
 	gchar * published_address;
 	gchar * published_port;
+	gchar * local_interface;
 	gchar * local_address;
 	gchar * local_port;
 	gchar * stun_enable;    
@@ -772,6 +773,9 @@ GtkWidget * create_advanced_tab(account_t **a)
 
 		published_sameas_local = g_hash_table_lookup(currentAccount->properties,  PUBLISHED_SAMEAS_LOCAL);
 
+		local_interface = g_hash_table_lookup(currentAccount->properties, LOCAL_INTERFACE);
+
+
 		local_port = g_hash_table_lookup(currentAccount->properties, LOCAL_PORT);
 		local_address = g_hash_table_lookup(currentAccount->properties,  LOCAL_ADDRESS);
 
@@ -849,7 +853,7 @@ GtkWidget * create_advanced_tab(account_t **a)
             gtk_list_store_set(ipInterfaceListStore, &iter, 0, *iface, -1 );
 
 	    // set the current local address
-	    if (!iface_found && (g_strcmp0(*iface, local_address) == 0)) {
+	    if (!iface_found && (g_strcmp0(*iface, local_interface) == 0)) {
                 DEBUG("Setting active local address combo box");
                 current_local_address_iter = iter;
 		iface_found = TRUE;
@@ -1114,9 +1118,13 @@ show_account_window (account_t * a)
 
 			g_hash_table_replace(currentAccount->properties, g_strdup(PUBLISHED_SAMEAS_LOCAL), g_strdup(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sameAsLocalRadioButton)) ? "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))));	
+			        g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
 
 			g_hash_table_replace(currentAccount->properties,
     				g_strdup(LOCAL_ADDRESS),
@@ -1136,6 +1144,7 @@ show_account_window (account_t * a)
 			   g_hash_table_replace(currentAccount->properties,
 						 g_strdup(PUBLISHED_PORT),
 						 g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(localPortSpinBox))));
+			   
 
 			   g_hash_table_replace(currentAccount->properties,
 						 g_strdup(PUBLISHED_ADDRESS),
diff --git a/sflphone-client-gnome/src/config/preferencesdialog.c b/sflphone-client-gnome/src/config/preferencesdialog.c
index fddc259eed..13257f4c91 100644
--- a/sflphone-client-gnome/src/config/preferencesdialog.c
+++ b/sflphone-client-gnome/src/config/preferencesdialog.c
@@ -165,7 +165,7 @@ static void use_sip_tls_cb(GtkWidget *widget, gpointer data)
 static void ip2ip_local_address_changed_cb(GtkWidget *widget, gpointer data)
 {
 	DEBUG("ip2ip_local_address_changed_cb\n");
-	g_hash_table_replace(directIpCallsProperties, g_strdup(LOCAL_ADDRESS), g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget))));
+	g_hash_table_replace(directIpCallsProperties, g_strdup(LOCAL_INTERFACE), g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget))));
 }
 
 static void ip2ip_local_port_changed_cb(GtkWidget *widget, gpointer data)
@@ -199,6 +199,7 @@ GtkWidget* create_direct_ip_calls_tab()
 	gchar * curKeyExchange = "0";
 	gchar * description;
 
+	gchar * local_interface;
 	gchar * local_address;
 	gchar * local_port;
 
@@ -207,8 +208,10 @@ GtkWidget* create_direct_ip_calls_tab()
 
 	if(directIpCallsProperties != NULL) {
 		DEBUG("got a directIpCallsProperties");
+		local_interface = g_hash_table_lookup(directIpCallsProperties, LOCAL_INTERFACE);
 		local_address = g_hash_table_lookup(directIpCallsProperties,  LOCAL_ADDRESS);
 		local_port = g_hash_table_lookup(directIpCallsProperties, LOCAL_PORT);
+		DEBUG("    local interface = %s", local_interface);
 		DEBUG("    local address = %s", local_address);
 		DEBUG("    local port = %s", local_port);
 		curSRTPEnabled = g_hash_table_lookup(directIpCallsProperties, ACCOUNT_SRTP_ENABLED);
@@ -264,7 +267,7 @@ GtkWidget* create_direct_ip_calls_tab()
 			gtk_list_store_append(ipInterfaceListStore, &iter );
 			gtk_list_store_set(ipInterfaceListStore, &iter, 0, *iface, -1 );
 
-			if (!iface_found && (g_strcmp0(*iface, local_address) == 0)) {
+			if (!iface_found && (g_strcmp0(*iface, local_interface) == 0)) {
 				DEBUG("Setting active local address combo box");
 				current_local_address_iter = iter;
 				iface_found = TRUE;
@@ -292,7 +295,7 @@ GtkWidget* create_direct_ip_calls_tab()
 	gtk_combo_box_set_active_iter(GTK_COMBO_BOX(localAddressCombo), &current_local_address_iter);
 	g_signal_connect (G_OBJECT(GTK_COMBO_BOX(localAddressCombo)), "changed", G_CALLBACK (ip2ip_local_address_changed_cb), localAddressCombo);
 
-	g_hash_table_replace(directIpCallsProperties, g_strdup(LOCAL_ADDRESS), g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo))));
+	g_hash_table_replace(directIpCallsProperties, g_strdup(LOCAL_INTERFACE), g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo))));
 
 
 	/**
diff --git a/sflphone-client-gnome/src/sflphone_const.h b/sflphone-client-gnome/src/sflphone_const.h
index b63a3e17e1..485e755dc0 100644
--- a/sflphone-client-gnome/src/sflphone_const.h
+++ b/sflphone-client-gnome/src/sflphone_const.h
@@ -88,6 +88,7 @@
 #define TLS_NEGOTIATION_TIMEOUT_SEC         "TLS.negotiationTimeoutSec"
 #define TLS_NEGOTIATION_TIMEOUT_MSEC        "TLS.negotiationTimemoutMsec"
 
+#define LOCAL_INTERFACE                     "Account.localInterface"
 #define PUBLISHED_SAMEAS_LOCAL              "Account.publishedSameAsLocal"
 #define LOCAL_PORT                          "Account.localPort"
 #define LOCAL_ADDRESS                       "Account.localAddress"
diff --git a/sflphone-common/src/dbus/configurationmanager.cpp b/sflphone-common/src/dbus/configurationmanager.cpp
index 7b13da09a8..05fdc738f3 100644
--- a/sflphone-common/src/dbus/configurationmanager.cpp
+++ b/sflphone-common/src/dbus/configurationmanager.cpp
@@ -77,6 +77,7 @@ ConfigurationManager::getIp2IpDetails (void)
     ip2ipAccountDetails.insert (std::pair<std::string, std::string> (ZRTP_NOT_SUPP_WARNING, Manager::instance().getConfigString (IP2IP_PROFILE, ZRTP_NOT_SUPP_WARNING)));
     ip2ipAccountDetails.insert (std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS_ONCE, Manager::instance().getConfigString (IP2IP_PROFILE, ZRTP_DISPLAY_SAS_ONCE)));
 
+    ip2ipAccountDetails.insert (std::pair<std::string, std::string> (LOCAL_INTERFACE, Manager::instance().getConfigString(IP2IP_PROFILE, LOCAL_INTERFACE)));
     ip2ipAccountDetails.insert (std::pair<std::string, std::string> (LOCAL_ADDRESS, Manager::instance().getConfigString (IP2IP_PROFILE, LOCAL_ADDRESS)));
     ip2ipAccountDetails.insert (std::pair<std::string, std::string> (LOCAL_PORT, Manager::instance().getConfigString (IP2IP_PROFILE, LOCAL_PORT)));
 
@@ -94,6 +95,12 @@ ConfigurationManager::setIp2IpDetails (const std::map< std::string, std::string
     std::map<std::string, std::string> map_cpy = details;
     std::map<std::string, std::string>::iterator it;
 
+    it = map_cpy.find (LOCAL_INTERFACE);
+
+    if (it != details.end()) {
+        Manager::instance().setConfig (IP2IP_PROFILE, LOCAL_INTERFACE, it->second);
+    }
+
     it = map_cpy.find (LOCAL_ADDRESS);
 
     if (it != details.end()) {
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index 29dcc62fd9..d4cd94ab24 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -3536,6 +3536,7 @@ std::map< std::string, std::string > ManagerImpl::getAccountDetails (const Accou
     a.insert (std::pair<std::string, std::string> (AUTHENTICATION_USERNAME, getConfigString (accountID, AUTHENTICATION_USERNAME)));
     a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_MAILBOX, getConfigString (accountID, CONFIG_ACCOUNT_MAILBOX)));
     a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_REGISTRATION_EXPIRE, getConfigString (accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE)));
+    a.insert (std::pair<std::string, std::string> (LOCAL_INTERFACE, getConfigString (accountID, LOCAL_INTERFACE)));
     a.insert (std::pair<std::string, std::string> (PUBLISHED_SAMEAS_LOCAL, getConfigString (accountID, PUBLISHED_SAMEAS_LOCAL)));
     a.insert (std::pair<std::string, std::string> (LOCAL_ADDRESS, getConfigString (accountID, LOCAL_ADDRESS)));
     a.insert (std::pair<std::string, std::string> (PUBLISHED_ADDRESS, getConfigString (accountID, PUBLISHED_ADDRESS)));
-- 
GitLab