/pidgin/main: 51d25c394fca: Convert conversation entry to a GtkW...

Elliott Sales de Andrade qulogic at pidgin.im
Tue Aug 14 04:03:27 EDT 2012


Changeset: 51d25c394fca4eff3d0a82485244189f641b484e
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2012-08-13 23:48 -0400
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/51d25c394fca

Description:

Convert conversation entry to a GtkWebView.

However, sizing still doesn't work right. Also, commands or tab
complete aren't done yet.

diffstat:

 pidgin/gtkconv.c |  342 ++++++++++++++++++++++++++++--------------------------
 pidgin/gtkconv.h |    1 -
 2 files changed, 177 insertions(+), 166 deletions(-)

diffs (truncated from 757 to 300 lines):

diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -64,8 +64,6 @@
 #include "gtkconv-theme.h"
 #include "gtkconv-theme-loader.h"
 #include "gtkdialogs.h"
-#include "gtkimhtml.h"
-#include "gtkimhtmltoolbar.h"
 #include "gtklog.h"
 #include "gtkmenutray.h"
 #include "gtkpounce.h"
@@ -74,6 +72,7 @@
 #include "gtkthemes.h"
 #include "gtkutils.h"
 #include "gtkwebview.h"
+#include "gtkwebviewtoolbar.h"
 #include "pidginstock.h"
 #include "pidgintooltip.h"
 #include "smileyparser.h"
@@ -331,20 +330,24 @@ static void
 default_formatize(PidginConversation *c)
 {
 	PurpleConversation *conv = c->active_conv;
-	gtk_imhtml_setup_entry(GTK_IMHTML(c->entry), purple_conversation_get_features(conv));
+	gtk_webview_setup_entry(GTK_WEBVIEW(c->entry), purple_conversation_get_features(conv));
 }
 
 static void
 conversation_entry_clear(PidginConversation *gtkconv)
 {
-	GtkIMHtml *imhtml = GTK_IMHTML(gtkconv->entry);
-	gtk_source_undo_manager_begin_not_undoable_action(imhtml->undo_manager);
-	gtk_imhtml_clear(imhtml);
-	gtk_source_undo_manager_end_not_undoable_action(imhtml->undo_manager);
-}
-
-static void
-clear_formatting_cb(GtkIMHtml *imhtml, PidginConversation *gtkconv)
+	GtkWebView *webview = GTK_WEBVIEW(gtkconv->entry);
+	gtk_webview_load_html_string(webview, "");
+#if 0
+	/* TODO WebKit */
+	gtk_source_undo_manager_begin_not_undoable_action(webview->undo_manager);
+	gtk_webview_clear(webview);
+	gtk_source_undo_manager_end_not_undoable_action(webview->undo_manager);
+#endif
+}
+
+static void
+clear_formatting_cb(GtkWebView *webview, PidginConversation *gtkconv)
 {
 	default_formatize(gtkconv);
 }
@@ -541,16 +544,13 @@ check_for_and_do_command(PurpleConversat
 	gtkconv = PIDGIN_CONVERSATION(conv);
 	prefix = pidgin_get_cmd_prefix();
 
-	cmd = gtk_imhtml_get_text(GTK_IMHTML(gtkconv->entry), NULL, NULL);
-	gtk_text_buffer_get_start_iter(GTK_IMHTML(gtkconv->entry)->text_buffer, &start);
-
-	if (cmd && (strncmp(cmd, prefix, strlen(prefix)) == 0)
-	   && !gtk_text_iter_get_child_anchor(&start)) {
+	cmd = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry));
+
+	if (cmd && purple_str_has_prefix(cmd, prefix)) {
 		PurpleCmdStatus status;
 		char *error, *cmdline, *markup, *send_history;
-		GtkTextIter end;
-
-		send_history = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry));
+
+		send_history = gtk_webview_get_body_html(GTK_WEBVIEW(gtkconv->entry));
 		send_history_add(gtkconv, send_history);
 		g_free(send_history);
 
@@ -563,9 +563,8 @@ check_for_and_do_command(PurpleConversat
 			return TRUE;
 		}
 
