pidgin: f102530d: Add a function for setting a WebView ent...

qulogic at pidgin.im qulogic at pidgin.im
Thu Jan 5 23:01:47 EST 2012


----------------------------------------------------------------------
Revision: f102530de280bc229ae948996fc728655d498b40
Parent:   f8cbd95346df8e53fb9bab967c3871456508c909
Author:   qulogic at pidgin.im
Date:     01/04/12 20:10:12
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f102530de280bc229ae948996fc728655d498b40

Changelog: 

Add a function for setting a WebView entry based on the
connection flags.

Changes against parent f8cbd95346df8e53fb9bab967c3871456508c909

  patched  pidgin/gtkwebview.c
  patched  pidgin/gtkwebview.h

-------------- next part --------------
============================================================
--- pidgin/gtkwebview.c	c677e914c56ca30e3489c48811a68fa578afe36b
+++ pidgin/gtkwebview.c	b40c2bda5f3e0d67d5f9dc32c66137c6f28ddb3b
@@ -300,6 +300,33 @@ scroll_idle_cb(gpointer data)
 	return FALSE;
 }
 
+static void
+webview_clear_formatting(GtkWebView *webview)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+	if (!webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview)))
+		return;
+
+	priv->edit.bold = FALSE;
+	priv->edit.italic = FALSE;
+	priv->edit.underline = FALSE;
+	priv->edit.strike = FALSE;
+	priv->edit.fontsize = 0;
+
+	g_free(priv->edit.fontface);
+	priv->edit.fontface = NULL;
+
+	g_free(priv->edit.forecolor);
+	priv->edit.forecolor = NULL;
+
+	g_free(priv->edit.backcolor);
+	priv->edit.backcolor = NULL;
+
+	g_free(priv->edit.background);
+	priv->edit.background = NULL;
+}
+
 /******************************************************************************
  * GObject Stuff
  *****************************************************************************/
@@ -528,6 +555,100 @@ void
 }
 
 void
+gtk_webview_setup_entry(GtkWebView *webview, PurpleConnectionFlags flags)
+{
+	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+	GtkWebViewButtons buttons;
+
+	if (flags & PURPLE_CONNECTION_HTML) {
+		char color[8];
+		GdkColor fg_color, bg_color;
+
+		buttons = GTK_WEBVIEW_ALL;
+
+		if (flags & PURPLE_CONNECTION_NO_BGCOLOR)
+			buttons &= ~GTK_WEBVIEW_BACKCOLOR;
+		if (flags & PURPLE_CONNECTION_NO_FONTSIZE)
+		{
+			buttons &= ~GTK_WEBVIEW_GROW;
+			buttons &= ~GTK_WEBVIEW_SHRINK;
+		}
+		if (flags & PURPLE_CONNECTION_NO_URLDESC)
+			buttons &= ~GTK_WEBVIEW_LINKDESC;
+
+		gtk_webview_set_format_functions(webview, GTK_WEBVIEW_ALL);
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != priv->edit.bold)
+			gtk_webview_toggle_bold(webview);
+
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != priv->edit.italic)
+			gtk_webview_toggle_italic(webview);
+
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != priv->edit.underline)
+			gtk_webview_toggle_underline(webview);
+
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike") != priv->edit.strike)
+			gtk_webview_toggle_strike(webview);
+
+		gtk_webview_toggle_fontface(webview,
+			purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/font_face"));
+
+		if (!(flags & PURPLE_CONNECTION_NO_FONTSIZE))
+		{
+			int size = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size");
+
+			/* 3 is the default. */
+			if (size != 3)
+				gtk_webview_font_set_size(webview, size);
+		}
+
+		if (strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"), "") != 0)
+		{
+			gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"),
+							&fg_color);
+			g_snprintf(color, sizeof(color), "#%02x%02x%02x",
+									fg_color.red   / 256,
+									fg_color.green / 256,
+									fg_color.blue  / 256);
+		} else
+			strcpy(color, "");
+
+		gtk_webview_toggle_forecolor(webview, color);
+
+		if(!(flags & PURPLE_CONNECTION_NO_BGCOLOR) &&
+		   strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"), "") != 0)
+		{
+			gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"),
+							&bg_color);
+			g_snprintf(color, sizeof(color), "#%02x%02x%02x",
+									bg_color.red   / 256,
+									bg_color.green / 256,
+									bg_color.blue  / 256);
+		} else
+			strcpy(color, "");
+
+		gtk_webview_toggle_background(webview, color);
+
+		if (flags & PURPLE_CONNECTION_FORMATTING_WBFO)
+			gtk_webview_set_whole_buffer_formatting_only(webview, TRUE);
+		else
+			gtk_webview_set_whole_buffer_formatting_only(webview, FALSE);
+	} else {
+		buttons = GTK_WEBVIEW_SMILEY | GTK_WEBVIEW_IMAGE;
+		webview_clear_formatting(webview);
+	}
+
+	if (flags & PURPLE_CONNECTION_NO_IMAGES)
+		buttons &= ~GTK_WEBVIEW_IMAGE;
+
+	if (flags & PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY)
+		buttons |= GTK_WEBVIEW_CUSTOM_SMILEY;
+	else
+		buttons &= ~GTK_WEBVIEW_CUSTOM_SMILEY;
+
+	gtk_webview_set_format_functions(webview, buttons);
+}
+
+void
 gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview, gboolean wbfo)
 {
 	GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
============================================================
--- pidgin/gtkwebview.h	f2b42ee6878efc969ec1702091b1ac1b1c23fe07
+++ pidgin/gtkwebview.h	bb1c525358d553e120275152f12834fe85e525d1
@@ -179,6 +179,14 @@ void gtk_webview_set_editable(GtkWebView
 void gtk_webview_set_editable(GtkWebView *webview, gboolean editable);
 
 /**
+ * Setup formatting for a GtkWebView depending on the flags specified.
+ *
+ * @param webview The GtkWebView.
+ * @param flags   The connection flags describing the allowed formatting.
+ */
+void gtk_webview_setup_entry(GtkWebView *webview, PurpleConnectionFlags flags);
+
+/**
  * Enables or disables whole buffer formatting only (wbfo) in a GtkWebView.
  * In this mode formatting options to the buffer take effect for the entire
  * buffer instead of specific text.


More information about the Commits mailing list