diff --git a/sflphone-client-gnome/src/actions.c b/sflphone-client-gnome/src/actions.c index 015e5d357754370a1061afb518a5adff182d076c..065494acf60ab931d0512170ee357513ae144627 100644 --- a/sflphone-client-gnome/src/actions.c +++ b/sflphone-client-gnome/src/actions.c @@ -359,8 +359,8 @@ gboolean sflphone_init (GError **error) if (!dbus_register (getpid (), "Gtk+ Client", error)) { return FALSE; } - - abookfactory_init_factory(); + + abookfactory_init_factory(); // Init icons factory init_icon_factory (); @@ -763,8 +763,7 @@ sflphone_new_call() if (calllist_get_size (current_calls) == 0) dbus_start_tone (TRUE , (current_account_has_new_message () > 0) ? TONE_WITH_MESSAGE : TONE_WITHOUT_MESSAGE) ; - callable_obj_t *c; - create_new_call (CALL, CALL_STATE_DIALING, "", "", "", "", &c); + callable_obj_t *c = create_new_call (CALL, CALL_STATE_DIALING, "", "", "", ""); c->_history_state = OUTGOING; @@ -984,9 +983,9 @@ static int _place_registered_call (callable_obj_t * c) } c->_history_state = OUTGOING; - + calllist_add_call (history, c); - calltree_add_call (history, c, NULL); + calltree_add_call (history, c, NULL); return 0; } @@ -1237,7 +1236,7 @@ void sflphone_fill_codec_list_per_account (account_t **account) guint caps_size = codec_list_get_size (), i=0; - for (i=0; i<caps_size; i++) { + for (i = 0; i < caps_size; i++) { codec_t * current_cap = capabilities_get_nth (i); @@ -1247,38 +1246,33 @@ void sflphone_fill_codec_list_per_account (account_t **account) // codec_create_new_from_caps (current_cap, &cpy); current_cap->is_active = active; codec_list_add (current_cap, &codeclist); - } else { } - } - (*account)->codecs = codeclist; } void sflphone_fill_call_list (void) { - gchar** calls = (gchar**) dbus_get_call_list(); GHashTable *call_details; - callable_obj_t *c; - gchar *callID; DEBUG ("sflphone_fill_call_list"); - if (calls) { - for (; *calls; calls++) { - c = g_new0 (callable_obj_t, 1); - callID = (gchar*) (*calls); - call_details = dbus_get_call_details (callID); - create_new_call_from_details (callID, call_details, &c); - c->_callID = g_strdup (callID); - c->_zrtp_confirmed = FALSE; - // Add it to the list - DEBUG ("Add call retrieved from server side: %s\n", c->_callID); - calllist_add_call (current_calls, c); - // Update the GUI - calltree_add_call (current_calls, c, NULL); - } + if (!calls) + return; + + for (; *calls; calls++) { + callable_obj_t *c = g_new0 (callable_obj_t, 1); + gchar *callID = (gchar*) (*calls); + call_details = dbus_get_call_details (callID); + c = create_new_call_from_details (callID, call_details); + g_free(callID); + c->_zrtp_confirmed = FALSE; + // Add it to the list + DEBUG ("Add call retrieved from server side: %s\n", c->_callID); + calllist_add_call (current_calls, c); + // Update the GUI + calltree_add_call (current_calls, c, NULL); } } @@ -1326,61 +1320,59 @@ void sflphone_fill_history (void) while (*entries) { gchar *current_entry = *entries; - // Parsed a conference - if(g_str_has_prefix(current_entry, "9999")) { - // create a conference entry - create_conference_history_entry_from_serialized(current_entry, &history_conf); - - // verify if this conference have been already created yet - conf = conferencelist_get(history, history_conf->_confID); - if(conf == NULL) { - // if this conference haven't been created yet, add it to the conference list - conferencelist_add(history, history_conf); - } - else { - // if this conference is already created since one of the participant have already - // been unserialized, update the recordfile value - conf->_recordfile = g_strdup(history_conf->_recordfile); - } - } - else { + // Parsed a conference + if(g_str_has_prefix(current_entry, "9999")) { + // create a conference entry + create_conference_history_entry_from_serialized(current_entry, &history_conf); + // verify if this conference have been already created yet + conf = conferencelist_get(history, history_conf->_confID); + if(conf == NULL) { + // if this conference haven't been created yet, add it to the conference list + conferencelist_add(history, history_conf); + } + else { + // if this conference is already created since one of the participant have already + // been unserialized, update the recordfile value + conf->_recordfile = g_strdup(history_conf->_recordfile); + } + } + else { // do something with key and value - create_history_entry_from_serialized_form (current_entry, &history_call); - - // Add it and update the GUI - calllist_add_call (history, history_call); + history_call = create_history_entry_from_serialized_form (current_entry); - if(history_call->_confID && g_strcmp0(history_call->_confID, "") != 0) { + // Add it and update the GUI + calllist_add_call (history, history_call); - // process conference - conf = conferencelist_get(history, history_call->_confID); - if(conf == NULL) { - // conference does not exist yet, create it - create_new_conference(CONFERENCE_STATE_ACTIVE_ATACHED, history_call->_confID, &conf); - conferencelist_add(history, conf); - } - - // add this participant to the conference - conference_add_participant(history_call->_callID, conf); + if (history_call->_confID && g_strcmp0(history_call->_confID, "") != 0) { - // conference start timestamp corespond to - if(conf->_time_start > history_call->_time_added) { - conf->_time_start = history_call->_time_added; + // process conference + conf = conferencelist_get(history, history_call->_confID); + if (!conf) { + // conference does not exist yet, create it + create_new_conference(CONFERENCE_STATE_ACTIVE_ATACHED, history_call->_confID, &conf); + conferencelist_add(history, conf); } - } + + // add this participant to the conference + conference_add_participant(history_call->_callID, conf); + + // conference start timestamp corespond to + if (conf->_time_start > history_call->_time_added) + conf->_time_start = history_call->_time_added; + } } - - g_free(*entries++); + + g_free(*entries++); } g_free(entries_orig); // fill the treeview with calls n = calllist_get_size(history); for(i = 0; i < n; i++) { - element = calllist_get_nth(history, i); - if(element->type == HIST_CALL) { - call = element->elem.call; + element = calllist_get_nth(history, i); + if(element->type == HIST_CALL) { + call = element->elem.call; calltree_add_call (history, call, NULL); } } @@ -1389,21 +1381,19 @@ void sflphone_fill_history (void) n = conferencelist_get_size(history); for(i = 0; i < n; i++) { conference_obj_t *conf = conferencelist_get_nth(history, i); - if(conf == NULL) { - DEBUG("SFLphone: Error: Could not find conference"); - } - calltree_add_conference(history, conf); - } - + if (!conf) + DEBUG("SFLphone: Error: Could not find conference"); + calltree_add_conference(history, conf); + } } #if ! (GLIB_CHECK_VERSION(2,28,0)) static void g_slist_free_full (GSList *list, - GDestroyNotify free_func) + GDestroyNotify free_func) { - g_slist_foreach (list, (GFunc) free_func, NULL); - g_slist_free (list); + g_slist_foreach (list, (GFunc) free_func, NULL); + g_slist_free (list); } #endif @@ -1426,8 +1416,8 @@ void sflphone_save_history (void) for (i = 0; i < size; i++) { current = calllist_get_nth (history, i); if (!current) { - WARN("SFLphone: Warning: %dth element is null", i); - break; + WARN("SFLphone: Warning: %dth element is null", i); + break; } gchar *value; @@ -1442,22 +1432,22 @@ void sflphone_save_history (void) gchar *key = convert_timestamp_to_gchar (current->elem.call->_time_start); g_hash_table_replace (result, (gpointer) key, - g_slist_append(g_hash_table_lookup(result, key),(gpointer) value)); + g_slist_append(g_hash_table_lookup(result, key),(gpointer) value)); } size = conferencelist_get_size(history); for(i = 0; i < size; i++) { conf = conferencelist_get_nth(history, i); - if(!conf) { - DEBUG("SFLphone: Error: Could not get %dth conference", i); - break; + if(!conf) { + DEBUG("SFLphone: Error: Could not get %dth conference", i); + break; } gchar *value = serialize_history_conference_entry(conf); - gchar *key = convert_timestamp_to_gchar(conf->_time_start); + gchar *key = convert_timestamp_to_gchar(conf->_time_start); - g_hash_table_replace(result, (gpointer) key, - g_slist_append(g_hash_table_lookup(result, key), (gpointer) value)); + g_hash_table_replace(result, (gpointer) key, + g_slist_append(g_hash_table_lookup(result, key), (gpointer) value)); } gchar **ordered_result = sflphone_order_history_hash_table(result); @@ -1601,8 +1591,7 @@ void sflphone_get_interface_addr_from_name (char *iface_name, char **iface_addr, tmp_addr = (char *) addr_in; snprintf (*iface_addr, size, "%d.%d.%d.%d", - UC (tmp_addr[0]), UC (tmp_addr[1]), UC (tmp_addr[2]), UC (tmp_addr[3])); + UC (tmp_addr[0]), UC (tmp_addr[1]), UC (tmp_addr[2]), UC (tmp_addr[3])); close (fd); - } diff --git a/sflphone-client-gnome/src/callable_obj.c b/sflphone-client-gnome/src/callable_obj.c index 2d447105f8abf47da17c30c2e7097d5f2d66c05e..7337fdb4fe7437ef7192db99d659c30e9176541e 100644 --- a/sflphone-client-gnome/src/callable_obj.c +++ b/sflphone-client-gnome/src/callable_obj.c @@ -36,10 +36,6 @@ #include <unistd.h> -#define UNIX_DAY 86400 -#define UNIX_WEEK 86400 * 6 -#define UNIX_TWO_DAYS 86400 * 2 - gint get_state_callstruct (gconstpointer a, gconstpointer b) { callable_obj_t * c = (callable_obj_t*) a; @@ -188,12 +184,11 @@ void stop_call_clock (callable_obj_t *c) } } -void create_new_call (callable_type_t type, call_state_t state, +callable_obj_t *create_new_call (callable_type_t type, call_state_t state, const gchar* const callID, const gchar* const accountID, const gchar* const peer_name, - const gchar* const peer_number, - callable_obj_t ** new_call) + const gchar* const peer_number) { GError *err1 = NULL ; callable_obj_t *obj; @@ -252,12 +247,11 @@ void create_new_call (callable_type_t type, call_state_t state, obj->_time_added = 0; - *new_call = obj; + return obj; } -void create_new_call_from_details (const gchar *call_id, GHashTable *details, callable_obj_t **call) +callable_obj_t *create_new_call_from_details (const gchar *call_id, GHashTable *details) { - callable_obj_t *new_call; call_state_t state; const gchar * const accountID = g_hash_table_lookup (details, "ACCOUNTID"); @@ -283,11 +277,10 @@ void create_new_call_from_details (const gchar *call_id, GHashTable *details, ca else state = CALL_STATE_FAILURE; - create_new_call (CALL, state, call_id, accountID, peer_name, call_get_peer_number (peer_number), &new_call); - *call = new_call; + return create_new_call (CALL, state, call_id, accountID, peer_name, call_get_peer_number (peer_number)); } -void create_history_entry_from_serialized_form (gchar *entry, callable_obj_t **call) +callable_obj_t *create_history_entry_from_serialized_form (const gchar *entry) { const gchar *peer_name = ""; const gchar *peer_number = ""; @@ -304,7 +297,7 @@ void create_history_entry_from_serialized_form (gchar *entry, callable_obj_t **c gchar ** ptr; gchar ** ptr_orig; static const gchar * const delim = "|"; - + ptr = g_strsplit(entry, delim, 10); ptr_orig = ptr; while (ptr != NULL && token < 10) { @@ -350,7 +343,7 @@ void create_history_entry_from_serialized_form (gchar *entry, callable_obj_t **c if (g_strcasecmp (peer_name, "empty") == 0) peer_name = ""; - create_new_call (HISTORY_ENTRY, CALL_STATE_DIALING, callID, accountID, peer_name, peer_number, &new_call); + new_call = create_new_call (HISTORY_ENTRY, CALL_STATE_DIALING, callID, accountID, peer_name, peer_number); new_call->_history_state = history_state; new_call->_time_start = convert_gchar_to_timestamp (time_start); new_call->_time_stop = convert_gchar_to_timestamp (time_stop); @@ -360,8 +353,8 @@ void create_history_entry_from_serialized_form (gchar *entry, callable_obj_t **c new_call->_time_added = convert_gchar_to_timestamp(time_start); new_call->_record_is_playing = FALSE; - *call = new_call; g_strfreev(ptr_orig); + return new_call; } void free_callable_obj_t (callable_obj_t *c) @@ -500,6 +493,9 @@ gchar* serialize_history_call_entry (callable_obj_t *entry) // gchar* get_formatted_start_timestamp (callable_obj_t *obj) gchar *get_formatted_start_timestamp (time_t time_start) { + enum { UNIX_DAY = 86400, + UNIX_WEEK = UNIX_DAY * 6, + UNIX_TWO_DAYS = UNIX_DAY * 2}; struct tm* ptr; time_t lt, now; diff --git a/sflphone-client-gnome/src/callable_obj.h b/sflphone-client-gnome/src/callable_obj.h index 3e5982ad1512710c52a045c1447329d43d812e76..ba51c093d4f7bbafbbd2c29686e12bca37cb36b1 100644 --- a/sflphone-client-gnome/src/callable_obj.h +++ b/sflphone-client-gnome/src/callable_obj.h @@ -178,11 +178,11 @@ typedef struct { } callable_obj_t; -void create_new_call (callable_type_t, call_state_t, const gchar* const, const gchar* const, const gchar* const, const gchar* const, callable_obj_t **); +callable_obj_t *create_new_call (callable_type_t, call_state_t, const gchar* const, const gchar* const, const gchar* const, const gchar* const); -void create_new_call_from_details (const gchar *, GHashTable *, callable_obj_t **); +callable_obj_t *create_new_call_from_details (const gchar *, GHashTable *); -void create_history_entry_from_serialized_form (gchar *, callable_obj_t **); +callable_obj_t *create_history_entry_from_serialized_form (const gchar *); void call_add_error (callable_obj_t * call, gpointer dialog); diff --git a/sflphone-client-gnome/src/contacts/calllist.c b/sflphone-client-gnome/src/contacts/calllist.c index ac92b81da3f0f3e0579cdddbe13f85dec1db1227..56e06a8d277b694ffa8d943fd84105f124f657f9 100644 --- a/sflphone-client-gnome/src/contacts/calllist.c +++ b/sflphone-client-gnome/src/contacts/calllist.c @@ -66,7 +66,7 @@ void calllist_add_contact (gchar *contact_name, gchar *contact_phone, contact_ty /* Check if the information is valid */ if (g_strcasecmp (contact_phone, EMPTY_ENTRY) != 0) { - create_new_call (CONTACT, CALL_STATE_DIALING, "", "", contact_name, contact_phone, &new_call); + new_call = create_new_call (CONTACT, CALL_STATE_DIALING, "", "", contact_name, contact_phone); // Attach a pixbuf to a contact if (photo) { diff --git a/sflphone-client-gnome/src/contacts/calltree.c b/sflphone-client-gnome/src/contacts/calltree.c index 8c3f824acbd75b57e1d9a68e9fda7d14994ed349..ac7ec05c0a5fb19192dbb8e0c7dd7ad06bc157df 100644 --- a/sflphone-client-gnome/src/contacts/calltree.c +++ b/sflphone-client-gnome/src/contacts/calltree.c @@ -221,8 +221,7 @@ row_activated (GtkTreeView *tree_view UNUSED, } } else { // If history or contact: double click action places a new call - callable_obj_t* new_call; - create_new_call (CALL, CALL_STATE_DIALING, "", selectedCall->_accountID, selectedCall->_peer_name, selectedCall->_peer_number, &new_call); + callable_obj_t* new_call = create_new_call (CALL, CALL_STATE_DIALING, "", selectedCall->_accountID, selectedCall->_peer_name, selectedCall->_peer_number); calllist_add_call(current_calls, new_call); calltree_add_call (current_calls, new_call, NULL); diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c index 1cc206fdbdbb50ef6d9ed75ddb11dfab0ead104a..88d91cc21ce37fa12980d0a06750d9f5671ddf86 100644 --- a/sflphone-client-gnome/src/dbus/dbus.c +++ b/sflphone-client-gnome/src/dbus/dbus.c @@ -128,14 +128,13 @@ static void new_call_created_cb (DBusGProxy *proxy UNUSED, const gchar *accountID, const gchar *callID, const gchar *to, void *foo UNUSED) { - callable_obj_t *c; const gchar *peer_name = to; const gchar *peer_number = to; DEBUG("DBUS: New Call (%s) created to (%s)", callID, to); - create_new_call(CALL, CALL_STATE_RINGING, callID, accountID, - peer_name, peer_number, &c); + callable_obj_t *c = create_new_call(CALL, CALL_STATE_RINGING, callID, accountID, + peer_name, peer_number); set_timestamp(&c->_time_start); @@ -164,8 +163,8 @@ incoming_call_cb (DBusGProxy *proxy UNUSED, const gchar* accountID, DEBUG ("DBus incoming peer name: %s", peer_name); DEBUG ("DBus incoming peer number: %s", peer_number); - create_new_call (CALL, CALL_STATE_INCOMING, callID, accountID, peer_name, - peer_number, &c); + c = create_new_call (CALL, CALL_STATE_INCOMING, callID, accountID, peer_name, + peer_number); #if GTK_CHECK_VERSION(2,10,0) status_tray_icon_blink (TRUE); popup_main_window(); @@ -298,7 +297,6 @@ call_state_cb (DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* state if ((strcmp (state, "RINGING")) == 0 || (strcmp (state, "CURRENT")) == 0 || (strcmp (state, "RECORD"))) { - callable_obj_t *new_call; GHashTable *call_details; gchar *type; @@ -306,7 +304,7 @@ call_state_cb (DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* state // We fetch the details associated to the specified call call_details = dbus_get_call_details (callID); - create_new_call_from_details (callID, call_details, &new_call); + callable_obj_t *new_call = create_new_call_from_details (callID, call_details); // Restore the callID to be synchronous with the daemon new_call->_callID = g_strdup (callID); diff --git a/sflphone-client-gnome/src/uimanager.c b/sflphone-client-gnome/src/uimanager.c index 32a6c6a844d2b84c8e9d739d790d6be71207b65a..066b8108cad520e7faf62c98efc6eb03e6013c82 100644 --- a/sflphone-client-gnome/src/uimanager.c +++ b/sflphone-client-gnome/src/uimanager.c @@ -678,8 +678,8 @@ call_pick_up (void * foo UNUSED) selectedCall = calltab_get_selected_call(active_calltree); if (selectedCall) { - create_new_call (CALL, CALL_STATE_DIALING, "", "", "", - selectedCall->_peer_number, &new_call); + new_call = create_new_call (CALL, CALL_STATE_DIALING, "", "", "", + selectedCall->_peer_number); calllist_add_call (current_calls, new_call); calltree_add_call (current_calls, new_call, NULL); @@ -835,8 +835,8 @@ call_back (void * foo UNUSED) return; } - create_new_call (CALL, CALL_STATE_DIALING, "", "", - selected_call->_peer_name, selected_call->_peer_number, &new_call); + new_call = create_new_call (CALL, CALL_STATE_DIALING, "", "", + selected_call->_peer_name, selected_call->_peer_number); calllist_add_call (current_calls, new_call); calltree_add_call (current_calls, new_call, NULL); @@ -1015,8 +1015,7 @@ call_mailbox_cb (void) 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); + mailbox_call = create_new_call (CALL, CALL_STATE_DIALING, "", account_id, _ ("Voicemail"), to); g_free(to); g_free(account_id); DEBUG ("TO : %s" , mailbox_call->_peer_number); @@ -1671,17 +1670,13 @@ show_popup_menu_contacts (GtkWidget *my_widget, GdkEventButton *event) static void ok_cb (GtkWidget *widget UNUSED, gpointer userdata) { - - 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; + const gchar * const new_number = (gchar*) gtk_entry_get_text (GTK_ENTRY (editable_num)); + callable_obj_t *original = (callable_obj_t*) userdata; // Create the new call - create_new_call (CALL, CALL_STATE_DIALING, "", original->_accountID, - original->_peer_name, new_number, &modified_call); + callable_obj_t *modified_call = create_new_call (CALL, CALL_STATE_DIALING, "", original->_accountID, + original->_peer_name, new_number); // Update the internal data structure and the GUI calllist_add_call (current_calls, modified_call);