/pidgin/main: 592be5c74b68: Fix sending of typing state

Ankit Vani a at nevitus.org
Sun Jan 12 05:46:35 EST 2014


Changeset: 592be5c74b6838c1789263220cc42628b54b187f
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2014-01-12 16:15 +0530
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/592be5c74b68

Description:

Fix sending of typing state

diffstat:

 pidgin/gtkconv.c |  95 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 59 insertions(+), 36 deletions(-)

diffs (131 lines):

diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -206,7 +206,6 @@ static gboolean tab_complete(PurpleConve
 static void pidgin_conv_updated(PurpleConversation *conv, PurpleConversationUpdateType type);
 static void conv_set_unseen(PurpleConversation *gtkconv, PidginUnseenState state);
 static void gtkconv_set_unseen(PidginConversation *gtkconv, PidginUnseenState state);
-static void update_typing_state(PidginConversation *gtkconv, gboolean deleting);
 static void update_typing_icon(PidginConversation *gtkconv);
 static void update_typing_message(PidginConversation *gtkconv, const char *message);
 gboolean pidgin_conv_has_focus(PurpleConversation *conv);
@@ -1944,6 +1943,58 @@ gtkconv_cycle_focus(PidginConversation *
 	return !!next;
 }
 
+static void
+update_typing_inserting(PidginConversation *gtkconv)
+{
+	gchar *text;
+
+	g_return_if_fail(gtkconv != NULL);
+
+	text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry));
+
+	got_typing_keypress(gtkconv, text[0] == '\0' || !strcmp(text, "\n"));
+
+	g_free(text);
+}
+
+static gboolean
+update_typing_deleting_cb(PidginConversation *gtkconv)
+{
+	PurpleIMConversation *im = PURPLE_IM_CONVERSATION(gtkconv->active_conv);
+	gchar *text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry));
+
+	if (!*text || !strcmp(text, "\n")) {
+		/* We deleted all the text, so turn off typing. */
+		purple_im_conversation_stop_send_typed_timeout(im);
+
+		serv_send_typing(purple_conversation_get_connection(gtkconv->active_conv),
+						 purple_conversation_get_name(gtkconv->active_conv),
+						 PURPLE_IM_NOT_TYPING);
+	}
+	else {
+		/* We're deleting, but not all of it, so it counts as typing. */
+		got_typing_keypress(gtkconv, FALSE);
+	}
+	g_free(text);
+
+	return FALSE;
+}
+
+static void
+update_typing_deleting(PidginConversation *gtkconv)
+{
+	gchar *text;
+
+	g_return_val_if_fail(gtkconv != NULL, FALSE);
+
+	text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry));
+
+	if (*text && strcmp(text, "\n"))
+		purple_timeout_add(0, (GSourceFunc)update_typing_deleting_cb, gtkconv);
+
+	g_free(text);
+}
+
 static gboolean
 conv_keypress_common(PidginConversation *gtkconv, GdkEventKey *event)
 {
@@ -2199,17 +2250,18 @@ entry_key_press_cb(GtkWidget *entry, Gdk
 		}
 	}
 
-	if (PURPLE_IS_IM_CONVERSATION(conv)) {
-		gboolean deleting = FALSE;
+	if (PURPLE_IS_IM_CONVERSATION(conv) &&
+			purple_prefs_get_bool("/purple/conversations/im/send_typing")) {
 
 		switch (event->keyval) {
 		case GDK_KEY_BackSpace:
 		case GDK_KEY_Delete:
 		case GDK_KEY_KP_Delete:
-			deleting = TRUE;
-		}
-
-		update_typing_state(gtkconv, deleting);
+			update_typing_deleting(gtkconv);
+			break;
+		default:
+			update_typing_inserting(gtkconv);
+		}
 	}
 
 	return FALSE;
@@ -2423,35 +2475,6 @@ menu_conv_sel_send_cb(GObject *m, gpoint
 	pidgin_conv_switch_active_conversation(PURPLE_CONVERSATION(im));
 }
 
-static void
-update_typing_state(PidginConversation *gtkconv, gboolean deleting)
-{
-	PurpleIMConversation *im;
-	gchar *text;
-
-	g_return_if_fail(gtkconv != NULL);
-
-	if (!purple_prefs_get_bool("/purple/conversations/im/send_typing"))
-		return;
-
-	im = PURPLE_IM_CONVERSATION(gtkconv->active_conv);
-
-	text = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry));
-
-	if (!*text) {
-
-		/* We deleted all the text, so turn off typing. */
-		purple_im_conversation_stop_send_typed_timeout(im);
-
-		serv_send_typing(purple_conversation_get_connection(gtkconv->active_conv),
-						 purple_conversation_get_name(gtkconv->active_conv),
-						 PURPLE_IM_NOT_TYPING);
-	}
-	else {
-		got_typing_keypress(gtkconv, !deleting && text[1] == '\0');
-	}
-}
-
 /**************************************************************************
  * A bunch of buddy icon functions
  **************************************************************************/



More information about the Commits mailing list