diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c index 8458466e22e129c5b1a204130e31be3325dc5e5b..5911e2338762fb3acf10d2ab818c0c6d7c7ee1b5 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 be5fe393b2f361a537eac89770bb289f314f8b17..cebbbdc9221ae44449470f60449ca9b6426f0b34 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 b1f16ac9661646a5a8eed8c7fad9f5cf54362fc4..0d3e6d3d031503e265ca9a0bf3572f221bd208ec 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 6ef49f61b19f88fcbb257a9e1ffe4316c21de7bb..80410916ca0e1e1f0f73c6c98d96d861a5006ddd 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 a234d411e9239846c4e4cc7ee9b661d5dd510d6e..574348903c1eea328531439f8174e95ac6e226e4 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 117076c1396574f82b2824a1b1f7403d91b27975..aafa5534e9b11838147130bce6d616f2e73be42b 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; }