From c33270a72253d77f3d80d06aca66d023c46e6213 Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Mon, 23 Aug 2010 12:18:43 -0400 Subject: [PATCH] [#3917] Add messages level (normal, error, warning). Handles now messages sent outside a call --- sflphone-client-gnome/src/dbus/dbus.c | 2 +- sflphone-client-gnome/src/widget/imwidget.c | 64 ++++++++++++++------- sflphone-client-gnome/src/widget/imwidget.h | 9 ++- sflphone-client-gnome/webkit/Makefile.am | 3 +- sflphone-client-gnome/webkit/im/im.css | 13 ++++- sflphone-common/src/sip/sipvoiplink.cpp | 8 ++- 6 files changed, 72 insertions(+), 27 deletions(-) diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c index 8458466e22..5911e23387 100644 --- a/sflphone-client-gnome/src/dbus/dbus.c +++ b/sflphone-client-gnome/src/dbus/dbus.c @@ -131,7 +131,7 @@ incoming_message_cb(DBusGProxy *proxy UNUSED, const gchar* callID UNUSED, const im_widget_display (&c); /* Display le message */ - im_widget_add_message (c, from, msg); + im_widget_add_message (c, from, msg, 0); if (c) { notify_incoming_message (callID, msg); diff --git a/sflphone-client-gnome/src/widget/imwidget.c b/sflphone-client-gnome/src/widget/imwidget.c index be5fe393b2..cebbbdc922 100644 --- a/sflphone-client-gnome/src/widget/imwidget.c +++ b/sflphone-client-gnome/src/widget/imwidget.c @@ -34,7 +34,7 @@ #define WEBKIT_DIR "file://" DATA_DIR "/webkit/" void -im_widget_add_message (callable_obj_t *call, const gchar *from, const gchar *message) +im_widget_add_message (callable_obj_t *call, const gchar *from, const gchar *message, gint level) { /* use the widget for this specific call, if exists */ if (!call){ @@ -48,9 +48,12 @@ im_widget_add_message (callable_obj_t *call, const gchar *from, const gchar *mes /* Update the informations about the call in the chat window */ im_widget_add_call_header (call); + + /* Check for the message level */ + gchar *css_class = (level == MESSAGE_LEVEL_ERROR ) ? "error" : ""; /* Prepare and execute the Javascript code */ - gchar *script = g_strdup_printf("add_message('%s', '%s', '%s', '%s');", message, from, call->_peer_number, call->_peer_info); + gchar *script = g_strdup_printf("add_message('%s', '%s', '%s', '%s');", message, from, call->_peer_number, css_class); webkit_web_view_execute_script (WEBKIT_WEB_VIEW(im->web_view), script); /* Cleanup */ @@ -131,10 +134,10 @@ on_Textview_changed (GtkWidget *widget, GdkEventKey *event, gpointer user_data) gchar *message = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); /* Display our own message in the chat window */ - im_widget_add_message (im->call, "Me", message); + im_widget_add_message (im->call, "Me", message, MESSAGE_LEVEL_NORMAL); /* Send the message to the peer */ - dbus_send_text_message (im->call->_callID, message); + im_widget_send_message (im->call, message); /* Empty the buffer */ gtk_text_buffer_delete (GTK_TEXT_BUFFER (buffer), &start, &end); @@ -147,6 +150,21 @@ on_Textview_changed (GtkWidget *widget, GdkEventKey *event, gpointer user_data) return FALSE; } + void +im_widget_send_message (callable_obj_t *call, const gchar *message) +{ + + /* First check if the call is in CURRENT state, otherwise it could not be sent */ + if (call->_type == CALL && call->_state == CALL_STATE_CURRENT) + { + /* Ship the message through D-Bus */ + dbus_send_text_message (call->_callID, message); + } + else { + /* Display an error message */ + im_widget_add_message (call, "sflphoned", "Oups, something went wrong! Unable to send text messages outside a call.", MESSAGE_LEVEL_ERROR); + } +} static void @@ -229,24 +247,26 @@ im_widget_display (callable_obj_t **call) callable_obj_t *tmp = *call; /* Use the widget for this specific call, if exists */ - IMWidget *im = IM_WIDGET (tmp->_im_widget); - - if (!im) { - g_print ("creating the im widget for this call\n"); - /* Create the im object */ - im = im_widget_new (); - tmp->_im_widget = im; - /* Update the call */ - *call = tmp; - im->call = *call; - - /* Add it to the main instant messaging window */ - gchar *label = get_peer_information (tmp); - im_window_add (im, label); - } - else { - g_print ("im widget exists for this call\n"); - im_window_show (); + if (tmp) { + IMWidget *im = IM_WIDGET (tmp->_im_widget); + + if (!im) { + g_print ("creating the im widget for this call\n"); + /* Create the im object */ + im = im_widget_new (); + tmp->_im_widget = im; + /* Update the call */ + *call = tmp; + im->call = *call; + + /* Add it to the main instant messaging window */ + gchar *label = get_peer_information (tmp); + im_window_add (im, label); + } + else { + g_print ("im widget exists for this call\n"); + im_window_show (); + } } } diff --git a/sflphone-client-gnome/src/widget/imwidget.h b/sflphone-client-gnome/src/widget/imwidget.h index b1f16ac966..0d3e6d3d03 100644 --- a/sflphone-client-gnome/src/widget/imwidget.h +++ b/sflphone-client-gnome/src/widget/imwidget.h @@ -44,6 +44,10 @@ G_BEGIN_DECLS #define IS_IM_WIDGET_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), IM_WIDGET_TYPE)) #define IM_WIDGET_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS((inst), IM_WIDGET_TYPE, IMWidgetClass)) +#define MESSAGE_LEVEL_NORMAL 0 +#define MESSAGE_LEVEL_WARNING 1 +#define MESSAGE_LEVEL_ERROR 2 + typedef struct _IMWidget IMWidget; typedef struct _IMWidgetClass IMWidgetClass; @@ -72,7 +76,10 @@ void im_widget_display (callable_obj_t**); GType im_widget_get_type(void) G_GNUC_CONST; GtkWidget *im_widget_new(void); -void im_widget_add_message (callable_obj_t *c, const gchar *from, const gchar *message); +void im_widget_add_message (callable_obj_t *c, const gchar *from, const gchar *message, gint level); + +void im_widget_send_message (callable_obj_t *call, const gchar *message); + G_END_DECLS diff --git a/sflphone-client-gnome/webkit/Makefile.am b/sflphone-client-gnome/webkit/Makefile.am index 6ef49f61b1..80410916ca 100644 --- a/sflphone-client-gnome/webkit/Makefile.am +++ b/sflphone-client-gnome/webkit/Makefile.am @@ -9,4 +9,5 @@ im_DATA = im/im.js \ im/im.html \ im/im.css \ im/sflphone.png \ - im/chat_info.png + im/chat_info.png \ + im/error.png diff --git a/sflphone-client-gnome/webkit/im/im.css b/sflphone-client-gnome/webkit/im/im.css index a234d411e9..574348903c 100644 --- a/sflphone-client-gnome/webkit/im/im.css +++ b/sflphone-client-gnome/webkit/im/im.css @@ -11,7 +11,7 @@ clear: both; } * { - font-size: 1em; + font-size: 12px; font-family: "Georgia","Verdana","Arial","Helvetica",sans-serif; } @@ -29,6 +29,7 @@ body { } #call-info { + font-size: 1.1em; margin: 40px; height: 96px; background: url(chat_info.png) no-repeat center left; @@ -36,3 +37,13 @@ height: 96px; border: 2px solid #dedede; -webkit-border-radius: 25px; } + +.error .text { + color: #de7575; + font-size: 1.3em; +} + +.error .author { + display: none; +} + diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 117076c139..aafa5534e9 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -1051,9 +1051,15 @@ SIPVoIPLink::sendTextMessage (const std::string& callID, const std::string& mess if (call) { - /* Test IM message */ + /* Send IM message */ status = imModule->send (call->getInvSession (), (CallID&)callID, message); } + else { + /* Notify the client of an error */ + /*Manager::instance ().incomingMessage ( "", + "sflphoned", + "Unable to send a message outside a call.");*/ + } return status; } -- GitLab