# HG changeset patch
# Node ID 074660b492c0
# Parent  356a9e4b4a87
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -730,6 +730,7 @@ version 3.0.0 (??/??/????):
 		* purple_status_type_add_attrs_vargs
 		* purple_status_type_get_primary_attr
 		* purple_status_type_set_primary_attr
+		* purple_strcasestr
 		* purple_strlcat
 		* purple_strlcpy
 		* purple_str_binary_to_ascii
@@ -747,6 +748,9 @@ version 3.0.0 (??/??/????):
 		* purple_unescape_filename
 		* PurpleUPnPMappingAddRemove
 		* purple_upnp_cancel_port_mapping
+		* purple_uri_escape_for_open
+		* purple_uri_list_extract_filenames
+		* purple_uri_list_extract_uris
 		* purple_url_decode
 		* purple_user_dir
 		* purple_utf8_salvage.  Use g_utf8_make_valid instead.
@@ -924,7 +928,9 @@ version 3.0.0 (??/??/????):
 		* pidgin_blist_visibility_manager_remove
 		* PidginBlistLayout
 		* pidgin_buddy_icon_chooser_new
+		* pidgin_buddy_icon_get_scale_size
 		* PidginBuddyList.connection_errors
+		* PidginButtonOrientation
 		* PidginButtonStyle
 		* PidginCellRendererExpander
 		* PIDGIN_TYPE_CELL_RENDERER_EXPANDER
@@ -971,6 +977,7 @@ version 3.0.0 (??/??/????):
 		* pidgin_conv_update_buttons_by_protocol
 		* pidgin_conversations_fill_menu
 		* pidgin_conversations_get_unseen_all
+		* pidgin_convert_buddy_icon
 		* pidgin_create_dialog, use pidgin_dialog_new instead.
 		* pidgin_create_icon_from_protocol
 		* pidgin_create_protocol_icon
@@ -1062,6 +1069,7 @@ version 3.0.0 (??/??/????):
 		* pidgin_scroll_book_new
 		* pidgin_scroll_book_get_notebook
 		* pidgin_separator
+		* pidgin_set_accessible_relations
 		* pidgin_set_cursor
 		* pidgin_set_custom_buddy_icon
 		* pidgin_set_sensitive_if_input
diff --git a/libpurple/tests/test_util.c b/libpurple/tests/test_util.c
--- a/libpurple/tests/test_util.c
+++ b/libpurple/tests/test_util.c
@@ -198,30 +198,6 @@ test_util_strdup_withhtml(void) {
 }
 
 /******************************************************************************
- * URI Escaping
- *****************************************************************************/
-static void
-test_uri_escape_for_open(void) {
-	/* make sure shell stuff is escaped... */
-	gchar *result = purple_uri_escape_for_open("https://$(xterm)");
-	g_assert_cmpstr("https://%24%28xterm%29", ==, result);
-	g_free(result);
-
-	result = purple_uri_escape_for_open("https://`xterm`");
-	g_assert_cmpstr("https://%60xterm%60", ==, result);
-	g_free(result);
-
-	result = purple_uri_escape_for_open("https://$((25 + 13))");
-	g_assert_cmpstr("https://%24%28%2825%20+%2013%29%29", ==, result);
-	g_free(result);
-
-	/* ...but keep brackets so that ipv6 links can be opened. */
-	result = purple_uri_escape_for_open("https://[123:4567:89a::::]");
-	g_assert_cmpstr("https://[123:4567:89a::::]", ==, result);
-	g_free(result);
-}
-
-/******************************************************************************
  * MANE
  *****************************************************************************/
 gint
@@ -245,8 +221,5 @@ main(gint argc, gchar **argv) {
 	g_test_add_func("/util/test_strdup_withhtml",
 	                test_util_strdup_withhtml);
 
-	g_test_add_func("/util/test_uri_escape_for_open",
-	                test_uri_escape_for_open);
-
 	return g_test_run();
 }