-		gtk_text_iter_forward_chars(&start, g_utf8_strlen(prefix, -1));
-		gtk_text_buffer_get_end_iter(GTK_IMHTML(gtkconv->entry)->text_buffer, &end);
-		markup = gtk_imhtml_get_markup_range(GTK_IMHTML(gtkconv->entry), &start, &end);
+		/* TODO WebKit: Cut out prefix for markup... */
+		markup = gtk_webview_get_body_html(GTK_WEBVIEW(gtkconv->entry));
 		status = purple_cmd_do_command(conv, cmdline, markup, &error);
 		g_free(markup);
 
@@ -627,6 +626,7 @@ check_for_and_do_command(PurpleConversat
 	}
 
 	g_free(cmd);
+
 	return retval;
 }
 
@@ -653,8 +653,8 @@ send_cb(GtkWidget *widget, PidginConvers
 	if (!purple_account_is_connected(account))
 		return;
 
-	buf = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry));
-	clean = gtk_imhtml_get_text(GTK_IMHTML(gtkconv->entry), NULL, NULL);
+	buf = gtk_webview_get_body_html(GTK_WEBVIEW(gtkconv->entry));
+	clean = gtk_webview_get_body_text(GTK_WEBVIEW(gtkconv->entry));
 
 	gtk_widget_grab_focus(gtkconv->entry);
 
@@ -666,16 +666,21 @@ send_cb(GtkWidget *widget, PidginConvers
 
 	purple_idle_touch();
 
+#if 0
+	/* TODO WebKit: Image stuff... */
 	/* XXX: is there a better way to tell if the message has images? */
-	if (GTK_IMHTML(gtkconv->entry)->im_images != NULL)
+	if (GTK_WEBVIEW(gtkconv->entry)->im_images != NULL)
 		flags |= PURPLE_MESSAGE_IMAGES;
-
-	gc = purple_account_get_connection(account);
+#endif
+
+	gc = NULL/*purple_account_get_connection(account)*/;
 	if (gc && (purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_NEWLINES)) {
+#if 0
+		/* TODO WebKit */
 		char **bufs;
 		int i;
 
-		bufs = gtk_imhtml_get_markup_lines(GTK_IMHTML(gtkconv->entry));
+		bufs = gtk_webview_get_markup_lines(GTK_WEBVIEW(gtkconv->entry));
 		for (i = 0; bufs[i]; i++) {
 			send_history_add(gtkconv, bufs[i]);
 			if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
@@ -685,6 +690,7 @@ send_cb(GtkWidget *widget, PidginConvers
 		}
 
 		g_strfreev(bufs);
+#endif
 
 	} else {
 		send_history_add(gtkconv, buf);
@@ -1265,13 +1271,12 @@ menu_insert_link_cb(GtkAction *action, g
 {
 	PidginWindow *win = data;
 	PidginConversation *gtkconv;
-	GtkIMHtmlToolbar *toolbar;
+	GtkWebViewToolbar *toolbar;
 
 	gtkconv = pidgin_conv_window_get_active_gtkconv(win);
-	toolbar = GTK_IMHTMLTOOLBAR(gtkconv->toolbar);
-
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link),
-			!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->link)));
+	toolbar = GTK_WEBVIEWTOOLBAR(gtkconv->toolbar);
+
+	gtk_webviewtoolbar_activate(toolbar, GTK_WEBVIEWTOOLBAR_ACTION_LINK);
 }
 
 static void
@@ -1279,15 +1284,13 @@ menu_insert_image_cb(GtkAction *action, 
 {
 	PidginWindow *win = data;
 	PidginConversation *gtkconv;
-	GtkIMHtmlToolbar *toolbar;
+	GtkWebViewToolbar *toolbar;
 
 	gtkconv = pidgin_conv_window_get_active_gtkconv(win);
-	toolbar = GTK_IMHTMLTOOLBAR(gtkconv->toolbar);
-
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image),
-			!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->image)));
-}
-
+	toolbar = GTK_WEBVIEWTOOLBAR(gtkconv->toolbar);
+
+	gtk_webviewtoolbar_activate(toolbar, GTK_WEBVIEWTOOLBAR_ACTION_IMAGE);
+}
 
 static void
 menu_alias_cb(GtkAction *action, gpointer data)
