Skip to content
Snippets Groups Projects
Commit 34bc4f6c authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

[#3621] Add message time

parent 6abac2d3
No related branches found
No related tags found
No related merge requests found
......@@ -127,17 +127,20 @@ incoming_message_cb(DBusGProxy *proxy UNUSED, const gchar* callID UNUSED, const
// Get the call information. Does this call exist?
callable_obj_t * c = calllist_get (current_calls, callID);
/* First check if the call is valid */
if (c) {
/* Make the instant messaging main window pops */
im_widget_display (&c);
/* Display le message */
im_widget_add_message (c, from, msg, 0);
/* Display the message */
im_widget_add_message (c, get_peer_information (c), msg, 0);
if (c) {
notify_incoming_message (callID, msg);
} else {
ERROR ("Message received, but no recipient found");
}
/*if (c) {
notify_incoming_message (callID, msg);*/
}
static void
......
......@@ -65,6 +65,13 @@ on_delete(GtkWidget * widget UNUSED, gpointer data UNUSED)
return TRUE;
}
static void
on_switch_page (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer userdata)
{
guint index = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
g_print ("switch to %i- current = %i\n", page_num, index);
}
static void
im_window_init()
{
......@@ -93,20 +100,17 @@ im_window_init()
gtk_widget_set_name(im_window, "imwindow");
g_signal_connect (G_OBJECT (im_window), "delete-event",
G_CALLBACK (on_delete), NULL);
g_signal_connect_object (G_OBJECT (im_window), "configure-event",
G_CALLBACK (window_configure_cb), NULL, 0);
GtkWidget *im_vbox = gtk_vbox_new (FALSE /*homogeneous*/, 0 /*spacing*/);
im_notebook = gtk_notebook_new ();
gtk_container_add (GTK_CONTAINER (im_window), im_vbox);
gtk_box_pack_start (GTK_BOX (im_vbox), im_notebook, TRUE, TRUE, 0);
gtk_widget_show (im_notebook);
g_signal_connect (G_OBJECT (im_window), "delete-event", G_CALLBACK (on_delete), NULL);
g_signal_connect_object (G_OBJECT (im_window), "configure-event", G_CALLBACK (window_configure_cb), NULL, 0);
g_signal_connect (G_OBJECT (im_notebook), "switch-page", G_CALLBACK (on_switch_page), NULL);
/* make sure that everything is visible */
gtk_widget_show_all (im_window);
......@@ -123,7 +127,8 @@ im_window_get()
}
void
im_window_show (){
im_window_show ()
{
gtk_widget_show (im_window_get ());
}
......@@ -134,11 +139,6 @@ im_window_add (GtkWidget *widget, gchar *label)
/* Add the new tab to the notebook */
im_window_add_tab (widget, label);
/* Switch to the newly opened tab */
guint index = gtk_notebook_page_num (GTK_NOTEBOOK (im_notebook), widget);
gtk_notebook_set_current_page (GTK_NOTEBOOK (im_notebook), 2);
g_print ("index %i - current %i\n", index, gtk_notebook_get_current_page (GTK_NOTEBOOK (im_notebook)));
/* Show it all */
gtk_widget_show_all (im_window);
}
......@@ -172,11 +172,15 @@ im_window_add_tab (GtkWidget *widget, gchar *label)
g_signal_connect (tab_CloseButton, "clicked", G_CALLBACK (close_tab_cb), widget);
gtk_widget_show_all (tab_Container);
gtk_notebook_append_page (GTK_NOTEBOOK (im_notebook), widget, tab_Container);
}
/* Add the page to the notebook */
gtk_notebook_append_page (GTK_NOTEBOOK (im_notebook), widget, tab_Container);
/* Switch to the newly opened tab */
guint tabIndex = gtk_notebook_page_num (GTK_NOTEBOOK (im_notebook), widget);
gtk_notebook_set_current_page (GTK_NOTEBOOK (im_notebook), tabIndex);
}
void
im_window_remove(GtkWidget *widget)
......
......@@ -49,11 +49,14 @@ 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);
/* Compute the date the message was sent */
gchar *msgtime = im_widget_add_message_time ();
/* 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, css_class);
gchar *script = g_strdup_printf("add_message('%s', '%s', '%s', '%s');", message, from, css_class, msgtime);
webkit_web_view_execute_script (WEBKIT_WEB_VIEW(im->web_view), script);
/* Cleanup */
......@@ -61,36 +64,21 @@ im_widget_add_message (callable_obj_t *call, const gchar *from, const gchar *mes
}
else {
/* If the chat window is not opened when we receive an incoming message, create the im widget first,
then call the javascript to display the message */
im = im_widget_new ();
im_window_add (im);
im->call = call;
call->_im_widget = im;
/* Prepare and execute the Javascript code */
gchar *script = g_strdup_printf("add_message('%s', '%s', '%s', '%s');", message, call->_peer_name, call->_peer_number, call->_peer_info);
webkit_web_view_execute_script (WEBKIT_WEB_VIEW(im->web_view), script);
/* Cleanup */
g_free(script);
}
}
}
void
im_widget_add_call_header (callable_obj_t *call) {
if (call) {
IMWidget *im = IM_WIDGET (call->_im_widget);
gchar *script = g_strdup_printf("add_call_info_header('%s', '%s', '%s');", call->_peer_name, call->_peer_number, call->_peer_info);
gchar *script = g_strdup_printf("add_call_info_header('%s', '%s');", call->_peer_name, call->_peer_number);
webkit_web_view_execute_script (WEBKIT_WEB_VIEW(im->web_view), script);
/* Cleanup */
g_free(script);
}
}
static gboolean
web_view_nav_requested_cb(
......@@ -107,8 +95,11 @@ web_view_nav_requested_cb(
if (!strncmp(uri, WEBKIT_DIR, sizeof(WEBKIT_DIR) - 1)) {
webkit_web_policy_decision_use (policy_decision);
} else {
printf("FIXME(jonas) open URL in browser: %s\n", uri);
/* Running a system command to open the URL in the user's default browser */
gchar *cmd = g_strdup_printf("x-www-browser %s", uri);
system (cmd);
webkit_web_policy_decision_ignore (policy_decision);
g_free (cmd);
}
return TRUE;
}
......@@ -150,6 +141,26 @@ on_Textview_changed (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
return FALSE;
}
gchar*
im_widget_add_message_time ()
{
time_t now;
unsigned char str[100];
/* Compute the current time */
(void) time (&now);
struct tm* ptr;
ptr = localtime (&now);
/* Get the time of the message. Format: HH:MM::SS */
strftime ((char *)str, 100, "%R", (const struct tm *)ptr);
gchar *res = g_strdup (str);
/* Return the new value */
return res;
}
void
im_widget_send_message (callable_obj_t *call, const gchar *message)
{
......@@ -176,7 +187,10 @@ im_widget_class_init(IMWidgetClass *klass)
im_widget_init (IMWidget *im)
{
/* A text view to enable users to enter text */
im->textarea = gtk_text_view_new ();
/* The webkit widget to display the message */
im->web_view = webkit_web_view_new();
GtkWidget *textscrollwin = gtk_scrolled_window_new (NULL, NULL);
GtkWidget *webscrollwin = gtk_scrolled_window_new (NULL, NULL);
......@@ -202,6 +216,7 @@ im_widget_init (IMWidget *im)
im->js_context = webkit_web_frame_get_global_context (im->web_frame);
im->js_global = JSContextGetGlobalObject (im->js_context);
webkit_web_view_load_uri (WEBKIT_WEB_VIEW(im->web_view), "file://" DATA_DIR "/webkit/im/im.html");
}
GtkWidget *
......
......@@ -80,6 +80,9 @@ void im_widget_add_message (callable_obj_t *c, const gchar *from, const gchar *m
void im_widget_send_message (callable_obj_t *call, const gchar *message);
gchar* im_widget_add_message_time ();
G_END_DECLS
......
.message {
-webkit-border-radius: 5px;
background: rgba(242, 242, 242, 0.75);
color: #777;
color: #444;
padding: 1em;
-webkit-box-shadow: 2px 2px 5px #000;
margin: 20px;
overflow: auto;
font-size: 0.95em;
clear: both;
}
......@@ -20,7 +19,11 @@ font-family: "Georgia","Verdana","Arial","Helvetica",sans-serif;
}
body {
background: #fbfdfe url(sflphone.png) no-repeat fixed bottom right;
background: #fbfdfe;
}
#logo {
float: right;
}
.author {
......@@ -28,9 +31,14 @@ body {
font-weight: bold;
}
#header {
margin: 40px;
}
#call-info {
float: left;
font-size: 1.1em;
margin: 40px;
height: 96px;
background: url(chat_info.png) no-repeat center left;
padding: 20px 20px 20px 100px;
......@@ -47,3 +55,12 @@ height: 96px;
display: none;
}
.message-time {
color: #777;
float: right;
}
#messages {
clear: both;
padding-top: 20px;
}
......@@ -5,10 +5,12 @@
</head>
<body>
<div class='page'>
<div id="header">
<div id="call-info">
<h2> Calling <span id='peer-number'></span></h2>
<p>Nom: <span id='peer-name'></span></p>
<p>Plus: <span id='peer-info'></span></p>
</div>
<div id="logo"><a href="http://www.sflphone.org" title="sflphone" alt="sflphone"><img src="sflphone.png"/></a></div>
</div>
<div id="messages">
</div>
......
......@@ -15,25 +15,25 @@ function linkify(text){
}
function add_message (message, peer_name, peer_number, class_additionnal)
function add_message (message, peer_name, class_additionnal, time)
{
var display_name = 'Unknown';
if (peer_name != '') {
display_name = peer_name;
}
var msgBody = document.getElementById ('messages');
msgBody.innerHTML = msgBody.innerHTML + '<div class="message ' + class_additionnal + '">' + '<span class="author">' + display_name + ': </span>' + '<p class="text">' + linkify (message) + '</p></div>' ;
msgBody.innerHTML = msgBody.innerHTML + '<div class="message ' + class_additionnal + '">' + '<span class="author">[' + peer_name + '] </span><span class="message-time">' + time + '</span><p class="text">' + linkify (message) + '</p></div>' ;
document.getElementById("bottom").scrollIntoView(true);
}
function add_call_info_header (peer_name, peer_number, peer_info)
function add_call_info_header (peer_name, peer_number)
{
var peerNumber = document.getElementById ('peer-number');
var peerName = document.getElementById ('peer-name');
var peerInfo = document.getElementById ('peer-info');
peerNumber.innerHTML = peer_number;
peerName.innerHTML = peer_name;
peerInfo.innerHTML = peer_info;
}
function open_url (uri) {
window.open(''+self.location,'mywin',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
}
sflphone-client-gnome/webkit/im/sflphone.png

12.7 KiB | W: | H:

sflphone-client-gnome/webkit/im/sflphone.png

12.7 KiB | W: | H:

sflphone-client-gnome/webkit/im/sflphone.png
sflphone-client-gnome/webkit/im/sflphone.png
sflphone-client-gnome/webkit/im/sflphone.png
sflphone-client-gnome/webkit/im/sflphone.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment