[gupnp-tools] common,av-cp: Fix server not browsed without icon



commit 6dcce4c57264f0258bceaaa82257527f1c85f636
Author: Jens Georg <mail jensge org>
Date:   Sat Jul 1 14:24:13 2017 +0200

    common,av-cp: Fix server not browsed without icon

 src/av-cp/playlist-treeview.c |    3 +++
 src/av-cp/renderer-combo.c    |    3 +++
 src/common/icons.c            |   34 +++++++++++++++++++++++-----------
 3 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/src/av-cp/playlist-treeview.c b/src/av-cp/playlist-treeview.c
index 22d8549..1f7b3f1 100644
--- a/src/av-cp/playlist-treeview.c
+++ b/src/av-cp/playlist-treeview.c
@@ -692,6 +692,9 @@ update_device_icon (GUPnPDeviceInfo *info)
         server = AV_CP_MEDIA_SERVER (info);
         g_object_get (G_OBJECT (server), "icon", &icon, NULL);
 
+        if (icon == NULL)
+                return;
+
         if (find_row (model,
                       NULL,
                       &iter,
diff --git a/src/av-cp/renderer-combo.c b/src/av-cp/renderer-combo.c
index 381a701..250c564 100644
--- a/src/av-cp/renderer-combo.c
+++ b/src/av-cp/renderer-combo.c
@@ -345,6 +345,9 @@ on_device_icon_available (GUPnPDeviceInfo *info,
         GtkTreeIter   iter;
         const char   *udn;
 
+        if (icon == NULL)
+                return;
+
         model = gtk_combo_box_get_model (GTK_COMBO_BOX (renderer_combo));
         g_assert (model != NULL);
 
diff --git a/src/common/icons.c b/src/common/icons.c
index b3c9c69..a6cf842 100644
--- a/src/common/icons.c
+++ b/src/common/icons.c
@@ -99,11 +99,11 @@ got_icon_url (SoupSession    *session,
               SoupMessage    *msg,
               GetIconURLData *data)
 {
+        GdkPixbuf *pixbuf = NULL;
+
         if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-                GdkPixbuf *pixbuf;
-                GError    *error;
+                GError *error = NULL;
 
-                error = NULL;
                 pixbuf = get_icon_from_message (msg, data, &error);
 
                 if (error) {
@@ -111,18 +111,30 @@ got_icon_url (SoupSession    *session,
                                    gupnp_device_info_get_udn (data->info),
                                    error->message);
                         g_error_free (error);
-                } else if (pixbuf) {
-                        data->callback (data->info, pixbuf);
-                } else {
+                } else if (!pixbuf) {
                         g_warning ("Failed to create icon for '%s'",
                                    gupnp_device_info_get_udn (data->info));
                 }
         }
 
+        data->callback (data->info, pixbuf);
+
         pending_gets = g_list_remove (pending_gets, data);
         get_icon_url_data_free (data);
 }
 
+static gboolean
+on_icon_schedule_error (gpointer user_data)
+{
+        GetIconURLData *data = (GetIconURLData *) user_data;
+
+        data->callback (data->info, NULL);
+        g_object_unref (data->info);
+        g_slice_free (GetIconURLData, data);
+
+        return FALSE;
+}
+
 void
 schedule_icon_update (GUPnPDeviceInfo            *info,
                       DeviceIconAvailableCallback callback)
@@ -131,6 +143,9 @@ schedule_icon_update (GUPnPDeviceInfo            *info,
         char           *icon_url;
 
         data = g_slice_new0 (GetIconURLData);
+        data->info = g_object_ref (info);
+        data->callback = callback;
+
         icon_url = gupnp_device_info_get_icon_url
                         (info,
                          NULL,
@@ -144,8 +159,8 @@ schedule_icon_update (GUPnPDeviceInfo            *info,
                          &data->height);
         if (icon_url == NULL) {
                 g_free (data->mime_type);
-                g_slice_free (GetIconURLData, data);
 
+                g_idle_add (on_icon_schedule_error, data);
                 return;
         }
 
@@ -158,14 +173,11 @@ schedule_icon_update (GUPnPDeviceInfo            *info,
 
                 g_free (icon_url);
                 g_free (data->mime_type);
-                g_slice_free (GetIconURLData, data);
+                g_idle_add (on_icon_schedule_error, data);
 
                 return;
         }
 
-        data->info = g_object_ref (info);
-        data->callback = callback;
-
         pending_gets = g_list_prepend (pending_gets, data);
         soup_session_queue_message (download_session,
                                     data->message,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]