From 2dea0427579c375ce12478a0f4cabd2e4172d14a Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Tue, 11 Dec 2007 14:19:51 -0500 Subject: [PATCH] Improve codec processing on client side + info screen on call Add a class codec on client side to manipulate codec-related data. Add a screen that displays on call the number called and the codec used. note: the screen doesn't display when a call is made with the keypad. TODO --- sflphone-gtk/src/Makefile.am | 5 +- sflphone-gtk/src/actions.c | 60 ++++++++----- sflphone-gtk/src/actions.h | 3 +- sflphone-gtk/src/codeclist.c | 94 ++++++++++++++++++++ sflphone-gtk/src/codeclist.h | 50 +++++++++++ sflphone-gtk/src/configurationmanager-glue.h | 20 ++--- sflphone-gtk/src/configwindow.c | 46 +++++----- sflphone-gtk/src/dbus.c | 4 +- sflphone-gtk/src/mainwindow.c | 27 ++++-- sflphone-gtk/src/screen.c | 12 ++- src/dbus/configurationmanager-glue.h | 12 +-- src/dbus/configurationmanager-introspec.xml | 4 +- src/dbus/configurationmanager.cpp | 8 +- src/dbus/configurationmanager.h | 4 +- src/managerimpl.cpp | 50 +++++++---- src/managerimpl.h | 17 +++- 16 files changed, 310 insertions(+), 106 deletions(-) create mode 100644 sflphone-gtk/src/codeclist.c create mode 100644 sflphone-gtk/src/codeclist.h diff --git a/sflphone-gtk/src/Makefile.am b/sflphone-gtk/src/Makefile.am index 0e01d99675..cc6de1e550 100644 --- a/sflphone-gtk/src/Makefile.am +++ b/sflphone-gtk/src/Makefile.am @@ -15,9 +15,10 @@ sflphone_gtk_SOURCES = \ accountwindow.c \ marshaller.c \ sliders.c \ - statusicon.c + statusicon.c \ + codeclist.c -noinst_HEADERS = actions.h dbus.h mainwindow.h calllist.h dialpad.h \ +noinst_HEADERS = actions.h dbus.h mainwindow.h calllist.h dialpad.h codeclist.h\ callmanager-glue.h configurationmanager-glue.h instance-glue.h menus.h calltree.h screen.h configwindow.h \ accountlist.h accountwindow.h marshaller.h sliders.h statusicon.h EXTRA_DIST = marshaller.list diff --git a/sflphone-gtk/src/actions.c b/sflphone-gtk/src/actions.c index 0ee3e7cf53..331bf623e8 100644 --- a/sflphone-gtk/src/actions.c +++ b/sflphone-gtk/src/actions.c @@ -18,7 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <accountlist.h> #include <actions.h> #include <calltree.h> #include <dbus.h> @@ -80,7 +79,7 @@ sflphone_hold(call_t * c ) c->state = CALL_STATE_HOLD; update_call_tree(c); update_menus(); - screen_clear(); + //screen_clear(); } void @@ -146,6 +145,7 @@ sflphone_init() { call_list_init (); account_list_init (); + codec_list_init(); if(!dbus_connect ()) { main_window_error_message("Unable to connect to the SFLphone server.\nMake sure the daemon is running."); @@ -156,7 +156,7 @@ sflphone_init() dbus_register(getpid(), "Gtk+ Client"); sflphone_fill_account_list(); sflphone_set_default_account(); - sflphone_get_codec_list(); + sflphone_fill_codec_list(); return TRUE; } } @@ -165,6 +165,7 @@ sflphone_init() sflphone_hang_up() { call_t * selectedCall = call_get_selected(); + main_window_callinfo(FALSE, selectedCall); if(selectedCall) { switch(selectedCall->state) @@ -195,6 +196,8 @@ sflphone_hang_up() sflphone_pick_up() { call_t * selectedCall = call_get_selected(); + //screen_set_call(selectedCall); + main_window_callinfo(TRUE, selectedCall); if(selectedCall) { switch(selectedCall->state) @@ -264,7 +267,7 @@ sflphone_fail( call_t * c ) c->state = CALL_STATE_FAILURE; update_call_tree(c); update_menus(); - screen_set_call(c); + main_window_callinfo(FALSE, c); } void @@ -273,7 +276,7 @@ sflphone_busy( call_t * c ) c->state = CALL_STATE_BUSY; update_call_tree(c); update_menus(); - screen_set_call(c); + //screen_set_call(c); } void @@ -282,7 +285,7 @@ sflphone_current( call_t * c ) c->state = CALL_STATE_CURRENT; update_call_tree(c); update_menus(); - screen_set_call(c); + //screen_set_call(c); } void @@ -293,7 +296,7 @@ sflphone_set_transfert() { c->state = CALL_STATE_TRANSFERT; c->to = g_strdup(""); - screen_set_call(c); + //screen_set_call(c); update_call_tree(c); update_menus(); } @@ -308,7 +311,7 @@ sflphone_unset_transfert() { c->state = CALL_STATE_CURRENT; c->to = g_strdup(""); - screen_set_call(c); + //screen_set_call(c); update_call_tree(c); update_menus(); } @@ -329,7 +332,7 @@ sflphone_hung_up (call_t * c ) call_list_remove(c->callID); update_call_tree_remove(c); update_menus(); - screen_clear(); + main_window_callinfo(FALSE, c); } void process_dialing(call_t * c, guint keyval, gchar * key) @@ -356,7 +359,7 @@ void process_dialing(call_t * c, guint keyval, gchar * key) g_free(c->from); c->from = g_strconcat("\"\" <", c->to, ">", NULL); } - screen_set_call(c); + //screen_set_call(c); update_call_tree(c); } else if(strlen(c->to) == 1) @@ -384,7 +387,7 @@ void process_dialing(call_t * c, guint keyval, gchar * key) g_free(c->from); c->from = g_strconcat("\"\" <", c->to, ">", NULL); } - screen_set_call(c); + //screen_set_call(c); update_call_tree(c); } break; @@ -405,7 +408,7 @@ call_t * sflphone_new_call() c->to = g_strdup(""); call_list_add(c); - screen_set_call(c); + //screen_set_call(c); update_call_tree_add(c); update_menus(); @@ -439,7 +442,7 @@ sflphone_keypad( guint keyval, gchar * key) c->from = g_strconcat("\"",call_get_name(c) ,"\" <", temp, ">", NULL); g_free(before); g_free(temp); - screen_set_call(c); + //screen_set_call(c); update_call_tree(c); } break; @@ -572,14 +575,29 @@ sflphone_set_default_account( ) /* Internal to action - get the codec list */ - gchar** -sflphone_get_codec_list() +void +sflphone_fill_codec_list() { - int i=0; - gchar** codecs = (gchar**)dbus_codec_list(); - while(codecs[i]!=NULL){ - printf("%s\n", codecs[i]); - i++; - } + + int i=0; + gchar** codecs = (gchar**)dbus_codec_list(); + while(codecs[i]!=NULL) + { + printf("%s\n", codecs[i]); + codec_t * c = g_new0(codec_t, 1); + c->name = codecs[i]; + codec_set_active(codecs[i]); // active by default + codec_list_add(c); + i++; + } } + + + + + + + + + diff --git a/sflphone-gtk/src/actions.h b/sflphone-gtk/src/actions.h index 7438627a45..e7ad545ce6 100644 --- a/sflphone-gtk/src/actions.h +++ b/sflphone-gtk/src/actions.h @@ -23,6 +23,7 @@ #include <calllist.h> #include <accountlist.h> +#include <codeclist.h> /** @file actions.h * @brief General functions that change the state of the application. @@ -105,5 +106,5 @@ void sflphone_place_call ( call_t * c ); void sflphone_fill_account_list(); void sflphone_set_default_account(); -gchar** sflphone_get_codec_list(); +void sflphone_fill_codec_list(); #endif diff --git a/sflphone-gtk/src/codeclist.c b/sflphone-gtk/src/codeclist.c new file mode 100644 index 0000000000..9c62d0aae4 --- /dev/null +++ b/sflphone-gtk/src/codeclist.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.net> + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <codeclist.h> + +#include <string.h> + +GQueue * codecQueue = NULL; + +gint +is_name_codecstruct (gconstpointer a, gconstpointer b) +{ + codec_t * c = (codec_t *)a; + if(strcmp(c->name, (const gchar *)b)==0) + return 0; + else + return 1; +} + +void +codec_list_init() +{ + codecQueue = g_queue_new(); +} + +void +codec_list_add(codec_t * c) +{ + g_queue_push_tail (codecQueue, (gpointer *) c); +} + + +void +codec_set_active(gchar * codec_name) +{ + codec_t * c = codec_list_get(codec_name); + if(c) + c->is_active = TRUE; +} + +void +codec_set_inactive(gchar * codec_name) +{ + codec_t * c = codec_list_get(codec_name); + if(c) + c->is_active = FALSE; +} + +guint +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_nth(guint index) +{ + return g_queue_peek_nth(codecQueue, index); +} + +void +codec_set_prefered_order(guint index) +{ + codec_t * prefered = codec_list_get_nth(index); + g_queue_pop_nth(codecQueue, index); + g_queue_push_head(codecQueue, prefered); +} + diff --git a/sflphone-gtk/src/codeclist.h b/sflphone-gtk/src/codeclist.h new file mode 100644 index 0000000000..d083231bbe --- /dev/null +++ b/sflphone-gtk/src/codeclist.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.net> + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __CODECLIST_H__ +#define __CODECLIST_H__ + +#include <gtk/gtk.h> +/** @file codeclist.h + * @brief A list to hold codecs. + */ + +typedef struct { + gchar * name; + guint sample_rate; + gboolean is_active; +}codec_t; + +void codec_list_init(); +void codec_list_add(codec_t * c); +void codec_set_active(gchar * codec_name); +void codec_set_inactive(gchar * codec_name); +guint codec_list_get_size(); +codec_t * codec_list_get(const gchar * codec_name); +codec_t* codec_list_get_nth(guint index); + +/** + * Set the prefered codec first in the codec list + * @param index The position in the list of the prefered codec + */ +void codec_set_prefered_order(guint index); +//gchar * codec_get_name(codec_t * c); +//guint codec_get_rate(gchar * codec_name); + +#endif diff --git a/sflphone-gtk/src/configurationmanager-glue.h b/sflphone-gtk/src/configurationmanager-glue.h index b000ecbce3..f4b3d0133e 100644 --- a/sflphone-gtk/src/configurationmanager-glue.h +++ b/sflphone-gtk/src/configurationmanager-glue.h @@ -353,10 +353,10 @@ static inline #endif gboolean -org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order (DBusGProxy *proxy, const char ** IN_ringtone, GError **error) +org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order (DBusGProxy *proxy, const char * IN_codec_name, GError **error) { - return dbus_g_proxy_call (proxy, "setCodecPreferedOrder", error, G_TYPE_STRV, IN_ringtone, G_TYPE_INVALID, G_TYPE_INVALID); + return dbus_g_proxy_call (proxy, "setCodecPreferedOrder", error, G_TYPE_STRING, IN_codec_name, G_TYPE_INVALID, G_TYPE_INVALID); } typedef void (*org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order_reply) (DBusGProxy *proxy, GError *error, gpointer userdata); @@ -376,36 +376,36 @@ static inline #endif DBusGProxyCall* -org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order_async (DBusGProxy *proxy, const char ** IN_ringtone, org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order_reply callback, gpointer userdata) +org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order_async (DBusGProxy *proxy, const char * IN_codec_name, org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order_reply callback, gpointer userdata) { DBusGAsyncData *stuff; stuff = g_new (DBusGAsyncData, 1); stuff->cb = G_CALLBACK (callback); stuff->userdata = userdata; - return dbus_g_proxy_begin_call (proxy, "setCodecPreferedOrder", org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order_async_callback, stuff, g_free, G_TYPE_STRV, IN_ringtone, G_TYPE_INVALID); + return dbus_g_proxy_begin_call (proxy, "setCodecPreferedOrder", org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order_async_callback, stuff, g_free, G_TYPE_STRING, IN_codec_name, G_TYPE_INVALID); } static #ifdef G_HAVE_INLINE inline #endif gboolean -org_sflphone_SFLphone_ConfigurationManager_get_codec_prefered_order (DBusGProxy *proxy, char *** OUT_ringtone, GError **error) +org_sflphone_SFLphone_ConfigurationManager_get_codec_prefered_order (DBusGProxy *proxy, char ** OUT_codec_name, GError **error) { - return dbus_g_proxy_call (proxy, "getCodecPreferedOrder", error, G_TYPE_INVALID, G_TYPE_STRV, OUT_ringtone, G_TYPE_INVALID); + return dbus_g_proxy_call (proxy, "getCodecPreferedOrder", error, G_TYPE_INVALID, G_TYPE_STRING, OUT_codec_name, G_TYPE_INVALID); } -typedef void (*org_sflphone_SFLphone_ConfigurationManager_get_codec_prefered_order_reply) (DBusGProxy *proxy, char * *OUT_ringtone, GError *error, gpointer userdata); +typedef void (*org_sflphone_SFLphone_ConfigurationManager_get_codec_prefered_order_reply) (DBusGProxy *proxy, char * OUT_codec_name, GError *error, gpointer userdata); static void org_sflphone_SFLphone_ConfigurationManager_get_codec_prefered_order_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) { DBusGAsyncData *data = (DBusGAsyncData*) user_data; GError *error = NULL; - char ** OUT_ringtone; - dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRV, &OUT_ringtone, G_TYPE_INVALID); - (*(org_sflphone_SFLphone_ConfigurationManager_get_codec_prefered_order_reply)data->cb) (proxy, OUT_ringtone, error, data->userdata); + char * OUT_codec_name; + dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_codec_name, G_TYPE_INVALID); + (*(org_sflphone_SFLphone_ConfigurationManager_get_codec_prefered_order_reply)data->cb) (proxy, OUT_codec_name, error, data->userdata); return; } diff --git a/sflphone-gtk/src/configwindow.c b/sflphone-gtk/src/configwindow.c index c411a750c5..3459016e20 100644 --- a/sflphone-gtk/src/configwindow.c +++ b/sflphone-gtk/src/configwindow.c @@ -74,25 +74,25 @@ config_window_fill_account_list () config_window_fill_codec_list() { - if(dialogOpen) - { - GtkTreeIter iter; - - gtk_list_store_clear(codec_store); - //gchar * description = "Select a codec:"; - //gtk_list_store_append(codec_store, &iter); - //gtk_list_store_set(codec_store, &iter, 0, description, -1); - int i=0; - gchar** codecs = (gchar**)dbus_codec_list(); - while(codecs[i]!=NULL) - { - gtk_list_store_append (codec_store, &iter); - gtk_list_store_set(codec_store, &iter,0,codecs[i],-1); - i++; - } - - } - + if(dialogOpen) + { + GtkTreeIter iter; + int i; + gtk_list_store_clear(codec_store); + gchar * description = "Select a codec:"; + //gtk_list_store_append(codec_store, &iter); + //gtk_list_store_set(codec_store, &iter, 0, description, -1); + for(i=0; i<codec_list_get_size(); i++) + { + codec_t* c = codec_list_get_nth(i); + printf("%s\n",c->name); + if(c) + { + gtk_list_store_append (codec_store, &iter); + gtk_list_store_set(codec_store, &iter,0,c->name,-1); + } + } + } } /** @@ -178,12 +178,8 @@ select_codec( GtkComboBox* wid) guint item = gtk_combo_box_get_active(wid); /* now we want this selected codec to be used as the preferred codec */ /* ie first in the list in the user config */ - gchar** codecs = (gchar**)dbus_codec_list(); - gchar* tmp; - tmp = codecs[0]; - codecs[0] = codecs[item]; - codecs[item]=tmp; - dbus_set_prefered_codec(codecs); + codec_set_prefered_order(item); + dbus_set_prefered_codec(codec_list_get_nth(0)->name); } void diff --git a/sflphone-gtk/src/dbus.c b/sflphone-gtk/src/dbus.c index ddaffbdf89..53a3357620 100644 --- a/sflphone-gtk/src/dbus.c +++ b/sflphone-gtk/src/dbus.c @@ -689,14 +689,14 @@ dbus_codec_list() } void -dbus_set_prefered_codec(const gchar** codecList) +dbus_set_prefered_codec(const gchar* codec) { g_print("Before"); GError *error = NULL; org_sflphone_SFLphone_ConfigurationManager_set_codec_prefered_order ( configurationManagerProxy, - codecList, + codec, &error); g_print("After"); diff --git a/sflphone-gtk/src/mainwindow.c b/sflphone-gtk/src/mainwindow.c index 1dc42e5ca4..6573bb0831 100644 --- a/sflphone-gtk/src/mainwindow.c +++ b/sflphone-gtk/src/mainwindow.c @@ -36,8 +36,9 @@ GtkWidget * window = NULL; GtkWidget * subvbox = NULL; GtkWidget * dialpad = NULL; GtkWidget * statusBar = NULL; -gboolean showDialpad = FALSE; // true if the dialpad have been showned - +GtkWidget * infoScreen = NULL; +gboolean showDialpad = FALSE; // true if the dialpad have been shown +gboolean showInfoScreen = FALSE; // true if the info screen have been shown /** * Terminate the main loop. @@ -149,9 +150,10 @@ create_main_window () gtk_box_pack_start (GTK_BOX (vbox), subvbox, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/); - widget = create_screen(); + //widget = create_screen(); // TODO Add the screen when we are decided //gtk_box_pack_start (GTK_BOX (subvbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); + widget = create_slider("speaker"); gtk_box_pack_start (GTK_BOX (subvbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); @@ -166,8 +168,7 @@ create_main_window () /* make sure that everything, window and label, are visible */ gtk_widget_show_all (window); - screen_clear(); - + //screen_clear(); // Welcome screen if (account_list_get_size() == 0) { @@ -244,6 +245,22 @@ main_window_dialpad(gboolean show){ showDialpad = show; } +void +main_window_callinfo(gboolean show, call_t* current) +{ + if(show && !showInfoScreen) + { + infoScreen = create_screen(); + gtk_box_pack_start (GTK_BOX (subvbox), infoScreen, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); + gtk_widget_show_all(infoScreen); + screen_set_call(current); + } + else if(!show && showInfoScreen) + { + gtk_container_remove(GTK_CONTAINER (subvbox), infoScreen); + } + showInfoScreen = show; +} void status_bar_message(const gchar * message) diff --git a/sflphone-gtk/src/screen.c b/sflphone-gtk/src/screen.c index b5809fba72..b4f3ecd744 100644 --- a/sflphone-gtk/src/screen.c +++ b/sflphone-gtk/src/screen.c @@ -19,7 +19,7 @@ #include <dialpad.h> #include <screen.h> - +#include <codeclist.h> GtkWidget * label; GtkWidget * hbox; @@ -43,7 +43,8 @@ create_screen() event = gtk_event_box_new (); gtk_widget_modify_bg (event, GTK_STATE_NORMAL, &color); - label = gtk_label_new ("test"); + //label = gtk_label_new ("test"); + label = gtk_label_new(""); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); gtk_misc_set_padding(GTK_MISC(label), 5, 5); gtk_misc_set_alignment(GTK_MISC(label), 0,0); @@ -60,13 +61,16 @@ create_screen() void screen_clear() { - gtk_label_set_markup(GTK_LABEL(label), "<big><b>Welcome to SFLphone</b></big>\n"); + gtk_label_set_markup(GTK_LABEL(label), "<b>CALL INFOS</b>\n"); } void screen_set_call(const call_t * c) { - gchar * markup = g_strconcat("<big><b>", call_get_name(c), "</b></big>\n", call_get_number(c), NULL); + //printf("accountID = %s\ncall to = %s\n", c->accountID, c->to); + //gchar * markup = g_strconcat("<big><b>", call_get_name(c), "</b></big>\n", call_get_number(c), NULL); + gchar * markup = g_strconcat("<b><i>Calling to:</i></b>", "\t", call_get_number(c), + "\n<b><i>Codec:</i></b>", "\t", codec_list_get_nth(0)->name, NULL); gtk_label_set_markup(GTK_LABEL(label), markup); g_free(markup); } diff --git a/src/dbus/configurationmanager-glue.h b/src/dbus/configurationmanager-glue.h index 2050874662..621f9593f2 100644 --- a/src/dbus/configurationmanager-glue.h +++ b/src/dbus/configurationmanager-glue.h @@ -89,12 +89,12 @@ public: }; static ::DBus::IntrospectedArgument setCodecPreferedOrder_args[] = { - { "ringtone", "as", true }, + { "codec_name", "s", true }, { 0, 0, 0 } }; static ::DBus::IntrospectedArgument getCodecPreferedOrder_args[] = { - { "ringtone", "as", false }, + { "codec_name", "s", false }, { 0, 0, 0 } }; static ::DBus::IntrospectedArgument getPlaybackDeviceList_args[] = @@ -191,8 +191,8 @@ public: virtual std::vector< ::DBus::String > getRingtoneList( ) = 0; virtual std::vector< ::DBus::String > getCodecList( ) = 0; virtual std::vector< ::DBus::String > getToneLocaleList( ) = 0; - virtual void setCodecPreferedOrder( const std::vector< ::DBus::String >& ringtone ) = 0; - virtual std::vector< ::DBus::String > getCodecPreferedOrder( ) = 0; + virtual void setCodecPreferedOrder( const ::DBus::String& codec_name ) = 0; + virtual ::DBus::String getCodecPreferedOrder( ) = 0; virtual std::vector< ::DBus::String > getPlaybackDeviceList( ) = 0; virtual std::vector< ::DBus::String > getRecordDeviceList( ) = 0; virtual std::vector< ::DBus::String > getSampleRateList( ) = 0; @@ -313,7 +313,7 @@ private: { ::DBus::MessageIter ri = call.reader(); - std::vector< ::DBus::String > argin1; ri >> argin1; + ::DBus::String argin1; ri >> argin1; setCodecPreferedOrder(argin1); ::DBus::ReturnMessage reply(call); return reply; @@ -322,7 +322,7 @@ private: { ::DBus::MessageIter ri = call.reader(); - std::vector< ::DBus::String > argout1 = getCodecPreferedOrder(); + ::DBus::String argout1 = getCodecPreferedOrder(); ::DBus::ReturnMessage reply(call); ::DBus::MessageIter wi = reply.writer(); wi << argout1; diff --git a/src/dbus/configurationmanager-introspec.xml b/src/dbus/configurationmanager-introspec.xml index 11d733cf5b..fd7c9171be 100644 --- a/src/dbus/configurationmanager-introspec.xml +++ b/src/dbus/configurationmanager-introspec.xml @@ -41,11 +41,11 @@ </method> <method name="setCodecPreferedOrder"> - <arg type="as" name="ringtone" direction="in"/> + <arg type="s" name="codec_name" direction="in"/> </method> <method name="getCodecPreferedOrder"> - <arg type="as" name="ringtone" direction="out"/> + <arg type="s" name="codec_name" direction="out"/> </method> <method name="getPlaybackDeviceList"> diff --git a/src/dbus/configurationmanager.cpp b/src/dbus/configurationmanager.cpp index c5b5445fee..af0573ae1d 100644 --- a/src/dbus/configurationmanager.cpp +++ b/src/dbus/configurationmanager.cpp @@ -106,19 +106,19 @@ ConfigurationManager::getCodecList( ) void -ConfigurationManager::setCodecPreferedOrder( const std::vector< ::DBus::String >& codecList ) +ConfigurationManager::setCodecPreferedOrder( const ::DBus::String& codec_name ) { _debug("ConfigurationManager::setCodecPreferedOrder received\n"); - return Manager::instance().setCodecsOrder(codecList); + Manager::instance().setPreferedCodec(codec_name); } - std::vector< ::DBus::String > + ::DBus::String ConfigurationManager::getCodecPreferedOrder( ) { _debug("ConfigurationManager::getCodecPreferedOrder received\n"); - + return Manager::instance().getPreferedCodec(); } diff --git a/src/dbus/configurationmanager.h b/src/dbus/configurationmanager.h index 0ef4ef4e38..510ff52e58 100644 --- a/src/dbus/configurationmanager.h +++ b/src/dbus/configurationmanager.h @@ -47,8 +47,8 @@ public: std::vector< ::DBus::String > getRingtoneList( ); std::vector< ::DBus::String > getCodecList( ); std::vector< ::DBus::String > getToneLocaleList( ); - void setCodecPreferedOrder( const std::vector< ::DBus::String >& codecList ); - std::vector< ::DBus::String > getCodecPreferedOrder( ); + void setCodecPreferedOrder( const ::DBus::String& codec_name ); + ::DBus::String getCodecPreferedOrder( ); std::vector< ::DBus::String > getPlaybackDeviceList( ); std::vector< ::DBus::String > getRecordDeviceList( ); std::vector< ::DBus::String > getSampleRateList( ); diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index d62670fa81..f4188f6b95 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -1100,40 +1100,52 @@ ManagerImpl::initAudioCodec (void) * Set prefered codec order */ void -ManagerImpl::setCodecsOrder(const std::vector< ::DBus::String >& codecs) -{ - // TODO: set codecs using the list. - - /* S'assurer ici de sauvegarderl es codecs aussi dans la configuration - * (appeler saveConfig ?), et de sauver pour les Codecs, le _codecName - * de chaque codec, et non pas la _description. Faut s'assurer de ça - * auprès de D-Bus aussi.*/ - std::vector<std::string> list = codecs; +ManagerImpl::setPreferedCodec(const ::DBus::String& codec_name) +{ + std::vector<std::string> list = getCodecList(); + std::string tmp; + int i=0; + while(list[i] != codec_name) + i++; + tmp = list[0]; + list[0] = list[i]; + list[i] = tmp; _codecDescriptorMap.setActive(list[0]); _codecDescriptorMap.setInactive(list[1]); _codecDescriptorMap.setInactive(list[2]); setConfig("Audio", "Codecs.codec1", list[0]); setConfig("Audio", "Codecs.codec2", list[1]); setConfig("Audio", "Codecs.codec3", list[2]); +} + +std::string +ManagerImpl::getPreferedCodec() +{ + return getConfigString(AUDIO, "Codecs.codec1"); +} +std::vector <std::string> +ManagerImpl::getDefaultCodecList( void ) +{ + std::vector< std::string > v; + v.push_back(DFT_CODEC1); // G711u + v.push_back(DFT_CODEC2); // G711a + v.push_back(DFT_CODEC3); // GSM + return v; } + /** - * Get the list of codecs + * Get the list of codecs. + * Contains all the codecs supported, with order set by the user. */ std::vector< std::string > ManagerImpl::getCodecList( void ) { std::vector< std::string > v; - std::string codec; - - codec = getConfigString(AUDIO, "Codecs.codec1"); - v.push_back(codec); - codec = getConfigString(AUDIO, "Codecs.codec2"); - v.push_back(codec); - codec = getConfigString(AUDIO, "Codecs.codec3"); - v.push_back(codec); - + v.push_back(getConfigString(AUDIO, "Codecs.codec1")); + v.push_back( getConfigString(AUDIO, "Codecs.codec2")); + v.push_back( getConfigString(AUDIO, "Codecs.codec3")); return v; } diff --git a/src/managerimpl.h b/src/managerimpl.h index 3b6e128485..7c14f20700 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -264,16 +264,27 @@ public: * Set the prefered order for codecs. * Called by D-Bus command: "setCodecPreferedOrder" * - * @param codecs A list of strings ("codecName"s) of the codecs. + * @param codec_name The name of the prefered codec. */ - void setCodecsOrder(const std::vector< ::DBus::String >& codecs); + void setPreferedCodec(const ::DBus::String& codec_name); +/** + * Get the prefered codec + * @return The name of the prefered codec + */ + std::string getPreferedCodec( ); + /** - * Get the list of codecs we supports + * Get the list of codecs we supports, ordered by the user * @ return The list of the codecs */ std::vector< ::DBus::String > getCodecList( void ); + /** + * Get the default list of codecs we supports + * @ return The list of the codecs + */ + std::vector< ::DBus::String > getDefaultCodecList( void ); /* -- GitLab