[gnome-software] Always show the featured application with the correct background



commit 6051ab25b6026763a553202ae97174528fe4cfc0
Author: Richard Hughes <richard hughsie com>
Date:   Mon Nov 4 10:37:05 2013 +0000

    Always show the featured application with the correct background
    
    We were not copying the metdata when de-duplicating objects, so there was a race
    to see which startup plugin finished first. If AppStream finished first, the
    object with the metdata got deleted and the AppStream object was used.

 src/gs-app.c           |   60 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-app.h           |    3 ++
 src/gs-plugin-loader.c |   35 +--------------------------
 3 files changed, 65 insertions(+), 33 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 769c862..71e6f3c 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -285,6 +285,66 @@ gs_app_to_string (GsApp *app)
 }
 
 /**
+ * gs_app_subsume:
+ *
+ * Imports all the useful data from @other into @app.
+ **/
+void
+gs_app_subsume (GsApp *app, GsApp *other)
+{
+       GList *keys;
+       GList *l;
+       GsAppPrivate *priv = app->priv;
+       GsAppPrivate *priv2 = other->priv;
+       const gchar *tmp;
+
+       /* wait for all the properties to be set */
+       g_object_freeze_notify (G_OBJECT (app));
+
+       /* an [updatable] installable package is more information than
+        * just the fact that something is installed */
+       if (priv2->state == GS_APP_STATE_UPDATABLE &&
+           priv->state == GS_APP_STATE_INSTALLED) {
+               /* we have to do the little dance to appease the
+                * angry gnome controlling the state-machine */
+               gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
+               gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
+       }
+
+       /* save any properties we already know */
+       if (priv2->sources->len > 0)
+               gs_app_set_sources (app, priv2->sources);
+       if (priv2->project_group != NULL)
+               gs_app_set_project_group (app, priv2->project_group);
+       if (priv2->name != NULL)
+               gs_app_set_name (app, priv2->name);
+       if (priv2->summary != NULL)
+               gs_app_set_summary (app, priv2->summary);
+       if (priv2->description != NULL)
+               gs_app_set_description (app, priv2->description);
+       if (priv2->update_details != NULL)
+               gs_app_set_update_details (app, priv2->update_details);
+       if (priv2->update_version != NULL)
+               gs_app_set_update_version (app, priv2->update_version);
+       if (priv2->pixbuf != NULL)
+               gs_app_set_pixbuf (app, priv2->pixbuf);
+
+       /* also metadata */
+       keys = g_hash_table_get_keys (priv2->metadata);
+       for (l = keys; l != NULL; l = l->next) {
+               tmp = g_hash_table_lookup (priv->metadata, l->data);
+               if (tmp != NULL)
+                       continue;
+               tmp = g_hash_table_lookup (priv2->metadata, l->data);
+               gs_app_set_metadata (other, l->data, tmp);
+       }
+       g_list_free (keys);
+
+       /* now emit all the changed signals */
+       g_object_thaw_notify (G_OBJECT (app));
+}
+
+/**
  * gs_app_get_id:
  **/
 const gchar *
diff --git a/src/gs-app.h b/src/gs-app.h
index 9446e8c..d779ed9 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -104,6 +104,9 @@ const gchar *gs_app_kind_to_string          (GsAppKind       kind);
 const gchar    *gs_app_id_kind_to_string       (GsAppIdKind     id_kind);
 const gchar    *gs_app_state_to_string         (GsAppState      state);
 
+void            gs_app_subsume                 (GsApp          *app,
+                                                GsApp          *other);
+
 const gchar    *gs_app_get_id                  (GsApp          *app);
 const gchar    *gs_app_get_id_full             (GsApp          *app);
 void            gs_app_set_id                  (GsApp          *app,
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 3b980d4..d96c756 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -122,39 +122,8 @@ gs_plugin_loader_dedupe (GsPluginLoader *plugin_loader, GsApp *app)
                goto out;
        }
 
-       /* wait for all the properties to be set */
-       g_object_freeze_notify (G_OBJECT (new_app));
-
-       /* an [updatable] installable package is more information than
-        * just the fact that something is installed */
-       if (gs_app_get_state (app) == GS_APP_STATE_UPDATABLE &&
-           gs_app_get_state (new_app) == GS_APP_STATE_INSTALLED) {
-               /* we have to do the little dance to appease the
-                * angry gnome controlling the state-machine */
-               gs_app_set_state (new_app, GS_APP_STATE_UNKNOWN);
-               gs_app_set_state (new_app, GS_APP_STATE_UPDATABLE);
-       }
-
-       /* save any properties we already know */
-       if (gs_app_get_sources(app)->len > 0)
-               gs_app_set_sources (new_app, gs_app_get_sources (app));
-       if (gs_app_get_project_group (app) != NULL)
-               gs_app_set_project_group (new_app, gs_app_get_project_group (app));
-       if (gs_app_get_name (app) != NULL)
-               gs_app_set_name (new_app, gs_app_get_name (app));
-       if (gs_app_get_summary (app) != NULL)
-               gs_app_set_summary (new_app, gs_app_get_summary (app));
-       if (gs_app_get_description (app) != NULL)
-               gs_app_set_description (new_app, gs_app_get_description (app));
-       if (gs_app_get_update_details (app) != NULL)
-               gs_app_set_update_details (new_app, gs_app_get_update_details (app));
-       if (gs_app_get_update_version (app) != NULL)
-               gs_app_set_update_version (new_app, gs_app_get_update_version (app));
-       if (gs_app_get_pixbuf (app) != NULL)
-               gs_app_set_pixbuf (new_app, gs_app_get_pixbuf (app));
-
-       /* now emit all the changed signals */
-       g_object_thaw_notify (G_OBJECT (new_app));
+       /* import all the useful properties */
+       gs_app_subsume (new_app, app);
 
        /* this looks a little odd to unref the method parameter,
         * but it allows us to do:


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