From 70add0afca764ed7a4db3b4169efe6642886e7ce Mon Sep 17 00:00:00 2001
From: Guillaume Carmel-Archambault
 <guillaume.carmel-archambault@savoirfairelinux.com>
Date: Tue, 5 Feb 2008 15:28:36 -0500
Subject: [PATCH] GTK Codec list update on change active and reorder + some web
 site errors

---
 doc/Goals.txt                   | 10 +++---
 sflphone-gtk/src/codeclist.c    | 47 +++++++++++++++++++---------
 sflphone-gtk/src/codeclist.h    |  7 +++--
 sflphone-gtk/src/configwindow.c | 55 +++++++++++++++++++++------------
 sflphone-gtk/src/configwindow.h | 24 ++++++++++----
 5 files changed, 96 insertions(+), 47 deletions(-)

diff --git a/doc/Goals.txt b/doc/Goals.txt
index 3d224e1f8b..b9d84b73a7 100644
--- a/doc/Goals.txt
+++ b/doc/Goals.txt
@@ -11,10 +11,10 @@ Goals for next release (0.8)
    * Functional IAX transport
    * Near perfect audio
    * Multiple-client (GUI or other) connectivity to server
- - New Gtk+ GUI with following functionnality (altough the server can do more):
+ - New Gtk+ GUI with following functionality (although the server can do more):
    * User can place a call
    * User can answer a call
-   * User can transfert a call
+   * User can transfer a call
    * User can have an unlimited number of calls
    * User can put a call on hold and off hold
    * User is informed of waiting voice mail
@@ -29,7 +29,7 @@ Goals for release 0.8.5
  - Server side:
    * Perfect audio
    * Better error handling of failed account registrations
-   * Fully working multiple account functionnality 
+   * Fully working multiple account functionality
  - Gtk+ GUI updates
    * User can set up audio parameters
    * User can set up STUN and proxy settings for SIP accounts
@@ -41,7 +41,7 @@ Goals for release 0.8.5
    * User can place a call
    * User can answer calls
    * User can send DTMF
-   * User can transfert a call
+   * User can transfer a call
 
 
 
@@ -55,7 +55,7 @@ Goals for release 0.9
  - Gtk+ GUI updates
    * User can receive and send SMS messages
    * User is informed of call duration
-   * User can set up speel call buttons
+   * User can set up speed call buttons
    * User can consult/clear call history
    * User can set a status
  - Python CLI client
diff --git a/sflphone-gtk/src/codeclist.c b/sflphone-gtk/src/codeclist.c
index 9a3b798ed4..2e15fb6570 100644
--- a/sflphone-gtk/src/codeclist.c
+++ b/sflphone-gtk/src/codeclist.c
@@ -67,13 +67,11 @@ codec_list_add(codec_t * c)
 void 
 codec_set_active(gchar* name)
 {
-  printf("entry point set active");
   codec_t * c = codec_list_get(name);
   if(c){
-    printf("blablabla");
+    printf("%s set active/n", c->name);
     c->is_active = TRUE;
   }
-  printf("exit point set active");
 }
 
 void
@@ -89,17 +87,7 @@ codec_list_get_size()
 {
   return g_queue_get_length(codecQueue);
 }
-/*
-codec_t*
-codec_list_get( const gchar * name)
-{
-  GList * c = g_queue_find_custom(codecQueue, name, is_name_codecstruct);
-  if(c)
-    return (codec_t *)c->data;
-  else
-    return NULL;
-}
-*/
+
 codec_t*
 codec_list_get( const gchar* name)
 {
@@ -124,3 +112,34 @@ codec_set_prefered_order(guint index)
   g_queue_push_head(codecQueue, prefered);
 }
 