diff --git a/libpurple/util.h b/libpurple/util.h
--- a/libpurple/util.h
+++ b/libpurple/util.h
@@ -377,18 +377,6 @@ char *purple_utf8_ncr_encode(const char 
 char *purple_utf8_ncr_decode(const char *in);
 
 /**
- * purple_strcasestr:
- * @haystack: The string to search in.
- * @needle:   The substring to find.
- *
- * This is like strstr, except that it ignores ASCII case in
- * searching for the substring.
- *
- * Returns: the location of the substring if found, or NULL if not
- */
-const char *purple_strcasestr(const char *haystack, const char *needle);
-
-/**
  * purple_str_seconds_to_string:
  * @sec: The seconds.
  *
@@ -437,47 +425,6 @@ const char *purple_url_encode(const char
  */
 gboolean purple_email_is_valid(const char *address);
 
-/**
- * purple_uri_list_extract_uris:
- * @uri_list: An uri-list in the standard format.
- *
- * This function extracts a list of URIs from the a "text/uri-list"
- * string.  It was "borrowed" from gnome_uri_list_extract_uris
- *
- * Returns: (element-type utf8) (transfer full): A list of strings that have
- *          been split from uri-list.
- */
-GList *purple_uri_list_extract_uris(const gchar *uri_list);
-
-/**
- * purple_uri_list_extract_filenames:
- * @uri_list: A uri-list in the standard format.
- *
- * This function extracts a list of filenames from a
- * "text/uri-list" string.  It was "borrowed" from
- * gnome_uri_list_extract_filenames
- *
- * Returns: (element-type utf8) (transfer full): A list of strings that contain
- *          the filenames in the uri-list. Note that unlike the
- *          purple_uri_list_extract_uris() function, this will discard any
- *          non-file uri from the result value.
- */
-GList *purple_uri_list_extract_filenames(const gchar *uri_list);
-
-/**
- * purple_uri_escape_for_open:
- * @unescaped: The unescaped URI.
- *
- * This function escapes any characters that might be interpreted by the shell
- * when executing a program to open a URI on some systems.
- *
- * Returns: A newly allocated string with any shell metacharacters replaced
- *          with their escaped equivalents.
- *
- * Since: 2.13.0
- */
-char *purple_uri_escape_for_open(const char *unescaped);
-
 /**************************************************************************
  * UTF8 String Functions
  **************************************************************************/
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -341,41 +341,6 @@ purple_strreplace(const char *string, co
 	return ret;
 }
 
-/* TODO: Expose this when we can add API */
-static const char *
-purple_strcasestr_len(const char *haystack, gssize hlen, const char *needle, gssize nlen)
-{
-	const char *tmp, *ret;
-
-	g_return_val_if_fail(haystack != NULL, NULL);
-	g_return_val_if_fail(needle != NULL, NULL);
-
-	if (hlen == -1)
-		hlen = strlen(haystack);
-	if (nlen == -1)
-		nlen = strlen(needle);
-	tmp = haystack,
-	ret = NULL;
-
-	g_return_val_if_fail(hlen > 0, NULL);
-	g_return_val_if_fail(nlen > 0, NULL);
-
-	while (*tmp && !ret && (hlen - (tmp - haystack)) >= nlen) {
-		if (!g_ascii_strncasecmp(needle, tmp, nlen))
-			ret = tmp;
-		else
-			tmp++;
-	}
-
-	return ret;
-}
-
-const char *
-purple_strcasestr(const char *haystack, const char *needle)
-{
-	return purple_strcasestr_len(haystack, -1, needle, -1);
-}
-
 char *
 purple_str_seconds_to_string(guint secs)
 {
@@ -616,93 +581,6 @@ purple_email_is_valid(const char *addres
 	return ((c - domain) > 3 ? TRUE : FALSE);
 }
 
-/* Stolen from gnome_uri_list_extract_uris */
-GList *
-purple_uri_list_extract_uris(const gchar *uri_list)
-{
-	const gchar *p, *q;
-	gchar *retval;
-	GList *result = NULL;
-
-	g_return_val_if_fail (uri_list != NULL, NULL);
-
-	p = uri_list;
-
-	/* We don't actually try to validate the URI according to RFC
-	* 2396, or even check for allowed characters - we just ignore
-	* comments and trim whitespace off the ends.  We also
-	* allow LF delimination as well as the specified CRLF.
-	*/
-	while (p) {
-		if (*p != '#') {
-			while (isspace(*p))
-				p++;
-
-			q = p;
-			while (*q && (*q != '\n') && (*q != '\r'))
-				q++;
-
-			if (q > p) {
-				q--;
-				while (q > p && isspace(*q))
-					q--;
-
-				retval = (gchar*)g_malloc (q - p + 2);
-				strncpy (retval, p, q - p + 1);
-				retval[q - p + 1] = '\0';
-
-				result = g_list_prepend (result, retval);
-			}
-		}
-		p = strchr (p, '\n');
-		if (p)
-			p++;
-	}
-
-	return g_list_reverse (result);
-}
-
-
-/* Stolen from gnome_uri_list_extract_filenames */
-GList *
-purple_uri_list_extract_filenames(const gchar *uri_list)
-{
-	GList *tmp_list, *node, *result;
-
-	g_return_val_if_fail (uri_list != NULL, NULL);
-
-	result = purple_uri_list_extract_uris(uri_list);
-
-	tmp_list = result;
-	while (tmp_list) {
-		gchar *s = (gchar*)tmp_list->data;
-
-		node = tmp_list;
-		tmp_list = tmp_list->next;
-
-		if (!strncmp (s, "file:", 5)) {
-			node->data = g_filename_from_uri (s, NULL, NULL);
-			/* not sure if this fallback is useful at all */
-			if (!node->data) node->data = g_strdup (s+5);
-		} else {
-			result = g_list_delete_link(result, node);
-		}
-		g_free (s);
-	}
-	return result;
-}
-
-char *
-purple_uri_escape_for_open(const char *unescaped)
-{
-	/* Replace some special characters like $ with their percent-encoded value.
-	 * This shouldn't be necessary because we shell-escape the entire arg before
-	 * exec'ing the browser, however, we had a report that a URL containing
-	 * $(xterm) was causing xterm to start on his system. This is obviously a
-	 * bug on his system, but it's pretty easy for us to protect against it. */
-	return g_uri_escape_string(unescaped, "[]:;/%#,+?=&@", FALSE);
-}
-
 /**************************************************************************
  * UTF8 String Functions
  **************************************************************************/
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -1804,8 +1804,6 @@ static GdkPixbuf *pidgin_blist_get_buddy
 			gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE);
 	}
 
