diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 931198c3e87838b1469b859401c42dc2209598ca..9171e779af01c2d7d14b027585de403925b8f36a 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -3339,7 +3339,6 @@ void transfer_client_cb (pjsip_evsub *sub, pjsip_event *event) /* * On incoming NOTIFY, notify application about call transfer progress. */ - pjsip_status_line status_line; _debug("UserAgent: PJSIP_EVSUB_STATE_ACTIVE PJSIP_EVSUB_STATE_TERMINATED"); @@ -3355,15 +3354,16 @@ void transfer_client_cb (pjsip_evsub *sub, pjsip_event *event) } /* Application is not interested with call progress status */ - if (!link or !event) { - _warn ("UserAgent: Either link or event is empty in transfer callback"); + if (!link or !event) return; - } - pjsip_rx_data* r_data = event->body.rx_msg.rdata; + if (!r_data) + return; std::string request = pjsip_rx_data_get_info (r_data); + pjsip_status_line status_line; + /* This better be a NOTIFY request */ if (r_data->msg_info.msg->line.req.method.id == PJSIP_OTHER_METHOD and request.find ("NOTIFY") != std::string::npos) { diff --git a/gnome/configure.ac b/gnome/configure.ac index 2fcd47a98847ca3299baa52dd243d4d036b8d659..580d75553d212ec6be4961b3afe2fc4112646236 100644 --- a/gnome/configure.ac +++ b/gnome/configure.ac @@ -23,7 +23,7 @@ else CFLAGS="$CFLAGS -Wall -Wextra" fi -AC_PROG_CC +AC_PROG_CC_C99 AM_PROG_CC_C_O dnl for per target flags, i.e. test_program_CFLAGS AC_PROG_INSTALL AC_HEADER_STDC diff --git a/gnome/src/actions.c b/gnome/src/actions.c index 55a17aff3a348edccee4cbe64af0f85baf3dbfc7..9898c6d58c32f6f1cfb892fb3e9ff36deee28ba6 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -155,45 +155,30 @@ void status_bar_display_account () { gchar* msg; - account_t* acc; statusbar_pop_message (__MSG_ACCOUNT_DEFAULT); - DEBUG ("status_bar_display_account begin"); - - acc = account_list_get_current (); + account_t *acc = account_list_get_current (); + status_tray_icon_online (acc != NULL); if (acc) { - status_tray_icon_online (TRUE); msg = g_markup_printf_escaped ("%s %s (%s)" , _ ("Using account"), (gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_ALIAS), (gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_TYPE)); } else { - status_tray_icon_online (FALSE); msg = g_markup_printf_escaped (_ ("No registered accounts")); } statusbar_push_message (msg, NULL, __MSG_ACCOUNT_DEFAULT); g_free (msg); - - DEBUG ("status_bar_display_account_end"); } -gboolean +void sflphone_quit () { - gboolean quit = FALSE; - guint count = calllist_get_size (current_calls); - - if (count > 0) { - quit = main_window_ask_quit(); - } else { - quit = TRUE; - } - - if (quit) { + if (calllist_get_size(current_calls) == 0 || main_window_ask_quit()) { // Save the history sflphone_save_history (); @@ -205,8 +190,6 @@ sflphone_quit () //account_list_clean() gtk_main_quit (); } - - return quit; } void @@ -250,8 +233,8 @@ sflphone_hung_up (callable_obj_t * c) #if GTK_CHECK_VERSION(2,10,0) status_tray_icon_blink (FALSE); #endif - stop_call_clock(c); - calltree_update_clock(); + + statusbar_update_clock(""); } /** Internal to actions: Fill account list */ @@ -346,13 +329,8 @@ void sflphone_fill_account_list (void) gboolean sflphone_init (GError **error) { - if (!dbus_connect (error)) { + if (!dbus_connect (error) || !dbus_register (getpid (), "Gtk+ Client", error)) return FALSE; - } - - if (!dbus_register (getpid (), "Gtk+ Client", error)) { - return FALSE; - } abookfactory_init_factory(); @@ -385,9 +363,9 @@ void sflphone_fill_ip2ip_profile (void) ip2ip_profile = (GHashTable *) dbus_get_ip2_ip_details(); } -void sflphone_get_ip2ip_properties (GHashTable **properties) +GHashTable *sflphone_get_ip2ip_properties(void) { - *properties = ip2ip_profile; + return ip2ip_profile; } void @@ -416,7 +394,7 @@ sflphone_hang_up() dbus_hang_up (selectedCall); call_remove_all_errors (selectedCall); selectedCall->_state = CALL_STATE_DIALING; - set_timestamp (&selectedCall->_time_stop); + time (&selectedCall->_time_stop); //if ( (im_window_get_nb_tabs() > 1) && selectedCall->_im_widget && // ! (IM_WIDGET (selectedCall->_im_widget)->containText)) @@ -440,7 +418,7 @@ sflphone_hang_up() case CALL_STATE_TRANSFERT: dbus_hang_up (selectedCall); call_remove_all_errors (selectedCall); - set_timestamp (&selectedCall->_time_stop); + time (&selectedCall->_time_stop); break; default: WARN ("Should not happen in sflphone_hang_up()!"); @@ -453,78 +431,57 @@ sflphone_hang_up() calltree_update_call (history, selectedCall, NULL); - if (selectedCall) - stop_call_clock (selectedCall); - - calltree_update_clock(); + statusbar_update_clock(""); } - -void -sflphone_conference_hang_up() -{ - conference_obj_t * selectedConf = calltab_get_selected_conf(current_calls); - - if (selectedConf) { - dbus_hang_up_conference (selectedConf); - } -} - - void sflphone_pick_up() { - callable_obj_t * selectedCall = NULL; - selectedCall = calltab_get_selected_call (active_calltree); + callable_obj_t *selectedCall = calltab_get_selected_call (active_calltree); DEBUG("SFLphone: Pick up"); - if (selectedCall) { - switch (selectedCall->_state) { - case CALL_STATE_DIALING: - sflphone_place_call (selectedCall); + if (!selectedCall) { + sflphone_new_call(); + return; + } + switch (selectedCall->_state) { + case CALL_STATE_DIALING: + sflphone_place_call (selectedCall); - // if instant messaging window is visible, create new tab (deleted automatically if not used) - if (im_window_is_visible()) - im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL); + // if instant messaging window is visible, create new tab (deleted automatically if not used) + if (im_window_is_visible()) + im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL); - break; - case CALL_STATE_INCOMING: - selectedCall->_history_state = INCOMING; - calltree_update_call (history, selectedCall, NULL); + break; + case CALL_STATE_INCOMING: + selectedCall->_history_state = INCOMING; + calltree_update_call (history, selectedCall, NULL); - // if instant messaging window is visible, create new tab (deleted automatically if not used) - if (selectedCall->_im_widget && im_window_is_visible()) { - im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL); - } + // if instant messaging window is visible, create new tab (deleted automatically if not used) + if (selectedCall->_im_widget && im_window_is_visible()) { + im_widget_display ( (IMWidget **) (&selectedCall->_im_widget), NULL, selectedCall->_callID, NULL); + } - dbus_accept (selectedCall); - stop_notification(); - break; - case CALL_STATE_HOLD: - sflphone_new_call(); - break; - case CALL_STATE_TRANSFERT: - dbus_transfert (selectedCall); - set_timestamp (&selectedCall->_time_stop); - calltree_remove_call(current_calls, selectedCall, NULL); - calllist_remove_call(current_calls, selectedCall->_callID); - break; - case CALL_STATE_CURRENT: - case CALL_STATE_RECORD: - sflphone_new_call(); - break; - case CALL_STATE_RINGING: - sflphone_new_call(); - break; - default: - WARN ("Should not happen in sflphone_pick_up()!"); - break; - } - } else { - sflphone_new_call(); + dbus_accept (selectedCall); + stop_notification(); + break; + case CALL_STATE_TRANSFERT: + dbus_transfert (selectedCall); + time (&selectedCall->_time_stop); + calltree_remove_call(current_calls, selectedCall, NULL); + calllist_remove_call(current_calls, selectedCall->_callID); + break; + case CALL_STATE_CURRENT: + case CALL_STATE_HOLD: + case CALL_STATE_RECORD: + case CALL_STATE_RINGING: + sflphone_new_call(); + break; + default: + WARN ("Should not happen in sflphone_pick_up()!"); + break; } - } void @@ -597,7 +554,7 @@ sflphone_current (callable_obj_t * c) { if (c->_state != CALL_STATE_HOLD) - set_timestamp (&c->_time_start); + time (&c->_time_start); c->_state = CALL_STATE_CURRENT; calltree_update_call (current_calls, c, NULL); @@ -608,7 +565,7 @@ void sflphone_record (callable_obj_t * c) { if (c->_state != CALL_STATE_HOLD) - set_timestamp (&c->_time_start); + time (&c->_time_start); c->_state = CALL_STATE_RECORD; calltree_update_call (current_calls, c, NULL); @@ -654,19 +611,16 @@ sflphone_display_transfer_status (const gchar* message) void sflphone_incoming_call (callable_obj_t * c) { - gchar *msg = ""; - c->_history_state = MISSED; calllist_add_call (current_calls, c); - calllist_add_call (history, c); calltree_add_call (current_calls, c, NULL); - calltree_add_call (history, c, NULL); + update_actions(); calltree_display (current_calls); // Change the status bar if we are dealing with a direct SIP call if (_is_direct_call (c)) { - msg = g_markup_printf_escaped (_ ("Direct SIP call")); + gchar *msg = g_markup_printf_escaped (_ ("Direct SIP call")); statusbar_pop_message (__MSG_ACCOUNT_DEFAULT); statusbar_push_message (msg , NULL, __MSG_ACCOUNT_DEFAULT); g_free (msg); @@ -804,7 +758,7 @@ sflphone_keypad (guint keyval, gchar * key) switch (keyval) { case 65307: /* ESCAPE */ dbus_hang_up (c); - set_timestamp (&c->_time_stop); + time (&c->_time_stop); calltree_update_call (history, c, NULL); break; default: @@ -839,7 +793,7 @@ sflphone_keypad (guint keyval, gchar * key) case 65293: /* ENTER */ case 65421: /* ENTER numpad */ dbus_transfert (c); - set_timestamp (&c->_time_stop); + time (&c->_time_stop); calltree_remove_call(current_calls, c, NULL); calllist_remove_call(current_calls, c->_callID); break; @@ -891,26 +845,15 @@ sflphone_keypad (guint keyval, gchar * key) } } -static int _place_direct_call (const callable_obj_t * c) +static void place_direct_call (const callable_obj_t * c) { - if (c->_state == CALL_STATE_DIALING) { - dbus_place_call (c); - } else { - return -1; - } - - return 0; + assert(c->_state == CALL_STATE_DIALING); } -static int _place_registered_call (callable_obj_t * c) +static int place_registered_call (callable_obj_t * c) { account_t * current = NULL; - if (c == NULL) { - DEBUG ("Actions: Callable_obj_t is NULL in _place_registered_call"); - return -1; - } - if (c->_state != CALL_STATE_DIALING) return -1; @@ -965,82 +908,47 @@ static int _place_registered_call (callable_obj_t * c) c->_history_state = OUTGOING; - calllist_add_call (history, c); - calltree_add_call (history, c, NULL); - return 0; } void sflphone_place_call (callable_obj_t * c) { - gchar *msg = ""; - - if (c == NULL) { - DEBUG ("Actions: Unexpected condition: callable_obj_t is null in %s at %d", __FILE__, __LINE__); - return; - } - DEBUG ("Actions: Placing call with %s @ %s and accountid %s", c->_peer_name, c->_peer_number, c->_accountID); if (_is_direct_call (c)) { - msg = g_markup_printf_escaped (_ ("Direct SIP call")); + gchar *msg = g_markup_printf_escaped (_ ("Direct SIP call")); statusbar_pop_message (__MSG_ACCOUNT_DEFAULT); statusbar_push_message (msg , NULL, __MSG_ACCOUNT_DEFAULT); g_free (msg); - if (_place_direct_call (c) < 0) { - DEBUG ("An error occured while placing direct call in %s at %d", __FILE__, __LINE__); - return; - } - } else { - if (_place_registered_call (c) < 0) { - DEBUG ("An error occured while placing registered call in %s at %d", __FILE__, __LINE__); - return; - } - } + place_direct_call (c); + } else if (place_registered_call (c) < 0) + DEBUG ("An error occured while placing registered call in %s at %d", __FILE__, __LINE__); } void sflphone_detach_participant (const gchar* callID) { - DEBUG ("Action: Detach participant from conference"); - - if (callID == NULL) { - callable_obj_t * selectedCall = calltab_get_selected_call (current_calls); - DEBUG ("Action: Detach participant %s", selectedCall->_callID); - - if (selectedCall->_confID) { - g_free (selectedCall->_confID); - selectedCall->_confID = NULL; - } - - // Instant messaging widget should have been deactivated during the conference - if (selectedCall->_im_widget) - im_widget_update_state (IM_WIDGET (selectedCall->_im_widget), TRUE); - - calltree_remove_call (current_calls, selectedCall, NULL); - calltree_add_call (current_calls, selectedCall, NULL); - dbus_detach_participant (selectedCall->_callID); - } else { - callable_obj_t * selectedCall = calllist_get_call (current_calls, callID); - DEBUG ("Action: Darticipant %s", callID); - - if (selectedCall->_confID) { - g_free (selectedCall->_confID); - selectedCall->_confID = NULL; - } + callable_obj_t * selectedCall; + if (callID == NULL) + selectedCall = calltab_get_selected_call (current_calls); + else + selectedCall = calllist_get_call (current_calls, callID); - // Instant messagin widget should have been deactivated during the conference - if (selectedCall->_im_widget) - im_widget_update_state (IM_WIDGET (selectedCall->_im_widget), TRUE); + DEBUG ("Action: Detach participant %s", selectedCall->_callID); - calltree_remove_call (current_calls, selectedCall, NULL); - calltree_add_call (current_calls, selectedCall, NULL); - dbus_detach_participant (callID); + if (selectedCall->_confID) { + g_free (selectedCall->_confID); + selectedCall->_confID = NULL; } - + // Instant messaging widget should have been deactivated during the conference + if (selectedCall->_im_widget) + im_widget_update_state (IM_WIDGET (selectedCall->_im_widget), TRUE); + calltree_remove_call (current_calls, selectedCall, NULL); + calltree_add_call (current_calls, selectedCall, NULL); + dbus_detach_participant (selectedCall->_callID); } void @@ -1066,7 +974,7 @@ sflphone_add_participant (const gchar* callID, const gchar* confID) return; } - set_timestamp(&call->_time_added); + time(&call->_time_added); iter = calltree_get_gtkiter_from_id(history, (gchar *)confID); @@ -1373,15 +1281,13 @@ static void hist_free_elt(gpointer list) void sflphone_save_history (void) { - gint size; - gint i; QueueElement *current; conference_obj_t *conf; GHashTable *result = g_hash_table_new_full (NULL, g_str_equal, g_free, hist_free_elt); - size = calllist_get_size (history); - for (i = 0; i < size; i++) { + gint size = calllist_get_size (history); + for (gint i = 0; i < size; i++) { current = calllist_get_nth (history, i); if (!current) { WARN("SFLphone: Warning: %dth element is null", i); @@ -1397,14 +1303,14 @@ void sflphone_save_history (void) ERROR("SFLphone: Error: Unknown type for serialization"); break; } - gchar *key = convert_timestamp_to_gchar (current->elem.call->_time_start); + gchar *key = g_strdup_printf ("%i", (int) current->elem.call->_time_start); g_hash_table_replace (result, (gpointer) key, g_slist_append(g_hash_table_lookup(result, key),(gpointer) value)); } size = conferencelist_get_size(history); - for(i = 0; i < size; i++) { + for(gint i = 0; i < size; i++) { conf = conferencelist_get_nth(history, i); if(!conf) { DEBUG("SFLphone: Error: Could not get %dth conference", i); @@ -1412,7 +1318,7 @@ void sflphone_save_history (void) } gchar *value = serialize_history_conference_entry(conf); - gchar *key = convert_timestamp_to_gchar(conf->_time_start); + gchar *key = g_strdup_printf ("%i", (int) conf->_time_start); g_hash_table_replace(result, (gpointer) key, g_slist_append(g_hash_table_lookup(result, key), (gpointer) value)); @@ -1427,7 +1333,6 @@ void sflphone_save_history (void) void sflphone_srtp_sdes_on (callable_obj_t * c) { - c->_srtp_state = SRTP_STATE_SDES_SUCCESS; calltree_update_call (current_calls, c, NULL); @@ -1464,36 +1369,13 @@ sflphone_srtp_zrtp_off (callable_obj_t * c) void sflphone_srtp_zrtp_show_sas (callable_obj_t * c, const gchar* sas, const gboolean verified) { - if (c == NULL) { - DEBUG ("Panic callable obj is NULL in %s at %d", __FILE__, __LINE__); - } - c->_sas = g_strdup (sas); - - if (verified == TRUE) { - c->_srtp_state = SRTP_STATE_ZRTP_SAS_CONFIRMED; - } else { - c->_srtp_state = SRTP_STATE_ZRTP_SAS_UNCONFIRMED; - } + c->_srtp_state = verified ? SRTP_STATE_ZRTP_SAS_CONFIRMED : SRTP_STATE_ZRTP_SAS_UNCONFIRMED; calltree_update_call (current_calls, c, NULL); update_actions(); } -void -sflphone_srtp_zrtp_not_supported (callable_obj_t * c) -{ - DEBUG ("ZRTP not supported"); - main_window_zrtp_not_supported (c); -} - -/* Method on sflphoned */ -void -sflphone_set_confirm_go_clear (callable_obj_t * c) -{ - dbus_set_confirm_go_clear (c); -} - void sflphone_request_go_clear (void) { @@ -1504,14 +1386,6 @@ sflphone_request_go_clear (void) } } -/* Signal sent by sflphoned */ -void -sflphone_confirm_go_clear (callable_obj_t * c) -{ - main_window_confirm_go_clear (c); -} - - void sflphone_call_state_changed (callable_obj_t * c, const gchar * description, const guint code) { diff --git a/gnome/src/actions.h b/gnome/src/actions.h index d37241d54cab8252990488eb96296ef6ddd705bf..5756dec3e609d969ba0ed1809b7e6847c3e9df5c 100644 --- a/gnome/src/actions.h +++ b/gnome/src/actions.h @@ -58,9 +58,8 @@ gboolean sflphone_init () ; /** * Steps when closing the application. Will ask for confirmation if a call is in progress. - * @return TRUE if the user wants to quit, FALSE otherwise. */ -gboolean sflphone_quit () ; +void sflphone_quit () ; /** * Hang up / refuse the current call @@ -172,7 +171,7 @@ void sflphone_fill_ip2ip_profile (void); * @return The internal hash table representing * the settings for the ip2ip profile. */ -void sflphone_get_ip2ip_properties (GHashTable **properties); +GHashTable *sflphone_get_ip2ip_properties(void); /** * Initialize the accounts data structure @@ -263,24 +262,6 @@ void sflphone_srtp_zrtp_off (callable_obj_t * c); */ void sflphone_srtp_zrtp_show_sas (callable_obj_t * c, const gchar* sas, const gboolean verified); -/** - * Called when the remote peer does not support ZRTP - * @param c* The current call - */ -void sflphone_srtp_zrtp_not_supported (callable_obj_t * c); - -/** - * Called when user wants to confirm go clear request. - * @param c* The call to confirm the go clear request. - */ -void sflphone_set_confirm_go_clear (callable_obj_t * c); - -/** - * Called when user wants to confirm go clear request. - * @param c* The call to confirm the go clear request. - */ -void sflphone_confirm_go_clear (callable_obj_t * c); - /** * Called when user wants to clear. * @param c* The call on which to go clear @@ -314,6 +295,4 @@ void sflphone_fill_conference_list (void); void sflphone_conference_on_hold (const conference_obj_t * c); -void sflphone_conference_hang_up(); - #endif diff --git a/gnome/src/callable_obj.c b/gnome/src/callable_obj.c index 262b93bcc097d0aad70e37585ce07a15b41564b5..9a00f2378e971bb8e115ea403bde117f000a7f6f 100644 --- a/gnome/src/callable_obj.c +++ b/gnome/src/callable_obj.c @@ -33,67 +33,61 @@ #include <sflphone_const.h> #include <time.h> #include "contacts/calltree.h" -#include <unistd.h> +#include <unistd.h> +#include <assert.h> gint get_state_callstruct (gconstpointer a, gconstpointer b) { callable_obj_t * c = (callable_obj_t*) a; + call_state_t state = *((call_state_t*)b); - if (c->_state == * ( (call_state_t*) b)) { - return 0; - } else { - return 1; - } + return c->_state == state ? 0 : 1; } gchar* call_get_peer_name (const gchar *format) { - const gchar *end, *name; - - DEBUG (" callable_obj: %s", format); - - end = g_strrstr (format, "<"); - - if (!end) { - return g_strndup (format, 0); - } else { - name = format; - return g_strndup (name, end - name); - } + const gchar *end = g_strrstr (format, "<"); + return g_strndup (format, end ? end - format : 0); } gchar* call_get_peer_number (const gchar *format) { - DEBUG (" callable_obj: %s", format); - - gchar * number = g_strrstr (format, "<") + 1; - gchar * end = g_strrstr (format, ">"); + gchar *number = g_strrstr (format, "<") + 1; + gchar *end = g_strrstr (format, ">"); if (end && number) - number = g_strndup (number, end - number); + return g_strndup (number, end - number); else - number = g_strdup (format); - - return number; + return g_strdup (format); } gchar* call_get_audio_codec (callable_obj_t *obj) { - if (obj) { - gchar * const audio_codec = dbus_get_current_audio_codec_name (obj); - account_t *acc = account_list_get_by_id(obj->_accountID); - if (acc) { - const codec_t * const codec = codec_list_get_by_name (audio_codec, acc->codecs); - if (codec) { - gchar *result = g_markup_printf_escaped ("%s/%i", audio_codec, codec->sample_rate); - g_free (audio_codec); - return result; - } - } - } - - return g_strdup(""); + gchar *ret = NULL; + gchar *audio_codec = NULL; + if (!obj) + goto out; + + audio_codec = dbus_get_current_audio_codec_name (obj); + if (!audio_codec) + goto out; + + account_t *acc = account_list_get_by_id(obj->_accountID); + if (!acc) + goto out; + + const codec_t *const codec = codec_list_get_by_name (audio_codec, acc->codecs); + if (!codec) + goto out; + + ret = g_strdup_printf("%s/%i", audio_codec, codec->sample_rate); + +out: + g_free(audio_codec); + if (ret == NULL) + return g_strdup(""); + return ret; } void call_add_error (callable_obj_t * call, gpointer dialog) @@ -111,74 +105,6 @@ void call_remove_all_errors (callable_obj_t * call) g_ptr_array_foreach (call->_error_dialogs, (GFunc) gtk_widget_destroy, NULL); } -void threaded_clock_incrementer (void *pc) -{ - - callable_obj_t *call = (callable_obj_t *) pc; - - - while (call->clockStarted) { - - int duration; - time_t start, current; - - gdk_threads_enter (); - - set_timestamp (& (call->_time_current)); - - start = call->_time_start; - current = call->_time_current; - - if (current == start) { - g_snprintf (call->_timestr, 20, "00:00"); - - } - - duration = (int) difftime (current, start); - - if (duration / 60 == 0) { - if (duration < 10) { - g_snprintf (call->_timestr, 20, "00:0%d", duration); - } else { - g_snprintf (call->_timestr, 20, "00:%d", duration); - } - } else { - if (duration%60 < 10) { - g_snprintf (call->_timestr, 20, "0%d:0%d", duration/60, duration%60); - } else { - g_snprintf (call->_timestr, 20, "%d:%d", duration/60, duration%60); - } - } - - // Update clock only if call is active (current, hold, recording transfer) - if ( (call->_state != CALL_STATE_INVALID) && - (call->_state != CALL_STATE_INCOMING) && - (call->_state != CALL_STATE_RINGING) && - (call->_state != CALL_STATE_DIALING) && - (call->_state != CALL_STATE_FAILURE) && - (call->_state != CALL_STATE_BUSY)) { - calltree_update_clock(); - } - - // gdk_flush(); - gdk_threads_leave (); - - - usleep (1000000); - } - - DEBUG ("CallableObj: Stopping Thread"); - - g_thread_exit (NULL); - -} - -void stop_call_clock (callable_obj_t *c) -{ - if (c->_type == CALL && c->clockStarted) - c->clockStarted = 0; -} - callable_obj_t *create_new_call (callable_type_t type, call_state_t state, const gchar* const callID, const gchar* const accountID, @@ -187,42 +113,20 @@ callable_obj_t *create_new_call (callable_type_t type, call_state_t state, { DEBUG ("CallableObj: Create new call (Account: %s)", accountID); - // Allocate memory callable_obj_t *obj = g_new0 (callable_obj_t, 1); obj->_error_dialogs = g_ptr_array_new(); - - // Set fields obj->_type = type; obj->_state = state; - - if (g_strcasecmp (callID, "") == 0) - { - obj->_callID = g_new0 (gchar, 30); - if (obj->_callID) - g_sprintf (obj->_callID, "%d", rand()); - } - else - obj->_callID = g_strdup (callID); - + obj->_callID = *callID ? g_strdup (callID) : g_strdup_printf("%d", rand()); obj->_accountID = g_strdup (accountID); - set_timestamp (& (obj->_time_start)); - set_timestamp (& (obj->_time_current)); - set_timestamp (& (obj->_time_stop)); + time (&obj->_time_start); + time (&obj->_time_stop); obj->_peer_name = g_strdup (peer_name); obj->_peer_number = g_strdup (peer_number); obj->_peer_info = get_peer_info (peer_name, peer_number); - obj->clockStarted = 1; - - if (obj->_type == CALL) { - GError *err1 = NULL ; - if (!g_thread_create ( (GThreadFunc) threaded_clock_incrementer, (void *) obj, TRUE, &err1)) { - DEBUG ("Thread creation failed!"); - g_error_free (err1) ; - } - } return obj; } @@ -238,23 +142,21 @@ callable_obj_t *create_new_call_from_details (const gchar *call_id, GHashTable * if (g_strcasecmp (state_str, "CURRENT") == 0) state = CALL_STATE_CURRENT; - else if (g_strcasecmp (state_str, "RINGING") == 0) state = CALL_STATE_RINGING; - else if (g_strcasecmp (state_str, "INCOMING") == 0) state = CALL_STATE_INCOMING; - else if (g_strcasecmp (state_str, "HOLD") == 0) state = CALL_STATE_HOLD; - else if (g_strcasecmp (state_str, "BUSY") == 0) state = CALL_STATE_BUSY; - else state = CALL_STATE_FAILURE; - return create_new_call (CALL, state, call_id, accountID, peer_name, call_get_peer_number (peer_number)); + gchar *number = call_get_peer_number (peer_number); + callable_obj_t *c = create_new_call (CALL, state, call_id, accountID, peer_name, number); + g_free(number); + return c; } callable_obj_t *create_history_entry_from_serialized_form (const gchar *entry) @@ -268,66 +170,37 @@ callable_obj_t *create_history_entry_from_serialized_form (const gchar *entry) const gchar *recordfile = ""; const gchar *confID = ""; const gchar *time_added = ""; - callable_obj_t *new_call; history_state_t history_state = MISSED; - gint token = 0; - gchar ** ptr; - gchar ** ptr_orig; - static const gchar * const delim = "|"; - - ptr = g_strsplit(entry, delim, 10); - ptr_orig = ptr; - while (ptr != NULL && token < 10) { + + gchar **ptr_orig = g_strsplit(entry, "|", 10); + gchar **ptr; + gint token; + for (ptr = ptr_orig, token = 0; ptr && token < 10; token++, ptr++) switch (token) { - case 0: - history_state = get_history_state_from_id (*ptr); - break; - case 1: - peer_number = *ptr; - break; - case 2: - peer_name = *ptr; - break; - case 3: - time_start = *ptr; - break; - case 4: - time_stop = *ptr; - break; - case 5: - callID = *ptr; - break; - case 6: - accountID = *ptr; - break; - case 7: - recordfile = *ptr; - break; - case 8: - confID = *ptr; - break; - case 9: - time_added = *ptr; - break; - default: - break; + case 0: history_state = get_history_state_from_id (*ptr); break; + case 1: peer_number = *ptr; break; + case 2: peer_name = *ptr; break; + case 3: time_start = *ptr; break; + case 4: time_stop = *ptr; break; + case 5: callID = *ptr; break; + case 6: accountID = *ptr; break; + case 7: recordfile = *ptr; break; + case 8: confID = *ptr; break; + case 9: time_added = *ptr; break; + default: break; } - token++; - ptr++; - } - if (g_strcasecmp (peer_name, "empty") == 0) peer_name = ""; - new_call = create_new_call (HISTORY_ENTRY, CALL_STATE_DIALING, callID, accountID, peer_name, peer_number); + callable_obj_t *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); + new_call->_time_start = atoi(time_start); + new_call->_time_stop = atoi(time_stop); new_call->_recordfile = g_strdup(recordfile); new_call->_confID = g_strdup(confID); new_call->_historyConfID = g_strdup(confID); - new_call->_time_added = convert_gchar_to_timestamp(time_start); + new_call->_time_added = atoi(time_start); new_call->_record_is_playing = FALSE; g_strfreev(ptr_orig); @@ -336,10 +209,6 @@ callable_obj_t *create_history_entry_from_serialized_form (const gchar *entry) void free_callable_obj_t (callable_obj_t *c) { - DEBUG ("CallableObj: Free callable object"); - - stop_call_clock (c); - g_free (c->_callID); g_free (c->_confID); g_free (c->_historyConfID); @@ -353,13 +222,6 @@ void free_callable_obj_t (callable_obj_t *c) g_free (c->_recordfile); g_free (c); - - calltree_update_clock(); -} - -void attach_thumbnail (callable_obj_t *call, GdkPixbuf *pixbuf) -{ - call->_contact_thumbnail = pixbuf; } gchar* get_peer_info (const gchar* const number, const gchar* const name) @@ -369,16 +231,9 @@ gchar* get_peer_info (const gchar* const number, const gchar* const name) history_state_t get_history_state_from_id (gchar *indice) { + history_state_t state = atoi(indice); - history_state_t state; - - if (g_strcasecmp (indice, "0") ==0) - state = MISSED; - else if (g_strcasecmp (indice, "1") ==0) - state = INCOMING; - else if (g_strcasecmp (indice, "2") ==0) - state = OUTGOING; - else + if (state > LAST) state = MISSED; return state; @@ -386,34 +241,10 @@ history_state_t get_history_state_from_id (gchar *indice) gchar* get_call_duration (callable_obj_t *obj) { - int duration; - time_t start, end; - - start = obj->_time_start; - end = obj->_time_stop; - - if (start == end) - return g_markup_printf_escaped ("<small>Duration:</small> 0:00"); - - duration = (int) difftime (end, start); - gchar *result; - - if (duration / 60 == 0) { - if (duration < 10) - result = g_markup_printf_escaped ("00:0%i", duration); - else - result = g_markup_printf_escaped ("00:%i", duration); - } else { - if (duration%60 < 10) - result = g_markup_printf_escaped ("%i:0%i" , duration/60 , duration%60); - else - result = g_markup_printf_escaped ("%i:%i" , duration/60 , duration%60); - } - - gchar *old_result = result; - result = g_markup_printf_escaped ("<small>Duration:</small> %s", old_result); - g_free(old_result); - return result; + long duration = difftime (obj->_time_stop, obj->_time_start); + if (duration < 0) + duration = 0; + return g_strdup_printf("<small>Duration:</small> %.2ld:%.2ld" , duration/60 , duration%60); } static const gchar* get_history_id_from_state (history_state_t state) @@ -436,16 +267,15 @@ gchar* serialize_history_call_entry (callable_obj_t *entry) // Need the string form for the history state const gchar *history_state = get_history_id_from_state (entry->_history_state); // and the timestamps - time_start = convert_timestamp_to_gchar (entry->_time_start); - time_stop = convert_timestamp_to_gchar (entry->_time_stop); - time_added = convert_timestamp_to_gchar (entry->_time_added); + time_start = g_strdup_printf ("%i", (int) entry->_time_start); + time_stop = g_strdup_printf ("%i", (int) entry->_time_stop); + time_added = g_strdup_printf ("%i", (int) entry->_time_added); peer_number = entry->_peer_number ? entry->_peer_number : ""; peer_name = (entry->_peer_name && *entry->_peer_name) ? entry->_peer_name : "empty"; account_id = (entry->_accountID && *entry->_accountID) ? entry->_accountID : "empty"; confID = entry->_historyConfID ? entry->_historyConfID : ""; - record_file = entry->_recordfile ? entry->_recordfile : ""; gchar *result = g_strconcat (history_state, separator, @@ -464,63 +294,32 @@ gchar* serialize_history_call_entry (callable_obj_t *entry) return result; } -gchar *get_formatted_start_timestamp (time_t time_start) +gchar *get_formatted_start_timestamp (time_t start) { - enum { UNIX_DAY = 86400, - UNIX_WEEK = UNIX_DAY * 6, - UNIX_TWO_DAYS = UNIX_DAY * 2}; - - struct tm* ptr; - time_t lt, now; - unsigned char str[100]; - - // Fetch the current timestamp - (void) time (&now); - lt = time_start; - - ptr = localtime (<); - - if (now - lt < UNIX_WEEK) { - if (now-lt < UNIX_DAY) { - strftime ( (char *) str, 100, N_ ("today at %R"), (const struct tm *) ptr); + time_t now = time (NULL); + struct tm start_tm; + + localtime_r (&start, &start_tm); + time_t diff = now - start; + if (diff < 0) + diff = 0; + const char *fmt; + + if (diff < 60 * 60 * 24 * 7) { // less than 1 week + if (diff < 60 * 60 * 24) { // less than 1 day + fmt = N_("today at %R"); } else { - if (now - lt < UNIX_TWO_DAYS) { - strftime ( (char *) str, 100, N_ ("yesterday at %R"), (const struct tm *) ptr); - } else { - strftime ( (char *) str, 100, N_ ("%A at %R"), (const struct tm *) ptr); + if (diff < 60 * 60 * 24 * 2) { // less than 2 days + fmt = N_("yesterday at %R"); + } else { // between 2 days and 1 week + fmt = N_("%A at %R"); } } - } else { - strftime ( (char *) str, 100, N_ ("%x at %R"), (const struct tm *) ptr); + } else { // more than 1 week + fmt = N_("%x at %R"); } - // result function of the current locale - return g_markup_printf_escaped ("\n%s\n" , str); -} - -void set_timestamp (time_t *timestamp) -{ - time_t tmp; - - // Set to the current value - (void) time (&tmp); - *timestamp=tmp; + char str[100]; + strftime(str, sizeof str, fmt, &start_tm); + return g_markup_printf_escaped ("%s\n", str); } - -gchar* convert_timestamp_to_gchar (const time_t timestamp) -{ - return g_markup_printf_escaped ("%i", (int) timestamp); -} - -time_t convert_gchar_to_timestamp (const gchar *timestamp) -{ - return (time_t) atoi (timestamp); -} - -gchar* -get_peer_information (callable_obj_t *c) -{ - return *c->_peer_name ? c->_peer_name : c->_peer_number; -} - - diff --git a/gnome/src/callable_obj.h b/gnome/src/callable_obj.h index e0eb7ccdf5f0d36525c0008d58a44c0cec3c4407..3c4c42ec416e51fad4b59f5180d4efd469d08f83 100644 --- a/gnome/src/callable_obj.h +++ b/gnome/src/callable_obj.h @@ -109,9 +109,7 @@ typedef struct { gchar* _historyConfID; // Persistent conf id to be stored in history gchar* _accountID; // The account the call is made with time_t _time_start; // The timestamp the call was initiating - time_t _time_current; // Clock increment to display call's elapsed time time_t _time_stop; // The timestamp the call was over - gchar _timestr[20]; // The timestamp as a string format for disply in statusbar history_state_t _history_state; // The history state if necessary srtp_state_t _srtp_state; // The state of security on the call gchar* _srtp_cipher; // Cipher used for the srtp session @@ -164,10 +162,7 @@ typedef struct { /* Associated IM widget */ GtkWidget *_im_widget; - int clockStarted; - time_t _time_added; - } 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); @@ -206,15 +201,9 @@ gchar* call_get_peer_name (const gchar*); */ gchar* call_get_peer_number (const gchar*); -void -attach_thumbnail (callable_obj_t *, GdkPixbuf *); - void free_callable_obj_t (callable_obj_t *c); -void -stop_call_clock (callable_obj_t *c); - gchar* get_peer_info (const gchar* const, const gchar* const); history_state_t get_history_state_from_id (gchar *indice); @@ -225,14 +214,6 @@ gchar* serialize_history_call_entry(callable_obj_t *entry); gchar* get_formatted_start_timestamp (time_t); -void set_timestamp (time_t*); - -gchar* convert_timestamp_to_gchar (time_t); - -time_t convert_gchar_to_timestamp (const gchar*); - gchar* call_get_audio_codec (callable_obj_t *obj); -gchar* get_peer_information (callable_obj_t *c); - #endif diff --git a/gnome/src/conference_obj.c b/gnome/src/conference_obj.c index 6cfc10cd460676f8145b9a15c1227314f1aa5f81..f2b2dc3d1d5337f00746a762f63cb9047d45507d 100644 --- a/gnome/src/conference_obj.c +++ b/gnome/src/conference_obj.c @@ -227,8 +227,8 @@ gchar *serialize_history_conference_entry(conference_obj_t *entry) confID = entry->_confID; - time_start = convert_timestamp_to_gchar(entry->_time_start); - time_stop = convert_timestamp_to_gchar(entry->_time_stop); + time_start = g_strdup_printf ("%i", (int) entry->_time_start); + time_stop = g_strdup_printf ("%i", (int) entry->_time_stop); peer_name = (entry->_confID == NULL || g_strcasecmp(entry->_confID, "") == 0) ? "empty": entry->_confID; @@ -314,8 +314,8 @@ conference_obj_t *create_conference_history_entry_from_serialized(gchar *entry) // create a new empty conference conference_obj_t *conf = create_new_conference(state, confID); - conf->_time_start = convert_gchar_to_timestamp(time_start); - conf->_time_stop = convert_gchar_to_timestamp(time_stop); + conf->_time_start = atoi(time_start); + conf->_time_stop = atoi(time_stop); conf->_recordfile = g_strdup(recordfile); return conf; diff --git a/gnome/src/contacts/addrbookfactory.c b/gnome/src/contacts/addrbookfactory.c index c1882fb082ebec9ec1d9e570d7698f2d7ba4e295..08a9319ce1e00a586eec615967c18c0142971c8a 100644 --- a/gnome/src/contacts/addrbookfactory.c +++ b/gnome/src/contacts/addrbookfactory.c @@ -55,69 +55,57 @@ void abookfactory_scan_directory(AddrBookFactory *factory UNUSED) { } -void abookfactory_load_module(AddrBookFactory *factory) { - - AddrBookHandle *ab; - void *handle; - +void abookfactory_load_module(AddrBookFactory *factory) +{ gchar *plugindir = PLUGINS_DIR; gchar *pluginpath = g_strdup_printf("%s/libevladdrbook.so", plugindir); DEBUG("AddressbookFactory: Loading addressbook: %s", pluginpath); - handle = dlopen(pluginpath, RTLD_LAZY); + void *handle = dlopen(pluginpath, RTLD_LAZY); g_free(pluginpath); if(handle == NULL) { ERROR("AddressbookFactory: Error: Could not load addressbook"); return; } - ab = g_malloc(sizeof(AddrBookHandle)); + AddrBookHandle *ab = g_malloc(sizeof(AddrBookHandle)); ab->init = dlsym(handle, "addressbook_init"); - if(ab->init == NULL) { + if(ab->init == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook_init function"); - } ab->is_ready = dlsym(handle, "addressbook_is_ready"); - if(ab->is_ready == NULL) { + if(ab->is_ready == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_is_ready function"); - } ab->is_enabled = dlsym(handle, "addressbook_is_enabled"); - if(ab->is_enabled == NULL) { + if(ab->is_enabled == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_is_enabled function"); - } ab->is_active = dlsym(handle, "addressbook_is_active"); - if(ab->is_active == NULL) { + if(ab->is_active == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_is_active function"); - } ab->search = dlsym(handle, "addressbook_search"); - if(ab->search == NULL) { + if(ab->search == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_search function"); - } ab->get_books_data = dlsym(handle, "addressbook_get_books_data"); - if(ab->get_books_data == NULL) { + if(ab->get_books_data == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_get_books_data function"); - } ab->get_book_data_by_uid = dlsym(handle, "addressbook_get_book_data_by_uid"); - if(ab->get_book_data_by_uid == NULL) { + if(ab->get_book_data_by_uid == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_get_books_data_by_uid function"); - } ab->set_current_book = dlsym(handle, "addressbook_set_current_book"); - if(ab->set_current_book == NULL) { + if(ab->set_current_book == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_ser_current_book"); - } ab->set_search_type = dlsym(handle, "addressbook_set_search_type"); - if(ab->set_search_type == NULL) { + if(ab->set_search_type == NULL) ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_set_search_type"); - } ab->search_cb = handler_async_search; @@ -141,55 +129,43 @@ free_hit (Hit *h) static void handler_async_search (GList *hits, gpointer user_data) { - GList *i; - GdkPixbuf *photo = NULL; - AddressBook_Config *addressbook_config; - callable_obj_t *j; - - printf("Addressbook: callback async search\n"); - - // freeing calls - while ( (j = (callable_obj_t *) g_queue_pop_tail (contacts->callQueue)) != NULL) { - free_callable_obj_t (j); - } // Retrieve the address book parameters - addressbook_config = (AddressBook_Config*) user_data; + AddressBook_Config *addressbook_config = user_data; // reset previous results calltree_reset (contacts); calllist_reset (contacts); for (i = hits; i != NULL; i = i->next) { - - Hit *entry; - entry = i->data; - - if (entry) { - // Get the photo - if (addressbook_display (addressbook_config, - ADDRESSBOOK_DISPLAY_CONTACT_PHOTO)) - photo = entry->photo; - - // Create entry for business phone information - if (addressbook_display (addressbook_config, - ADDRESSBOOK_DISPLAY_PHONE_BUSINESS)) - calllist_add_contact (entry->name, entry->phone_business, - CONTACT_PHONE_BUSINESS, photo); - - // Create entry for home phone information - if (addressbook_display (addressbook_config, - ADDRESSBOOK_DISPLAY_PHONE_HOME)) - calllist_add_contact (entry->name, entry->phone_home, - CONTACT_PHONE_HOME, photo); - - // Create entry for mobile phone iddnformation - if (addressbook_display (addressbook_config, - ADDRESSBOOK_DISPLAY_PHONE_MOBILE)) - calllist_add_contact (entry->name, entry->phone_mobile, - CONTACT_PHONE_MOBILE, photo); - } + GdkPixbuf *photo = NULL; + Hit *entry = i->data; + if (!entry) + continue; + + // Get the photo + if (addressbook_display (addressbook_config, + ADDRESSBOOK_DISPLAY_CONTACT_PHOTO)) + photo = entry->photo; + + // Create entry for business phone information + if (addressbook_display (addressbook_config, + ADDRESSBOOK_DISPLAY_PHONE_BUSINESS)) + calllist_add_contact (entry->name, entry->phone_business, + CONTACT_PHONE_BUSINESS, photo); + + // Create entry for home phone information + if (addressbook_display (addressbook_config, + ADDRESSBOOK_DISPLAY_PHONE_HOME)) + calllist_add_contact (entry->name, entry->phone_home, + CONTACT_PHONE_HOME, photo); + + // Create entry for mobile phone iddnformation + if (addressbook_display (addressbook_config, + ADDRESSBOOK_DISPLAY_PHONE_MOBILE)) + calllist_add_contact (entry->name, entry->phone_mobile, + CONTACT_PHONE_MOBILE, photo); free_hit (entry); } diff --git a/gnome/src/contacts/calllist.c b/gnome/src/contacts/calllist.c index 74d93caeaea15eacee918e661b30a16cd8f3c7e1..3cd3cbcc476d4d224757bdf2cec1f1055140193e 100644 --- a/gnome/src/contacts/calllist.c +++ b/gnome/src/contacts/calllist.c @@ -36,70 +36,47 @@ static gint is_callID_callstruct(gconstpointer a, gconstpointer b) { - QueueElement *c = (QueueElement *) a; - callable_obj_t *call; - - if(c == NULL) { - return 1; - } - - if(c->type != HIST_CALL) { + const QueueElement *c = a; + if(c == NULL || c->type != HIST_CALL) return 1; - } - - call = c->elem.call; - if(g_strcasecmp(call->_callID, (const gchar *) b) == 0) { - return 0; - } - else { - return 1; - } + return g_strcasecmp(c->elem.call->_callID, (const gchar *) b); } // TODO : sflphoneGTK : try to do this more generic void calllist_add_contact (gchar *contact_name, gchar *contact_phone, contact_type_t type, GdkPixbuf *photo) { - - callable_obj_t *new_call; - GdkPixbuf *pixbuf; - /* Check if the information is valid */ - if (g_strcasecmp (contact_phone, EMPTY_ENTRY) != 0) { - new_call = create_new_call (CONTACT, CALL_STATE_DIALING, "", "", contact_name, contact_phone); + if (g_strcasecmp (contact_phone, EMPTY_ENTRY) == 0) + return; - // Attach a pixbuf to a contact - if (photo) { - attach_thumbnail (new_call, gdk_pixbuf_copy (photo)); - } else { - switch (type) { - case CONTACT_PHONE_BUSINESS: - pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/users.svg", NULL); - break; - case CONTACT_PHONE_HOME: - pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/home.svg", NULL); - break; - case CONTACT_PHONE_MOBILE: - pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/phone.svg", NULL); - break; - default: - pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/contact_default.svg", NULL); - break; - } + callable_obj_t *new_call = create_new_call (CONTACT, CALL_STATE_DIALING, "", "", contact_name, contact_phone); - attach_thumbnail (new_call, pixbuf); + // Attach a pixbuf to a contact + if (photo) { + new_call->_contact_thumbnail = gdk_pixbuf_copy (photo); + } else { + GdkPixbuf *pixbuf; + switch (type) { + case CONTACT_PHONE_BUSINESS: + pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/users.svg", NULL); + break; + case CONTACT_PHONE_HOME: + pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/home.svg", NULL); + break; + case CONTACT_PHONE_MOBILE: + pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/phone.svg", NULL); + break; + default: + pixbuf = gdk_pixbuf_new_from_file (ICONS_DIR "/contact_default.svg", NULL); + break; } - calllist_add_call (contacts, new_call); - calltree_add_call (contacts, new_call, NULL); + new_call->_contact_thumbnail = pixbuf; } -} -void -calllist_init (calltab_t* tab) -{ - tab->callQueue = g_queue_new (); - tab->selectedCall = NULL; + calllist_add_call (contacts, new_call); + calltree_add_call (contacts, new_call, NULL); } /* @@ -132,10 +109,8 @@ calllist_reset (calltab_t* tab) void calllist_add_history_call (callable_obj_t *obj) { - QueueElement *element; - if (eel_gconf_get_integer (HISTORY_ENABLED)) { - element = (QueueElement *)malloc(sizeof(QueueElement)); + QueueElement *element = malloc(sizeof(QueueElement)); element->type = HIST_CALL; element->elem.call = obj; g_queue_push_tail (history->callQueue, (gpointer) element); @@ -145,10 +120,8 @@ void calllist_add_history_call (callable_obj_t *obj) void calllist_add_history_conference(conference_obj_t *obj) { - QueueElement *element; - if(eel_gconf_get_integer (HISTORY_ENABLED)) { - element = (QueueElement *)malloc(sizeof(QueueElement)); + QueueElement *element = malloc(sizeof(QueueElement)); element->type = HIST_CONFERENCE; element->elem.conf = obj; g_queue_push_tail (history->callQueue, (gpointer) element); @@ -159,11 +132,9 @@ void calllist_add_history_conference(conference_obj_t *obj) void calllist_add_call (calltab_t* tab, callable_obj_t * c) { - QueueElement *element; - DEBUG("Calllist: Add Call %s", c->_callID); - element = (QueueElement *)malloc(sizeof(QueueElement)); + QueueElement *element = malloc(sizeof(QueueElement)); element->type = HIST_CALL; element->elem.call = c; g_queue_push_tail (tab->callQueue, (gpointer) element); @@ -172,12 +143,8 @@ calllist_add_call (calltab_t* tab, callable_obj_t * c) void calllist_clean_history (void) { - guint i; guint size = calllist_get_size (history); - - DEBUG ("CallList: History list size %d", size); - - for (i = 0 ; i < size; i++) { + for (guint i = 0 ; i < size; i++) { QueueElement* c = calllist_get_nth (history , i); if(c->type == HIST_CALL) { calltree_remove_call (history, c->elem.call, NULL); @@ -191,36 +158,34 @@ calllist_clean_history (void) calllist_reset (history); } -// TODO : sflphoneGTK : try to do this more generic void calllist_remove_from_history (callable_obj_t* c) { calllist_remove_call (history, c->_callID); calltree_remove_call (history, c, NULL); - DEBUG ("CallList: Size of history = %d" , calllist_get_size (history)); } void calllist_remove_call (calltab_t* tab, const gchar * callID) { - QueueElement *element; - GList *c; - DEBUG("CallList: Remove call %s from list", callID); - c = g_queue_find_custom (tab->callQueue, callID, is_callID_callstruct); + GList *c = g_queue_find_custom (tab->callQueue, callID, is_callID_callstruct); if(c == NULL) { DEBUG("CallList: Could not remove call %s", callID); return; } - element = (QueueElement *)c->data; + QueueElement *element = (QueueElement *)c->data; if(element->type != HIST_CALL) { ERROR("CallList: Error: Element %s is not a call", callID); return; } g_queue_remove (tab->callQueue, element); + + calllist_add_call (history, element->elem.call); + calltree_add_call (history, element->elem.call, NULL); } @@ -228,13 +193,7 @@ callable_obj_t * calllist_get_by_state (calltab_t* tab, call_state_t state) { GList * c = g_queue_find_custom (tab->callQueue, &state, get_state_callstruct); - - if (c) { - return (callable_obj_t *) c->data; - } else { - return NULL; - } - + return c ? c->data : NULL; } guint @@ -252,9 +211,6 @@ calllist_get_nth (calltab_t* tab, guint n) callable_obj_t * calllist_get_call (calltab_t* tab, const gchar * callID) { - QueueElement *element; - callable_obj_t *call; - DEBUG("CallList: Get call: %s", callID); GList * c = g_queue_find_custom (tab->callQueue, callID, is_callID_callstruct); @@ -263,13 +219,11 @@ calllist_get_call (calltab_t* tab, const gchar * callID) return NULL; } - element = (QueueElement *)c->data; + QueueElement *element = c->data; if(element->type != HIST_CALL) { ERROR("CallList: Error: Element %s is not a call", callID); return NULL; } - call = element->elem.call; - - return call; + return element->elem.call; } diff --git a/gnome/src/contacts/calllist.h b/gnome/src/contacts/calllist.h index ea7e087df3fb78e6857e12f3c7c96460f5058026..288162457bfe439843e2c1ed4a1ae30343b4e5af 100644 --- a/gnome/src/contacts/calllist.h +++ b/gnome/src/contacts/calllist.h @@ -73,10 +73,6 @@ void calllist_add_history_call (callable_obj_t *obj); void calllist_add_history_conference (conference_obj_t *obj); -/** This function initialize a call list. */ -void -calllist_init (calltab_t* tab); - /** This function empty and free the call list. */ void calllist_clean (calltab_t* tab); diff --git a/gnome/src/contacts/calltab.c b/gnome/src/contacts/calltab.c index 148dda4e37d288a442a833d64346f51d2c7a751c..0df4e7dda1b3b00564ae3a7b5fb46ea6e13d33e6 100644 --- a/gnome/src/contacts/calltab.c +++ b/gnome/src/contacts/calltab.c @@ -40,7 +40,9 @@ calltab_t* calltab_init (gboolean searchbar_type, gchar *name) ret->_name = g_strdup (name); calltree_create (ret, searchbar_type); - calllist_init (ret); + + ret->callQueue = g_queue_new (); + ret->selectedCall = NULL; return ret; } @@ -84,18 +86,6 @@ calltab_get_selected_conf (calltab_t *tab) return tab->selectedConf; } -void -calltab_unselect_all(calltab_t *tab) -{ - if(tab == NULL) { - ERROR("CallTab: Tab is NULL"); - return; - } - - tab->selectedCall = NULL; - tab->selectedConf = NULL; -} - void calltab_create_searchbar (calltab_t* tab) { diff --git a/gnome/src/contacts/calltab.h b/gnome/src/contacts/calltab.h index a428bad26ea56d2255c2350db02199816b74c167..e9d0e70b1afe2da2044954a62d158dcc9b33f0ea 100644 --- a/gnome/src/contacts/calltab.h +++ b/gnome/src/contacts/calltab.h @@ -64,8 +64,6 @@ calltab_get_selected_call (calltab_t *); conference_obj_t * calltab_get_selected_conf (calltab_t *); -void calltab_unselect_all(calltab_t *); - void calltab_create_searchbar (calltab_t *); diff --git a/gnome/src/contacts/calltree.c b/gnome/src/contacts/calltree.c index 2cb65c5beb262a98c74283a2de5f05b8060bccd6..3972a511b546f03ba7f9c854405547b2a004d327 100644 --- a/gnome/src/contacts/calltree.c +++ b/gnome/src/contacts/calltree.c @@ -329,9 +329,7 @@ row_single_click (GtkTreeView *tree_view UNUSED, void * data UNUSED) displaySasOnce = g_hash_table_lookup (account_details->properties, ACCOUNT_DISPLAY_SAS_ONCE); DEBUG ("Display SAS once %s", displaySasOnce); } else { - GHashTable * properties = NULL; - sflphone_get_ip2ip_properties (&properties); - + GHashTable *properties = sflphone_get_ip2ip_properties(); if (properties != NULL) { displaySasOnce = g_hash_table_lookup (properties, ACCOUNT_DISPLAY_SAS_ONCE); DEBUG ("IP2IP displaysasonce %s", displaySasOnce); @@ -377,25 +375,22 @@ row_single_click (GtkTreeView *tree_view UNUSED, void * data UNUSED) static gboolean button_pressed (GtkWidget* widget, GdkEventButton *event, gpointer user_data UNUSED) { - if (event->button == 3 && event->type == GDK_BUTTON_PRESS) { - if (active_calltree == current_calls) { - show_popup_menu (widget, event); - return TRUE; - } else if (active_calltree == history) { - show_popup_menu_history (widget, event); - return TRUE; - } else { - show_popup_menu_contacts (widget, event); - return TRUE; - } - } + if (event->button != 3 || event->type != GDK_BUTTON_PRESS) + return FALSE; - return FALSE; + if (active_calltree == current_calls) + show_popup_menu (widget, event); + else if (active_calltree == history) + show_popup_menu_history (widget, event); + else + show_popup_menu_contacts (widget, event); + + return TRUE; } static gchar * -calltree_display_call_info (callable_obj_t * c, CallDisplayType display_type, const gchar * const audio_codec) +calltree_display_call_info (callable_obj_t * c, CallDisplayType display_type, const gchar *const audio_codec) { gchar display_number[strlen(c->_peer_number) + 1]; strcpy(display_number, c->_peer_number); @@ -419,7 +414,7 @@ calltree_display_call_info (callable_obj_t * c, CallDisplayType display_type, co details = ""; } - gchar *desc = g_markup_printf_escaped ("<b>%s</b> <i>%s</i>", name, details); + gchar *desc = g_markup_printf_escaped ("<b>%s</b> <i>%s</i> ", name, details); gchar *suffix = NULL; switch (display_type) { @@ -609,8 +604,6 @@ void calltree_remove_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) { GtkTreeIter iter; - GValue val; - callable_obj_t * iterCall; GtkTreeStore* store = tab->store; if (!c) @@ -619,17 +612,15 @@ calltree_remove_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) DEBUG ("CallTree: Remove call %s", c->_callID); int nbChild = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), parent); - int i; - - for (i = 0; i < nbChild; i++) { + for (int i = 0; i < nbChild; i++) { if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter, parent, i)) { if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (store), &iter)) calltree_remove_call (tab, c, &iter); - val.g_type = 0; + GValue val = { .g_type = 0 }; gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, COLUMN_ACCOUNT_PTR, &val); - iterCall = (callable_obj_t*) g_value_get_pointer (&val); + callable_obj_t * iterCall = g_value_get_pointer (&val); g_value_unset (&val); if (iterCall == c) @@ -637,16 +628,12 @@ calltree_remove_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) } } - callable_obj_t * selectedCall = calltab_get_selected_call (tab); - - if (selectedCall == c) + if (calltab_get_selected_call (tab) == c) calltab_select_call (tab, NULL); update_actions(); - calltree_update_clock(); - - DEBUG ("Calltree remove call ended"); + statusbar_update_clock(""); } void @@ -674,8 +661,7 @@ calltree_update_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) if (g_strcasecmp (g_hash_table_lookup (account_details->properties, ACCOUNT_ZRTP_DISPLAY_SAS),"false") == 0) display_sas = FALSE; } else { - GHashTable * properties = NULL; - sflphone_get_ip2ip_properties (&properties); + GHashTable * properties = sflphone_get_ip2ip_properties(); if (properties != NULL) { srtp_enabled = g_hash_table_lookup (properties, ACCOUNT_SRTP_ENABLED); @@ -863,9 +849,7 @@ void calltree_add_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) if (c) { account_details = account_list_get_by_id (c->_accountID); - if (account_details == NULL) - ERROR("CallTree: Could not find account %s", c->_accountID); - else { + if (account_details) { srtp_enabled = g_hash_table_lookup (account_details->properties, ACCOUNT_SRTP_ENABLED); key_exchange = g_hash_table_lookup (account_details->properties, ACCOUNT_KEY_EXCHANGE); } @@ -938,7 +922,7 @@ void calltree_add_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent) gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (tab->view)), &iter); - history_reinit (history); + //history_init(); } void calltree_add_history_entry (callable_obj_t *c, GtkTreeIter *parent) @@ -1019,7 +1003,7 @@ void calltree_add_history_entry (callable_obj_t *c, GtkTreeIter *parent) gtk_tree_view_set_model (GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history->store)); - history_reinit (history); + history_search(); } @@ -1210,50 +1194,47 @@ void calltree_remove_conference (calltab_t* tab, const conference_obj_t* conf, G conference_obj_t *tempconf = NULL; GtkTreeStore* store = tab->store; int nbParticipant; - int i, j; DEBUG ("CallTree: Remove conference %s", conf->_confID); int nbChild = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), parent); - for (i = 0; i < nbChild; i++) { - - if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_parent, parent, i)) { - if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (store), &iter_parent)) { + for (int i = 0; i < nbChild; i++) { + if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_parent, parent, i)) + continue; + if (!gtk_tree_model_iter_has_child (GTK_TREE_MODEL (store), &iter_parent)) + continue; - calltree_remove_conference (tab, conf, &iter_parent); + calltree_remove_conference (tab, conf, &iter_parent); - confval.g_type = 0; - gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter_parent, COLUMN_ACCOUNT_PTR, &confval); + confval.g_type = 0; + gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter_parent, COLUMN_ACCOUNT_PTR, &confval); - tempconf = (conference_obj_t*) g_value_get_pointer (&confval); - g_value_unset (&confval); + tempconf = (conference_obj_t*) g_value_get_pointer (&confval); + g_value_unset (&confval); - if (tempconf == conf) { + if (tempconf != conf) + continue; - nbParticipant = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), &iter_parent); - DEBUG ("CallTree: nbParticipant: %d", nbParticipant); + nbParticipant = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), &iter_parent); + DEBUG ("CallTree: nbParticipant: %d", nbParticipant); - for (j = 0; j < nbParticipant; j++) { - callable_obj_t *call = NULL; - - if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_child, &iter_parent, j)) { + for (int j = 0; j < nbParticipant; j++) { + if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_child, &iter_parent, j)) + continue; - callval.g_type = 0; - gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter_child, COLUMN_ACCOUNT_PTR, &callval); + callval.g_type = 0; + gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter_child, COLUMN_ACCOUNT_PTR, &callval); - call = (callable_obj_t*) g_value_get_pointer (&callval); - g_value_unset (&callval); + callable_obj_t *call = g_value_get_pointer (&callval); + g_value_unset (&callval); - // do not add back call in history calltree when cleaning it - if (call && tab != history) - calltree_add_call (tab, call, NULL); - } - } - gtk_tree_store_remove (store, &iter_parent); - } - } + // do not add back call in history calltree when cleaning it + if (call && tab != history) + calltree_add_call (tab, call, NULL); } + + gtk_tree_store_remove (store, &iter_parent); } update_actions(); @@ -1262,7 +1243,7 @@ void calltree_remove_conference (calltab_t* tab, const conference_obj_t* conf, G void calltree_add_history_conference(conference_obj_t *conf) { GdkPixbuf *pixbuf = NULL; - const gchar *description = "Conference: "; + const gchar *description = "Conference: \n"; GtkTreeIter iter; GSList *conference_participant; @@ -1290,7 +1271,7 @@ void calltree_add_history_conference(conference_obj_t *conf) if (call) calltree_add_history_entry(call, &iter); else - ERROR("ConferenceList: Error: Could not find call %s", call_id); + ERROR("ConferenceList: Error: Could not find call \"%s\"", call_id); conference_participant = conference_next_participant(conference_participant); } @@ -1351,31 +1332,31 @@ void calltree_display (calltab_t *tab) } -void calltree_update_clock() +gboolean calltree_update_clock(gpointer data UNUSED) { + char timestr[20]; + char *msg = ""; + long duration; callable_obj_t *c = calltab_get_selected_call (current_calls); - if (!c) { - statusbar_update_clock (""); - return; - } - - if (!(c->_timestr)) { - statusbar_update_clock (""); - return; - } - - if ((c->_state != CALL_STATE_INVALID) && - (c->_state != CALL_STATE_INCOMING) && - (c->_state != CALL_STATE_RINGING) && - (c->_state != CALL_STATE_DIALING) && - (c->_state != CALL_STATE_FAILURE) && - (c->_state != CALL_STATE_BUSY)) { + if (c) + switch (c->_state) { + case CALL_STATE_INVALID: + case CALL_STATE_INCOMING: + case CALL_STATE_RINGING: + case CALL_STATE_FAILURE: + case CALL_STATE_DIALING: + case CALL_STATE_BUSY: + break; + default: + duration = difftime (time(NULL), c->_time_start); + if (duration < 0) + duration = 0; + g_snprintf (timestr, sizeof(timestr), "%.2ld:%.2ld", duration / 60, duration % 60); + msg = timestr; + } - // TODO this make the whole thing crash... - statusbar_update_clock (c->_timestr); - } else - statusbar_update_clock (""); + statusbar_update_clock (msg); } @@ -1752,32 +1733,23 @@ static void menuitem_response( gchar *string ) GtkTreeIter calltree_get_gtkiter_from_id(calltab_t *tab, gchar *id) { GtkTreeIter iter; - GValue val; - GtkTreeModel *tree_model; - conference_obj_t *conf; - callable_obj_t *call; - - tree_model = GTK_TREE_MODEL(tab->store); + GtkTreeModel *tree_model = GTK_TREE_MODEL(tab->store); gtk_tree_model_get_iter_first(tree_model, &iter); while(gtk_tree_model_iter_next(tree_model, &iter)) { - val.g_type = 0; + GValue val = { .g_type = 0 }; gtk_tree_model_get_value (tree_model, &iter, COLUMN_ACCOUNT_PTR, &val); if(gtk_tree_model_iter_has_child(tree_model, &iter)) { - conf = (conference_obj_t *) g_value_get_pointer (&val); - - if(g_strcmp0(conf->_confID, id) == 0) { + conference_obj_t *conf = (conference_obj_t *) g_value_get_pointer (&val); + if(g_strcmp0(conf->_confID, id) == 0) return iter; - } } else { - call = (callable_obj_t *) g_value_get_pointer(&val); - - if(g_strcmp0(call->_callID, id) == 0) { + callable_obj_t *call = (callable_obj_t *) g_value_get_pointer(&val); + if(g_strcmp0(call->_callID, id) == 0) return iter; - } } } diff --git a/gnome/src/contacts/calltree.h b/gnome/src/contacts/calltree.h index faf3d61234927ffb57b41a29db91e9bb0b585c92..b41d3bdff36389fefa939833a067927a09aae5f7 100644 --- a/gnome/src/contacts/calltree.h +++ b/gnome/src/contacts/calltree.h @@ -118,10 +118,10 @@ void row_activated (GtkTreeView *, GtkTreePath *, GtkTreeViewColumn *, void *); /** - * Update elapced time based on selected calltree's call + * Update elapsed time based on selected calltree's call */ -void -calltree_update_clock(); +gboolean +calltree_update_clock(gpointer); /** * Get the iter to a row provided the callID/confID diff --git a/gnome/src/contacts/history.c b/gnome/src/contacts/history.c index 5aa4ef2880c9037a800e5e9856633ede289638be..c7899de90a9e5e8dad8ecccbb4be99605d9fa755 100644 --- a/gnome/src/contacts/history.c +++ b/gnome/src/contacts/history.c @@ -33,92 +33,68 @@ #include <searchbar.h> #include <calltab.h> -GtkTreeModel* history_filter; -GtkWidget * history_searchbar_widget; - -static GtkTreeModel* history_create_filter (GtkTreeModel*); -static gboolean history_is_visible (GtkTreeModel*, GtkTreeIter*, gpointer); - -void history_search (SearchType search_type UNUSED) -{ - if (history_filter != NULL) { - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (history_filter)); - } -} - -void history_init (void) -{ - history_filter = history_create_filter (GTK_TREE_MODEL (history->store)); - gtk_tree_view_set_model (GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history_filter)); -} - -void history_reinit (calltab_t* history) -{ - history_filter = history_create_filter (GTK_TREE_MODEL (history->store)); - gtk_tree_view_set_model (GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history_filter)); -} - - -void history_set_searchbar_widget (GtkWidget *searchbar) -{ - history_searchbar_widget = searchbar; -} - -static GtkTreeModel* history_create_filter (GtkTreeModel* child) -{ - GtkTreeModel* ret; - - DEBUG ("Create Filter"); - ret = gtk_tree_model_filter_new (child, NULL); - gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (ret), history_is_visible, NULL, NULL); - return GTK_TREE_MODEL (ret); -} +static GtkTreeModel *history_filter; +static GtkEntry *history_searchbar_widget; static gboolean history_is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED) { - GValue val, obj; - callable_obj_t *history_entry = NULL; gchar* text = NULL; - gchar* search = (gchar*) gtk_entry_get_text (GTK_ENTRY (history_searchbar_widget)); - - memset (&val, 0, sizeof (val)); - memset (&obj, 0, sizeof (obj)); - // Fetch the call description + GValue val; + memset(&val, 0, sizeof val); gtk_tree_model_get_value (GTK_TREE_MODEL (model), iter, 1, &val); - if (G_VALUE_HOLDS_STRING (&val)) { + if (G_VALUE_HOLDS_STRING (&val)) text = (gchar *) g_value_get_string (&val); - } // Fetch the call type + GValue obj; + memset(&obj, 0, sizeof obj); gtk_tree_model_get_value (GTK_TREE_MODEL (model), iter, 3, &obj); - if (G_VALUE_HOLDS_POINTER (&obj)) { + if (G_VALUE_HOLDS_POINTER (&obj)) history_entry = (gpointer) g_value_get_pointer (&obj); + + if (text && history_entry) { + // Filter according to the type of call + // MISSED, INCOMING, OUTGOING, ALL + const gchar* search = gtk_entry_get_text (history_searchbar_widget); + if (!search || !*search) + return TRUE; + SearchType search_type = get_current_history_search_type(); + gboolean match = g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); + + if (search_type == SEARCH_ALL) + return match; + else // We need a match on the history_state_t and the current search type + return (history_entry->_history_state + 1) == search_type && match; } - gboolean result = TRUE; + return TRUE; +} - if (text != NULL) { - if (history_entry) { - // Filter according to the type of call - // MISSED, INCOMING, OUTGOING, ALL - if ( (int) get_current_history_search_type () == SEARCH_ALL) - result = g_regex_match_simple (search, text, G_REGEX_CASELESS, 0); - else { - // We need a match on the history_state_t and the current search type - result = (history_entry->_history_state + 1) == (guint) get_current_history_search_type () && - g_regex_match_simple (search, text, G_REGEX_CASELESS, 0); - } - } - } +static GtkTreeModel* history_create_filter (GtkTreeModel* child) +{ + GtkTreeModel* ret = gtk_tree_model_filter_new (child, NULL); + gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (ret), history_is_visible, NULL, NULL); + return GTK_TREE_MODEL (ret); +} + +void history_search (void) +{ + if (history_filter != NULL) + gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (history_filter)); +} - // Clean up - g_value_unset (&val); - g_value_unset (&obj); +void history_search_init (void) +{ + history_filter = history_create_filter (GTK_TREE_MODEL (history->store)); + gtk_tree_view_set_model (GTK_TREE_VIEW (history->view), GTK_TREE_MODEL (history_filter)); +} - return result; +void history_set_searchbar_widget (GtkWidget *searchbar) +{ + history_searchbar_widget = GTK_ENTRY(searchbar); } diff --git a/gnome/src/contacts/history.h b/gnome/src/contacts/history.h index f21dd3e2efadcb86fd2e4e2b5e8587eb0bfb5926..2b2dc9290f5ad3845831f89d0ff332a8a3988a3c 100644 --- a/gnome/src/contacts/history.h +++ b/gnome/src/contacts/history.h @@ -48,16 +48,13 @@ typedef enum { /** * Execute a search in history */ -void history_search (SearchType search_type); +void history_search(); /** * Initialize history */ void -history_init(); - - -void history_reinit (calltab_t* history); +history_search_init(); /** * Set history search bar widget (needed for is_visible) diff --git a/gnome/src/contacts/searchbar.c b/gnome/src/contacts/searchbar.c index 2c8875f95c6bdacb8ed87109a971f8d4bfa683de..e6d1c549ac5e6617f345264acd3e69ab29d882de 100644 --- a/gnome/src/contacts/searchbar.c +++ b/gnome/src/contacts/searchbar.c @@ -76,22 +76,16 @@ void searchbar_entry_changed (GtkEntry* entry UNUSED, gchar* arg1 UNUSED, gpoint // Search made only when text entry is activated // addressbook_search (entry); } else if (active_calltree == history) { - history_search (HistorySearchType); + history_search(); } } static void cbox_changed_cb (GtkWidget *widget, gpointer user_data UNUSED) { - gchar *name; - - DEBUG ("Searchbar: Addressbook changed callback"); - - name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)); - if(abookfactory_is_addressbook_loaded()) { DEBUG("Searchbar: Set new addressbook"); AddrBookFactory *factory = abookfactory_get_factory(); - factory->addrbook->set_current_book (name); + factory->addrbook->set_current_book (gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget))); AddressBook_Config *addressbook_config; addressbook_config_load_parameters(&addressbook_config); factory->addrbook->search(factory->addrbook, GTK_ENTRY(addressbookentry), addressbook_config); @@ -105,18 +99,15 @@ void set_focus_on_addressbook_searchbar () void update_searchbar_addressbook_list() { - gint count; GtkTreeIter iter, activeIter; gchar *activeText; GSList *book_list_iterator; book_data_t *book_data; GSList *books_data = NULL; - gchar **book_list; if(abookfactory_is_addressbook_loaded()) { AddrBookFactory *factory = abookfactory_get_factory(); - book_list = dbus_get_addressbook_list(); - books_data = factory->addrbook->get_books_data(book_list); + books_data = factory->addrbook->get_books_data(dbus_get_addressbook_list()); } if(books_data == NULL) { @@ -138,7 +129,6 @@ void update_searchbar_addressbook_list() gtk_list_store_clear (liststore); // Populate menu - count = 0; gboolean activeIsSet = FALSE; for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator @@ -155,8 +145,6 @@ void update_searchbar_addressbook_list() activeIter = iter; activeIsSet = TRUE; } - - count++; } } @@ -217,7 +205,7 @@ static void search_all (GtkWidget *item UNUSED, GtkEntry *entry) _ ("Search all"), _ ("Click here to change the search type"))); - history_search (HistorySearchType); + history_search(); } static void search_by_missed (GtkWidget *item UNUSED, GtkEntry *entry) @@ -229,7 +217,7 @@ static void search_by_missed (GtkWidget *item UNUSED, GtkEntry *entry) g_markup_printf_escaped ("%s\n%s", _ ("Search by missed call"), _ ("Click here to change the search type"))); - history_search (HistorySearchType); + history_search(); } static void search_by_incoming (GtkWidget *item UNUSED, GtkEntry *entry) @@ -241,7 +229,7 @@ static void search_by_incoming (GtkWidget *item UNUSED, GtkEntry *entry) g_markup_printf_escaped ("%s\n%s", _ ("Search by incoming call"), _ ("Click here to change the search type"))); - history_search (HistorySearchType); + history_search(); } static void search_by_outgoing (GtkWidget *item UNUSED, GtkEntry *entry) @@ -253,7 +241,7 @@ static void search_by_outgoing (GtkWidget *item UNUSED, GtkEntry *entry) g_markup_printf_escaped ("%s\n%s", _ ("Search by outgoing call"), _ ("Click here to change the search type"))); - history_search (HistorySearchType); + history_search(); } static void icon_press_cb (GtkEntry *entry, gint position, GdkEventButton *event, gpointer data UNUSED) @@ -324,18 +312,6 @@ focus_on_searchbar_in() focus_is_on_searchbar = TRUE; } -void searchbar_init (calltab_t *tab) -{ - if (g_strcasecmp (tab->_name, CONTACTS) == 0) { - } - else if (g_strcasecmp (tab->_name, HISTORY) == 0) { - history_init(); - } - else { - ERROR ("searchbar.c - searchbar_init should not happen within this widget\n"); - } -} - GtkWidget* history_searchbar_new (void) { @@ -559,4 +535,3 @@ SearchType get_current_history_search_type (void) { return HistorySearchType; } - diff --git a/gnome/src/contacts/searchbar.h b/gnome/src/contacts/searchbar.h index 4d0431dfcc4ee71d396ba85e23f21205ac3dd405..eaf29e3e17e68ce6586814f37da9292015f04cca 100644 --- a/gnome/src/contacts/searchbar.h +++ b/gnome/src/contacts/searchbar.h @@ -71,11 +71,6 @@ GtkWidget* contacts_searchbar_new (void); */ SearchType get_current_history_search_type (void); -/** - * Initialize a specific search bar - */ -void searchbar_init (calltab_t *); - /** * Activate a waiting layer during search */ diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index 766d752410c9589626b556b9a7f58cffd50ac4da..62b7fe91db3a78e9a6ecaf62f7af64bc68dc8c2c 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -136,12 +136,10 @@ new_call_created_cb (DBusGProxy *proxy UNUSED, const gchar *accountID, callable_obj_t *c = create_new_call(CALL, CALL_STATE_RINGING, callID, accountID, peer_name, peer_number); - set_timestamp(&c->_time_start); + time(&c->_time_start); calllist_add_call(current_calls, c); - calllist_add_call(history, c); calltree_add_call(current_calls, c, NULL); - calltree_add_call(history, c, NULL); update_actions(); calltree_display(current_calls); @@ -151,26 +149,21 @@ static void incoming_call_cb (DBusGProxy *proxy UNUSED, const gchar* accountID, const gchar* callID, const gchar* from, void * foo UNUSED) { - callable_obj_t * c; - gchar *peer_name, *peer_number; - - DEBUG ("DBus: Incoming call (%s) from %s", callID, from); - // We receive the from field under a formatted way. We want to extract the number and the name of the caller - peer_name = call_get_peer_name (from); - peer_number = call_get_peer_number (from); + gchar *peer_name = call_get_peer_name (from); + gchar *peer_number = call_get_peer_number (from); + + DEBUG ("DBus: Incoming call (%s) from %s (%s : %s)", callID, from, peer_name, peer_number); - DEBUG ("DBus incoming peer name: %s", peer_name); - DEBUG ("DBus incoming peer number: %s", peer_number); + callable_obj_t *c = create_new_call (CALL, CALL_STATE_INCOMING, callID, accountID, peer_name, peer_number); + + g_free(peer_number); - 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(); #endif - set_timestamp (&c->_time_start); notify_incoming_call (c); sflphone_incoming_call (c); } @@ -257,15 +250,11 @@ call_state_cb (DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* state { DEBUG ("DBUS: Call %s state %s",callID, state); callable_obj_t *c = calllist_get_call (current_calls, callID); - if(c == NULL) { - ERROR("DBUS: Error: Call is NULL in "); - } - if (c) { if (g_strcmp0 (state, "HUNGUP") == 0) { if (c->_state == CALL_STATE_CURRENT) { // peer hung up, the conversation was established, so _stop has been initialized with the current time value - set_timestamp (&c->_time_stop); + time(&c->_time_stop); calltree_update_call (history, c, NULL); } @@ -291,33 +280,25 @@ call_state_cb (DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* state sflphone_busy (c); } } else { + ERROR("DBUS: Error: Call is NULL in %s", __func__); + // The callID is unknow, threat it like a new call // If it were an incoming call, we won't be here // It means that a new call has been initiated with an other client (cli for instance) if ((g_strcmp0 (state, "RINGING")) == 0 || (g_strcmp0 (state, "CURRENT")) == 0 || (g_strcmp0 (state, "RECORD"))) { - GHashTable *call_details; - gchar *type; DEBUG ("DBUS: New ringing call! accountID: %s", callID); // We fetch the details associated to the specified call - call_details = dbus_get_call_details (callID); + GHashTable *call_details = dbus_get_call_details (callID); 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); - type = g_hash_table_lookup (call_details, "CALL_TYPE"); - - if (g_strcasecmp (type, "0") == 0) { - new_call->_history_state = INCOMING; - } else { - new_call->_history_state = OUTGOING; - } + new_call->_history_state = (g_strcasecmp (g_hash_table_lookup (call_details, "CALL_TYPE"), "0") == 0) + ? INCOMING : OUTGOING; calllist_add_call (current_calls, new_call); - calllist_add_call (history, new_call); calltree_add_call (current_calls, new_call, NULL); update_actions(); calltree_display (current_calls); @@ -418,7 +399,7 @@ conference_created_cb (DBusGProxy *proxy UNUSED, const gchar* confID, void * foo callable_obj_t *call = calllist_get_call (current_calls, call_id); // set when this call have been added to the conference - set_timestamp(&call->_time_added); + time(&call->_time_added); // if a text widget is already created, disable it, use conference widget instead if (call->_im_widget) @@ -432,7 +413,7 @@ conference_created_cb (DBusGProxy *proxy UNUSED, const gchar* confID, void * foo call->_historyConfID = g_strdup (confID); } - set_timestamp(&new_conf->_time_start); + time(&new_conf->_time_start); conferencelist_add (current_calls, new_conf); conferencelist_add (history, new_conf); @@ -657,10 +638,8 @@ confirm_go_clear_cb (DBusGProxy *proxy UNUSED, const gchar* callID, void * foo DEBUG ("DBUS: Confirm Go Clear request"); callable_obj_t * c = calllist_get_call (current_calls, callID); - - if (c) { - sflphone_confirm_go_clear (c); - } + if (c) + main_window_confirm_go_clear (c); } static void @@ -670,7 +649,7 @@ zrtp_not_supported_cb (DBusGProxy *proxy UNUSED, const gchar* callID, void * foo callable_obj_t * c = calllist_get_call (current_calls, callID); if (c) { - sflphone_srtp_zrtp_not_supported (c); + main_window_zrtp_not_supported (c); notify_zrtp_not_supported (c); } } diff --git a/gnome/src/imwindow.c b/gnome/src/imwindow.c index 6980a46b8061f45c484881e8785bdfefa85db5ae..f501e8fe965bbca6a7fdf03a62092ba50835db55 100644 --- a/gnome/src/imwindow.c +++ b/gnome/src/imwindow.c @@ -211,7 +211,7 @@ im_window_add_tab (GtkWidget *widget) im->tab = tab_Container; if (im_widget_call) - tab_Label = gtk_label_new (get_peer_information (im_widget_call)); + tab_Label = gtk_label_new (*im_widget_call->_peer_name ? im_widget_call->_peer_name : im_widget_call->_peer_number); else if (im_widget_conf) tab_Label = gtk_label_new ("Conferencing"); else diff --git a/gnome/src/main.c b/gnome/src/main.c index 111b431132a9e0f560e4a9c941884290c47ad16a..0334a0496fa4d3ee95dcfbdf07285aec596f316c 100644 --- a/gnome/src/main.c +++ b/gnome/src/main.c @@ -43,6 +43,7 @@ #include <stdlib.h> #include "shortcuts.h" +#include "history.h" int main (int argc, char *argv[]) @@ -116,19 +117,16 @@ main (int argc, char *argv[]) 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 (); + history_search_init(); // Update the GUI update_actions (); shortcuts_initialize_bindings(); - /* start the main loop */ gtk_main (); shortcuts_destroy_bindings(); diff --git a/gnome/src/mainwindow.c b/gnome/src/mainwindow.c index 78187715da559dadd7f67674bd9904b1219948af..0e325472b02b68283115d38ae86ce8ed6e2cf9b6 100644 --- a/gnome/src/mainwindow.c +++ b/gnome/src/mainwindow.c @@ -297,15 +297,13 @@ create_main_window () /* dont't show the contact list */ gtk_widget_hide (contacts->tree); - searchbar_init (history); - searchbar_init (contacts); - /* don't show waiting layer */ gtk_widget_hide (waitingLayer); - // pthread_mutex_init (&statusbar_message_mutex, NULL); gmutex = g_mutex_new(); + g_timeout_add(1000, calltree_update_clock, NULL); + // Configuration wizard if (account_list_get_size () == 1) { #if GTK_CHECK_VERSION(2,10,0) @@ -442,16 +440,8 @@ statusbar_pop_message (guint id) void statusbar_update_clock (const gchar * const msg) { - gchar *message = NULL; - - if (!msg) { - statusbar_pop_message (__MSG_ACCOUNT_DEFAULT); - statusbar_push_message (message, NULL, __MSG_ACCOUNT_DEFAULT); - } - - g_mutex_lock (gmutex); - message = g_strdup (status_current_message); + gchar *message = g_strdup (status_current_message); g_mutex_unlock (gmutex); if (message) { @@ -489,8 +479,7 @@ main_window_zrtp_not_supported (callable_obj_t * c) DEBUG ("Warning Enabled %s", warning_enabled); } else { DEBUG ("Account is null callID %s", c->_callID); - GHashTable * properties = NULL; - sflphone_get_ip2ip_properties (&properties); + GHashTable * properties = sflphone_get_ip2ip_properties(); if (properties != NULL) { warning_enabled = g_hash_table_lookup (properties, @@ -556,7 +545,7 @@ main_window_confirm_go_clear (callable_obj_t * c) 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); + (PidginMiniDialogCallback) dbus_set_confirm_go_clear, NULL); pidgin_mini_dialog_add_button (mini_dialog, _ ("Stop Call"), sflphone_hang_up, NULL); diff --git a/gnome/src/toolbar.c b/gnome/src/toolbar.c deleted file mode 100644 index 1160e38e81d949c3b00c4d93e068ebad7c136efa..0000000000000000000000000000000000000000 --- a/gnome/src/toolbar.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc. - * Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include <toolbar.h> -#include <contacts/addressbook.h> - - -static void -call_mailbox (GtkWidget* widget UNUSED, gpointer data UNUSED) -{ - 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 ("Call: 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); -} - -/** - * Make a call - */ -static void -call_button (GtkWidget *widget UNUSED, gpointer data UNUSED) -{ - 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); - } -} diff --git a/gnome/src/toolbar.h b/gnome/src/toolbar.h deleted file mode 100644 index 96aa3658e9093b95a6a56001f5d73ffdfe7b7de2..0000000000000000000000000000000000000000 --- a/gnome/src/toolbar.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc. - * Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#ifndef __TOOLBAR_H__ -#define __TOOLBAR_H__ - -#include <callable_obj.h> -#include <gtk/gtk.h> -#include <sflphone_const.h> -#include <actions.h> - -GtkWidget * toolbar; -GtkToolItem * pickupButton; -GtkToolItem * callButton; -GtkToolItem * hangupButton; -GtkToolItem * holdButton; -GtkToolItem * transfertButton; -GtkToolItem * unholdButton; -GtkToolItem * mailboxButton; -GtkToolItem * detachButton; -GtkToolItem * recButton; -GtkToolItem * historyButton; -GtkToolItem * contactButton; -guint transfertButtonConnId; //The button toggled signal connection ID - -/** - * Build the toolbar - * @return GtkWidget* The toolbar - */ -GtkWidget * -create_toolbar(); - -GtkWidget * -create_filter_entry(); - -/** - * Update the toolbar's buttons state, according to the call state - */ -void -toolbar_update_buttons(); - -#endif diff --git a/gnome/src/uimanager.c b/gnome/src/uimanager.c index ffddd7830a18c872f9fa02c53a456a7fac448983..0ca3b4fdc8ffc2f65a100040d2dcab2c79d4b998 100644 --- a/gnome/src/uimanager.c +++ b/gnome/src/uimanager.c @@ -712,8 +712,9 @@ static void conference_hang_up (void) { DEBUG ("UIManager: Hang up button pressed (conference)"); - - sflphone_conference_hang_up(); + conference_obj_t * selectedConf = calltab_get_selected_conf(current_calls); + if (selectedConf) + dbus_hang_up_conference (selectedConf); } static void @@ -952,8 +953,7 @@ edit_paste (void * foo UNUSED) gchar * temp = g_strconcat (selectedCall->_peer_number, oneNo, NULL); g_free (selectedCall->_peer_info); - selectedCall->_peer_info = get_peer_info (temp, - selectedCall->_peer_name); + selectedCall->_peer_info = get_peer_info (temp, selectedCall->_peer_name); g_free (temp); g_free (oneNo); calltree_update_call (current_calls, selectedCall, NULL);