[gnome-software] Never set the GsApp ID to the application ID



commit fc51640de9835a9dae9c20ad312be544c4f717bc
Author: Richard Hughes <richard hughsie com>
Date:   Sun Sep 1 16:23:04 2013 +0100

    Never set the GsApp ID to the application ID
    
    We want plugins to be able to set the ID from other metadata items if required.

 src/gs-app.c                                   |    2 -
 src/gs-plugin-loader.c                         |   37 ++++++++++++++++++++++--
 src/plugins/gs-plugin-datadir-filename.c       |    2 +
 src/plugins/gs-plugin-desktopdb.c              |   12 ++++----
 src/plugins/gs-plugin-hardcoded-descriptions.c |    9 ++++--
 src/plugins/gs-plugin-hardcoded-ratings.c      |    7 +++-
 src/plugins/gs-plugin-packagekit.c             |    4 +-
 7 files changed, 55 insertions(+), 18 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 9e6c476..259067b 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -101,8 +101,6 @@ void
 gs_app_set_id (GsApp *app, const gchar *id)
 {
        g_return_if_fail (GS_IS_APP (app));
-       g_return_if_fail (id != NULL);
-
        g_free (app->priv->id);
        app->priv->id = g_strdup (id);
 }
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index db4029e..ec6907d 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -71,6 +71,12 @@ gs_plugin_loader_dedupe (GsPluginLoader *plugin_loader, GsApp *app)
        GsApp *new_app;
        GsPluginLoaderPrivate *priv = plugin_loader->priv;
 
+       /* not yet set */
+       if (gs_app_get_id (app) == NULL) {
+               new_app = app;
+               goto out;
+       }
+
        /* already exists */
        new_app = g_hash_table_lookup (priv->app_cache, gs_app_get_id (app));
        if (new_app != NULL) {
@@ -229,6 +235,28 @@ out:
 }
 
 /**
+ * gs_plugin_loader_get_app_str:
+ **/
+static const gchar *
+gs_plugin_loader_get_app_str (GsApp *app)
+{
+       const gchar *id;
+
+       /* first try the actual id */
+       id = gs_app_get_id (app);
+       if (id != NULL)
+               return id;
+
+       /* first try the actual id */
+       id = gs_app_get_metadata_item (app, "package-id");
+       if (id != NULL)
+               return id;
+
+       /* urmmm */
+       return "<invalid>";
+}
+
+/**
  * gs_plugin_loader_app_is_valid:
  **/
 static gboolean