@@ -1961,7 +1964,7 @@ conv_keypress_common(PidginConversation 
 	PidginWindow *win;
 	int curconv;
 
-	win      = gtkconv->win;
+	win     = gtkconv->win;
 	curconv = gtk_notebook_get_current_page(GTK_NOTEBOOK(win->notebook));
 
 	/* clear any tooltips */
@@ -2077,44 +2080,42 @@ entry_key_press_cb(GtkWidget *entry, Gdk
 					break;
 
 				if (!gtkconv->send_history->prev) {
-					GtkTextIter start, end;
-
 					g_free(gtkconv->send_history->data);
 
-					gtk_text_buffer_get_start_iter(gtkconv->entry_buffer,
-												   &start);
-					gtk_text_buffer_get_end_iter(gtkconv->entry_buffer, &end);
-
 					gtkconv->send_history->data =
-						gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry));
+						gtk_webview_get_body_html(GTK_WEBVIEW(gtkconv->entry));
 				}
 
 				if (gtkconv->send_history->next && gtkconv->send_history->next->data) {
 					GObject *object;
+#if 0
+					/* TODO WebKit: maybe not necessary? */
 					GtkTextIter iter;
 					GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
+#endif
 
 					gtkconv->send_history = gtkconv->send_history->next;
 
 					/* Block the signal to prevent application of default formatting. */
 					object = g_object_ref(G_OBJECT(gtkconv->entry));
-					g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
-													NULL, gtkconv);
+					g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA,
+					                                0, 0, NULL, NULL, gtkconv);
 					/* Clear the formatting. */
-					gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry));
+					gtk_webview_clear_formatting(GTK_WEBVIEW(gtkconv->entry));
 					/* Unblock the signal. */
-					g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
-													  NULL, gtkconv);
+					g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA,
+					                                  0, 0, NULL, NULL, gtkconv);
 					g_object_unref(object);
 
-					gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
-					gtk_imhtml_append_text_with_images(
-						GTK_IMHTML(gtkconv->entry), gtkconv->send_history->data,
-						0, NULL);
+					gtk_webview_load_html_string(GTK_WEBVIEW(gtkconv->entry),
+					                             gtkconv->send_history->data);
 					/* this is mainly just a hack so the formatting at the
 					 * cursor gets picked up. */
+#if 0
+					/* TODO WebKit: maybe not necessary? */
 					gtk_text_buffer_get_end_iter(buffer, &iter);
 					gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter);
+#endif
 				}
 
 				return TRUE;
@@ -2129,31 +2130,35 @@ entry_key_press_cb(GtkWidget *entry, Gdk
 
 				if (gtkconv->send_history->prev && gtkconv->send_history->prev->data) {
 					GObject *object;
+#if 0
+					/* TODO WebKit: maybe not necessary? */
 					GtkTextIter iter;
 					GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
+#endif
 
 					gtkconv->send_history = gtkconv->send_history->prev;
 
 					/* Block the signal to prevent application of default formatting. */
 					object = g_object_ref(G_OBJECT(gtkconv->entry));
-					g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
-													NULL, gtkconv);
+					g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA,
+					                                0, 0, NULL, NULL, gtkconv);
 					/* Clear the formatting. */
-					gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry));
+					gtk_webview_clear_formatting(GTK_WEBVIEW(gtkconv->entry));
 					/* Unblock the signal. */
-					g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL,
-													  NULL, gtkconv);
+					g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA,
+					                                  0, 0, NULL, NULL, gtkconv);
 					g_object_unref(object);
 
-					gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
-					gtk_imhtml_append_text_with_images(
-						GTK_IMHTML(gtkconv->entry), gtkconv->send_history->data,
-						0, NULL);
+					gtk_webview_load_html_string(GTK_WEBVIEW(gtkconv->entry),
+					                             gtkconv->send_history->data);
 					/* this is mainly just a hack so the formatting at the
 					 * cursor gets picked up. */
 					if (*(char *)gtkconv->send_history->data) {
+#if 0
+					/* TODO WebKit: maybe not necessary? */
 						gtk_text_buffer_get_end_iter(buffer, &iter);
 						gtk_text_buffer_move_mark_by_name(buffer, "insert", &iter);
+#endif
 					} else {
 						/* Restore the default formatting */
 						default_formatize(gtkconv);
@@ -2199,6 +2204,12 @@ entry_key_press_cb(GtkWidget *entry, Gdk
 			return TRUE;
 			break;
 
+		case GDK_KEY_KP_Enter:
+		case GDK_KEY_Return:
+			send_cb(entry, gtkconv);



More information about the Commits mailing list