[gupnp] Respect 'prefer_bigger' even if icon size is not requested
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp] Respect 'prefer_bigger' even if icon size is not requested
- Date: Fri, 18 Jul 2014 19:21:25 +0000 (UTC)
commit ce83d1cead07ad740a73f17c30522bce49592ff6
Author: Jussi Kukkonen <jku goto fi>
Date: Wed Jul 9 13:26:40 2014 +0300
Respect 'prefer_bigger' even if icon size is not requested
If gupnp_device_info_get_icon_url() was called without a specific size
request, it returned the last icon in the list.
This patch makes the function return in those circumstances either the
largest icon or the smallest icon, based on 'prefer_bigger' argument
value.
https://bugzilla.gnome.org/show_bug.cgi?id=722696
libgupnp/gupnp-device-info.c | 71 ++++++++++++++++++++++++++---------------
1 files changed, 45 insertions(+), 26 deletions(-)
---
diff --git a/libgupnp/gupnp-device-info.c b/libgupnp/gupnp-device-info.c
index b314eee..6e932d3 100644
--- a/libgupnp/gupnp-device-info.c
+++ b/libgupnp/gupnp-device-info.c
@@ -765,31 +765,36 @@ gupnp_device_info_get_icon_url (GUPnPDeviceInfo *info,
/* Filter out icons with incorrect mime type or
* incorrect depth. */
+ /* Note: Meaning of 'weight' changes when no
+ * size request is included. */
if (mime_type_ok && icon->weight >= 0) {
- if (requested_width >= 0) {
- if (prefer_bigger) {
- icon->weight +=
- icon->width -
- requested_width;
- } else {
- icon->weight +=
- requested_width -
- icon->width;
+ if (requested_width < 0 && requested_height < 0) {
+ icon->weight = icon->width * icon->height;
+ } else {
+ if (requested_width >= 0) {
+ if (prefer_bigger) {
+ icon->weight +=
+ icon->width -
+ requested_width;
+ } else {
+ icon->weight +=
+ requested_width -
+ icon->width;
+ }
}
- }
- if (requested_height >= 0) {
- if (prefer_bigger) {
- icon->weight +=
- icon->height -
- requested_height;
- } else {
- icon->weight +=
- requested_height -
- icon->height;
+ if (requested_height >= 0) {
+ if (prefer_bigger) {
+ icon->weight +=
+ icon->height -
+ requested_height;
+ } else {
+ icon->weight +=
+ requested_height -
+ icon->height;
+ }
}
}
-
icons = g_list_prepend (icons, icon);
} else
icon_free (icon);
@@ -799,18 +804,32 @@ gupnp_device_info_get_icon_url (GUPnPDeviceInfo *info,
if (icons == NULL)
return NULL;
- /* Find closest match */
+ /* If no size was requested, find the largest or smallest */
closest = NULL;
- for (l = icons; l; l = l->next) {
- icon = l->data;
+ if (requested_height < 0 && requested_width < 0) {
+ for (l = icons; l; l = l->next) {
+ icon = l->data;
- /* Look between icons with positive weight first */
- if (icon->weight >= 0) {
- if (!closest || icon->weight < closest->weight)
+ if (!closest ||
+ (prefer_bigger && icon->weight > closest->weight) ||
+ (!prefer_bigger && icon->weight < closest->weight))
closest = icon;
}
}
+ /* Find the match closest to requested size */
+ if (!closest) {
+ for (l = icons; l; l = l->next) {
+ icon = l->data;
+
+ /* Look between icons with positive weight first */
+ if (icon->weight >= 0) {
+ if (!closest || icon->weight < closest->weight)
+ closest = icon;
+ }
+ }
+ }
+
if (!closest) {
for (l = icons; l; l = l->next) {
icon = l->data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]