@@ -236,16 +264,19 @@ gs_plugin_loader_app_is_valid (GsApp *app)
 {
        /* don't show unconverted packages in the application view */
        if (gs_app_get_kind (app) == GS_APP_KIND_PACKAGE) {
-               g_debug ("app invalid as only a package %s", gs_app_get_id (app));
+               g_debug ("app invalid as only a package %s",
+                        gs_plugin_loader_get_app_str (app));
                return FALSE;
        }
        /* don't show apps that do not have a name */
        if (gs_app_get_name (app) == NULL) {
-               g_debug ("app invalid as no name %s", gs_app_get_id (app));
+               g_debug ("app invalid as no name %s",
+                        gs_plugin_loader_get_app_str (app));
                return FALSE;
        }
        if (gs_app_get_summary (app) == NULL) {
-               g_debug ("app invalid as no summary %s", gs_app_get_id (app));
+               g_debug ("app invalid as no summary %s",
+                        gs_plugin_loader_get_app_str (app));
                return FALSE;
        }
        return TRUE;
diff --git a/src/plugins/gs-plugin-datadir-filename.c b/src/plugins/gs-plugin-datadir-filename.c
index b2c83ba..ab82d30 100644
--- a/src/plugins/gs-plugin-datadir-filename.c
+++ b/src/plugins/gs-plugin-datadir-filename.c
@@ -82,6 +82,8 @@ gs_plugin_datadir_filename_find (GsPlugin *plugin,
 
        /* try and get from cache */
        id = gs_app_get_id (app);
+       if (id == NULL)
+               goto out;
        ret = g_hash_table_lookup_extended (plugin->priv->cache,
                                            id,
                                            NULL,
diff --git a/src/plugins/gs-plugin-desktopdb.c b/src/plugins/gs-plugin-desktopdb.c
index b065e2f..dd25a3e 100644
--- a/src/plugins/gs-plugin-desktopdb.c
+++ b/src/plugins/gs-plugin-desktopdb.c
@@ -131,10 +131,10 @@ gs_plugin_refine (GsPlugin *plugin,
                  GCancellable *cancellable,
                  GError **error)
 {
-       GsApp *app;
-       GList *l;
-       const gchar *tmp;
+       const gchar *pkgname;
        gboolean ret = TRUE;
+       GList *l;
+       GsApp *app;
 
        /* not loaded yet */
        if (!plugin->priv->loaded) {
@@ -150,10 +150,10 @@ gs_plugin_refine (GsPlugin *plugin,
                        continue;
                if (gs_app_get_metadata_item (app, "datadir-desktop-filename") != NULL)
                        continue;
-               tmp = gs_app_get_metadata_item (app, "package-name");
-               if (tmp == NULL)
+               pkgname = gs_app_get_metadata_item (app, "package-name");
+               if (pkgname == NULL)
                        continue;
-               gs_plugin_desktopdb_set_metadata (plugin, app, tmp);
+               gs_plugin_desktopdb_set_metadata (plugin, app, pkgname);
        }
 out:
        return ret;
diff --git a/src/plugins/gs-plugin-hardcoded-descriptions.c b/src/plugins/gs-plugin-hardcoded-descriptions.c
index f062ee3..988786d 100644
--- a/src/plugins/gs-plugin-hardcoded-descriptions.c
+++ b/src/plugins/gs-plugin-hardcoded-descriptions.c
@@ -124,9 +124,10 @@ gs_plugin_refine (GsPlugin *plugin,
                  GCancellable *cancellable,
                  GError **error)
 {
+       const gchar *id;
+       const gchar *value;
        gboolean ret = TRUE;
        GList *l;
-       const gchar *value;
        GsApp *app;
 
        /* already loaded */
@@ -141,8 +142,10 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_description (app) != NULL)
                        continue;
-               value = g_hash_table_lookup (plugin->priv->cache,
-                                            gs_app_get_id (app));
+               id = gs_app_get_id (app);
+               if (id == NULL)
+                       continue;
+               value = g_hash_table_lookup (plugin->priv->cache, id);
                if (value != NULL)
                        gs_app_set_description (app, value);
        }
diff --git a/src/plugins/gs-plugin-hardcoded-ratings.c b/src/plugins/gs-plugin-hardcoded-ratings.c
index 92e1759..0a1ff31 100644
--- a/src/plugins/gs-plugin-hardcoded-ratings.c
+++ b/src/plugins/gs-plugin-hardcoded-ratings.c
@@ -721,6 +721,7 @@ gs_plugin_refine (GsPlugin *plugin,
                  GCancellable *cancellable,
                  GError **error)
 {
+       const gchar *id;
        gboolean ret = TRUE;
        GList *l;
        gpointer value;
@@ -736,8 +737,10 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_rating (app) != -1)
                        continue;
-               value = g_hash_table_lookup (plugin->priv->cache,
-                                            gs_app_get_id (app));
+               id = gs_app_get_id (app);
+               if (id == NULL)
+                       continue;
+               value = g_hash_table_lookup (plugin->priv->cache, id);
                if (value != NULL) {
                        gs_app_set_rating (app, GPOINTER_TO_INT (value));
                } else {
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 34a2716..d5a5115 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -161,7 +161,7 @@ gs_plugin_packagekit_add_installed_results (GsPlugin *plugin,
        array = pk_results_get_package_array (results);
        for (i = 0; i < array->len; i++) {
                package = g_ptr_array_index (array, i);
-               app = gs_app_new (pk_package_get_id (package));
+               app = gs_app_new (NULL);
                gs_app_set_metadata (app,
                                     "package-id",
                                     pk_package_get_id (package));
@@ -346,7 +346,7 @@ gs_plugin_packagekit_add_updates_results (GsPlugin *plugin,
                              "update-text", &update_text,
                              NULL);
                split = pk_package_id_split (package_id);
-               app = gs_app_new (package_id);
+               app = gs_app_new (NULL);
                gs_app_set_metadata (app, "package-id", package_id);
                gs_app_set_metadata (app, "package-name", split[PK_PACKAGE_ID_NAME]);
                gs_app_set_metadata (app, "update-name", split[PK_PACKAGE_ID_NAME]);


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