+void
+codec_list_move_codec_up(guint index)
+{
+	if(index != 0)
+	{
+		gpointer codec = g_queue_pop_nth(codecQueue, index);
+		g_queue_push_nth(codecQueue, codec, index-1);
+	}
+	
+	// TEMP
+	int i;
+	printf("\nCodec list\n");
+	for(i=0; i < codecQueue->length; i++)
+		printf("%s\n", codec_list_get_nth(i)->name);
+}
+
+void
+codec_list_move_codec_down(guint index)
+{
+	if(index != codecQueue->length)
+	{
+		gpointer codec = g_queue_pop_nth(codecQueue, index);
+		g_queue_push_nth(codecQueue, codec, index+1);
+	}
+
+	// TEMP
+	int i;
+	printf("\nCodec list\n");
+	for(i=0; i < codecQueue->length; i++)
+		printf("%s\n", codec_list_get_nth(i)->name);
+}
diff --git a/sflphone-gtk/src/codeclist.h b/sflphone-gtk/src/codeclist.h
index 08047d7eb0..edeea9d993 100644
--- a/sflphone-gtk/src/codeclist.h
+++ b/sflphone-gtk/src/codeclist.h
@@ -37,8 +37,8 @@ typedef struct {
 void codec_list_init();
 void codec_list_clear();
 void codec_list_add(codec_t * c);
-//void codec_set_active(gchar* name);
-//void codec_set_inactive(gchar* name);
+void codec_set_active(gchar* name);
+void codec_set_inactive(gchar* name);
 guint codec_list_get_size();
 codec_t * codec_list_get(const gchar * name);
 //codec_t * codec_list_get(const int payload);
@@ -52,4 +52,7 @@ void codec_set_prefered_order(guint index);
 //gchar * codec_get_name(codec_t * c);
 //guint codec_get_rate(gchar * codec_name);
 
+void codec_list_move_codec_up(guint index);
+void codec_list_move_codec_down(guint index);
+
 #endif
diff --git a/sflphone-gtk/src/configwindow.c b/sflphone-gtk/src/configwindow.c
index 27d39aba2a..90a24e389f 100644
--- a/sflphone-gtk/src/configwindow.c
+++ b/sflphone-gtk/src/configwindow.c
@@ -16,7 +16,7 @@
  *  
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <accountlist.h>
@@ -267,23 +267,36 @@ codec_active_toggled(GtkCellRendererToggle *renderer, gchar *path, gpointer data
 	GtkTreePath *treePath;
 	GtkTreeModel *model;
 	gboolean active;
+	char* name;
 	
 	// Get path of clicked codec active toggle box
 	treePath = gtk_tree_path_new_from_string(path);
 	model = gtk_tree_view_get_model(GTK_TREE_VIEW(data));
 	gtk_tree_model_get_iter(model, &iter, treePath);
 
-	// Get value at iteration
+	// Get active value and name at iteration
 	gtk_tree_model_get(model, &iter,
 			COLUMN_CODEC_ACTIVE, &active,
+			COLUMN_CODEC_NAME, &name,
 			-1);
 	
+	printf("%s\n", name);
+
 	// Toggle active value
+	active = !active;
+	
+	// Store value
 	gtk_list_store_set(GTK_LIST_STORE(model), &iter,
-			COLUMN_CODEC_ACTIVE, !active,
+			COLUMN_CODEC_ACTIVE, active,
 			-1);
 
 	gtk_tree_path_free(treePath);
+
+	// Modify codec queue to represent change	
+	if(active)
+		codec_set_active(name);
+	else
+		codec_set_inactive(name);
 	
 	// TODO Perpetuate changes to the deamon
 }
@@ -293,7 +306,7 @@ codec_active_toggled(GtkCellRendererToggle *renderer, gchar *path, gpointer data
  * update changes in the deamon list and the configuration files
  */
 static void
-moveCodec(gboolean moveUp, gpointer data)
+codec_move(gboolean moveUp, gpointer data)
 {
 	GtkTreeIter iter;
 	GtkTreeIter *iter2;
@@ -315,7 +328,9 @@ moveCodec(gboolean moveUp, gpointer data)
 	// Find path of iteration
 	path = gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(model), &iter);
 	treePath = gtk_tree_path_new_from_string(path);
-
+	gint *indices = gtk_tree_path_get_indices(treePath);
+	gint indice = indices[0];
+	
 	// Depending on button direction get new path
 	if(moveUp)
 		gtk_tree_path_prev(treePath);
@@ -335,33 +350,33 @@ moveCodec(gboolean moveUp, gpointer data)
 	gtk_tree_iter_free(iter2);
 	g_free(path);
 	
+	// Perpetuate changes in codec queue
+	if(moveUp)
+		codec_list_move_codec_up(indice);
+	else
+		codec_list_move_codec_down(indice);
+	
 	// TODO Perpetuate changes to the deamon
-	/* Update the gconf key
-	codecs_data = gm_codecs_list_to_gm_conf_list (GTK_WIDGET (data));
-
-	gm_conf_set_string_list (AUDIO_CODECS_KEY "list", codecs_data);
-
-	g_slist_foreach (codecs_data, (GFunc) g_free, NULL);
-	g_slist_free (codecs_data);
-	*/
 }
 
 /**
  * Called from move up codec button signal
  */
-void
-moveCodecUp(GtkButton *button, gpointer data)
+static void
+codec_move_up(GtkButton *button, gpointer data)
 {
-	moveCodec(TRUE, data);
+	// Change tree view ordering and get indice changed
+	codec_move(TRUE, data);
 }
 
 /**
  * Called from move down codec button signal
  */
 static void
-moveCodecDown(GtkButton *button, gpointer data)
+codec_move_down(GtkButton *button, gpointer data)
 {
-	moveCodec(FALSE, data);
+	// Change tree view ordering and get indice changed
+	codec_move(FALSE, data);
 }
 
 /**
@@ -505,12 +520,12 @@ create_codec_table()
 	moveUpButton = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
 	gtk_widget_set_sensitive(GTK_WIDGET(moveUpButton), FALSE);
 	gtk_box_pack_start(GTK_BOX(buttonBox), moveUpButton, FALSE, FALSE, 0);
-	g_signal_connect(G_OBJECT(moveUpButton), "clicked", G_CALLBACK(moveCodecUp), codecTreeView);
+	g_signal_connect(G_OBJECT(moveUpButton), "clicked", G_CALLBACK(codec_move_up), codecTreeView);
 	
 	moveDownButton = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
 	gtk_widget_set_sensitive(GTK_WIDGET(moveDownButton), FALSE);
 	gtk_box_pack_start(GTK_BOX(buttonBox), moveDownButton, FALSE, FALSE, 0);
-	g_signal_connect(G_OBJECT(moveDownButton), "clicked", G_CALLBACK(moveCodecDown), codecTreeView);
+	g_signal_connect(G_OBJECT(moveDownButton), "clicked", G_CALLBACK(codec_move_down), codecTreeView);
 	
 	config_window_fill_codec_list();
 
diff --git a/sflphone-gtk/src/configwindow.h b/sflphone-gtk/src/configwindow.h
index 819e19211f..3597e5cbc3 100644
--- a/sflphone-gtk/src/configwindow.h
+++ b/sflphone-gtk/src/configwindow.h
@@ -16,16 +16,28 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
- 
+
 #ifndef __CONFIGWINDOW_H__
 #define __CONFIGWINDOW_H__
 
 #include <calllist.h>
 
-/** @file configwindow.h
-  * @brief The Preferences window.
-  */
-void show_config_window ( );
-void config_window_fill_account_list ( );
+/**
+ * @file configwindow.h
+ * @brief The Preferences window.
+ */
+void config_window_fill_account_list();
+void config_window_fill_codec_list();
+void show_config_window();
+void config_window_fill_audio_manager_list();
+void config_window_fill_output_audio_device_list();
+void config_window_fill_input_audio_device_list();
+void default_account(GtkWidget *widget, gpointer data);
+void bold_if_default_account(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data);
+void default_codecs(GtkWidget* widget, gpointer data);
+GtkWidget * create_codec_table();
+GtkWidget * create_accounts_tab();
+GtkWidget * create_audio_tab();
+void show_config_window();
 
 #endif 
-- 
GitLab