From b23323f1af1b4467e26e6540c58b3c07601686cc Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.com> Date: Wed, 21 Jul 2010 12:03:19 -0400 Subject: [PATCH] [#3218] Add mutex to display bar current messages --- sflphone-client-gnome/src/callable_obj.c | 14 +++--- sflphone-client-gnome/src/callable_obj.h | 6 +-- sflphone-client-gnome/src/contacts/calltree.c | 6 ++- sflphone-client-gnome/src/contacts/calltree.h | 5 +- sflphone-client-gnome/src/mainwindow.c | 48 +++++++++++++++++-- sflphone-client-gnome/src/mainwindow.h | 7 +++ 6 files changed, 68 insertions(+), 18 deletions(-) diff --git a/sflphone-client-gnome/src/callable_obj.c b/sflphone-client-gnome/src/callable_obj.c index 67fde62f7a..19fe299881 100644 --- a/sflphone-client-gnome/src/callable_obj.c +++ b/sflphone-client-gnome/src/callable_obj.c @@ -155,22 +155,24 @@ void *threaded_clock_incrementer(void *pc) { if( duration / 60 == 0 ) { if( duration < 10 ) - res = g_markup_printf_escaped("00:0%i", duration); + call->_timestr = g_markup_printf_escaped("00:0%i", duration); else - res = g_markup_printf_escaped("00:%i", duration); + call->_timestr = g_markup_printf_escaped("00:%i", duration); } else { if( duration%60 < 10 ) - res = g_markup_printf_escaped("%i:0%i" , duration/60 , duration%60); + call->_timestr = g_markup_printf_escaped("%i:0%i" , duration/60 , duration%60); else - res = g_markup_printf_escaped("%i:%i" , duration/60 , duration%60); + call->_timestr = g_markup_printf_escaped("%i:%i" , duration/60 , duration%60); } // return g_markup_printf_escaped("<small>Duration:</small> %s", res); - DEBUG("%s", res); + // call->_timestr = res; + + DEBUG("%s", call->_timestr); - calltree_update_clock(call); + calltree_update_clock(); sleep(1); } diff --git a/sflphone-client-gnome/src/callable_obj.h b/sflphone-client-gnome/src/callable_obj.h index 414245854f..581651b05d 100644 --- a/sflphone-client-gnome/src/callable_obj.h +++ b/sflphone-client-gnome/src/callable_obj.h @@ -112,6 +112,7 @@ typedef struct { 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; // The timestamp as a string format for 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 @@ -154,7 +155,7 @@ typedef struct { // thread id to increment clock pthread_t tid; - int clockStarted; + int clockStarted; } callable_obj_t; @@ -194,9 +195,6 @@ gchar* call_get_peer_name (const gchar*); */ gchar* call_get_peer_number (const gchar*); - - - void attach_thumbnail (callable_obj_t *, GdkPixbuf *); diff --git a/sflphone-client-gnome/src/contacts/calltree.c b/sflphone-client-gnome/src/contacts/calltree.c index 051f147c56..87118f31f9 100644 --- a/sflphone-client-gnome/src/contacts/calltree.c +++ b/sflphone-client-gnome/src/contacts/calltree.c @@ -1406,12 +1406,14 @@ void calltree_display (calltab_t *tab) { } -void -calltree_update_clock(callable_obj_t *c) { +void calltree_update_clock() { DEBUG("UPDATE CLOCK"); // TODO this make the whole thing crash... // calltree_update_call(current_calls, c, NULL); + + if(selected_call) + statusbar_update_clock(selected_call->_timestr); } diff --git a/sflphone-client-gnome/src/contacts/calltree.h b/sflphone-client-gnome/src/contacts/calltree.h index 899ea71e42..b6a9eca3af 100644 --- a/sflphone-client-gnome/src/contacts/calltree.h +++ b/sflphone-client-gnome/src/contacts/calltree.h @@ -111,7 +111,10 @@ calltree_display (calltab_t *tab); void row_activated(GtkTreeView *, GtkTreePath *, GtkTreeViewColumn *, void *); +/** + * Update elapced time based on selected calltree's call + */ void -calltree_update_clock(callable_obj_t *c); +calltree_update_clock(); #endif diff --git a/sflphone-client-gnome/src/mainwindow.c b/sflphone-client-gnome/src/mainwindow.c index cf3ca81757..7376858e52 100644 --- a/sflphone-client-gnome/src/mainwindow.c +++ b/sflphone-client-gnome/src/mainwindow.c @@ -59,6 +59,9 @@ GtkWidget * statusBar = NULL; GtkWidget * filterEntry = NULL; PidginScrollBook *embedded_error_notebook; +gchar *status_current_message = NULL; +pthread_mutex_t statusbar_message_mutex; + /** * Handle main window resizing */ @@ -91,6 +94,8 @@ on_delete (GtkWidget * widget UNUSED, gpointer data UNUSED) else { sflphone_quit (); } + + pthread_mutex_destroy(&statusbar_message_mutex); return TRUE; } @@ -292,6 +297,8 @@ create_main_window () /* don't show waiting layer */ gtk_widget_hide (waitingLayer); + pthread_mutex_init(&statusbar_message_mutex, NULL); + // Configuration wizard if (account_list_get_size () == 1) { @@ -407,20 +414,51 @@ main_window_volume_controls (gboolean state) void statusbar_push_message (const gchar * message, guint id) { - gtk_statusbar_push (GTK_STATUSBAR(statusBar), id, message); + // DEBUG("Message: %s", message); + + // if(id == __MSG_ACCOUNT_DEFAULT) + pthread_mutex_lock(&statusbar_message_mutex); + + g_free(status_current_message); + status_current_message = g_strdup(message); + + gtk_statusbar_push (GTK_STATUSBAR(statusBar), id, message); + + pthread_mutex_unlock(&statusbar_message_mutex); } void statusbar_pop_message (guint id) { - gtk_statusbar_pop (GTK_STATUSBAR(statusBar), id); + gtk_statusbar_pop (GTK_STATUSBAR(statusBar), id); } - static void +void +statusbar_update_clock(gchar *msg) +{ + gchar *message; + + pthread_mutex_lock(&statusbar_message_mutex); + message = g_strdup(status_current_message); + pthread_mutex_unlock(&statusbar_message_mutex); + + DEBUG("------------------------------ MESSAGE %s", message); + + if(message) { + DEBUG("STATUS CURRENT MESSAGE %s", status_current_message); + + statusbar_pop_message(__MSG_ACCOUNT_DEFAULT); + statusbar_push_message(message, __MSG_ACCOUNT_DEFAULT); + } + + g_free(message); +} + +static void add_error_dialog (GtkWidget *dialog, callable_obj_t * call) { - gtk_container_add (GTK_CONTAINER(embedded_error_notebook), dialog); - call_add_error (call, dialog); + gtk_container_add (GTK_CONTAINER(embedded_error_notebook), dialog); + call_add_error (call, dialog); } static void diff --git a/sflphone-client-gnome/src/mainwindow.h b/sflphone-client-gnome/src/mainwindow.h index db7007cd3c..17a4ffdfae 100644 --- a/sflphone-client-gnome/src/mainwindow.h +++ b/sflphone-client-gnome/src/mainwindow.h @@ -105,6 +105,13 @@ void statusbar_push_message( const gchar* message , guint id ); */ void statusbar_pop_message( guint id ); +/** + * Update selected call's clock in statusbar + * @param id The identifier of the message + */ +void statusbar_update_clock( gchar *time); + + //static gboolean //on_key_released (GtkWidget *widget, GdkEventKey *event, // gpointer user_data); -- GitLab