[gnome-software: 4/18] gs-app: Split out functionality to remove all icons




commit 2ee47d444c8aa546e209dfbd38cd7fbebd3a3dd2
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Mar 1 23:58:49 2021 +0000

    gs-app: Split out functionality to remove all icons
    
    If it’s controlled by passing `NULL` as the new icon to
    `gs_app_add_icon()`, then it could easily be triggered if a plugin fails
    to load the icon it subsequently passes in. That seems like quite a big
    consequence for a failure (even if it is a programmer error due to not
    checking for errors properly).
    
    Split out the functionality to remove all icons, so it’s explicitly a
    separate function.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1147

 lib/gs-app.c                              | 28 ++++++++++++++++++++++------
 lib/gs-app.h                              |  1 +
 plugins/packagekit/gs-plugin-packagekit.c |  2 +-
 plugins/rpm-ostree/gs-plugin-rpm-ostree.c |  2 +-
 4 files changed, 25 insertions(+), 8 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 1aec14ff5..c7350964e 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -1939,7 +1939,7 @@ icon_sort_width_cb (gconstpointer a,
 /**
  * gs_app_add_icon:
  * @app: a #GsApp
- * @icon: a #AsIcon, or %NULL to remove all icons
+ * @icon: a #AsIcon
  *
  * Adds an icon to use for the application.
  * If the first icon added cannot be loaded then the next one is tried.
@@ -1952,13 +1952,9 @@ gs_app_add_icon (GsApp *app, AsIcon *icon)
        GsAppPrivate *priv = gs_app_get_instance_private (app);
        g_autoptr(GMutexLocker) locker = NULL;
        g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (AS_IS_ICON (icon));
        locker = g_mutex_locker_new (&priv->mutex);
 
-       if (icon == NULL) {
-               g_ptr_array_set_size (priv->icons, 0);
-               return;
-       }
-
        if (priv->icons == NULL)
                priv->icons = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
 
@@ -1968,6 +1964,26 @@ gs_app_add_icon (GsApp *app, AsIcon *icon)
        g_ptr_array_sort (priv->icons, icon_sort_width_cb);
 }
 
+/**
+ * gs_app_remove_all_icons:
+ * @app: a #GsApp
+ *
+ * Remove all icons from @app.
+ *
+ * Since: 40
+ */
+void
+gs_app_remove_all_icons (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_autoptr(GMutexLocker) locker = NULL;
+       g_return_if_fail (GS_IS_APP (app));
+       locker = g_mutex_locker_new (&priv->mutex);
+
+       if (priv->icons != NULL)
+               g_ptr_array_set_size (priv->icons, 0);
+}
+
 /**
  * gs_app_get_use_drop_shadow:
  * @app: a #GsApp
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 582140ea2..0ea253d5b 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -361,6 +361,7 @@ void                 gs_app_add_pixbuf              (GsApp          *app,
 GPtrArray      *gs_app_get_icons               (GsApp          *app);
 void            gs_app_add_icon                (GsApp          *app,
                                                 AsIcon         *icon);
+void            gs_app_remove_all_icons        (GsApp          *app);
 gboolean        gs_app_get_use_drop_shadow     (GsApp          *app);
 GFile          *gs_app_get_local_file          (GsApp          *app);
 void            gs_app_set_local_file          (GsApp          *app,
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 0c7309c88..64781cb43 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -444,7 +444,7 @@ gs_plugin_app_install (GsPlugin *plugin,
 
                /* get the new icon from the package */
                gs_app_set_local_file (app, NULL);
-               gs_app_add_icon (app, NULL);
+               gs_app_remove_all_icons (app);
                break;
        default:
                g_set_error (error,
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index a3117aeae..3df016150 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -1208,7 +1208,7 @@ gs_plugin_app_install (GsPlugin *plugin,
 
        /* get the new icon from the package */
        gs_app_set_local_file (app, NULL);
-       gs_app_add_icon (app, NULL);
+       gs_app_remove_all_icons (app);
 
        /* no longer valid */
        gs_app_clear_source_ids (app);


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