comparison console/gntconv.c @ 15201:6a647ede0a76

[gaim-migrate @ 17990] Update the typing notification properly. Some change to sending typing notification. It needs more work. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 14 Dec 2006 01:06:18 +0000
parents fc4d6f704d46
children 4e004a29ccf3
comparison
equal deleted inserted replaced
15200:b52cdf3cff4f 15201:6a647ede0a76
43 #include "gnttextview.h" 43 #include "gnttextview.h"
44 44
45 #define PREF_ROOT "/gaim/gnt/conversations" 45 #define PREF_ROOT "/gaim/gnt/conversations"
46 46
47 #include "config.h" 47 #include "config.h"
48
49 static gboolean
50 send_typing_notification(GntWidget *w, const char *key, GGConv *ggconv)
51 {
52 if (key[0] != 27 && key[0] != '\r') {
53 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
54 gboolean first = (!text || !*text);
55 if (gaim_prefs_get_bool("/gaim/gnt/conversations/notify_typing")) {
56 /* Xerox'ed */
57 GaimConversation *conv = ggconv->active_conv;
58 GaimConvIm *im = GAIM_CONV_IM(conv);
59
60 gaim_conv_im_stop_send_typed_timeout(im);
61 gaim_conv_im_start_send_typed_timeout(im);
62 if (first || (gaim_conv_im_get_type_again(im) != 0 &&
63 time(NULL) > gaim_conv_im_get_type_again(im))) {
64 unsigned int timeout;
65 timeout = serv_send_typing(gaim_conversation_get_gc(conv),
66 gaim_conversation_get_name(conv),
67 GAIM_TYPING);
68 gaim_conv_im_set_type_again(im, timeout);
69 }
70 }
71 }
72 return FALSE;
73 }
48 74
49 static gboolean 75 static gboolean
50 entry_key_pressed(GntWidget *w, const char *key, GGConv *ggconv) 76 entry_key_pressed(GntWidget *w, const char *key, GGConv *ggconv)
51 { 77 {
52 if (key[0] == '\r' && key[1] == 0) 78 if (key[0] == '\r' && key[1] == 0)
140 return FALSE; 166 return FALSE;
141 return TRUE; 167 return TRUE;
142 } 168 }
143 else 169 else
144 { 170 {
145 gboolean first = !gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
146 if (gaim_prefs_get_bool("/gaim/gnt/conversations/notify_typing")) {
147 /* Xerox'ed */
148 GaimConversation *conv = ggconv->active_conv;
149 GaimConvIm *im = GAIM_CONV_IM(conv);
150
151 gaim_conv_im_stop_send_typed_timeout(im);
152 gaim_conv_im_start_send_typed_timeout(im);
153 if (first || (gaim_conv_im_get_type_again(im) != 0 &&
154 time(NULL) > gaim_conv_im_get_type_again(im))) {
155 unsigned int timeout;
156 timeout = serv_send_typing(gaim_conversation_get_gc(conv),
157 gaim_conversation_get_name(conv),
158 GAIM_TYPING);
159 gaim_conv_im_set_type_again(im, timeout);
160 }
161 }
162 } 171 }
163 172
164 return FALSE; 173 return FALSE;
165 } 174 }
166 175
242 gnt_ascii_only() ? "T" : "\342\243\277"); 251 gnt_ascii_only() ? "T" : "\342\243\277");
243 g_free(str); 252 g_free(str);
244 253
245 scroll = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggc->tv)); 254 scroll = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggc->tv));
246 str = g_strdup_printf(_("\n%s is typing..."), gaim_conversation_get_name(conv)); 255 str = g_strdup_printf(_("\n%s is typing..."), gaim_conversation_get_name(conv));
247 /* Update an existing notification if there's one. */ 256 /* Updating is a little buggy. So just remove and add a new one */
248 if (gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", str, TRUE) == 0) 257 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE);
249 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggc->tv), 258 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggc->tv),
250 str, GNT_TEXT_FLAG_DIM, "typing"); 259 str, GNT_TEXT_FLAG_DIM, "typing");
251 g_free(str); 260 g_free(str);
252 if (scroll <= 1) 261 if (scroll <= 1)
253 gnt_text_view_scroll(GNT_TEXT_VIEW(ggc->tv), 0); 262 gnt_text_view_scroll(GNT_TEXT_VIEW(ggc->tv), 0);
254 } else { 263 } else {
255 title = get_conversation_title(conv, account); 264 title = get_conversation_title(conv, account);
315 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1); 324 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1);
316 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE); 325 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE);
317 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE); 326 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE);
318 327
319 g_signal_connect_after(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc); 328 g_signal_connect_after(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc);
329 g_signal_connect(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(send_typing_notification), ggc);
320 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); 330 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc);
321 331
322 gnt_widget_set_position(ggc->window, gaim_prefs_get_int(PREF_ROOT "/position/x"), 332 gnt_widget_set_position(ggc->window, gaim_prefs_get_int(PREF_ROOT "/position/x"),
323 gaim_prefs_get_int(PREF_ROOT "/position/y")); 333 gaim_prefs_get_int(PREF_ROOT "/position/y"));
324 gnt_widget_show(ggc->window); 334 gnt_widget_show(ggc->window);