comparison pidgin/gtkconv.c @ 21875:7efb9a7de561

Typing notification in the conversation history.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 18 Dec 2007 21:24:28 +0000
parents 8a52e4cf64c5
children 65e23b7a4398
comparison
equal deleted inserted replaced
21874:c2af0701d9cc 21875:7efb9a7de561
151 static gboolean tab_complete(PurpleConversation *conv); 151 static gboolean tab_complete(PurpleConversation *conv);
152 static void pidgin_conv_updated(PurpleConversation *conv, PurpleConvUpdateType type); 152 static void pidgin_conv_updated(PurpleConversation *conv, PurpleConvUpdateType type);
153 static void conv_set_unseen(PurpleConversation *gtkconv, PidginUnseenState state); 153 static void conv_set_unseen(PurpleConversation *gtkconv, PidginUnseenState state);
154 static void gtkconv_set_unseen(PidginConversation *gtkconv, PidginUnseenState state); 154 static void gtkconv_set_unseen(PidginConversation *gtkconv, PidginUnseenState state);
155 static void update_typing_icon(PidginConversation *gtkconv); 155 static void update_typing_icon(PidginConversation *gtkconv);
156 static void update_typing_message(PidginConversation *gtkconv, const char *message);
156 static const char *item_factory_translate_func (const char *path, gpointer func_data); 157 static const char *item_factory_translate_func (const char *path, gpointer func_data);
157 gboolean pidgin_conv_has_focus(PurpleConversation *conv); 158 gboolean pidgin_conv_has_focus(PurpleConversation *conv);
158 static void pidgin_conv_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data); 159 static void pidgin_conv_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data);
159 static void pidgin_conv_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data); 160 static void pidgin_conv_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data);
160 static GdkColor* generate_nick_colors(guint *numcolors, GdkColor background); 161 static GdkColor* generate_nick_colors(guint *numcolors, GdkColor background);
3375 gtk_widget_show(gtkwin->menu.typing_icon); 3376 gtk_widget_show(gtkwin->menu.typing_icon);
3376 return TRUE; 3377 return TRUE;
3377 } 3378 }
3378 3379
3379 static void 3380 static void
3381 update_typing_message(PidginConversation *gtkconv, const char *message)
3382 {
3383 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml));
3384 GtkTextMark *stmark, *enmark;
3385
3386 stmark = gtk_text_buffer_get_mark(buffer, "typing-notification-start");
3387 enmark = gtk_text_buffer_get_mark(buffer, "typing-notification-end");
3388 if (stmark && enmark) {
3389 GtkTextIter start, end;
3390 gtk_text_buffer_get_iter_at_mark(buffer, &start, stmark);
3391 gtk_text_buffer_get_iter_at_mark(buffer, &end, enmark);
3392 gtk_text_buffer_delete_mark(buffer, stmark);
3393 gtk_text_buffer_delete_mark(buffer, enmark);
3394 gtk_text_buffer_delete(buffer, &start, &end);
3395 }
3396
3397 if (message) {
3398 GtkTextIter iter;
3399 gtk_text_buffer_get_end_iter(buffer, &iter);
3400 gtk_text_buffer_create_mark(buffer, "typing-notification-start", &iter, TRUE);
3401 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, message, -1, "TYPING-NOTIFICATION", NULL);
3402 gtk_text_buffer_get_end_iter(buffer, &iter);
3403 gtk_text_buffer_create_mark(buffer, "typing-notification-end", &iter, TRUE);
3404 }
3405 }
3406
3407 static void
3380 update_typing_icon(PidginConversation *gtkconv) 3408 update_typing_icon(PidginConversation *gtkconv)
3381 { 3409 {
3382 PidginWindow *gtkwin; 3410 PidginWindow *gtkwin;
3383 PurpleConvIm *im = NULL; 3411 PurpleConvIm *im = NULL;
3384 PurpleConversation *conv = gtkconv->active_conv; 3412 PurpleConversation *conv = gtkconv->active_conv;
3385 char *stock_id; 3413 char *stock_id;
3386 const char *tooltip; 3414 const char *tooltip;
3415 char *message = NULL;
3387 3416
3388 gtkwin = gtkconv->win; 3417 gtkwin = gtkconv->win;
3389 3418
3390 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) 3419 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
3391 im = PURPLE_CONV_IM(conv); 3420 im = PURPLE_CONV_IM(conv);
3400 if (purple_conv_im_get_typing_state(im) == PURPLE_NOT_TYPING) { 3429 if (purple_conv_im_get_typing_state(im) == PURPLE_NOT_TYPING) {
3401 if (gtkconv->u.im->typing_timer != 0) { 3430 if (gtkconv->u.im->typing_timer != 0) {
3402 g_source_remove(gtkconv->u.im->typing_timer); 3431 g_source_remove(gtkconv->u.im->typing_timer);
3403 gtkconv->u.im->typing_timer = 0; 3432 gtkconv->u.im->typing_timer = 0;
3404 } 3433 }
3434 update_typing_message(gtkconv, NULL);
3405 return; 3435 return;
3406 } 3436 }
3407 3437
3408 if (purple_conv_im_get_typing_state(im) == PURPLE_TYPING) { 3438 if (purple_conv_im_get_typing_state(im) == PURPLE_TYPING) {
3409 if (gtkconv->u.im->typing_timer == 0) { 3439 if (gtkconv->u.im->typing_timer == 0) {
3410 gtkconv->u.im->typing_timer = g_timeout_add(250, typing_animation, gtkconv); 3440 gtkconv->u.im->typing_timer = g_timeout_add(250, typing_animation, gtkconv);
3411 } 3441 }
3412 stock_id = PIDGIN_STOCK_ANIMATION_TYPING1; 3442 stock_id = PIDGIN_STOCK_ANIMATION_TYPING1;
3413 tooltip = _("User is typing..."); 3443 tooltip = _("User is typing...");
3444 message = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv));
3414 } else { 3445 } else {
3415 stock_id = PIDGIN_STOCK_ANIMATION_TYPING5; 3446 stock_id = PIDGIN_STOCK_ANIMATION_TYPING5;
3416 tooltip = _("User has typed something and stopped"); 3447 tooltip = _("User has typed something and stopped");
3448 message = g_strdup_printf(_("\n%s has typed something and stopped"), purple_conversation_get_name(conv));
3417 if (gtkconv->u.im->typing_timer != 0) { 3449 if (gtkconv->u.im->typing_timer != 0) {
3418 g_source_remove(gtkconv->u.im->typing_timer); 3450 g_source_remove(gtkconv->u.im->typing_timer);
3419 gtkconv->u.im->typing_timer = 0; 3451 gtkconv->u.im->typing_timer = 0;
3420 } 3452 }
3421 } 3453 }
3434 gtkwin->menu.typing_icon, 3466 gtkwin->menu.typing_icon,
3435 tooltip); 3467 tooltip);
3436 } 3468 }
3437 3469
3438 gtk_widget_show(gtkwin->menu.typing_icon); 3470 gtk_widget_show(gtkwin->menu.typing_icon);
3471 update_typing_message(gtkconv, message);
3472 g_free(message);
3439 } 3473 }
3440 3474
3441 static gboolean 3475 static gboolean
3442 update_send_to_selection(PidginWindow *win) 3476 update_send_to_selection(PidginWindow *win)
3443 { 3477 {
5028 G_CALLBACK(conv_dnd_recv), gtkconv); 5062 G_CALLBACK(conv_dnd_recv), gtkconv);
5029 g_signal_connect(G_OBJECT(gtkconv->imhtml), "drag_data_received", 5063 g_signal_connect(G_OBJECT(gtkconv->imhtml), "drag_data_received",
5030 G_CALLBACK(conv_dnd_recv), gtkconv); 5064 G_CALLBACK(conv_dnd_recv), gtkconv);
5031 g_signal_connect(G_OBJECT(gtkconv->entry), "drag_data_received", 5065 g_signal_connect(G_OBJECT(gtkconv->entry), "drag_data_received",
5032 G_CALLBACK(conv_dnd_recv), gtkconv); 5066 G_CALLBACK(conv_dnd_recv), gtkconv);
5067
5068 gtk_text_buffer_create_tag(GTK_IMHTML(gtkconv->imhtml)->text_buffer, "TYPING-NOTIFICATION",
5069 "foreground", "#888888",
5070 "justification", GTK_JUSTIFY_LEFT, /* XXX: RTL'ify */
5071 "weight", PANGO_WEIGHT_BOLD, NULL);
5033 5072
5034 /* Setup the container for the tab. */ 5073 /* Setup the container for the tab. */
5035 gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); 5074 gtkconv->tab_cont = tab_cont = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
5036 g_object_set_data(G_OBJECT(tab_cont), "PidginConversation", gtkconv); 5075 g_object_set_data(G_OBJECT(tab_cont), "PidginConversation", gtkconv);
5037 gtk_container_set_border_width(GTK_CONTAINER(tab_cont), PIDGIN_HIG_BOX_SPACE); 5076 gtk_container_set_border_width(GTK_CONTAINER(tab_cont), PIDGIN_HIG_BOX_SPACE);