diff --git a/sflphone-client-gnome/.settings/org.eclipse.cdt.core.prefs b/sflphone-client-gnome/.settings/org.eclipse.cdt.core.prefs index 7c854e89f13800abc972b7dda44727d6577f5049..ed89bea14460d0c3a260f4b65a05db93ab7ed0e5 100644 --- a/sflphone-client-gnome/.settings/org.eclipse.cdt.core.prefs +++ b/sflphone-client-gnome/.settings/org.eclipse.cdt.core.prefs @@ -1,4 +1,4 @@ -#Tue Feb 23 14:32:32 EST 2010 +#Fri Feb 26 15:32:40 EST 2010 eclipse.preferences.version=1 org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration=80 @@ -124,8 +124,8 @@ org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch=insert org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification=insert org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for=insert org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=insert +org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=insert org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch=insert org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while=insert diff --git a/sflphone-client-gnome/.settings/org.eclipse.cdt.ui.prefs b/sflphone-client-gnome/.settings/org.eclipse.cdt.ui.prefs index 9281ecd41f6b758197d07f8869691d0953314ea4..c3a02722d10ec788e674fbee2750915052b6a0d7 100644 --- a/sflphone-client-gnome/.settings/org.eclipse.cdt.ui.prefs +++ b/sflphone-client-gnome/.settings/org.eclipse.cdt.ui.prefs @@ -1,4 +1,4 @@ -#Thu Mar 26 14:05:05 EDT 2009 +#Fri Feb 26 15:30:12 EST 2010 eclipse.preferences.version=1 -formatter_profile=org.eclipse.cdt.ui.default.gnu_profile +formatter_profile=_GNU - SFLphone formatter_settings_version=1 diff --git a/sflphone-client-gnome/src/config/preferencesdialog.c b/sflphone-client-gnome/src/config/preferencesdialog.c index c5f6db485d78c7aa4b13cbbdc5a3437c984af6c4..710ff0f640ca8f8c2ed04848c271e28e34aac9da 100644 --- a/sflphone-client-gnome/src/config/preferencesdialog.c +++ b/sflphone-client-gnome/src/config/preferencesdialog.c @@ -51,483 +51,273 @@ GtkWidget * history_value; GtkWidget * status; +GtkWidget *showstatusicon; +GtkWidget *starthidden; +GtkWidget *popupwindow; +GtkWidget *neverpopupwindow; + static int history_limit; static gboolean history_enabled = TRUE; -static void set_md5_hash_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) { - - gboolean enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - dbus_set_md5_credential_hashing(enabled); +static void +set_md5_hash_cb (GtkWidget *widget UNUSED, gpointer data UNUSED) +{ + + gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)); + dbus_set_md5_credential_hashing (enabled); } - static void -start_hidden( void ) +static void +start_hidden (void) { - dbus_start_hidden(); + dbus_start_hidden (); } -static void set_popup_mode (GtkWidget *widget, gpointer *userdata) +static void +set_popup_mode (GtkWidget *widget, gpointer *userdata) { - if (dbus_popup_mode () || gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) - dbus_switch_popup_mode (); + if (dbus_popup_mode () || gtk_toggle_button_get_active ( + GTK_TOGGLE_BUTTON (widget))) + dbus_switch_popup_mode (); } - - void -set_notif_level( ) +void +set_notif_level () { - dbus_set_notify(); + dbus_set_notify (); } -static void history_limit_cb (GtkSpinButton *button, void *ptr) +static void +history_limit_cb (GtkSpinButton *button, void *ptr) { - history_limit = gtk_spin_button_get_value_as_int((GtkSpinButton *)(ptr)); + history_limit = gtk_spin_button_get_value_as_int ((GtkSpinButton *) (ptr)); } -static void history_enabled_cb (GtkWidget *widget) +static void +history_enabled_cb (GtkWidget *widget) { - history_enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); - gtk_widget_set_sensitive (GTK_WIDGET (history_value), history_enabled); + history_enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + gtk_widget_set_sensitive (GTK_WIDGET (history_value), history_enabled); - // Toggle it through D-Bus - dbus_set_history_enabled (); + // Toggle it through D-Bus + dbus_set_history_enabled (); } - void -clean_history( void ) +void +clean_history (void) { - calllist_clean_history(); + calllist_clean_history (); } +void showstatusicon_cb (GtkWidget *widget, gpointer data) { -/* -//static void show_advanced_zrtp_options_cb(GtkWidget *widget UNUSED, gpointer data) -//{ -// DEBUG("Advanced options for ZRTP"); -// show_advanced_zrtp_options((GHashTable *) data); -//} -// -//static void show_advanced_tls_options_cb(GtkWidget *widget UNUSED, gpointer data) -//{ -// DEBUG("Advanced options for TLS"); -// show_advanced_tls_options((GHashTable *) data); -//} -// -//static void key_exchange_changed_cb(GtkWidget *widget, gpointer data) -//{ -// DEBUG("Key exchange changed"); -// if (g_strcasecmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget)), (gchar *) "ZRTP") == 0) { -// gtk_widget_set_sensitive(GTK_WIDGET(data), TRUE); -// g_hash_table_replace(directIpCallsProperties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true")); -// g_hash_table_replace(directIpCallsProperties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(ZRTP)); -// } -// else if (g_strcasecmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget)), (gchar *) "SDES") == 0) { -// gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE); -// g_hash_table_replace(directIpCallsProperties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("true")); -// g_hash_table_replace(directIpCallsProperties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(SDES)); -// } -// else { -// gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE); -// DEBUG("Setting key exchange %s to %s\n", ACCOUNT_KEY_EXCHANGE, KEY_EXCHANGE_NONE); -// g_hash_table_replace(directIpCallsProperties, g_strdup(ACCOUNT_SRTP_ENABLED), g_strdup("false")); -// g_hash_table_replace(directIpCallsProperties, g_strdup(ACCOUNT_KEY_EXCHANGE), g_strdup(KEY_EXCHANGE_NONE)); -// } -//} -// -//static void use_sip_tls_cb(GtkWidget *widget, gpointer data) -//{ -// if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { -// DEBUG("Using sips"); -// gtk_widget_set_sensitive(GTK_WIDGET(data), TRUE); -// g_hash_table_replace(directIpCallsProperties, -// g_strdup(TLS_ENABLE), g_strdup("true")); -// } else { -// gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE); -// g_hash_table_replace(directIpCallsProperties, -// g_strdup(TLS_ENABLE), g_strdup("false")); -// } -//} -// -// -//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_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) -//{ -// DEBUG("ip2ip_local_port_changed_cb\n"); -// gint new_port = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget)); -// DEBUG("new_port %i", new_port); -// g_hash_table_replace(directIpCallsProperties, -// g_strdup(LOCAL_PORT), g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_SPIN_BUTTON(widget))))); -//} -// -// -//GtkWidget* create_direct_ip_calls_tab() -//{ -// GtkWidget * frame; -// GtkWidget * table; -// GtkWidget * label; -// GtkWidget * explanationLabel; -// -// GtkWidget * localPortLabel; -// // GtkWidget * localPortSpinBox; -// GtkWidget * localAddressLabel; -// // GtkWidget * localAddressCombo; -// -// GtkWidget * keyExchangeCombo; -// GtkWidget * advancedZrtpButton; -// GtkWidget * useSipTlsCheckBox; -// -// gchar * curSRTPEnabled = "false"; -// gchar * curTlsEnabled = "false"; -// gchar * curKeyExchange = "0"; -// gchar * description; -// -// gchar * local_interface; -// gchar * local_address; -// gchar * local_port; -// -// //directIpCallsProperties = sflphone_get_ip2ip_properties(); -// sflphone_get_ip2ip_properties (&directIpCallsProperties); -// -// if(directIpCallsProperties != NULL) { -// DEBUG("got a directIpCallsProperties"); -// local_interface = g_hash_table_lookup(directIpCallsProperties, LOCAL_INTERFACE); -// local_port = g_hash_table_lookup(directIpCallsProperties, LOCAL_PORT); -// DEBUG(" local interface = %s", local_interface); -// DEBUG(" local port = %s", local_port); -// curSRTPEnabled = g_hash_table_lookup(directIpCallsProperties, ACCOUNT_SRTP_ENABLED); -// DEBUG(" curSRTPEnabled = %s", curSRTPEnabled); -// curKeyExchange = g_hash_table_lookup(directIpCallsProperties, ACCOUNT_KEY_EXCHANGE); -// curTlsEnabled = g_hash_table_lookup(directIpCallsProperties, TLS_ENABLE); -// } -// -// -// -// GtkWidget * vbox = gtk_vbox_new(FALSE, 10); -// gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); -// -// description = g_markup_printf_escaped(_("This profile is used when you want to reach a remote peer simply by typing a sip URI such as <b>sip:remotepeer</b>. The settings you define here will also be used if no account can be matched to an incoming or outgoing call.")); -// explanationLabel = gtk_label_new(NULL); -// gtk_label_set_markup(GTK_LABEL(explanationLabel), description); -// gtk_misc_set_alignment(GTK_MISC(explanationLabel), 0, 0.5); -// gtk_box_pack_start(GTK_BOX(vbox), explanationLabel, FALSE, FALSE, 0); -// -// /** -// * Network Interface Section -// */ -// gnome_main_section_new_with_table (_("Network Interface"), &frame, &table, 2, 3); -// gtk_container_set_border_width (GTK_CONTAINER(table), 10); -// gtk_table_set_row_spacings (GTK_TABLE(table), 10); -// gtk_table_set_col_spacings( GTK_TABLE(table), 10); -// gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0); -// -// /** -// * Retreive the list of IP interface from the -// * the daemon and build the combo box. -// */ -// -// GtkListStore * ipInterfaceListStore; -// GtkTreeIter iter; -// -// ipInterfaceListStore = gtk_list_store_new( 1, G_TYPE_STRING ); -// localAddressLabel = gtk_label_new_with_mnemonic (_("Local address")); -// gtk_table_attach ( GTK_TABLE( table ), localAddressLabel, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); -// gtk_misc_set_alignment(GTK_MISC (localAddressLabel), 0, 0.5); -// -// GtkTreeIter current_local_address_iter = iter; -// gchar ** iface_list = NULL; -// // iface_list = (gchar**) dbus_get_all_ip_interface(); -// iface_list = (gchar**) dbus_get_all_ip_interface_by_name(); -// gchar ** iface; -// -// gboolean iface_found = FALSE; -// -// if (iface_list != NULL) { -// -// for (iface = iface_list; *iface; iface++) { -// gtk_list_store_append(ipInterfaceListStore, &iter ); -// gtk_list_store_set(ipInterfaceListStore, &iter, 0, *iface, -1 ); -// -// if (!iface_found && (g_strcmp0(*iface, local_interface) == 0)) { -// DEBUG("Setting active local address combo box"); -// current_local_address_iter = iter; -// iface_found = TRUE; -// } -// } -// -// if(!iface_found) { -// DEBUG("Did not find local ip address, take fisrt in the list"); -// gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ipInterfaceListStore), ¤t_local_address_iter); -// } -// } -// -// -// -// -// localAddressCombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ipInterfaceListStore)); -// gtk_label_set_mnemonic_widget(GTK_LABEL(localAddressLabel), localAddressCombo); -// gtk_table_attach ( GTK_TABLE( table ), localAddressCombo, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); -// g_object_unref(G_OBJECT(ipInterfaceListStore)); -// -// GtkCellRenderer * ipInterfaceCellRenderer; -// ipInterfaceCellRenderer = gtk_cell_renderer_text_new(); -// gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(localAddressCombo), ipInterfaceCellRenderer, TRUE); -// gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(localAddressCombo), ipInterfaceCellRenderer, "text", 0, NULL); -// gtk_combo_box_set_active_iter(GTK_COMBO_BOX(localAddressCombo), ¤t_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_INTERFACE), g_strdup((gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(localAddressCombo)))); -// -// -// /** -// * Local port -// */ -// /** SIP port information */ -// localPortLabel = gtk_label_new_with_mnemonic (_("Local port")); -// gtk_table_attach_defaults(GTK_TABLE(table), localPortLabel, 0, 1, 1, 2); -// -// gtk_misc_set_alignment(GTK_MISC (localPortLabel), 0, 0.5); -// localPortSpinBox = gtk_spin_button_new_with_range(1, 65535, 1); -// gtk_label_set_mnemonic_widget (GTK_LABEL (localPortLabel), localPortSpinBox); -// gtk_spin_button_set_value(GTK_SPIN_BUTTON(localPortSpinBox), g_ascii_strtod(local_port, NULL)); -// -// gtk_table_attach_defaults(GTK_TABLE(table), localPortSpinBox, 1, 2, 1, 2); -// g_signal_connect (G_OBJECT(localPortSpinBox), "changed", G_CALLBACK (ip2ip_local_port_changed_cb), localPortSpinBox); -// -// -// GtkWidget *applyModificationButton = gtk_button_new_from_stock(GTK_STOCK_APPLY); -// // g_signal_connect( G_OBJECT(applyModificationButton) , "clicked" , G_CALLBACK( update_ip_address_port_cb ), localPortSpinBox); -// gtk_table_attach( GTK_TABLE(table), applyModificationButton, 2, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); -// -// -// /** -// * Security Section -// */ -// gnome_main_section_new_with_table (_("Security"), &frame, &table, 2, 3); -// gtk_container_set_border_width (GTK_CONTAINER(table), 10); -// gtk_table_set_row_spacings (GTK_TABLE(table), 10); -// gtk_table_set_col_spacings( GTK_TABLE(table), 10); -// gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0); -// -// GtkWidget * sipTlsAdvancedButton; -// sipTlsAdvancedButton = gtk_button_new_from_stock(GTK_STOCK_EDIT); -// gtk_table_attach_defaults(GTK_TABLE(table), sipTlsAdvancedButton, 2, 3, 0, 1); -// gtk_widget_set_sensitive(GTK_WIDGET(sipTlsAdvancedButton), FALSE); -// g_signal_connect(G_OBJECT(sipTlsAdvancedButton), "clicked", G_CALLBACK(show_advanced_tls_options_cb), directIpCallsProperties); -// -// useSipTlsCheckBox = gtk_check_button_new_with_mnemonic(_("Use TLS transport (sips)")); -// g_signal_connect (useSipTlsCheckBox, "toggled", G_CALLBACK(use_sip_tls_cb), sipTlsAdvancedButton); -// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(useSipTlsCheckBox), (g_strcmp0(curTlsEnabled, "false") == 0) ? FALSE:TRUE); -// gtk_table_attach_defaults(GTK_TABLE(table), useSipTlsCheckBox, 0, 2, 0, 1); -// -// label = gtk_label_new_with_mnemonic (_("SRTP key exchange")); -// gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); -// keyExchangeCombo = gtk_combo_box_new_text(); -// gtk_label_set_mnemonic_widget (GTK_LABEL (label), keyExchangeCombo); -// gtk_combo_box_append_text(GTK_COMBO_BOX(keyExchangeCombo), "ZRTP"); -// gtk_combo_box_append_text(GTK_COMBO_BOX(keyExchangeCombo), "SDES"); -// gtk_combo_box_append_text(GTK_COMBO_BOX(keyExchangeCombo), _("Disabled")); -// -// advancedZrtpButton = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES); -// g_signal_connect(G_OBJECT(advancedZrtpButton), "clicked", G_CALLBACK(show_advanced_zrtp_options_cb), directIpCallsProperties); -// -// if (g_strcasecmp(curKeyExchange, ZRTP) == 0) { -// gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo),0); -// } -// else if(g_strcasecmp(curKeyExchange, SDES) == 0) { -// gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo),1); -// } -// else { -// gtk_combo_box_set_active(GTK_COMBO_BOX(keyExchangeCombo), 2); -// gtk_widget_set_sensitive(GTK_WIDGET(advancedZrtpButton), FALSE); -// } -// -// g_signal_connect (G_OBJECT (GTK_COMBO_BOX(keyExchangeCombo)), "changed", G_CALLBACK (key_exchange_changed_cb), advancedZrtpButton); -// -// gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); -// gtk_table_attach_defaults(GTK_TABLE(table), keyExchangeCombo, 1, 2, 1, 2); -// gtk_table_attach_defaults(GTK_TABLE(table), advancedZrtpButton, 2, 3, 1, 2); -// -// gtk_widget_show_all(table); -// -// GtkRequisition requisition; -// gtk_widget_size_request(GTK_WIDGET(table), &requisition); -// gtk_widget_set_size_request(GTK_WIDGET(explanationLabel), requisition.width * 1.5, -1); -// gtk_label_set_line_wrap(GTK_LABEL(explanationLabel), TRUE); -// -// gtk_widget_show_all(vbox); -// -// return vbox; -//} -// - -GtkWidget* create_general_settings () { - - GtkWidget *ret; - - GtkWidget *notifAll; - - GtkWidget *trayItem; - GtkWidget *frame; - GtkWidget *checkBoxWidget; - GtkWidget *label; - GtkWidget *table; - - // Load history configuration - history_load_configuration (); - - // Main widget - ret = gtk_vbox_new(FALSE, 10); - gtk_container_set_border_width(GTK_CONTAINER(ret), 10); - - // Notifications Frame - gnome_main_section_new_with_table (_("Desktop Notifications"), &frame, &table, 2, 1); - gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0); - - // Notification All - notifAll = gtk_check_button_new_with_mnemonic( _("_Enable notifications")); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(notifAll), dbus_get_notify() ); - g_signal_connect(G_OBJECT( notifAll ) , "clicked" , G_CALLBACK( set_notif_level ) , NULL ); - gtk_table_attach( GTK_TABLE(table), notifAll, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - - // System Tray option frame - gnome_main_section_new_with_table (_("System Tray Icon"), &frame, &table, 3, 1); - gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0); - - GtkWidget* trayItem1 = gtk_radio_button_new_with_mnemonic(NULL, _("_Popup main window on incoming call")); - g_signal_connect(G_OBJECT (trayItem1), "toggled", G_CALLBACK (set_popup_mode), NULL); - gtk_table_attach( GTK_TABLE(table), trayItem1, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - - trayItem = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON(trayItem1), _("Ne_ver popup main window")); - gtk_table_attach( GTK_TABLE(table), trayItem, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - - // Toggle according to the user configuration - dbus_popup_mode () ? gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (trayItem1), TRUE) : gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (trayItem), TRUE); - - trayItem = gtk_check_button_new_with_mnemonic(_("Hide SFLphone window on _startup")); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(trayItem), dbus_is_start_hidden() ); - g_signal_connect(G_OBJECT( trayItem ) , "clicked" , G_CALLBACK( start_hidden ) , NULL); - gtk_table_attach( GTK_TABLE(table), trayItem, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - - // HISTORY CONFIGURATION - gnome_main_section_new_with_table (_("Calls History"), &frame, &table, 3, 1); - gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0); - - checkBoxWidget = gtk_check_button_new_with_mnemonic(_("_Keep my history for at least")); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkBoxWidget), history_enabled); - g_signal_connect (G_OBJECT (checkBoxWidget) , "clicked" , G_CALLBACK (history_enabled_cb) , NULL); - gtk_table_attach( GTK_TABLE(table), checkBoxWidget, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - - history_value = gtk_spin_button_new_with_range(1, 99, 1); - gtk_spin_button_set_value (GTK_SPIN_BUTTON(history_value), history_limit); - g_signal_connect( G_OBJECT (history_value) , "value-changed" , G_CALLBACK (history_limit_cb) , history_value); - gtk_widget_set_sensitive (GTK_WIDGET (history_value), gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkBoxWidget))); - gtk_table_attach( GTK_TABLE(table), history_value, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - - label = gtk_label_new(_("days")); - gtk_table_attach( GTK_TABLE(table), label, 2, 3, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - - // Configuration File - // Commented out because not functional yet - /* - gnome_main_section_new_with_table (_("Configuration File"), &frame, &table, 1, 1); - gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0); - checkBoxWidget = gtk_check_button_new_with_mnemonic(_("Store SIP credentials as MD5 hash")); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(checkBoxWidget), dbus_is_md5_credential_hashing() ); - g_signal_connect(G_OBJECT( checkBoxWidget ) , "clicked" , G_CALLBACK(set_md5_hash_cb) , NULL); - gtk_table_attach( GTK_TABLE(table), checkBoxWidget, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); - */ - - gtk_widget_show_all(ret); - - return ret; + gboolean currentstatus = FALSE; + + // data contains the previous value of dbus_is_status_icon_enabled () - ie before the click. + currentstatus = (gboolean) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + + // Update the widget states + gtk_widget_set_sensitive (GTK_WIDGET (popupwindow), currentstatus); + gtk_widget_set_sensitive (GTK_WIDGET (neverpopupwindow), currentstatus); + gtk_widget_set_sensitive (GTK_WIDGET (starthidden), currentstatus); + + currentstatus ? show_status_icon () : hide_status_icon (); + + // Update through D-Bus + dbus_enable_status_icon (currentstatus ? "true" : "false"); } -void save_configuration_parameters (void) { - // Address book config - addressbook_config_save_parameters (); - hooks_save_parameters (); +GtkWidget* +create_general_settings () +{ + + GtkWidget *ret, *notifAll, *trayItem, *frame, *checkBoxWidget, *label, *table; + gboolean statusicon = FALSE; + + // Load history configuration + history_load_configuration (); + + // Main widget + ret = gtk_vbox_new (FALSE, 10); + gtk_container_set_border_width (GTK_CONTAINER(ret), 10); + + // Notifications Frame + gnome_main_section_new_with_table (_("Desktop Notifications"), &frame, + &table, 2, 1); + gtk_box_pack_start (GTK_BOX(ret), frame, FALSE, FALSE, 0); + + // Notification All + notifAll = gtk_check_button_new_with_mnemonic (_("_Enable notifications")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(notifAll), dbus_get_notify ()); + g_signal_connect(G_OBJECT( notifAll ) , "clicked" , G_CALLBACK( set_notif_level ) , NULL ); + gtk_table_attach (GTK_TABLE(table), notifAll, 0, 1, 0, 1, GTK_EXPAND + | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); + + // System Tray option frame + gnome_main_section_new_with_table (_("System Tray Icon"), &frame, &table, 4, + 1); + gtk_box_pack_start (GTK_BOX(ret), frame, FALSE, FALSE, 0); + + if (g_strcasecmp (dbus_is_status_icon_enabled (), "true") == 0) + statusicon = TRUE; + else + statusicon = FALSE; + + showstatusicon = gtk_check_button_new_with_mnemonic ( + _("Show SFLphone in the system tray")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(showstatusicon), statusicon); + g_signal_connect (G_OBJECT (showstatusicon) , "clicked" , G_CALLBACK (showstatusicon_cb), NULL); + gtk_table_attach (GTK_TABLE (table), showstatusicon, 0, 1, 0, 1, GTK_EXPAND + | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); + + popupwindow = gtk_radio_button_new_with_mnemonic (NULL, + _("_Popup main window on incoming call")); + g_signal_connect(G_OBJECT (popupwindow), "toggled", G_CALLBACK (set_popup_mode), NULL); + gtk_table_attach (GTK_TABLE(table), popupwindow, 0, 1, 1, 2, GTK_EXPAND + | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); + + neverpopupwindow = gtk_radio_button_new_with_mnemonic_from_widget ( + GTK_RADIO_BUTTON (popupwindow), _("Ne_ver popup main window")); + gtk_table_attach (GTK_TABLE(table), neverpopupwindow, 0, 1, 2, 3, GTK_EXPAND + | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); + + // Toggle according to the user configuration + dbus_popup_mode () ? gtk_toggle_button_set_active ( + GTK_TOGGLE_BUTTON (popupwindow), TRUE) : gtk_toggle_button_set_active ( + GTK_TOGGLE_BUTTON (neverpopupwindow), TRUE); + + starthidden = gtk_check_button_new_with_mnemonic ( + _("Hide SFLphone window on _startup")); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(starthidden), + dbus_is_start_hidden ()); + g_signal_connect(G_OBJECT (starthidden) , "clicked" , G_CALLBACK( start_hidden ) , NULL); + gtk_table_attach (GTK_TABLE(table), starthidden, 0, 1, 3, 4, GTK_EXPAND + | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); + + // Update the widget states + gtk_widget_set_sensitive (GTK_WIDGET (popupwindow),statusicon); + gtk_widget_set_sensitive (GTK_WIDGET (neverpopupwindow),statusicon); + gtk_widget_set_sensitive (GTK_WIDGET (starthidden),statusicon); + + // HISTORY CONFIGURATION + gnome_main_section_new_with_table (_("Calls History"), &frame, &table, 3, 1); + gtk_box_pack_start (GTK_BOX(ret), frame, FALSE, FALSE, 0); + + checkBoxWidget = gtk_check_button_new_with_mnemonic ( + _("_Keep my history for at least")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkBoxWidget), + history_enabled); + g_signal_connect (G_OBJECT (checkBoxWidget) , "clicked" , G_CALLBACK (history_enabled_cb) , NULL); + gtk_table_attach (GTK_TABLE(table), checkBoxWidget, 0, 1, 0, 1, GTK_EXPAND + | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); + + history_value = gtk_spin_button_new_with_range (1, 99, 1); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(history_value), history_limit); + g_signal_connect( G_OBJECT (history_value) , "value-changed" , G_CALLBACK (history_limit_cb) , history_value); + gtk_widget_set_sensitive (GTK_WIDGET (history_value), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkBoxWidget))); + gtk_table_attach (GTK_TABLE(table), history_value, 1, 2, 0, 1, GTK_EXPAND + | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 5); + + label = gtk_label_new (_("days")); + gtk_table_attach (GTK_TABLE(table), label, 2, 3, 0, 1, GTK_EXPAND | GTK_FILL, + GTK_EXPAND | GTK_FILL, 0, 5); + + gtk_widget_show_all (ret); + + return ret; +} + +void +save_configuration_parameters (void) +{ + + // Address book config + addressbook_config_save_parameters (); + hooks_save_parameters (); - // History config - dbus_set_history_limit (history_limit); + // History config + dbus_set_history_limit (history_limit); - // Direct IP calls config - // dbus_set_ip2ip_details (directIpCallsProperties); + // Direct IP calls config + // dbus_set_ip2ip_details (directIpCallsProperties); } -void history_load_configuration () +void +history_load_configuration () { - history_limit = dbus_get_history_limit (); - history_enabled = TRUE; - if (g_strcasecmp (dbus_get_history_enabled (), "false") == 0) - history_enabled = FALSE; + history_limit = dbus_get_history_limit (); + history_enabled = TRUE; + if (g_strcasecmp (dbus_get_history_enabled (), "false") == 0) + history_enabled = FALSE; } /** * Show configuration window with tabs */ - void +void show_preferences_dialog () { - GtkDialog * dialog; - GtkWidget * notebook; - GtkWidget * tab; - guint result; - - dialogOpen = TRUE; - - dialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Preferences"), - GTK_WINDOW(get_main_window()), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLOSE, - GTK_RESPONSE_ACCEPT, - NULL)); - - // Set window properties - gtk_dialog_set_has_separator(dialog, FALSE); - gtk_window_set_default_size(GTK_WINDOW(dialog), 600, 400); - gtk_container_set_border_width(GTK_CONTAINER(dialog), 0); - - // Create tabs container - 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); - - // General settings tab - tab = create_general_settings(); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("General"))); - gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab); - - // Audio tab - tab = create_audio_configuration(); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Audio"))); - gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab); - - // Addressbook tab - tab = create_addressbook_settings(); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Address Book"))); - gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab); - - // Hooks tab - tab = create_hooks_settings(); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Hooks"))); - gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab); - - gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook) , 0); - - result = gtk_dialog_run(dialog); - - save_configuration_parameters (); - update_actions(); - - dialogOpen = FALSE; - - gtk_widget_destroy(GTK_WIDGET(dialog)); + GtkDialog * dialog; + GtkWidget * notebook; + GtkWidget * tab; + guint result; + + dialogOpen = TRUE; + + dialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Preferences"), + GTK_WINDOW(get_main_window()), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CLOSE, + GTK_RESPONSE_ACCEPT, + NULL)); + + // Set window properties + gtk_dialog_set_has_separator (dialog, FALSE); + gtk_window_set_default_size (GTK_WINDOW(dialog), 600, 400); + gtk_container_set_border_width (GTK_CONTAINER(dialog), 0); + + // Create tabs container + 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); + + // General settings tab + tab = create_general_settings (); + gtk_notebook_append_page (GTK_NOTEBOOK(notebook), tab, gtk_label_new ( + _("General"))); + gtk_notebook_page_num (GTK_NOTEBOOK(notebook), tab); + + // Audio tab + tab = create_audio_configuration (); + gtk_notebook_append_page (GTK_NOTEBOOK(notebook), tab, gtk_label_new ( + _("Audio"))); + gtk_notebook_page_num (GTK_NOTEBOOK(notebook), tab); + + // Addressbook tab + tab = create_addressbook_settings (); + gtk_notebook_append_page (GTK_NOTEBOOK(notebook), tab, gtk_label_new ( + _("Address Book"))); + gtk_notebook_page_num (GTK_NOTEBOOK(notebook), tab); + + // Hooks tab + tab = create_hooks_settings (); + gtk_notebook_append_page (GTK_NOTEBOOK(notebook), tab, gtk_label_new ( + _("Hooks"))); + gtk_notebook_page_num (GTK_NOTEBOOK(notebook), tab); + + gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0); + + result = gtk_dialog_run (dialog); + + save_configuration_parameters (); + update_actions (); + + dialogOpen = FALSE; + + gtk_widget_destroy (GTK_WIDGET(dialog)); } diff --git a/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml b/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml index 3361c16dd5a6b74dd9b6a60241b664b059fa6350..6be7c8b6d3168ecaff8727ba732214bdffa8d150 100644 --- a/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml +++ b/sflphone-client-gnome/src/dbus/configurationmanager-introspec.xml @@ -461,6 +461,15 @@ <arg type="i" name="posY" direction="in"/> </method> + <method name="enableStatusIcon"> + <arg type="s" name="value" direction="in"/> + </method> + + <method name="isStatusIconEnabled"> + <arg type="s" name="value" direction="out"/> + </method> + + <!-- Addressbook configuration --> <method name="getAddressbookSettings"> <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringInt"/> diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c index e4d0f53bfe537a53fd62cb6e4464a79202e21fbf..d0de1d908e2cef00b7c14d20918c91a4340f6395 100644 --- a/sflphone-client-gnome/src/dbus/dbus.c +++ b/sflphone-client-gnome/src/dbus/dbus.c @@ -2580,3 +2580,32 @@ void dbus_set_window_position_y (const guint posy) { } } + +void dbus_enable_status_icon (const gchar *value) { + + GError *error = NULL; + + org_sflphone_SFLphone_ConfigurationManager_enable_status_icon (configurationManagerProxy, value, &error); + + if (error != NULL) { + ERROR ("Failed to call enable_status_icon on ConfigurationManager: %s", + error->message); + g_error_free (error); + } +} + +gchar* dbus_is_status_icon_enabled (void) { + + GError *error = NULL; + gchar* value = TRUE; + + org_sflphone_SFLphone_ConfigurationManager_is_status_icon_enabled (configurationManagerProxy, &value, &error); + + if (error != NULL) { + ERROR ("Failed to call is_status_icon_enabled on ConfigurationManager: %s", + error->message); + g_error_free (error); + } + return value; +} + diff --git a/sflphone-client-gnome/src/dbus/dbus.h b/sflphone-client-gnome/src/dbus/dbus.h index c8dd014f8789afa3891afd3cdb83c69f10734ee0..4aa4af643f528eb12daf8c4fd6ae518eac3d6f46 100644 --- a/sflphone-client-gnome/src/dbus/dbus.h +++ b/sflphone-client-gnome/src/dbus/dbus.h @@ -606,4 +606,8 @@ guint dbus_get_window_position_y (void); void dbus_set_window_position_x (const guint posx); void dbus_set_window_position_y (const guint posy); +void dbus_enable_status_icon (const gchar*); +gchar* dbus_is_status_icon_enabled (void); + + #endif diff --git a/sflphone-client-gnome/src/main.c b/sflphone-client-gnome/src/main.c index fffd9a831b849f5b91b4c97625bd9ff1f2d7f156..33911a7cab14275b0c6d8a630f64060adba2fc24 100644 --- a/sflphone-client-gnome/src/main.c +++ b/sflphone-client-gnome/src/main.c @@ -33,9 +33,9 @@ * Stop logging engine */ static void -shutdown_logging() +shutdown_logging () { - if (log4c_fini()) + if (log4c_fini ()) { ERROR("log4c_fini() failed"); } @@ -45,87 +45,88 @@ shutdown_logging() * Start loggin engine */ static void -startup_logging() +startup_logging () { - log4c_init(); - if (log4c_load(DATA_DIR "/log4crc") == -1) - g_warning("Cannot load log4j configuration file : %s",DATA_DIR "/log4crc"); + log4c_init (); + if (log4c_load (DATA_DIR "/log4crc") == -1) + g_warning ("Cannot load log4j configuration file : %s", DATA_DIR "/log4crc"); - log4c_sfl_gtk_category = log4c_category_get("org.sflphone.gtk"); + log4c_sfl_gtk_category = log4c_category_get ("org.sflphone.gtk"); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { // Handle logging int i; + gboolean statusicon = FALSE; // Startup logging - startup_logging(); + startup_logging (); // Check arguments if debug mode is activated for (i = 0; i < argc; i++) - if (g_strcmp0(argv[i], "--debug") == 0) - log4c_category_set_priority(log4c_sfl_gtk_category, LOG4C_PRIORITY_DEBUG); + if (g_strcmp0 (argv[i], "--debug") == 0) + log4c_category_set_priority (log4c_sfl_gtk_category, LOG4C_PRIORITY_DEBUG); // Start GTK application - gtk_init(&argc, &argv); + gtk_init (&argc, &argv); - g_print("%s %s\n", PACKAGE, VERSION); - g_print("Copyright (c) 2005 2006 2007 2008 2009 Savoir-faire Linux Inc.\n"); - g_print( + g_print ("%s %s\n", PACKAGE, VERSION); + g_print ("Copyright (c) 2005 2006 2007 2008 2009 Savoir-faire Linux Inc.\n"); + g_print ( "This is free software. You may redistribute copies of it under the terms of\n\ the GNU General Public License Version 3 <http://www.gnu.org/licenses/gpl.html>.\n\ There is NO WARRANTY, to the extent permitted by law.\n\n"); DEBUG("Logging Started"); - srand(time(NULL)); + srand (time (NULL)); // Internationalization - bindtextdomain("sflphone-client-gnome", LOCALEDIR); - textdomain("sflphone-client-gnome"); + bindtextdomain ("sflphone-client-gnome", LOCALEDIR); + textdomain ("sflphone-client-gnome"); // Initialises the GNOME libraries - gnome_program_init ( "sflphone", VERSION, - LIBGNOMEUI_MODULE, argc, argv, - GNOME_PROGRAM_STANDARD_PROPERTIES, - NULL); + gnome_program_init ("sflphone", VERSION, LIBGNOMEUI_MODULE, argc, argv, + GNOME_PROGRAM_STANDARD_PROPERTIES, + NULL) ; - if (sflphone_init()) + if (sflphone_init ()) { -#if GTK_CHECK_VERSION(2,10,0) - show_status_icon(); -#endif - create_main_window(); -#if GTK_CHECK_VERSION(2,10,0) - if (dbus_is_start_hidden()) + if (g_strcasecmp (dbus_is_status_icon_enabled (), "true") == 0) + statusicon = TRUE; + + if (statusicon) show_status_icon (); + create_main_window (); + + if (statusicon && dbus_is_start_hidden ()) { - gtk_widget_hide(GTK_WIDGET( get_main_window() )); - set_minimized(TRUE); + gtk_widget_hide (GTK_WIDGET( get_main_window() )); + set_minimized (TRUE); } -#endif - status_bar_display_account(); - // Load the history - sflphone_fill_history (); + status_bar_display_account (); + + // Load the history + sflphone_fill_history (); + + // Get the active calls and conferences at startup + sflphone_fill_call_list (); + sflphone_fill_conference_list (); - // Get the active calls and conferences at startup - sflphone_fill_call_list (); - sflphone_fill_conference_list(); + // Update the GUI + update_actions (); - // Update the GUI - update_actions (); - - /* start the main loop */ - gtk_main(); + /* start the main loop */ + gtk_main (); } // Cleanly stop logging - shutdown_logging(); + shutdown_logging (); return 0; } diff --git a/sflphone-client-gnome/src/mainwindow.c b/sflphone-client-gnome/src/mainwindow.c index 6138e7c6373c6ff762098cfd9d998d8da25ccc40..0f34b5df9b82e507dd12d20461ac46be9faeb446 100644 --- a/sflphone-client-gnome/src/mainwindow.c +++ b/sflphone-client-gnome/src/mainwindow.c @@ -37,424 +37,475 @@ /** Local variables */ GtkUIManager *ui_manager = NULL; GtkAccelGroup * accelGroup = NULL; -GtkWidget * window = NULL; -GtkWidget * subvbox = NULL; -GtkWidget * vbox = NULL; -GtkWidget * dialpad = NULL; +GtkWidget * window = NULL; +GtkWidget * subvbox = NULL; +GtkWidget * vbox = NULL; +GtkWidget * dialpad = NULL; GtkWidget * speaker_control = NULL; GtkWidget * mic_control = NULL; GtkWidget * statusBar = NULL; GtkWidget * filterEntry = NULL; PidginScrollBook *embedded_error_notebook; -static gboolean window_configure_cb (GtkWidget *win, GdkEventConfigure *event) { +static gboolean +window_configure_cb (GtkWidget *win, GdkEventConfigure *event) +{ - int pos_x, pos_y; + int pos_x, pos_y; - dbus_set_window_width ( (guint)event->width); - dbus_set_window_height ( (guint)event->height); + dbus_set_window_width ((guint) event->width); + dbus_set_window_height ((guint) event->height); - gtk_window_get_position (GTK_WINDOW (window), &pos_x, &pos_y); - dbus_set_window_position_x ( (guint)pos_x); - dbus_set_window_position_y ( (guint)pos_y); + gtk_window_get_position (GTK_WINDOW (window), &pos_x, &pos_y); + dbus_set_window_position_x ((guint) pos_x); + dbus_set_window_position_y ((guint) pos_y); - return FALSE; + return FALSE; } - /** * Minimize the main window. */ - static gboolean +static gboolean on_delete (GtkWidget * widget UNUSED, gpointer data UNUSED) { -#if GTK_CHECK_VERSION(2,10,0) - gtk_widget_hide(GTK_WIDGET( get_main_window() )); - set_minimized( TRUE ); -#endif - return TRUE; + + if (g_strcasecmp (dbus_is_status_icon_enabled (), "true") == 0) { + gtk_widget_hide (GTK_WIDGET( get_main_window() )); + set_minimized (TRUE); + } + else { + sflphone_quit (); + } + return TRUE; } /** Ask the user if he wants to hangup current calls */ gboolean -main_window_ask_quit(){ - guint count = calllist_get_size(current_calls); - GtkWidget * dialog; - gint response; - gchar * question; - - if(count == 1) - { - question = _("There is one call in progress."); - } - else - { - question = _("There are calls in progress."); - } - - dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(window) , - GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "%s\n%s", - question, - _("Do you still want to quit?") ); - - - response = gtk_dialog_run (GTK_DIALOG (dialog)); - - gtk_widget_destroy (dialog); - if(response == GTK_RESPONSE_YES) - { - return TRUE; - } - else if(response == GTK_RESPONSE_NO) - { - return FALSE; - } - return TRUE; -} +main_window_ask_quit () +{ + guint count = calllist_get_size (current_calls); + GtkWidget * dialog; + gint response; + gchar * question; + if (count == 1) + { + question = _("There is one call in progress."); + } + else + { + question = _("There are calls in progress."); + } + + dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(window), + GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s\n%s", + question, _("Do you still want to quit?") ); + response = gtk_dialog_run (GTK_DIALOG (dialog)); - static gboolean + gtk_widget_destroy (dialog); + if (response == GTK_RESPONSE_YES) + { + return TRUE; + } + else if (response == GTK_RESPONSE_NO) + { + return FALSE; + } + return TRUE; +} + +static gboolean on_key_released (GtkWidget *widget, GdkEventKey *event, gpointer user_data UNUSED) { - DEBUG("On key released from Main Window : %s", gtk_widget_get_name(widget)); - - if (focus_is_on_searchbar == FALSE) { - // If a modifier key is pressed, it's a shortcut, pass along - if(event->state & GDK_CONTROL_MASK || - event->state & GDK_MOD1_MASK || - event->keyval == 60 || // < - event->keyval == 62 || // > - event->keyval == 34 || // " - event->keyval == 65289 || // tab - event->keyval == 65361 || // left arrow - event->keyval == 65363 || // right arrow - event->keyval >= 65470 || // F-keys - event->keyval == 32 // space - ) - return FALSE; - else - sflphone_keypad(event->keyval, event->string); - } - - return TRUE; + DEBUG("On key released from Main Window : %s", gtk_widget_get_name(widget)); + + if (focus_is_on_searchbar == FALSE) + { + // If a modifier key is pressed, it's a shortcut, pass along + if (event->state & GDK_CONTROL_MASK || event->state & GDK_MOD1_MASK + || event->keyval == 60 || // < + event->keyval == 62 || // > + event->keyval == 34 || // " + event->keyval == 65289 || // tab + event->keyval == 65361 || // left arrow + event->keyval == 65363 || // right arrow + event->keyval >= 65470 || // F-keys + event->keyval == 32 // space + ) + return FALSE; + else + sflphone_keypad (event->keyval, event->string); + } + + return TRUE; } void -focus_on_mainwindow_out(){ - // gtk_widget_grab_focus(GTK_WIDGET(window)); +focus_on_mainwindow_out () +{ + // gtk_widget_grab_focus(GTK_WIDGET(window)); } void -focus_on_mainwindow_in(){ - // gtk_widget_grab_focus(GTK_WIDGET(window)); +focus_on_mainwindow_in () +{ + // gtk_widget_grab_focus(GTK_WIDGET(window)); } - - void +void create_main_window () { - GtkWidget *widget; - gchar *path; - GError *error = NULL; - gboolean ret; - const char *window_title = "SFLphone VoIP Client"; - int width, height, position_x, position_y; - - focus_is_on_calltree = FALSE; - focus_is_on_searchbar = FALSE; - - // Get configuration stored - width = dbus_get_window_width (); - height = dbus_get_window_height (); - position_x = dbus_get_window_position_x (); - position_y = dbus_get_window_position_y (); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_container_set_border_width (GTK_CONTAINER (window), 0); - gtk_window_set_title (GTK_WINDOW (window), window_title); - gtk_window_set_default_size (GTK_WINDOW (window), width, height); - gtk_window_set_default_icon_from_file (LOGO, - NULL); - gtk_window_set_position( GTK_WINDOW( window ) , GTK_WIN_POS_MOUSE); - - /* Connect the destroy event of the window with our on_destroy function - * When the window is about to be destroyed we get a notificaiton and - * stop the main GTK loop - */ - g_signal_connect (G_OBJECT (window), "delete-event", - G_CALLBACK (on_delete), NULL); - - g_signal_connect (G_OBJECT (window), "key-release-event", - G_CALLBACK (on_key_released), NULL); - - g_signal_connect_after (G_OBJECT (window), "focus-in-event", - G_CALLBACK (focus_on_mainwindow_in), NULL); - - g_signal_connect_after (G_OBJECT (window), "focus-out-event", - G_CALLBACK (focus_on_mainwindow_out), NULL); - - g_signal_connect_object (G_OBJECT (window), "configure-event", - G_CALLBACK (window_configure_cb), NULL, 0); - - gtk_widget_set_name (window, "mainwindow"); - - ret = uimanager_new (&ui_manager); - if (!ret) + GtkWidget *widget; + gchar *path; + GError *error = NULL; + gboolean ret; + const char *window_title = "SFLphone VoIP Client"; + int width, height, position_x, position_y; + + focus_is_on_calltree = FALSE; + focus_is_on_searchbar = FALSE; + + // Get configuration stored + width = dbus_get_window_width (); + height = dbus_get_window_height (); + position_x = dbus_get_window_position_x (); + position_y = dbus_get_window_position_y (); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + gtk_window_set_title (GTK_WINDOW (window), window_title); + gtk_window_set_default_size (GTK_WINDOW (window), width, height); + gtk_window_set_default_icon_from_file (LOGO, NULL); + gtk_window_set_position (GTK_WINDOW( window ), GTK_WIN_POS_MOUSE); + + /* Connect the destroy event of the window with our on_destroy function + * When the window is about to be destroyed we get a notificaiton and + * stop the main GTK loop + */ + g_signal_connect (G_OBJECT (window), "delete-event", + G_CALLBACK (on_delete), NULL); + + g_signal_connect (G_OBJECT (window), "key-release-event", + G_CALLBACK (on_key_released), NULL); + + g_signal_connect_after (G_OBJECT (window), "focus-in-event", + G_CALLBACK (focus_on_mainwindow_in), NULL); + + g_signal_connect_after (G_OBJECT (window), "focus-out-event", + G_CALLBACK (focus_on_mainwindow_out), NULL); + + g_signal_connect_object (G_OBJECT (window), "configure-event", + G_CALLBACK (window_configure_cb), NULL, 0); + + gtk_widget_set_name (window, "mainwindow"); + + ret = uimanager_new (&ui_manager); + if (!ret) { - ERROR ("Could not load xml GUI\n"); - g_error_free (error); - exit (1); + ERROR ("Could not load xml GUI\n"); + g_error_free (error); + exit (1); } - /* Create an accel group for window's shortcuts */ - gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group (ui_manager)); + /* Create an accel group for window's shortcuts */ + gtk_window_add_accel_group (GTK_WINDOW(window), + gtk_ui_manager_get_accel_group (ui_manager)); + + vbox = gtk_vbox_new (FALSE /*homogeneous*/, 0 /*spacing*/); + subvbox = gtk_vbox_new (FALSE /*homogeneous*/, 5 /*spacing*/); - vbox = gtk_vbox_new ( FALSE /*homogeneous*/, 0 /*spacing*/); - subvbox = gtk_vbox_new ( FALSE /*homogeneous*/, 5 /*spacing*/); + create_menus (ui_manager, &widget); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, + 0 /*padding*/); - create_menus (ui_manager, &widget); - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); + create_toolbar_actions (ui_manager, &widget); + // Do not override GNOME user settings + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, + 0 /*padding*/); - create_toolbar_actions (ui_manager, &widget); - // Do not override GNOME user settings - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - - gtk_box_pack_start (GTK_BOX (vbox), current_calls->tree, TRUE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_box_pack_start (GTK_BOX (vbox), history->tree, TRUE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_box_pack_start (GTK_BOX (vbox), contacts->tree, TRUE /*expand*/, TRUE /*fill*/, 0 /*padding*/); + gtk_box_pack_start (GTK_BOX (vbox), current_calls->tree, TRUE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_box_pack_start (GTK_BOX (vbox), history->tree, TRUE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_box_pack_start (GTK_BOX (vbox), contacts->tree, TRUE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); - gtk_box_pack_start (GTK_BOX (vbox), subvbox, FALSE /*expand*/, FALSE /*fill*/, 0 /*padding*/); + gtk_box_pack_start (GTK_BOX (vbox), subvbox, FALSE /*expand*/, + FALSE /*fill*/, 0 /*padding*/); - embedded_error_notebook = PIDGIN_SCROLL_BOOK(pidgin_scroll_book_new()); - gtk_box_pack_start(GTK_BOX(subvbox), - GTK_WIDGET(embedded_error_notebook), FALSE, FALSE, 0); + embedded_error_notebook = PIDGIN_SCROLL_BOOK(pidgin_scroll_book_new()); + gtk_box_pack_start (GTK_BOX(subvbox), GTK_WIDGET(embedded_error_notebook), + FALSE, FALSE, 0); - if(SHOW_VOLUME){ - speaker_control = create_slider("speaker"); - gtk_box_pack_end (GTK_BOX (subvbox), speaker_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_widget_show_all (speaker_control); - mic_control = create_slider("mic"); - gtk_box_pack_end (GTK_BOX (subvbox), mic_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_widget_show_all (mic_control); - } + if (SHOW_VOLUME) + { + speaker_control = create_slider ("speaker"); + gtk_box_pack_end (GTK_BOX (subvbox), speaker_control, FALSE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_widget_show_all (speaker_control); + mic_control = create_slider ("mic"); + gtk_box_pack_end (GTK_BOX (subvbox), mic_control, FALSE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_widget_show_all (mic_control); + } - if(SHOW_DIALPAD){ - dialpad = create_dialpad(); - gtk_box_pack_end (GTK_BOX (subvbox), dialpad, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_widget_show_all (dialpad); - } + if (SHOW_DIALPAD) + { + dialpad = create_dialpad (); + gtk_box_pack_end (GTK_BOX (subvbox), dialpad, FALSE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_widget_show_all (dialpad); + } - /* Status bar */ - statusBar = gtk_statusbar_new(); - gtk_box_pack_start (GTK_BOX (vbox), statusBar, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_container_add (GTK_CONTAINER (window), vbox); + /* Status bar */ + statusBar = gtk_statusbar_new (); + gtk_box_pack_start (GTK_BOX (vbox), statusBar, FALSE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_container_add (GTK_CONTAINER (window), vbox); - /* make sure that everything, window and label, are visible */ - gtk_widget_show_all (window); + /* make sure that everything, window and label, are visible */ + gtk_widget_show_all (window); - /* dont't show the history */ - gtk_widget_hide(history->tree); + /* dont't show the history */ + gtk_widget_hide (history->tree); - /* dont't show the contact list */ - gtk_widget_hide(contacts->tree); + /* dont't show the contact list */ + gtk_widget_hide (contacts->tree); - searchbar_init(history); - searchbar_init(contacts); + searchbar_init (history); + searchbar_init (contacts); - /* don't show waiting layer */ - gtk_widget_hide(waitingLayer); + /* don't show waiting layer */ + gtk_widget_hide (waitingLayer); - // Configuration wizard - if (account_list_get_size() == 0) - { + // Configuration wizard + if (account_list_get_size () == 0) + { #if GTK_CHECK_VERSION(2,10,0) - build_wizard(); + build_wizard (); #else - GtkWidget * dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_YES_NO, - "<b><big>Welcome to SFLphone!</big></b>\n\nThere are no VoIP accounts configured, would you like to edit the preferences now?"); + GtkWidget * dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_YES_NO, + "<b><big>Welcome to SFLphone!</big></b>\n\nThere are no VoIP accounts configured, would you like to edit the preferences now?"); - int response = gtk_dialog_run (GTK_DIALOG(dialog)); + int response = gtk_dialog_run (GTK_DIALOG(dialog)); - gtk_widget_destroy (GTK_WIDGET(dialog)); + gtk_widget_destroy (GTK_WIDGET(dialog)); - if (response == GTK_RESPONSE_YES) - { - show_preferences_dialog(); - } + if (response == GTK_RESPONSE_YES) + { + show_preferences_dialog(); + } #endif - } + } - // Move the main window - gtk_window_move (GTK_WINDOW (window), position_x, position_y); + // Move the main window + gtk_window_move (GTK_WINDOW (window), position_x, position_y); } - GtkAccelGroup * -get_accel_group() +GtkAccelGroup * +get_accel_group () { - return accelGroup; + return accelGroup; } - GtkWidget * -get_main_window() +GtkWidget * +get_main_window () { - return window; + return window; } void -main_window_message(GtkMessageType type, gchar * markup){ +main_window_message (GtkMessageType type, gchar * markup) +{ - GtkWidget * dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW(get_main_window()), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - type, - GTK_BUTTONS_CLOSE, - NULL); + GtkWidget * dialog = gtk_message_dialog_new_with_markup ( + GTK_WINDOW(get_main_window()), GTK_DIALOG_MODAL + | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_CLOSE, NULL); - gtk_window_set_title(GTK_WINDOW(dialog), _("SFLphone Error")); - gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), markup); + gtk_window_set_title (GTK_WINDOW(dialog), _("SFLphone Error")); + gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG(dialog), markup); - gtk_dialog_run (GTK_DIALOG(dialog)); - gtk_widget_destroy (GTK_WIDGET(dialog)); + gtk_dialog_run (GTK_DIALOG(dialog)); + gtk_widget_destroy (GTK_WIDGET(dialog)); } void -main_window_error_message(gchar * markup){ - main_window_message(GTK_MESSAGE_ERROR, markup); +main_window_error_message (gchar * markup) +{ + main_window_message (GTK_MESSAGE_ERROR, markup); } void -main_window_warning_message(gchar * markup){ - main_window_message(GTK_MESSAGE_WARNING, markup); +main_window_warning_message (gchar * markup) +{ + main_window_message (GTK_MESSAGE_WARNING, markup); } void -main_window_info_message(gchar * markup){ - main_window_message(GTK_MESSAGE_INFO, markup); +main_window_info_message (gchar * markup) +{ + main_window_message (GTK_MESSAGE_INFO, markup); } -void main_window_dialpad (gboolean state){ +void +main_window_dialpad (gboolean state) +{ - g_print ("main_window_dialpad\n"); + g_print ("main_window_dialpad\n"); - if(state) { - dialpad = create_dialpad(); - gtk_box_pack_end (GTK_BOX (subvbox), dialpad, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_widget_show_all (dialpad); - } else { - gtk_container_remove(GTK_CONTAINER (subvbox), dialpad); - } + if (state) + { + dialpad = create_dialpad (); + gtk_box_pack_end (GTK_BOX (subvbox), dialpad, FALSE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_widget_show_all (dialpad); + } + else + { + gtk_container_remove (GTK_CONTAINER (subvbox), dialpad); + } } void -main_window_volume_controls( gboolean state ){ - if(state){ - speaker_control = create_slider("speaker"); - gtk_box_pack_end (GTK_BOX (subvbox), speaker_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_widget_show_all (speaker_control); - mic_control = create_slider("mic"); - gtk_box_pack_end (GTK_BOX (subvbox), mic_control, FALSE /*expand*/, TRUE /*fill*/, 0 /*padding*/); - gtk_widget_show_all (mic_control); - } else { - gtk_container_remove( GTK_CONTAINER(subvbox) , speaker_control ); - gtk_container_remove( GTK_CONTAINER(subvbox) , mic_control ); - } -} - - void -statusbar_push_message(const gchar * message, guint id) +main_window_volume_controls (gboolean state) { - gtk_statusbar_push(GTK_STATUSBAR(statusBar), id, message); + if (state) + { + speaker_control = create_slider ("speaker"); + gtk_box_pack_end (GTK_BOX (subvbox), speaker_control, FALSE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_widget_show_all (speaker_control); + mic_control = create_slider ("mic"); + gtk_box_pack_end (GTK_BOX (subvbox), mic_control, FALSE /*expand*/, + TRUE /*fill*/, 0 /*padding*/); + gtk_widget_show_all (mic_control); + } + else + { + gtk_container_remove (GTK_CONTAINER(subvbox), speaker_control); + gtk_container_remove (GTK_CONTAINER(subvbox), mic_control); + } } - void -statusbar_pop_message(guint id) +void +statusbar_push_message (const gchar * message, guint id) { - gtk_statusbar_pop(GTK_STATUSBAR(statusBar), id); + gtk_statusbar_push (GTK_STATUSBAR(statusBar), id, message); } - static void -add_error_dialog(GtkWidget *dialog, callable_obj_t * call) +void +statusbar_pop_message (guint id) { - gtk_container_add(GTK_CONTAINER(embedded_error_notebook), dialog); - call_add_error(call, dialog); + gtk_statusbar_pop (GTK_STATUSBAR(statusBar), id); } - static void -destroy_error_dialog_cb(GtkObject *dialog, callable_obj_t * call) +static void +add_error_dialog (GtkWidget *dialog, callable_obj_t * call) { - call_remove_error(call, dialog); + gtk_container_add (GTK_CONTAINER(embedded_error_notebook), dialog); + call_add_error (call, dialog); } - void -main_window_zrtp_not_supported(callable_obj_t * c) +static void +destroy_error_dialog_cb (GtkObject *dialog, callable_obj_t * call) { - account_t* account_details=NULL; - gchar* warning_enabled=""; - - account_details = account_list_get_by_id(c->_accountID); - if(account_details != NULL) { - warning_enabled = g_hash_table_lookup(account_details->properties, ACCOUNT_ZRTP_NOT_SUPP_WARNING); - DEBUG("Warning Enabled %s", warning_enabled); - } else { - DEBUG("Account is null callID %s", c->_callID); - GHashTable * properties = NULL; - sflphone_get_ip2ip_properties (&properties); - if(properties != NULL) - { warning_enabled = g_hash_table_lookup(properties, ACCOUNT_ZRTP_NOT_SUPP_WARNING); } - } - - if(g_strcasecmp(warning_enabled,"true") == 0) { - PidginMiniDialog *mini_dialog; - gchar *desc = g_markup_printf_escaped(_("ZRTP is not supported by peer %s\n"), c->_peer_number); - mini_dialog = pidgin_mini_dialog_new(_("Secure Communication Unavailable"), desc, GTK_STOCK_DIALOG_WARNING); - pidgin_mini_dialog_add_button(mini_dialog, _("Continue"), NULL, NULL); - pidgin_mini_dialog_add_button(mini_dialog, _("Stop Call"), sflphone_hang_up, NULL); - - g_signal_connect_after(mini_dialog, "destroy", (GCallback) destroy_error_dialog_cb, c); - - add_error_dialog(GTK_WIDGET(mini_dialog), c); - } + call_remove_error (call, dialog); } - void -main_window_zrtp_negotiation_failed(const gchar* callID, const gchar* reason, const gchar* severity) +void +main_window_zrtp_not_supported (callable_obj_t * c) { - gchar* peer_number = "(number unknown)"; - callable_obj_t * c = NULL; - c = calllist_get(current_calls, callID); - if (c != NULL) { - peer_number = c->_peer_number; - } - - PidginMiniDialog *mini_dialog; - gchar *desc = g_markup_printf_escaped(_("A %s error forced the call with %s to fall under unencrypted mode.\nExact reason: %s\n"), severity, peer_number, reason); - mini_dialog = pidgin_mini_dialog_new(_("ZRTP negotiation failed"), desc, GTK_STOCK_DIALOG_WARNING); - pidgin_mini_dialog_add_button(mini_dialog, _("Continue"), NULL, NULL); - pidgin_mini_dialog_add_button(mini_dialog, _("Stop Call"), sflphone_hang_up, NULL); - - g_signal_connect_after(mini_dialog, "destroy", (GCallback) destroy_error_dialog_cb, c); - - add_error_dialog(GTK_WIDGET(mini_dialog), c); + account_t* account_details = NULL; + gchar* warning_enabled = ""; + + account_details = account_list_get_by_id (c->_accountID); + if (account_details != NULL) + { + warning_enabled = g_hash_table_lookup (account_details->properties, + ACCOUNT_ZRTP_NOT_SUPP_WARNING); + DEBUG("Warning Enabled %s", warning_enabled); + } + else + { + DEBUG("Account is null callID %s", c->_callID); + GHashTable * properties = NULL; + sflphone_get_ip2ip_properties (&properties); + if (properties != NULL) + { + warning_enabled = g_hash_table_lookup (properties, + ACCOUNT_ZRTP_NOT_SUPP_WARNING); + } + } + + if (g_strcasecmp (warning_enabled, "true") == 0) + { + PidginMiniDialog *mini_dialog; + gchar *desc = g_markup_printf_escaped ( + _("ZRTP is not supported by peer %s\n"), c->_peer_number); + mini_dialog = pidgin_mini_dialog_new ( + _("Secure Communication Unavailable"), desc, + GTK_STOCK_DIALOG_WARNING); + pidgin_mini_dialog_add_button (mini_dialog, _("Continue"), NULL, NULL); + pidgin_mini_dialog_add_button (mini_dialog, _("Stop Call"), + sflphone_hang_up, NULL); + + g_signal_connect_after(mini_dialog, "destroy", (GCallback) destroy_error_dialog_cb, c); + + add_error_dialog (GTK_WIDGET(mini_dialog), c); + } } - void -main_window_confirm_go_clear(callable_obj_t * c) +void +main_window_zrtp_negotiation_failed (const gchar* callID, const gchar* reason, + const gchar* severity) { - PidginMiniDialog *mini_dialog; - gchar *desc = g_markup_printf_escaped(_("%s wants to stop using secure communication. Confirm will resume conversation without SRTP.\n"), c->_peer_number); - mini_dialog = pidgin_mini_dialog_new(_("Confirm Go Clear"), desc, GTK_STOCK_STOP); - pidgin_mini_dialog_add_button(mini_dialog, _("Confirm"), (PidginMiniDialogCallback)sflphone_set_confirm_go_clear, NULL); - pidgin_mini_dialog_add_button(mini_dialog, _("Stop Call"), sflphone_hang_up, NULL); + gchar* peer_number = "(number unknown)"; + callable_obj_t * c = NULL; + c = calllist_get (current_calls, callID); + if (c != NULL) + { + peer_number = c->_peer_number; + } - add_error_dialog(GTK_WIDGET(mini_dialog), c); + PidginMiniDialog *mini_dialog; + gchar + *desc = + g_markup_printf_escaped ( + _("A %s error forced the call with %s to fall under unencrypted mode.\nExact reason: %s\n"), + severity, peer_number, reason); + mini_dialog = pidgin_mini_dialog_new (_("ZRTP negotiation failed"), desc, + GTK_STOCK_DIALOG_WARNING); + pidgin_mini_dialog_add_button (mini_dialog, _("Continue"), NULL, NULL); + pidgin_mini_dialog_add_button (mini_dialog, _("Stop Call"), sflphone_hang_up, + NULL); + + g_signal_connect_after(mini_dialog, "destroy", (GCallback) destroy_error_dialog_cb, c); + + add_error_dialog (GTK_WIDGET(mini_dialog), c); } - +void +main_window_confirm_go_clear (callable_obj_t * c) +{ + PidginMiniDialog *mini_dialog; + gchar + *desc = + g_markup_printf_escaped ( + _("%s wants to stop using secure communication. Confirm will resume conversation without SRTP.\n"), + c->_peer_number); + mini_dialog = pidgin_mini_dialog_new (_("Confirm Go Clear"), desc, + GTK_STOCK_STOP); + pidgin_mini_dialog_add_button (mini_dialog, _("Confirm"), + (PidginMiniDialogCallback) sflphone_set_confirm_go_clear, NULL); + pidgin_mini_dialog_add_button (mini_dialog, _("Stop Call"), sflphone_hang_up, + NULL); + + add_error_dialog (GTK_WIDGET(mini_dialog), c); +} diff --git a/sflphone-client-gnome/src/statusicon.c b/sflphone-client-gnome/src/statusicon.c index 984326b2c754a4b839a3956ff438a25da9c79b30..7f74f6f066ed8c9d77a52b948658c1d44dae01ae 100644 --- a/sflphone-client-gnome/src/statusicon.c +++ b/sflphone-client-gnome/src/statusicon.c @@ -29,119 +29,129 @@ GtkStatusIcon *status; GtkWidget *show_menu_item, *hangup_menu_item; gboolean __minimized = MINIMIZED; -void popup_main_window (void) +void +popup_main_window(void) { - if (__POPUP_WINDOW) - { - gtk_widget_show (get_main_window ()); - gtk_window_move (GTK_WINDOW (get_main_window ()), dbus_get_window_position_x (), dbus_get_window_position_y ()); - set_minimized (FALSE); - } + if (__POPUP_WINDOW) + { + gtk_widget_show(get_main_window()); + gtk_window_move(GTK_WINDOW (get_main_window ()), + dbus_get_window_position_x(), dbus_get_window_position_y()); + set_minimized(FALSE); + } } -void show_status_hangup_icon() { - +void +show_status_hangup_icon() +{ + if (status) { DEBUG("Show Hangup in Systray"); gtk_widget_show(GTK_WIDGET(hangup_menu_item)); - + } } -void hide_status_hangup_icon() { - - DEBUG("Hide Hangup in Systray"); +void +hide_status_hangup_icon() +{ + if (status) { + DEBUG("Hide Hangup in Systray"); gtk_widget_hide(GTK_WIDGET(hangup_menu_item)); + } } - -void -status_quit ( void * foo UNUSED) +void +status_quit(void * foo UNUSED) { sflphone_quit(); } void -status_hangup () +status_hangup() { sflphone_hang_up(); -} +} -void +void status_icon_unminimize() { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), TRUE); } - -gboolean main_widget_minimized() +gboolean +main_widget_minimized() { return __minimized; } -void show_hide (void) +void +show_hide(void) { - if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item))) - { - gtk_widget_show(GTK_WIDGET(get_main_window())); - gtk_window_move (GTK_WINDOW (get_main_window ()), dbus_get_window_position_x (), dbus_get_window_position_y ()); - set_minimized( !MINIMIZED ); - } - else - { - gtk_widget_hide(GTK_WIDGET(get_main_window())); - set_minimized( MINIMIZED ); - } + if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item))) + { + gtk_widget_show(GTK_WIDGET(get_main_window())); + gtk_window_move(GTK_WINDOW (get_main_window ()), + dbus_get_window_position_x(), dbus_get_window_position_y()); + set_minimized(!MINIMIZED); + } + else + { + gtk_widget_hide(GTK_WIDGET(get_main_window())); + set_minimized(MINIMIZED); + } } - -void status_click (GtkStatusIcon *status_icon UNUSED, void * foo UNUSED) +void +status_click(GtkStatusIcon *status_icon UNUSED, void * foo UNUSED) { - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), - !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item))); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), + !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(show_menu_item))); } -void menu (GtkStatusIcon *status_icon, - guint button, - guint activate_time, - GtkWidget * menu) +void +menu(GtkStatusIcon *status_icon, guint button, guint activate_time, + GtkWidget * menu) { - gtk_menu_popup(GTK_MENU(menu), NULL, NULL, gtk_status_icon_position_menu, - status_icon, button, activate_time); + gtk_menu_popup(GTK_MENU(menu), NULL, NULL, gtk_status_icon_position_menu, + status_icon, button, activate_time); } -GtkWidget* create_menu() +GtkWidget* +create_menu() { GtkWidget * menu; GtkWidget * menu_items; GtkWidget * image; - - menu = gtk_menu_new (); - - show_menu_item = gtk_check_menu_item_new_with_mnemonic (_("_Show main window")); + + menu = gtk_menu_new(); + + show_menu_item + = gtk_check_menu_item_new_with_mnemonic(_("_Show main window")); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), TRUE); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), show_menu_item); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), show_menu_item); g_signal_connect(G_OBJECT (show_menu_item), "toggled", - G_CALLBACK (show_hide), - NULL); - + G_CALLBACK (show_hide), + NULL); + hangup_menu_item = gtk_image_menu_item_new_with_mnemonic(_("_Hang up")); - image = gtk_image_new_from_file( ICONS_DIR "/icon_hangup.svg"); + image = gtk_image_new_from_file(ICONS_DIR "/icon_hangup.svg"); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(hangup_menu_item), image); gtk_menu_shell_append(GTK_MENU_SHELL(menu), hangup_menu_item); g_signal_connect(G_OBJECT (hangup_menu_item), "activate", - G_CALLBACK (status_hangup), - NULL); + G_CALLBACK (status_hangup), + NULL); - menu_items = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); + menu_items = gtk_separator_menu_item_new(); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); - menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_QUIT, get_accel_group()); + menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, + get_accel_group()); g_signal_connect_swapped (G_OBJECT (menu_items), "activate", - G_CALLBACK (status_quit), - NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - - gtk_widget_show_all (menu); - + G_CALLBACK (status_quit), + NULL); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + + gtk_widget_show_all(menu); + return menu; } @@ -150,52 +160,67 @@ show_status_icon() { status = gtk_status_icon_new_from_file(LOGO); g_signal_connect (G_OBJECT (status), "activate", - G_CALLBACK (status_click), - NULL); + G_CALLBACK (status_click), + NULL); g_signal_connect (G_OBJECT (status), "popup-menu", - G_CALLBACK (menu), - create_menu()); + G_CALLBACK (menu), + create_menu()); - statusicon_set_tooltip (); + statusicon_set_tooltip(); } -void statusicon_set_tooltip () { - - int count; - gchar *tip; +void hide_status_icon (void) { - // Add a tooltip to the system tray icon - count = account_list_get_registered_accounts (); - tip = g_markup_printf_escaped ("%s - %s" , - _("SFLphone"), - g_markup_printf_escaped(n_("%i active account", "%i active accounts", count),count)); - gtk_status_icon_set_tooltip (status, tip); - g_free(tip); + g_object_unref (status); + status = NULL; } -void status_tray_icon_blink (gboolean active) +void +statusicon_set_tooltip() { - // Set a different icon to notify of an event - active ? gtk_status_icon_set_from_file (status, LOGO_NOTIF) : gtk_status_icon_set_from_file (status, LOGO); + int count; + gchar *tip; + + // Add a tooltip to the system tray icon + count = account_list_get_registered_accounts(); + tip = g_markup_printf_escaped("%s - %s", _("SFLphone"), + g_markup_printf_escaped( + n_("%i active account", "%i active accounts", count), count)); + gtk_status_icon_set_tooltip(status, tip); + g_free(tip); } -void status_tray_icon_online (gboolean online) +void +status_tray_icon_blink(gboolean active) +{ + if (status) { + // Set a different icon to notify of an event + active ? gtk_status_icon_set_from_file(status, LOGO_NOTIF) + : gtk_status_icon_set_from_file(status, LOGO); + } +} + +void +status_tray_icon_online(gboolean online) { - // Set a different icon to notify of an event - online ? gtk_status_icon_set_from_file (status, LOGO) : gtk_status_icon_set_from_file (status, LOGO_OFFLINE); + if (status) { + // Set a different icon to notify of an event + online ? gtk_status_icon_set_from_file(status, LOGO) + : gtk_status_icon_set_from_file(status, LOGO_OFFLINE); + } } -GtkStatusIcon* -get_status_icon( void ) +GtkStatusIcon* +get_status_icon(void) { return status; } void -set_minimized( gboolean state) +set_minimized(gboolean state) { - __minimized = state ; + __minimized = state; gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_menu_item), !state); } diff --git a/sflphone-client-gnome/src/statusicon.h b/sflphone-client-gnome/src/statusicon.h index 29fe256e27ccec19d1fac1013d3a9f5c4fe0dd40..fc45eeec5b12555a4e1de3f030fccb55c2320f45 100644 --- a/sflphone-client-gnome/src/statusicon.h +++ b/sflphone-client-gnome/src/statusicon.h @@ -36,9 +36,15 @@ void popup_main_window (void); /** - * Create the status icon + * Create the system tray icon */ -void show_status_icon(); +void show_status_icon (); + + +/** + * Hide the system tray icon + */ +void hide_status_icon (); /** * Set the menu active diff --git a/sflphone-client-gnome/src/uimanager.c b/sflphone-client-gnome/src/uimanager.c index eeff70c7efbe326594139ee2c2a2203945d87d33..1042bf0c13682a5aef2eee6a5d1a4bfc8c174bab 100644 --- a/sflphone-client-gnome/src/uimanager.c +++ b/sflphone-client-gnome/src/uimanager.c @@ -55,1312 +55,1464 @@ GtkWidget * voicemailToolbar; GtkWidget * editable_num; GtkDialog * edit_dialog; - -enum { - CALLTREE_CALLS, - CALLTREE_HISTORY, - CALLTREE_CONTACTS +enum +{ + CALLTREE_CALLS, CALLTREE_HISTORY, CALLTREE_CONTACTS }; - -static gboolean is_inserted (GtkWidget* button, GtkWidget *current_toolbar) +static gboolean +is_inserted(GtkWidget* button, GtkWidget *current_toolbar) { - return (GTK_WIDGET (button)->parent == GTK_WIDGET (current_toolbar)); + return (GTK_WIDGET (button)->parent == GTK_WIDGET (current_toolbar)); } -void update_actions() +void +update_actions() { - DEBUG("Update action"); - - gtk_action_set_sensitive( GTK_ACTION (newCallAction), TRUE); - gtk_action_set_sensitive (GTK_ACTION (pickUpAction), FALSE); - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), FALSE); - - g_object_ref (hangUpWidget); - g_object_ref (recordWidget); - g_object_ref (holdToolbar); - g_object_ref (offHoldToolbar); - g_object_ref (contactButton); - g_object_ref (transferToolbar); - g_object_ref (voicemailToolbar); - - if (is_inserted (GTK_WIDGET(hangUpWidget), GTK_WIDGET (toolbar))) - { - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (hangUpWidget)); - } - - if (is_inserted (GTK_WIDGET(recordWidget), GTK_WIDGET (toolbar))) - { - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (recordWidget)); - } - - if (is_inserted (GTK_WIDGET(transferToolbar), GTK_WIDGET (toolbar))) - { - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (transferToolbar)); - } - - if (is_inserted (GTK_WIDGET(contactButton), GTK_WIDGET (toolbar))) - { - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (contactButton)); - } - - if (is_inserted (GTK_WIDGET (voicemailToolbar), GTK_WIDGET (toolbar))) - { - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (voicemailToolbar)); - } - - gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), FALSE); - gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), FALSE); - gtk_widget_set_sensitive (GTK_WIDGET (offHoldToolbar), FALSE); - gtk_action_set_sensitive (GTK_ACTION (recordAction), FALSE); - gtk_action_set_sensitive (GTK_ACTION (copyAction), FALSE); - gtk_widget_set_sensitive( GTK_WIDGET(contactButton), FALSE); - gtk_widget_set_tooltip_text (GTK_WIDGET (contactButton), _("No address book selected")); - - if (is_inserted (GTK_WIDGET (holdToolbar), GTK_WIDGET (toolbar))) - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (holdToolbar)); - if (is_inserted (GTK_WIDGET (offHoldToolbar), GTK_WIDGET (toolbar))) - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (offHoldToolbar)); - - if (is_inserted (GTK_WIDGET (newCallWidget), GTK_WIDGET (toolbar))) - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (newCallWidget)); - if (is_inserted (GTK_WIDGET (pickUpWidget), GTK_WIDGET (toolbar))) - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (pickUpWidget)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (newCallWidget), 0); - - // If addressbook support has been enabled and all addressbooks are loaded, display the icon - if (addressbook_is_enabled () && addressbook_is_ready ()) { - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (contactButton), -1); - // Make the icon clickable only if at least one address book is active - if (addressbook_is_active ()) - { - gtk_widget_set_sensitive( GTK_WIDGET(contactButton), TRUE); - gtk_widget_set_tooltip_text (GTK_WIDGET (contactButton), _("Address book")); - } - } - - // g_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId); - // gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), FALSE); - // g_signal_handler_unblock ( GTK_OBJECT (transferToolbar), transfertButtonConnId); - - callable_obj_t * selectedCall = calltab_get_selected_call(active_calltree); - conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree); - - if (selectedCall) - { - // update icon in systray - show_status_hangup_icon(); - - gtk_action_set_sensitive (GTK_ACTION (copyAction), TRUE); - - switch(selectedCall->_state) - { - case CALL_STATE_INCOMING: - // Make the button toolbar clickable - gtk_action_set_sensitive (GTK_ACTION (pickUpAction), TRUE); - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - // Replace the dial button with the hangup button - g_object_ref (newCallWidget); - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET(newCallWidget)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget), 0); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - break; - case CALL_STATE_HOLD: - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (offHoldToolbar), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (newCallWidget), TRUE); - // Replace the hold button with the off-hold button - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - gtk_toolbar_insert (GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM (offHoldToolbar), 2); - break; - case CALL_STATE_RINGING: - gtk_action_set_sensitive (GTK_ACTION (pickUpAction), TRUE); - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - break; - case CALL_STATE_DIALING: - gtk_action_set_sensitive (GTK_ACTION(pickUpAction), TRUE); - if (active_calltree == current_calls) gtk_action_set_sensitive( GTK_ACTION(hangUpAction), TRUE); - //gtk_action_set_sensitive( GTK_ACTION(newCallMenu),TRUE); - g_object_ref (newCallWidget); - gtk_container_remove (GTK_CONTAINER (toolbar), GTK_WIDGET (newCallWidget)); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget), 0); - if (active_calltree == current_calls) gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - break; - case CALL_STATE_CURRENT: - case CALL_STATE_RECORD: - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE); - //gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (holdMenu), gtk_image_new_from_stock (GTK_STOCK_ONHOLD, GTK_ICON_SIZE_MENU)); - gtk_widget_set_sensitive (GTK_WIDGET (transferToolbar), TRUE); - //gtk_action_set_sensitive( GTK_ACTION(newCallMenu),TRUE); - gtk_action_set_sensitive( GTK_ACTION (recordAction), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (transferToolbar), 3); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (recordWidget), 4); - gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId); - gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), FALSE); - gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId); - break; - case CALL_STATE_BUSY: - case CALL_STATE_FAILURE: - gtk_action_set_sensitive( GTK_ACTION(hangUpAction), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - break; - case CALL_STATE_TRANSFERT: - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (transferToolbar), 2); - gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId); - gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), TRUE); - gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId); - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (holdMenu), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (transferToolbar), TRUE); - break; - default: - WARN("Should not happen in update_actions()!"); - break; - } - } - else if (selectedConf){ - - // update icon in systray - show_status_hangup_icon(); - - switch(selectedConf->_state) { - - case CONFERENCE_STATE_ACTIVE_ATACHED: - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2); - break; - - case CONFERENCE_STATE_ACTIVE_DETACHED: - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2); - break; - - case CONFERENCE_STATE_RECORD: - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (holdToolbar), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), 2); - break; - - case CONFERENCE_STATE_HOLD: - gtk_action_set_sensitive (GTK_ACTION (hangUpAction), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (offHoldToolbar), TRUE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), 1); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (offHoldToolbar), 2); - break; - - default: - WARN("Should not happen in update_action()!"); - break; - - } - } - - else { - - // update icon in systray - hide_status_hangup_icon(); - - if( account_list_get_size() > 0 && current_account_has_mailbox ()) - { - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (voicemailToolbar), -2); - update_voicemail_status (); - } - } + DEBUG("Update action"); + + gtk_action_set_sensitive(GTK_ACTION (newCallAction), TRUE); + gtk_action_set_sensitive(GTK_ACTION (pickUpAction), FALSE); + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), FALSE); + + g_object_ref(hangUpWidget); + g_object_ref(recordWidget); + g_object_ref(holdToolbar); + g_object_ref(offHoldToolbar); + g_object_ref(contactButton); + g_object_ref(transferToolbar); + g_object_ref(voicemailToolbar); + + if (is_inserted(GTK_WIDGET(hangUpWidget), GTK_WIDGET (toolbar))) + { + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET (hangUpWidget)); + } + + if (is_inserted(GTK_WIDGET(recordWidget), GTK_WIDGET (toolbar))) + { + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET (recordWidget)); + } + + if (is_inserted(GTK_WIDGET(transferToolbar), GTK_WIDGET (toolbar))) + { + gtk_container_remove(GTK_CONTAINER (toolbar), + GTK_WIDGET (transferToolbar)); + } + + if (is_inserted(GTK_WIDGET(contactButton), GTK_WIDGET (toolbar))) + { + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET (contactButton)); + } + + if (is_inserted(GTK_WIDGET (voicemailToolbar), GTK_WIDGET (toolbar))) + { + gtk_container_remove(GTK_CONTAINER (toolbar), + GTK_WIDGET (voicemailToolbar)); + } + + gtk_widget_set_sensitive(GTK_WIDGET (holdMenu), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET (offHoldToolbar), FALSE); + gtk_action_set_sensitive(GTK_ACTION (recordAction), FALSE); + gtk_action_set_sensitive(GTK_ACTION (copyAction), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(contactButton), FALSE); + gtk_widget_set_tooltip_text(GTK_WIDGET (contactButton), + _("No address book selected")); + + if (is_inserted(GTK_WIDGET (holdToolbar), GTK_WIDGET (toolbar))) + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET (holdToolbar)); + if (is_inserted(GTK_WIDGET (offHoldToolbar), GTK_WIDGET (toolbar))) + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET (offHoldToolbar)); + + if (is_inserted(GTK_WIDGET (newCallWidget), GTK_WIDGET (toolbar))) + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET (newCallWidget)); + if (is_inserted(GTK_WIDGET (pickUpWidget), GTK_WIDGET (toolbar))) + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET (pickUpWidget)); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (newCallWidget), 0); + + // If addressbook support has been enabled and all addressbooks are loaded, display the icon + if (addressbook_is_enabled() && addressbook_is_ready()) + { + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (contactButton), + -1); + // Make the icon clickable only if at least one address book is active + if (addressbook_is_active()) + { + gtk_widget_set_sensitive(GTK_WIDGET(contactButton), TRUE); + gtk_widget_set_tooltip_text(GTK_WIDGET (contactButton), + _("Address book")); + } + } + + // g_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId); + // gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar), FALSE); + // g_signal_handler_unblock ( GTK_OBJECT (transferToolbar), transfertButtonConnId); + + callable_obj_t * selectedCall = calltab_get_selected_call(active_calltree); + conference_obj_t * selectedConf = calltab_get_selected_conf(active_calltree); + + if (selectedCall) + { + // update icon in systray + show_status_hangup_icon(); + + gtk_action_set_sensitive(GTK_ACTION (copyAction), TRUE); + + switch (selectedCall->_state) + { + case CALL_STATE_INCOMING: + // Make the button toolbar clickable + gtk_action_set_sensitive(GTK_ACTION (pickUpAction), TRUE); + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + // Replace the dial button with the hangup button + g_object_ref(newCallWidget); + gtk_container_remove(GTK_CONTAINER (toolbar), GTK_WIDGET(newCallWidget)); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget), + 0); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + break; + case CALL_STATE_HOLD: + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (holdMenu), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (offHoldToolbar), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (newCallWidget), TRUE); + // Replace the hold button with the off-hold button + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), + GTK_TOOL_ITEM (offHoldToolbar), 2); + break; + case CALL_STATE_RINGING: + gtk_action_set_sensitive(GTK_ACTION (pickUpAction), TRUE); + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + break; + case CALL_STATE_DIALING: + gtk_action_set_sensitive(GTK_ACTION(pickUpAction), TRUE); + if (active_calltree == current_calls) + gtk_action_set_sensitive(GTK_ACTION(hangUpAction), TRUE); + //gtk_action_set_sensitive( GTK_ACTION(newCallMenu),TRUE); + g_object_ref(newCallWidget); + gtk_container_remove(GTK_CONTAINER (toolbar), + GTK_WIDGET (newCallWidget)); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (pickUpWidget), + 0); + if (active_calltree == current_calls) + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (hangUpWidget), 1); + break; + case CALL_STATE_CURRENT: + case CALL_STATE_RECORD: + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + gtk_widget_set_sensitive(GTK_WIDGET (holdMenu), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), TRUE); + //gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (holdMenu), gtk_image_new_from_stock (GTK_STOCK_ONHOLD, GTK_ICON_SIZE_MENU)); + gtk_widget_set_sensitive(GTK_WIDGET (transferToolbar), TRUE); + //gtk_action_set_sensitive( GTK_ACTION(newCallMenu),TRUE); + gtk_action_set_sensitive(GTK_ACTION (recordAction), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), + 2); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (transferToolbar), 3); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (recordWidget), + 4); + gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId); + gtk_toggle_tool_button_set_active( + GTK_TOGGLE_TOOL_BUTTON (transferToolbar), FALSE); + gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId); + break; + case CALL_STATE_BUSY: + case CALL_STATE_FAILURE: + gtk_action_set_sensitive(GTK_ACTION(hangUpAction), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + break; + case CALL_STATE_TRANSFERT: + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (transferToolbar), 2); + gtk_signal_handler_block (GTK_OBJECT (transferToolbar), transfertButtonConnId); + gtk_toggle_tool_button_set_active( + GTK_TOGGLE_TOOL_BUTTON (transferToolbar), TRUE); + gtk_signal_handler_unblock (transferToolbar, transfertButtonConnId); + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (holdMenu), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (transferToolbar), TRUE); + break; + default: + WARN("Should not happen in update_actions()!") + ; + break; + } + } + else if (selectedConf) + { + + // update icon in systray + show_status_hangup_icon(); + + switch (selectedConf->_state) + { + + case CONFERENCE_STATE_ACTIVE_ATACHED: + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), + 2); + break; + + case CONFERENCE_STATE_ACTIVE_DETACHED: + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), + 2); + break; + + case CONFERENCE_STATE_RECORD: + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (holdToolbar), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (holdToolbar), + 2); + break; + + case CONFERENCE_STATE_HOLD: + gtk_action_set_sensitive(GTK_ACTION (hangUpAction), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET (offHoldToolbar), TRUE); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (hangUpWidget), + 1); + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (offHoldToolbar), 2); + break; + + default: + WARN("Should not happen in update_action()!") + ; + break; + + } + } + + else + { + + // update icon in systray + hide_status_hangup_icon(); + + if (account_list_get_size() > 0 && current_account_has_mailbox()) + { + gtk_toolbar_insert(GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (voicemailToolbar), -2); + update_voicemail_status(); + } + } } -void update_voicemail_status (void) +void +update_voicemail_status(void) { - gchar *messages = ""; - messages = g_markup_printf_escaped (_("Voicemail (%i)"), current_account_get_message_number ()); - (current_account_has_new_message ()) ? - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (voicemailToolbar), "mail-message-new"): - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (voicemailToolbar), "mail-read"); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (voicemailToolbar), messages); - g_free (messages); + gchar *messages = ""; + messages = g_markup_printf_escaped(_("Voicemail (%i)"), + current_account_get_message_number()); + (current_account_has_new_message()) ? gtk_tool_button_set_icon_name( + GTK_TOOL_BUTTON (voicemailToolbar), "mail-message-new") + : gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (voicemailToolbar), + "mail-read"); + gtk_tool_button_set_label(GTK_TOOL_BUTTON (voicemailToolbar), messages); + g_free(messages); } -static void volume_bar_cb (GtkToggleAction *togglemenuitem, gpointer user_data) +static void +volume_bar_cb(GtkToggleAction *togglemenuitem, gpointer user_data) { - gboolean toggled = gtk_toggle_action_get_active (togglemenuitem); - if (toggled == SHOW_VOLUME) - return; - main_window_volume_controls(toggled); - if (toggled || SHOW_VOLUME) - dbus_set_volume_controls(toggled); + gboolean toggled = gtk_toggle_action_get_active(togglemenuitem); + if (toggled == SHOW_VOLUME) + return; + main_window_volume_controls(toggled); + if (toggled || SHOW_VOLUME) + dbus_set_volume_controls(toggled); } -static void dialpad_bar_cb (GtkToggleAction *togglemenuitem, gpointer user_data) +static void +dialpad_bar_cb(GtkToggleAction *togglemenuitem, gpointer user_data) { - gboolean toggled = gtk_toggle_action_get_active (togglemenuitem); - if (toggled == SHOW_DIALPAD) - return; - main_window_dialpad (toggled); - if (toggled || SHOW_DIALPAD) - dbus_set_dialpad(toggled); + gboolean toggled = gtk_toggle_action_get_active(togglemenuitem); + if (toggled == SHOW_DIALPAD) + return; + main_window_dialpad(toggled); + if (toggled || SHOW_DIALPAD) + dbus_set_dialpad(toggled); } -static void help_contents_cb (GtkAction *action) +static void +help_contents_cb(GtkAction *action) { - GError *error = NULL; - - gnome_help_display ("sflphone.xml", NULL, &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } + GError *error = NULL; + + gnome_help_display("sflphone.xml", NULL, &error); + if (error != NULL) + { + g_warning("%s", error->message); + g_error_free(error); + } } -static void help_about ( void * foo UNUSED) +static void +help_about(void * foo UNUSED) { - gchar *authors[] = { - "Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>", - "Jean-Philippe Barrette-LaPierre", - "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>", - "Julien Bonjean <julien.bonjean@savoirfairelinux.com>", - "Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>", - "Laurielle Lea", - "Yun Liu <yun.liu@savoirfairelinux.com>", - "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>", - "Yan Morin <yan.morin@savoirfairelinux.com>", - "Jérôme Oufella <jerome.oufella@savoirfairelinux.com>", - "Julien Plissonneau Duquene <julien.plissonneau.duquene@savoirfairelinux.com>", - "Alexandre Savard <alexandre.savard@savoirfairelinux.com>", - NULL}; - gchar *artists[] = { - "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>", - "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>", - NULL}; - - gtk_show_about_dialog( GTK_WINDOW(get_main_window()), - "artists", artists, - "authors", authors, - "comments", _("SFLphone is a VoIP client compatible with SIP and IAX2 protocols."), - "copyright", "Copyright © 2004-2009 Savoir-faire Linux Inc.", - "name", PACKAGE, - "title", _("About SFLphone"), - "version", VERSION, - "website", "http://www.sflphone.org", - NULL); + gchar + *authors[] = + { + "Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>", + "Jean-Philippe Barrette-LaPierre", + "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>", + "Julien Bonjean <julien.bonjean@savoirfairelinux.com>", + "Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>", + "Laurielle Lea", + "Yun Liu <yun.liu@savoirfairelinux.com>", + "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>", + "Yan Morin <yan.morin@savoirfairelinux.com>", + "Jérôme Oufella <jerome.oufella@savoirfairelinux.com>", + "Julien Plissonneau Duquene <julien.plissonneau.duquene@savoirfairelinux.com>", + "Alexandre Savard <alexandre.savard@savoirfairelinux.com>", NULL }; + gchar *artists[] = + { "Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>", + "Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>", NULL }; + + gtk_show_about_dialog(GTK_WINDOW(get_main_window()), "artists", artists, + "authors", authors, "comments", + _("SFLphone is a VoIP client compatible with SIP and IAX2 protocols."), + "copyright", "Copyright © 2004-2009 Savoir-faire Linux Inc.", "name", + PACKAGE, "title", _("About SFLphone"), "version", VERSION, "website", + "http://www.sflphone.org", NULL); } /* ----------------------------------------------------------------- */ - static void -call_new_call ( void * foo UNUSED) +static void +call_new_call(void * foo UNUSED) { - sflphone_new_call(); + sflphone_new_call(); } - static void -call_quit ( void * foo UNUSED) +static void +call_quit(void * foo UNUSED) { - sflphone_quit(); + sflphone_quit(); } - static void -call_minimize ( void * foo UNUSED) +static void +call_minimize(void * foo UNUSED) { -#if GTK_CHECK_VERSION(2,10,0) - gtk_widget_hide(GTK_WIDGET( get_main_window() )); - set_minimized( TRUE ); -#endif + + if (g_strcasecmp (dbus_is_status_icon_enabled (), "true") == 0) { + gtk_widget_hide(GTK_WIDGET( get_main_window() )); + set_minimized(TRUE); + } + else { + sflphone_quit (); + } } - static void -switch_account( GtkWidget* item , gpointer data UNUSED) +static void +switch_account(GtkWidget* item, gpointer data UNUSED) { - account_t* acc = g_object_get_data( G_OBJECT(item) , "account" ); - DEBUG("%s" , acc->accountID); - account_list_set_current (acc); - status_bar_display_account (); + account_t* acc = g_object_get_data(G_OBJECT(item), "account"); + DEBUG("%s" , acc->accountID); + account_list_set_current(acc); + status_bar_display_account(); } - static void -call_hold (void* foo UNUSED) +static void +call_hold(void* foo UNUSED) { - callable_obj_t * selectedCall = calltab_get_selected_call(current_calls); - conference_obj_t * selectedConf = calltab_get_selected_conf(); - - if(selectedCall) - { - if(selectedCall->_state == CALL_STATE_HOLD) - { - sflphone_off_hold(); - } - else - { - sflphone_on_hold(); - } - } - else if (selectedConf) { - - switch(selectedConf->_state) { - - case CONFERENCE_STATE_HOLD: - { - selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED; - sflphone_conference_off_hold(selectedConf); - } - break; - - case CONFERENCE_STATE_ACTIVE_ATACHED: - case CONFERENCE_STATE_ACTIVE_DETACHED: { - selectedConf->_state = CONFERENCE_STATE_HOLD; - sflphone_conference_on_hold(selectedConf); - } - break; - default: - break; - } - - } + callable_obj_t * selectedCall = calltab_get_selected_call(current_calls); + conference_obj_t * selectedConf = calltab_get_selected_conf(); + + if (selectedCall) + { + if (selectedCall->_state == CALL_STATE_HOLD) + { + sflphone_off_hold(); + } + else + { + sflphone_on_hold(); + } + } + else if (selectedConf) + { + + switch (selectedConf->_state) + { + + case CONFERENCE_STATE_HOLD: + { + selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED; + sflphone_conference_off_hold(selectedConf); + } + break; + + case CONFERENCE_STATE_ACTIVE_ATACHED: + case CONFERENCE_STATE_ACTIVE_DETACHED: + { + selectedConf->_state = CONFERENCE_STATE_HOLD; + sflphone_conference_on_hold(selectedConf); + } + break; + default: + break; + } + + } } - static void -conference_hold (void* foo UNUSED) +static void +conference_hold(void* foo UNUSED) { - conference_obj_t * selectedConf = calltab_get_selected_conf(); - - switch(selectedConf->_state) - { - case CONFERENCE_STATE_HOLD: - { - selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED; - sflphone_conference_off_hold(selectedConf); - } - break; - - case CONFERENCE_STATE_ACTIVE_ATACHED: - case CONFERENCE_STATE_ACTIVE_DETACHED: - { - selectedConf->_state = CONFERENCE_STATE_HOLD; - sflphone_conference_on_hold(selectedConf); - } - break; - default: - break; - } + conference_obj_t * selectedConf = calltab_get_selected_conf(); + + switch (selectedConf->_state) + { + case CONFERENCE_STATE_HOLD: + { + selectedConf->_state = CONFERENCE_STATE_ACTIVE_ATACHED; + sflphone_conference_off_hold(selectedConf); + } + break; + + case CONFERENCE_STATE_ACTIVE_ATACHED: + case CONFERENCE_STATE_ACTIVE_DETACHED: + { + selectedConf->_state = CONFERENCE_STATE_HOLD; + sflphone_conference_on_hold(selectedConf); + } + break; + default: + break; + } } - static void -call_pick_up ( void * foo UNUSED) +static void +call_pick_up(void * foo UNUSED) { - DEBUG("------ call_button -----"); - callable_obj_t * selectedCall; - callable_obj_t* new_call; - - selectedCall = calltab_get_selected_call(active_calltree); - - if(calllist_get_size(current_calls)>0) - sflphone_pick_up(); - - else if(calllist_get_size(active_calltree) > 0){ - if( selectedCall) - { - create_new_call (CALL, CALL_STATE_DIALING, "", "", "", selectedCall->_peer_number, &new_call); - - calllist_add(current_calls, new_call); - calltree_add_call(current_calls, new_call, NULL); - sflphone_place_call(new_call); - calltree_display (current_calls); - } - else - { - sflphone_new_call(); - calltree_display(current_calls); - } - } - else - { - sflphone_new_call(); - calltree_display(current_calls); - } + DEBUG("------ call_button -----"); + callable_obj_t * selectedCall; + callable_obj_t* new_call; + + selectedCall = calltab_get_selected_call(active_calltree); + + if (calllist_get_size(current_calls) > 0) + sflphone_pick_up(); + + else if (calllist_get_size(active_calltree) > 0) + { + if (selectedCall) + { + create_new_call(CALL, CALL_STATE_DIALING, "", "", "", + selectedCall->_peer_number, &new_call); + + calllist_add(current_calls, new_call); + calltree_add_call(current_calls, new_call, NULL); + sflphone_place_call(new_call); + calltree_display(current_calls); + } + else + { + sflphone_new_call(); + calltree_display(current_calls); + } + } + else + { + sflphone_new_call(); + calltree_display(current_calls); + } } -static void call_hang_up (void) +static void +call_hang_up(void) { - sflphone_hang_up(); + sflphone_hang_up(); } -static void conference_hang_up (void) +static void +conference_hang_up(void) { - sflphone_conference_hang_up(); + sflphone_conference_hang_up(); } -static void call_record (void) +static void +call_record(void) { - sflphone_rec_call(); + sflphone_rec_call(); } - static void -call_configuration_assistant ( void * foo UNUSED) +static void +call_configuration_assistant(void * foo UNUSED) { #if GTK_CHECK_VERSION(2,10,0) - build_wizard(); + build_wizard(); #endif } - static void -remove_from_history( void * foo UNUSED) +static void +remove_from_history(void * foo UNUSED) { - callable_obj_t* c = calltab_get_selected_call( history ); - if(c){ - DEBUG("Remove the call from the history"); - calllist_remove_from_history( c ); - } + callable_obj_t* c = calltab_get_selected_call(history); + if (c) + { + DEBUG("Remove the call from the history"); + calllist_remove_from_history(c); + } } - static void -call_back( void * foo UNUSED) +static void +call_back(void * foo UNUSED) { - callable_obj_t *selected_call, *new_call; + callable_obj_t *selected_call, *new_call; - selected_call = calltab_get_selected_call( active_calltree ); + selected_call = calltab_get_selected_call(active_calltree); - if( selected_call ) - { - create_new_call (CALL, CALL_STATE_DIALING, "", "", selected_call->_peer_name, selected_call->_peer_number, &new_call); + if (selected_call) + { + create_new_call(CALL, CALL_STATE_DIALING, "", "", + selected_call->_peer_name, selected_call->_peer_number, &new_call); - calllist_add(current_calls, new_call); - calltree_add_call(current_calls, new_call, NULL); - sflphone_place_call(new_call); - calltree_display (current_calls); - } + calllist_add(current_calls, new_call); + calltree_add_call(current_calls, new_call, NULL); + sflphone_place_call(new_call); + calltree_display(current_calls); + } } - static void -edit_preferences ( void * foo UNUSED) +static void +edit_preferences(void * foo UNUSED) { - show_preferences_dialog(); + show_preferences_dialog(); } - static void -edit_accounts ( void * foo UNUSED) +static void +edit_accounts(void * foo UNUSED) { - show_account_list_config_dialog(); + show_account_list_config_dialog(); } // The menu Edit/Copy should copy the current selected call's number - static void -edit_copy ( void * foo UNUSED) +static void +edit_copy(void * foo UNUSED) { - GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); - callable_obj_t * selectedCall = calltab_get_selected_call(current_calls); - gchar * no = NULL; - - if(selectedCall) - { - switch(selectedCall->_state) - { - case CALL_STATE_TRANSFERT: - case CALL_STATE_DIALING: - case CALL_STATE_RINGING: - no = selectedCall->_peer_number; - break; - case CALL_STATE_CURRENT: - case CALL_STATE_HOLD: - case CALL_STATE_BUSY: - case CALL_STATE_FAILURE: - case CALL_STATE_INCOMING: - default: - no = selectedCall->_peer_number; - break; - } - DEBUG("Clipboard number: %s\n", no); - gtk_clipboard_set_text (clip, no, strlen(no) ); - } + GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); + callable_obj_t * selectedCall = calltab_get_selected_call(current_calls); + gchar * no = NULL; + + if (selectedCall) + { + switch (selectedCall->_state) + { + case CALL_STATE_TRANSFERT: + case CALL_STATE_DIALING: + case CALL_STATE_RINGING: + no = selectedCall->_peer_number; + break; + case CALL_STATE_CURRENT: + case CALL_STATE_HOLD: + case CALL_STATE_BUSY: + case CALL_STATE_FAILURE: + case CALL_STATE_INCOMING: + default: + no = selectedCall->_peer_number; + break; + } + DEBUG("Clipboard number: %s\n", no); + gtk_clipboard_set_text(clip, no, strlen(no)); + } } // The menu Edit/Paste should paste the clipboard into the current selected call - static void -edit_paste ( void * foo UNUSED) +static void +edit_paste(void * foo UNUSED) { - GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); - callable_obj_t * selectedCall = calltab_get_selected_call(current_calls); - gchar * no = gtk_clipboard_wait_for_text (clip); - - if(no && selectedCall) - { - switch(selectedCall->_state) - { - case CALL_STATE_TRANSFERT: - case CALL_STATE_DIALING: - // Add the text to the number - { - gchar * before; - before = selectedCall->_peer_number; - DEBUG("TO: %s\n", before); - selectedCall->_peer_number = g_strconcat(before, no, NULL); - - if(selectedCall->_state == CALL_STATE_DIALING) - { - selectedCall->_peer_info = g_strconcat("\"\" <", selectedCall->_peer_number, ">", NULL); - } - calltree_update_call(current_calls, selectedCall, NULL); - } - break; - case CALL_STATE_RINGING: - case CALL_STATE_INCOMING: - case CALL_STATE_BUSY: - case CALL_STATE_FAILURE: - case CALL_STATE_HOLD: - { // Create a new call to hold the new text - selectedCall = sflphone_new_call(); - - gchar * before = selectedCall->_peer_number; - selectedCall->_peer_number = g_strconcat(selectedCall->_peer_number, no, NULL); - DEBUG("TO: %s", selectedCall->_peer_number); - - selectedCall->_peer_info = g_strconcat("\"\" <", selectedCall->_peer_number, ">", NULL); - - calltree_update_call(current_calls, selectedCall, NULL); - } - break; - case CALL_STATE_CURRENT: - default: - { - unsigned int i; - for(i = 0; i < strlen(no); i++) - { - gchar * oneNo = g_strndup(&no[i], 1); - DEBUG("<%s>", oneNo); - dbus_play_dtmf(oneNo); - - gchar * temp = g_strconcat(selectedCall->_peer_number, oneNo, NULL); - selectedCall->_peer_info = get_peer_info (temp, selectedCall->_peer_name); - // g_free(temp); - calltree_update_call(current_calls, selectedCall, NULL); - - } - } - break; - } - - } - else // There is no current call, create one - { - selectedCall = sflphone_new_call(); - - gchar * before = selectedCall->_peer_number; - selectedCall->_peer_number = g_strconcat(selectedCall->_peer_number, no, NULL); - g_free(before); - DEBUG("TO: %s", selectedCall->_peer_number); - - g_free(selectedCall->_peer_info); - selectedCall->_peer_info = g_strconcat("\"\" <", selectedCall->_peer_number, ">", NULL); - calltree_update_call(current_calls, selectedCall, NULL); - } + GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); + callable_obj_t * selectedCall = calltab_get_selected_call(current_calls); + gchar * no = gtk_clipboard_wait_for_text(clip); + + if (no && selectedCall) + { + switch (selectedCall->_state) + { + case CALL_STATE_TRANSFERT: + case CALL_STATE_DIALING: + // Add the text to the number + { + gchar * before; + before = selectedCall->_peer_number; + DEBUG("TO: %s\n", before); + selectedCall->_peer_number = g_strconcat(before, no, NULL); + + if (selectedCall->_state == CALL_STATE_DIALING) + { + selectedCall->_peer_info = g_strconcat("\"\" <", + selectedCall->_peer_number, ">", NULL); + } + calltree_update_call(current_calls, selectedCall, NULL); + } + break; + case CALL_STATE_RINGING: + case CALL_STATE_INCOMING: + case CALL_STATE_BUSY: + case CALL_STATE_FAILURE: + case CALL_STATE_HOLD: + { // Create a new call to hold the new text + selectedCall = sflphone_new_call(); + + gchar * before = selectedCall->_peer_number; + selectedCall->_peer_number = g_strconcat(selectedCall->_peer_number, + no, NULL); + DEBUG("TO: %s", selectedCall->_peer_number); + + selectedCall->_peer_info = g_strconcat("\"\" <", + selectedCall->_peer_number, ">", NULL); + + calltree_update_call(current_calls, selectedCall, NULL); + } + break; + case CALL_STATE_CURRENT: + default: + { + unsigned int i; + for (i = 0; i < strlen(no); i++) + { + gchar * oneNo = g_strndup(&no[i], 1); + DEBUG("<%s>", oneNo); + dbus_play_dtmf(oneNo); + + gchar * temp = g_strconcat(selectedCall->_peer_number, oneNo, + NULL); + selectedCall->_peer_info = get_peer_info(temp, + selectedCall->_peer_name); + // g_free(temp); + calltree_update_call(current_calls, selectedCall, NULL); + + } + } + break; + } + + } + else // There is no current call, create one + { + selectedCall = sflphone_new_call(); + + gchar * before = selectedCall->_peer_number; + selectedCall->_peer_number = g_strconcat(selectedCall->_peer_number, no, + NULL); + g_free(before); + DEBUG("TO: %s", selectedCall->_peer_number); + + g_free(selectedCall->_peer_info); + selectedCall->_peer_info = g_strconcat("\"\" <", + selectedCall->_peer_number, ">", NULL); + calltree_update_call(current_calls, selectedCall, NULL); + } } -static void clear_history (void) +static void +clear_history(void) { - if( calllist_get_size( history ) != 0 ){ - calllist_clean_history(); - } + if (calllist_get_size(history) != 0) + { + calllist_clean_history(); + } } /** * Transfert the line */ -static void call_transfer_cb () +static void +call_transfer_cb() { - gboolean active = gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (transferToolbar)); - active ? sflphone_set_transfert() : sflphone_unset_transfert() ; + gboolean active = gtk_toggle_tool_button_get_active( + GTK_TOGGLE_TOOL_BUTTON (transferToolbar)); + active ? sflphone_set_transfert() : sflphone_unset_transfert(); } -static void call_mailbox_cb (void) +static void +call_mailbox_cb(void) { - account_t* current; - callable_obj_t *mailbox_call; - gchar *to, *from, *account_id; - - current = account_list_get_current (); - if( current == NULL ) // Should not happens - return; - - to = g_strdup(g_hash_table_lookup(current->properties, ACCOUNT_MAILBOX)); - account_id = g_strdup (current->accountID); - - create_new_call (CALL, CALL_STATE_DIALING, "", account_id, _("Voicemail"), to, &mailbox_call); - DEBUG("TO : %s" , mailbox_call->_peer_number); - calllist_add( current_calls , mailbox_call ); - calltree_add_call( current_calls, mailbox_call, NULL); - update_actions(); - sflphone_place_call( mailbox_call ); - calltree_display(current_calls); + account_t* current; + callable_obj_t *mailbox_call; + gchar *to, *from, *account_id; + + current = account_list_get_current(); + if (current == NULL) // Should not happens + return; + + to = g_strdup(g_hash_table_lookup(current->properties, ACCOUNT_MAILBOX)); + account_id = g_strdup(current->accountID); + + create_new_call(CALL, CALL_STATE_DIALING, "", account_id, _("Voicemail"), to, + &mailbox_call); + DEBUG("TO : %s" , mailbox_call->_peer_number); + calllist_add(current_calls, mailbox_call); + calltree_add_call(current_calls, mailbox_call, NULL); + update_actions(); + sflphone_place_call(mailbox_call); + calltree_display(current_calls); } -static void toggle_history_cb (GtkToggleAction *action, gpointer user_data) +static void +toggle_history_cb(GtkToggleAction *action, gpointer user_data) { - gboolean toggle; - toggle = gtk_toggle_action_get_active (action); - (toggle)? calltree_display (history) : calltree_display (current_calls); + gboolean toggle; + toggle = gtk_toggle_action_get_active(action); + (toggle) ? calltree_display(history) : calltree_display(current_calls); } -static void toggle_addressbook_cb (GtkToggleAction *action, gpointer user_data) +static void +toggle_addressbook_cb(GtkToggleAction *action, gpointer user_data) { - gboolean toggle; - toggle = gtk_toggle_action_get_active (action); - (toggle)? calltree_display (contacts) : calltree_display (current_calls); + gboolean toggle; + toggle = gtk_toggle_action_get_active(action); + (toggle) ? calltree_display(contacts) : calltree_display(current_calls); } -static const GtkActionEntry menu_entries[] = { - - // Call Menu - { "Call", NULL, N_("Call") }, - { "NewCall", GTK_STOCK_DIAL, N_("_New call"), "<control>N", N_("Place a new call"), G_CALLBACK (call_new_call) }, - { "PickUp", GTK_STOCK_PICKUP, N_("_Pick up"), NULL, N_("Answer the call"), G_CALLBACK (call_pick_up) }, - { "HangUp", GTK_STOCK_HANGUP, N_("_Hang up"), "<control>S", N_("Finish the call"), G_CALLBACK (call_hang_up) }, - { "OnHold", GTK_STOCK_ONHOLD, N_("O_n hold"), "<control>P", N_("Place the call on hold"), G_CALLBACK (call_hold) }, - { "OffHold", GTK_STOCK_OFFHOLD, N_("O_ff hold"), "<control>P", N_("Place the call off hold"), G_CALLBACK (call_hold) }, - { "AccountAssistant", NULL, N_("Configuration _Assistant"), NULL, N_("Run the configuration assistant"), G_CALLBACK (call_configuration_assistant) }, - { "Voicemail", "mail-read", N_("Voicemail"), NULL, N_("Call your voicemail"), G_CALLBACK (call_mailbox_cb) }, - { "Close", GTK_STOCK_CLOSE, N_("_Close"), "<control>W", N_("Minimize to system tray"), G_CALLBACK (call_minimize) }, - { "Quit", GTK_STOCK_CLOSE, N_("_Quit"), "<control>Q", N_("Quit the program"), G_CALLBACK (call_quit) }, - - // Edit Menu - { "Edit", NULL, N_("_Edit") }, - { "Copy", GTK_STOCK_COPY, N_("_Copy"), "<control>C", N_("Copy the selection"), G_CALLBACK (edit_copy) }, - { "Paste", GTK_STOCK_PASTE, N_("_Paste"), "<control>V", N_("Paste the clipboard"), G_CALLBACK (edit_paste) }, - { "ClearHistory", GTK_STOCK_CLEAR, N_("Clear _history"), NULL, N_("Clear the call history"), G_CALLBACK (clear_history) }, - { "Accounts", NULL, N_("_Accounts"), NULL, N_("Edit your accounts"), G_CALLBACK (edit_accounts) }, - { "Preferences", GTK_STOCK_PREFERENCES, N_("_Preferences"), NULL, N_("Change your preferences"), G_CALLBACK (edit_preferences) }, - - // View Menu - { "View", NULL, N_("_View") }, - - // Help menu - { "Help", NULL, N_("_Help") }, - { "HelpContents", GTK_STOCK_HELP, N_("Contents"), "F1", N_("Open the manual"), G_CALLBACK (help_contents_cb) }, - { "About", GTK_STOCK_ABOUT, NULL, NULL, N_("About this application"), G_CALLBACK (help_about) } - -}; - -static const GtkToggleActionEntry toggle_menu_entries[] = { - - { "Transfer", GTK_STOCK_TRANSFER, N_("_Transfer"), "<control>T", N_("Transfer the call"), NULL }, //G_CALLBACK (call_transfer_cb) }, - { "Record", GTK_STOCK_MEDIA_RECORD, N_("_Record"), "<control>R", N_("Record the current conversation"), NULL }, // G_CALLBACK (call_record) }, - { "Toolbar", NULL, N_("_Show toolbar"), "<control>T", N_("Show the toolbar"), NULL }, - { "Dialpad", NULL, N_("_Dialpad"), "<control>D", N_("Show the dialpad"), G_CALLBACK (dialpad_bar_cb) }, - { "VolumeControls",NULL, N_("_Volume controls"), "<control>V", N_("Show the volume controls"), G_CALLBACK (volume_bar_cb) }, - { "History", "appointment-soon", N_("_History"), NULL, N_("Calls history"), G_CALLBACK (toggle_history_cb), FALSE}, - { "Addressbook", GTK_STOCK_ADDRESSBOOK, N_("_Address book"), NULL, N_("Address book"), G_CALLBACK (toggle_addressbook_cb), FALSE} - -}; +static const GtkActionEntry menu_entries[] = + { + + // Call Menu + { "Call", NULL, N_("Call") }, + { "NewCall", GTK_STOCK_DIAL, N_("_New call"), "<control>N", + N_("Place a new call"), G_CALLBACK (call_new_call) }, + { "PickUp", GTK_STOCK_PICKUP, N_("_Pick up"), NULL, + N_("Answer the call"), G_CALLBACK (call_pick_up) }, + { "HangUp", GTK_STOCK_HANGUP, N_("_Hang up"), "<control>S", + N_("Finish the call"), G_CALLBACK (call_hang_up) }, + { "OnHold", GTK_STOCK_ONHOLD, N_("O_n hold"), "<control>P", + N_("Place the call on hold"), G_CALLBACK (call_hold) }, + { "OffHold", GTK_STOCK_OFFHOLD, N_("O_ff hold"), "<control>P", + N_("Place the call off hold"), G_CALLBACK (call_hold) }, + { "AccountAssistant", NULL, N_("Configuration _Assistant"), NULL, + N_("Run the configuration assistant"), + G_CALLBACK (call_configuration_assistant) }, + { "Voicemail", "mail-read", N_("Voicemail"), NULL, + N_("Call your voicemail"), G_CALLBACK (call_mailbox_cb) }, + { "Close", GTK_STOCK_CLOSE, N_("_Close"), "<control>W", + N_("Minimize to system tray"), G_CALLBACK (call_minimize) }, + { "Quit", GTK_STOCK_CLOSE, N_("_Quit"), "<control>Q", + N_("Quit the program"), G_CALLBACK (call_quit) }, + + // Edit Menu + { "Edit", NULL, N_("_Edit") }, + { "Copy", GTK_STOCK_COPY, N_("_Copy"), "<control>C", + N_("Copy the selection"), G_CALLBACK (edit_copy) }, + { "Paste", GTK_STOCK_PASTE, N_("_Paste"), "<control>V", + N_("Paste the clipboard"), G_CALLBACK (edit_paste) }, + { "ClearHistory", GTK_STOCK_CLEAR, N_("Clear _history"), NULL, + N_("Clear the call history"), G_CALLBACK (clear_history) }, + { "Accounts", NULL, N_("_Accounts"), NULL, N_("Edit your accounts"), + G_CALLBACK (edit_accounts) }, + { "Preferences", GTK_STOCK_PREFERENCES, N_("_Preferences"), NULL, + N_("Change your preferences"), G_CALLBACK (edit_preferences) }, + + // View Menu + { "View", NULL, N_("_View") }, + + // Help menu + { "Help", NULL, N_("_Help") }, + { "HelpContents", GTK_STOCK_HELP, N_("Contents"), "F1", + N_("Open the manual"), G_CALLBACK (help_contents_cb) }, + { "About", GTK_STOCK_ABOUT, NULL, NULL, N_("About this application"), + G_CALLBACK (help_about) } + + }; + +static const GtkToggleActionEntry toggle_menu_entries[] = + { + + { "Transfer", GTK_STOCK_TRANSFER, N_("_Transfer"), "<control>T", + N_("Transfer the call"), NULL }, //G_CALLBACK (call_transfer_cb) }, + { "Record", GTK_STOCK_MEDIA_RECORD, N_("_Record"), "<control>R", + N_("Record the current conversation"), NULL }, // G_CALLBACK (call_record) }, + { "Toolbar", NULL, N_("_Show toolbar"), "<control>T", + N_("Show the toolbar"), NULL }, + { "Dialpad", NULL, N_("_Dialpad"), "<control>D", + N_("Show the dialpad"), G_CALLBACK (dialpad_bar_cb) }, + { "VolumeControls", NULL, N_("_Volume controls"), "<control>V", + N_("Show the volume controls"), G_CALLBACK (volume_bar_cb) }, + { "History", "appointment-soon", N_("_History"), NULL, + N_("Calls history"), G_CALLBACK (toggle_history_cb), FALSE }, + { "Addressbook", GTK_STOCK_ADDRESSBOOK, N_("_Address book"), NULL, + N_("Address book"), G_CALLBACK (toggle_addressbook_cb), FALSE } + + }; + +gboolean +uimanager_new(GtkUIManager **_ui_manager) +{ -gboolean uimanager_new (GtkUIManager **_ui_manager) { - - GtkUIManager *ui_manager; - GtkActionGroup *action_group; - GtkWidget *window; - gchar *path; - GError *error = NULL; - - window = get_main_window (); - ui_manager = gtk_ui_manager_new (); - - /* Create an accel group for window's shortcuts */ - path = g_build_filename (SFLPHONE_UIDIR_UNINSTALLED, "./ui.xml", NULL); - if (g_file_test (path, G_FILE_TEST_EXISTS)) { - gtk_ui_manager_add_ui_from_file (ui_manager, path, &error); - - if (error != NULL) - { - g_error_free (error); - return FALSE; - } - g_free (path); - } - else { - path = g_build_filename (SFLPHONE_UIDIR, "./ui.xml", NULL); - if (g_file_test (path, G_FILE_TEST_EXISTS)) { - gtk_ui_manager_add_ui_from_file (ui_manager, path, &error); - - if (error != NULL) - { - g_error_free (error); - return FALSE; - } - g_free (path); - } - else - return FALSE; - } - action_group = gtk_action_group_new ("SFLphoneWindowActions"); - // To translate label and tooltip entries - gtk_action_group_set_translation_domain (action_group, "sflphone-client-gnome"); - gtk_action_group_add_actions (action_group, menu_entries, G_N_ELEMENTS (menu_entries), window); - gtk_action_group_add_toggle_actions (action_group, toggle_menu_entries, G_N_ELEMENTS (toggle_menu_entries), window); - //gtk_action_group_add_radio_actions (action_group, radio_menu_entries, G_N_ELEMENTS (radio_menu_entries), CALLTREE_CALLS, G_CALLBACK (calltree_switch_cb), window); - gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); - - *_ui_manager = ui_manager; - - return TRUE; + GtkUIManager *ui_manager; + GtkActionGroup *action_group; + GtkWidget *window; + gchar *path; + GError *error = NULL; + + window = get_main_window(); + ui_manager = gtk_ui_manager_new(); + + /* Create an accel group for window's shortcuts */ + path = g_build_filename(SFLPHONE_UIDIR_UNINSTALLED, "./ui.xml", NULL); + if (g_file_test(path, G_FILE_TEST_EXISTS)) + { + gtk_ui_manager_add_ui_from_file(ui_manager, path, &error); + + if (error != NULL) + { + g_error_free(error); + return FALSE; + } + g_free(path); + } + else + { + path = g_build_filename(SFLPHONE_UIDIR, "./ui.xml", NULL); + if (g_file_test(path, G_FILE_TEST_EXISTS)) + { + gtk_ui_manager_add_ui_from_file(ui_manager, path, &error); + + if (error != NULL) + { + g_error_free(error); + return FALSE; + } + g_free(path); + } + else + return FALSE; + } + action_group = gtk_action_group_new("SFLphoneWindowActions"); + // To translate label and tooltip entries + gtk_action_group_set_translation_domain(action_group, "sflphone-client-gnome"); + gtk_action_group_add_actions(action_group, menu_entries, + G_N_ELEMENTS (menu_entries), window); + gtk_action_group_add_toggle_actions(action_group, toggle_menu_entries, + G_N_ELEMENTS (toggle_menu_entries), window); + //gtk_action_group_add_radio_actions (action_group, radio_menu_entries, G_N_ELEMENTS (radio_menu_entries), CALLTREE_CALLS, G_CALLBACK (calltree_switch_cb), window); + gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); + + *_ui_manager = ui_manager; + + return TRUE; } -static void edit_number_cb (GtkWidget *widget UNUSED, gpointer user_data) { - +static void +edit_number_cb(GtkWidget *widget UNUSED, gpointer user_data) +{ - show_edit_number ((callable_obj_t*)user_data); + show_edit_number((callable_obj_t*) user_data); } -void add_registered_accounts_to_menu (GtkWidget *menu) { - - GtkWidget *menu_items; - unsigned int i; - account_t* acc, *current; - gchar* alias; - - menu_items = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - gtk_widget_show (menu_items); - - for( i = 0 ; i < account_list_get_size() ; i++ ){ - acc = account_list_get_nth(i); - // Display only the registered accounts - if( g_strcasecmp( account_state_name(acc->state) , account_state_name(ACCOUNT_STATE_REGISTERED) ) == 0 ){ - alias = g_strconcat( g_hash_table_lookup(acc->properties , ACCOUNT_ALIAS) , " - ",g_hash_table_lookup(acc->properties , ACCOUNT_TYPE), NULL); - menu_items = gtk_check_menu_item_new_with_mnemonic(alias); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_object_set_data( G_OBJECT( menu_items ) , "account" , acc ); - g_free( alias ); - current = account_list_get_current(); - if(current){ - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items), - (g_strcasecmp( acc->accountID , current->accountID) == 0)? TRUE : FALSE); - } - g_signal_connect (G_OBJECT (menu_items), "activate", - G_CALLBACK (switch_account), - NULL); - gtk_widget_show (menu_items); - } // fi - } +void +add_registered_accounts_to_menu(GtkWidget *menu) +{ -} + GtkWidget *menu_items; + unsigned int i; + account_t* acc, *current; + gchar* alias; + + menu_items = gtk_separator_menu_item_new(); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + gtk_widget_show(menu_items); + + for (i = 0; i < account_list_get_size(); i++) + { + acc = account_list_get_nth(i); + // Display only the registered accounts + if (g_strcasecmp(account_state_name(acc->state), account_state_name( + ACCOUNT_STATE_REGISTERED)) == 0) + { + alias = g_strconcat(g_hash_table_lookup(acc->properties, + ACCOUNT_ALIAS), " - ", g_hash_table_lookup(acc->properties, + ACCOUNT_TYPE), NULL); + menu_items = gtk_check_menu_item_new_with_mnemonic(alias); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_object_set_data(G_OBJECT( menu_items ), "account", acc); + g_free(alias); + current = account_list_get_current(); + if (current) + { + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(menu_items), + (g_strcasecmp(acc->accountID, current->accountID) == 0) ? TRUE + : FALSE); + } + g_signal_connect (G_OBJECT (menu_items), "activate", + G_CALLBACK (switch_account), + NULL); + gtk_widget_show(menu_items); + } // fi + } +} - void -show_popup_menu (GtkWidget *my_widget, GdkEventButton *event) +void +show_popup_menu(GtkWidget *my_widget, GdkEventButton *event) { - // TODO update the selection to make sure the call under the mouse is the call selected - - // call type boolean - gboolean pickup = FALSE, hangup = FALSE, hold = FALSE, copy = FALSE, record = FALSE, detach = FALSE; - gboolean accounts = FALSE; - - // conference type boolean - gboolean hangup_conf = FALSE, hold_conf = FALSE; - - callable_obj_t * selectedCall; - conference_obj_t * selectedConf; - - if (calltab_get_selected_type(current_calls) == A_CALL) - { - DEBUG("MENUS: SELECTED A CALL"); - selectedCall = calltab_get_selected_call(current_calls); - - if (selectedCall) - { - copy = TRUE; - switch(selectedCall->_state) - { - case CALL_STATE_INCOMING: - pickup = TRUE; - hangup = TRUE; - detach = TRUE; - break; - case CALL_STATE_HOLD: - hangup = TRUE; - hold = TRUE; - detach = TRUE; - break; - case CALL_STATE_RINGING: - hangup = TRUE; - detach = TRUE; - break; - case CALL_STATE_DIALING: - pickup = TRUE; - hangup = TRUE; - accounts = TRUE; - break; - case CALL_STATE_RECORD: - case CALL_STATE_CURRENT: - hangup = TRUE; - hold = TRUE; - record = TRUE; - detach = TRUE; - break; - case CALL_STATE_BUSY: - case CALL_STATE_FAILURE: - hangup = TRUE; - break; - default: - WARN("Should not happen in show_popup_menu for calls!"); - break; - } - } - } - else - { - DEBUG("MENUS: SELECTED A CONF"); - selectedConf = calltab_get_selected_conf(); - - if (selectedConf) - { - switch(selectedConf->_state) - { - case CONFERENCE_STATE_ACTIVE_ATACHED: - hangup_conf = TRUE; - hold_conf = TRUE; - break; - case CONFERENCE_STATE_ACTIVE_DETACHED: - break; - case CONFERENCE_STATE_HOLD: - hangup_conf = TRUE; - hold_conf = TRUE; - break; - default: - WARN("Should not happen in show_popup_menu for conferences!"); - break; - } - } - - } - - GtkWidget *menu; - GtkWidget *image; - int button, event_time; - GtkWidget * menu_items; - - menu = gtk_menu_new (); - //g_signal_connect (menu, "deactivate", - // G_CALLBACK (gtk_widget_destroy), NULL); - if (calltab_get_selected_type(current_calls) == A_CALL) - { - DEBUG("BUILD CALL MENU"); - - if(copy) - { - menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_COPY, get_accel_group()); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate", - G_CALLBACK (edit_copy), - NULL); - gtk_widget_show (menu_items); - } - - menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_PASTE, get_accel_group()); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate", - G_CALLBACK (edit_paste), - NULL); - gtk_widget_show (menu_items); - - if(pickup || hangup || hold) - { - menu_items = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - gtk_widget_show (menu_items); - } - - if(pickup) - { - - menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Pick up")); - image = gtk_image_new_from_file( ICONS_DIR "/icon_accept.svg"); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate", - G_CALLBACK (call_pick_up), - NULL); - gtk_widget_show (menu_items); - } - - if(hangup) - { - menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Hang up")); - image = gtk_image_new_from_file( ICONS_DIR "/icon_hangup.svg"); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate", - G_CALLBACK (call_hang_up), - NULL); - gtk_widget_show (menu_items); - } - - if(hold) - { - menu_items = gtk_check_menu_item_new_with_mnemonic (_("On _Hold")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items), - (selectedCall->_state == CALL_STATE_HOLD ? TRUE : FALSE)); - g_signal_connect(G_OBJECT (menu_items), "activate", - G_CALLBACK (call_hold), - NULL); - gtk_widget_show (menu_items); - } - - if(record) - { - menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Record")); - image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_RECORD, GTK_ICON_SIZE_MENU); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate", - G_CALLBACK (call_record), - NULL); - gtk_widget_show (menu_items); - } - - } - else - { - DEBUG("BUILD CONFERENCE MENU"); - - if(hangup_conf) - { - menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Hang up")); - image = gtk_image_new_from_file( ICONS_DIR "/icon_hangup.svg"); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate", - G_CALLBACK (conference_hang_up), - NULL); - gtk_widget_show (menu_items); - } - - if(hold_conf) - { - menu_items = gtk_check_menu_item_new_with_mnemonic (_("On _Hold")); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items), - (selectedCall->_state == CALL_STATE_HOLD ? TRUE : FALSE)); - g_signal_connect(G_OBJECT (menu_items), "activate", - G_CALLBACK (conference_hold), - NULL); - gtk_widget_show (menu_items); - } - } - - if(accounts) - { - add_registered_accounts_to_menu (menu); - } - - if (event) - { - button = event->button; - event_time = event->time; - } - else - { - button = 0; - event_time = gtk_get_current_event_time (); - } - - gtk_menu_attach_to_widget (GTK_MENU (menu), my_widget, NULL); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - button, event_time); + // TODO update the selection to make sure the call under the mouse is the call selected + + // call type boolean + gboolean pickup = FALSE, hangup = FALSE, hold = FALSE, copy = FALSE, record = + FALSE, detach = FALSE; + gboolean accounts = FALSE; + + // conference type boolean + gboolean hangup_conf = FALSE, hold_conf = FALSE; + + callable_obj_t * selectedCall; + conference_obj_t * selectedConf; + + if (calltab_get_selected_type(current_calls) == A_CALL) + { + DEBUG("MENUS: SELECTED A CALL"); + selectedCall = calltab_get_selected_call(current_calls); + + if (selectedCall) + { + copy = TRUE; + switch (selectedCall->_state) + { + case CALL_STATE_INCOMING: + pickup = TRUE; + hangup = TRUE; + detach = TRUE; + break; + case CALL_STATE_HOLD: + hangup = TRUE; + hold = TRUE; + detach = TRUE; + break; + case CALL_STATE_RINGING: + hangup = TRUE; + detach = TRUE; + break; + case CALL_STATE_DIALING: + pickup = TRUE; + hangup = TRUE; + accounts = TRUE; + break; + case CALL_STATE_RECORD: + case CALL_STATE_CURRENT: + hangup = TRUE; + hold = TRUE; + record = TRUE; + detach = TRUE; + break; + case CALL_STATE_BUSY: + case CALL_STATE_FAILURE: + hangup = TRUE; + break; + default: + WARN("Should not happen in show_popup_menu for calls!") + ; + break; + } + } + } + else + { + DEBUG("MENUS: SELECTED A CONF"); + selectedConf = calltab_get_selected_conf(); + + if (selectedConf) + { + switch (selectedConf->_state) + { + case CONFERENCE_STATE_ACTIVE_ATACHED: + hangup_conf = TRUE; + hold_conf = TRUE; + break; + case CONFERENCE_STATE_ACTIVE_DETACHED: + break; + case CONFERENCE_STATE_HOLD: + hangup_conf = TRUE; + hold_conf = TRUE; + break; + default: + WARN("Should not happen in show_popup_menu for conferences!") + ; + break; + } + } + + } + + GtkWidget *menu; + GtkWidget *image; + int button, event_time; + GtkWidget * menu_items; + + menu = gtk_menu_new(); + //g_signal_connect (menu, "deactivate", + // G_CALLBACK (gtk_widget_destroy), NULL); + if (calltab_get_selected_type(current_calls) == A_CALL) + { + DEBUG("BUILD CALL MENU"); + + if (copy) + { + menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_COPY, + get_accel_group()); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate", + G_CALLBACK (edit_copy), + NULL); + gtk_widget_show(menu_items); + } + + menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_PASTE, + get_accel_group()); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate", + G_CALLBACK (edit_paste), + NULL); + gtk_widget_show(menu_items); + + if (pickup || hangup || hold) + { + menu_items = gtk_separator_menu_item_new(); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + gtk_widget_show(menu_items); + } + + if (pickup) + { + + menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Pick up")); + image = gtk_image_new_from_file(ICONS_DIR "/icon_accept.svg"); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate", + G_CALLBACK (call_pick_up), + NULL); + gtk_widget_show(menu_items); + } + + if (hangup) + { + menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Hang up")); + image = gtk_image_new_from_file(ICONS_DIR "/icon_hangup.svg"); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate", + G_CALLBACK (call_hang_up), + NULL); + gtk_widget_show(menu_items); + } + + if (hold) + { + menu_items = gtk_check_menu_item_new_with_mnemonic(_("On _Hold")); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items), + (selectedCall->_state == CALL_STATE_HOLD ? TRUE : FALSE)); + g_signal_connect(G_OBJECT (menu_items), "activate", + G_CALLBACK (call_hold), + NULL); + gtk_widget_show(menu_items); + } + + if (record) + { + menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Record")); + image = gtk_image_new_from_stock(GTK_STOCK_MEDIA_RECORD, + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate", + G_CALLBACK (call_record), + NULL); + gtk_widget_show(menu_items); + } + + } + else + { + DEBUG("BUILD CONFERENCE MENU"); + + if (hangup_conf) + { + menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Hang up")); + image = gtk_image_new_from_file(ICONS_DIR "/icon_hangup.svg"); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_items), image); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate", + G_CALLBACK (conference_hang_up), + NULL); + gtk_widget_show(menu_items); + } + + if (hold_conf) + { + menu_items = gtk_check_menu_item_new_with_mnemonic(_("On _Hold")); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items), + (selectedCall->_state == CALL_STATE_HOLD ? TRUE : FALSE)); + g_signal_connect(G_OBJECT (menu_items), "activate", + G_CALLBACK (conference_hold), + NULL); + gtk_widget_show(menu_items); + } + } + + if (accounts) + { + add_registered_accounts_to_menu(menu); + } + + if (event) + { + button = event->button; + event_time = event->time; + } + else + { + button = 0; + event_time = gtk_get_current_event_time(); + } + + gtk_menu_attach_to_widget(GTK_MENU (menu), my_widget, NULL); + gtk_menu_popup(GTK_MENU (menu), NULL, NULL, NULL, NULL, button, event_time); } - - void +void show_popup_menu_history(GtkWidget *my_widget, GdkEventButton *event) { - gboolean pickup = FALSE; - gboolean remove = FALSE; - gboolean edit = FALSE; - gboolean accounts = FALSE; - - callable_obj_t * selectedCall = calltab_get_selected_call( history ); - if (selectedCall) - { - remove = TRUE; - pickup = TRUE; - edit = TRUE; - accounts = TRUE; - } - - GtkWidget *menu; - GtkWidget *image; - int button, event_time; - GtkWidget * menu_items; - - menu = gtk_menu_new (); - //g_signal_connect (menu, "deactivate", - // G_CALLBACK (gtk_widget_destroy), NULL); - - if(pickup) - { - - menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Call back")); - image = gtk_image_new_from_file( ICONS_DIR "/icon_accept.svg"); - gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( menu_items ), image ); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (call_back), NULL); - gtk_widget_show (menu_items); - } - - menu_items = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - gtk_widget_show (menu_items); - - if (edit) - { - menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_EDIT, get_accel_group()); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (edit_number_cb), selectedCall); - gtk_widget_show (menu_items); - } - - - if(remove) - { - menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_DELETE, get_accel_group()); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate", G_CALLBACK (remove_from_history), NULL); - gtk_widget_show (menu_items); - } - - if(accounts) - { - add_registered_accounts_to_menu (menu); - } - - if (event) - { - button = event->button; - event_time = event->time; - } - else - { - button = 0; - event_time = gtk_get_current_event_time (); - } - - gtk_menu_attach_to_widget (GTK_MENU (menu), my_widget, NULL); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - button, event_time); + gboolean pickup = FALSE; + gboolean remove = FALSE; + gboolean edit = FALSE; + gboolean accounts = FALSE; + + callable_obj_t * selectedCall = calltab_get_selected_call(history); + if (selectedCall) + { + remove = TRUE; + pickup = TRUE; + edit = TRUE; + accounts = TRUE; + } + + GtkWidget *menu; + GtkWidget *image; + int button, event_time; + GtkWidget * menu_items; + + menu = gtk_menu_new(); + //g_signal_connect (menu, "deactivate", + // G_CALLBACK (gtk_widget_destroy), NULL); + + if (pickup) + { + + menu_items = gtk_image_menu_item_new_with_mnemonic(_("_Call back")); + image = gtk_image_new_from_file(ICONS_DIR "/icon_accept.svg"); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM ( menu_items ), image); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (call_back), NULL); + gtk_widget_show(menu_items); + } + + menu_items = gtk_separator_menu_item_new(); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + gtk_widget_show(menu_items); + + if (edit) + { + menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_EDIT, + get_accel_group()); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (edit_number_cb), selectedCall); + gtk_widget_show(menu_items); + } + + if (remove) + { + menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_DELETE, + get_accel_group()); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate", G_CALLBACK (remove_from_history), NULL); + gtk_widget_show(menu_items); + } + + if (accounts) + { + add_registered_accounts_to_menu(menu); + } + + if (event) + { + button = event->button; + event_time = event->time; + } + else + { + button = 0; + event_time = gtk_get_current_event_time(); + } + + gtk_menu_attach_to_widget(GTK_MENU (menu), my_widget, NULL); + gtk_menu_popup(GTK_MENU (menu), NULL, NULL, NULL, NULL, button, event_time); } - void +void show_popup_menu_contacts(GtkWidget *my_widget, GdkEventButton *event) { - gboolean pickup = FALSE; - gboolean accounts = FALSE; - gboolean edit = FALSE; - - callable_obj_t * selectedCall = calltab_get_selected_call( contacts ); - if (selectedCall) - { - pickup = TRUE; - accounts = TRUE; - edit = TRUE; - } - - GtkWidget *menu; - GtkWidget *image; - int button, event_time; - GtkWidget * menu_items; - - menu = gtk_menu_new (); - //g_signal_connect (menu, "deactivate", - // G_CALLBACK (gtk_widget_destroy), NULL); - - if(pickup) - { - - menu_items = gtk_image_menu_item_new_with_mnemonic(_("_New call")); - image = gtk_image_new_from_file( ICONS_DIR "/icon_accept.svg"); - gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM ( menu_items ), image ); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (call_back), NULL); - gtk_widget_show (menu_items); - } - - if (edit) - { - menu_items = gtk_image_menu_item_new_from_stock( GTK_STOCK_EDIT, get_accel_group()); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items); - g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (edit_number_cb), selectedCall); - gtk_widget_show (menu_items); - } - - if(accounts) - { - add_registered_accounts_to_menu (menu); - } - - if (event) - { - button = event->button; - event_time = event->time; - } - else - { - button = 0; - event_time = gtk_get_current_event_time (); - } - - gtk_menu_attach_to_widget (GTK_MENU (menu), my_widget, NULL); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - button, event_time); + gboolean pickup = FALSE; + gboolean accounts = FALSE; + gboolean edit = FALSE; + + callable_obj_t * selectedCall = calltab_get_selected_call(contacts); + if (selectedCall) + { + pickup = TRUE; + accounts = TRUE; + edit = TRUE; + } + + GtkWidget *menu; + GtkWidget *image; + int button, event_time; + GtkWidget * menu_items; + + menu = gtk_menu_new(); + //g_signal_connect (menu, "deactivate", + // G_CALLBACK (gtk_widget_destroy), NULL); + + if (pickup) + { + + menu_items = gtk_image_menu_item_new_with_mnemonic(_("_New call")); + image = gtk_image_new_from_file(ICONS_DIR "/icon_accept.svg"); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM ( menu_items ), image); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (call_back), NULL); + gtk_widget_show(menu_items); + } + + if (edit) + { + menu_items = gtk_image_menu_item_new_from_stock(GTK_STOCK_EDIT, + get_accel_group()); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menu_items); + g_signal_connect (G_OBJECT (menu_items), "activate",G_CALLBACK (edit_number_cb), selectedCall); + gtk_widget_show(menu_items); + } + + if (accounts) + { + add_registered_accounts_to_menu(menu); + } + + if (event) + { + button = event->button; + event_time = event->time; + } + else + { + button = 0; + event_time = gtk_get_current_event_time(); + } + + gtk_menu_attach_to_widget(GTK_MENU (menu), my_widget, NULL); + gtk_menu_popup(GTK_MENU (menu), NULL, NULL, NULL, NULL, button, event_time); } +static void +ok_cb(GtkWidget *widget UNUSED, gpointer userdata) +{ -static void ok_cb (GtkWidget *widget UNUSED, gpointer userdata) { - - gchar *new_number; - callable_obj_t *modified_call, *original; + gchar *new_number; + callable_obj_t *modified_call, *original; - // Change the number of the selected call before calling - new_number = (gchar*) gtk_entry_get_text (GTK_ENTRY (editable_num)); - original = (callable_obj_t*)userdata; + // Change the number of the selected call before calling + new_number = (gchar*) gtk_entry_get_text(GTK_ENTRY (editable_num)); + original = (callable_obj_t*) userdata; - // Create the new call - create_new_call (CALL, CALL_STATE_DIALING, "", g_strdup (original->_accountID), original->_peer_name, g_strdup (new_number), &modified_call); + // Create the new call + create_new_call(CALL, CALL_STATE_DIALING, "", g_strdup(original->_accountID), + original->_peer_name, g_strdup(new_number), &modified_call); - // Update the internal data structure and the GUI - calllist_add(current_calls, modified_call); - calltree_add_call(current_calls, modified_call, NULL); - sflphone_place_call(modified_call); - calltree_display (current_calls); + // Update the internal data structure and the GUI + calllist_add(current_calls, modified_call); + calltree_add_call(current_calls, modified_call, NULL); + sflphone_place_call(modified_call); + calltree_display(current_calls); - // Close the contextual menu - gtk_widget_destroy (GTK_WIDGET (edit_dialog)); + // Close the contextual menu + gtk_widget_destroy(GTK_WIDGET (edit_dialog)); } -static void on_delete (GtkWidget * widget) +static void +on_delete(GtkWidget * widget) { - gtk_widget_destroy (widget); + gtk_widget_destroy(widget); } -void show_edit_number (callable_obj_t *call) { +void +show_edit_number(callable_obj_t *call) +{ - GtkWidget *ok, *hbox, *image; - GdkPixbuf *pixbuf; + GtkWidget *ok, *hbox, *image; + GdkPixbuf *pixbuf; - edit_dialog = GTK_DIALOG (gtk_dialog_new()); + edit_dialog = GTK_DIALOG (gtk_dialog_new()); - // Set window properties - gtk_window_set_default_size(GTK_WINDOW(edit_dialog), 300, 20); - gtk_window_set_title(GTK_WINDOW(edit_dialog), _("Edit phone number")); - gtk_window_set_resizable (GTK_WINDOW (edit_dialog), FALSE); + // Set window properties + gtk_window_set_default_size(GTK_WINDOW(edit_dialog), 300, 20); + gtk_window_set_title(GTK_WINDOW(edit_dialog), _("Edit phone number")); + gtk_window_set_resizable(GTK_WINDOW (edit_dialog), FALSE); - g_signal_connect (G_OBJECT (edit_dialog), "delete-event", G_CALLBACK (on_delete), NULL); + g_signal_connect (G_OBJECT (edit_dialog), "delete-event", G_CALLBACK (on_delete), NULL); - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start(GTK_BOX (edit_dialog->vbox), hbox, TRUE, TRUE, 0); + hbox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX (edit_dialog->vbox), hbox, TRUE, TRUE, 0); - // Set the number to be edited - editable_num = gtk_entry_new (); + // Set the number to be edited + editable_num = gtk_entry_new(); #if GTK_CHECK_VERSION(2,12,0) - gtk_widget_set_tooltip_text(GTK_WIDGET(editable_num), _("Edit the phone number before making a call")); + gtk_widget_set_tooltip_text(GTK_WIDGET(editable_num), + _("Edit the phone number before making a call")); #endif - if (call) - gtk_entry_set_text(GTK_ENTRY(editable_num), g_strdup (call->_peer_number)); - else - ERROR ("This a bug, the call should be defined. menus.c line 1051"); + if (call) + gtk_entry_set_text(GTK_ENTRY(editable_num), g_strdup(call->_peer_number)); + else + ERROR ("This a bug, the call should be defined. menus.c line 1051"); - gtk_box_pack_start(GTK_BOX (hbox), editable_num, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX (hbox), editable_num, TRUE, TRUE, 0); - // Set a custom image for the button - pixbuf = gdk_pixbuf_new_from_file_at_scale (ICONS_DIR "/outgoing.svg", 32, 32, TRUE, NULL); - image = gtk_image_new_from_pixbuf (pixbuf); - ok = gtk_button_new (); - gtk_button_set_image (GTK_BUTTON (ok), image); - gtk_box_pack_start(GTK_BOX (hbox), ok, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT (ok), "clicked", G_CALLBACK (ok_cb), call); + // Set a custom image for the button + pixbuf = gdk_pixbuf_new_from_file_at_scale(ICONS_DIR "/outgoing.svg", 32, 32, + TRUE, NULL); + image = gtk_image_new_from_pixbuf(pixbuf); + ok = gtk_button_new(); + gtk_button_set_image(GTK_BUTTON (ok), image); + gtk_box_pack_start(GTK_BOX (hbox), ok, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT (ok), "clicked", G_CALLBACK (ok_cb), call); - gtk_widget_show_all (edit_dialog->vbox); + gtk_widget_show_all(edit_dialog->vbox); - gtk_dialog_run(edit_dialog); + gtk_dialog_run(edit_dialog); } -GtkWidget* create_waiting_icon() +GtkWidget* +create_waiting_icon() { - GtkWidget * waiting_icon; - waiting_icon = gtk_image_menu_item_new_with_label(""); - gtk_image_menu_item_set_image ( - GTK_IMAGE_MENU_ITEM(waiting_icon), - gtk_image_new_from_animation( - gdk_pixbuf_animation_new_from_file(ICONS_DIR "/wait-on.gif", NULL))); - gtk_menu_item_set_right_justified(GTK_MENU_ITEM(waiting_icon),TRUE); - - return waiting_icon; + GtkWidget * waiting_icon; + waiting_icon = gtk_image_menu_item_new_with_label(""); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(waiting_icon), + gtk_image_new_from_animation(gdk_pixbuf_animation_new_from_file( + ICONS_DIR "/wait-on.gif", NULL))); + gtk_menu_item_set_right_justified(GTK_MENU_ITEM(waiting_icon), TRUE); + + return waiting_icon; } -void create_menus (GtkUIManager *ui_manager, GtkWidget **widget) +void +create_menus(GtkUIManager *ui_manager, GtkWidget **widget) { - GtkWidget * menu_bar; - - menu_bar = gtk_ui_manager_get_widget (ui_manager, "/MenuBar"); - pickUpAction = gtk_ui_manager_get_action (ui_manager, "/MenuBar/CallMenu/PickUp"); - newCallAction = gtk_ui_manager_get_action (ui_manager, "/MenuBar/CallMenu/NewCall"); - hangUpAction = gtk_ui_manager_get_action (ui_manager, "/MenuBar/CallMenu/HangUp"); - holdMenu = gtk_ui_manager_get_widget (ui_manager, "/MenuBar/CallMenu/OnHoldMenu"); - recordAction = gtk_ui_manager_get_action (ui_manager, "/MenuBar/CallMenu/Record"); - copyAction = gtk_ui_manager_get_action (ui_manager, "/MenuBar/EditMenu/Copy"); - pasteAction = gtk_ui_manager_get_action (ui_manager, "/MenuBar/EditMenu/Paste"); - volumeToggle = gtk_ui_manager_get_action (ui_manager, "/MenuBar/ViewMenu/VolumeControls"); - - // Set the toggle buttons - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (ui_manager, "/MenuBar/ViewMenu/Dialpad")), (gboolean) SHOW_DIALPAD); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (volumeToggle), (gboolean) SHOW_VOLUME); - - gtk_action_set_sensitive (GTK_ACTION (volumeToggle), SHOW_ALSA_CONF); - - // Disable it right now - gtk_action_set_sensitive (GTK_ACTION (gtk_ui_manager_get_action (ui_manager, "/MenuBar/ViewMenu/Toolbar")), FALSE); - - waitingLayer = create_waiting_icon (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), waitingLayer); - - *widget = menu_bar; + GtkWidget * menu_bar; + + menu_bar = gtk_ui_manager_get_widget(ui_manager, "/MenuBar"); + pickUpAction = gtk_ui_manager_get_action(ui_manager, + "/MenuBar/CallMenu/PickUp"); + newCallAction = gtk_ui_manager_get_action(ui_manager, + "/MenuBar/CallMenu/NewCall"); + hangUpAction = gtk_ui_manager_get_action(ui_manager, + "/MenuBar/CallMenu/HangUp"); + holdMenu = gtk_ui_manager_get_widget(ui_manager, + "/MenuBar/CallMenu/OnHoldMenu"); + recordAction = gtk_ui_manager_get_action(ui_manager, + "/MenuBar/CallMenu/Record"); + copyAction = gtk_ui_manager_get_action(ui_manager, "/MenuBar/EditMenu/Copy"); + pasteAction + = gtk_ui_manager_get_action(ui_manager, "/MenuBar/EditMenu/Paste"); + volumeToggle = gtk_ui_manager_get_action(ui_manager, + "/MenuBar/ViewMenu/VolumeControls"); + + // Set the toggle buttons + gtk_toggle_action_set_active( + GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (ui_manager, "/MenuBar/ViewMenu/Dialpad")), + (gboolean) SHOW_DIALPAD); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION (volumeToggle), + (gboolean) SHOW_VOLUME); + + gtk_action_set_sensitive(GTK_ACTION (volumeToggle), SHOW_ALSA_CONF); + + // Disable it right now + gtk_action_set_sensitive( + GTK_ACTION (gtk_ui_manager_get_action (ui_manager, "/MenuBar/ViewMenu/Toolbar")), + FALSE); + + waitingLayer = create_waiting_icon(); + gtk_menu_shell_append(GTK_MENU_SHELL (menu_bar), waitingLayer); + + *widget = menu_bar; } -void create_toolbar_actions (GtkUIManager *ui_manager, GtkWidget **widget) +void +create_toolbar_actions(GtkUIManager *ui_manager, GtkWidget **widget) { - toolbar = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions"); - - holdToolbar = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/OnHoldToolbar"); - offHoldToolbar = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/OffHoldToolbar"); - transferToolbar = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/TransferToolbar"); - voicemailAction = gtk_ui_manager_get_action (ui_manager, "/ToolbarActions/Voicemail"); - voicemailToolbar = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/VoicemailToolbar"); - newCallWidget = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/NewCallToolbar"); - pickUpWidget = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/PickUpToolbar"); - hangUpWidget = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/HangUpToolbar"); - recordWidget = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/RecordToolbar"); - historyButton = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/HistoryToolbar"); - contactButton = gtk_ui_manager_get_widget (ui_manager, "/ToolbarActions/AddressbookToolbar"); - - // Set the handler ID for the transfer - transfertButtonConnId = g_signal_connect (G_OBJECT (transferToolbar), "toggled", G_CALLBACK (call_transfer_cb), NULL); - recordButtonConnId = g_signal_connect (G_OBJECT (recordWidget), "toggled", G_CALLBACK (call_record), NULL); - active_calltree = current_calls; - - *widget = toolbar; + toolbar = gtk_ui_manager_get_widget(ui_manager, "/ToolbarActions"); + + holdToolbar = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/OnHoldToolbar"); + offHoldToolbar = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/OffHoldToolbar"); + transferToolbar = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/TransferToolbar"); + voicemailAction = gtk_ui_manager_get_action(ui_manager, + "/ToolbarActions/Voicemail"); + voicemailToolbar = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/VoicemailToolbar"); + newCallWidget = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/NewCallToolbar"); + pickUpWidget = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/PickUpToolbar"); + hangUpWidget = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/HangUpToolbar"); + recordWidget = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/RecordToolbar"); + historyButton = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/HistoryToolbar"); + contactButton = gtk_ui_manager_get_widget(ui_manager, + "/ToolbarActions/AddressbookToolbar"); + + // Set the handler ID for the transfer + transfertButtonConnId + = g_signal_connect (G_OBJECT (transferToolbar), "toggled", G_CALLBACK (call_transfer_cb), NULL); + recordButtonConnId + = g_signal_connect (G_OBJECT (recordWidget), "toggled", G_CALLBACK (call_record), NULL); + active_calltree = current_calls; + + *widget = toolbar; } diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp index e532515d604c30dac6e10e9e3a0fe8c3ce2fe2f7..646aa89b95d65652bb446f860364e011cc0ec92f 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp @@ -125,14 +125,14 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) void AudioRtpFactory::start (void) { if (_rtpSession == NULL) { - throw AudioRtpFactoryException ("_rtpSession was null when trying to start audio thread"); + throw AudioRtpFactoryException ("RTP: Error: _rtpSession was null when trying to start audio thread"); } switch (_rtpSessionType) { case Sdes: if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread() != 0) { - throw AudioRtpFactoryException ("Failed to start AudioSRtpSession thread"); + throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSRtpSession thread"); } break; @@ -140,7 +140,7 @@ void AudioRtpFactory::start (void) _debug ("Starting symmetric rtp thread"); if (static_cast<AudioSymmetricRtpSession *> (_rtpSession)->startRtpThread() != 0) { - throw AudioRtpFactoryException ("Failed to start AudioSymmetricRtpSession thread"); + throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSymmetricRtpSession thread"); } break; @@ -148,9 +148,8 @@ void AudioRtpFactory::start (void) case Zrtp: if (static_cast<AudioZrtpSession *> (_rtpSession)->startRtpThread() != 0) { - throw AudioRtpFactoryException ("Failed to start AudioZrtpSession thread"); + throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioZrtpSession thread"); } - break; } } @@ -158,10 +157,10 @@ void AudioRtpFactory::start (void) void AudioRtpFactory::stop (void) { ost::MutexLock mutex (_audioRtpThreadMutex); - _debug ("Stopping audio rtp session"); + _info("RTP: Stopping audio rtp session"); if (_rtpSession == NULL) { - _debugException ("_rtpSession is null when trying to stop. Returning."); + _debugException ("RTP: Error: _rtpSession is null when trying to stop. Returning."); return; } @@ -183,16 +182,16 @@ void AudioRtpFactory::stop (void) _rtpSession = NULL; } catch (...) { - _debugException ("Exception caught when stopping the audio rtp session"); - throw AudioRtpFactoryException("caught exception in AudioRtpFactory::stop"); + _debugException ("RTP: Error: Exception caught when stopping the audio rtp session"); + throw AudioRtpFactoryException("RTP: Error: caught exception in AudioRtpFactory::stop"); } } void AudioRtpFactory::updateDestinationIpAddress (void) { - _debug ("Updating IP address"); + _info ("RTP: Updating IP address"); if (_rtpSession == NULL) { - throw AudioRtpFactoryException ("_rtpSession was null when trying to update IP address"); + throw AudioRtpFactoryException ("RTP: Error: _rtpSession was null when trying to update IP address"); } switch (_rtpSessionType) { @@ -216,19 +215,20 @@ sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession() if ( (_rtpSessionType == Zrtp) && (_rtpSessionType != NULL)) { return static_cast<AudioZrtpSession *> (_rtpSession); } else { - throw AudioRtpFactoryException("_rtpSession is NULL in getAudioZrtpSession"); + throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in getAudioZrtpSession"); } } - void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) +void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) { if ( _rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) { static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo(nego); } else { - throw AudioRtpFactoryException("_rtpSession is NULL in setRemoteCryptoInfo"); + throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo"); } } + } diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h index cfa14165f1cf0f85960eb775b4b09fd476df7062..0076c968c8262ccd743a56b53d421439b1878dd4 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h @@ -63,27 +63,27 @@ namespace sfl { void initAudioRtpConfig(SIPCall *ca); - /** - * Lazy instantiation method. Create a new RTP session of a given - * type according to the content of the configuration file. - * @param ca A pointer on a SIP call - * @return A new AudioRtpSession object - */ - void initAudioRtpSession(SIPCall *ca); - - /** - * Start the audio rtp thread of the type specified in the configuration - * file. initAudioRtpSession must have been called prior to that. - * @param None - */ - void start(); - - /** - * Stop the audio rtp thread of the type specified in the configuration - * file. initAudioRtpSession must have been called prior to that. - * @param None - */ - void stop(); + /** + * Lazy instantiation method. Create a new RTP session of a given + * type according to the content of the configuration file. + * @param ca A pointer on a SIP call + * @return A new AudioRtpSession object + */ + void initAudioRtpSession(SIPCall *ca); + + /** + * Start the audio rtp thread of the type specified in the configuration + * file. initAudioRtpSession must have been called prior to that. + * @param None + */ + void start(); + + /** + * Stop the audio rtp thread of the type specified in the configuration + * file. initAudioRtpSession must have been called prior to that. + * @param None + */ + void stop(); /** * Update current RTP destination address with one stored in call diff --git a/sflphone-common/src/audio/audiortp/AudioRtpSession.h b/sflphone-common/src/audio/audiortp/AudioRtpSession.h index 29057bec3ec82fbcb302f8e172164d1f8a20bbf0..b6d4908445ba7cee17c3230976ec340413329f93 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioRtpSession.h @@ -67,10 +67,10 @@ namespace sfl { int startRtpThread(); - /** - * Used mostly when receiving a reinvite - */ - void updateDestinationIpAddress(void); + /** + * Used mostly when receiving a reinvite + */ + void updateDestinationIpAddress(void); private: @@ -104,15 +104,16 @@ namespace sfl { // start() with no semaphore at all. ost::Semaphore * _mainloopSemaphore; - // Main destination address for this rtp session. - // Stored in case or reINVITE, which may require to forget - // this destination and update a new one. - ost::InetHostAddress _remote_ip; + // Main destination address for this rtp session. + // Stored in case or reINVITE, which may require to forget + // this destination and update a new one. + ost::InetHostAddress _remote_ip; + - // Main destination port for this rtp session. - // Stored in case reINVITE, which may require to forget - // this destination and update a new one - unsigned short _remote_port; + // Main destination port for this rtp session. + // Stored in case reINVITE, which may require to forget + // this destination and update a new one + unsigned short _remote_port; AudioCodec * _audiocodec; @@ -163,23 +164,23 @@ namespace sfl { */ ManagerImpl * _manager; - /** - * Sampling rate of audio converter - */ - int _converterSamplingRate; + /** + * Sampling rate of audio converter + */ + int _converterSamplingRate; - /** - * Timestamp for this session - */ - int _timestamp; + /** + * Timestamp for this session + */ + int _timestamp; - /** - * Time counter used to trigger incoming call notification - */ - int _countNotificationTime; + /** + * Time counter used to trigger incoming call notification + */ + int _countNotificationTime; protected: - SIPCall * _ca; + SIPCall * _ca; }; @@ -208,7 +209,7 @@ namespace sfl { assert(_ca); - _debug ("Local audio port %i will be used", _ca->getLocalAudioPort()); + _info ("Rtp: Local audio port %i will be used", _ca->getLocalAudioPort()); //mic, we receive from soundcard in stereo, and we send encoded _audiolayer = _manager->getAudioDriver(); @@ -223,7 +224,7 @@ namespace sfl { template <typename D> AudioRtpSession<D>::~AudioRtpSession() { - _debug ("Delete AudioRtpSession instance"); + _debug ("Rtp: Delete AudioRtpSession instance"); try { terminate(); @@ -232,9 +233,7 @@ namespace sfl { throw; } - _debug("Unbind audio RTP stream for call id %s", _ca->getCallId().c_str()); - // _audiolayer->getMainBuffer()->unBindAll(_ca->getCallId()); - _manager->getAudioDriver()->getMainBuffer()->unBindAll(_ca->getCallId()); + _manager->getAudioDriver()->getMainBuffer()->unBindAll(_ca->getCallId()); delete [] _micData; delete [] _micDataConverted; @@ -243,22 +242,21 @@ namespace sfl { delete [] _spkrDataConverted; delete _time; delete _converter; - _debug ("AudioRtpSession instance deleted"); } template <typename D> void AudioRtpSession<D>::initBuffers() { - // Set sampling rate, main buffer choose the highest one - // _audiolayer->getMainBuffer()->setInternalSamplingRate(_codecSampleRate); + // Set sampling rate, main buffer choose the highest one + // _audiolayer->getMainBuffer()->setInternalSamplingRate(_codecSampleRate); _manager->getAudioDriver()->getMainBuffer()->setInternalSamplingRate(_codecSampleRate); - // may be different than one already setted - // converterSamplingRate = _audiolayer->getMainBuffer()->getInternalSamplingRate(); - _converterSamplingRate = _manager->getAudioDriver()->getMainBuffer()->getInternalSamplingRate(); + // may be different than one already setted + // converterSamplingRate = _audiolayer->getMainBuffer()->getInternalSamplingRate(); + _converterSamplingRate = _manager->getAudioDriver()->getMainBuffer()->getInternalSamplingRate(); - // initialize SampleRate converter using AudioLayer's sampling rate - // (internal buffers initialized with maximal sampling rate and frame size) + // initialize SampleRate converter using AudioLayer's sampling rate + // (internal buffers initialized with maximal sampling rate and frame size) _converter = new SamplerateConverter(_layerSampleRate, _layerFrameSize); int nbSamplesMax = (int)(_codecSampleRate * _layerFrameSize /1000)*2; @@ -268,7 +266,7 @@ namespace sfl { _spkrDataConverted = new SFLDataFormat[nbSamplesMax]; _spkrDataDecoded = new SFLDataFormat[nbSamplesMax]; - _manager->addStream(_ca->getCallId()); + _manager->addStream(_ca->getCallId()); } template <typename D> @@ -288,8 +286,8 @@ namespace sfl { { assert(_ca); - AudioCodecType pl = (AudioCodecType)_ca->getLocalSDP()->get_session_media()->getPayload(); - _audiocodec = _manager->getCodecDescriptorMap().instantiateCodec(pl); + AudioCodecType pl = (AudioCodecType)_ca->getLocalSDP()->get_session_media()->getPayload(); + _audiocodec = _manager->getCodecDescriptorMap().instantiateCodec(pl); if (_audiocodec == NULL) { _debug ("No audiocodec, can't init RTP media"); @@ -318,26 +316,29 @@ namespace sfl { void AudioRtpSession<D>::setDestinationIpAddress(void) { if (_ca == NULL) { - _debug ("Sipcall is gone."); + _warn ("Rtp: Sipcall is gone."); throw AudioRtpSessionException(); } - _debug ("Setting IP address for the RTP session"); + _info ("RTP: Setting IP address for the RTP session"); - // Store remote ip in case we would need to forget current destination + // Store remote ip in case we would need to forget current destination _remote_ip = ost::InetHostAddress(_ca->getLocalSDP()->get_remote_ip().c_str()); - _debug ("Init audio RTP session: remote ip %s", _ca->getLocalSDP()->get_remote_ip().data()); if (!_remote_ip) { - _debug ("Target IP address [%s] is not correct!", _ca->getLocalSDP()->get_remote_ip().data()); + _warn("Rtp: Target IP address (%s) is not correct!", + _ca->getLocalSDP()->get_remote_ip().data()); return; } - // Store remote port in case we would need to forget current destination - _remote_port = (unsigned short) _ca->getLocalSDP()->get_remote_audio_port(); + // Store remote port in case we would need to forget current destination + _remote_port = (unsigned short) _ca->getLocalSDP()->get_remote_audio_port(); + + _info("RTP: New remote address for session: %s:%d", + _ca->getLocalSDP()->get_remote_ip().data(), _remote_port); if (! static_cast<D*>(this)->addDestination (_remote_ip, _remote_port)) { - _debug ("Can't add destination to session!"); + _warn("Rtp: Can't add new destination to session!"); return; } } @@ -346,12 +347,13 @@ namespace sfl { void AudioRtpSession<D>::updateDestinationIpAddress(void) { // Destination address are stored in a list in ccrtp - // This method clear off this entry - _debug("updateDestinationIpAddress: remove destination %s", _ca->getLocalSDP()->get_remote_ip().c_str()); - static_cast<D*>(this)->forgetDestination(_remote_ip, _remote_port); + // This method remove the current destination entry + + if(!static_cast<D*>(this)->forgetDestination(_remote_ip, _remote_port, _remote_port+1)) + _warn("Rtp: Could not remove previous destination"); - // new destination is stored in call - // we just need to recall this method + // new destination is stored in call + // we just need to recall this method setDestinationIpAddress(); } @@ -534,7 +536,6 @@ namespace sfl { { setSessionTimeouts(); - setDestinationIpAddress(); setSessionMedia(); initBuffers(); diff --git a/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp index 5b6b67101f740635b5eb7f9ebcc77343689eba93..cb82fe29e227fe0071d48c6aeda2cab3be5e9008 100644 --- a/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp @@ -38,7 +38,6 @@ AudioZrtpSession::AudioZrtpSession (ManagerImpl * manager, SIPCall * sipcall, co { _debug ("AudioZrtpSession initialized"); initializeZid(); - // startZrtp(); } void AudioZrtpSession::initializeZid (void) diff --git a/sflphone-common/src/audio/audiortp/AudioZrtpSession.h b/sflphone-common/src/audio/audiortp/AudioZrtpSession.h index 2e41e04b45b42086f903e551207563cdd9fdfba7..138bd2684733881494e2e26f8e1af01c85fe931c 100644 --- a/sflphone-common/src/audio/audiortp/AudioZrtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioZrtpSession.h @@ -38,8 +38,8 @@ namespace sfl { class AudioZrtpSession : public ost::SymmetricZRTPSession, public AudioRtpSession<AudioZrtpSession> { public: - AudioZrtpSession(ManagerImpl * manager, SIPCall * sipcall, const std::string& zidFilename); - + AudioZrtpSession(ManagerImpl * manager, SIPCall * sipcall, const std::string& zidFilename); + private: void initializeZid(void); std::string _zidFilename; diff --git a/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp b/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp index f866b39e007a7b9ffd11fb4c5307a05c6b9f0547..145792e0bce09f97977772b4602a12559e2d4566 100644 --- a/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp +++ b/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp @@ -150,7 +150,6 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _infoMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug:"); } } @@ -158,7 +157,6 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _warningMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug:"); } } @@ -166,10 +164,11 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _severeMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug:"); } } + + if (sev == ZrtpError) { if (subCode < 0) { // received an error packet from peer subCode *= -1; @@ -181,7 +180,7 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _zrtpMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug: %s", msg->c_str()); + } } } diff --git a/sflphone-common/src/dbus/configurationmanager-introspec.xml b/sflphone-common/src/dbus/configurationmanager-introspec.xml index 3361c16dd5a6b74dd9b6a60241b664b059fa6350..6be7c8b6d3168ecaff8727ba732214bdffa8d150 100644 --- a/sflphone-common/src/dbus/configurationmanager-introspec.xml +++ b/sflphone-common/src/dbus/configurationmanager-introspec.xml @@ -461,6 +461,15 @@ <arg type="i" name="posY" direction="in"/> </method> + <method name="enableStatusIcon"> + <arg type="s" name="value" direction="in"/> + </method> + + <method name="isStatusIconEnabled"> + <arg type="s" name="value" direction="out"/> + </method> + + <!-- Addressbook configuration --> <method name="getAddressbookSettings"> <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringInt"/> diff --git a/sflphone-common/src/dbus/configurationmanager.cpp b/sflphone-common/src/dbus/configurationmanager.cpp index 1eb0c06ff7670e2a80ca120085566fd3a0e29328..84588ea011319c0a4e23b4b2b4ab363167f75791 100644 --- a/sflphone-common/src/dbus/configurationmanager.cpp +++ b/sflphone-common/src/dbus/configurationmanager.cpp @@ -868,3 +868,13 @@ void ConfigurationManager::setWindowPositionY (const int32_t& posY) { Manager::instance ().setConfig (PREFERENCES, WINDOW_POSITION_Y, posY); } + +void ConfigurationManager::enableStatusIcon (const std::string& value) { + + Manager::instance ().setConfig (PREFERENCES, SHOW_STATUSICON, value); +} + +std::string ConfigurationManager::isStatusIconEnabled (void) { + + return Manager::instance ().getConfigString (PREFERENCES, SHOW_STATUSICON); +} diff --git a/sflphone-common/src/dbus/configurationmanager.h b/sflphone-common/src/dbus/configurationmanager.h index 7749fd233ad4fc6073a5564b3feb63800a28c3ca..eb1f63107285d0df3171f0680547d18418076c59 100644 --- a/sflphone-common/src/dbus/configurationmanager.h +++ b/sflphone-common/src/dbus/configurationmanager.h @@ -123,6 +123,9 @@ public: void setWindowPositionX (const int32_t& posX); void setWindowPositionY (const int32_t& posY); + void enableStatusIcon (const std::string&); + std::string isStatusIconEnabled (void); + std::map<std::string, int32_t> getAddressbookSettings (void); void setAddressbookSettings (const std::map<std::string, int32_t>& settings); std::vector< std::string > getAddressbookList ( void ); diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index fc85025e76608bf0f11aca32ba66569b8aa7331f..f4e3f899ebb350e93cf2a9878225a64a105dbd22 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -51,7 +51,6 @@ #include <sys/types.h> // mkdir(2) #include <sys/stat.h> // mkdir(2) #include <pwd.h> // getpwuid - #define DIRECT_IP_CALL "IP CALL" #define fill_config_str(name, value) \ @@ -61,2132 +60,2007 @@ #define MD5_APPEND(pms,buf,len) pj_md5_update(pms, (const pj_uint8_t*)buf, len) -ManagerImpl::ManagerImpl (void) - : _hasTriedToRegister (false) - , _config() - , _currentCallId2() - , _currentCallMutex() - , _codecBuilder (NULL) - , _audiodriver (NULL) - , _dtmfKey (NULL) - , _codecDescriptorMap() - , _toneMutex() - , _telephoneTone (NULL) - , _audiofile() - , _spkr_volume (0) - , _mic_volume (0) - , _mutex() - , _dbus (NULL) - , _waitingCall() - , _waitingCallMutex() - , _nbIncomingWaitingCall (0) - , _path ("") - , _exist (0) - , _setupLoaded (false) - , _callAccountMap() - , _callAccountMapMutex() - , _callConfigMap() - , _accountMap() - , _directIpAccount (NULL) - , _cleaner (NULL) - , _history (NULL) -{ - - // initialize random generator for call id - srand (time (NULL)); - - _cleaner = new NumberCleaner (); - _history = new HistoryManager (); +ManagerImpl::ManagerImpl (void) : + _hasTriedToRegister(false), _config(), _currentCallId2(), + _currentCallMutex(), _codecBuilder(NULL), _audiodriver(NULL), + _dtmfKey(NULL), _codecDescriptorMap(), _toneMutex(), + _telephoneTone(NULL), _audiofile(), _spkr_volume(0), + _mic_volume(0), _mutex(), _dbus(NULL), _waitingCall(), + _waitingCallMutex(), _nbIncomingWaitingCall(0), _path(""), + _exist(0), _setupLoaded(false), _callAccountMap(), + _callAccountMapMutex(), _callConfigMap(), _accountMap(), + _directIpAccount(NULL), _cleaner(NULL), _history(NULL) { + + // initialize random generator for call id + srand(time(NULL)); + + _cleaner = new NumberCleaner(); + _history = new HistoryManager(); #ifdef TEST - testAccountMap(); - loadAccountMap(); - testCallAccountMap(); - unloadAccountMap(); + testAccountMap(); + loadAccountMap(); + testCallAccountMap(); + unloadAccountMap(); #endif - // should be call before initConfigFile - // loadAccountMap();, called in init() now. + // should be call before initConfigFile + // loadAccountMap();, called in init() now. } // never call if we use only the singleton... -ManagerImpl::~ManagerImpl (void) -{ - // terminate(); - delete _cleaner; - _cleaner=0; - _debug ("%s stop correctly.", PROGNAME); +ManagerImpl::~ManagerImpl (void) { + // terminate(); + delete _cleaner; + _cleaner = 0; + _debug ("%s stop correctly.", PROGNAME); } -void -ManagerImpl::init() -{ - - // Load accounts, init map - loadAccountMap(); +void ManagerImpl::init () { - initVolume(); + // Load accounts, init map + loadAccountMap(); - if (_exist == 0) { - _debug ("Cannot create config file in your home directory"); - } + initVolume(); - initAudioDriver(); + if (_exist == 0) { + _debug ("Cannot create config file in your home directory"); + } - selectAudioDriver(); + initAudioDriver(); - // Initialize the list of supported audio codecs - initAudioCodec(); + selectAudioDriver(); - AudioLayer *audiolayer = getAudioDriver(); + // Initialize the list of supported audio codecs + initAudioCodec(); - if (audiolayer != 0) { - unsigned int sampleRate = audiolayer->getSampleRate(); + AudioLayer *audiolayer = getAudioDriver(); - _debugInit ("Load Telephone Tone"); - std::string country = getConfigString (PREFERENCES, ZONE_TONE); - _telephoneTone = new TelephoneTone (country, sampleRate); + if (audiolayer != 0) { + unsigned int sampleRate = audiolayer->getSampleRate(); - _debugInit ("Loading DTMF key"); - _dtmfKey = new DTMF (sampleRate); - } + _debugInit ("Load Telephone Tone"); + std::string country = getConfigString(PREFERENCES, ZONE_TONE); + _telephoneTone = new TelephoneTone(country, sampleRate); - if (audiolayer == 0) - audiolayer->stopStream(); + _debugInit ("Loading DTMF key"); + _dtmfKey = new DTMF(sampleRate); + } + if (audiolayer == 0) + audiolayer->stopStream(); - // Load the history - _history->load_history (getConfigInt (PREFERENCES, CONFIG_HISTORY_LIMIT)); + // Load the history + _history->load_history(getConfigInt(PREFERENCES, CONFIG_HISTORY_LIMIT)); } -void ManagerImpl::terminate() -{ - _debug ("ManagerImpl::terminate "); - saveConfig(); +void ManagerImpl::terminate () { + _debug ("ManagerImpl::terminate "); + saveConfig(); - unloadAccountMap(); + unloadAccountMap(); - _debug ("Unload DTMF Key "); - delete _dtmfKey; + _debug ("Unload DTMF Key "); + delete _dtmfKey; - _debug ("Unload Audio Driver "); - delete _audiodriver; - _audiodriver = NULL; + _debug ("Unload Audio Driver "); + delete _audiodriver; + _audiodriver = NULL; - _debug ("Unload Telephone Tone "); - delete _telephoneTone; - _telephoneTone = NULL; + _debug ("Unload Telephone Tone "); + delete _telephoneTone; + _telephoneTone = NULL; - _debug ("Unload Audio Codecs "); - _codecDescriptorMap.deleteHandlePointer(); + _debug ("Unload Audio Codecs "); + _codecDescriptorMap.deleteHandlePointer(); } -bool -ManagerImpl::isCurrentCall (const CallID& callId) -{ - return (_currentCallId2 == callId ? true : false); +bool ManagerImpl::isCurrentCall (const CallID& callId) { + return (_currentCallId2 == callId ? true : false); } -bool -ManagerImpl::hasCurrentCall() -{ - // _debug ("ManagerImpl::hasCurrentCall current call ID = %s", _currentCallId2.c_str()); +bool ManagerImpl::hasCurrentCall () { + // _debug ("ManagerImpl::hasCurrentCall current call ID = %s", _currentCallId2.c_str()); - if (_currentCallId2 != "") { - return true; - } + if (_currentCallId2 != "") { + return true; + } - return false; + return false; } const CallID& -ManagerImpl::getCurrentCallId() -{ - return _currentCallId2; +ManagerImpl::getCurrentCallId () { + return _currentCallId2; } -void -ManagerImpl::switchCall (const CallID& id) -{ - ost::MutexLock m (_currentCallMutex); - _debug ("----- Switch current call id to %s -----", id.c_str()); - _currentCallId2 = id; +void ManagerImpl::switchCall (const CallID& id) { + ost::MutexLock m(_currentCallMutex); + _debug ("----- Switch current call id to %s -----", id.c_str()); + _currentCallId2 = id; - /* - AudioLayer *al = getAudioDriver(); + /* + AudioLayer *al = getAudioDriver(); - if (id != "") { + if (id != "") { - if(isConference(id)) { + if(isConference(id)) { - Conference *conf; + Conference *conf; - ConferenceMap::iterator iter = _conferencemap.find(id); - if(iter != _conferencemap.end()) - { - _debug(" set call recordable in audio layer"); - conf = iter->second; - al->setRecorderInstance((Recordable*)conf); - } - } - else { + ConferenceMap::iterator iter = _conferencemap.find(id); + if(iter != _conferencemap.end()) + { + _debug(" set call recordable in audio layer"); + conf = iter->second; + al->setRecorderInstance((Recordable*)conf); + } + } + else { - // set the recordable instance in audiolayer - AccountID account_id = getAccountFromCall(id); + // set the recordable instance in audiolayer + AccountID account_id = getAccountFromCall(id); - Call *call = NULL; - call = getAccountLink (account_id)->getCall(id); + Call *call = NULL; + call = getAccountLink (account_id)->getCall(id); - _debug(" set call recordable in audio layer"); - al->setRecorderInstance((Recordable*)call); - } - } - */ + _debug(" set call recordable in audio layer"); + al->setRecorderInstance((Recordable*)call); + } + } + */ } - /////////////////////////////////////////////////////////////////////////////// // Management of events' IP-phone user /////////////////////////////////////////////////////////////////////////////// /* Main Thread */ -bool -ManagerImpl::outgoingCall (const std::string& account_id, const CallID& call_id, const std::string& to) -{ - std::string pattern, to_cleaned; - Call::CallConfiguration callConfig; - SIPVoIPLink *siplink; - - _debug ("ManagerImpl::outgoingCall(%s)", call_id.c_str()); +bool ManagerImpl::outgoingCall (const std::string& account_id, + const CallID& call_id, const std::string& to) { + std::string pattern, to_cleaned; + Call::CallConfiguration callConfig; + SIPVoIPLink *siplink; - CallID current_call_id = getCurrentCallId(); + _debug ("ManagerImpl::outgoingCall(%s)", call_id.c_str()); - if (getConfigString (HOOKS, PHONE_NUMBER_HOOK_ENABLED) == "1") - _cleaner->set_phone_number_prefix (getConfigString (HOOKS, PHONE_NUMBER_HOOK_ADD_PREFIX)); - else - _cleaner->set_phone_number_prefix (""); + CallID current_call_id = getCurrentCallId(); - to_cleaned = _cleaner->clean (to); + if (getConfigString(HOOKS, PHONE_NUMBER_HOOK_ENABLED) == "1") + _cleaner->set_phone_number_prefix(getConfigString(HOOKS, + PHONE_NUMBER_HOOK_ADD_PREFIX)); + else + _cleaner->set_phone_number_prefix(""); - /* Check what kind of call we are dealing with */ - check_call_configuration (call_id, to_cleaned, &callConfig); + to_cleaned = _cleaner->clean(to); - // in any cases we have to detach from current communication - if (hasCurrentCall()) { + /* Check what kind of call we are dealing with */ + check_call_configuration(call_id, to_cleaned, &callConfig); - _debug (" outgoingCall: Has current call (%s) put it onhold", current_call_id.c_str()); + // in any cases we have to detach from current communication + if (hasCurrentCall()) { - // if this is not a conferenceand this and is not a conference participant + _debug (" outgoingCall: Has current call (%s) put it onhold", current_call_id.c_str()); - if (!isConference (current_call_id) && !participToConference (current_call_id)) { - _debug (" outgoingCall: Put the current call (%s) on hold", current_call_id.c_str()); - onHoldCall (current_call_id); - } else if (isConference (current_call_id) && !participToConference (call_id)) { - _debug (" outgoingCall: detach main participant from conference"); - detachParticipant (default_id, current_call_id); - } - } + // if this is not a conferenceand this and is not a conference participant - if (callConfig == Call::IPtoIP) { - _debug (" outgoingCall: Start IP to IP call"); - /* We need to retrieve the sip voiplink instance */ - siplink = SIPVoIPLink::instance (""); + if (!isConference(current_call_id) && !participToConference( + current_call_id)) { + _debug (" outgoingCall: Put the current call (%s) on hold", current_call_id.c_str()); + onHoldCall(current_call_id); + } else if (isConference(current_call_id) && !participToConference( + call_id)) { + _debug (" outgoingCall: detach main participant from conference"); + detachParticipant(default_id, current_call_id); + } + } - if (siplink->new_ip_to_ip_call (call_id, to_cleaned)) { - switchCall (call_id); - return true; - } else { - callFailure (call_id); - } + if (callConfig == Call::IPtoIP) { + _debug (" outgoingCall: Start IP to IP call"); + /* We need to retrieve the sip voiplink instance */ + siplink = SIPVoIPLink::instance(""); - return false; - } + if (siplink->new_ip_to_ip_call(call_id, to_cleaned)) { + switchCall(call_id); + return true; + } else { + callFailure(call_id); + } - if (!accountExists (account_id)) { - _debug ("! Manager Error: Outgoing Call: account doesn't exist"); - return false; - } + return false; + } - if (getAccountFromCall (call_id) != AccountNULL) { - _debug ("! Manager Error: Outgoing Call: call id already exists"); - return false; - } + if (!accountExists(account_id)) { + _debug ("! Manager Error: Outgoing Call: account doesn't exist"); + return false; + } + if (getAccountFromCall(call_id) != AccountNULL) { + _debug ("! Manager Error: Outgoing Call: call id already exists"); + return false; + } - _debug ("- Manager Action: Adding Outgoing Call %s on account %s", call_id.data(), account_id.data()); + _debug ("- Manager Action: Adding Outgoing Call %s on account %s", call_id.data(), account_id.data()); - associateCallToAccount (call_id, account_id); + associateCallToAccount(call_id, account_id); - if (getAccountLink (account_id)->newOutgoingCall (call_id, to_cleaned)) { - switchCall (call_id); - return true; - } else { - callFailure (call_id); - _debug ("! Manager Error: An error occur, the call was not created"); - } + if (getAccountLink(account_id)->newOutgoingCall(call_id, to_cleaned)) { + switchCall(call_id); + return true; + } else { + callFailure(call_id); + _debug ("! Manager Error: An error occur, the call was not created"); + } - return false; + return false; } //THREAD=Main : for outgoing Call -bool -ManagerImpl::answerCall (const CallID& call_id) -{ +bool ManagerImpl::answerCall (const CallID& call_id) { - _debug ("ManagerImpl::answerCall(%s)", call_id.c_str()); + _debug ("ManagerImpl::answerCall(%s)", call_id.c_str()); - stopTone (); + stopTone(); - // store the current call id - CallID current_call_id = getCurrentCallId(); + // store the current call id + CallID current_call_id = getCurrentCallId(); - AccountID account_id = getAccountFromCall (call_id); + AccountID account_id = getAccountFromCall(call_id); - if (account_id == AccountNULL) { - _debug (" answerCall: AccountId is null"); - } - - Call* call = NULL; + if (account_id == AccountNULL) { + _debug (" answerCall: AccountId is null"); + } - call = getAccountLink (account_id)->getCall (call_id); + Call* call = NULL; - if (call == NULL) { - _debug (" answerCall: Call is null"); - } + call = getAccountLink(account_id)->getCall(call_id); - // in any cases we have to detach from current communication - if (hasCurrentCall()) { + if (call == NULL) { + _debug (" answerCall: Call is null"); + } - _debug (" answerCall: Currently conversing with %s", current_call_id.c_str()); - // if it is not a conference and is not a conference participant + // in any cases we have to detach from current communication + if (hasCurrentCall()) { - if (!isConference (current_call_id) && !participToConference (current_call_id)) { - _debug (" answerCall: Put the current call (%s) on hold", current_call_id.c_str()); - onHoldCall (current_call_id); - } + _debug (" answerCall: Currently conversing with %s", current_call_id.c_str()); + // if it is not a conference and is not a conference participant - // if we are talking to a conference and we are answering an incoming call - else if (isConference (current_call_id) && !participToConference (call_id)) { - _debug (" answerCall: Detach main participant from conference"); - detachParticipant (default_id, current_call_id); - } + if (!isConference(current_call_id) && !participToConference( + current_call_id)) { + _debug (" answerCall: Put the current call (%s) on hold", current_call_id.c_str()); + onHoldCall(current_call_id); + } - } + // if we are talking to a conference and we are answering an incoming call + else if (isConference(current_call_id) + && !participToConference(call_id)) { + _debug (" answerCall: Detach main participant from conference"); + detachParticipant(default_id, current_call_id); + } + } - if (!getAccountLink (account_id)->answer (call_id)) { - // error when receiving... - removeCallAccount (call_id); - return false; - } + if (!getAccountLink(account_id)->answer(call_id)) { + // error when receiving... + removeCallAccount(call_id); + return false; + } - // if it was waiting, it's waiting no more - if (_dbus) _dbus->getCallManager()->callStateChanged (call_id, "CURRENT"); + // if it was waiting, it's waiting no more + if (_dbus) + _dbus->getCallManager()->callStateChanged(call_id, "CURRENT"); - // std::string codecName = Manager::instance().getCurrentCodecName (call_id); - // if (_dbus) _dbus->getCallManager()->currentSelectedCodec (call_id, codecName.c_str()); + // std::string codecName = Manager::instance().getCurrentCodecName (call_id); + // if (_dbus) _dbus->getCallManager()->currentSelectedCodec (call_id, codecName.c_str()); - removeWaitingCall (call_id); + removeWaitingCall(call_id); - // if we dragged this call into a conference already - if (participToConference (call_id)) { + // if we dragged this call into a conference already + if (participToConference(call_id)) { - // AccountID currentAccountId; - // Call* call = NULL; + // AccountID currentAccountId; + // Call* call = NULL; - // currentAccountId = getAccountFromCall (call_id); - // call = getAccountLink (currentAccountId)->getCall (call_id); + // currentAccountId = getAccountFromCall (call_id); + // call = getAccountLink (currentAccountId)->getCall (call_id); - switchCall (call->getConfId()); - } else { - switchCall (call_id); - } + switchCall(call->getConfId()); + } else { + switchCall(call_id); + } - return true; + return true; } //THREAD=Main -bool -ManagerImpl::hangupCall (const CallID& call_id) -{ - _debug ("ManagerImpl::hangupCall(%s)", call_id.c_str()); - PulseLayer *pulselayer; - AccountID account_id; - bool returnValue = true; +bool ManagerImpl::hangupCall (const CallID& call_id) { + _debug ("ManagerImpl::hangupCall(%s)", call_id.c_str()); + PulseLayer *pulselayer; + AccountID account_id; + bool returnValue = true; - // store the current call id - CallID current_call_id = getCurrentCallId(); + // store the current call id + CallID current_call_id = getCurrentCallId(); - stopTone (); + stopTone(); - /* Broadcast a signal over DBus */ - _debug (" hangupCall: Send DBUS call state change (HUNGUP) for id %s", call_id.c_str()); + /* Broadcast a signal over DBus */ + _debug (" hangupCall: Send DBUS call state change (HUNGUP) for id %s", call_id.c_str()); - if (_dbus) _dbus->getCallManager()->callStateChanged (call_id, "HUNGUP"); + if (_dbus) + _dbus->getCallManager()->callStateChanged(call_id, "HUNGUP"); - if (participToConference (call_id)) { + if (participToConference(call_id)) { - Conference *conf = getConferenceFromCallID (call_id); + Conference *conf = getConferenceFromCallID(call_id); - if (conf != NULL) { - // remove this participant - removeParticipant (call_id); + if (conf != NULL) { + // remove this participant + removeParticipant(call_id); - processRemainingParticipant (current_call_id, conf); - } + processRemainingParticipant(current_call_id, conf); + } - } else { - // we are not participating to a conference, current call switched to "" - if (!isConference (current_call_id)) - switchCall (""); - } + } else { + // we are not participating to a conference, current call switched to "" + if (!isConference(current_call_id)) + switchCall(""); + } - /* Direct IP to IP call */ - if (getConfigFromCall (call_id) == Call::IPtoIP) { - returnValue = SIPVoIPLink::instance (AccountNULL)->hangup (call_id); - } - /* Classic call, attached to an account */ - else { - account_id = getAccountFromCall (call_id); + /* Direct IP to IP call */ + if (getConfigFromCall(call_id) == Call::IPtoIP) { + returnValue = SIPVoIPLink::instance(AccountNULL)->hangup(call_id); + } + /* Classic call, attached to an account */ + else { + account_id = getAccountFromCall(call_id); - if (account_id == AccountNULL) { + if (account_id == AccountNULL) { - _debug ("! Manager Hangup Call: Call doesn't exists"); - returnValue = false; - } - else { + _debug ("! Manager Hangup Call: Call doesn't exists"); + returnValue = false; + } else { - returnValue = getAccountLink (account_id)->hangup (call_id); - removeCallAccount (call_id); + returnValue = getAccountLink(account_id)->hangup(call_id); + removeCallAccount(call_id); + } } - } - int nbCalls = getCallList().size(); + int nbCalls = getCallList().size(); - AudioLayer *audiolayer = getAudioDriver(); + AudioLayer *audiolayer = getAudioDriver(); - // stop streams - if (audiolayer && (nbCalls <= 0)) { - _debug (" hangupCall: stop audio stream, ther is only %i call(s) remaining", nbCalls); - audiolayer->stopStream(); - } + // stop streams + if (audiolayer && (nbCalls <= 0)) { + _debug (" hangupCall: stop audio stream, ther is only %i call(s) remaining", nbCalls); + audiolayer->stopStream(); + } - if (_audiodriver->getLayerType() == PULSEAUDIO) { - pulselayer = dynamic_cast<PulseLayer *> (getAudioDriver()); - } + if (_audiodriver->getLayerType() == PULSEAUDIO) { + pulselayer = dynamic_cast<PulseLayer *> (getAudioDriver()); + } - return returnValue; + return returnValue; } +bool ManagerImpl::hangupConference (const ConfID& id) { + _debug ("ManagerImpl::hangupConference()"); -bool -ManagerImpl::hangupConference (const ConfID& id) -{ - _debug ("ManagerImpl::hangupConference()"); - - Conference *conf; - ConferenceMap::iterator iter_conf = _conferencemap.find (id); + Conference *conf; + ConferenceMap::iterator iter_conf = _conferencemap.find(id); - AccountID currentAccountId; + AccountID currentAccountId; - // Call* call = NULL; + // Call* call = NULL; - if (iter_conf != _conferencemap.end()) { - conf = iter_conf->second; + if (iter_conf != _conferencemap.end()) { + conf = iter_conf->second; - ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + ParticipantSet participants = conf->getParticipantList(); + ParticipantSet::iterator iter_participant = participants.begin(); - while (iter_participant != participants.end()) { - _debug ("ManagerImpl::hangupConference participant %s", (*iter_participant).c_str()); + while (iter_participant != participants.end()) { + _debug ("ManagerImpl::hangupConference participant %s", (*iter_participant).c_str()); - hangupCall (*iter_participant); + hangupCall(*iter_participant); - iter_participant++; + iter_participant++; - } + } - } + } - switchCall (""); + switchCall(""); - return true; + return true; } - //THREAD=Main -bool -ManagerImpl::cancelCall (const CallID& id) -{ - AccountID accountid; - bool returnValue; +bool ManagerImpl::cancelCall (const CallID& id) { + AccountID accountid; + bool returnValue; - stopTone (); + stopTone(); - /* Direct IP to IP call */ + /* Direct IP to IP call */ - if (getConfigFromCall (id) == Call::IPtoIP) { - returnValue = SIPVoIPLink::instance (AccountNULL)->cancel (id); - } + if (getConfigFromCall(id) == Call::IPtoIP) { + returnValue = SIPVoIPLink::instance(AccountNULL)->cancel(id); + } - /* Classic call, attached to an account */ - else { - accountid = getAccountFromCall (id); + /* Classic call, attached to an account */ + else { + accountid = getAccountFromCall(id); - if (accountid == AccountNULL) { - _debug ("! Manager Cancel Call: Call doesn't exists"); - return false; - } + if (accountid == AccountNULL) { + _debug ("! Manager Cancel Call: Call doesn't exists"); + return false; + } - returnValue = getAccountLink (accountid)->cancel (id); + returnValue = getAccountLink(accountid)->cancel(id); - removeCallAccount (id); - } + removeCallAccount(id); + } - // it could be a waiting call? - removeWaitingCall (id); + // it could be a waiting call? + removeWaitingCall(id); - switchCall (""); + switchCall(""); - return returnValue; + return returnValue; } //THREAD=Main -bool -ManagerImpl::onHoldCall (const CallID& call_id) -{ - AccountID account_id; - bool returnValue; +bool ManagerImpl::onHoldCall (const CallID& call_id) { + AccountID account_id; + bool returnValue; - _debug ("ManagerImpl::onHoldCall(%s)", call_id.c_str()); + _debug ("ManagerImpl::onHoldCall(%s)", call_id.c_str()); - stopTone (); + stopTone(); - CallID current_call_id = getCurrentCallId(); + CallID current_call_id = getCurrentCallId(); - _debug (" onHoldCall: try to put call %s on hold", call_id.c_str()); + _debug (" onHoldCall: try to put call %s on hold", call_id.c_str()); - /* Direct IP to IP call */ + /* Direct IP to IP call */ - if (getConfigFromCall (call_id) == Call::IPtoIP) { - returnValue = SIPVoIPLink::instance (AccountNULL)-> onhold (call_id); - } + if (getConfigFromCall(call_id) == Call::IPtoIP) { + returnValue = SIPVoIPLink::instance(AccountNULL)-> onhold(call_id); + } - /* Classic call, attached to an account */ - else { - account_id = getAccountFromCall (call_id); + /* Classic call, attached to an account */ + else { + account_id = getAccountFromCall(call_id); - if (account_id == AccountNULL) { - _debug (" onHoldCall: Account ID %s or callid %s doesn't exists", account_id.c_str(), call_id.c_str()); - return false; - } + if (account_id == AccountNULL) { + _debug (" onHoldCall: Account ID %s or callid %s doesn't exists", account_id.c_str(), call_id.c_str()); + return false; + } - returnValue = getAccountLink (account_id)->onhold (call_id); - } + returnValue = getAccountLink(account_id)->onhold(call_id); + } - removeWaitingCall (call_id); + removeWaitingCall(call_id); - // keeps current call id if the action is not holding this call or a new outgoing call + // keeps current call id if the action is not holding this call or a new outgoing call - if (current_call_id == call_id) { + if (current_call_id == call_id) { - switchCall (""); - } + switchCall(""); + } - if (_dbus) _dbus->getCallManager()->callStateChanged (call_id, "HOLD"); + if (_dbus) + _dbus->getCallManager()->callStateChanged(call_id, "HOLD"); - return returnValue; + return returnValue; } //THREAD=Main -bool -ManagerImpl::offHoldCall (const CallID& call_id) -{ - - AccountID account_id; - bool returnValue, is_rec; - std::string codecName; - - is_rec = false; +bool ManagerImpl::offHoldCall (const CallID& call_id) { - _debug ("ManagerImpl::offHoldCall(%s)", call_id.c_str()); + AccountID account_id; + bool returnValue, is_rec; + std::string codecName; - stopTone (); + is_rec = false; - CallID current_call_id = getCurrentCallId(); + _debug ("ManagerImpl::offHoldCall(%s)", call_id.c_str()); - //Place current call on hold if it isn't + stopTone(); - if (hasCurrentCall()) { - // if this is not a conferenceand this and is not a conference participant - if (!isConference (current_call_id) && !participToConference (current_call_id)) { - _debug (" offHoldCall: put current call (%s) on hold", current_call_id.c_str()); - onHoldCall (current_call_id); - } else if (isConference (current_call_id) && !participToConference (call_id)) { - _debug (" offHoldCall Put current conference (%s) on hold", current_call_id.c_str()); - detachParticipant (default_id, current_call_id); - } - } + CallID current_call_id = getCurrentCallId(); - // switch current call id to id since sipvoip link need it to amke a call - // switchCall(id); + //Place current call on hold if it isn't - /* Direct IP to IP call */ - if (getConfigFromCall (call_id) == Call::IPtoIP) { - // is_rec = SIPVoIPLink::instance (AccountNULL)-> isRecording (call_id); - returnValue = SIPVoIPLink::instance (AccountNULL)-> offhold (call_id); - } + if (hasCurrentCall()) { + // if this is not a conferenceand this and is not a conference participant + if (!isConference(current_call_id) && !participToConference( + current_call_id)) { + _debug (" offHoldCall: put current call (%s) on hold", current_call_id.c_str()); + onHoldCall(current_call_id); + } else if (isConference(current_call_id) && !participToConference( + call_id)) { + _debug (" offHoldCall Put current conference (%s) on hold", current_call_id.c_str()); + detachParticipant(default_id, current_call_id); + } + } - /* Classic call, attached to an account */ - else { - account_id = getAccountFromCall (call_id); + // switch current call id to id since sipvoip link need it to amke a call + // switchCall(id); - if (account_id == AccountNULL) { - _debug ("Manager OffHold Call: Call doesn't exists"); - return false; - } + /* Direct IP to IP call */ + if (getConfigFromCall(call_id) == Call::IPtoIP) { + // is_rec = SIPVoIPLink::instance (AccountNULL)-> isRecording (call_id); + returnValue = SIPVoIPLink::instance(AccountNULL)-> offhold(call_id); + } - _debug ("Setting OFFHOLD, Account %s, callid %s", account_id.c_str(), call_id.c_str()); + /* Classic call, attached to an account */ + else { + account_id = getAccountFromCall(call_id); - is_rec = getAccountLink (account_id)->getCall (call_id)->isRecording(); - returnValue = getAccountLink (account_id)->offhold (call_id); - } + if (account_id == AccountNULL) { + _debug ("Manager OffHold Call: Call doesn't exists"); + return false; + } + _debug ("Setting OFFHOLD, Account %s, callid %s", account_id.c_str(), call_id.c_str()); - if (_dbus) { - if (is_rec) - _dbus->getCallManager()->callStateChanged (call_id, "UNHOLD_RECORD"); - else - _dbus->getCallManager()->callStateChanged (call_id, "UNHOLD_CURRENT"); + is_rec = getAccountLink(account_id)->getCall(call_id)->isRecording(); + returnValue = getAccountLink(account_id)->offhold(call_id); + } - } + if (_dbus) { + if (is_rec) + _dbus->getCallManager()->callStateChanged(call_id, "UNHOLD_RECORD"); + else + _dbus->getCallManager()->callStateChanged(call_id, "UNHOLD_CURRENT"); - if (participToConference (call_id)) { + } - AccountID currentAccountId; - Call* call = NULL; + if (participToConference(call_id)) { - currentAccountId = getAccountFromCall (call_id); - call = getAccountLink (currentAccountId)->getCall (call_id); + AccountID currentAccountId; + Call* call = NULL; - switchCall (call->getConfId()); + currentAccountId = getAccountFromCall(call_id); + call = getAccountLink(currentAccountId)->getCall(call_id); - } else { - switchCall (call_id); - _audiodriver->flushMain(); - } + switchCall(call->getConfId()); + } else { + switchCall(call_id); + _audiodriver->flushMain(); + } - // codecName = getCurrentCodecName (call_id); - // _debug("ManagerImpl::hangupCall(): broadcast codec name %s ",codecName.c_str()); + // codecName = getCurrentCodecName (call_id); + // _debug("ManagerImpl::hangupCall(): broadcast codec name %s ",codecName.c_str()); - // if (_dbus) _dbus->getCallManager()->currentSelectedCodec (call_id,codecName.c_str()); + // if (_dbus) _dbus->getCallManager()->currentSelectedCodec (call_id,codecName.c_str()); - return returnValue; + return returnValue; } //THREAD=Main -bool -ManagerImpl::transferCall (const CallID& call_id, const std::string& to) -{ - AccountID accountid; - bool returnValue; +bool ManagerImpl::transferCall (const CallID& call_id, const std::string& to) { + AccountID accountid; + bool returnValue; - stopTone (); + stopTone(); - CallID current_call_id = getCurrentCallId(); + CallID current_call_id = getCurrentCallId(); - if (participToConference (call_id)) { + if (participToConference(call_id)) { - _debug("Particip to a conference\n"); + _debug("Particip to a conference\n"); - Conference *conf = getConferenceFromCallID (call_id); + Conference *conf = getConferenceFromCallID(call_id); - if (conf != NULL) { - // remove this participant - removeParticipant (call_id); + if (conf != NULL) { + // remove this participant + removeParticipant(call_id); - processRemainingParticipant (current_call_id, conf); - } - } else { + processRemainingParticipant(current_call_id, conf); + } + } else { - _debug("Do not Particip to a conference\n"); + _debug("Do not Particip to a conference\n"); - // we are not participating to a conference, current call switched to "" - if (!isConference (current_call_id)) - switchCall (""); - } + // we are not participating to a conference, current call switched to "" + if (!isConference(current_call_id)) + switchCall(""); + } - /* Direct IP to IP call */ - if (getConfigFromCall (call_id) == Call::IPtoIP) { - returnValue = SIPVoIPLink::instance (AccountNULL)-> transfer (call_id, to); - } - /* Classic call, attached to an account */ - else { - accountid = getAccountFromCall (call_id); + /* Direct IP to IP call */ + if (getConfigFromCall(call_id) == Call::IPtoIP) { + returnValue + = SIPVoIPLink::instance(AccountNULL)-> transfer(call_id, to); + } + /* Classic call, attached to an account */ + else { + accountid = getAccountFromCall(call_id); - if (accountid == AccountNULL) { - _debug ("! Manager Transfer Call: Call doesn't exists"); - return false; - } + if (accountid == AccountNULL) { + _debug ("! Manager Transfer Call: Call doesn't exists"); + return false; + } - returnValue = getAccountLink (accountid)->transfer (call_id, to); + returnValue = getAccountLink(accountid)->transfer(call_id, to); - removeCallAccount (call_id); - } + removeCallAccount(call_id); + } - removeWaitingCall (call_id); + removeWaitingCall(call_id); - if (_dbus) _dbus->getCallManager()->callStateChanged (call_id, "HUNGUP"); + if (_dbus) + _dbus->getCallManager()->callStateChanged(call_id, "HUNGUP"); - return returnValue; + return returnValue; } -void ManagerImpl::transferFailed() -{ - if (_dbus) _dbus->getCallManager()->transferFailed(); +void ManagerImpl::transferFailed () { + if (_dbus) + _dbus->getCallManager()->transferFailed(); } -void ManagerImpl::transferSucceded() -{ - if (_dbus) _dbus->getCallManager()->transferSucceded(); +void ManagerImpl::transferSucceded () { + if (_dbus) + _dbus->getCallManager()->transferSucceded(); } - //THREAD=Main : Call:Incoming -bool -ManagerImpl::refuseCall (const CallID& id) -{ - AccountID accountid; - bool returnValue; - - CallID current_call_id = getCurrentCallId(); +bool ManagerImpl::refuseCall (const CallID& id) { + AccountID accountid; + bool returnValue; - stopTone (); + CallID current_call_id = getCurrentCallId(); + stopTone(); - int nbCalls = getCallList().size(); + int nbCalls = getCallList().size(); - // AudioLayer* audiolayer = getAudioDriver(); + // AudioLayer* audiolayer = getAudioDriver(); - if (nbCalls <= 1) { - _debug (" hangupCall: stop audio stream, ther is only %i call(s) remaining", nbCalls); + if (nbCalls <= 1) { + _debug (" hangupCall: stop audio stream, ther is only %i call(s) remaining", nbCalls); - AudioLayer* audiolayer = getAudioDriver(); - audiolayer->stopStream(); - } - - /* Direct IP to IP call */ - - if (getConfigFromCall (id) == Call::IPtoIP) { - returnValue = SIPVoIPLink::instance (AccountNULL)-> refuse (id); - } + AudioLayer* audiolayer = getAudioDriver(); + audiolayer->stopStream(); + } - /* Classic call, attached to an account */ - else { - accountid = getAccountFromCall (id); + /* Direct IP to IP call */ - if (accountid == AccountNULL) { - _debug ("! Manager OffHold Call: Call doesn't exists"); - return false; - } + if (getConfigFromCall(id) == Call::IPtoIP) { + returnValue = SIPVoIPLink::instance(AccountNULL)-> refuse(id); + } - returnValue = getAccountLink (accountid)->refuse (id); + /* Classic call, attached to an account */ + else { + accountid = getAccountFromCall(id); - removeCallAccount (id); - } + if (accountid == AccountNULL) { + _debug ("! Manager OffHold Call: Call doesn't exists"); + return false; + } - // if the call was outgoing or established, we didn't refuse it - // so the method did nothing - if (returnValue) { - removeWaitingCall (id); + returnValue = getAccountLink(accountid)->refuse(id); - if (_dbus) _dbus->getCallManager()->callStateChanged (id, "HUNGUP"); + removeCallAccount(id); + } - // if(current_call_id.compare("") != 0) - // switchCall (""); - } + // if the call was outgoing or established, we didn't refuse it + // so the method did nothing + if (returnValue) { + removeWaitingCall(id); + if (_dbus) + _dbus->getCallManager()->callStateChanged(id, "HUNGUP"); + // if(current_call_id.compare("") != 0) + // switchCall (""); + } - return returnValue; + return returnValue; } - Conference* -ManagerImpl::createConference (const CallID& id1, const CallID& id2) -{ - _debug ("ManagerImpl::createConference()"); +ManagerImpl::createConference (const CallID& id1, const CallID& id2) { + _debug ("ManagerImpl::createConference()"); - Conference* conf = new Conference(); + Conference* conf = new Conference(); - // _conferencecall.insert(pair<CallID, Conference*>(id1, conf)); - // _conferencecall.insert(pair<CallID, Conference*>(id2, conf)); - _conferencemap.insert (pair<CallID, Conference*> (conf->getConfID(), conf)); + // _conferencecall.insert(pair<CallID, Conference*>(id1, conf)); + // _conferencecall.insert(pair<CallID, Conference*>(id2, conf)); + _conferencemap.insert(pair<CallID, Conference*> (conf->getConfID(), conf)); - conf->add (id1); - conf->add (id2); + conf->add(id1); + conf->add(id2); - // broadcast a signal over dbus - _dbus->getCallManager()->conferenceCreated (conf->getConfID()); + // broadcast a signal over dbus + _dbus->getCallManager()->conferenceCreated(conf->getConfID()); - return conf; + return conf; } -void -ManagerImpl::removeConference (const ConfID& conference_id) -{ - - _debug ("ManagerImpl::removeConference(%s)", conference_id.c_str()); +void ManagerImpl::removeConference (const ConfID& conference_id) { - Conference* conf = NULL; + _debug ("ManagerImpl::removeConference(%s)", conference_id.c_str()); - _debug (" removeConference: _conferencemap.size: %i", (int) _conferencemap.size()); - ConferenceMap::iterator iter = _conferencemap.find (conference_id); + Conference* conf = NULL; - if (iter != _conferencemap.end()) { - _debug (" removeConference: Found conference id %s in conferencemap", conference_id.c_str()); - conf = iter->second; - } + _debug (" removeConference: _conferencemap.size: %i", (int) _conferencemap.size()); + ConferenceMap::iterator iter = _conferencemap.find(conference_id); - if (conf == NULL) { + if (iter != _conferencemap.end()) { + _debug (" removeConference: Found conference id %s in conferencemap", conference_id.c_str()); + conf = iter->second; + } - _debug (" removeConference: Error conference not found"); - return; - } + if (conf == NULL) { + _debug (" removeConference: Error conference not found"); + return; + } - // We now need to bind the audio to the remain participant + // We now need to bind the audio to the remain participant - // unbind main participant from conference (just to be sure) - _audiodriver->getMainBuffer()->unBindAll (default_id); + // unbind main participant from conference (just to be sure) + _audiodriver->getMainBuffer()->unBindAll(default_id); - ParticipantSet participants = conf->getParticipantList(); + ParticipantSet participants = conf->getParticipantList(); - // bind main participant to remaining conference call - ParticipantSet::iterator iter_p = participants.begin(); + // bind main participant to remaining conference call + ParticipantSet::iterator iter_p = participants.begin(); - if (iter_p != participants.end()) { + if (iter_p != participants.end()) { - // to avoid puting onhold the call - // switchCall(""); - _audiodriver->getMainBuffer()->bindCallID (*iter_p, default_id); - } + // to avoid puting onhold the call + // switchCall(""); + _audiodriver->getMainBuffer()->bindCallID(*iter_p, default_id); + } - // Then remove the conference from the conference map - _debug ("ManagerImpl:: remove conference %s", conference_id.c_str()); + // Then remove the conference from the conference map + _debug ("ManagerImpl:: remove conference %s", conference_id.c_str()); - if (_conferencemap.erase (conference_id) == 1) - _debug ("ManagerImpl:: conference %s removed succesfully", conference_id.c_str()); - else - _debug ("ManagerImpl:: error cannot remove conference id: %s", conference_id.c_str()); + if (_conferencemap.erase(conference_id) == 1) + _debug ("ManagerImpl:: conference %s removed succesfully", conference_id.c_str()); + else + _debug ("ManagerImpl:: error cannot remove conference id: %s", conference_id.c_str()); - // broadcast a signal over dbus - _debug ("ManagerImpl::removeConference broadcast call removed on dbus: %s", conference_id.c_str()); + // broadcast a signal over dbus + _debug ("ManagerImpl::removeConference broadcast call removed on dbus: %s", conference_id.c_str()); - _dbus->getCallManager()->conferenceRemoved (conference_id); + _dbus->getCallManager()->conferenceRemoved(conference_id); } - Conference* -ManagerImpl::getConferenceFromCallID (const CallID& call_id) -{ - AccountID account_id; - Call* call = NULL; +ManagerImpl::getConferenceFromCallID (const CallID& call_id) { + AccountID account_id; + Call* call = NULL; - account_id = getAccountFromCall (call_id); - call = getAccountLink (account_id)->getCall (call_id); + account_id = getAccountFromCall(call_id); + call = getAccountLink(account_id)->getCall(call_id); - ConferenceMap::iterator iter = _conferencemap.find (call->getConfId()); + ConferenceMap::iterator iter = _conferencemap.find(call->getConfId()); - if (iter != _conferencemap.end()) { - return iter->second; - } else { - return NULL; - } + if (iter != _conferencemap.end()) { + return iter->second; + } else { + return NULL; + } } -void -ManagerImpl::holdConference (const CallID& id) -{ - _debug ("ManagerImpl::holdConference()"); - - Conference *conf; - ConferenceMap::iterator iter_conf = _conferencemap.find (id); +void ManagerImpl::holdConference (const CallID& id) { + _debug ("ManagerImpl::holdConference()"); - AccountID currentAccountId; + Conference *conf; + ConferenceMap::iterator iter_conf = _conferencemap.find(id); - Call* call = NULL; + AccountID currentAccountId; - if (iter_conf != _conferencemap.end()) { - conf = iter_conf->second; + Call* call = NULL; - ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + if (iter_conf != _conferencemap.end()) { + conf = iter_conf->second; - while (iter_participant != participants.end()) { - _debug (" holdConference: participant %s", (*iter_participant).c_str()); - currentAccountId = getAccountFromCall (*iter_participant); - call = getAccountLink (currentAccountId)->getCall (*iter_participant); + ParticipantSet participants = conf->getParticipantList(); + ParticipantSet::iterator iter_participant = participants.begin(); - switchCall (*iter_participant); - onHoldCall (*iter_participant); + while (iter_participant != participants.end()) { + _debug (" holdConference: participant %s", (*iter_participant).c_str()); + currentAccountId = getAccountFromCall(*iter_participant); + call = getAccountLink(currentAccountId)->getCall(*iter_participant); - iter_participant++; + switchCall(*iter_participant); + onHoldCall(*iter_participant); - } + iter_participant++; - conf->setState (Conference::Hold); - - _dbus->getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); - - } + } + conf->setState(Conference::Hold); + _dbus->getCallManager()->conferenceChanged(conf->getConfID(), + conf->getStateStr()); + } } +void ManagerImpl::unHoldConference (const CallID& id) { -void -ManagerImpl::unHoldConference (const CallID& id) -{ + _debug ("ManagerImpl::unHoldConference()"); - _debug ("ManagerImpl::unHoldConference()"); + Conference *conf; + ConferenceMap::iterator iter_conf = _conferencemap.find(id); - Conference *conf; - ConferenceMap::iterator iter_conf = _conferencemap.find (id); + AccountID currentAccountId; - AccountID currentAccountId; + Call* call = NULL; - Call* call = NULL; + if (iter_conf != _conferencemap.end()) { + conf = iter_conf->second; - if (iter_conf != _conferencemap.end()) { - conf = iter_conf->second; + ParticipantSet participants = conf->getParticipantList(); + ParticipantSet::iterator iter_participant = participants.begin(); - ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + while (iter_participant != participants.end()) { + _debug (" unholdConference: participant %s", (*iter_participant).c_str()); + currentAccountId = getAccountFromCall(*iter_participant); + call = getAccountLink(currentAccountId)->getCall(*iter_participant); - while (iter_participant != participants.end()) { - _debug (" unholdConference: participant %s", (*iter_participant).c_str()); - currentAccountId = getAccountFromCall (*iter_participant); - call = getAccountLink (currentAccountId)->getCall (*iter_participant); + offHoldCall(*iter_participant); - offHoldCall (*iter_participant); + iter_participant++; - iter_participant++; - - } + } - conf->setState (Conference::Active_Atached); + conf->setState(Conference::Active_Atached); - _dbus->getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); + _dbus->getCallManager()->conferenceChanged(conf->getConfID(), + conf->getStateStr()); - } + } } -bool -ManagerImpl::isConference (const CallID& id) -{ - ConferenceMap::iterator iter = _conferencemap.find (id); +bool ManagerImpl::isConference (const CallID& id) { + ConferenceMap::iterator iter = _conferencemap.find(id); - if (iter == _conferencemap.end()) { - return false; - } else { - return true; - } + if (iter == _conferencemap.end()) { + return false; + } else { + return true; + } } -bool -ManagerImpl::participToConference (const CallID& call_id) -{ +bool ManagerImpl::participToConference (const CallID& call_id) { - AccountID accountId; + AccountID accountId; - Call* call = NULL; + Call* call = NULL; - accountId = getAccountFromCall (call_id); - call = getAccountLink (accountId)->getCall (call_id); + accountId = getAccountFromCall(call_id); + call = getAccountLink(accountId)->getCall(call_id); - if (call == NULL) { - return false; + if (call == NULL) { + return false; - } + } - if (call->getConfId() == "") { - return false; - } else { - - return true; - } -} + if (call->getConfId() == "") { + return false; + } else { + return true; + } +} -void -ManagerImpl::addParticipant (const CallID& call_id, const CallID& conference_id) -{ - _debug ("ManagerImpl::addParticipant(%s, %s)", call_id.c_str(), conference_id.c_str()); +void ManagerImpl::addParticipant (const CallID& call_id, + const CallID& conference_id) { + _debug ("ManagerImpl::addParticipant(%s, %s)", call_id.c_str(), conference_id.c_str()); - std::map<std::string, std::string> call_details = getCallDetails (call_id); + std::map<std::string, std::string> call_details = getCallDetails(call_id); - ConferenceMap::iterator iter = _conferencemap.find (conference_id); - std::map<std::string, std::string>::iterator iter_details; + ConferenceMap::iterator iter = _conferencemap.find(conference_id); + std::map<std::string, std::string>::iterator iter_details; - // store the current call id (it will change in offHoldCall or in answerCall) - CallID current_call_id = getCurrentCallId(); + // store the current call id (it will change in offHoldCall or in answerCall) + CallID current_call_id = getCurrentCallId(); - // detach from the conference and switch to this conference + // detach from the conference and switch to this conference - if (current_call_id != call_id) { - if (isConference (current_call_id)) { - detachParticipant (default_id, current_call_id); - } else - onHoldCall (current_call_id); - } + if (current_call_id != call_id) { + if (isConference(current_call_id)) { + detachParticipant(default_id, current_call_id); + } else + onHoldCall(current_call_id); + } - // TODO: remove this ugly hack => There should be different calls when double clicking - // a conference to add main participant to it, or (in this case) adding a participant - // toconference - switchCall (""); + // TODO: remove this ugly hack => There should be different calls when double clicking + // a conference to add main participant to it, or (in this case) adding a participant + // toconference + switchCall(""); - addMainParticipant (conference_id); + addMainParticipant(conference_id); - _debug (" addParticipant: enter main process"); + _debug (" addParticipant: enter main process"); - if (iter != _conferencemap.end()) { + if (iter != _conferencemap.end()) { - Conference* conf = iter->second; - switchCall (conf->getConfID()); + Conference* conf = iter->second; + switchCall(conf->getConfID()); - AccountID currentAccountId; - Call* call = NULL; + AccountID currentAccountId; + Call* call = NULL; - currentAccountId = getAccountFromCall (call_id); - call = getAccountLink (currentAccountId)->getCall (call_id); - call->setConfId (conf->getConfID()); + currentAccountId = getAccountFromCall(call_id); + call = getAccountLink(currentAccountId)->getCall(call_id); + call->setConfId(conf->getConfID()); - conf->add (call_id); + conf->add(call_id); - iter_details = call_details.find ("CALL_STATE"); + iter_details = call_details.find("CALL_STATE"); - _debug (" addParticipant: call state: %s", iter_details->second.c_str()); + _debug (" addParticipant: call state: %s", iter_details->second.c_str()); - if (iter_details->second == "HOLD") { - _debug (" OFFHOLD %s", call_id.c_str()); + if (iter_details->second == "HOLD") { + _debug (" OFFHOLD %s", call_id.c_str()); - // offHoldCall create a new rtp session which use addStream to bind participant - offHoldCall (call_id); - } else if (iter_details->second == "INCOMING") { - _debug (" ANSWER %s", call_id.c_str()); - // answerCall create a new rtp session which use addStream to bind participant - answerCall (call_id); - } else if (iter_details->second == "CURRENT") { - // Already a curent call, so we beed to reset audio stream bindings manually - _audiodriver->getMainBuffer()->unBindAll (call_id); - conf->bindParticipant (call_id); - } + // offHoldCall create a new rtp session which use addStream to bind participant + offHoldCall(call_id); + } else if (iter_details->second == "INCOMING") { + _debug (" ANSWER %s", call_id.c_str()); + // answerCall create a new rtp session which use addStream to bind participant + answerCall(call_id); + } else if (iter_details->second == "CURRENT") { + // Already a curent call, so we beed to reset audio stream bindings manually + _audiodriver->getMainBuffer()->unBindAll(call_id); + conf->bindParticipant(call_id); + } - // _dbus->getCallManager()->conferenceChanged(conference_id, conf->getStateStr()); + // _dbus->getCallManager()->conferenceChanged(conference_id, conf->getStateStr()); - ParticipantSet participants = conf->getParticipantList(); + ParticipantSet participants = conf->getParticipantList(); - // reset ring buffer for all conference participant - ParticipantSet::iterator iter_p = participants.begin(); + // reset ring buffer for all conference participant + ParticipantSet::iterator iter_p = participants.begin(); - while (iter_p != participants.end()) { + while (iter_p != participants.end()) { - // flush conference participants only - _audiodriver->getMainBuffer()->flush (*iter_p); + // flush conference participants only + _audiodriver->getMainBuffer()->flush(*iter_p); - iter_p++; - } + iter_p++; + } - _audiodriver->getMainBuffer()->flush (default_id); - } else { - _debug (" addParticipant: Error, conference %s conference_id not found!", conference_id.c_str()); - } + _audiodriver->getMainBuffer()->flush(default_id); + } else { + _debug (" addParticipant: Error, conference %s conference_id not found!", conference_id.c_str()); + } } -void -ManagerImpl::addMainParticipant (const CallID& conference_id) -{ - if (hasCurrentCall()) { - CallID current_call_id = getCurrentCallId(); +void ManagerImpl::addMainParticipant (const CallID& conference_id) { + if (hasCurrentCall()) { + CallID current_call_id = getCurrentCallId(); - if (isConference (current_call_id)) { - detachParticipant (default_id, current_call_id); - } else { - onHoldCall (current_call_id); - } - } + if (isConference(current_call_id)) { + detachParticipant(default_id, current_call_id); + } else { + onHoldCall(current_call_id); + } + } - ConferenceMap::iterator iter = _conferencemap.find (conference_id); + ConferenceMap::iterator iter = _conferencemap.find(conference_id); - Conference *conf = NULL; + Conference *conf = NULL; - if (iter != _conferencemap.end()) { - conf = iter->second; + if (iter != _conferencemap.end()) { + conf = iter->second; - ParticipantSet participants = conf->getParticipantList(); + ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + ParticipantSet::iterator iter_participant = participants.begin(); - while (iter_participant != participants.end()) { - _audiodriver->getMainBuffer()->bindCallID (*iter_participant, default_id); + while (iter_participant != participants.end()) { + _audiodriver->getMainBuffer()->bindCallID(*iter_participant, + default_id); - iter_participant++; - } + iter_participant++; + } - // Reset ringbuffer's readpointers - iter_participant = participants.begin(); + // Reset ringbuffer's readpointers + iter_participant = participants.begin(); - while (iter_participant != participants.end()) { - _audiodriver->getMainBuffer()->flush (*iter_participant); + while (iter_participant != participants.end()) { + _audiodriver->getMainBuffer()->flush(*iter_participant); - iter_participant++; - } + iter_participant++; + } - _audiodriver->getMainBuffer()->flush (default_id); + _audiodriver->getMainBuffer()->flush(default_id); - conf->setState (Conference::Active_Atached); + conf->setState(Conference::Active_Atached); - _dbus->getCallManager()->conferenceChanged (conference_id, conf->getStateStr()); + _dbus->getCallManager()->conferenceChanged(conference_id, + conf->getStateStr()); - } + } - switchCall (conference_id); + switchCall(conference_id); } +void ManagerImpl::joinParticipant (const CallID& call_id1, + const CallID& call_id2) { + _debug ("ManagerImpl::joinParticipant(%s, %s)", call_id1.c_str(), call_id2.c_str()); + // _debug(" Current call ID %s", getCurrentCallId().c_str()); -void -ManagerImpl::joinParticipant (const CallID& call_id1, const CallID& call_id2) -{ - _debug ("ManagerImpl::joinParticipant(%s, %s)", call_id1.c_str(), call_id2.c_str()); - // _debug(" Current call ID %s", getCurrentCallId().c_str()); - - std::map<std::string, std::string> call1_details = getCallDetails (call_id1); - std::map<std::string, std::string> call2_details = getCallDetails (call_id2); - - std::map<std::string, std::string>::iterator iter_details; - - AccountID currentAccountId; - Call* call = NULL; - - CallID current_call_id = getCurrentCallId(); - _debug (" joinParticipant: current_call_id %s", current_call_id.c_str()); - + std::map<std::string, std::string> call1_details = getCallDetails(call_id1); + std::map<std::string, std::string> call2_details = getCallDetails(call_id2); - // detach from the conference and switch to this conference + std::map<std::string, std::string>::iterator iter_details; - if ( (current_call_id != call_id1) && (current_call_id != call_id2)) { - if (isConference (current_call_id)) - detachParticipant (default_id, current_call_id); - else - onHoldCall (current_call_id); - } + AccountID currentAccountId; + Call* call = NULL; - _debug (" joinParticipant: create a conference"); + CallID current_call_id = getCurrentCallId(); + _debug (" joinParticipant: current_call_id %s", current_call_id.c_str()); - Conference *conf = createConference (call_id1, call_id2); - switchCall (conf->getConfID()); + // detach from the conference and switch to this conference - currentAccountId = getAccountFromCall (call_id1); - call = getAccountLink (currentAccountId)->getCall (call_id1); - call->setConfId (conf->getConfID()); - - iter_details = call1_details.find ("CALL_STATE"); - _debug (" joinParticipant: call1 %s state: %s", call_id1.c_str(), iter_details->second.c_str()); - - if (iter_details->second == "HOLD") { - _debug (" OFFHOLD %s", call_id1.c_str()); - offHoldCall (call_id1); - } else if (iter_details->second == "INCOMING") { - _debug (" ANSWER %s", call_id1.c_str()); - answerCall (call_id1); - } else if (iter_details->second == "CURRENT") { - _debug (" CURRENT %s", call_id1.c_str()); - _audiodriver->getMainBuffer()->unBindAll (call_id1); - conf->bindParticipant (call_id1); - } else if (iter_details->second == "INACTIVE") { - _debug (" INACTIVE %s", call_id1.c_str()); - answerCall (call_id1); - } else { - _debug (" CAll State not recognized"); - } - - currentAccountId = getAccountFromCall (call_id2); - - call = getAccountLink (currentAccountId)->getCall (call_id2); - call->setConfId (conf->getConfID()); + if ((current_call_id != call_id1) && (current_call_id != call_id2)) { + if (isConference(current_call_id)) + detachParticipant(default_id, current_call_id); + else + onHoldCall(current_call_id); + } - iter_details = call2_details.find ("CALL_STATE"); - _debug (" joinParticipant: call2 %s state: %s", call_id2.c_str(), iter_details->second.c_str()); + _debug (" joinParticipant: create a conference"); + + Conference *conf = createConference(call_id1, call_id2); + switchCall(conf->getConfID()); + + currentAccountId = getAccountFromCall(call_id1); + call = getAccountLink(currentAccountId)->getCall(call_id1); + call->setConfId(conf->getConfID()); + + iter_details = call1_details.find("CALL_STATE"); + _debug (" joinParticipant: call1 %s state: %s", call_id1.c_str(), iter_details->second.c_str()); + + if (iter_details->second == "HOLD") { + _debug (" OFFHOLD %s", call_id1.c_str()); + offHoldCall(call_id1); + } else if (iter_details->second == "INCOMING") { + _debug (" ANSWER %s", call_id1.c_str()); + answerCall(call_id1); + } else if (iter_details->second == "CURRENT") { + _debug (" CURRENT %s", call_id1.c_str()); + _audiodriver->getMainBuffer()->unBindAll(call_id1); + conf->bindParticipant(call_id1); + } else if (iter_details->second == "INACTIVE") { + _debug (" INACTIVE %s", call_id1.c_str()); + answerCall(call_id1); + } else { + _debug (" CAll State not recognized"); + } - if (iter_details->second == "HOLD") { - _debug (" OFFHOLD %s", call_id2.c_str()); - offHoldCall (call_id2); - } else if (iter_details->second == "INCOMING") { - _debug (" ANSWER %s", call_id2.c_str()); - answerCall (call_id2); - } else if (iter_details->second == "CURRENT") { - _debug (" CURRENT %s", call_id2.c_str()); - _audiodriver->getMainBuffer()->unBindAll (call_id2); - conf->bindParticipant (call_id2); - } else if (iter_details->second == "INACTIVE") { - _debug (" INACTIVE %s", call_id2.c_str()); - answerCall (call_id2); - } else { - _debug (" CAll State not recognized"); - } + currentAccountId = getAccountFromCall(call_id2); + + call = getAccountLink(currentAccountId)->getCall(call_id2); + call->setConfId(conf->getConfID()); + + iter_details = call2_details.find("CALL_STATE"); + _debug (" joinParticipant: call2 %s state: %s", call_id2.c_str(), iter_details->second.c_str()); + + if (iter_details->second == "HOLD") { + _debug (" OFFHOLD %s", call_id2.c_str()); + offHoldCall(call_id2); + } else if (iter_details->second == "INCOMING") { + _debug (" ANSWER %s", call_id2.c_str()); + answerCall(call_id2); + } else if (iter_details->second == "CURRENT") { + _debug (" CURRENT %s", call_id2.c_str()); + _audiodriver->getMainBuffer()->unBindAll(call_id2); + conf->bindParticipant(call_id2); + } else if (iter_details->second == "INACTIVE") { + _debug (" INACTIVE %s", call_id2.c_str()); + answerCall(call_id2); + } else { + _debug (" CAll State not recognized"); + } - // finally bind main participant to conference - // addMainParticipant(default_conf); + // finally bind main participant to conference + // addMainParticipant(default_conf); - // switchCall(conf->getConfID()); + // switchCall(conf->getConfID()); - if (_audiodriver) - _audiodriver->getMainBuffer()->stateInfo(); + if (_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); } +void ManagerImpl::detachParticipant (const CallID& call_id, + const CallID& current_id) { + _debug ("ManagerImpl::detachParticipant(%s)", call_id.c_str()); -void -ManagerImpl::detachParticipant (const CallID& call_id, const CallID& current_id) -{ - _debug ("ManagerImpl::detachParticipant(%s)", call_id.c_str()); + CallID current_call_id = current_id; - CallID current_call_id = current_id; + current_call_id = getCurrentCallId(); - current_call_id = getCurrentCallId(); + if (call_id != default_id) { + AccountID currentAccountId; + Call* call = NULL; - if (call_id != default_id) { - AccountID currentAccountId; - Call* call = NULL; + currentAccountId = getAccountFromCall(call_id); + call = getAccountLink(currentAccountId)->getCall(call_id); - currentAccountId = getAccountFromCall (call_id); - call = getAccountLink (currentAccountId)->getCall (call_id); + // TODO: add conference_id as a second parameter + ConferenceMap::iterator iter = _conferencemap.find(call->getConfId()); - // TODO: add conference_id as a second parameter - ConferenceMap::iterator iter = _conferencemap.find (call->getConfId()); + Conference *conf = getConferenceFromCallID(call_id); - Conference *conf = getConferenceFromCallID (call_id); + if (conf != NULL) { - if (conf != NULL) { + _debug (" detachParticipant: detaching participant %s", call_id.c_str()); - _debug (" detachParticipant: detaching participant %s", call_id.c_str()); + std::map<std::string, std::string> call_details = getCallDetails( + call_id); + std::map<std::string, std::string>::iterator iter_details; - std::map<std::string, std::string> call_details = getCallDetails (call_id); - std::map<std::string, std::string>::iterator iter_details; + iter_details = call_details.find("CALL_STATE"); - iter_details = call_details.find ("CALL_STATE"); + if (iter_details->second == "RINGING") { + removeParticipant(call_id); + } else { + _debug (" ONHOLD %s", call_id.c_str()); + onHoldCall(call_id); - if (iter_details->second == "RINGING") { - removeParticipant (call_id); - } else { - _debug (" ONHOLD %s", call_id.c_str()); - onHoldCall (call_id); + removeParticipant(call_id); - removeParticipant (call_id); + processRemainingParticipant(current_call_id, conf); + } + } else { - processRemainingParticipant (current_call_id, conf); - } - } else { + _debug (" detachParticipant: call is not conferencing, cannot detach"); + } + } else { + _debug (" detachParticipant: unbind main participant from all"); + _audiodriver->getMainBuffer()->unBindAll(default_id); - _debug (" detachParticipant: call is not conferencing, cannot detach"); - - } - } else { - _debug (" detachParticipant: unbind main participant from all"); - _audiodriver->getMainBuffer()->unBindAll (default_id); - - if (isConference (current_call_id)) { + if (isConference(current_call_id)) { - ConferenceMap::iterator iter = _conferencemap.find (current_call_id); - Conference *conf = iter->second; + ConferenceMap::iterator iter = _conferencemap.find(current_call_id); + Conference *conf = iter->second; - conf->setState (Conference::Active_Detached); + conf->setState(Conference::Active_Detached); - _dbus->getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); - } + _dbus->getCallManager()->conferenceChanged(conf->getConfID(), + conf->getStateStr()); + } - switchCall (""); + switchCall(""); - } + } } +void ManagerImpl::removeParticipant (const CallID& call_id) { + _debug ("ManagerImpl::removeParticipant(%s)", call_id.c_str()); -void -ManagerImpl::removeParticipant (const CallID& call_id) -{ - _debug ("ManagerImpl::removeParticipant(%s)", call_id.c_str()); - - // TODO: add conference_id as a second parameter - Conference* conf; + // TODO: add conference_id as a second parameter + Conference* conf; - AccountID currentAccountId; - Call* call = NULL; + AccountID currentAccountId; + Call* call = NULL; - // this call is no more a conference participant - currentAccountId = getAccountFromCall (call_id); - call = getAccountLink (currentAccountId)->getCall (call_id); + // this call is no more a conference participant + currentAccountId = getAccountFromCall(call_id); + call = getAccountLink(currentAccountId)->getCall(call_id); - ConferenceMap conf_map = _conferencemap; - ConferenceMap::iterator iter = conf_map.find (call->getConfId()); + ConferenceMap conf_map = _conferencemap; + ConferenceMap::iterator iter = conf_map.find(call->getConfId()); - if (iter == conf_map.end()) { - _debug (" no conference created, cannot remove participant "); - } else { + if (iter == conf_map.end()) { + _debug (" no conference created, cannot remove participant "); + } else { - conf = iter->second; + conf = iter->second; - _debug (" removeParticipant %s", call_id.c_str()); - conf->remove (call_id); - call->setConfId (""); + _debug (" removeParticipant %s", call_id.c_str()); + conf->remove(call_id); + call->setConfId(""); - } + } - if (_audiodriver) - _audiodriver->getMainBuffer()->stateInfo(); + if (_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); } +void ManagerImpl::processRemainingParticipant (CallID current_call_id, + Conference *conf) { -void -ManagerImpl::processRemainingParticipant (CallID current_call_id, Conference *conf) -{ + _debug ("ManagerImpl::processRemainingParticipant()"); - _debug ("ManagerImpl::processRemainingParticipant()"); + if (conf->getNbParticipants() > 1) { - if (conf->getNbParticipants() > 1) { + ParticipantSet participants = conf->getParticipantList(); + ParticipantSet::iterator iter_participant = participants.begin(); - ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + // Reset ringbuffer's readpointers + iter_participant = participants.begin(); - // Reset ringbuffer's readpointers - iter_participant = participants.begin(); + while (iter_participant != participants.end()) { + _audiodriver->getMainBuffer()->flush(*iter_participant); - while (iter_participant != participants.end()) { - _audiodriver->getMainBuffer()->flush (*iter_participant); - - iter_participant++; - } + iter_participant++; + } - _audiodriver->getMainBuffer()->flush (default_id); + _audiodriver->getMainBuffer()->flush(default_id); - } else if (conf->getNbParticipants() == 1) { - AccountID currentAccountId; - Call* call = NULL; + } else if (conf->getNbParticipants() == 1) { + AccountID currentAccountId; + Call* call = NULL; - ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + ParticipantSet participants = conf->getParticipantList(); + ParticipantSet::iterator iter_participant = participants.begin(); - // bind main participant to remaining conference call + // bind main participant to remaining conference call - if (iter_participant != participants.end()) { + if (iter_participant != participants.end()) { - // this call is no more a conference participant - currentAccountId = getAccountFromCall (*iter_participant); - call = getAccountLink (currentAccountId)->getCall (*iter_participant); - call->setConfId (""); + // this call is no more a conference participant + currentAccountId = getAccountFromCall(*iter_participant); + call = getAccountLink(currentAccountId)->getCall(*iter_participant); + call->setConfId(""); - // if we are not listening to this conference + // if we are not listening to this conference - if (current_call_id != conf->getConfID()) { - onHoldCall (call->getCallId()); - } else { - switchCall (*iter_participant); - } - } + if (current_call_id != conf->getConfID()) { + onHoldCall(call->getCallId()); + } else { + switchCall(*iter_participant); + } + } - removeConference (conf->getConfID()); - } else { - removeConference (conf->getConfID()); + removeConference(conf->getConfID()); + } else { + removeConference(conf->getConfID()); - switchCall (""); - } + switchCall(""); + } } -void -ManagerImpl::joinConference (const CallID& conf_id1, const CallID& conf_id2) -{ - _debug ("ManagerImpl::joinConference(%s, %s)", conf_id1.c_str(), conf_id2.c_str()); +void ManagerImpl::joinConference (const CallID& conf_id1, + const CallID& conf_id2) { + _debug ("ManagerImpl::joinConference(%s, %s)", conf_id1.c_str(), conf_id2.c_str()); - ConferenceMap::iterator iter; + ConferenceMap::iterator iter; - Conference *conf1 = NULL; - Conference *conf2 = NULL; + Conference *conf1 = NULL; + Conference *conf2 = NULL; - iter = _conferencemap.find (conf_id1); + iter = _conferencemap.find(conf_id1); - if (iter != _conferencemap.end()) - conf1 = iter->second; + if (iter != _conferencemap.end()) + conf1 = iter->second; - iter = _conferencemap.find (conf_id2); + iter = _conferencemap.find(conf_id2); - if (iter != _conferencemap.end()) - conf2 = iter->second; + if (iter != _conferencemap.end()) + conf2 = iter->second; - ParticipantSet participants = conf1->getParticipantList(); + ParticipantSet participants = conf1->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + ParticipantSet::iterator iter_participant = participants.begin(); - while (iter_participant != participants.end()) { - detachParticipant (*iter_participant, ""); - addParticipant (*iter_participant, conf_id2); + while (iter_participant != participants.end()) { + detachParticipant(*iter_participant, ""); + addParticipant(*iter_participant, conf_id2); - iter_participant++; - } + iter_participant++; + } - // detachParticipant(default_id, ""); + // detachParticipant(default_id, ""); } -void -ManagerImpl::addStream (const CallID& call_id) -{ - _debug ("ManagerImpl::addStream %s", call_id.c_str()); - - AccountID currentAccountId; - Call* call = NULL; - - currentAccountId = getAccountFromCall (call_id); - call = getAccountLink (currentAccountId)->getCall (call_id); +void ManagerImpl::addStream (const CallID& call_id) { + _debug ("ManagerImpl::addStream %s", call_id.c_str()); - if (participToConference (call_id)) { + AccountID currentAccountId; + Call* call = NULL; - // bind to conference participant - ConferenceMap::iterator iter = _conferencemap.find (call->getConfId()); + currentAccountId = getAccountFromCall(call_id); + call = getAccountLink(currentAccountId)->getCall(call_id); - if (iter != _conferencemap.end()) { - Conference* conf = iter->second; + if (participToConference(call_id)) { + // bind to conference participant + ConferenceMap::iterator iter = _conferencemap.find(call->getConfId()); - conf->bindParticipant (call_id); + if (iter != _conferencemap.end()) { + Conference* conf = iter->second; - ParticipantSet participants = conf->getParticipantList(); - // reset ring buffer for all conference participant - ParticipantSet::iterator iter_p = participants.begin(); + conf->bindParticipant(call_id); - while (iter_p != participants.end()) { + ParticipantSet participants = conf->getParticipantList(); + // reset ring buffer for all conference participant + ParticipantSet::iterator iter_p = participants.begin(); - // to avoid puting onhold the call - // switchCall(""); - _audiodriver->getMainBuffer()->flush (*iter_p); + while (iter_p != participants.end()) { - iter_p++; - } + // to avoid puting onhold the call + // switchCall(""); + _audiodriver->getMainBuffer()->flush(*iter_p); - _audiodriver->getMainBuffer()->flush (default_id); - } + iter_p++; + } - } else { + _audiodriver->getMainBuffer()->flush(default_id); + } + } else { - // bind to main - getAudioDriver()->getMainBuffer()->bindCallID (call_id); + // bind to main + getAudioDriver()->getMainBuffer()->bindCallID(call_id); - // _audiodriver->getMainBuffer()->flush(default_id); - _audiodriver->flushUrgent(); - _audiodriver->flushMain(); + // _audiodriver->getMainBuffer()->flush(default_id); + _audiodriver->flushUrgent(); + _audiodriver->flushMain(); - } + } - if (_audiodriver) - _audiodriver->getMainBuffer()->stateInfo(); + if (_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); } -void -ManagerImpl::removeStream (const CallID& call_id) -{ - _debug ("ManagerImpl::removeStream %s", call_id.c_str()); +void ManagerImpl::removeStream (const CallID& call_id) { + _debug ("ManagerImpl::removeStream %s", call_id.c_str()); - getAudioDriver()->getMainBuffer()->unBindAll (call_id); + getAudioDriver()->getMainBuffer()->unBindAll(call_id); - if (participToConference (call_id)) { - removeParticipant (call_id); - } + if (participToConference(call_id)) { + removeParticipant(call_id); + } - if (_audiodriver) - _audiodriver->getMainBuffer()->stateInfo(); + if (_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); } //THREAD=Main -bool -ManagerImpl::saveConfig (void) -{ - _debug ("Saving Configuration to XDG directory %s ... ", _path.c_str()); - setConfig (AUDIO, VOLUME_SPKR, getSpkrVolume()); - setConfig (AUDIO, VOLUME_MICRO, getMicVolume()); +bool ManagerImpl::saveConfig (void) { + _debug ("Saving Configuration to XDG directory %s ... ", _path.c_str()); + setConfig(AUDIO, VOLUME_SPKR, getSpkrVolume()); + setConfig(AUDIO, VOLUME_MICRO, getMicVolume()); - _setupLoaded = _config.saveConfigTree (_path.data()); - return _setupLoaded; + _setupLoaded = _config.saveConfigTree(_path.data()); + return _setupLoaded; } - //THREAD=Main -bool -ManagerImpl::sendDtmf (const CallID& id, char code) -{ - AccountID accountid = getAccountFromCall (id); +bool ManagerImpl::sendDtmf (const CallID& id, char code) { + AccountID accountid = getAccountFromCall(id); - if (accountid == AccountNULL) { - playDtmf (code); - return false; - } + if (accountid == AccountNULL) { + playDtmf(code); + return false; + } - int sendType = getConfigInt (SIGNALISATION, SEND_DTMF_AS); + int sendType = getConfigInt(SIGNALISATION, SEND_DTMF_AS); - bool returnValue = false; + bool returnValue = false; - switch (sendType) { + switch (sendType) { - case 0: // SIP INFO - playDtmf (code); - returnValue = getAccountLink (accountid)->carryingDTMFdigits (id, code); - break; + case 0: // SIP INFO + playDtmf(code); + returnValue = getAccountLink(accountid)->carryingDTMFdigits(id, code); + break; - case 1: // Audio way - break; + case 1: // Audio way + break; - case 2: // rfc 2833 - break; + case 2: // rfc 2833 + break; - default: // unknown - error config? - break; - } + default: // unknown - error config? + break; + } - return returnValue; + return returnValue; } //THREAD=Main | VoIPLink -bool -ManagerImpl::playDtmf (char code) -{ - int pulselen, layer, size; - bool ret = false; - AudioLayer *audiolayer; - SFLDataFormat *buf; +bool ManagerImpl::playDtmf (char code) { + int pulselen, layer, size; + bool ret = false; + AudioLayer *audiolayer; + SFLDataFormat *buf; - stopTone (); + stopTone(); - bool hasToPlayTone = getConfigBool (SIGNALISATION, PLAY_DTMF); + bool hasToPlayTone = getConfigBool(SIGNALISATION, PLAY_DTMF); - if (!hasToPlayTone) { - _debug (" playDtmf: Do not have to play a tone..."); - return false; - } - - // length in milliseconds - pulselen = getConfigInt (SIGNALISATION, PULSE_LENGTH); - - if (!pulselen) { - _debug (" playDtmf: Pulse length is not set..."); - return false; - } - - // numbers of int = length in milliseconds / 1000 (number of seconds) - // = number of seconds * SAMPLING_RATE by SECONDS - audiolayer = getAudioDriver(); + if (!hasToPlayTone) { + _debug (" playDtmf: Do not have to play a tone..."); + return false; + } - layer = audiolayer->getLayerType(); + // length in milliseconds + pulselen = getConfigInt(SIGNALISATION, PULSE_LENGTH); - // fast return, no sound, so no dtmf - if (audiolayer==0 || _dtmfKey == 0) { - _debug (" playDtmf: Error no audio layer..."); - return false; - } + if (!pulselen) { + _debug (" playDtmf: Pulse length is not set..."); + return false; + } - // number of data sampling in one pulselen depends on samplerate - // size (n sampling) = time_ms * sampling/s - // --------------------- - // ms/s - size = (int) ( (pulselen * (float) audiolayer->getSampleRate()) / 1000); + // numbers of int = length in milliseconds / 1000 (number of seconds) + // = number of seconds * SAMPLING_RATE by SECONDS + audiolayer = getAudioDriver(); - // this buffer is for mono - // TODO <-- this should be global and hide if same size - buf = new SFLDataFormat[size]; + layer = audiolayer->getLayerType(); - // Handle dtmf - _dtmfKey->startTone (code); + // fast return, no sound, so no dtmf + if (audiolayer == 0 || _dtmfKey == 0) { + _debug (" playDtmf: Error no audio layer..."); + return false; + } - // copy the sound - if (_dtmfKey->generateDTMF (buf, size)) { - // Put buffer to urgentRingBuffer - // put the size in bytes... - // so size * 1 channel (mono) * sizeof (bytes for the data) - // audiolayer->flushUrgent(); - audiolayer->startStream(); - audiolayer->putUrgent (buf, size * sizeof (SFLDataFormat)); - } + // number of data sampling in one pulselen depends on samplerate + // size (n sampling) = time_ms * sampling/s + // --------------------- + // ms/s + size = (int) ((pulselen * (float) audiolayer->getSampleRate()) / 1000); + + // this buffer is for mono + // TODO <-- this should be global and hide if same size + buf = new SFLDataFormat[size]; + + // Handle dtmf + _dtmfKey->startTone(code); + + // copy the sound + if (_dtmfKey->generateDTMF(buf, size)) { + // Put buffer to urgentRingBuffer + // put the size in bytes... + // so size * 1 channel (mono) * sizeof (bytes for the data) + // audiolayer->flushUrgent(); + audiolayer->startStream(); + audiolayer->putUrgent(buf, size * sizeof(SFLDataFormat)); + } - ret = true; + ret = true; - // TODO Cache the DTMF + // TODO Cache the DTMF - delete[] buf; - buf = 0; + delete[] buf; + buf = 0; - return ret; + return ret; } // Multi-thread -bool -ManagerImpl::incomingCallWaiting() -{ - return (_nbIncomingWaitingCall > 0) ? true : false; +bool ManagerImpl::incomingCallWaiting () { + return (_nbIncomingWaitingCall > 0) ? true : false; } -void -ManagerImpl::addWaitingCall (const CallID& id) -{ - ost::MutexLock m (_waitingCallMutex); - _waitingCall.insert (id); - _nbIncomingWaitingCall++; +void ManagerImpl::addWaitingCall (const CallID& id) { + ost::MutexLock m(_waitingCallMutex); + _waitingCall.insert(id); + _nbIncomingWaitingCall++; } -void -ManagerImpl::removeWaitingCall (const CallID& id) -{ - ost::MutexLock m (_waitingCallMutex); - // should return more than 1 if it erase a call +void ManagerImpl::removeWaitingCall (const CallID& id) { + ost::MutexLock m(_waitingCallMutex); + // should return more than 1 if it erase a call - if (_waitingCall.erase (id)) { - _nbIncomingWaitingCall--; - } + if (_waitingCall.erase(id)) { + _nbIncomingWaitingCall--; + } } -bool -ManagerImpl::isWaitingCall (const CallID& id) -{ - CallIDSet::iterator iter = _waitingCall.find (id); +bool ManagerImpl::isWaitingCall (const CallID& id) { + CallIDSet::iterator iter = _waitingCall.find(id); - if (iter != _waitingCall.end()) { - return false; - } + if (iter != _waitingCall.end()) { + return false; + } - return true; + return true; } /////////////////////////////////////////////////////////////////////////////// // Management of event peer IP-phone //////////////////////////////////////////////////////////////////////////////// // SipEvent Thread -bool -ManagerImpl::incomingCall (Call* call, const AccountID& accountId) -{ - PulseLayer *pulselayer; - std::string from, number, display_name, display; - - stopTone (); +bool ManagerImpl::incomingCall (Call* call, const AccountID& accountId) { + PulseLayer *pulselayer; + std::string from, number, display_name, display; - _debug ("Incoming call %s for account %s", call->getCallId().data(), accountId.c_str()); + stopTone(); - associateCallToAccount (call->getCallId(), accountId); + _debug ("Incoming call %s for account %s", call->getCallId().data(), accountId.c_str()); - // If account is null it is an ip to ip call + associateCallToAccount(call->getCallId(), accountId); - if (accountId==AccountNULL) { + // If account is null it is an ip to ip call - associateConfigToCall (call->getCallId(), Call::IPtoIP); - } else { - // strip sip: which is not required and bring confusion with ip to ip calls - // when placing new call from history (if call is IAX, do nothing) - std::string peerNumber = call->getPeerNumber(); + if (accountId == AccountNULL) { - int startIndex = peerNumber.find ("sip:"); + associateConfigToCall(call->getCallId(), Call::IPtoIP); + } else { + // strip sip: which is not required and bring confusion with ip to ip calls + // when placing new call from history (if call is IAX, do nothing) + std::string peerNumber = call->getPeerNumber(); - // if "sip:" is found => it is not an IAX call + int startIndex = peerNumber.find("sip:"); - if (startIndex != (int) string::npos) { - std::string strippedPeerNumber = peerNumber.substr (startIndex+4); - call->setPeerNumber (strippedPeerNumber); - } + // if "sip:" is found => it is not an IAX call - } + if (startIndex != (int) string::npos) { + std::string strippedPeerNumber = peerNumber.substr(startIndex + 4); + call->setPeerNumber(strippedPeerNumber); + } - _debug ("ManagerImpl::incomingCall :: hasCurrentCall() %i ", hasCurrentCall()); + } - if (!hasCurrentCall()) { + _debug ("ManagerImpl::incomingCall :: hasCurrentCall() %i ", hasCurrentCall()); - call->setConnectionState (Call::Ringing); - ringtone(); - // switchCall (call->getCallId()); + if (!hasCurrentCall()) { - } + call->setConnectionState(Call::Ringing); + ringtone(); + // switchCall (call->getCallId()); - /* - else { - addWaitingCall(call->getCallId()); - } - */ + } - addWaitingCall (call->getCallId()); + /* + else { + addWaitingCall(call->getCallId()); + } + */ - from = call->getPeerName(); + addWaitingCall(call->getCallId()); - number = call->getPeerNumber(); + from = call->getPeerName(); - display_name = call->getDisplayName(); + number = call->getPeerNumber(); - // _debug( "incomingCall from: %s, number: %s, display_name: %s", from.c_str(), number.c_str(), display_name.c_str()); + display_name = call->getDisplayName(); - if (from != "" && number != "") { - from.append (" <"); - from.append (number); - from.append (">"); - } else if (from.empty()) { - from.append ("<"); - from.append (number); - from.append (">"); - } + // _debug( "incomingCall from: %s, number: %s, display_name: %s", from.c_str(), number.c_str(), display_name.c_str()); - /* - CallIDSet::iterator iter = _waitingCall.begin(); - while (iter != _waitingCall.end()) { - CallID ident = *iter; - _debug("ManagerImpl::incomingCall :: CALL iteration: %s ",ident.c_str()); - ++iter; - } - */ + if (from != "" && number != "") { + from.append(" <"); + from.append(number); + from.append(">"); + } else if (from.empty()) { + from.append("<"); + from.append(number); + from.append(">"); + } - /* Broadcast a signal over DBus */ - _debug ("From: %s, Number: %s, DisplayName: %s", from.c_str(), number.c_str(), display_name.c_str()); + /* + CallIDSet::iterator iter = _waitingCall.begin(); + while (iter != _waitingCall.end()) { + CallID ident = *iter; + _debug("ManagerImpl::incomingCall :: CALL iteration: %s ",ident.c_str()); + ++iter; + } + */ - display = display_name; + /* Broadcast a signal over DBus */ + _debug ("From: %s, Number: %s, DisplayName: %s", from.c_str(), number.c_str(), display_name.c_str()); - display.append (" "); + display = display_name; - display.append (from); + display.append(" "); + display.append(from); - if (_dbus) _dbus->getCallManager()->incomingCall (accountId, call->getCallId(), display.c_str()); + if (_dbus) + _dbus->getCallManager()->incomingCall(accountId, call->getCallId(), + display.c_str()); - //if (_dbus) _dbus->getCallManager()->callStateChanged(call->getCallId(), "INCOMING"); + //if (_dbus) _dbus->getCallManager()->callStateChanged(call->getCallId(), "INCOMING"); - if (_audiodriver->getLayerType() == PULSEAUDIO) { - pulselayer = dynamic_cast<PulseLayer *> (getAudioDriver()); - } + if (_audiodriver->getLayerType() == PULSEAUDIO) { + pulselayer = dynamic_cast<PulseLayer *> (getAudioDriver()); + } - return true; + return true; } //THREAD=VoIP -void -ManagerImpl::incomingMessage (const AccountID& accountId, const std::string& message) -{ - if (_dbus) { - _dbus->getCallManager()->incomingMessage (accountId, message); - } +void ManagerImpl::incomingMessage (const AccountID& accountId, + const std::string& message) { + if (_dbus) { + _dbus->getCallManager()->incomingMessage(accountId, message); + } } //THREAD=VoIP CALL=Outgoing -void -ManagerImpl::peerAnsweredCall (const CallID& id) -{ - // The if statement is usefull only if we sent two calls at the same time. - if (isCurrentCall (id)) { - stopTone (); - } +void ManagerImpl::peerAnsweredCall (const CallID& id) { + // The if statement is usefull only if we sent two calls at the same time. + if (isCurrentCall(id)) { + stopTone(); + } - if (_dbus) _dbus->getCallManager()->callStateChanged (id, "CURRENT"); + if (_dbus) + _dbus->getCallManager()->callStateChanged(id, "CURRENT"); - // std::string codecName = getCurrentCodecName (id); + // std::string codecName = getCurrentCodecName (id); - // _debug("ManagerImpl::hangupCall(): broadcast codec name %s ",codecName.c_str()); - // if (_dbus) _dbus->getCallManager()->currentSelectedCodec (id,codecName.c_str()); + // _debug("ManagerImpl::hangupCall(): broadcast codec name %s ",codecName.c_str()); + // if (_dbus) _dbus->getCallManager()->currentSelectedCodec (id,codecName.c_str()); - // Required if there have been no sip reinvite, in this case we must reinit buffers since the - _audiodriver->flushMain(); + // Required if there have been no sip reinvite, in this case we must reinit buffers since the + _audiodriver->flushMain(); - _audiodriver->flushUrgent(); + _audiodriver->flushUrgent(); } //THREAD=VoIP Call=Outgoing -void -ManagerImpl::peerRingingCall (const CallID& id) -{ - if (isCurrentCall (id)) { - ringback(); - } +void ManagerImpl::peerRingingCall (const CallID& id) { + if (isCurrentCall(id)) { + ringback(); + } - if (_dbus) _dbus->getCallManager()->callStateChanged (id, "RINGING"); + if (_dbus) + _dbus->getCallManager()->callStateChanged(id, "RINGING"); } //THREAD=VoIP Call=Outgoing/Ingoing -void -ManagerImpl::peerHungupCall (const CallID& call_id) -{ - PulseLayer *pulselayer; - AccountID account_id; - bool returnValue; - - _debug ("ManagerImpl::peerHungupCall(%s)", call_id.c_str()); - - // store the current call id - CallID current_call_id = getCurrentCallId(); +void ManagerImpl::peerHungupCall (const CallID& call_id) { + PulseLayer *pulselayer; + AccountID account_id; + bool returnValue; + _debug ("ManagerImpl::peerHungupCall(%s)", call_id.c_str()); - if (participToConference (call_id)) { + // store the current call id + CallID current_call_id = getCurrentCallId(); - Conference *conf = getConferenceFromCallID (call_id); + if (participToConference(call_id)) { - if (conf != NULL) { + Conference *conf = getConferenceFromCallID(call_id); - removeParticipant (call_id); + if (conf != NULL) { - processRemainingParticipant (current_call_id, conf); - } - } else { - if (isCurrentCall (call_id)) { - stopTone (); + removeParticipant(call_id); - switchCall (""); - } - } + processRemainingParticipant(current_call_id, conf); + } + } else { + if (isCurrentCall(call_id)) { + stopTone(); - /* Direct IP to IP call */ - if (getConfigFromCall (call_id) == Call::IPtoIP) { - SIPVoIPLink::instance (AccountNULL)->hangup (call_id); - } + switchCall(""); + } + } - else { + /* Direct IP to IP call */ + if (getConfigFromCall(call_id) == Call::IPtoIP) { + SIPVoIPLink::instance(AccountNULL)->hangup(call_id); + } - account_id = getAccountFromCall (call_id); + else { - if (account_id == AccountNULL) { - _debug ("peerHungupCall: Call doesn't exists"); - return; - } + account_id = getAccountFromCall(call_id); - returnValue = getAccountLink (account_id)->peerHungup (call_id); - } + if (account_id == AccountNULL) { + _debug ("peerHungupCall: Call doesn't exists"); + return; + } - /* Broadcast a signal over DBus */ - if (_dbus) _dbus->getCallManager()->callStateChanged (call_id, "HUNGUP"); + returnValue = getAccountLink(account_id)->peerHungup(call_id); + } - removeWaitingCall (call_id); + /* Broadcast a signal over DBus */ + if (_dbus) + _dbus->getCallManager()->callStateChanged(call_id, "HUNGUP"); - removeCallAccount (call_id); + removeWaitingCall(call_id); - int nbCalls = getCallList().size(); + removeCallAccount(call_id); - // stop streams + int nbCalls = getCallList().size(); - if (nbCalls <= 0) { - _debug (" hangupCall: stop audio stream, ther is only %i call(s) remaining", nbCalls); + // stop streams - AudioLayer* audiolayer = getAudioDriver(); - audiolayer->stopStream(); - } + if (nbCalls <= 0) { + _debug (" hangupCall: stop audio stream, ther is only %i call(s) remaining", nbCalls); + AudioLayer* audiolayer = getAudioDriver(); + audiolayer->stopStream(); + } - if (_audiodriver->getLayerType() == PULSEAUDIO) { - pulselayer = dynamic_cast<PulseLayer *> (getAudioDriver()); - } + if (_audiodriver->getLayerType() == PULSEAUDIO) { + pulselayer = dynamic_cast<PulseLayer *> (getAudioDriver()); + } } //THREAD=VoIP -void -ManagerImpl::callBusy (const CallID& id) -{ - _debug ("Call busy"); +void ManagerImpl::callBusy (const CallID& id) { + _debug ("Call busy"); - if (_dbus) _dbus->getCallManager()->callStateChanged (id, "BUSY"); + if (_dbus) + _dbus->getCallManager()->callStateChanged(id, "BUSY"); - if (isCurrentCall (id)) { - playATone (Tone::TONE_BUSY); - switchCall (""); - } + if (isCurrentCall(id)) { + playATone(Tone::TONE_BUSY); + switchCall(""); + } - removeCallAccount (id); + removeCallAccount(id); - removeWaitingCall (id); + removeWaitingCall(id); } //THREAD=VoIP -void -ManagerImpl::callFailure (const CallID& call_id) -{ - if (_dbus) _dbus->getCallManager()->callStateChanged (call_id, "FAILURE"); +void ManagerImpl::callFailure (const CallID& call_id) { + if (_dbus) + _dbus->getCallManager()->callStateChanged(call_id, "FAILURE"); - if (isCurrentCall (call_id)) { - playATone (Tone::TONE_BUSY); - switchCall (""); - } + if (isCurrentCall(call_id)) { + playATone(Tone::TONE_BUSY); + switchCall(""); + } - CallID current_call_id = getCurrentCallId(); + CallID current_call_id = getCurrentCallId(); - if (participToConference (call_id)) { + if (participToConference(call_id)) { - _debug ("Call %s participating to a conference failed\n", call_id.c_str()); + _debug ("Call %s participating to a conference failed\n", call_id.c_str()); - Conference *conf = getConferenceFromCallID (call_id); + Conference *conf = getConferenceFromCallID(call_id); - if (conf != NULL) { - // remove this participant - removeParticipant (call_id); + if (conf != NULL) { + // remove this participant + removeParticipant(call_id); - processRemainingParticipant (current_call_id, conf); - } + processRemainingParticipant(current_call_id, conf); + } - } + } - removeCallAccount (call_id); + removeCallAccount(call_id); - removeWaitingCall (call_id); + removeWaitingCall(call_id); } //THREAD=VoIP -void -ManagerImpl::startVoiceMessageNotification (const AccountID& accountId, int nb_msg) -{ - if (_dbus) _dbus->getCallManager()->voiceMailNotify (accountId, nb_msg) ; +void ManagerImpl::startVoiceMessageNotification (const AccountID& accountId, + int nb_msg) { + if (_dbus) + _dbus->getCallManager()->voiceMailNotify(accountId, nb_msg); } -void ManagerImpl::connectionStatusNotification() -{ - if (_dbus != NULL) { - _dbus->getConfigurationManager()->accountsChanged(); - } +void ManagerImpl::connectionStatusNotification () { + if (_dbus != NULL) { + _dbus->getConfigurationManager()->accountsChanged(); + } } /** * Multi Thread */ -bool ManagerImpl::playATone (Tone::TONEID toneId) -{ - bool hasToPlayTone; - // AudioLoop *audioloop; - AudioLayer *audiolayer; - // unsigned int nbSamples; - - _debug ("ManagerImpl::playATone"); - - hasToPlayTone = getConfigBool (SIGNALISATION, PLAY_TONES); +bool ManagerImpl::playATone (Tone::TONEID toneId) { + bool hasToPlayTone; + // AudioLoop *audioloop; + AudioLayer *audiolayer; + // unsigned int nbSamples; - if (!hasToPlayTone) - return false; + _debug ("ManagerImpl::playATone"); - audiolayer = getAudioDriver(); + hasToPlayTone = getConfigBool(SIGNALISATION, PLAY_TONES); + if (!hasToPlayTone) + return false; - if (audiolayer) { + audiolayer = getAudioDriver(); - audiolayer->flushUrgent(); - audiolayer->startStream(); - } - - if (_telephoneTone != 0) { - _toneMutex.enterMutex(); - _telephoneTone->setCurrentTone (toneId); - _toneMutex.leaveMutex(); - /* - audioloop = getTelephoneTone(); - nbSamples = audioloop->getSize(); - SFLDataFormat buf[nbSamples]; + if (audiolayer) { + audiolayer->flushUrgent(); + audiolayer->startStream(); + } - if (audiolayer) { - audiolayer->putUrgent (buf, nbSamples); - } else - return false; - */ - } + if (_telephoneTone != 0) { + _toneMutex.enterMutex(); + _telephoneTone->setCurrentTone(toneId); + _toneMutex.leaveMutex(); + /* + audioloop = getTelephoneTone(); + nbSamples = audioloop->getSize(); + SFLDataFormat buf[nbSamples]; + + + if (audiolayer) { + audiolayer->putUrgent (buf, nbSamples); + } else + return false; + */ + } - return true; + return true; } /** * Multi Thread */ -void ManagerImpl::stopTone () -{ - bool hasToPlayTone; +void ManagerImpl::stopTone () { + bool hasToPlayTone; - hasToPlayTone = getConfigBool (SIGNALISATION, PLAY_TONES); + hasToPlayTone = getConfigBool(SIGNALISATION, PLAY_TONES); - if (!hasToPlayTone) - return; + if (!hasToPlayTone) + return; - _toneMutex.enterMutex(); + _toneMutex.enterMutex(); - if (_telephoneTone != 0) { - _telephoneTone->setCurrentTone (Tone::TONE_NULL); - } + if (_telephoneTone != 0) { + _telephoneTone->setCurrentTone(Tone::TONE_NULL); + } - _toneMutex.leaveMutex(); + _toneMutex.leaveMutex(); - // for ringing tone.. - _toneMutex.enterMutex(); - _audiofile.stop(); - _toneMutex.leaveMutex(); + // for ringing tone.. + _toneMutex.enterMutex(); + _audiofile.stop(); + _toneMutex.leaveMutex(); } /** * Multi Thread */ -bool -ManagerImpl::playTone() -{ - playATone (Tone::TONE_DIALTONE); - return true; +bool ManagerImpl::playTone () { + playATone(Tone::TONE_DIALTONE); + return true; } /** * Multi Thread */ -bool -ManagerImpl::playToneWithMessage() -{ - playATone (Tone::TONE_CONGESTION); - return true; +bool ManagerImpl::playToneWithMessage () { + playATone(Tone::TONE_CONGESTION); + return true; } /** * Multi Thread */ -void -ManagerImpl::congestion () -{ - playATone (Tone::TONE_CONGESTION); +void ManagerImpl::congestion () { + playATone(Tone::TONE_CONGESTION); } /** * Multi Thread */ -void -ManagerImpl::ringback () -{ - _debug ("ManagerImpl::ringback"); +void ManagerImpl::ringback () { + _debug ("ManagerImpl::ringback"); - playATone (Tone::TONE_RINGTONE); + playATone(Tone::TONE_RINGTONE); } /** * Multi Thread */ -void -ManagerImpl::ringtone() -{ - _debug ("ManagerImpl::ringtone"); - std::string ringchoice; - AudioLayer *audiolayer; - AudioCodec *codecForTone; - int layer, samplerate; - bool loadFile; - - if (isRingtoneEnabled()) { - - _debug (" Tone is enabled"); - //TODO Comment this because it makes the daemon crashes since the main thread - //synchronizes the ringtone thread. - - ringchoice = getConfigString (AUDIO, RING_CHOICE); - //if there is no / inside the path - - if (ringchoice.find (DIR_SEPARATOR_CH) == std::string::npos) { - // check inside global share directory - ringchoice = std::string (PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR + DIR_SEPARATOR_STR + ringchoice; - } - - audiolayer = getAudioDriver(); +void ManagerImpl::ringtone () { + _debug ("ManagerImpl::ringtone"); + std::string ringchoice; + AudioLayer *audiolayer; + AudioCodec *codecForTone; + int layer, samplerate; + bool loadFile; + + if (isRingtoneEnabled()) { + + _debug (" Tone is enabled"); + //TODO Comment this because it makes the daemon crashes since the main thread + //synchronizes the ringtone thread. + + ringchoice = getConfigString(AUDIO, RING_CHOICE); + //if there is no / inside the path + + if (ringchoice.find(DIR_SEPARATOR_CH) == std::string::npos) { + // check inside global share directory + ringchoice = std::string(PROGSHAREDIR) + DIR_SEPARATOR_STR + + RINGDIR + DIR_SEPARATOR_STR + ringchoice; + } - layer = audiolayer->getLayerType(); + audiolayer = getAudioDriver(); - if (audiolayer == 0) - return; + layer = audiolayer->getLayerType(); + if (audiolayer == 0) + return; - samplerate = audiolayer->getSampleRate(); + samplerate = audiolayer->getSampleRate(); - codecForTone = _codecDescriptorMap.getFirstCodecAvailable(); + codecForTone = _codecDescriptorMap.getFirstCodecAvailable(); - _toneMutex.enterMutex(); + _toneMutex.enterMutex(); - loadFile = _audiofile.loadFile (ringchoice, codecForTone , samplerate); + loadFile = _audiofile.loadFile(ringchoice, codecForTone, samplerate); - _toneMutex.leaveMutex(); + _toneMutex.leaveMutex(); - if (loadFile) { + if (loadFile) { - _toneMutex.enterMutex(); - _audiofile.start(); - _toneMutex.leaveMutex(); + _toneMutex.enterMutex(); + _audiofile.start(); + _toneMutex.leaveMutex(); - // start audio if not started AND flush all buffers (main and urgent) - audiolayer->startStream(); + // start audio if not started AND flush all buffers (main and urgent) + audiolayer->startStream(); - } else { - ringback(); - } + } else { + ringback(); + } - } else { - ringback(); - } + } else { + ringback(); + } } AudioLoop* -ManagerImpl::getTelephoneTone() -{ - // _debug("ManagerImpl::getTelephoneTone()"); - if (_telephoneTone != 0) { - ost::MutexLock m (_toneMutex); - return _telephoneTone->getCurrentTone(); - } else { - return 0; - } +ManagerImpl::getTelephoneTone () { + // _debug("ManagerImpl::getTelephoneTone()"); + if (_telephoneTone != 0) { + ost::MutexLock m(_toneMutex); + return _telephoneTone->getCurrentTone(); + } else { + return 0; + } } AudioLoop* -ManagerImpl::getTelephoneFile() -{ - // _debug("ManagerImpl::getTelephoneFile()"); - ost::MutexLock m (_toneMutex); - - if (_audiofile.isStarted()) { - return &_audiofile; - } else { - return 0; - } +ManagerImpl::getTelephoneFile () { + // _debug("ManagerImpl::getTelephoneFile()"); + ost::MutexLock m(_toneMutex); + + if (_audiofile.isStarted()) { + return &_audiofile; + } else { + return 0; + } } -void ManagerImpl::notificationIncomingCall (void) -{ - AudioLayer *audiolayer; - std::ostringstream frequency; - unsigned int samplerate, nbSampling; +void ManagerImpl::notificationIncomingCall (void) { + AudioLayer *audiolayer; + std::ostringstream frequency; + unsigned int samplerate, nbSampling; - audiolayer = getAudioDriver(); + audiolayer = getAudioDriver(); - _debug ("ManagerImpl::notificationIncomingCall"); + _debug ("ManagerImpl::notificationIncomingCall"); - if (audiolayer != 0) { - samplerate = audiolayer->getSampleRate(); - frequency << "440/" << FRAME_PER_BUFFER; - Tone tone (frequency.str(), samplerate); - nbSampling = tone.getSize(); - SFLDataFormat buf[nbSampling]; - tone.getNext (buf, tone.getSize()); - /* Put the data in the urgent ring buffer */ - audiolayer->flushUrgent(); - audiolayer->putUrgent (buf, sizeof (SFLDataFormat) *nbSampling); - } + if (audiolayer != 0) { + samplerate = audiolayer->getSampleRate(); + frequency << "440/" << FRAME_PER_BUFFER; + Tone tone(frequency.str(), samplerate); + nbSampling = tone.getSize(); + SFLDataFormat buf[nbSampling]; + tone.getNext(buf, tone.getSize()); + /* Put the data in the urgent ring buffer */ + audiolayer->flushUrgent(); + audiolayer->putUrgent(buf, sizeof(SFLDataFormat) * nbSampling); + } } - /////////////////////////////////////////////////////////////////////////////// // Private functions /////////////////////////////////////////////////////////////////////////////// @@ -2195,1254 +2069,1314 @@ void ManagerImpl::notificationIncomingCall (void) * @return 1: ok -1: error directory */ -int -ManagerImpl::createSettingsPath (void) -{ +int ManagerImpl::createSettingsPath (void) { - std::string xdg_config, xdg_env; + std::string xdg_config, xdg_env; - _debug ("XDG_CONFIG_HOME: %s", XDG_CONFIG_HOME); + _debug ("XDG_CONFIG_HOME: %s", XDG_CONFIG_HOME); - xdg_config = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".config" + DIR_SEPARATOR_STR + PROGDIR; + xdg_config = std::string(HOMEDIR) + DIR_SEPARATOR_STR + ".config" + + DIR_SEPARATOR_STR + PROGDIR; - if (XDG_CONFIG_HOME != NULL) { - xdg_env = std::string (XDG_CONFIG_HOME); - (xdg_env.length() > 0) ? _path = xdg_env - : _path = xdg_config; - } else - _path = xdg_config; + if (XDG_CONFIG_HOME != NULL) { + xdg_env = std::string(XDG_CONFIG_HOME); + (xdg_env.length() > 0) ? _path = xdg_env : _path = xdg_config; + } else + _path = xdg_config; - if (mkdir (_path.data(), 0700) != 0) { - // If directory creation failed - if (errno != EEXIST) { - _debug ("Cannot create directory: %s", strerror (errno)); - return -1; - } - } + if (mkdir(_path.data(), 0700) != 0) { + // If directory creation failed + if (errno != EEXIST) { + _debug ("Cannot create directory: %s", strerror (errno)); + return -1; + } + } - // Load user's configuration - _path = _path + DIR_SEPARATOR_STR + PROGNAME + "rc"; + // Load user's configuration + _path = _path + DIR_SEPARATOR_STR + PROGNAME + "rc"; - return 1; + return 1; } /** * Initialization: Main Thread */ -void -ManagerImpl::initConfigFile (bool load_user_value, std::string alternate) -{ - _debug ("ManagerImpl::InitConfigFile"); - - // Default values, that will be overwritten by the call to - // 'populateFromFile' below. - - // Peer to peer settings - _config.addDefaultValue (std::pair<std::string, std::string> (SRTP_ENABLE, FALSE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (SRTP_RTP_FALLBACK, FALSE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (SRTP_KEY_EXCHANGE, "1"), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (ZRTP_HELLO_HASH, TRUE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS, TRUE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS_ONCE, FALSE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (ZRTP_NOT_SUPP_WARNING, TRUE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_LISTENER_PORT, DEFAULT_SIP_TLS_PORT), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_ENABLE, FALSE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_CA_LIST_FILE, EMPTY_FIELD), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_CERTIFICATE_FILE, EMPTY_FIELD), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_PRIVATE_KEY_FILE, EMPTY_FIELD), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_PASSWORD, EMPTY_FIELD), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_METHOD, "TLSv1"), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_CIPHERS, EMPTY_FIELD), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_SERVER_NAME, EMPTY_FIELD), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_VERIFY_SERVER, TRUE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_VERIFY_CLIENT, TRUE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_REQUIRE_CLIENT_CERTIFICATE, TRUE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_SEC, "2"), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_MSEC, "0"), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (LOCAL_INTERFACE, "default"), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (PUBLISHED_SAMEAS_LOCAL, TRUE_STR), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (LOCAL_PORT, DEFAULT_SIP_PORT), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (PUBLISHED_PORT, DEFAULT_SIP_PORT), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (PUBLISHED_ADDRESS, DEFAULT_ADDRESS), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (STUN_ENABLE, DFT_STUN_ENABLE), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (STUN_SERVER, DFT_STUN_SERVER), IP2IP_PROFILE); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, EMPTY_FIELD), IP2IP_PROFILE); - - // Init display name to the username under which - // this sflphone instance is running. - std::string diplayName (""); - uid_t uid = getuid(); - - struct passwd * user_info = NULL; - user_info = getpwuid (uid); - - if (user_info != NULL) { - diplayName = user_info->pw_name; - } - - _config.addDefaultValue (std::pair<std::string, std::string> (DISPLAY_NAME, diplayName), IP2IP_PROFILE); - - // Signalisation settings - _config.addDefaultValue (std::pair<std::string, std::string> (SYMMETRIC, TRUE_STR), SIGNALISATION); - _config.addDefaultValue (std::pair<std::string, std::string> (PLAY_DTMF, TRUE_STR), SIGNALISATION); - _config.addDefaultValue (std::pair<std::string, std::string> (PLAY_TONES, TRUE_STR), SIGNALISATION); - _config.addDefaultValue (std::pair<std::string, std::string> (PULSE_LENGTH, DFT_PULSE_LENGTH_STR), SIGNALISATION); - _config.addDefaultValue (std::pair<std::string, std::string> (SEND_DTMF_AS, SIP_INFO_STR), SIGNALISATION); - _config.addDefaultValue (std::pair<std::string, std::string> (ZRTP_ZIDFILE, ZRTP_ZID_FILENAME), SIGNALISATION); - - // Audio settings - _config.addDefaultValue (std::pair<std::string, std::string> (ALSA_CARD_ID_IN, ALSA_DFT_CARD), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (ALSA_CARD_ID_OUT, ALSA_DFT_CARD), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (AUDIO_SAMPLE_RATE, DFT_SAMPLE_RATE), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (ALSA_FRAME_SIZE, DFT_FRAME_SIZE), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (ALSA_PLUGIN, PCM_DEFAULT), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (RING_CHOICE, DFT_RINGTONE), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (VOLUME_SPKR, DFT_VOL_SPKR_STR), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (VOLUME_MICRO, DFT_VOL_MICRO_STR), AUDIO); - _config.addDefaultValue (std::pair<std::string, std::string> (RECORD_PATH,DFT_RECORD_PATH), AUDIO); - - // General settings - _config.addDefaultValue (std::pair<std::string, std::string> (ZONE_TONE, DFT_ZONE), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_RINGTONE, TRUE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_DIALPAD, TRUE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_SEARCHBAR, TRUE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_START, FALSE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_POPUP, TRUE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_NOTIFY, TRUE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_MAIL_NOTIFY, FALSE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_VOLUME, TRUE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_HISTORY_LIMIT, DFT_HISTORY_LIMIT), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_HISTORY_ENABLED, TRUE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_AUDIO, DFT_AUDIO_MANAGER), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_SIP_PORT, DFT_SIP_PORT), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNTS_ORDER, EMPTY_FIELD), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_MD5HASH, FALSE_STR), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (WINDOW_WIDTH, DFT_WINDOW_WIDTH), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (WINDOW_HEIGHT, DFT_WINDOW_HEIGHT), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (WINDOW_POSITION_X, "0"), PREFERENCES); - _config.addDefaultValue (std::pair<std::string, std::string> (WINDOW_POSITION_Y, "0"), PREFERENCES); - - // Addressbook settings - _config.addDefaultValue (std::pair<std::string, std::string> (ADDRESSBOOK_ENABLE, TRUE_STR), ADDRESSBOOK); - _config.addDefaultValue (std::pair<std::string, std::string> (ADDRESSBOOK_MAX_RESULTS, "25"), ADDRESSBOOK); - _config.addDefaultValue (std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, FALSE_STR), ADDRESSBOOK); - _config.addDefaultValue (std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, TRUE_STR), ADDRESSBOOK); - _config.addDefaultValue (std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_PHONE_HOME, FALSE_STR), ADDRESSBOOK); - _config.addDefaultValue (std::pair<std::string, std::string> (ADDRESSBOOK_DISPLAY_PHONE_MOBILE, FALSE_STR), ADDRESSBOOK); - - // Hooks settings - _config.addDefaultValue (std::pair<std::string, std::string> (URLHOOK_SIP_FIELD, HOOK_DEFAULT_SIP_FIELD), HOOKS); - _config.addDefaultValue (std::pair<std::string, std::string> (URLHOOK_COMMAND, HOOK_DEFAULT_URL_COMMAND), HOOKS); - _config.addDefaultValue (std::pair<std::string, std::string> (URLHOOK_SIP_ENABLED, FALSE_STR), HOOKS); - _config.addDefaultValue (std::pair<std::string, std::string> (URLHOOK_IAX2_ENABLED, FALSE_STR), HOOKS); - _config.addDefaultValue (std::pair<std::string, std::string> (PHONE_NUMBER_HOOK_ENABLED, FALSE_STR), HOOKS); - _config.addDefaultValue (std::pair<std::string, std::string> (PHONE_NUMBER_HOOK_ADD_PREFIX, EMPTY_FIELD), HOOKS); - - std::string path; - // Loads config from ~/.sflphone/sflphonedrc or so.. - - if (createSettingsPath() == 1 && load_user_value) { - (alternate == "") ? path = _path : path = alternate; - std::cout << path << std::endl; - _exist = _config.populateFromFile (path); - } - - // Globally shared default values (not to be populated from file) - _config.addDefaultValue (std::pair<std::string, std::string> (HOSTNAME, EMPTY_FIELD)); - - _config.addDefaultValue (std::pair<std::string, std::string> (AUTHENTICATION_USERNAME, EMPTY_FIELD)); - - _config.addDefaultValue (std::pair<std::string, std::string> (USERNAME, EMPTY_FIELD)); - - _config.addDefaultValue (std::pair<std::string, std::string> (PASSWORD, EMPTY_FIELD)); - - _config.addDefaultValue (std::pair<std::string, std::string> (REALM, DEFAULT_REALM)); - - _config.addDefaultValue (std::pair<std::string, std::string> (USERAGENT, DFT_USERAGENT)); - - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNT_REGISTRATION_EXPIRE, DFT_EXPIRE_VALUE)); - - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNT_RESOLVE_ONCE, FALSE_STR)); - - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, EMPTY_FIELD)); - - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNT_MAILBOX, EMPTY_FIELD)); +void ManagerImpl::initConfigFile (bool load_user_value, std::string alternate) { + _debug ("ManagerImpl::InitConfigFile"); + + // Default values, that will be overwritten by the call to + // 'populateFromFile' below. + + // Peer to peer settings + _config.addDefaultValue(std::pair<std::string, std::string>(SRTP_ENABLE, + FALSE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + SRTP_RTP_FALLBACK, FALSE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + SRTP_KEY_EXCHANGE, "1"), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + ZRTP_HELLO_HASH, TRUE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + ZRTP_DISPLAY_SAS, TRUE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + ZRTP_DISPLAY_SAS_ONCE, FALSE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + ZRTP_NOT_SUPP_WARNING, TRUE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_LISTENER_PORT, DEFAULT_SIP_TLS_PORT), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(TLS_ENABLE, + FALSE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_CA_LIST_FILE, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_CERTIFICATE_FILE, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_PRIVATE_KEY_FILE, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(TLS_PASSWORD, + EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(TLS_METHOD, + "TLSv1"), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(TLS_CIPHERS, + EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_SERVER_NAME, EMPTY_FIELD), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_VERIFY_SERVER, TRUE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_VERIFY_CLIENT, TRUE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_REQUIRE_CLIENT_CERTIFICATE, TRUE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_NEGOTIATION_TIMEOUT_SEC, "2"), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + TLS_NEGOTIATION_TIMEOUT_MSEC, "0"), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + LOCAL_INTERFACE, "default"), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + PUBLISHED_SAMEAS_LOCAL, TRUE_STR), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(LOCAL_PORT, + DEFAULT_SIP_PORT), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(PUBLISHED_PORT, + DEFAULT_SIP_PORT), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + PUBLISHED_ADDRESS, DEFAULT_ADDRESS), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(STUN_ENABLE, + DFT_STUN_ENABLE), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>(STUN_SERVER, + DFT_STUN_SERVER), IP2IP_PROFILE); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNT_ALIAS, EMPTY_FIELD), IP2IP_PROFILE); + + // Init display name to the username under which + // this sflphone instance is running. + std::string diplayName(""); + uid_t uid = getuid(); + + struct passwd * user_info = NULL; + user_info = getpwuid(uid); + + if (user_info != NULL) { + diplayName = user_info->pw_name; + } + + _config.addDefaultValue(std::pair<std::string, std::string>(DISPLAY_NAME, + diplayName), IP2IP_PROFILE); + + // Signalisation settings + _config.addDefaultValue(std::pair<std::string, std::string>(SYMMETRIC, + TRUE_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string>(PLAY_DTMF, + TRUE_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string>(PLAY_TONES, + TRUE_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string>(PULSE_LENGTH, + DFT_PULSE_LENGTH_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string>(SEND_DTMF_AS, + SIP_INFO_STR), SIGNALISATION); + _config.addDefaultValue(std::pair<std::string, std::string>(ZRTP_ZIDFILE, + ZRTP_ZID_FILENAME), SIGNALISATION); + + // Audio settings + _config.addDefaultValue(std::pair<std::string, std::string>( + ALSA_CARD_ID_IN, ALSA_DFT_CARD), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>( + ALSA_CARD_ID_OUT, ALSA_DFT_CARD), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>( + AUDIO_SAMPLE_RATE, DFT_SAMPLE_RATE), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>( + ALSA_FRAME_SIZE, DFT_FRAME_SIZE), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>(ALSA_PLUGIN, + PCM_DEFAULT), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>(RING_CHOICE, + DFT_RINGTONE), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>(VOLUME_SPKR, + DFT_VOL_SPKR_STR), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>(VOLUME_MICRO, + DFT_VOL_MICRO_STR), AUDIO); + _config.addDefaultValue(std::pair<std::string, std::string>(RECORD_PATH, + DFT_RECORD_PATH), AUDIO); + + // General settings + _config.addDefaultValue(std::pair<std::string, std::string>(ZONE_TONE, + DFT_ZONE), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_RINGTONE, TRUE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(CONFIG_DIALPAD, + TRUE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_SEARCHBAR, TRUE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(CONFIG_START, + FALSE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(CONFIG_POPUP, + TRUE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(CONFIG_NOTIFY, + TRUE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_MAIL_NOTIFY, FALSE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(CONFIG_VOLUME, + TRUE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_HISTORY_LIMIT, DFT_HISTORY_LIMIT), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_HISTORY_ENABLED, TRUE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(CONFIG_AUDIO, + DFT_AUDIO_MANAGER), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_SIP_PORT, DFT_SIP_PORT), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNTS_ORDER, EMPTY_FIELD), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(CONFIG_MD5HASH, + FALSE_STR), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(WINDOW_WIDTH, + DFT_WINDOW_WIDTH), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>(WINDOW_HEIGHT, + DFT_WINDOW_HEIGHT), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + WINDOW_POSITION_X, "0"), PREFERENCES); + _config.addDefaultValue(std::pair<std::string, std::string>( + WINDOW_POSITION_Y, "0"), PREFERENCES); + + // Addressbook settings + _config.addDefaultValue(std::pair<std::string, std::string>( + ADDRESSBOOK_ENABLE, TRUE_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string>( + ADDRESSBOOK_MAX_RESULTS, "25"), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string>( + ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, FALSE_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string>( + ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, TRUE_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string>( + ADDRESSBOOK_DISPLAY_PHONE_HOME, FALSE_STR), ADDRESSBOOK); + _config.addDefaultValue(std::pair<std::string, std::string>( + ADDRESSBOOK_DISPLAY_PHONE_MOBILE, FALSE_STR), ADDRESSBOOK); + + // Hooks settings + _config.addDefaultValue(std::pair<std::string, std::string>( + URLHOOK_SIP_FIELD, HOOK_DEFAULT_SIP_FIELD), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string>( + URLHOOK_COMMAND, HOOK_DEFAULT_URL_COMMAND), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string>( + URLHOOK_SIP_ENABLED, FALSE_STR), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string>( + URLHOOK_IAX2_ENABLED, FALSE_STR), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string>( + PHONE_NUMBER_HOOK_ENABLED, FALSE_STR), HOOKS); + _config.addDefaultValue(std::pair<std::string, std::string>( + PHONE_NUMBER_HOOK_ADD_PREFIX, EMPTY_FIELD), HOOKS); + + std::string path; + // Loads config from ~/.sflphone/sflphonedrc or so.. + + if (createSettingsPath() == 1 && load_user_value) { + (alternate == "") ? path = _path : path = alternate; + std::cout << path << std::endl; + _exist = _config.populateFromFile(path); + } + + // Globally shared default values (not to be populated from file) + _config.addDefaultValue(std::pair<std::string, std::string>(HOSTNAME, + EMPTY_FIELD)); + + _config.addDefaultValue(std::pair<std::string, std::string>( + AUTHENTICATION_USERNAME, EMPTY_FIELD)); + + _config.addDefaultValue(std::pair<std::string, std::string>(USERNAME, + EMPTY_FIELD)); + + _config.addDefaultValue(std::pair<std::string, std::string>(PASSWORD, + EMPTY_FIELD)); + + _config.addDefaultValue(std::pair<std::string, std::string>(REALM, + DEFAULT_REALM)); + + _config.addDefaultValue(std::pair<std::string, std::string>(USERAGENT, + DFT_USERAGENT)); + + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNT_REGISTRATION_EXPIRE, DFT_EXPIRE_VALUE)); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ENABLE, TRUE_STR)); - - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_CREDENTIAL_NUMBER, "0")); + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNT_RESOLVE_ONCE, FALSE_STR)); - _config.addDefaultValue (std::pair<std::string, std::string> (CONFIG_ACCOUNT_TYPE, DEFAULT_ACCOUNT_TYPE)); - - _setupLoaded = (_exist == 2) ? false : true; + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNT_ALIAS, EMPTY_FIELD)); + + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNT_MAILBOX, EMPTY_FIELD)); + + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNT_ENABLE, TRUE_STR)); + + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_CREDENTIAL_NUMBER, "0")); + + _config.addDefaultValue(std::pair<std::string, std::string>( + CONFIG_ACCOUNT_TYPE, DEFAULT_ACCOUNT_TYPE)); + + _setupLoaded = (_exist == 2) ? false : true; } /** * Initialization: Main Thread */ -void -ManagerImpl::initAudioCodec (void) -{ - _info("Manager: Init audio codecs"); - - /* Init list of all supported codecs by the application. - * This is a global list. Every account will inherit it. - */ +void ManagerImpl::initAudioCodec (void) { + _info("Manager: Init audio codecs"); + + /* Init list of all supported codecs by the application. + * This is a global list. Every account will inherit it. + */ _codecDescriptorMap.init(); } /* * TODO Retrieve the active codec list per account */ -std::vector<std::string> ManagerImpl::retrieveActiveCodecs() { +std::vector<std::string> ManagerImpl::retrieveActiveCodecs () { // This property is now set per account basis - std::string s = getConfigString (AUDIO, "ActiveCodecs"); - _info("Manager: Retrieve active codecs: %s", s.c_str ()); - return unserialize (s); + std::string s = getConfigString(AUDIO, "ActiveCodecs"); + _info("Manager: Retrieve active codecs: %s", s.c_str ()); + return unserialize(s); } std::vector<std::string> ManagerImpl::unserialize (std::string s) { - std::vector<std::string> list; - std::string temp; + std::vector<std::string> list; + std::string temp; - while (s.find ("/", 0) != std::string::npos) { - size_t pos = s.find ("/", 0); - temp = s.substr (0, pos); - s.erase (0, pos + 1); - list.push_back (temp); - } + while (s.find("/", 0) != std::string::npos) { + size_t pos = s.find("/", 0); + temp = s.substr(0, pos); + s.erase(0, pos + 1); + list.push_back(temp); + } - return list; + return list; } std::string ManagerImpl::serialize (std::vector<std::string> v) { - unsigned int i; - std::string res; + unsigned int i; + std::string res; - for (i=0;i<v.size();i++) { - res += v[i] + "/"; - } + for (i = 0; i < v.size(); i++) { + res += v[i] + "/"; + } - return res; + return res; } std::string ManagerImpl::getCurrentCodecName (const CallID& id) { - AccountID accountid = getAccountFromCall (id); - VoIPLink* link = getAccountLink (accountid); - Call* call = link->getCall (id); + AccountID accountid = getAccountFromCall(id); + VoIPLink* link = getAccountLink(accountid); + Call* call = link->getCall(id); - if (!call) - return ""; + if (!call) + return ""; - if (call->getState() != Call::Active) - return ""; - else - return link->getCurrentCodecName(); + if (call->getState() != Call::Active) + return ""; + else + return link->getCurrentCodecName(); } /** * Set input audio plugin */ -void -ManagerImpl::setInputAudioPlugin (const std::string& audioPlugin) -{ - int layer = _audiodriver -> getLayerType(); - - if (CHECK_INTERFACE (layer , ALSA)) { - _debug ("Set input audio plugin"); - _audiodriver -> setErrorMessage (-1); - _audiodriver -> openDevice (_audiodriver -> getIndexIn(), - _audiodriver -> getIndexOut(), - _audiodriver -> getSampleRate(), - _audiodriver -> getFrameSize(), - SFL_PCM_CAPTURE, - audioPlugin); - - if (_audiodriver -> getErrorMessage() != -1) - notifyErrClient (_audiodriver -> getErrorMessage()); - } else {} +void ManagerImpl::setInputAudioPlugin (const std::string& audioPlugin) { + int layer = _audiodriver -> getLayerType(); + + if (CHECK_INTERFACE (layer , ALSA)) { + _debug ("Set input audio plugin"); + _audiodriver -> setErrorMessage(-1); + _audiodriver -> openDevice(_audiodriver -> getIndexIn(), + _audiodriver -> getIndexOut(), _audiodriver -> getSampleRate(), + _audiodriver -> getFrameSize(), SFL_PCM_CAPTURE, audioPlugin); + + if (_audiodriver -> getErrorMessage() != -1) + notifyErrClient(_audiodriver -> getErrorMessage()); + } else { + } } /** * Set output audio plugin */ -void -ManagerImpl::setOutputAudioPlugin (const std::string& audioPlugin) -{ +void ManagerImpl::setOutputAudioPlugin (const std::string& audioPlugin) { - int res; + int res; - _debug ("Set output audio plugin"); - _audiodriver -> setErrorMessage (-1); - res = _audiodriver -> openDevice (_audiodriver -> getIndexIn(), - _audiodriver -> getIndexOut(), - _audiodriver -> getSampleRate(), - _audiodriver -> getFrameSize(), - SFL_PCM_BOTH, - audioPlugin); + _debug ("Set output audio plugin"); + _audiodriver -> setErrorMessage(-1); + res = _audiodriver -> openDevice(_audiodriver -> getIndexIn(), + _audiodriver -> getIndexOut(), _audiodriver -> getSampleRate(), + _audiodriver -> getFrameSize(), SFL_PCM_BOTH, audioPlugin); - if (_audiodriver -> getErrorMessage() != -1) - notifyErrClient (_audiodriver -> getErrorMessage()); + if (_audiodriver -> getErrorMessage() != -1) + notifyErrClient(_audiodriver -> getErrorMessage()); - // set config - if (res) setConfig (AUDIO , ALSA_PLUGIN , audioPlugin); + // set config + if (res) + setConfig(AUDIO, ALSA_PLUGIN, audioPlugin); } /** * Get list of supported audio output device */ -std::vector<std::string> -ManagerImpl::getAudioOutputDeviceList (void) -{ - _debug ("Get audio output device list"); - AlsaLayer *layer; - std::vector <std::string> devices; +std::vector<std::string> ManagerImpl::getAudioOutputDeviceList (void) { + _debug ("Get audio output device list"); + AlsaLayer *layer; + std::vector<std::string> devices; - layer = dynamic_cast<AlsaLayer*> (getAudioDriver ()); + layer = dynamic_cast<AlsaLayer*> (getAudioDriver()); - if (layer) - devices = layer -> getSoundCardsInfo (SFL_PCM_PLAYBACK); + if (layer) + devices = layer -> getSoundCardsInfo(SFL_PCM_PLAYBACK); - return devices; + return devices; } /** * Set audio output device */ -void -ManagerImpl::setAudioOutputDevice (const int index) -{ - AlsaLayer *alsalayer; - std::string alsaplugin; - _debug ("Set audio output device: %i", index); +void ManagerImpl::setAudioOutputDevice (const int index) { + AlsaLayer *alsalayer; + std::string alsaplugin; + _debug ("Set audio output device: %i", index); - _audiodriver -> setErrorMessage (-1); + _audiodriver -> setErrorMessage(-1); - alsalayer = dynamic_cast<AlsaLayer*> (getAudioDriver ()); - alsaplugin = alsalayer->getAudioPlugin (); + alsalayer = dynamic_cast<AlsaLayer*> (getAudioDriver()); + alsaplugin = alsalayer->getAudioPlugin(); - _debug (" set output plugin: %s", alsaplugin.c_str()); + _debug (" set output plugin: %s", alsaplugin.c_str()); - _audiodriver->openDevice (_audiodriver->getIndexIn(), index, _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), SFL_PCM_PLAYBACK, alsaplugin); + _audiodriver->openDevice(_audiodriver->getIndexIn(), index, + _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), + SFL_PCM_PLAYBACK, alsaplugin); - if (_audiodriver -> getErrorMessage() != -1) - notifyErrClient (_audiodriver -> getErrorMessage()); + if (_audiodriver -> getErrorMessage() != -1) + notifyErrClient(_audiodriver -> getErrorMessage()); - // set config - setConfig (AUDIO , ALSA_CARD_ID_OUT , index); + // set config + setConfig(AUDIO, ALSA_CARD_ID_OUT, index); } /** * Get list of supported audio input device */ -std::vector<std::string> -ManagerImpl::getAudioInputDeviceList (void) -{ - AlsaLayer *audiolayer; - std::vector <std::string> devices; - - audiolayer = dynamic_cast<AlsaLayer *> (getAudioDriver()); +std::vector<std::string> ManagerImpl::getAudioInputDeviceList (void) { + AlsaLayer *audiolayer; + std::vector<std::string> devices; + audiolayer = dynamic_cast<AlsaLayer *> (getAudioDriver()); - if (audiolayer) - devices = audiolayer->getSoundCardsInfo (SFL_PCM_CAPTURE); + if (audiolayer) + devices = audiolayer->getSoundCardsInfo(SFL_PCM_CAPTURE); - return devices; + return devices; } /** * Set audio input device */ -void -ManagerImpl::setAudioInputDevice (const int index) -{ - AlsaLayer *alsalayer; - std::string alsaplugin; +void ManagerImpl::setAudioInputDevice (const int index) { + AlsaLayer *alsalayer; + std::string alsaplugin; - _debug ("Set audio input device %i", index); + _debug ("Set audio input device %i", index); - _audiodriver -> setErrorMessage (-1); + _audiodriver -> setErrorMessage(-1); - alsalayer = dynamic_cast<AlsaLayer*> (getAudioDriver ()); - alsaplugin = alsalayer->getAudioPlugin (); + alsalayer = dynamic_cast<AlsaLayer*> (getAudioDriver()); + alsaplugin = alsalayer->getAudioPlugin(); - _debug (" set input plugin: %s", alsaplugin.c_str()); + _debug (" set input plugin: %s", alsaplugin.c_str()); - _audiodriver->openDevice (index, _audiodriver->getIndexOut(), _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), SFL_PCM_CAPTURE, alsaplugin); + _audiodriver->openDevice(index, _audiodriver->getIndexOut(), + _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), + SFL_PCM_CAPTURE, alsaplugin); - if (_audiodriver -> getErrorMessage() != -1) - notifyErrClient (_audiodriver -> getErrorMessage()); + if (_audiodriver -> getErrorMessage() != -1) + notifyErrClient(_audiodriver -> getErrorMessage()); - // set config - setConfig (AUDIO , ALSA_CARD_ID_IN , index); + // set config + setConfig(AUDIO, ALSA_CARD_ID_IN, index); } /** * Get string array representing integer indexes of output and input device */ -std::vector<std::string> -ManagerImpl::getCurrentAudioDevicesIndex() -{ - _debug ("Get current audio devices index"); - std::vector<std::string> v; - std::stringstream ssi , sso; - sso << _audiodriver->getIndexOut(); - v.push_back (sso.str()); - ssi << _audiodriver->getIndexIn(); - v.push_back (ssi.str()); - return v; -} - -int -ManagerImpl::isIax2Enabled (void) -{ +std::vector<std::string> ManagerImpl::getCurrentAudioDevicesIndex () { + _debug ("Get current audio devices index"); + std::vector<std::string> v; + std::stringstream ssi, sso; + sso << _audiodriver->getIndexOut(); + v.push_back(sso.str()); + ssi << _audiodriver->getIndexIn(); + v.push_back(ssi.str()); + return v; +} + +int ManagerImpl::isIax2Enabled (void) { #ifdef USE_IAX - return true; + return true; #else - return false; + return false; #endif } -int -ManagerImpl::isRingtoneEnabled (void) -{ - return (getConfigString (PREFERENCES, CONFIG_RINGTONE) == "true") ? 1:0; +int ManagerImpl::isRingtoneEnabled (void) { + return (getConfigString(PREFERENCES, CONFIG_RINGTONE) == "true") ? 1 : 0; } -void -ManagerImpl::ringtoneEnabled (void) -{ - (getConfigString (PREFERENCES , CONFIG_RINGTONE) == RINGTONE_ENABLED) ? setConfig (PREFERENCES , CONFIG_RINGTONE , FALSE_STR) : setConfig (PREFERENCES , CONFIG_RINGTONE , TRUE_STR); +void ManagerImpl::ringtoneEnabled (void) { + (getConfigString(PREFERENCES, CONFIG_RINGTONE) == RINGTONE_ENABLED) ? setConfig( + PREFERENCES, CONFIG_RINGTONE, FALSE_STR) + : setConfig(PREFERENCES, CONFIG_RINGTONE, TRUE_STR); } -std::string -ManagerImpl::getRingtoneChoice (void) -{ - // we need the absolute path - std::string tone_name = getConfigString (AUDIO , RING_CHOICE); - std::string tone_path ; +std::string ManagerImpl::getRingtoneChoice (void) { + // we need the absolute path + std::string tone_name = getConfigString(AUDIO, RING_CHOICE); + std::string tone_path; - if (tone_name.find (DIR_SEPARATOR_CH) == std::string::npos) { - // check in ringtone directory ($(PREFIX)/share/sflphone/ringtones) - tone_path = std::string (PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR + DIR_SEPARATOR_STR + tone_name ; - } else { - // the absolute has been saved; do nothing - tone_path = tone_name ; - } + if (tone_name.find(DIR_SEPARATOR_CH) == std::string::npos) { + // check in ringtone directory ($(PREFIX)/share/sflphone/ringtones) + tone_path = std::string(PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR + + DIR_SEPARATOR_STR + tone_name; + } else { + // the absolute has been saved; do nothing + tone_path = tone_name; + } - _debug ("%s", tone_path.c_str()); + _debug ("%s", tone_path.c_str()); - return tone_path; + return tone_path; } -void -ManagerImpl::setRingtoneChoice (const std::string& tone) -{ - // we save the absolute path - setConfig (AUDIO , RING_CHOICE , tone); +void ManagerImpl::setRingtoneChoice (const std::string& tone) { + // we save the absolute path + setConfig(AUDIO, RING_CHOICE, tone); } -std::string -ManagerImpl::getRecordPath (void) -{ - return getConfigString (AUDIO, RECORD_PATH); +std::string ManagerImpl::getRecordPath (void) { + return getConfigString(AUDIO, RECORD_PATH); } -void -ManagerImpl::setRecordPath (const std::string& recPath) -{ - _debug ("ManagerImpl::setRecordPath(%s)! ", recPath.c_str()); - setConfig (AUDIO, RECORD_PATH, recPath); +void ManagerImpl::setRecordPath (const std::string& recPath) { + _debug ("ManagerImpl::setRecordPath(%s)! ", recPath.c_str()); + setConfig(AUDIO, RECORD_PATH, recPath); } -bool -ManagerImpl::getMd5CredentialHashing (void) -{ - return getConfigBool (PREFERENCES, CONFIG_MD5HASH); +bool ManagerImpl::getMd5CredentialHashing (void) { + return getConfigBool(PREFERENCES, CONFIG_MD5HASH); } -int -ManagerImpl::getDialpad (void) -{ - if (getConfigString (PREFERENCES, CONFIG_DIALPAD) == TRUE_STR) { - return 1; - } else { - return 0; - } +int ManagerImpl::getDialpad (void) { + if (getConfigString(PREFERENCES, CONFIG_DIALPAD) == TRUE_STR) { + return 1; + } else { + return 0; + } } -void -ManagerImpl::setDialpad (bool display) -{ - std::string set; +void ManagerImpl::setDialpad (bool display) { + std::string set; - display ? set = TRUE_STR : set = FALSE_STR; - // If the value we received is different from the one saved in the config file, save the new value - // Else do nothing + display ? set = TRUE_STR : set = FALSE_STR; + // If the value we received is different from the one saved in the config file, save the new value + // Else do nothing - if ( (display && (getConfigString (PREFERENCES, CONFIG_DIALPAD) != TRUE_STR)) || - (!display && (getConfigString (PREFERENCES, CONFIG_DIALPAD) != FALSE_STR))) - setConfig (PREFERENCES, CONFIG_DIALPAD, set); + if ((display && (getConfigString(PREFERENCES, CONFIG_DIALPAD) != TRUE_STR)) + || (!display && (getConfigString(PREFERENCES, CONFIG_DIALPAD) + != FALSE_STR))) + setConfig(PREFERENCES, CONFIG_DIALPAD, set); } -int -ManagerImpl::getVolumeControls (void) -{ - if (getConfigString (PREFERENCES , CONFIG_VOLUME) == TRUE_STR) { - return 1; - } else { - return 0; - } +int ManagerImpl::getVolumeControls (void) { + if (getConfigString(PREFERENCES, CONFIG_VOLUME) == TRUE_STR) { + return 1; + } else { + return 0; + } } -void ManagerImpl::setVolumeControls (bool display) -{ - std::string set; +void ManagerImpl::setVolumeControls (bool display) { + std::string set; - display ? set = TRUE_STR : set = FALSE_STR; - // If the value we received is different from the one saved in the config file, save the new value - // Else do nothing + display ? set = TRUE_STR : set = FALSE_STR; + // If the value we received is different from the one saved in the config file, save the new value + // Else do nothing - if ( (display && (getConfigString (PREFERENCES, CONFIG_VOLUME) != TRUE_STR)) || - (!display && (getConfigString (PREFERENCES, CONFIG_VOLUME) != FALSE_STR))) - setConfig (PREFERENCES, CONFIG_VOLUME, set); + if ((display && (getConfigString(PREFERENCES, CONFIG_VOLUME) != TRUE_STR)) + || (!display && (getConfigString(PREFERENCES, CONFIG_VOLUME) + != FALSE_STR))) + setConfig(PREFERENCES, CONFIG_VOLUME, set); } -void -ManagerImpl::setRecordingCall (const CallID& id) -{ - /* - _debug ("ManagerImpl::setRecording()! "); - AccountID accountid = getAccountFromCall (id); +void ManagerImpl::setRecordingCall (const CallID& id) { + /* + _debug ("ManagerImpl::setRecording()! "); + AccountID accountid = getAccountFromCall (id); - getAccountLink (accountid)->setRecording (id); - */ - AccountID accountid = getAccountFromCall (id); - Recordable* rec = (Recordable*) getAccountLink (accountid)->getCall (id); + getAccountLink (accountid)->setRecording (id); + */ + AccountID accountid = getAccountFromCall(id); + Recordable* rec = (Recordable*) getAccountLink(accountid)->getCall(id); - rec->setRecording(); + rec->setRecording(); } -bool -ManagerImpl::isRecording (const CallID& id) -{ - /* - _debug ("ManagerImpl::isRecording()! "); - AccountID accountid = getAccountFromCall (id); +bool ManagerImpl::isRecording (const CallID& id) { + /* + _debug ("ManagerImpl::isRecording()! "); + AccountID accountid = getAccountFromCall (id); - return getAccountLink (accountid)->isRecording (id); - */ + return getAccountLink (accountid)->isRecording (id); + */ - AccountID accountid = getAccountFromCall (id); - Recordable* rec = (Recordable*) getAccountLink (accountid)->getCall (id); + AccountID accountid = getAccountFromCall(id); + Recordable* rec = (Recordable*) getAccountLink(accountid)->getCall(id); - return rec->isRecording(); + return rec->isRecording(); } -void -ManagerImpl::startHidden (void) -{ - (getConfigString (PREFERENCES, CONFIG_START) == START_HIDDEN) ? setConfig (PREFERENCES , CONFIG_START , FALSE_STR) : setConfig (PREFERENCES , CONFIG_START , TRUE_STR); +void ManagerImpl::startHidden (void) { + (getConfigString(PREFERENCES, CONFIG_START) == START_HIDDEN) ? setConfig( + PREFERENCES, CONFIG_START, FALSE_STR) : setConfig(PREFERENCES, + CONFIG_START, TRUE_STR); } -int -ManagerImpl::isStartHidden (void) -{ - return (getConfigBool (PREFERENCES, CONFIG_START) == true) ? 1:0; +int ManagerImpl::isStartHidden (void) { + return (getConfigBool(PREFERENCES, CONFIG_START) == true) ? 1 : 0; } -void -ManagerImpl::switchPopupMode (void) -{ - (getConfigString (PREFERENCES, CONFIG_POPUP) == WINDOW_POPUP) ? setConfig (PREFERENCES, CONFIG_POPUP, FALSE_STR) : setConfig (PREFERENCES, CONFIG_POPUP, TRUE_STR); +void ManagerImpl::switchPopupMode (void) { + (getConfigString(PREFERENCES, CONFIG_POPUP) == WINDOW_POPUP) ? setConfig( + PREFERENCES, CONFIG_POPUP, FALSE_STR) : setConfig(PREFERENCES, + CONFIG_POPUP, TRUE_STR); } -void ManagerImpl::setHistoryLimit (const int& days) -{ - setConfig (PREFERENCES, CONFIG_HISTORY_LIMIT, days); +void ManagerImpl::setHistoryLimit (const int& days) { + setConfig(PREFERENCES, CONFIG_HISTORY_LIMIT, days); } -int ManagerImpl::getHistoryLimit (void) -{ - return getConfigInt (PREFERENCES , CONFIG_HISTORY_LIMIT); +int ManagerImpl::getHistoryLimit (void) { + return getConfigInt(PREFERENCES, CONFIG_HISTORY_LIMIT); } -std::string ManagerImpl::getHistoryEnabled (void) -{ - return getConfigString (PREFERENCES, CONFIG_HISTORY_ENABLED); +std::string ManagerImpl::getHistoryEnabled (void) { + return getConfigString(PREFERENCES, CONFIG_HISTORY_ENABLED); } -void ManagerImpl::setHistoryEnabled (void) -{ - (getConfigString (PREFERENCES, CONFIG_HISTORY_ENABLED) == TRUE_STR) ? setConfig (PREFERENCES, CONFIG_HISTORY_ENABLED, FALSE_STR) : setConfig (PREFERENCES, CONFIG_HISTORY_ENABLED, TRUE_STR); +void ManagerImpl::setHistoryEnabled (void) { + (getConfigString(PREFERENCES, CONFIG_HISTORY_ENABLED) == TRUE_STR) ? setConfig( + PREFERENCES, CONFIG_HISTORY_ENABLED, FALSE_STR) + : setConfig(PREFERENCES, CONFIG_HISTORY_ENABLED, TRUE_STR); } -int -ManagerImpl::getSearchbar (void) -{ - return getConfigInt (PREFERENCES , CONFIG_SEARCHBAR); +int ManagerImpl::getSearchbar (void) { + return getConfigInt(PREFERENCES, CONFIG_SEARCHBAR); } -void -ManagerImpl::setSearchbar (void) -{ - (getConfigInt (PREFERENCES , CONFIG_SEARCHBAR) == 1) ? setConfig (PREFERENCES , CONFIG_SEARCHBAR , FALSE_STR) : setConfig (PREFERENCES , CONFIG_SEARCHBAR , TRUE_STR); +void ManagerImpl::setSearchbar (void) { + (getConfigInt(PREFERENCES, CONFIG_SEARCHBAR) == 1) ? setConfig(PREFERENCES, + CONFIG_SEARCHBAR, FALSE_STR) : setConfig(PREFERENCES, + CONFIG_SEARCHBAR, TRUE_STR); } -int -ManagerImpl::popupMode (void) -{ - return (getConfigBool (PREFERENCES, CONFIG_POPUP) == true) ? 1:0 ; +int ManagerImpl::popupMode (void) { + return (getConfigBool(PREFERENCES, CONFIG_POPUP) == true) ? 1 : 0; } -int32_t -ManagerImpl::getNotify (void) -{ - return (getConfigBool (PREFERENCES , CONFIG_NOTIFY) == true) ? 1:0; +int32_t ManagerImpl::getNotify (void) { + return (getConfigBool(PREFERENCES, CONFIG_NOTIFY) == true) ? 1 : 0; } -void -ManagerImpl::setNotify (void) -{ - (getConfigString (PREFERENCES, CONFIG_NOTIFY) == NOTIFY_ALL) ? setConfig (PREFERENCES, CONFIG_NOTIFY , FALSE_STR) : setConfig (PREFERENCES, CONFIG_NOTIFY , TRUE_STR); +void ManagerImpl::setNotify (void) { + (getConfigString(PREFERENCES, CONFIG_NOTIFY) == NOTIFY_ALL) ? setConfig( + PREFERENCES, CONFIG_NOTIFY, FALSE_STR) : setConfig(PREFERENCES, + CONFIG_NOTIFY, TRUE_STR); } -int32_t -ManagerImpl::getMailNotify (void) -{ - return getConfigInt (PREFERENCES, CONFIG_MAIL_NOTIFY); +int32_t ManagerImpl::getMailNotify (void) { + return getConfigInt(PREFERENCES, CONFIG_MAIL_NOTIFY); } -void ManagerImpl::setAudioManager (const int32_t& api) -{ +void ManagerImpl::setAudioManager (const int32_t& api) { - int type; - std::string alsaPlugin; + int type; + std::string alsaPlugin; - _debug ("Setting audio manager "); + _debug ("Setting audio manager "); - if (!_audiodriver) - return; + if (!_audiodriver) + return; - type = _audiodriver->getLayerType(); + type = _audiodriver->getLayerType(); - if (type == api) { - _debug ("Audio manager chosen already in use. No changes made. "); - return; - } + if (type == api) { + _debug ("Audio manager chosen already in use. No changes made. "); + return; + } - setConfig (PREFERENCES , CONFIG_AUDIO , api) ; + setConfig(PREFERENCES, CONFIG_AUDIO, api); - switchAudioManager(); - return; + switchAudioManager(); + return; } -int32_t -ManagerImpl::getAudioManager (void) -{ - return getConfigInt (PREFERENCES , CONFIG_AUDIO); +int32_t ManagerImpl::getAudioManager (void) { + return getConfigInt(PREFERENCES, CONFIG_AUDIO); } -void -ManagerImpl::setMailNotify (void) -{ - (getConfigString (PREFERENCES , CONFIG_MAIL_NOTIFY) == NOTIFY_ALL) ? setConfig (PREFERENCES , CONFIG_MAIL_NOTIFY , FALSE_STR) : setConfig (PREFERENCES , CONFIG_MAIL_NOTIFY , TRUE_STR); +void ManagerImpl::setMailNotify (void) { + (getConfigString(PREFERENCES, CONFIG_MAIL_NOTIFY) == NOTIFY_ALL) ? setConfig( + PREFERENCES, CONFIG_MAIL_NOTIFY, FALSE_STR) + : setConfig(PREFERENCES, CONFIG_MAIL_NOTIFY, TRUE_STR); } -void -ManagerImpl::notifyErrClient (const int32_t& errCode) -{ - if (_dbus) { - _debug ("NOTIFY ERR NUMBER %i" , errCode); - _dbus -> getConfigurationManager() -> errorAlert (errCode); - } +void ManagerImpl::notifyErrClient (const int32_t& errCode) { + if (_dbus) { + _debug ("NOTIFY ERR NUMBER %i" , errCode); + _dbus -> getConfigurationManager() -> errorAlert(errCode); + } } -int -ManagerImpl::getAudioDeviceIndex (const std::string name) -{ - AlsaLayer *alsalayer; +int ManagerImpl::getAudioDeviceIndex (const std::string name) { + AlsaLayer *alsalayer; - _debug ("Get audio device index"); + _debug ("Get audio device index"); - alsalayer = dynamic_cast<AlsaLayer *> (getAudioDriver()); + alsalayer = dynamic_cast<AlsaLayer *> (getAudioDriver()); - if (alsalayer) - return alsalayer -> soundCardGetIndex (name); - else - return 0; + if (alsalayer) + return alsalayer -> soundCardGetIndex(name); + else + return 0; } -std::string -ManagerImpl::getCurrentAudioOutputPlugin (void) -{ - AlsaLayer *alsalayer; +std::string ManagerImpl::getCurrentAudioOutputPlugin (void) { + AlsaLayer *alsalayer; - _debug ("Get alsa plugin"); + _debug ("Get alsa plugin"); - alsalayer = dynamic_cast<AlsaLayer *> (getAudioDriver()); + alsalayer = dynamic_cast<AlsaLayer *> (getAudioDriver()); - if (alsalayer) return alsalayer -> getAudioPlugin (); - else return getConfigString (AUDIO , ALSA_PLUGIN); + if (alsalayer) + return alsalayer -> getAudioPlugin(); + else + return getConfigString(AUDIO, ALSA_PLUGIN); } -int ManagerImpl::app_is_running (std::string process) -{ - std::ostringstream cmd; +int ManagerImpl::app_is_running (std::string process) { + std::ostringstream cmd; - cmd << "ps -C " << process; - return system (cmd.str().c_str()); + cmd << "ps -C " << process; + return system(cmd.str().c_str()); } - /** * Initialization: Main Thread */ -bool -ManagerImpl::initAudioDriver (void) -{ - - int error; - - _debugInit ("AudioLayer Creation"); - - if (getConfigInt (PREFERENCES , CONFIG_AUDIO) == ALSA) { - _audiodriver = new AlsaLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - } else if (getConfigInt (PREFERENCES , CONFIG_AUDIO) == PULSEAUDIO) { - if (app_is_running ("pulseaudio") == 0) { - _audiodriver = new PulseLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - } else { - _audiodriver = new AlsaLayer (this); - setConfig (PREFERENCES, CONFIG_AUDIO, ALSA); - _audiodriver->setMainBuffer (&_mainBuffer); - } - } else - _debug ("Error - Audio API unknown"); - - if (_audiodriver == 0) { - _debug ("Init audio driver error"); - return false; - } else { - error = getAudioDriver()->getErrorMessage(); - - if (error == -1) { - _debug ("Init audio driver: %i", error); - return false; - } - } +bool ManagerImpl::initAudioDriver (void) { + + int error; + + _debugInit ("AudioLayer Creation"); + + if (getConfigInt(PREFERENCES, CONFIG_AUDIO) == ALSA) { + _audiodriver = new AlsaLayer(this); + _audiodriver->setMainBuffer(&_mainBuffer); + } else if (getConfigInt(PREFERENCES, CONFIG_AUDIO) == PULSEAUDIO) { + if (app_is_running("pulseaudio") == 0) { + _audiodriver = new PulseLayer(this); + _audiodriver->setMainBuffer(&_mainBuffer); + } else { + _audiodriver = new AlsaLayer(this); + setConfig(PREFERENCES, CONFIG_AUDIO, ALSA); + _audiodriver->setMainBuffer(&_mainBuffer); + } + } else + _debug ("Error - Audio API unknown"); + + if (_audiodriver == 0) { + _debug ("Init audio driver error"); + return false; + } else { + error = getAudioDriver()->getErrorMessage(); + + if (error == -1) { + _debug ("Init audio driver: %i", error); + return false; + } + } - return true; + return true; } /** * Initialization: Main Thread and gui */ -void -ManagerImpl::selectAudioDriver (void) -{ - int layer, numCardIn, numCardOut, sampleRate, frameSize; - std::string alsaPlugin; - AlsaLayer *alsalayer; - - layer = _audiodriver->getLayerType(); - _debug ("Audio layer type: %i" , layer); - - /* Retrieve the global devices info from the user config */ - alsaPlugin = getConfigString (AUDIO , ALSA_PLUGIN); - numCardIn = getConfigInt (AUDIO , ALSA_CARD_ID_IN); - numCardOut = getConfigInt (AUDIO , ALSA_CARD_ID_OUT); - sampleRate = getConfigInt (AUDIO , AUDIO_SAMPLE_RATE); - - if (sampleRate <=0 || sampleRate > 48000) { - sampleRate = 44100; - } +void ManagerImpl::selectAudioDriver (void) { + int layer, numCardIn, numCardOut, sampleRate, frameSize; + std::string alsaPlugin; + AlsaLayer *alsalayer; + + layer = _audiodriver->getLayerType(); + _debug ("Audio layer type: %i" , layer); + + /* Retrieve the global devices info from the user config */ + alsaPlugin = getConfigString(AUDIO, ALSA_PLUGIN); + numCardIn = getConfigInt(AUDIO, ALSA_CARD_ID_IN); + numCardOut = getConfigInt(AUDIO, ALSA_CARD_ID_OUT); + sampleRate = getConfigInt(AUDIO, AUDIO_SAMPLE_RATE); + + if (sampleRate <= 0 || sampleRate > 48000) { + sampleRate = 44100; + } - frameSize = getConfigInt (AUDIO , ALSA_FRAME_SIZE); + frameSize = getConfigInt(AUDIO, ALSA_FRAME_SIZE); - /* Only for the ALSA layer, we check the sound card information */ + /* Only for the ALSA layer, we check the sound card information */ - if (layer == ALSA) { - alsalayer = dynamic_cast<AlsaLayer*> (getAudioDriver ()); + if (layer == ALSA) { + alsalayer = dynamic_cast<AlsaLayer*> (getAudioDriver()); - if (!alsalayer -> soundCardIndexExist (numCardIn , SFL_PCM_CAPTURE)) { - _debug (" Card with index %i doesn't exist or cannot capture. Switch to 0.", numCardIn); - numCardIn = ALSA_DFT_CARD_ID ; - setConfig (AUDIO , ALSA_CARD_ID_IN , ALSA_DFT_CARD_ID); - } + if (!alsalayer -> soundCardIndexExist(numCardIn, SFL_PCM_CAPTURE)) { + _debug (" Card with index %i doesn't exist or cannot capture. Switch to 0.", numCardIn); + numCardIn = ALSA_DFT_CARD_ID; + setConfig(AUDIO, ALSA_CARD_ID_IN, ALSA_DFT_CARD_ID); + } - if (!alsalayer -> soundCardIndexExist (numCardOut , SFL_PCM_PLAYBACK)) { - _debug (" Card with index %i doesn't exist or cannot playback . Switch to 0.", numCardOut); - numCardOut = ALSA_DFT_CARD_ID ; - setConfig (AUDIO , ALSA_CARD_ID_OUT , ALSA_DFT_CARD_ID); - } - } + if (!alsalayer -> soundCardIndexExist(numCardOut, SFL_PCM_PLAYBACK)) { + _debug (" Card with index %i doesn't exist or cannot playback . Switch to 0.", numCardOut); + numCardOut = ALSA_DFT_CARD_ID; + setConfig(AUDIO, ALSA_CARD_ID_OUT, ALSA_DFT_CARD_ID); + } + } - _audiodriver->setErrorMessage (-1); + _audiodriver->setErrorMessage(-1); - /* Open the audio devices */ - _audiodriver->openDevice (numCardIn , numCardOut, sampleRate, frameSize, SFL_PCM_BOTH, alsaPlugin); - /* Notify the error if there is one */ + /* Open the audio devices */ + _audiodriver->openDevice(numCardIn, numCardOut, sampleRate, frameSize, + SFL_PCM_BOTH, alsaPlugin); + /* Notify the error if there is one */ - if (_audiodriver -> getErrorMessage() != -1) - notifyErrClient (_audiodriver -> getErrorMessage()); + if (_audiodriver -> getErrorMessage() != -1) + notifyErrClient(_audiodriver -> getErrorMessage()); } -void ManagerImpl::switchAudioManager (void) -{ - int type, samplerate, framesize, numCardIn, numCardOut; - std::string alsaPlugin; +void ManagerImpl::switchAudioManager (void) { + int type, samplerate, framesize, numCardIn, numCardOut; + std::string alsaPlugin; - _debug ("Switching audio manager "); + _debug ("Switching audio manager "); - if (!_audiodriver) - return; + if (!_audiodriver) + return; - type = _audiodriver->getLayerType(); + type = _audiodriver->getLayerType(); - samplerate = getConfigInt (AUDIO , AUDIO_SAMPLE_RATE); + samplerate = getConfigInt(AUDIO, AUDIO_SAMPLE_RATE); - framesize = getConfigInt (AUDIO , ALSA_FRAME_SIZE); + framesize = getConfigInt(AUDIO, ALSA_FRAME_SIZE); - _debug ("samplerate: %i, framesize %i\n", samplerate, framesize); + _debug ("samplerate: %i, framesize %i\n", samplerate, framesize); - alsaPlugin = getConfigString (AUDIO , ALSA_PLUGIN); + alsaPlugin = getConfigString(AUDIO, ALSA_PLUGIN); - numCardIn = getConfigInt (AUDIO , ALSA_CARD_ID_IN); + numCardIn = getConfigInt(AUDIO, ALSA_CARD_ID_IN); - numCardOut = getConfigInt (AUDIO , ALSA_CARD_ID_OUT); + numCardOut = getConfigInt(AUDIO, ALSA_CARD_ID_OUT); - _debug ("Deleting current layer... "); + _debug ("Deleting current layer... "); - // ost::MutexLock lock (*getAudioLayerMutex()); - getAudioLayerMutex()->enter(); + // ost::MutexLock lock (*getAudioLayerMutex()); + getAudioLayerMutex()->enter(); - // _audiodriver->closeLayer(); - delete _audiodriver; + // _audiodriver->closeLayer(); + delete _audiodriver; - _audiodriver = NULL; + _audiodriver = NULL; - switch (type) { + switch (type) { - case ALSA: - _debug ("Creating Pulseaudio layer..."); - _audiodriver = new PulseLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - break; + case ALSA: + _debug ("Creating Pulseaudio layer..."); + _audiodriver = new PulseLayer(this); + _audiodriver->setMainBuffer(&_mainBuffer); + break; - case PULSEAUDIO: - _debug ("Creating ALSA layer..."); - _audiodriver = new AlsaLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - break; + case PULSEAUDIO: + _debug ("Creating ALSA layer..."); + _audiodriver = new AlsaLayer(this); + _audiodriver->setMainBuffer(&_mainBuffer); + break; - default: - _debug ("Error: audio layer unknown"); - break; - } + default: + _debug ("Error: audio layer unknown"); + break; + } - _audiodriver->setErrorMessage (-1); + _audiodriver->setErrorMessage(-1); - _audiodriver->openDevice (numCardIn , numCardOut, samplerate, framesize, SFL_PCM_BOTH, alsaPlugin); + _audiodriver->openDevice(numCardIn, numCardOut, samplerate, framesize, + SFL_PCM_BOTH, alsaPlugin); - if (_audiodriver -> getErrorMessage() != -1) - notifyErrClient (_audiodriver -> getErrorMessage()); + if (_audiodriver -> getErrorMessage() != -1) + notifyErrClient(_audiodriver -> getErrorMessage()); - _debug ("Current device: %i ", type); + _debug ("Current device: %i ", type); - _debug ("has current call: %i ", hasCurrentCall()); + _debug ("has current call: %i ", hasCurrentCall()); - if (hasCurrentCall()) - _audiodriver->startStream(); + if (hasCurrentCall()) + _audiodriver->startStream(); - // ost::MutexLock unlock (*getAudioLayerMutex()); - getAudioLayerMutex()->leave(); + // ost::MutexLock unlock (*getAudioLayerMutex()); + getAudioLayerMutex()->leave(); - // need to stop audio streams if there is currently no call - // if ( (type != PULSEAUDIO) && (!hasCurrentCall())) { - // _debug("There is currently a call!!"); - // _audiodriver->stopStream(); + // need to stop audio streams if there is currently no call + // if ( (type != PULSEAUDIO) && (!hasCurrentCall())) { + // _debug("There is currently a call!!"); + // _audiodriver->stopStream(); - // } + // } } /** * Init the volume for speakers/micro from 0 to 100 value * Initialization: Main Thread */ -void -ManagerImpl::initVolume() -{ - _debugInit ("Initiate Volume"); - setSpkrVolume (getConfigInt (AUDIO, VOLUME_SPKR)); - setMicVolume (getConfigInt (AUDIO, VOLUME_MICRO)); +void ManagerImpl::initVolume () { + _debugInit ("Initiate Volume"); + setSpkrVolume(getConfigInt(AUDIO, VOLUME_SPKR)); + setMicVolume(getConfigInt(AUDIO, VOLUME_MICRO)); } +void ManagerImpl::setSpkrVolume (unsigned short spkr_vol) { + PulseLayer *pulselayer = NULL; -void ManagerImpl::setSpkrVolume (unsigned short spkr_vol) -{ - PulseLayer *pulselayer = NULL; + /* Set the manager sound volume */ + _spkr_volume = spkr_vol; - /* Set the manager sound volume */ - _spkr_volume = spkr_vol; + /* Only for PulseAudio */ + pulselayer = dynamic_cast<PulseLayer*> (getAudioDriver()); - /* Only for PulseAudio */ - pulselayer = dynamic_cast<PulseLayer*> (getAudioDriver()); - - if (pulselayer) { - if (pulselayer->getLayerType() == PULSEAUDIO) { - if (pulselayer) pulselayer->setPlaybackVolume (spkr_vol); - } - } + if (pulselayer) { + if (pulselayer->getLayerType() == PULSEAUDIO) { + if (pulselayer) + pulselayer->setPlaybackVolume(spkr_vol); + } + } } - -void ManagerImpl::setMicVolume (unsigned short mic_vol) -{ - _mic_volume = mic_vol; +void ManagerImpl::setMicVolume (unsigned short mic_vol) { + _mic_volume = mic_vol; } - - - -int ManagerImpl::getLocalIp2IpPort (void) -{ - // The SIP port used for default account (IP to IP) calls= - return getConfigInt (IP2IP_PROFILE, LOCAL_PORT); +int ManagerImpl::getLocalIp2IpPort (void) { + // The SIP port used for default account (IP to IP) calls= + return getConfigInt(IP2IP_PROFILE, LOCAL_PORT); } - // TODO: rewrite this /** * Main Thread */ -bool -ManagerImpl::getCallStatus (const std::string& sequenceId UNUSED) -{ - if (!_dbus) { - return false; - } - - ost::MutexLock m (_callAccountMapMutex); - - CallAccountMap::iterator iter = _callAccountMap.begin(); - TokenList tk; - std::string code; - std::string status; - std::string destination; - std::string number; - - while (iter != _callAccountMap.end()) { - Call* call = getAccountLink (iter->second)->getCall (iter->first); - Call::ConnectionState state = call->getConnectionState(); - - if (state != Call::Connected) { - switch (state) { - - case Call::Trying: - code="110"; - status = "Trying"; - break; - - case Call::Ringing: - code="111"; - status = "Ringing"; - break; - - case Call::Progressing: - code="125"; - status = "Progressing"; - break; - - case Call::Disconnected: - code="125"; - status = "Disconnected"; - break; - - default: - code=""; - status= ""; - } - } else { - switch (call->getState()) { - - case Call::Active: - - case Call::Conferencing: - code="112"; - status = "Established"; - break; - - case Call::Hold: - code="114"; - status = "Held"; - break; - - case Call::Busy: - code="113"; - status = "Busy"; - break; - - case Call::Refused: - code="125"; - status = "Refused"; - break; - - case Call::Error: - code="125"; - status = "Error"; - break; - - case Call::Inactive: - code="125"; - status = "Inactive"; - break; - } - } - - // No Congestion - // No Wrong Number - // 116 <CSeq> <call-id> <acc> <destination> Busy - destination = call->getPeerName(); - - number = call->getPeerNumber(); - - if (number!="") { - destination.append (" <"); - destination.append (number); - destination.append (">"); - } - - tk.push_back (iter->second); - - tk.push_back (destination); - tk.push_back (status); - tk.clear(); - - iter++; - } - - return true; +bool ManagerImpl::getCallStatus (const std::string& sequenceId UNUSED) { + if (!_dbus) { + return false; + } + + ost::MutexLock m(_callAccountMapMutex); + + CallAccountMap::iterator iter = _callAccountMap.begin(); + TokenList tk; + std::string code; + std::string status; + std::string destination; + std::string number; + + while (iter != _callAccountMap.end()) { + Call* call = getAccountLink(iter->second)->getCall(iter->first); + Call::ConnectionState state = call->getConnectionState(); + + if (state != Call::Connected) { + switch (state) { + + case Call::Trying: + code = "110"; + status = "Trying"; + break; + + case Call::Ringing: + code = "111"; + status = "Ringing"; + break; + + case Call::Progressing: + code = "125"; + status = "Progressing"; + break; + + case Call::Disconnected: + code = "125"; + status = "Disconnected"; + break; + + default: + code = ""; + status = ""; + } + } else { + switch (call->getState()) { + + case Call::Active: + + case Call::Conferencing: + code = "112"; + status = "Established"; + break; + + case Call::Hold: + code = "114"; + status = "Held"; + break; + + case Call::Busy: + code = "113"; + status = "Busy"; + break; + + case Call::Refused: + code = "125"; + status = "Refused"; + break; + + case Call::Error: + code = "125"; + status = "Error"; + break; + + case Call::Inactive: + code = "125"; + status = "Inactive"; + break; + } + } + + // No Congestion + // No Wrong Number + // 116 <CSeq> <call-id> <acc> <destination> Busy + destination = call->getPeerName(); + + number = call->getPeerNumber(); + + if (number != "") { + destination.append(" <"); + destination.append(number); + destination.append(">"); + } + + tk.push_back(iter->second); + + tk.push_back(destination); + tk.push_back(status); + tk.clear(); + + iter++; + } + + return true; } //THREAD=Main -bool -ManagerImpl::getConfig (const std::string& section, const std::string& name, TokenList& arg) -{ - return _config.getConfigTreeItemToken (section, name, arg); +bool ManagerImpl::getConfig (const std::string& section, + const std::string& name, TokenList& arg) { + return _config.getConfigTreeItemToken(section, name, arg); } //THREAD=Main // throw an Conf::ConfigTreeItemException if not found -int -ManagerImpl::getConfigInt (const std::string& section, const std::string& name) -{ - try { - return _config.getConfigTreeItemIntValue (section, name); - } catch (Conf::ConfigTreeItemException& e) { - throw e; - } +int ManagerImpl::getConfigInt (const std::string& section, + const std::string& name) { + try { + return _config.getConfigTreeItemIntValue(section, name); + } catch (Conf::ConfigTreeItemException& e) { + throw e; + } - return 0; + return 0; } -bool -ManagerImpl::getConfigBool (const std::string& section, const std::string& name) -{ - try { - return (_config.getConfigTreeItemValue (section, name) == TRUE_STR) ? true:false; - } catch (Conf::ConfigTreeItemException& e) { - throw e; - } +bool ManagerImpl::getConfigBool (const std::string& section, + const std::string& name) { + try { + return (_config.getConfigTreeItemValue(section, name) == TRUE_STR) ? true + : false; + } catch (Conf::ConfigTreeItemException& e) { + throw e; + } - return false; + return false; } //THREAD=Main -std::string -ManagerImpl::getConfigString (const std::string& section, const std::string& - name) -{ - try { - return _config.getConfigTreeItemValue (section, name); - } catch (Conf::ConfigTreeItemException& e) { - throw e; - } +std::string ManagerImpl::getConfigString (const std::string& section, + const std::string& name) { + try { + return _config.getConfigTreeItemValue(section, name); + } catch (Conf::ConfigTreeItemException& e) { + throw e; + } - return ""; + return ""; } //THREAD=Main -bool -ManagerImpl::setConfig (const std::string& section, const std::string& name, const std::string& value) -{ - _debug ("ManagerImpl::setConfig %s %s %s", section.c_str(), name.c_str(), value.c_str()); - return _config.setConfigTreeItem (section, name, value); +bool ManagerImpl::setConfig (const std::string& section, + const std::string& name, const std::string& value) { + _debug ("ManagerImpl::setConfig %s %s %s", section.c_str(), name.c_str(), value.c_str()); + return _config.setConfigTreeItem(section, name, value); } //THREAD=Main -bool -ManagerImpl::setConfig (const std::string& section, const std::string& name, int value) -{ - std::ostringstream valueStream; - valueStream << value; - return _config.setConfigTreeItem (section, name, valueStream.str()); +bool ManagerImpl::setConfig (const std::string& section, + const std::string& name, int value) { + std::ostringstream valueStream; + valueStream << value; + return _config.setConfigTreeItem(section, name, valueStream.str()); } -void ManagerImpl::setAccountsOrder (const std::string& order) -{ - _debug ("Setcreate accounts order : %s", order.c_str()); - // Set the new config - setConfig (PREFERENCES, CONFIG_ACCOUNTS_ORDER, order); +void ManagerImpl::setAccountsOrder (const std::string& order) { + _debug ("Setcreate accounts order : %s", order.c_str()); + // Set the new config + setConfig(PREFERENCES, CONFIG_ACCOUNTS_ORDER, order); } -std::vector< std::string > ManagerImpl::getAccountList() { +std::vector<std::string> ManagerImpl::getAccountList () { - std::vector< std::string > v; - std::vector< std::string > account_order; - unsigned int i; + std::vector<std::string> v; + std::vector<std::string> account_order; + unsigned int i; - account_order = loadAccountOrder (); - AccountMap::iterator iter; + account_order = loadAccountOrder(); + AccountMap::iterator iter; // The IP2IP profile is always available, and first in the list - iter = _accountMap.find (IP2IP_PROFILE); + iter = _accountMap.find(IP2IP_PROFILE); if (iter->second != NULL) - v.push_back (iter->first.data ()); - - // If no order has been set, load the default one - // ie according to the creation date. - - if (account_order.size () == 0) { - iter = _accountMap.begin (); - - while (iter != _accountMap.end()) { - - if (iter->second != NULL && iter->first != IP2IP_PROFILE) { - //_debug("PUSHING BACK %s\n", iter->first.c_str()); - v.push_back (iter->first.data()); - } - - iter++; - } - } - - // Otherelse, load the custom one - // ie according to the saved order - else { - - for (i=0; i<account_order.size (); i++) { - // This account has not been loaded, so we ignore it - if ( (iter=_accountMap.find (account_order[i])) != _accountMap.end()) { - // If the account is valid - if (iter->second != NULL && iter->first != IP2IP_PROFILE) { - v.push_back (iter->first.data ()); - } - } - } - } - - return v; -} - -std::map< std::string, std::string > ManagerImpl::getAccountDetails (const AccountID& accountID) -{ - std::map<std::string, std::string> a; - - Account * account = _accountMap[accountID]; - - if (account == NULL) { - _debug ("Cannot getAccountDetails on a non-existing accountID %s. Defaults will be used.", accountID.c_str()); - } - - - a.insert (std::pair<std::string, std::string> (ACCOUNT_ID, accountID)); - - // The IP profile does not allow to set an alias - (accountID == IP2IP_PROFILE) ? a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, DIRECT_IP_CALL)) : a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ALIAS, getConfigString (accountID, CONFIG_ACCOUNT_ALIAS))); - - a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_ENABLE, getConfigString (accountID, CONFIG_ACCOUNT_ENABLE))); - a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_RESOLVE_ONCE, getConfigString (accountID, CONFIG_ACCOUNT_RESOLVE_ONCE))); - a.insert (std::pair<std::string, std::string> (CONFIG_ACCOUNT_TYPE, getConfigString (accountID, CONFIG_ACCOUNT_TYPE))); - a.insert (std::pair<std::string, std::string> (HOSTNAME, getConfigString (accountID, HOSTNAME))); - a.insert (std::pair<std::string, std::string> (USERNAME, getConfigString (accountID, USERNAME))); - a.insert (std::pair<std::string, std::string> (PASSWORD, getConfigString (accountID, PASSWORD))); - a.insert (std::pair<std::string, std::string> (REALM, getConfigString (accountID, REALM))); - a.insert (std::pair<std::string, std::string> (USERAGENT, getConfigString (accountID, USERAGENT))); - 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> (PUBLISHED_ADDRESS, getConfigString (accountID, PUBLISHED_ADDRESS))); - a.insert (std::pair<std::string, std::string> (LOCAL_PORT, getConfigString (accountID, LOCAL_PORT))); - a.insert (std::pair<std::string, std::string> (PUBLISHED_PORT, getConfigString (accountID, PUBLISHED_PORT))); - a.insert (std::pair<std::string, std::string> (DISPLAY_NAME, getConfigString (accountID, DISPLAY_NAME))); - a.insert (std::pair<std::string, std::string> (STUN_ENABLE, getConfigString (accountID, STUN_ENABLE))); - a.insert (std::pair<std::string, std::string> (STUN_SERVER, getConfigString (accountID, STUN_SERVER))); - - RegistrationState state; - std::string registrationStateCode; - std::string registrationStateDescription; - - if (account != NULL) { + v.push_back(iter->first.data()); + + // If no order has been set, load the default one + // ie according to the creation date. + + if (account_order.size() == 0) { + iter = _accountMap.begin(); + + while (iter != _accountMap.end()) { + + if (iter->second != NULL && iter->first != IP2IP_PROFILE) { + //_debug("PUSHING BACK %s\n", iter->first.c_str()); + v.push_back(iter->first.data()); + } + + iter++; + } + } + + // Otherelse, load the custom one + // ie according to the saved order + else { + + for (i = 0; i < account_order.size(); i++) { + // This account has not been loaded, so we ignore it + if ((iter = _accountMap.find(account_order[i])) + != _accountMap.end()) { + // If the account is valid + if (iter->second != NULL && iter->first != IP2IP_PROFILE) { + v.push_back(iter->first.data()); + } + } + } + } + + return v; +} + +std::map<std::string, std::string> ManagerImpl::getAccountDetails ( + const AccountID& accountID) { + std::map<std::string, std::string> a; + + Account * account = _accountMap[accountID]; + + if (account == NULL) { + _debug ("Cannot getAccountDetails on a non-existing accountID %s. Defaults will be used.", accountID.c_str()); + } + + a.insert(std::pair<std::string, std::string>(ACCOUNT_ID, accountID)); + + // The IP profile does not allow to set an alias + (accountID == IP2IP_PROFILE) ? a.insert( + std::pair<std::string, std::string>(CONFIG_ACCOUNT_ALIAS, + DIRECT_IP_CALL)) : a.insert(std::pair<std::string, + std::string>(CONFIG_ACCOUNT_ALIAS, getConfigString(accountID, + CONFIG_ACCOUNT_ALIAS))); + + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_ENABLE, + getConfigString(accountID, CONFIG_ACCOUNT_ENABLE))); + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_RESOLVE_ONCE, + getConfigString(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE))); + a.insert(std::pair<std::string, std::string>(CONFIG_ACCOUNT_TYPE, + getConfigString(accountID, CONFIG_ACCOUNT_TYPE))); + a.insert(std::pair<std::string, std::string>(HOSTNAME, getConfigString( + accountID, HOSTNAME))); + a.insert(std::pair<std::string, std::string>(USERNAME, getConfigString( + accountID, USERNAME))); + a.insert(std::pair<std::string, std::string>(PASSWORD, getConfigString( + accountID, PASSWORD))); + a.insert(std::pair<std::string, std::string>(REALM, getConfigString( + accountID, REALM))); + a.insert(std::pair<std::string, std::string>(USERAGENT, getConfigString( + accountID, USERAGENT))); + 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>(PUBLISHED_ADDRESS, + getConfigString(accountID, PUBLISHED_ADDRESS))); + a.insert(std::pair<std::string, std::string>(LOCAL_PORT, getConfigString( + accountID, LOCAL_PORT))); + a.insert(std::pair<std::string, std::string>(PUBLISHED_PORT, + getConfigString(accountID, PUBLISHED_PORT))); + a.insert(std::pair<std::string, std::string>(DISPLAY_NAME, getConfigString( + accountID, DISPLAY_NAME))); + a.insert(std::pair<std::string, std::string>(STUN_ENABLE, getConfigString( + accountID, STUN_ENABLE))); + a.insert(std::pair<std::string, std::string>(STUN_SERVER, getConfigString( + accountID, STUN_SERVER))); + + RegistrationState state; + std::string registrationStateCode; + std::string registrationStateDescription; + + if (account != NULL) { if (accountID == IP2IP_PROFILE) { registrationStateCode = EMPTY_FIELD; registrationStateDescription = "Direct IP call"; - } - else { + } else { state = account->getRegistrationState(); int code = account->getRegistrationStateDetailed().first; std::stringstream out; out << code; registrationStateCode = out.str(); - registrationStateDescription = account->getRegistrationStateDetailed().second; + registrationStateDescription + = account->getRegistrationStateDetailed().second; } - } else { - state = Unregistered; - } - - (accountID == IP2IP_PROFILE) ? a.insert (std::pair<std::string, std::string> (REGISTRATION_STATUS, "READY")) : - a.insert (std::pair<std::string, std::string> (REGISTRATION_STATUS, mapStateNumberToString (state))); - - a.insert (std::pair<std::string, std::string> (REGISTRATION_STATE_CODE, registrationStateCode)); - a.insert (std::pair<std::string, std::string> (REGISTRATION_STATE_DESCRIPTION, registrationStateDescription)); - a.insert (std::pair<std::string, std::string> (SRTP_KEY_EXCHANGE, getConfigString (accountID, SRTP_KEY_EXCHANGE))); - a.insert (std::pair<std::string, std::string> (SRTP_ENABLE, getConfigString (accountID, SRTP_ENABLE))); - a.insert (std::pair<std::string, std::string> (SRTP_RTP_FALLBACK, getConfigString (accountID, SRTP_RTP_FALLBACK))); - a.insert (std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS, getConfigString (accountID, ZRTP_DISPLAY_SAS))); - a.insert (std::pair<std::string, std::string> (ZRTP_DISPLAY_SAS_ONCE, getConfigString (accountID, ZRTP_DISPLAY_SAS_ONCE))); - a.insert (std::pair<std::string, std::string> (ZRTP_HELLO_HASH, getConfigString (accountID, ZRTP_HELLO_HASH))); - a.insert (std::pair<std::string, std::string> (ZRTP_NOT_SUPP_WARNING, getConfigString (accountID, ZRTP_NOT_SUPP_WARNING))); - - - // TLS listener is unique and parameters are modified through IP2IP_PROFILE - a.insert (std::pair<std::string, std::string> (TLS_LISTENER_PORT, Manager::instance().getConfigString(IP2IP_PROFILE, TLS_LISTENER_PORT))); - a.insert (std::pair<std::string, std::string> (TLS_ENABLE, Manager::instance().getConfigString (accountID, TLS_ENABLE))); - a.insert (std::pair<std::string, std::string> (TLS_CA_LIST_FILE, Manager::instance().getConfigString (accountID, TLS_CA_LIST_FILE))); - a.insert (std::pair<std::string, std::string> (TLS_CERTIFICATE_FILE, Manager::instance().getConfigString (accountID, TLS_CERTIFICATE_FILE))); - a.insert (std::pair<std::string, std::string> (TLS_PRIVATE_KEY_FILE, Manager::instance().getConfigString (accountID, TLS_PRIVATE_KEY_FILE))); - a.insert (std::pair<std::string, std::string> (TLS_PASSWORD, Manager::instance().getConfigString (accountID, TLS_PASSWORD))); - a.insert (std::pair<std::string, std::string> (TLS_METHOD, Manager::instance().getConfigString (accountID, TLS_METHOD))); - a.insert (std::pair<std::string, std::string> (TLS_CIPHERS, Manager::instance().getConfigString (accountID, TLS_CIPHERS))); - a.insert (std::pair<std::string, std::string> (TLS_SERVER_NAME, Manager::instance().getConfigString (accountID, TLS_SERVER_NAME))); - a.insert (std::pair<std::string, std::string> (TLS_VERIFY_SERVER, Manager::instance().getConfigString (accountID, TLS_VERIFY_SERVER))); - a.insert (std::pair<std::string, std::string> (TLS_VERIFY_CLIENT, Manager::instance().getConfigString (accountID, TLS_VERIFY_CLIENT))); - a.insert (std::pair<std::string, std::string> (TLS_REQUIRE_CLIENT_CERTIFICATE, Manager::instance().getConfigString (accountID, TLS_REQUIRE_CLIENT_CERTIFICATE))); - a.insert (std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_SEC, Manager::instance().getConfigString (accountID, TLS_NEGOTIATION_TIMEOUT_SEC))); - a.insert (std::pair<std::string, std::string> (TLS_NEGOTIATION_TIMEOUT_MSEC, Manager::instance().getConfigString (accountID, TLS_NEGOTIATION_TIMEOUT_MSEC))); - - return a; + } else { + state = Unregistered; + } + + (accountID == IP2IP_PROFILE) ? a.insert( + std::pair<std::string, std::string>(REGISTRATION_STATUS, "READY")) + : a.insert(std::pair<std::string, std::string>(REGISTRATION_STATUS, + mapStateNumberToString(state))); + + a.insert(std::pair<std::string, std::string>(REGISTRATION_STATE_CODE, + registrationStateCode)); + a.insert(std::pair<std::string, std::string>( + REGISTRATION_STATE_DESCRIPTION, registrationStateDescription)); + a.insert(std::pair<std::string, std::string>(SRTP_KEY_EXCHANGE, + getConfigString(accountID, SRTP_KEY_EXCHANGE))); + a.insert(std::pair<std::string, std::string>(SRTP_ENABLE, getConfigString( + accountID, SRTP_ENABLE))); + a.insert(std::pair<std::string, std::string>(SRTP_RTP_FALLBACK, + getConfigString(accountID, SRTP_RTP_FALLBACK))); + a.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS, + getConfigString(accountID, ZRTP_DISPLAY_SAS))); + a.insert(std::pair<std::string, std::string>(ZRTP_DISPLAY_SAS_ONCE, + getConfigString(accountID, ZRTP_DISPLAY_SAS_ONCE))); + a.insert(std::pair<std::string, std::string>(ZRTP_HELLO_HASH, + getConfigString(accountID, ZRTP_HELLO_HASH))); + a.insert(std::pair<std::string, std::string>(ZRTP_NOT_SUPP_WARNING, + getConfigString(accountID, ZRTP_NOT_SUPP_WARNING))); + + // TLS listener is unique and parameters are modified through IP2IP_PROFILE + a.insert(std::pair<std::string, std::string>(TLS_LISTENER_PORT, + Manager::instance().getConfigString(IP2IP_PROFILE, + TLS_LISTENER_PORT))); + a.insert(std::pair<std::string, std::string>(TLS_ENABLE, + Manager::instance().getConfigString(accountID, TLS_ENABLE))); + a.insert(std::pair<std::string, std::string>(TLS_CA_LIST_FILE, + Manager::instance().getConfigString(accountID, TLS_CA_LIST_FILE))); + a.insert( + std::pair<std::string, std::string>(TLS_CERTIFICATE_FILE, + Manager::instance().getConfigString(accountID, + TLS_CERTIFICATE_FILE))); + a.insert( + std::pair<std::string, std::string>(TLS_PRIVATE_KEY_FILE, + Manager::instance().getConfigString(accountID, + TLS_PRIVATE_KEY_FILE))); + a.insert(std::pair<std::string, std::string>(TLS_PASSWORD, + Manager::instance().getConfigString(accountID, TLS_PASSWORD))); + a.insert(std::pair<std::string, std::string>(TLS_METHOD, + Manager::instance().getConfigString(accountID, TLS_METHOD))); + a.insert(std::pair<std::string, std::string>(TLS_CIPHERS, + Manager::instance().getConfigString(accountID, TLS_CIPHERS))); + a.insert(std::pair<std::string, std::string>(TLS_SERVER_NAME, + Manager::instance().getConfigString(accountID, TLS_SERVER_NAME))); + a.insert(std::pair<std::string, std::string>(TLS_VERIFY_SERVER, + Manager::instance().getConfigString(accountID, TLS_VERIFY_SERVER))); + a.insert(std::pair<std::string, std::string>(TLS_VERIFY_CLIENT, + Manager::instance().getConfigString(accountID, TLS_VERIFY_CLIENT))); + a.insert(std::pair<std::string, std::string>( + TLS_REQUIRE_CLIENT_CERTIFICATE, + Manager::instance().getConfigString(accountID, + TLS_REQUIRE_CLIENT_CERTIFICATE))); + a.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_SEC, + Manager::instance().getConfigString(accountID, + TLS_NEGOTIATION_TIMEOUT_SEC))); + a.insert(std::pair<std::string, std::string>(TLS_NEGOTIATION_TIMEOUT_MSEC, + Manager::instance().getConfigString(accountID, + TLS_NEGOTIATION_TIMEOUT_MSEC))); + + return a; } /* Transform digest to string. @@ -3453,1041 +3387,1055 @@ std::map< std::string, std::string > ManagerImpl::getAccountDetails (const Accou * NOTE: THE OUTPUT STRING IS NOT NULL TERMINATED! */ -void ManagerImpl::digest2str (const unsigned char digest[], char *output) -{ - int i; +void ManagerImpl::digest2str (const unsigned char digest[], char *output) { + int i; - for (i = 0; i<16; ++i) { - pj_val_to_hex_digit (digest[i], output); - output += 2; - } + for (i = 0; i < 16; ++i) { + pj_val_to_hex_digit(digest[i], output); + output += 2; + } } -std::string ManagerImpl::computeMd5HashFromCredential (const std::string& username, const std::string& password, const std::string& realm) -{ - pj_md5_context pms; - unsigned char digest[16]; - char ha1[PJSIP_MD5STRLEN]; +std::string ManagerImpl::computeMd5HashFromCredential ( + const std::string& username, const std::string& password, + const std::string& realm) { + pj_md5_context pms; + unsigned char digest[16]; + char ha1[PJSIP_MD5STRLEN]; - pj_str_t usernamePjFormat = pj_str (strdup (username.c_str())); - pj_str_t passwordPjFormat = pj_str (strdup (password.c_str())); - pj_str_t realmPjFormat = pj_str (strdup (realm.c_str())); + pj_str_t usernamePjFormat = pj_str(strdup(username.c_str())); + pj_str_t passwordPjFormat = pj_str(strdup(password.c_str())); + pj_str_t realmPjFormat = pj_str(strdup(realm.c_str())); - /* Compute md5 hash = MD5(username ":" realm ":" password) */ - pj_md5_init (&pms); - MD5_APPEND (&pms, usernamePjFormat.ptr, usernamePjFormat.slen); - MD5_APPEND (&pms, ":", 1); - MD5_APPEND (&pms, realmPjFormat.ptr, realmPjFormat.slen); - MD5_APPEND (&pms, ":", 1); - MD5_APPEND (&pms, passwordPjFormat.ptr, passwordPjFormat.slen); - pj_md5_final (&pms, digest); + /* Compute md5 hash = MD5(username ":" realm ":" password) */ + pj_md5_init(&pms); + MD5_APPEND (&pms, usernamePjFormat.ptr, usernamePjFormat.slen); + MD5_APPEND (&pms, ":", 1); + MD5_APPEND (&pms, realmPjFormat.ptr, realmPjFormat.slen); + MD5_APPEND (&pms, ":", 1); + MD5_APPEND (&pms, passwordPjFormat.ptr, passwordPjFormat.slen); + pj_md5_final(&pms, digest); - digest2str (digest, ha1); + digest2str(digest, ha1); - char ha1_null_terminated[PJSIP_MD5STRLEN+1]; - memcpy (ha1_null_terminated, ha1, sizeof (char) *PJSIP_MD5STRLEN); - ha1_null_terminated[PJSIP_MD5STRLEN] = '\0'; + char ha1_null_terminated[PJSIP_MD5STRLEN + 1]; + memcpy(ha1_null_terminated, ha1, sizeof(char) * PJSIP_MD5STRLEN); + ha1_null_terminated[PJSIP_MD5STRLEN] = '\0'; - std::string hashedDigest = ha1_null_terminated; - return hashedDigest; + std::string hashedDigest = ha1_null_terminated; + return hashedDigest; } -void ManagerImpl::setCredential (const std::string& accountID, const int32_t& index, const std::map< std::string, std::string >& details) -{ - std::map<std::string, std::string>::iterator it; - std::map<std::string, std::string> credentialInformation = details; - - std::string credentialIndex; - std::stringstream streamOut; - streamOut << index; - credentialIndex = streamOut.str(); +void ManagerImpl::setCredential (const std::string& accountID, + const int32_t& index, const std::map<std::string, std::string>& details) { + std::map<std::string, std::string>::iterator it; + std::map<std::string, std::string> credentialInformation = details; - std::string section = "Credential" + std::string (":") + accountID + std::string (":") + credentialIndex; + std::string credentialIndex; + std::stringstream streamOut; + streamOut << index; + credentialIndex = streamOut.str(); - _debug ("Setting credential in section %s", section.c_str()); + std::string section = "Credential" + std::string(":") + accountID + + std::string(":") + credentialIndex; - it = credentialInformation.find (USERNAME); - std::string username; + _debug ("Setting credential in section %s", section.c_str()); - if (it == credentialInformation.end()) { - username = EMPTY_FIELD; - } else { - username = it->second; - } + it = credentialInformation.find(USERNAME); + std::string username; - Manager::instance().setConfig (section, USERNAME, username); - - it = credentialInformation.find (REALM); - std::string realm; + if (it == credentialInformation.end()) { + username = EMPTY_FIELD; + } else { + username = it->second; + } - if (it == credentialInformation.end()) { - realm = EMPTY_FIELD; - } else { - realm = it->second; - } + Manager::instance().setConfig(section, USERNAME, username); - Manager::instance().setConfig (section, REALM, realm); + it = credentialInformation.find(REALM); + std::string realm; + if (it == credentialInformation.end()) { + realm = EMPTY_FIELD; + } else { + realm = it->second; + } - it = credentialInformation.find (PASSWORD); - std::string password; + Manager::instance().setConfig(section, REALM, realm); - if (it == credentialInformation.end()) { - password = EMPTY_FIELD; - } else { - password = it->second; - } + it = credentialInformation.find(PASSWORD); + std::string password; - if (getMd5CredentialHashing()) { - // TODO: Fix this. - // This is an extremly weak test in order to check - // if the password is a hashed value. This is done - // because deleteCredential() is called before this - // method. Therefore, we cannot check if the value - // is different from the one previously stored in - // the configuration file. This is to avoid to - // re-hash a hashed password. + if (it == credentialInformation.end()) { + password = EMPTY_FIELD; + } else { + password = it->second; + } - if (password.length() != 32) { - password = computeMd5HashFromCredential (username, password, realm); - } - } + if (getMd5CredentialHashing()) { + // TODO: Fix this. + // This is an extremly weak test in order to check + // if the password is a hashed value. This is done + // because deleteCredential() is called before this + // method. Therefore, we cannot check if the value + // is different from the one previously stored in + // the configuration file. This is to avoid to + // re-hash a hashed password. + + if (password.length() != 32) { + password = computeMd5HashFromCredential(username, password, realm); + } + } - Manager::instance().setConfig (section, PASSWORD, password); + Manager::instance().setConfig(section, PASSWORD, password); } //TODO: tidy this up. Make a macro or inline // method to reduce the if/else mess. // Even better, switch to XML ! -void ManagerImpl::setAccountDetails (const std::string& accountID, const std::map< std::string, std::string >& details) -{ +void ManagerImpl::setAccountDetails (const std::string& accountID, + const std::map<std::string, std::string>& details) { - std::string accountType; - std::map <std::string, std::string> map_cpy; - std::map<std::string, std::string>::iterator iter; + std::string accountType; + std::map<std::string, std::string> map_cpy; + std::map<std::string, std::string>::iterator iter; - // Work on a copy - map_cpy = details; + // Work on a copy + map_cpy = details; - std::string username; - std::string authenticationName; - std::string password; - std::string realm; - std::string voicemail_count; + std::string username; + std::string authenticationName; + std::string password; + std::string realm; + std::string voicemail_count; std::string ua_name; - if ( (iter = map_cpy.find (AUTHENTICATION_USERNAME)) != map_cpy.end()) { - authenticationName = iter->second; - } - - if ( (iter = map_cpy.find (USERNAME)) != map_cpy.end()) { - username = iter->second; - } - - if ( (iter = map_cpy.find (PASSWORD)) != map_cpy.end()) { - password = iter->second; - } - - if ( (iter = map_cpy.find (REALM)) != map_cpy.end()) { - realm = iter->second; - } - - if ( (iter = map_cpy.find (USERAGENT)) != map_cpy.end()) { - ua_name = iter->second; - } - - setConfig (accountID, REALM, realm); - setConfig (accountID, USERAGENT, ua_name); - setConfig (accountID, USERNAME, username); - setConfig (accountID, AUTHENTICATION_USERNAME, authenticationName); - - if (!getMd5CredentialHashing()) { - setConfig (accountID, PASSWORD, password); - } else { - // Make sure not to re-hash the password field if - // it is already saved as a MD5 Hash. - // TODO: This test is weak. Fix this. - if ( (password.compare (getConfigString (accountID, PASSWORD)) != 0)) { - _debug ("Password sent and password from config are different. Re-hashing"); - std::string hash; - - if (authenticationName.empty()) { - hash = computeMd5HashFromCredential (username, password, realm); - } else { - hash = computeMd5HashFromCredential (authenticationName, password, realm); - } - - setConfig (accountID, PASSWORD, hash); - } - } - - std::string alias; - - std::string mailbox; - std::string accountEnable; - std::string type; - std::string resolveOnce; - std::string registrationExpire; - - std::string hostname; - std::string displayName; - std::string localInterface; - std::string publishedSameasLocal; - std::string localAddress; - std::string publishedAddress; - std::string localPort; - std::string publishedPort; - std::string stunEnable; - std::string stunServer; - std::string srtpEnable; - std::string srtpRtpFallback; - std::string zrtpDisplaySas; - std::string zrtpDisplaySasOnce; - std::string zrtpNotSuppWarning; - std::string zrtpHelloHash; - std::string srtpKeyExchange; - - std::string tlsListenerPort; - std::string tlsEnable; - std::string tlsCaListFile; - std::string tlsCertificateFile; - std::string tlsPrivateKeyFile; - std::string tlsPassword; - std::string tlsMethod; - std::string tlsCiphers; - std::string tlsServerName; - std::string tlsVerifyServer; - std::string tlsVerifyClient; - std::string tlsRequireClientCertificate; - std::string tlsNegotiationTimeoutSec; - std::string tlsNegotiationTimeoutMsec; - - if ( (iter = map_cpy.find (HOSTNAME)) != map_cpy.end()) { - hostname = iter->second; - } - - if ( (iter = map_cpy.find (DISPLAY_NAME)) != map_cpy.end()) { - displayName = iter->second; - } - - if ( (iter = map_cpy.find (LOCAL_INTERFACE)) != map_cpy.end()) { - localInterface = iter->second; - } - - if ( (iter = map_cpy.find (PUBLISHED_SAMEAS_LOCAL)) != map_cpy.end()) { - publishedSameasLocal = iter->second; - } - - if ( (iter = map_cpy.find (PUBLISHED_ADDRESS)) != map_cpy.end()) { - publishedAddress = iter->second; - } - - if ( (iter = map_cpy.find (LOCAL_PORT)) != map_cpy.end()) { - localPort = iter->second; - } - - if ( (iter = map_cpy.find (PUBLISHED_PORT)) != map_cpy.end()) { - publishedPort = iter->second; - } - - if ( (iter = map_cpy.find (STUN_ENABLE)) != map_cpy.end()) { - stunEnable = iter->second; - } - - if ( (iter = map_cpy.find (STUN_SERVER)) != map_cpy.end()) { - stunServer = iter->second; - } - - if ( (iter = map_cpy.find (SRTP_ENABLE)) != map_cpy.end()) { - srtpEnable = iter->second; - } - - if ( (iter = map_cpy.find (SRTP_RTP_FALLBACK)) != map_cpy.end()) { - srtpRtpFallback = iter->second; - } - - if ( (iter = map_cpy.find (ZRTP_DISPLAY_SAS)) != map_cpy.end()) { - zrtpDisplaySas = iter->second; - } - - if ( (iter = map_cpy.find (ZRTP_DISPLAY_SAS_ONCE)) != map_cpy.end()) { - zrtpDisplaySasOnce = iter->second; - } - - if ( (iter = map_cpy.find (ZRTP_NOT_SUPP_WARNING)) != map_cpy.end()) { - zrtpNotSuppWarning = iter->second; - } - - if ( (iter = map_cpy.find (ZRTP_HELLO_HASH)) != map_cpy.end()) { - zrtpHelloHash = iter->second; - } - - if ( (iter = map_cpy.find (SRTP_KEY_EXCHANGE)) != map_cpy.end()) { - srtpKeyExchange = iter->second; - } - - if ( (iter = map_cpy.find (CONFIG_ACCOUNT_ALIAS)) != map_cpy.end()) { - alias = iter->second; - } - - if ( (iter = map_cpy.find (CONFIG_ACCOUNT_MAILBOX)) != map_cpy.end()) { - mailbox = iter->second; - } - - if ( (iter = map_cpy.find (CONFIG_ACCOUNT_ENABLE)) != map_cpy.end()) { - accountEnable = iter->second; - } - - if ( (iter = map_cpy.find (CONFIG_ACCOUNT_TYPE)) != map_cpy.end()) { - type = iter->second; - } - - if ( (iter = map_cpy.find (CONFIG_ACCOUNT_RESOLVE_ONCE)) != map_cpy.end()) { - resolveOnce = iter->second; - } - - if ( (iter = map_cpy.find (CONFIG_ACCOUNT_REGISTRATION_EXPIRE)) != map_cpy.end()) { - registrationExpire = iter->second; - } - - // The TLS listener is unique and globally defined through IP2IP_PROFILE - if((accountID == IP2IP_PROFILE) && (iter = map_cpy.find (TLS_LISTENER_PORT)) != map_cpy.end()) { - tlsListenerPort = iter->second; - } - - if ( (iter = map_cpy.find (TLS_ENABLE)) != map_cpy.end()) { - tlsEnable = iter->second; - } - - if ( (iter = map_cpy.find (TLS_CA_LIST_FILE)) != map_cpy.end()) { - tlsCaListFile = iter->second; - } - - if ( (iter = map_cpy.find (TLS_CERTIFICATE_FILE)) != map_cpy.end()) { - tlsCertificateFile = iter->second; - } - - if ( (iter = map_cpy.find (TLS_PRIVATE_KEY_FILE)) != map_cpy.end()) { - tlsPrivateKeyFile = iter->second; - } - - if ( (iter = map_cpy.find (TLS_PASSWORD)) != map_cpy.end()) { - tlsPassword = iter->second; - } - - if ( (iter = map_cpy.find (TLS_METHOD)) != map_cpy.end()) { - tlsMethod = iter->second; - } - - if ( (iter = map_cpy.find (TLS_CIPHERS)) != map_cpy.end()) { - tlsCiphers = iter->second; - } - - if ( (iter = map_cpy.find (TLS_SERVER_NAME)) != map_cpy.end()) { - tlsServerName = iter->second; - } - - if ( (iter = map_cpy.find (TLS_VERIFY_SERVER)) != map_cpy.end()) { - tlsVerifyServer = iter->second; - } - - if ( (iter = map_cpy.find (TLS_VERIFY_CLIENT)) != map_cpy.end()) { - tlsVerifyClient = iter->second; - } - - if ( (iter = map_cpy.find (TLS_REQUIRE_CLIENT_CERTIFICATE)) != map_cpy.end()) { - tlsRequireClientCertificate = iter->second; - } - - if ( (iter = map_cpy.find (TLS_NEGOTIATION_TIMEOUT_SEC)) != map_cpy.end()) { - tlsNegotiationTimeoutSec = iter->second; - } - - if ( (iter = map_cpy.find (TLS_NEGOTIATION_TIMEOUT_MSEC)) != map_cpy.end()) { - tlsNegotiationTimeoutMsec = iter->second; - } - - setConfig (accountID, HOSTNAME, hostname); - - setConfig (accountID, LOCAL_INTERFACE, localInterface); - setConfig (accountID, PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal); - setConfig (accountID, PUBLISHED_ADDRESS, publishedAddress); - setConfig (accountID, LOCAL_PORT, localPort); - setConfig (accountID, PUBLISHED_PORT, publishedPort); - setConfig (accountID, DISPLAY_NAME, displayName); - setConfig (accountID, SRTP_ENABLE, srtpEnable); - setConfig (accountID, SRTP_RTP_FALLBACK, srtpRtpFallback); - setConfig (accountID, ZRTP_DISPLAY_SAS, zrtpDisplaySas); - setConfig (accountID, ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce); - setConfig (accountID, ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning); - setConfig (accountID, ZRTP_HELLO_HASH, zrtpHelloHash); - setConfig (accountID, SRTP_KEY_EXCHANGE, srtpKeyExchange); - - setConfig (accountID, STUN_ENABLE, stunEnable); - setConfig (accountID, STUN_SERVER, stunServer); - - // The TLS listener is unique and globally defined through IP2IP_PROFILE - if(accountID == IP2IP_PROFILE) - setConfig(accountID, TLS_LISTENER_PORT, tlsListenerPort); - - setConfig (accountID, TLS_ENABLE, tlsEnable); - setConfig (accountID, TLS_CA_LIST_FILE, tlsCaListFile); - setConfig (accountID, TLS_CERTIFICATE_FILE, tlsCertificateFile); - setConfig (accountID, TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile); - setConfig (accountID, TLS_PASSWORD, tlsPassword); - setConfig (accountID, TLS_METHOD, tlsMethod); - setConfig (accountID, TLS_CIPHERS, tlsCiphers); - setConfig (accountID, TLS_SERVER_NAME, tlsServerName); - setConfig (accountID, TLS_VERIFY_SERVER, tlsVerifyServer); - setConfig (accountID, TLS_VERIFY_CLIENT, tlsVerifyClient); - setConfig (accountID, TLS_REQUIRE_CLIENT_CERTIFICATE, tlsRequireClientCertificate); - setConfig (accountID, TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec); - setConfig (accountID, TLS_NEGOTIATION_TIMEOUT_MSEC, tlsNegotiationTimeoutMsec); - - setConfig (accountID, CONFIG_ACCOUNT_ALIAS, alias); - setConfig (accountID, CONFIG_ACCOUNT_MAILBOX, mailbox); - setConfig (accountID, CONFIG_ACCOUNT_ENABLE, accountEnable); - setConfig (accountID, CONFIG_ACCOUNT_TYPE, type); - setConfig (accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce); - setConfig (accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire); - - saveConfig(); - - Account * acc = NULL; - acc = getAccount (accountID); - - if (acc != NULL) { - acc->loadConfig(); - - if (acc->isEnabled()) { - acc->registerVoIPLink(); - } else { - acc->unregisterVoIPLink(); - } - } else { - _debug ("ManagerImpl::setAccountDetails: account is NULL"); - } + if ((iter = map_cpy.find(AUTHENTICATION_USERNAME)) != map_cpy.end()) { + authenticationName = iter->second; + } + + if ((iter = map_cpy.find(USERNAME)) != map_cpy.end()) { + username = iter->second; + } + + if ((iter = map_cpy.find(PASSWORD)) != map_cpy.end()) { + password = iter->second; + } + + if ((iter = map_cpy.find(REALM)) != map_cpy.end()) { + realm = iter->second; + } + + if ((iter = map_cpy.find(USERAGENT)) != map_cpy.end()) { + ua_name = iter->second; + } + + setConfig(accountID, REALM, realm); + setConfig(accountID, USERAGENT, ua_name); + setConfig(accountID, USERNAME, username); + setConfig(accountID, AUTHENTICATION_USERNAME, authenticationName); + + if (!getMd5CredentialHashing()) { + setConfig(accountID, PASSWORD, password); + } else { + // Make sure not to re-hash the password field if + // it is already saved as a MD5 Hash. + // TODO: This test is weak. Fix this. + if ((password.compare(getConfigString(accountID, PASSWORD)) != 0)) { + _debug ("Password sent and password from config are different. Re-hashing"); + std::string hash; + + if (authenticationName.empty()) { + hash = computeMd5HashFromCredential(username, password, realm); + } else { + hash = computeMd5HashFromCredential(authenticationName, + password, realm); + } + + setConfig(accountID, PASSWORD, hash); + } + } + + std::string alias; + + std::string mailbox; + std::string accountEnable; + std::string type; + std::string resolveOnce; + std::string registrationExpire; + + std::string hostname; + std::string displayName; + std::string localInterface; + std::string publishedSameasLocal; + std::string localAddress; + std::string publishedAddress; + std::string localPort; + std::string publishedPort; + std::string stunEnable; + std::string stunServer; + std::string srtpEnable; + std::string srtpRtpFallback; + std::string zrtpDisplaySas; + std::string zrtpDisplaySasOnce; + std::string zrtpNotSuppWarning; + std::string zrtpHelloHash; + std::string srtpKeyExchange; + + std::string tlsListenerPort; + std::string tlsEnable; + std::string tlsCaListFile; + std::string tlsCertificateFile; + std::string tlsPrivateKeyFile; + std::string tlsPassword; + std::string tlsMethod; + std::string tlsCiphers; + std::string tlsServerName; + std::string tlsVerifyServer; + std::string tlsVerifyClient; + std::string tlsRequireClientCertificate; + std::string tlsNegotiationTimeoutSec; + std::string tlsNegotiationTimeoutMsec; + + if ((iter = map_cpy.find(HOSTNAME)) != map_cpy.end()) { + hostname = iter->second; + } + + if ((iter = map_cpy.find(DISPLAY_NAME)) != map_cpy.end()) { + displayName = iter->second; + } + + if ((iter = map_cpy.find(LOCAL_INTERFACE)) != map_cpy.end()) { + localInterface = iter->second; + } + + if ((iter = map_cpy.find(PUBLISHED_SAMEAS_LOCAL)) != map_cpy.end()) { + publishedSameasLocal = iter->second; + } + + if ((iter = map_cpy.find(PUBLISHED_ADDRESS)) != map_cpy.end()) { + publishedAddress = iter->second; + } + + if ((iter = map_cpy.find(LOCAL_PORT)) != map_cpy.end()) { + localPort = iter->second; + } + + if ((iter = map_cpy.find(PUBLISHED_PORT)) != map_cpy.end()) { + publishedPort = iter->second; + } + + if ((iter = map_cpy.find(STUN_ENABLE)) != map_cpy.end()) { + stunEnable = iter->second; + } + + if ((iter = map_cpy.find(STUN_SERVER)) != map_cpy.end()) { + stunServer = iter->second; + } + + if ((iter = map_cpy.find(SRTP_ENABLE)) != map_cpy.end()) { + srtpEnable = iter->second; + } + + if ((iter = map_cpy.find(SRTP_RTP_FALLBACK)) != map_cpy.end()) { + srtpRtpFallback = iter->second; + } + + if ((iter = map_cpy.find(ZRTP_DISPLAY_SAS)) != map_cpy.end()) { + zrtpDisplaySas = iter->second; + } + + if ((iter = map_cpy.find(ZRTP_DISPLAY_SAS_ONCE)) != map_cpy.end()) { + zrtpDisplaySasOnce = iter->second; + } - // Update account details to the client side - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); + if ((iter = map_cpy.find(ZRTP_NOT_SUPP_WARNING)) != map_cpy.end()) { + zrtpNotSuppWarning = iter->second; + } + + if ((iter = map_cpy.find(ZRTP_HELLO_HASH)) != map_cpy.end()) { + zrtpHelloHash = iter->second; + } + + if ((iter = map_cpy.find(SRTP_KEY_EXCHANGE)) != map_cpy.end()) { + srtpKeyExchange = iter->second; + } + + if ((iter = map_cpy.find(CONFIG_ACCOUNT_ALIAS)) != map_cpy.end()) { + alias = iter->second; + } + + if ((iter = map_cpy.find(CONFIG_ACCOUNT_MAILBOX)) != map_cpy.end()) { + mailbox = iter->second; + } + + if ((iter = map_cpy.find(CONFIG_ACCOUNT_ENABLE)) != map_cpy.end()) { + accountEnable = iter->second; + } + + if ((iter = map_cpy.find(CONFIG_ACCOUNT_TYPE)) != map_cpy.end()) { + type = iter->second; + } + + if ((iter = map_cpy.find(CONFIG_ACCOUNT_RESOLVE_ONCE)) != map_cpy.end()) { + resolveOnce = iter->second; + } + + if ((iter = map_cpy.find(CONFIG_ACCOUNT_REGISTRATION_EXPIRE)) + != map_cpy.end()) { + registrationExpire = iter->second; + } + + // The TLS listener is unique and globally defined through IP2IP_PROFILE + if ((accountID == IP2IP_PROFILE) + && (iter = map_cpy.find(TLS_LISTENER_PORT)) != map_cpy.end()) { + tlsListenerPort = iter->second; + } + + if ((iter = map_cpy.find(TLS_ENABLE)) != map_cpy.end()) { + tlsEnable = iter->second; + } + + if ((iter = map_cpy.find(TLS_CA_LIST_FILE)) != map_cpy.end()) { + tlsCaListFile = iter->second; + } + + if ((iter = map_cpy.find(TLS_CERTIFICATE_FILE)) != map_cpy.end()) { + tlsCertificateFile = iter->second; + } + + if ((iter = map_cpy.find(TLS_PRIVATE_KEY_FILE)) != map_cpy.end()) { + tlsPrivateKeyFile = iter->second; + } + + if ((iter = map_cpy.find(TLS_PASSWORD)) != map_cpy.end()) { + tlsPassword = iter->second; + } + + if ((iter = map_cpy.find(TLS_METHOD)) != map_cpy.end()) { + tlsMethod = iter->second; + } + + if ((iter = map_cpy.find(TLS_CIPHERS)) != map_cpy.end()) { + tlsCiphers = iter->second; + } + + if ((iter = map_cpy.find(TLS_SERVER_NAME)) != map_cpy.end()) { + tlsServerName = iter->second; + } + + if ((iter = map_cpy.find(TLS_VERIFY_SERVER)) != map_cpy.end()) { + tlsVerifyServer = iter->second; + } + + if ((iter = map_cpy.find(TLS_VERIFY_CLIENT)) != map_cpy.end()) { + tlsVerifyClient = iter->second; + } + + if ((iter = map_cpy.find(TLS_REQUIRE_CLIENT_CERTIFICATE)) != map_cpy.end()) { + tlsRequireClientCertificate = iter->second; + } + + if ((iter = map_cpy.find(TLS_NEGOTIATION_TIMEOUT_SEC)) != map_cpy.end()) { + tlsNegotiationTimeoutSec = iter->second; + } + + if ((iter = map_cpy.find(TLS_NEGOTIATION_TIMEOUT_MSEC)) != map_cpy.end()) { + tlsNegotiationTimeoutMsec = iter->second; + } + + setConfig(accountID, HOSTNAME, hostname); + + setConfig(accountID, LOCAL_INTERFACE, localInterface); + setConfig(accountID, PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal); + setConfig(accountID, PUBLISHED_ADDRESS, publishedAddress); + setConfig(accountID, LOCAL_PORT, localPort); + setConfig(accountID, PUBLISHED_PORT, publishedPort); + setConfig(accountID, DISPLAY_NAME, displayName); + setConfig(accountID, SRTP_ENABLE, srtpEnable); + setConfig(accountID, SRTP_RTP_FALLBACK, srtpRtpFallback); + setConfig(accountID, ZRTP_DISPLAY_SAS, zrtpDisplaySas); + setConfig(accountID, ZRTP_DISPLAY_SAS_ONCE, zrtpDisplaySasOnce); + setConfig(accountID, ZRTP_NOT_SUPP_WARNING, zrtpNotSuppWarning); + setConfig(accountID, ZRTP_HELLO_HASH, zrtpHelloHash); + setConfig(accountID, SRTP_KEY_EXCHANGE, srtpKeyExchange); + + setConfig(accountID, STUN_ENABLE, stunEnable); + setConfig(accountID, STUN_SERVER, stunServer); + + // The TLS listener is unique and globally defined through IP2IP_PROFILE + if (accountID == IP2IP_PROFILE) + setConfig(accountID, TLS_LISTENER_PORT, tlsListenerPort); + + setConfig(accountID, TLS_ENABLE, tlsEnable); + setConfig(accountID, TLS_CA_LIST_FILE, tlsCaListFile); + setConfig(accountID, TLS_CERTIFICATE_FILE, tlsCertificateFile); + setConfig(accountID, TLS_PRIVATE_KEY_FILE, tlsPrivateKeyFile); + setConfig(accountID, TLS_PASSWORD, tlsPassword); + setConfig(accountID, TLS_METHOD, tlsMethod); + setConfig(accountID, TLS_CIPHERS, tlsCiphers); + setConfig(accountID, TLS_SERVER_NAME, tlsServerName); + setConfig(accountID, TLS_VERIFY_SERVER, tlsVerifyServer); + setConfig(accountID, TLS_VERIFY_CLIENT, tlsVerifyClient); + setConfig(accountID, TLS_REQUIRE_CLIENT_CERTIFICATE, + tlsRequireClientCertificate); + setConfig(accountID, TLS_NEGOTIATION_TIMEOUT_SEC, tlsNegotiationTimeoutSec); + setConfig(accountID, TLS_NEGOTIATION_TIMEOUT_MSEC, + tlsNegotiationTimeoutMsec); + + setConfig(accountID, CONFIG_ACCOUNT_ALIAS, alias); + setConfig(accountID, CONFIG_ACCOUNT_MAILBOX, mailbox); + setConfig(accountID, CONFIG_ACCOUNT_ENABLE, accountEnable); + setConfig(accountID, CONFIG_ACCOUNT_TYPE, type); + setConfig(accountID, CONFIG_ACCOUNT_RESOLVE_ONCE, resolveOnce); + setConfig(accountID, CONFIG_ACCOUNT_REGISTRATION_EXPIRE, registrationExpire); + + saveConfig(); + + Account * acc = NULL; + acc = getAccount(accountID); + + if (acc != NULL) { + acc->loadConfig(); + + if (acc->isEnabled()) { + acc->registerVoIPLink(); + } else { + acc->unregisterVoIPLink(); + } + } else { + _debug ("ManagerImpl::setAccountDetails: account is NULL"); + } + + // Update account details to the client side + if (_dbus) + _dbus->getConfigurationManager()->accountsChanged(); } -std::string -ManagerImpl::addAccount (const std::map< std::string, std::string >& details) -{ +std::string ManagerImpl::addAccount ( + const std::map<std::string, std::string>& details) { - /** @todo Deal with both the _accountMap and the Configuration */ - std::string accountType, account_list; - Account* newAccount; - std::stringstream accountID; - AccountID newAccountID; + /** @todo Deal with both the _accountMap and the Configuration */ + std::string accountType, account_list; + Account* newAccount; + std::stringstream accountID; + AccountID newAccountID; - accountID << "Account:" << time (NULL); - newAccountID = accountID.str(); + accountID << "Account:" << time(NULL); + newAccountID = accountID.str(); - // Get the type - accountType = (*details.find (CONFIG_ACCOUNT_TYPE)).second; + // Get the type + accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second; - _debug ("%s", newAccountID.c_str()); + _debug ("%s", newAccountID.c_str()); - /** @todo Verify the uniqueness, in case a program adds accounts, two in a row. */ + /** @todo Verify the uniqueness, in case a program adds accounts, two in a row. */ - if (accountType == "SIP") { - newAccount = AccountCreator::createAccount (AccountCreator::SIP_ACCOUNT, newAccountID); - newAccount->setVoIPLink(); - } else if (accountType == "IAX") { - newAccount = AccountCreator::createAccount (AccountCreator::IAX_ACCOUNT, newAccountID); - } else { - _debug ("Unknown %s param when calling addAccount(): %s", CONFIG_ACCOUNT_TYPE, accountType.c_str()); - return ""; - } + if (accountType == "SIP") { + newAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, + newAccountID); + newAccount->setVoIPLink(); + } else if (accountType == "IAX") { + newAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, + newAccountID); + } else { + _debug ("Unknown %s param when calling addAccount(): %s", CONFIG_ACCOUNT_TYPE, accountType.c_str()); + return ""; + } - _accountMap[newAccountID] = newAccount; + _accountMap[newAccountID] = newAccount; - setAccountDetails (accountID.str(), details); + setAccountDetails(accountID.str(), details); - // Add the newly created account in the account order list - account_list = getConfigString (PREFERENCES, CONFIG_ACCOUNTS_ORDER); + // Add the newly created account in the account order list + account_list = getConfigString(PREFERENCES, CONFIG_ACCOUNTS_ORDER); - if (account_list != "") { - newAccountID += "/"; - // Prepend the new account - account_list.insert (0, newAccountID); - setConfig (PREFERENCES, CONFIG_ACCOUNTS_ORDER, account_list); - } + if (account_list != "") { + newAccountID += "/"; + // Prepend the new account + account_list.insert(0, newAccountID); + setConfig(PREFERENCES, CONFIG_ACCOUNTS_ORDER, account_list); + } - saveConfig(); + saveConfig(); - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); + if (_dbus) + _dbus->getConfigurationManager()->accountsChanged(); - return newAccountID; + return newAccountID; } -void -ManagerImpl::deleteAllCredential (const AccountID& accountID) -{ - int numberOfCredential = getConfigInt (accountID, CONFIG_CREDENTIAL_NUMBER); +void ManagerImpl::deleteAllCredential (const AccountID& accountID) { + int numberOfCredential = getConfigInt(accountID, CONFIG_CREDENTIAL_NUMBER); - int i; + int i; - for (i = 0; i < numberOfCredential; i++) { - std::string credentialIndex; - std::stringstream streamOut; - streamOut << i; - credentialIndex = streamOut.str(); - std::string section = "Credential" + std::string (":") + accountID + std::string (":") + credentialIndex; + for (i = 0; i < numberOfCredential; i++) { + std::string credentialIndex; + std::stringstream streamOut; + streamOut << i; + credentialIndex = streamOut.str(); + std::string section = "Credential" + std::string(":") + accountID + + std::string(":") + credentialIndex; - _config.removeSection (section); - } + _config.removeSection(section); + } - if (accountID.empty() == false) { - setConfig (accountID, CONFIG_CREDENTIAL_NUMBER, 0); - } + if (accountID.empty() == false) { + setConfig(accountID, CONFIG_CREDENTIAL_NUMBER, 0); + } } -void -ManagerImpl::removeAccount (const AccountID& accountID) -{ - // Get it down and dying - Account* remAccount = NULL; - remAccount = getAccount (accountID); +void ManagerImpl::removeAccount (const AccountID& accountID) { + // Get it down and dying + Account* remAccount = NULL; + remAccount = getAccount(accountID); - if (remAccount != NULL) { - remAccount->unregisterVoIPLink(); - _accountMap.erase (accountID); - // http://projects.savoirfairelinux.net/issues/show/2355 - // delete remAccount; - } + if (remAccount != NULL) { + remAccount->unregisterVoIPLink(); + _accountMap.erase(accountID); + // http://projects.savoirfairelinux.net/issues/show/2355 + // delete remAccount; + } - _config.removeSection (accountID); + _config.removeSection(accountID); - saveConfig(); + saveConfig(); - _debug ("REMOVE ACCOUNT"); + _debug ("REMOVE ACCOUNT"); - if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); + if (_dbus) + _dbus->getConfigurationManager()->accountsChanged(); } // ACCOUNT handling -bool -ManagerImpl::associateCallToAccount (const CallID& callID, const AccountID& accountID) -{ - if (getAccountFromCall (callID) == AccountNULL) { // nothing with the same ID - if (accountExists (accountID)) { // account id exist in AccountMap - ost::MutexLock m (_callAccountMapMutex); - _callAccountMap[callID] = accountID; - _debug ("Associate Call %s with Account %s", callID.data(), accountID.data()); - return true; - } else { - return false; - } - } else { - return false; - } +bool ManagerImpl::associateCallToAccount (const CallID& callID, + const AccountID& accountID) { + if (getAccountFromCall(callID) == AccountNULL) { // nothing with the same ID + if (accountExists(accountID)) { // account id exist in AccountMap + ost::MutexLock m(_callAccountMapMutex); + _callAccountMap[callID] = accountID; + _debug ("Associate Call %s with Account %s", callID.data(), accountID.data()); + return true; + } else { + return false; + } + } else { + return false; + } } -AccountID -ManagerImpl::getAccountFromCall (const CallID& callID) -{ - ost::MutexLock m (_callAccountMapMutex); - CallAccountMap::iterator iter = _callAccountMap.find (callID); +AccountID ManagerImpl::getAccountFromCall (const CallID& callID) { + ost::MutexLock m(_callAccountMapMutex); + CallAccountMap::iterator iter = _callAccountMap.find(callID); - if (iter == _callAccountMap.end()) { - return AccountNULL; - } else { - return iter->second; - } + if (iter == _callAccountMap.end()) { + return AccountNULL; + } else { + return iter->second; + } } -bool -ManagerImpl::removeCallAccount (const CallID& callID) -{ - ost::MutexLock m (_callAccountMapMutex); +bool ManagerImpl::removeCallAccount (const CallID& callID) { + ost::MutexLock m(_callAccountMapMutex); - if (_callAccountMap.erase (callID)) { - return true; - } + if (_callAccountMap.erase(callID)) { + return true; + } - return false; + return false; } -CallID -ManagerImpl::getNewCallID() -{ - std::ostringstream random_id ("s"); - random_id << (unsigned) rand(); +CallID ManagerImpl::getNewCallID () { + std::ostringstream random_id("s"); + random_id << (unsigned) rand(); - // when it's not found, it return "" - // generate, something like s10000s20000s4394040 + // when it's not found, it return "" + // generate, something like s10000s20000s4394040 - while (getAccountFromCall (random_id.str()) != AccountNULL) { - random_id.clear(); - random_id << "s"; - random_id << (unsigned) rand(); - } + while (getAccountFromCall(random_id.str()) != AccountNULL) { + random_id.clear(); + random_id << "s"; + random_id << (unsigned) rand(); + } - return random_id.str(); + return random_id.str(); } -std::vector <std::string> ManagerImpl::loadAccountOrder (void) -{ +std::vector<std::string> ManagerImpl::loadAccountOrder (void) { - std::string account_list; - std::vector <std::string> account_vect; + std::string account_list; + std::vector<std::string> account_vect; - account_list = getConfigString (PREFERENCES, CONFIG_ACCOUNTS_ORDER); - return unserialize (account_list); + account_list = getConfigString(PREFERENCES, CONFIG_ACCOUNTS_ORDER); + return unserialize(account_list); } +short ManagerImpl::loadAccountMap () { -short -ManagerImpl::loadAccountMap() -{ + _debug ("Loading account map"); - _debug ("Loading account map"); + short nbAccount = 0; + TokenList sections = _config.getSections(); + std::string accountType; + Account *tmpAccount = 0; + std::vector<std::string> account_order; - short nbAccount = 0; - TokenList sections = _config.getSections(); - std::string accountType; - Account *tmpAccount = 0; - std::vector <std::string> account_order; + TokenList::iterator iter = sections.begin(); - TokenList::iterator iter = sections.begin(); + // Those calls that are placed to an uri that cannot be + // associated to an account are using that special account. + // An account, that is not account, in the sense of + // registration. This is useful since the Account object + // provides a handful of method that simplifies URI creation + // and loading of various settings. + _directIpAccount = AccountCreator::createAccount( + AccountCreator::SIP_DIRECT_IP_ACCOUNT, ""); - // Those calls that are placed to an uri that cannot be - // associated to an account are using that special account. - // An account, that is not account, in the sense of - // registration. This is useful since the Account object - // provides a handful of method that simplifies URI creation - // and loading of various settings. - _directIpAccount = AccountCreator::createAccount (AccountCreator::SIP_DIRECT_IP_ACCOUNT, ""); + _debug ("Create default \"account\" (used as default UDP transport)"); + if (_directIpAccount == NULL) { - _debug ("Create default \"account\" (used as default UDP transport)"); - if (_directIpAccount == NULL) { + _debug ("Failed to create default \"account\""); + } else { - _debug ("Failed to create default \"account\""); - } else { + _accountMap[IP2IP_PROFILE] = _directIpAccount; - _accountMap[IP2IP_PROFILE] = _directIpAccount; + // Force IP2IP settings to be loaded to be loaded + // No registration in the sense of the REGISTER method is performed. + _directIpAccount->registerVoIPLink(); - // Force IP2IP settings to be loaded to be loaded - // No registration in the sense of the REGISTER method is performed. - _directIpAccount->registerVoIPLink(); + // SIPVoIPlink is used as a singleton, it is the first call to instance here + // The SIP library initialization is done in the SIPVoIPLink constructor + // We need the IP2IP settings to be loaded at this time as they are used + // for default sip transport - // SIPVoIPlink is used as a singleton, it is the first call to instance here - // The SIP library initialization is done in the SIPVoIPLink constructor - // We need the IP2IP settings to be loaded at this time as they are used - // for default sip transport + // _directIpAccount->setVoIPLink(SIPVoIPLink::instance ("")); + _directIpAccount->setVoIPLink(); - // _directIpAccount->setVoIPLink(SIPVoIPLink::instance ("")); - _directIpAccount->setVoIPLink(); - - } + } - // initialize other accounts - while (iter != sections.end()) { - // Check if it starts with "Account:" (SIP and IAX pour le moment) - if ( (int) (iter->find ("Account:")) != 0) { - iter++; - continue; - } + // initialize other accounts + while (iter != sections.end()) { + // Check if it starts with "Account:" (SIP and IAX pour le moment) + if ((int) (iter->find("Account:")) != 0) { + iter++; + continue; + } - accountType = getConfigString (*iter, CONFIG_ACCOUNT_TYPE); + accountType = getConfigString(*iter, CONFIG_ACCOUNT_TYPE); - if (accountType == "SIP") { - tmpAccount = AccountCreator::createAccount (AccountCreator::SIP_ACCOUNT, *iter); - } + if (accountType == "SIP") { + tmpAccount = AccountCreator::createAccount( + AccountCreator::SIP_ACCOUNT, *iter); + } - else if (accountType == "IAX") { - tmpAccount = AccountCreator::createAccount (AccountCreator::IAX_ACCOUNT, *iter); - } + else if (accountType == "IAX") { + tmpAccount = AccountCreator::createAccount( + AccountCreator::IAX_ACCOUNT, *iter); + } - else { - _error ("Unknown %s param in config file (%s)", CONFIG_ACCOUNT_TYPE, accountType.c_str()); - } + else { + _error ("Unknown %s param in config file (%s)", CONFIG_ACCOUNT_TYPE, accountType.c_str()); + } - if (tmpAccount != NULL) { - _debug ("Loading account %s ", iter->c_str()); - _accountMap[iter->c_str() ] = tmpAccount; - // tmpAccount->setVoIPLink(SIPVoIPLink::instance ("")); - tmpAccount->setVoIPLink(); - nbAccount++; - } + if (tmpAccount != NULL) { + _debug ("Loading account %s ", iter->c_str()); + _accountMap[iter->c_str()] = tmpAccount; + // tmpAccount->setVoIPLink(SIPVoIPLink::instance ("")); + tmpAccount->setVoIPLink(); + nbAccount++; + } - iter++; - } + iter++; + } - _debug ("nb account loaded %i \n", nbAccount); + _debug ("nb account loaded %i \n", nbAccount); - return nbAccount; + return nbAccount; } -void -ManagerImpl::unloadAccountMap() -{ +void ManagerImpl::unloadAccountMap () { - AccountMap::iterator iter = _accountMap.begin(); + AccountMap::iterator iter = _accountMap.begin(); - while (iter != _accountMap.end()) { + while (iter != _accountMap.end()) { - _debug ("Unloading account %s\n", iter->first.c_str()); + _debug ("Unloading account %s\n", iter->first.c_str()); - delete iter->second; - iter->second = 0; + delete iter->second; + iter->second = 0; - iter++; - } + iter++; + } - _accountMap.clear(); + _accountMap.clear(); } -bool -ManagerImpl::accountExists (const AccountID& accountID) -{ - AccountMap::iterator iter = _accountMap.find (accountID); +bool ManagerImpl::accountExists (const AccountID& accountID) { + AccountMap::iterator iter = _accountMap.find(accountID); - if (iter == _accountMap.end()) { - return false; - } + if (iter == _accountMap.end()) { + return false; + } - return true; + return true; } Account* -ManagerImpl::getAccount (const AccountID& accountID) -{ - // In our definition, - // this is the "direct ip calls account" - if (accountID == AccountNULL) { - _debug ("Returns the direct IP account"); - return _directIpAccount; - } +ManagerImpl::getAccount (const AccountID& accountID) { + // In our definition, + // this is the "direct ip calls account" + if (accountID == AccountNULL) { + _debug ("Returns the direct IP account"); + return _directIpAccount; + } - AccountMap::iterator iter = _accountMap.find (accountID); + AccountMap::iterator iter = _accountMap.find(accountID); - if (iter == _accountMap.end()) { - return NULL; - } + if (iter == _accountMap.end()) { + return NULL; + } - return iter->second; + return iter->second; } -AccountID -ManagerImpl::getAccountIdFromNameAndServer (const std::string& userName, const std::string& server) -{ - AccountMap::iterator iter; - SIPAccount *account; - _debug ("getAccountIdFromNameAndServer : username = %s , server = %s", userName.c_str(), server.c_str()); - // Try to find the account id from username and server name by full match +AccountID ManagerImpl::getAccountIdFromNameAndServer ( + const std::string& userName, const std::string& server) { + AccountMap::iterator iter; + SIPAccount *account; + _debug ("getAccountIdFromNameAndServer : username = %s , server = %s", userName.c_str(), server.c_str()); + // Try to find the account id from username and server name by full match - for (iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { - _debug ("for : account = %s", iter->first.c_str()); - account = dynamic_cast<SIPAccount *> (iter->second); + for (iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { + _debug ("for : account = %s", iter->first.c_str()); + account = dynamic_cast<SIPAccount *> (iter->second); - if (account != NULL) { - if (account->fullMatch (userName, server)) { - _debug ("Matching accountId in request is a fullmatch"); - return iter->first; - } - } - } + if (account != NULL) { + if (account->fullMatch(userName, server)) { + _debug ("Matching accountId in request is a fullmatch"); + return iter->first; + } + } + } - // We failed! Then only match the hostname - for (iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { - account = dynamic_cast<SIPAccount *> (iter->second); + // We failed! Then only match the hostname + for (iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { + account = dynamic_cast<SIPAccount *> (iter->second); - if (account != NULL) { - if (account->hostnameMatch (server)) { - _debug ("Matching accountId in request with hostname"); - return iter->first; - } - } - } + if (account != NULL) { + if (account->hostnameMatch(server)) { + _debug ("Matching accountId in request with hostname"); + return iter->first; + } + } + } - // We failed! Then only match the username - for (iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { - account = dynamic_cast<SIPAccount *> (iter->second); + // We failed! Then only match the username + for (iter = _accountMap.begin(); iter != _accountMap.end(); ++iter) { + account = dynamic_cast<SIPAccount *> (iter->second); - if (account != NULL) { - if (account->userMatch (userName)) { - _debug ("Matching accountId in request with username"); - return iter->first; - } - } - } + if (account != NULL) { + if (account->userMatch(userName)) { + _debug ("Matching accountId in request with username"); + return iter->first; + } + } + } - // Failed again! return AccountNULL - return AccountNULL; + // Failed again! return AccountNULL + return AccountNULL; } -std::map<std::string, int32_t> ManagerImpl::getAddressbookSettings () -{ +std::map<std::string, int32_t> ManagerImpl::getAddressbookSettings () { - std::map<std::string, int32_t> settings; + std::map<std::string, int32_t> settings; - settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_ENABLE", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_ENABLE))); - settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_MAX_RESULTS", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS))); - settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_DISPLAY_CONTACT_PHOTO", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO))); - settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_DISPLAY_PHONE_BUSINESS", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS))); - settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_DISPLAY_PHONE_HOME", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_HOME))); - settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_DISPLAY_PHONE_MOBILE", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_MOBILE))); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_ENABLE", + getConfigInt(ADDRESSBOOK, ADDRESSBOOK_ENABLE))); + settings.insert(std::pair<std::string, int32_t>("ADDRESSBOOK_MAX_RESULTS", + getConfigInt(ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS))); + settings.insert(std::pair<std::string, int32_t>( + "ADDRESSBOOK_DISPLAY_CONTACT_PHOTO", getConfigInt(ADDRESSBOOK, + ADDRESSBOOK_DISPLAY_CONTACT_PHOTO))); + settings.insert(std::pair<std::string, int32_t>( + "ADDRESSBOOK_DISPLAY_PHONE_BUSINESS", getConfigInt(ADDRESSBOOK, + ADDRESSBOOK_DISPLAY_PHONE_BUSINESS))); + settings.insert(std::pair<std::string, int32_t>( + "ADDRESSBOOK_DISPLAY_PHONE_HOME", getConfigInt(ADDRESSBOOK, + ADDRESSBOOK_DISPLAY_PHONE_HOME))); + settings.insert(std::pair<std::string, int32_t>( + "ADDRESSBOOK_DISPLAY_PHONE_MOBILE", getConfigInt(ADDRESSBOOK, + ADDRESSBOOK_DISPLAY_PHONE_MOBILE))); - return settings; + return settings; } -void ManagerImpl::setAddressbookSettings (const std::map<std::string, int32_t>& settings) -{ +void ManagerImpl::setAddressbookSettings ( + const std::map<std::string, int32_t>& settings) { - setConfig (ADDRESSBOOK, ADDRESSBOOK_ENABLE, (*settings.find ("ADDRESSBOOK_ENABLE")).second); - setConfig (ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS, (*settings.find ("ADDRESSBOOK_MAX_RESULTS")).second); - setConfig (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO , (*settings.find ("ADDRESSBOOK_DISPLAY_CONTACT_PHOTO")).second); - setConfig (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS , (*settings.find ("ADDRESSBOOK_DISPLAY_PHONE_BUSINESS")).second); - setConfig (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_HOME , (*settings.find ("ADDRESSBOOK_DISPLAY_PHONE_HOME")).second); - setConfig (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_MOBILE , (*settings.find ("ADDRESSBOOK_DISPLAY_PHONE_MOBILE")).second); + setConfig(ADDRESSBOOK, ADDRESSBOOK_ENABLE, (*settings.find( + "ADDRESSBOOK_ENABLE")).second); + setConfig(ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS, (*settings.find( + "ADDRESSBOOK_MAX_RESULTS")).second); + setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, (*settings.find( + "ADDRESSBOOK_DISPLAY_CONTACT_PHOTO")).second); + setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, (*settings.find( + "ADDRESSBOOK_DISPLAY_PHONE_BUSINESS")).second); + setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_HOME, (*settings.find( + "ADDRESSBOOK_DISPLAY_PHONE_HOME")).second); + setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_MOBILE, (*settings.find( + "ADDRESSBOOK_DISPLAY_PHONE_MOBILE")).second); - // Write it to the configuration file - saveConfig (); + // Write it to the configuration file + saveConfig(); } -void -ManagerImpl::setAddressbookList (const std::vector< std::string >& list) -{ +void ManagerImpl::setAddressbookList (const std::vector<std::string>& list) { - std::string s = serialize (list); - setConfig (ADDRESSBOOK, ADDRESSBOOK_LIST, s); + std::string s = serialize(list); + setConfig(ADDRESSBOOK, ADDRESSBOOK_LIST, s); } -std::vector <std::string> -ManagerImpl::getAddressbookList (void) -{ +std::vector<std::string> ManagerImpl::getAddressbookList (void) { - std::string s = getConfigString (ADDRESSBOOK, ADDRESSBOOK_LIST); - return unserialize (s); + std::string s = getConfigString(ADDRESSBOOK, ADDRESSBOOK_LIST); + return unserialize(s); } -std::map<std::string, std::string> ManagerImpl::getHookSettings () -{ +std::map<std::string, std::string> ManagerImpl::getHookSettings () { - std::map<std::string, std::string> settings; + std::map<std::string, std::string> settings; - settings.insert (std::pair<std::string, std::string> ("URLHOOK_SIP_FIELD", getConfigString (HOOKS, URLHOOK_SIP_FIELD))); - settings.insert (std::pair<std::string, std::string> ("URLHOOK_COMMAND", getConfigString (HOOKS, URLHOOK_COMMAND))); - settings.insert (std::pair<std::string, std::string> ("URLHOOK_SIP_ENABLED", getConfigString (HOOKS, URLHOOK_SIP_ENABLED))); - settings.insert (std::pair<std::string, std::string> ("URLHOOK_IAX2_ENABLED", getConfigString (HOOKS, URLHOOK_IAX2_ENABLED))); - settings.insert (std::pair<std::string, std::string> ("PHONE_NUMBER_HOOK_ENABLED", getConfigString (HOOKS, PHONE_NUMBER_HOOK_ENABLED))); - settings.insert (std::pair<std::string, std::string> ("PHONE_NUMBER_HOOK_ADD_PREFIX", getConfigString (HOOKS, PHONE_NUMBER_HOOK_ADD_PREFIX))); + settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_FIELD", + getConfigString(HOOKS, URLHOOK_SIP_FIELD))); + settings.insert(std::pair<std::string, std::string>("URLHOOK_COMMAND", + getConfigString(HOOKS, URLHOOK_COMMAND))); + settings.insert(std::pair<std::string, std::string>("URLHOOK_SIP_ENABLED", + getConfigString(HOOKS, URLHOOK_SIP_ENABLED))); + settings.insert(std::pair<std::string, std::string>("URLHOOK_IAX2_ENABLED", + getConfigString(HOOKS, URLHOOK_IAX2_ENABLED))); + settings.insert(std::pair<std::string, std::string>( + "PHONE_NUMBER_HOOK_ENABLED", getConfigString(HOOKS, + PHONE_NUMBER_HOOK_ENABLED))); + settings.insert(std::pair<std::string, std::string>( + "PHONE_NUMBER_HOOK_ADD_PREFIX", getConfigString(HOOKS, + PHONE_NUMBER_HOOK_ADD_PREFIX))); - return settings; + return settings; } -void ManagerImpl::setHookSettings (const std::map<std::string, std::string>& settings) -{ +void ManagerImpl::setHookSettings ( + const std::map<std::string, std::string>& settings) { - setConfig (HOOKS, URLHOOK_SIP_FIELD, (*settings.find ("URLHOOK_SIP_FIELD")).second); - setConfig (HOOKS, URLHOOK_COMMAND, (*settings.find ("URLHOOK_COMMAND")).second); - setConfig (HOOKS, URLHOOK_SIP_ENABLED, (*settings.find ("URLHOOK_SIP_ENABLED")).second); - setConfig (HOOKS, URLHOOK_IAX2_ENABLED, (*settings.find ("URLHOOK_IAX2_ENABLED")).second); - setConfig (HOOKS, PHONE_NUMBER_HOOK_ENABLED, (*settings.find ("PHONE_NUMBER_HOOK_ENABLED")).second); - setConfig (HOOKS, PHONE_NUMBER_HOOK_ADD_PREFIX, (*settings.find ("PHONE_NUMBER_HOOK_ADD_PREFIX")).second); + setConfig(HOOKS, URLHOOK_SIP_FIELD, + (*settings.find("URLHOOK_SIP_FIELD")).second); + setConfig(HOOKS, URLHOOK_COMMAND, + (*settings.find("URLHOOK_COMMAND")).second); + setConfig(HOOKS, URLHOOK_SIP_ENABLED, + (*settings.find("URLHOOK_SIP_ENABLED")).second); + setConfig(HOOKS, URLHOOK_IAX2_ENABLED, (*settings.find( + "URLHOOK_IAX2_ENABLED")).second); + setConfig(HOOKS, PHONE_NUMBER_HOOK_ENABLED, (*settings.find( + "PHONE_NUMBER_HOOK_ENABLED")).second); + setConfig(HOOKS, PHONE_NUMBER_HOOK_ADD_PREFIX, (*settings.find( + "PHONE_NUMBER_HOOK_ADD_PREFIX")).second); - // Write it to the configuration file - saveConfig (); + // Write it to the configuration file + saveConfig(); } -void ManagerImpl::check_call_configuration (const CallID& id, const std::string &to, Call::CallConfiguration *callConfig) -{ - Call::CallConfiguration config; - - if (to.find (SIP_SCHEME) == 0 || to.find (SIPS_SCHEME) == 0) { - _debug ("Sending Sip Call "); - config = Call::IPtoIP; - } else { - config = Call::Classic; - } +void ManagerImpl::check_call_configuration (const CallID& id, + const std::string &to, Call::CallConfiguration *callConfig) { + Call::CallConfiguration config; + + if (to.find(SIP_SCHEME) == 0 || to.find(SIPS_SCHEME) == 0) { + _debug ("Sending Sip Call "); + config = Call::IPtoIP; + } else { + config = Call::Classic; + } - associateConfigToCall (id, config); + associateConfigToCall(id, config); - *callConfig = config; + *callConfig = config; } +bool ManagerImpl::associateConfigToCall (const CallID& callID, + Call::CallConfiguration config) { -bool ManagerImpl::associateConfigToCall (const CallID& callID, Call::CallConfiguration config) -{ - - if (getConfigFromCall (callID) == CallConfigNULL) { // nothing with the same ID - _callConfigMap[callID] = config; - _debug ("Associate Call %s with config %i", callID.data(), config); - return true; - } else { - return false; - } + if (getConfigFromCall(callID) == CallConfigNULL) { // nothing with the same ID + _callConfigMap[callID] = config; + _debug ("Associate Call %s with config %i", callID.data(), config); + return true; + } else { + return false; + } } -Call::CallConfiguration ManagerImpl::getConfigFromCall (const CallID& callID) -{ +Call::CallConfiguration ManagerImpl::getConfigFromCall (const CallID& callID) { - CallConfigMap::iterator iter = _callConfigMap.find (callID); + CallConfigMap::iterator iter = _callConfigMap.find(callID); - if (iter == _callConfigMap.end()) { - return (Call::CallConfiguration) CallConfigNULL; - } else { - return iter->second; - } + if (iter == _callConfigMap.end()) { + return (Call::CallConfiguration) CallConfigNULL; + } else { + return iter->second; + } } -bool ManagerImpl::removeCallConfig (const CallID& callID) -{ +bool ManagerImpl::removeCallConfig (const CallID& callID) { - if (_callConfigMap.erase (callID)) { - return true; - } + if (_callConfigMap.erase(callID)) { + return true; + } - return false; + return false; } -std::map< std::string, std::string > ManagerImpl::getCallDetails (const CallID& callID) -{ - - std::map<std::string, std::string> call_details; - AccountID accountid; - Account *account; - VoIPLink *link; - Call *call = NULL; - std::stringstream type; +std::map<std::string, std::string> ManagerImpl::getCallDetails ( + const CallID& callID) { + std::map<std::string, std::string> call_details; + AccountID accountid; + Account *account; + VoIPLink *link; + Call *call = NULL; + std::stringstream type; - // We need here to retrieve the call information attached to the call ID - // To achieve that, we need to get the voip link attached to the call - // But to achieve that, we need to get the account the call was made with + // We need here to retrieve the call information attached to the call ID + // To achieve that, we need to get the voip link attached to the call + // But to achieve that, we need to get the account the call was made with - // So first we fetch the account - accountid = getAccountFromCall (callID); - _debug ("%s",callID.c_str()); - // Then the VoIP link this account is linked with (IAX2 or SIP) + // So first we fetch the account + accountid = getAccountFromCall(callID); + _debug ("%s",callID.c_str()); + // Then the VoIP link this account is linked with (IAX2 or SIP) - if ( (account=getAccount (accountid)) != 0) { - link = account->getVoIPLink (); + if ((account = getAccount(accountid)) != 0) { + link = account->getVoIPLink(); - if (link) { - call = link->getCall (callID); - } - } + if (link) { + call = link->getCall(callID); + } + } - if (call) { - type << call->getCallType (); - call_details.insert (std::pair<std::string, std::string> ("ACCOUNTID", accountid)); - call_details.insert (std::pair<std::string, std::string> ("PEER_NUMBER", call->getPeerNumber ())); - call_details.insert (std::pair<std::string, std::string> ("PEER_NAME", call->getPeerName ())); - call_details.insert (std::pair<std::string, std::string> ("DISPLAY_NAME", call->getDisplayName ())); - call_details.insert (std::pair<std::string, std::string> ("CALL_STATE", call->getStateStr ())); - call_details.insert (std::pair<std::string, std::string> ("CALL_TYPE", type.str ())); - } else { - _debug ("Error: Managerimpl - getCallDetails ()"); - call_details.insert (std::pair<std::string, std::string> ("ACCOUNTID", AccountNULL)); - call_details.insert (std::pair<std::string, std::string> ("PEER_NUMBER", "Unknown")); - call_details.insert (std::pair<std::string, std::string> ("PEER_NAME", "Unknown")); - call_details.insert (std::pair<std::string, std::string> ("CALL_STATE", "UNKNOWN")); - call_details.insert (std::pair<std::string, std::string> ("CALL_TYPE", "0")); - } + if (call) { + type << call->getCallType(); + call_details.insert(std::pair<std::string, std::string>("ACCOUNTID", + accountid)); + call_details.insert(std::pair<std::string, std::string>("PEER_NUMBER", + call->getPeerNumber())); + call_details.insert(std::pair<std::string, std::string>("PEER_NAME", + call->getPeerName())); + call_details.insert(std::pair<std::string, std::string>("DISPLAY_NAME", + call->getDisplayName())); + call_details.insert(std::pair<std::string, std::string>("CALL_STATE", + call->getStateStr())); + call_details.insert(std::pair<std::string, std::string>("CALL_TYPE", + type.str())); + } else { + _debug ("Error: Managerimpl - getCallDetails ()"); + call_details.insert(std::pair<std::string, std::string>("ACCOUNTID", + AccountNULL)); + call_details.insert(std::pair<std::string, std::string>("PEER_NUMBER", + "Unknown")); + call_details.insert(std::pair<std::string, std::string>("PEER_NAME", + "Unknown")); + call_details.insert(std::pair<std::string, std::string>("CALL_STATE", + "UNKNOWN")); + call_details.insert(std::pair<std::string, std::string>("CALL_TYPE", + "0")); + } - return call_details; + return call_details; } - -std::map<std::string, std::string> ManagerImpl::send_history_to_client (void) -{ - return _history->get_history_serialized (); +std::map<std::string, std::string> ManagerImpl::send_history_to_client (void) { + return _history->get_history_serialized(); } -void ManagerImpl::receive_history_from_client (std::map<std::string, std::string> history) -{ - _history->set_serialized_history (history, Manager::instance().getConfigInt (PREFERENCES, CONFIG_HISTORY_LIMIT)); - _history->save_history (); +void ManagerImpl::receive_history_from_client (std::map<std::string, + std::string> history) { + _history->set_serialized_history(history, Manager::instance().getConfigInt( + PREFERENCES, CONFIG_HISTORY_LIMIT)); + _history->save_history(); } +std::vector<std::string> ManagerImpl::getCallList (void) { + std::vector<std::string> v; -std::vector< std::string > -ManagerImpl::getCallList (void) -{ - std::vector< std::string > v; + CallAccountMap::iterator iter = _callAccountMap.begin(); - CallAccountMap::iterator iter = _callAccountMap.begin (); - - while (iter != _callAccountMap.end ()) { - v.push_back (iter->first.data()); - iter++; - } + while (iter != _callAccountMap.end()) { + v.push_back(iter->first.data()); + iter++; + } - return v; + return v; } +std::map<std::string, std::string> ManagerImpl::getConferenceDetails ( + const ConfID& confID) { -std::map< std::string, std::string > -ManagerImpl::getConferenceDetails (const ConfID& confID) -{ - - std::map<std::string, std::string> conf_details; - ConferenceMap::iterator iter_conf; + std::map<std::string, std::string> conf_details; + ConferenceMap::iterator iter_conf; - iter_conf = _conferencemap.find (confID); + iter_conf = _conferencemap.find(confID); - Conference* conf = NULL; + Conference* conf = NULL; - if (iter_conf != _conferencemap.end()) { + if (iter_conf != _conferencemap.end()) { - conf = iter_conf->second; - conf_details.insert (std::pair<std::string, std::string> ("CONFID", confID)); - conf_details.insert (std::pair<std::string, std::string> ("CONF_STATE", conf->getStateStr())); - } + conf = iter_conf->second; + conf_details.insert(std::pair<std::string, std::string>("CONFID", + confID)); + conf_details.insert(std::pair<std::string, std::string>("CONF_STATE", + conf->getStateStr())); + } - return conf_details; + return conf_details; } +std::vector<std::string> ManagerImpl::getConferenceList (void) { + _debug ("ManagerImpl::getConferenceList"); + std::vector<std::string> v; -std::vector< std::string > -ManagerImpl::getConferenceList (void) -{ - _debug ("ManagerImpl::getConferenceList"); - std::vector< std::string > v; - - ConferenceMap::iterator iter = _conferencemap.begin(); + ConferenceMap::iterator iter = _conferencemap.begin(); - while (iter != _conferencemap.end ()) { - v.push_back (iter->first); - iter++; - } + while (iter != _conferencemap.end()) { + v.push_back(iter->first); + iter++; + } - return v; + return v; } +std::vector<std::string> ManagerImpl::getParticipantList ( + const std::string& confID) { + _debug ("ManagerImpl::getParticipantList"); + std::vector<std::string> v; -std::vector< std::string > -ManagerImpl::getParticipantList (const std::string& confID) -{ - _debug ("ManagerImpl::getParticipantList"); - std::vector< std::string > v; + ConferenceMap::iterator iter_conf = _conferencemap.find(confID); + Conference *conf = NULL; - ConferenceMap::iterator iter_conf = _conferencemap.find (confID); - Conference *conf = NULL; + if (iter_conf != _conferencemap.end()) + conf = iter_conf->second; - if (iter_conf != _conferencemap.end()) - conf = iter_conf->second; + if (conf != NULL) { + ParticipantSet participants = conf->getParticipantList(); + ParticipantSet::iterator iter_participant = participants.begin(); - if (conf != NULL) { - ParticipantSet participants = conf->getParticipantList(); - ParticipantSet::iterator iter_participant = participants.begin(); + while (iter_participant != participants.end()) { - while (iter_participant != participants.end ()) { + v.push_back(*iter_participant); - v.push_back (*iter_participant); - - iter_participant++; - } - } + iter_participant++; + } + } - return v; + return v; } diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index ba4e856b301a3009fd1a222f60b157bcbd67fa27..886dc1430f588511d7b3794f3cf77b96a6a31c83 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -489,9 +489,6 @@ void Sdp::set_negotiated_sdp (const pjmedia_sdp_session *sdp) pjmedia_sdp_attr_to_rtpmap (_pool, attribute, &rtpmap); - // _debug("================== set_negociated_offer ===================== %i", pj_strtoul(&rtpmap->pt)); - // _debug("================== set_negociated_offer ===================== %s", current->desc.fmt[j].ptr); - // _debug("================== set_negociated_offer ===================== %i", atoi(current->desc.fmt[j].ptr)); iter = codecs_list.find ( (AudioCodecType) pj_strtoul (&rtpmap->pt)); if (iter==codecs_list.end()) @@ -627,7 +624,7 @@ void Sdp::set_remote_ip_from_sdp (const pjmedia_sdp_session *r_sdp) { std::string remote_ip (r_sdp->conn->addr.ptr, r_sdp->conn->addr.slen); - _debug (" Remote IP from fetching SDP: %s", remote_ip.c_str()); + _info ("SDP: Remote IP from fetching SDP: %s", remote_ip.c_str()); this->set_remote_ip (remote_ip); } @@ -637,21 +634,21 @@ void Sdp::set_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media) int remote_port; remote_port = r_media->desc.port; - _debug (" Remote Audio Port from fetching SDP: %d", remote_port); + _info ("SDP: Remote Audio Port from fetching SDP: %d", remote_port); this->set_remote_audio_port (remote_port); } void Sdp::set_media_transport_info_from_remote_sdp (const pjmedia_sdp_session *remote_sdp) { - _debug ("Fetching media from sdp"); + _info ("SDP: Fetching media from sdp"); pjmedia_sdp_media *r_media; this->get_remote_sdp_media_from_offer (remote_sdp, &r_media); if (r_media==NULL) { - _debug ("SDP Failure: no remote sdp media found in the remote offer"); + _warn ("SDP: Error: no remote sdp media found in the remote offer"); return; } diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 9e25418377d8708030acd33bb9c0a9adb8a38cd6..5c5bed594177da1b7dd388a7f38b1b50cb699d4b 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -1020,7 +1020,7 @@ int SIPVoIPLink::inv_session_reinvite (SIPCall *call, std::string direction) local_sdp = call->getLocalSDP()->get_local_sdp_session(); if (local_sdp == NULL) { - _debug ("! SIP Failure: unable to find local_sdp"); + _debug ("SIP: Error: unable to find local sdp"); return !PJ_SUCCESS; } @@ -3142,7 +3142,7 @@ void call_on_state_changed (pjsip_inv_session *inv, pjsip_event *e) // This callback is called after SDP offer/answer session has completed. void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) { - _debug ("UserAgent: call_on_media_update"); + _debug ("UserAgent: Call on media update"); const pjmedia_sdp_session *local_sdp; const pjmedia_sdp_session *remote_sdp; @@ -3153,19 +3153,19 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) call = reinterpret_cast<SIPCall *> (inv->mod_data[getModId() ]); if (!call) { - _debug ("Call declined by peer, SDP negociation stopped"); + _debug ("UserAgent: Call declined by peer, SDP negociation stopped"); return; } link = dynamic_cast<SIPVoIPLink *> (Manager::instance().getAccountLink (AccountNULL)); if (link == NULL) { - _debug ("Failed to get sip link"); + _warn ("UserAgent: Error: Failed to get sip link"); return; } if (status != PJ_SUCCESS) { - _debug ("Error while negotiating the offer"); + _warn ("UserAgent: Error: while negotiating the offer"); link->hangup (call->getCallId()); Manager::instance().callFailure (call->getCallId()); return; @@ -3198,39 +3198,39 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) } + // Get the crypto attribute containing srtp's cryptographic context (keys, cipher) CryptoOffer crypto_offer; call->getLocalSDP()->get_remote_sdp_crypto_from_offer(remote_sdp, crypto_offer); - bool nego_success = false; if(!crypto_offer.empty()) { - _debug("Crypto attribute in SDP: init Srtp session"); + _debug("Crypto attribute in SDP: init Srtp session"); - // init local cryptografic capabilities for negotiation - std::vector<sfl::CryptoSuiteDefinition>localCapabilities; - for(int i = 0; i < 3; i++) { - localCapabilities.push_back(sfl::CryptoSuites[i]); - } + // init local cryptografic capabilities for negotiation + std::vector<sfl::CryptoSuiteDefinition>localCapabilities; + for(int i = 0; i < 3; i++) { + localCapabilities.push_back(sfl::CryptoSuites[i]); + } - sfl::SdesNegotiator sdesnego(localCapabilities, crypto_offer); + sfl::SdesNegotiator sdesnego(localCapabilities, crypto_offer); - if(sdesnego.negotiate()) { - _debug("SDES negociation successfull \n"); - nego_success = true; + if(sdesnego.negotiate()) { + _debug("SDES negociation successfull \n"); + nego_success = true; _debug("Set remote cryptographic context\n"); try { - call->getAudioRtp()->setRemoteCryptoInfo(sdesnego); + call->getAudioRtp()->setRemoteCryptoInfo(sdesnego); } catch(...) {} - DBusManager::instance().getCallManager()->secureSdesOn (call->getCallId()); - } - else { - DBusManager::instance().getCallManager()->secureSdesOff (call->getCallId()); - } + DBusManager::instance().getCallManager()->secureSdesOn (call->getCallId()); + } + else { + DBusManager::instance().getCallManager()->secureSdesOff (call->getCallId()); + } } // We did not found any crypto context for this media @@ -3256,6 +3256,7 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) _debug("Sdes not initialized for this call\n"); } + try { call->setAudioStart (true); call->getAudioRtp()->start(); diff --git a/sflphone-common/src/user_cfg.h b/sflphone-common/src/user_cfg.h index 096b7f11f12558fea09f48ff7bb952d2eb2d1b02..4e8ce791b81fe8d0d6d221519bc3c35deebeab64 100644 --- a/sflphone-common/src/user_cfg.h +++ b/sflphone-common/src/user_cfg.h @@ -64,6 +64,8 @@ #define WINDOW_HEIGHT "Window.height" #define WINDOW_POSITION_X "Window.positionX" #define WINDOW_POSITION_Y "Window.positionY" +#define SHOW_STATUSICON "Statusicon.show" + #define IP2IP_PROFILE "IP2IP" #define SIGNALISATION "VoIPLink" /** Section Signalisation */