Mercurial > pidgin.yaz
comparison src/conversation.c @ 13842:a9ff4499d9ce
[gaim-migrate @ 16295]
Hopefully improve the typing notification code so it's a lot easier
to understand. This also creates a distinction between the signals
emitted when receiving GAIM_TYPED and GAIM_NOT_TYPING messages
(by adding a gaim-typed signal). And the gaim-not-typing signal
should work in all cases.
Most of this is stuff I changed last week during work, thanks to
Meebo
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 20 Jun 2006 08:17:49 +0000 |
parents | dd00149f6f9b |
children | 60278852c20c |
comparison
equal
deleted
inserted
replaced
13841:f3d4a9902ead | 13842:a9ff4499d9ce |
---|---|
44 { | 44 { |
45 default_ops = ops; | 45 default_ops = ops; |
46 } | 46 } |
47 | 47 |
48 static gboolean | 48 static gboolean |
49 reset_typing(gpointer data) | 49 reset_typing_cb(gpointer data) |
50 { | 50 { |
51 GaimConversation *c = (GaimConversation *)data; | 51 GaimConversation *c = (GaimConversation *)data; |
52 GaimConvIm *im; | 52 GaimConvIm *im; |
53 | |
54 if (!g_list_find(conversations, c)) | |
55 return FALSE; | |
56 | 53 |
57 im = GAIM_CONV_IM(c); | 54 im = GAIM_CONV_IM(c); |
58 | 55 |
59 gaim_conv_im_set_typing_state(im, GAIM_NOT_TYPING); | 56 gaim_conv_im_set_typing_state(im, GAIM_NOT_TYPING); |
60 gaim_conv_im_update_typing(im); | 57 gaim_conv_im_update_typing(im); |
61 gaim_conv_im_stop_typing_timeout(im); | 58 gaim_conv_im_stop_typing_timeout(im); |
62 | 59 |
60 gaim_signal_emit(gaim_conversations_get_handle(), | |
61 "buddy-typing-stopped", c); | |
62 | |
63 return FALSE; | 63 return FALSE; |
64 } | 64 } |
65 | 65 |
66 static gboolean | 66 static gboolean |
67 send_typed(gpointer data) | 67 send_typed_cb(gpointer data) |
68 { | 68 { |
69 GaimConversation *conv = (GaimConversation *)data; | 69 GaimConversation *conv = (GaimConversation *)data; |
70 GaimConnection *gc; | 70 GaimConnection *gc; |
71 const char *name; | 71 const char *name; |
72 | 72 |
73 g_return_val_if_fail(conv != NULL, FALSE); | 73 g_return_val_if_fail(conv != NULL, FALSE); |
74 | 74 |
75 gc = gaim_conversation_get_gc(conv); | 75 gc = gaim_conversation_get_gc(conv); |
76 name = gaim_conversation_get_name(conv); | 76 name = gaim_conversation_get_name(conv); |
77 | 77 |
78 if (gc != NULL && name != NULL) { | 78 if (gc != NULL && name != NULL) { |
79 gaim_conv_im_set_type_again(GAIM_CONV_IM(conv), TRUE); | 79 /* We set this to 1 so that GAIM_TYPING will be sent |
80 * if the Gaim user types anything else. | |
81 */ | |
82 gaim_conv_im_set_type_again(GAIM_CONV_IM(conv), 1); | |
80 | 83 |
81 serv_send_typing(gc, name, GAIM_TYPED); | 84 serv_send_typing(gc, name, GAIM_TYPED); |
85 gaim_signal_emit(gaim_conversations_get_handle(), | |
86 "buddy-typed", conv); | |
82 | 87 |
83 gaim_debug(GAIM_DEBUG_MISC, "conversation", "typed...\n"); | 88 gaim_debug(GAIM_DEBUG_MISC, "conversation", "typed...\n"); |
84 } | 89 } |
85 | 90 |
86 return FALSE; | 91 return FALSE; |
418 conv->name = NULL; | 423 conv->name = NULL; |
419 conv->title = NULL; | 424 conv->title = NULL; |
420 | 425 |
421 if (conv->type == GAIM_CONV_TYPE_IM) { | 426 if (conv->type == GAIM_CONV_TYPE_IM) { |
422 gaim_conv_im_stop_typing_timeout(conv->u.im); | 427 gaim_conv_im_stop_typing_timeout(conv->u.im); |
423 gaim_conv_im_stop_type_again_timeout(conv->u.im); | 428 gaim_conv_im_stop_send_typed_timeout(conv->u.im); |
424 | 429 |
425 if (conv->u.im->icon != NULL) | 430 if (conv->u.im->icon != NULL) |
426 gaim_buddy_icon_unref(conv->u.im->icon); | 431 gaim_buddy_icon_unref(conv->u.im->icon); |
427 conv->u.im->icon = NULL; | 432 conv->u.im->icon = NULL; |
428 | 433 |
984 if (state == GAIM_TYPING) | 989 if (state == GAIM_TYPING) |
985 { | 990 { |
986 gaim_signal_emit(gaim_conversations_get_handle(), | 991 gaim_signal_emit(gaim_conversations_get_handle(), |
987 "buddy-typing", im->conv->account, im->conv->name); | 992 "buddy-typing", im->conv->account, im->conv->name); |
988 } | 993 } |
989 else | 994 else if (state == GAIM_TYPED) |
995 { | |
996 gaim_signal_emit(gaim_conversations_get_handle(), | |
997 "buddy-typed", im->conv->account, im->conv->name); | |
998 } | |
999 else if (state == GAIM_NOT_TYPING) | |
990 { | 1000 { |
991 gaim_signal_emit(gaim_conversations_get_handle(), | 1001 gaim_signal_emit(gaim_conversations_get_handle(), |
992 "buddy-typing-stopped", im->conv->account, im->conv->name); | 1002 "buddy-typing-stopped", im->conv->account, im->conv->name); |
993 } | 1003 } |
994 } | 1004 } |
1014 gaim_conv_im_stop_typing_timeout(im); | 1024 gaim_conv_im_stop_typing_timeout(im); |
1015 | 1025 |
1016 conv = gaim_conv_im_get_conversation(im); | 1026 conv = gaim_conv_im_get_conversation(im); |
1017 name = gaim_conversation_get_name(conv); | 1027 name = gaim_conversation_get_name(conv); |
1018 | 1028 |
1019 im->typing_timeout = gaim_timeout_add(timeout * 1000, reset_typing, conv); | 1029 im->typing_timeout = gaim_timeout_add(timeout * 1000, reset_typing_cb, conv); |
1020 } | 1030 } |
1021 | 1031 |
1022 void | 1032 void |
1023 gaim_conv_im_stop_typing_timeout(GaimConvIm *im) | 1033 gaim_conv_im_stop_typing_timeout(GaimConvIm *im) |
1024 { | 1034 { |
1038 | 1048 |
1039 return im->typing_timeout; | 1049 return im->typing_timeout; |
1040 } | 1050 } |
1041 | 1051 |
1042 void | 1052 void |
1043 gaim_conv_im_set_type_again(GaimConvIm *im, time_t val) | 1053 gaim_conv_im_set_type_again(GaimConvIm *im, unsigned int val) |
1044 { | 1054 { |
1045 g_return_if_fail(im != NULL); | 1055 g_return_if_fail(im != NULL); |
1046 | 1056 |
1047 im->type_again = val; | 1057 if (val == 0) |
1058 im->type_again = 0; | |
1059 else | |
1060 im->type_again = time(NULL) + val; | |
1048 } | 1061 } |
1049 | 1062 |
1050 time_t | 1063 time_t |
1051 gaim_conv_im_get_type_again(const GaimConvIm *im) | 1064 gaim_conv_im_get_type_again(const GaimConvIm *im) |
1052 { | 1065 { |
1054 | 1067 |
1055 return im->type_again; | 1068 return im->type_again; |
1056 } | 1069 } |
1057 | 1070 |
1058 void | 1071 void |
1059 gaim_conv_im_start_type_again_timeout(GaimConvIm *im) | 1072 gaim_conv_im_start_send_typed_timeout(GaimConvIm *im) |
1060 { | 1073 { |
1061 g_return_if_fail(im != NULL); | 1074 g_return_if_fail(im != NULL); |
1062 | 1075 |
1063 im->type_again_timeout = gaim_timeout_add(SEND_TYPED_TIMEOUT, send_typed, | 1076 im->send_typed_timeout = gaim_timeout_add(SEND_TYPED_TIMEOUT, send_typed_cb, |
1064 gaim_conv_im_get_conversation(im)); | 1077 gaim_conv_im_get_conversation(im)); |
1065 } | 1078 } |
1066 | 1079 |
1067 void | 1080 void |
1068 gaim_conv_im_stop_type_again_timeout(GaimConvIm *im) | 1081 gaim_conv_im_stop_send_typed_timeout(GaimConvIm *im) |
1069 { | 1082 { |
1070 g_return_if_fail(im != NULL); | 1083 g_return_if_fail(im != NULL); |
1071 | 1084 |
1072 if (im->type_again_timeout == 0) | 1085 if (im->send_typed_timeout == 0) |
1073 return; | 1086 return; |
1074 | 1087 |
1075 gaim_timeout_remove(im->type_again_timeout); | 1088 gaim_timeout_remove(im->send_typed_timeout); |
1076 im->type_again_timeout = 0; | 1089 im->send_typed_timeout = 0; |
1077 } | 1090 } |
1078 | 1091 |
1079 guint | 1092 guint |
1080 gaim_conv_im_get_type_again_timeout(const GaimConvIm *im) | 1093 gaim_conv_im_get_send_typed_timeout(const GaimConvIm *im) |
1081 { | 1094 { |
1082 g_return_val_if_fail(im != NULL, 0); | 1095 g_return_val_if_fail(im != NULL, 0); |
1083 | 1096 |
1084 return im->type_again_timeout; | 1097 return im->send_typed_timeout; |
1085 } | 1098 } |
1086 | 1099 |
1087 void | 1100 void |
1088 gaim_conv_im_update_typing(GaimConvIm *im) | 1101 gaim_conv_im_update_typing(GaimConvIm *im) |
1089 { | 1102 { |
2088 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | 2101 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, |
2089 gaim_value_new(GAIM_TYPE_SUBTYPE, | 2102 gaim_value_new(GAIM_TYPE_SUBTYPE, |
2090 GAIM_SUBTYPE_ACCOUNT), | 2103 GAIM_SUBTYPE_ACCOUNT), |
2091 gaim_value_new(GAIM_TYPE_STRING)); | 2104 gaim_value_new(GAIM_TYPE_STRING)); |
2092 | 2105 |
2106 gaim_signal_register(handle, "buddy-typed", | |
2107 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | |
2108 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2109 GAIM_SUBTYPE_ACCOUNT), | |
2110 gaim_value_new(GAIM_TYPE_STRING)); | |
2111 | |
2093 gaim_signal_register(handle, "buddy-typing-stopped", | 2112 gaim_signal_register(handle, "buddy-typing-stopped", |
2094 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | 2113 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, |
2095 gaim_value_new(GAIM_TYPE_SUBTYPE, | 2114 gaim_value_new(GAIM_TYPE_SUBTYPE, |
2096 GAIM_SUBTYPE_ACCOUNT), | 2115 GAIM_SUBTYPE_ACCOUNT), |
2097 gaim_value_new(GAIM_TYPE_STRING)); | 2116 gaim_value_new(GAIM_TYPE_STRING)); |