-	/* I'd use the pidgin_buddy_icon_get_scale_size() thing, but it won't
-	 * tell me the original size, which I need for scaling purposes. */
 	scale_width = orig_width = gdk_pixbuf_get_width(buf);
 	scale_height = orig_height = gdk_pixbuf_get_height(buf);
 
diff --git a/pidgin/gtkutils.h b/pidgin/gtkutils.h
--- a/pidgin/gtkutils.h
+++ b/pidgin/gtkutils.h
@@ -30,20 +30,6 @@
 
 #include <purple.h>
 
-typedef enum
-{
-	PIDGIN_BUTTON_HORIZONTAL,
-	PIDGIN_BUTTON_VERTICAL
-
-} PidginButtonOrientation;
-
-typedef enum
-{
-	PIDGIN_PROTOCOL_ICON_SMALL,
-	PIDGIN_PROTOCOL_ICON_MEDIUM,
-	PIDGIN_PROTOCOL_ICON_LARGE
-} PidginProtocolIconSize;
-
 typedef struct {
 	gboolean is_buddy;
 	PurpleBuddy *buddy;
@@ -124,34 +110,6 @@ void pidgin_retrieve_user_info_in_chat(P
 void pidgin_set_accessible_label(GtkWidget *w, GtkLabel *l);
 
 /**
- * pidgin_set_accessible_relations:
- * @w: The widget that we want to label.
- * @l: A GtkLabel that we want to use as the label for the widget.
- *
- * Sets the labelled-by and label-for ATK relationships.
- */
-void pidgin_set_accessible_relations(GtkWidget *w, GtkLabel *l);
-
-/**
- * pidgin_buddy_icon_get_scale_size:
- *
- * Convenience wrapper for purple_buddy_icon_spec_get_scaled_size
- */
-void pidgin_buddy_icon_get_scale_size(GdkPixbuf *buf, PurpleBuddyIconSpec *spec, PurpleBuddyIconScaleFlags rules, int *width, int *height);
-
-/**
- * pidgin_convert_buddy_icon:
- * @protocol:   The protocol to convert the icon
- * @path:       The path of a file to convert
- * @len:        If not %NULL, the length of the returned data will be set here.
- *
- * Converts a buddy icon to the required size and format
- *
- * Returns:           The converted image data, or %NULL if an error occurred.
- */
-gpointer pidgin_convert_buddy_icon(PurpleProtocol *protocol, const char *path, size_t *len);
-
-/**
  * pidgin_tree_view_search_equal_func:
  *
  * This is a callback function to be used for Ctrl+F searching in treeviews.
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -175,12 +175,6 @@ void pidgin_retrieve_user_info_in_chat(P
 void
 pidgin_set_accessible_label(GtkWidget *w, GtkLabel *l)
 {
-	pidgin_set_accessible_relations(w, l);
-}
-
-void
-pidgin_set_accessible_relations (GtkWidget *w, GtkLabel *l)
-{
 	GtkAccessible *acc, *label;
 
 	acc = GTK_ACCESSIBLE(w);
@@ -194,23 +188,6 @@ pidgin_set_accessible_relations (GtkWidg
 	                               label, NULL, -1);
 }
 
-void pidgin_buddy_icon_get_scale_size(GdkPixbuf *buf, PurpleBuddyIconSpec *spec, PurpleBuddyIconScaleFlags rules, int *width, int *height)
-{
-	*width = gdk_pixbuf_get_width(buf);
-	*height = gdk_pixbuf_get_height(buf);
-
-	if ((spec == NULL) || !(spec->scale_rules & rules))
-		return;
-
-	purple_buddy_icon_spec_get_scaled_size(spec, width, height);
-
-	/* and now for some arbitrary sanity checks */
-	if(*width > 100)
-		*width = 100;
-	if(*height > 100)
-		*height = 100;
-}
-
 static gboolean buddyname_completion_match_func(GtkEntryCompletion *completion,
 		const gchar *key, GtkTreeIter *iter, gpointer user_data)
 {
@@ -473,207 +450,6 @@ pidgin_screenname_autocomplete_default_f
 }
 
 /*
- * str_array_match:
- *
- * Returns: %TRUE if any string from array @a exists in array @b.
- */
-static gboolean
-str_array_match(char **a, char **b)
-{
-	int i, j;
-
-	if (!a || !b)
-		return FALSE;
-	for (i = 0; a[i] != NULL; i++)
-		for (j = 0; b[j] != NULL; j++)
-			if (!g_ascii_strcasecmp(a[i], b[j]))
-				return TRUE;
-	return FALSE;
-}
-
-gpointer
-pidgin_convert_buddy_icon(PurpleProtocol *protocol, const char *path, size_t *len)
-{
-	PurpleBuddyIconSpec *spec;
-	int orig_width, orig_height, new_width, new_height;
-	GdkPixbufFormat *format;
-	char **pixbuf_formats;
-	char **protocol_formats;
-	GError *error = NULL;
-	gchar *contents;
-	gsize length;
-	GdkPixbuf *pixbuf, *original;
-	float scale_factor;
-	int i;
-	gchar *tmp;
-
-	spec = purple_protocol_get_icon_spec(protocol);
-	if(spec->format == NULL) {
-		purple_buddy_icon_spec_free(spec);
-
-		return NULL;
-	}
-
-	format = gdk_pixbuf_get_file_info(path, &orig_width, &orig_height);
-	if (format == NULL) {
-		purple_debug_warning("buddyicon", "Could not get file info of %s\n", path);
-
-		purple_buddy_icon_spec_free(spec);
-
-		return NULL;
-	}
-
-	pixbuf_formats = gdk_pixbuf_format_get_extensions(format);
-	protocol_formats = g_strsplit(spec->format, ",", 0);
-
-	if (str_array_match(pixbuf_formats, protocol_formats) && /* This is an acceptable format AND */
-		 (!(spec->scale_rules & PURPLE_ICON_SCALE_SEND) || /* The protocol doesn't scale before it sends OR */
-		  (spec->min_width <= orig_width && spec->max_width >= orig_width &&
-		   spec->min_height <= orig_height && spec->max_height >= orig_height))) /* The icon is the correct size */
-	{
-		g_strfreev(pixbuf_formats);
-
-		if (!g_file_get_contents(path, &contents, &length, &error)) {
-			purple_debug_warning("buddyicon", "Could not get file contents "
-					"of %s: %s\n", path, error->message);
-			g_strfreev(protocol_formats);
-			purple_buddy_icon_spec_free(spec);
-			return NULL;
-		}
-
-		if (spec->max_filesize == 0 || length < spec->max_filesize) {
-			/* The supplied image fits the file size, dimensions and type
-			   constraints.  Great!  Return it without making any changes. */
-			if (len)
-				*len = length;
-			g_strfreev(protocol_formats);
-			purple_buddy_icon_spec_free(spec);
-			return contents;
-		}
-
-		/* The image was too big.  Fall-through and try scaling it down. */
-		g_free(contents);
-	} else {
-		g_strfreev(pixbuf_formats);
-	}
-
-	/* The original image wasn't compatible.  Scale it or convert file type. */
-	pixbuf = gdk_pixbuf_new_from_file(path, &error);
-	if (error) {
-		purple_debug_warning("buddyicon", "Could not open icon '%s' for "
-				"conversion: %s\n", path, error->message);
-		g_error_free(error);
-		g_strfreev(protocol_formats);
-		purple_buddy_icon_spec_free(spec);
-		return NULL;
-	}
-	original = g_object_ref(pixbuf);
-
-	new_width = orig_width;
-	new_height = orig_height;
-
-	/* Make sure the image is the correct dimensions */
-	if (spec->scale_rules & PURPLE_ICON_SCALE_SEND &&
-		(orig_width < spec->min_width || orig_width > spec->max_width ||
-		 orig_height < spec->min_height || orig_height > spec->max_height))
-	{
-		purple_buddy_icon_spec_get_scaled_size(spec, &new_width, &new_height);
-
-		g_object_unref(G_OBJECT(pixbuf));
-		pixbuf = gdk_pixbuf_scale_simple(original, new_width, new_height, GDK_INTERP_HYPER);
-	}
-
-	scale_factor = 1;
-	do {
-		for (i = 0; protocol_formats[i]; i++) {
-			int quality = 100;
-			do {
-				const char *key = NULL;
-				const char *value = NULL;
-				gchar tmp_buf[4];
-
-				purple_debug_info("buddyicon", "Converting buddy icon to %s\n", protocol_formats[i]);
-
-				if (purple_strequal(protocol_formats[i], "png")) {
-					key = "compression";
-					value = "9";
-				} else if (purple_strequal(protocol_formats[i], "jpeg")) {
-					sprintf(tmp_buf, "%u", quality);
-					key = "quality";
-					value = tmp_buf;
-				}
-
-				if (!gdk_pixbuf_save_to_buffer(pixbuf, &contents, &length,
-						protocol_formats[i], &error, key, value, NULL))
-				{
-					/* The NULL checking of error is necessary due to this bug:
-					 * http://bugzilla.gnome.org/show_bug.cgi?id=405539 */
-					purple_debug_warning("buddyicon",
-							"Could not convert to %s: %s\n", protocol_formats[i],
-							(error && error->message) ? error->message : "Unknown error");
-					g_error_free(error);
-					error = NULL;
-
-					/* We couldn't convert to this image type.  Try the next
-					   image type. */
-					break;
-				}
-
-				if (spec->max_filesize == 0 || length <= spec->max_filesize) {
-					/* We were able to save the image as this image type and
-					   have it be within the size constraints.  Great!  Return
-					   the image. */
-					purple_debug_info("buddyicon", "Converted image from "
-							"%dx%d to %dx%d, format=%s, quality=%u, "
-							"filesize=%" G_GSIZE_FORMAT "\n",
-							orig_width, orig_height, new_width, new_height,
-							protocol_formats[i], quality, length);
-					if (len)
-						*len = length;
-					g_strfreev(protocol_formats);
-					g_object_unref(G_OBJECT(pixbuf));
-					g_object_unref(G_OBJECT(original));
-					purple_buddy_icon_spec_free(spec);
-					return contents;
-				}
-
-				g_free(contents);
-
-				if (!purple_strequal(protocol_formats[i], "jpeg")) {
-					/* File size was too big and we can't lower the quality,
-					   so skip to the next image type. */
-					break;
-				}
-
-				/* File size was too big, but we're dealing with jpeg so try
-				   lowering the quality. */
-				quality -= 5;
-			} while (quality >= 70);
-		}
-
-		/* We couldn't save the image in any format that was below the max
-		   file size.  Maybe we can reduce the image dimensions? */
-		scale_factor *= 0.8;
-		new_width = orig_width * scale_factor;
-		new_height = orig_height * scale_factor;
-		g_object_unref(G_OBJECT(pixbuf));
-		pixbuf = gdk_pixbuf_scale_simple(original, new_width, new_height, GDK_INTERP_HYPER);
-	} while ((new_width > 10 || new_height > 10) && new_width > spec->min_width && new_height > spec->min_height);
-	g_strfreev(protocol_formats);
-	g_object_unref(G_OBJECT(pixbuf));
-	g_object_unref(G_OBJECT(original));
-
-	tmp = g_strdup_printf(_("The file '%s' is too large for %s.  Please try a smaller image.\n"),
-			path, purple_protocol_get_name(protocol));
-	purple_notify_error(NULL, _("Icon Error"), _("Could not set icon"), tmp, NULL);
-	g_free(tmp);
-
-	purple_buddy_icon_spec_free(spec);
-
-	return NULL;
-}
-
-/*
  * "This is so dead sexy."
  * "Two thumbs up."
  * "Best movie of the year."
