/dev/qulogic/ckeditor: 5ee4f16452c8: Setup a webkit protocol han...

Elliott Sales de Andrade qulogic at pidgin.im
Fri Aug 9 03:13:30 EDT 2013


Changeset: 5ee4f16452c84299debd4e6352c28ef008745ef1
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2013-08-08 04:03 -0400
Branch:	 default
URL: https://hg.pidgin.im/dev/qulogic/ckeditor/rev/5ee4f16452c8

Description:

Setup a webkit protocol handler for themed icons.

diffstat:

 pidgin/gtkwebview.c |  46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diffs (63 lines):

diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -36,6 +36,8 @@
 
 #include "gtk3compat.h"
 
+#define PIDGIN_ICON_PROTOCOL "icon:"
+
 #define MAX_FONT_SIZE 7
 #define MAX_SCROLL_TIME 0.4 /* seconds */
 #define SCROLL_DELAY 33 /* milliseconds */
@@ -710,6 +712,50 @@ webview_resource_loading(WebKitWebView *
 			g_free(b64);
 			g_free(tmp);
 		}
+	} else if (purple_str_has_prefix(uri, PIDGIN_ICON_PROTOCOL)) {
+		char **strs;
+		char *icon;
+		char *size_str;
+		int size;
+		GtkIconTheme *theme;
+		GtkIconInfo *info;
+		const char *filename;
+
+		uri += sizeof(PIDGIN_ICON_PROTOCOL) - 1;
+
+		strs = g_strsplit(uri, ":", 2);
+		if (!strs[0] || !strs[1]) {
+			g_strfreev(strs);
+			return;
+		}
+		icon = strs[0];
+		size_str = strs[1];
+		g_free(strs);
+
+		if (sscanf(size_str, "%dpx", &size) != 1) {
+			/* TODO: What about HiDPI situations? */
+			size = 16;
+		}
+		g_free(size_str);
+
+		theme = gtk_icon_theme_get_default();
+		info = gtk_icon_theme_lookup_icon(theme, icon, size, 0);
+		g_free(icon);
+		if (!info)
+			return;
+
+		filename = gtk_icon_info_get_filename(info);
+		if (filename) {
+			char *tmp = g_strdup_printf("file://%s", filename);
+			webkit_network_request_set_uri(request, tmp);
+			g_free(tmp);
+		}
+
+#if GTK_CHECK_VERSION(3,8,0)
+		g_object_unref(info);
+#else
+		gtk_icon_info_free(info);
+#endif
 	}
 }
 



More information about the Commits mailing list