diff options
author | Jussi Kukkonen <jku@goto.fi> | 2014-07-09 13:26:40 +0300 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2014-07-18 21:20:04 +0200 |
commit | ce83d1cead07ad740a73f17c30522bce49592ff6 (patch) | |
tree | dfa6fa2038f58a7acb0a481de96228f7ead18f03 | |
parent | b6e316975e07c99aa56645584707df36b0250425 (diff) | |
download | gupnp-ce83d1cead07ad740a73f17c30522bce49592ff6.tar.gz |
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
-rw-r--r-- | 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; |