[gnome-software] Add gs_app_get_update_runtime()



commit 90b66ca1b375feef380d68dd3e46857602c8ce91
Author: Richard Hughes <richard hughsie com>
Date:   Mon Jan 9 13:34:12 2017 +0000

    Add gs_app_get_update_runtime()
    
    This splits up gs_app_get_runtime() to allow for the fact that the application
    update might actually depend on a different (or different version) of runtime.

 src/gs-app.c               |   49 +++++++++++++++++++++++++++++++++++++++++--
 src/gs-app.h               |    3 ++
 src/plugins/gs-appstream.c |    2 +-
 src/plugins/gs-flatpak.c   |    2 +-
 4 files changed, 51 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 688c37b..db3bf37 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -91,6 +91,7 @@ struct _GsApp
        gchar                   *update_version_ui;
        gchar                   *update_details;
        AsUrgencyKind            update_urgency;
+       GsApp                   *update_runtime;
        gchar                   *management_plugin;
        guint                    match_value;
        guint                    priority;
@@ -497,6 +498,10 @@ gs_app_to_string (GsApp *app)
                g_autofree gchar *runtime = gs_app_to_string (app->runtime);
                g_string_append_printf (str, "\n\tRuntime:\n\t%s\n", runtime);
        }
+       if (app->update_runtime != NULL) {
+               g_autofree gchar *runtime = gs_app_to_string (app->update_runtime);
+               g_string_append_printf (str, "\n\tUpdate Runtime:\n\t%s\n", runtime);
+       }
 
        return g_string_free (str, FALSE);
 }
@@ -1453,7 +1458,7 @@ gs_app_set_content_rating (GsApp *app, AsContentRating *content_rating)
  * gs_app_get_runtime:
  * @app: a #GsApp
  *
- * Gets the runtime for the application.
+ * Gets the runtime for the installed application.
  *
  * Returns: (transfer none): a #GsApp, or %NULL for unset
  *
@@ -1471,7 +1476,7 @@ gs_app_get_runtime (GsApp *app)
  * @app: a #GsApp
  * @runtime: a #GsApp
  *
- * Sets the runtime that the application requires.
+ * Sets the runtime that the installed application requires.
  *
  * Since: 3.22
  **/
@@ -1484,6 +1489,40 @@ gs_app_set_runtime (GsApp *app, GsApp *runtime)
 }
 
 /**
+ * gs_app_get_update_runtime:
+ * @app: a #GsApp
+ *
+ * Gets the runtime required for the application update.
+ *
+ * Returns: (transfer none): a #GsApp, or %NULL for unset
+ *
+ * Since: 3.24
+ **/
+GsApp *
+gs_app_get_update_runtime (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->update_runtime;
+}
+
+/**
+ * gs_app_set_update_runtime:
+ * @app: a #GsApp
+ * @runtime: a #GsApp
+ *
+ * Sets the runtime that the application update requires.
+ *
+ * Since: 3.24
+ **/
+void
+gs_app_set_update_runtime (GsApp *app, GsApp *runtime)
+{
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&app->mutex);
+       g_return_if_fail (GS_IS_APP (app));
+       g_set_object (&app->update_runtime, runtime);
+}
+
+/**
  * gs_app_set_pixbuf:
  * @app: a #GsApp
  * @pixbuf: a #GdkPixbuf, or %NULL
@@ -2519,7 +2558,10 @@ gs_app_get_size_download (GsApp *app)
        sz = app->size_download;
 
        /* add the runtime if this is not installed */
-       if (app->runtime != NULL) {
+       if (app->update_runtime != NULL) {
+               if (gs_app_get_state (app->update_runtime) == AS_APP_STATE_AVAILABLE)
+                       sz += gs_app_get_size_installed (app->update_runtime);
+       } else if (app->runtime != NULL) {
                if (gs_app_get_state (app->runtime) == AS_APP_STATE_AVAILABLE)
                        sz += gs_app_get_size_installed (app->runtime);
        }
@@ -3465,6 +3507,7 @@ gs_app_dispose (GObject *object)
        GsApp *app = GS_APP (object);
 
        g_clear_object (&app->runtime);
+       g_clear_object (&app->update_runtime);
 
        g_clear_pointer (&app->addons, g_ptr_array_unref);
        g_clear_pointer (&app->history, g_ptr_array_unref);
diff --git a/src/gs-app.h b/src/gs-app.h
index a0523f3..e002a0f 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -199,6 +199,9 @@ void                 gs_app_set_update_details      (GsApp          *app,
 AsUrgencyKind   gs_app_get_update_urgency      (GsApp          *app);
 void            gs_app_set_update_urgency      (GsApp          *app,
                                                 AsUrgencyKind   update_urgency);
+GsApp          *gs_app_get_update_runtime      (GsApp          *app);
+void            gs_app_set_update_runtime      (GsApp          *app,
+                                                GsApp          *runtime);
 const gchar    *gs_app_get_management_plugin   (GsApp          *app);
 void            gs_app_set_management_plugin   (GsApp          *app,
                                                 const gchar    *management_plugin);
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 7af6954..23acf5d 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -368,7 +368,7 @@ gs_refine_item_management_plugin (GsPlugin *plugin, GsApp *app, AsApp *item)
                                        g_debug ("runtime for %s is %s",
                                                 gs_app_get_unique_id (app),
                                                 runtime);
-                                       gs_app_set_runtime (app, app2);
+                                       gs_app_set_update_runtime (app, app2);
                                }
                        }
                        break;
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 052a6fe..4c325fb 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -2075,7 +2075,7 @@ install_runtime_for_app (GsFlatpak *self,
                         GError **error)
 {
        GsApp *runtime;
-       runtime = gs_app_get_runtime (app);
+       runtime = gs_app_get_update_runtime (app);
 
        /* the runtime could come from a different remote to the app */
        if (!gs_refine_item_metadata (self, runtime, cancellable, error)) {


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