[gnome-software/gnome-3-22] Add gs_app_get_update_runtime()



commit 141cce81b7e721de10cd592f66339bbee99ff843
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 022195f..bb58b05 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -92,6 +92,7 @@ struct _GsApp
        gchar                   *update_version_ui;
        gchar                   *update_details;
        AsUrgencyKind            update_urgency;
+       GsApp                   *update_runtime;
        gchar                   *management_plugin;
        guint                    match_value;
        guint                    priority;
@@ -488,6 +489,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);
 }
@@ -1413,7 +1418,7 @@ gs_app_set_local_file (GsApp *app, GFile *local_file)
  * 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
  *
@@ -1431,7 +1436,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
  **/
@@ -1444,6 +1449,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.22
+ **/
+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.22
+ **/
+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
@@ -2480,7 +2519,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);
        }
@@ -3428,6 +3470,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 7324e18..1e90de0 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -194,6 +194,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 7a5051e..d461ca6 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -374,7 +374,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 4484214..cad29cd 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -1930,7 +1930,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]