[gnome-software/wip/temp/ubuntu-xenial-rebased-corrected: 307/331] Add gs_app_set_local_file()



commit c870777d28b37ffebe3438060206c0f6be8d1cba
Author: Richard Hughes <richard hughsie com>
Date:   Mon Apr 25 11:36:45 2016 +0100

    Add gs_app_set_local_file()

 src/gs-app.c                               |   27 +++++++++++++++++++++++++++
 src/gs-app.h                               |    3 +++
 src/gs-plugin-loader.c                     |   11 +++++++++++
 src/gs-self-test.c                         |    1 +
 src/plugins/gs-plugin-fwupd.c              |   10 +++++++---
 src/plugins/gs-plugin-packagekit-refresh.c |    8 +++++---
 src/plugins/gs-plugin-packagekit.c         |    5 ++++-
 src/plugins/gs-plugin-xdg-app.c            |    8 +-------
 8 files changed, 59 insertions(+), 14 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index a37a01f..d3b58e8 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -105,6 +105,7 @@ struct _GsApp
        AsAppQuirk               quirk;
        gboolean                 license_is_free;
        GsApp                   *runtime;
+       GFile                   *local_file;
 };
 
 enum {
@@ -277,6 +278,10 @@ gs_app_to_string (GsApp *app)
                key = g_strdup_printf ("source-id-%02i", i);
                gs_app_kv_lpad (str, key, tmp);
        }
+       if (app->local_file != NULL) {
+               g_autofree gchar *fn = g_file_get_path (app->local_file);
+               g_string_append_printf (str, "\tlocal-filename:\t%s\n", fn);
+       }
        tmp = g_hash_table_lookup (app->urls, as_url_kind_to_string (AS_URL_KIND_HOMEPAGE));
        if (tmp != NULL)
                gs_app_kv_lpad (str, "url{homepage}", tmp);
@@ -1001,6 +1006,26 @@ gs_app_set_icon (GsApp *app, AsIcon *icon)
 }
 
 /**
+ * gs_app_get_local_file:
+ */
+GFile *
+gs_app_get_local_file (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->local_file;
+}
+
+/**
+ * gs_app_set_local_file:
+ */
+void
+gs_app_set_local_file (GsApp *app, GFile *local_file)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_set_object (&app->local_file, local_file);
+}
+
+/**
  * gs_app_get_runtime:
  */
 GsApp *
@@ -2331,6 +2356,8 @@ gs_app_finalize (GObject *object)
                g_ptr_array_unref (app->keywords);
        if (app->last_error != NULL)
                g_error_free (app->last_error);
+       if (app->local_file != NULL)
+               g_object_unref (app->local_file);
 
        G_OBJECT_CLASS (gs_app_parent_class)->finalize (object);
 }
diff --git a/src/gs-app.h b/src/gs-app.h
index d546673..d09dc1d 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -177,6 +177,9 @@ void                 gs_app_set_pixbuf              (GsApp          *app,
 AsIcon         *gs_app_get_icon                (GsApp          *app);
 void            gs_app_set_icon                (GsApp          *app,
                                                 AsIcon         *icon);
+GFile          *gs_app_get_local_file          (GsApp          *app);
+void            gs_app_set_local_file          (GsApp          *app,
+                                                GFile          *icon);
 GsApp          *gs_app_get_runtime             (GsApp          *app);
 void            gs_app_set_runtime             (GsApp          *app,
                                                 GsApp          *runtime);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 05a50d8..b480f06 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3639,6 +3639,7 @@ gs_plugin_loader_file_to_app_thread_cb (GTask *task,
        const gchar *function_name = "gs_plugin_file_to_app";
        gboolean ret = TRUE;
        GError *error = NULL;
+       GList *l;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPlugin *plugin;
        GsPluginFileToAppFunc plugin_func = NULL;
@@ -3676,6 +3677,13 @@ gs_plugin_loader_file_to_app_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
+       /* set the local file on any of the returned results */
+       for (l = state->list; l != NULL; l = l->next) {
+               GsApp *app = GS_APP (l->data);
+               if (gs_app_get_local_file (app) == NULL)
+                       gs_app_set_local_file (app, state->file);
+       }
+
        /* run refine() on each one */
        ret = gs_plugin_loader_run_refine (plugin_loader,
                                           function_name,
@@ -3721,6 +3729,9 @@ gs_plugin_loader_file_to_app_thread_cb (GTask *task,
  * Once the list of updates is refined, some of the #GsApp's of kind
  * %AS_APP_KIND_GENERIC will have been promoted to a kind of %AS_APP_KIND_DESKTOP,
  * or if they are core applications.
+ *
+ * Files that are supported will have the GFile used to create them available
+ * from the gs_app_get_local_file() method.
  **/
 void
 gs_plugin_loader_file_to_app_async (GsPluginLoader *plugin_loader,
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 25d0f05..aad1280 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -455,6 +455,7 @@ gs_plugin_loader_dpkg_func (GsPluginLoader *plugin_loader)
        g_assert_cmpstr (gs_app_get_description (app), ==,
                         "This is the first paragraph in the example "
                         "package control file.\nThis is the second paragraph.");
+       g_assert (gs_app_get_local_file (app) != NULL);
 }
 
 int
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index d08bd75..02fe467 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -276,6 +276,7 @@ gs_plugin_add_update_app (GsPlugin *plugin,
        g_autofree gchar *update_hash = NULL;
        g_autofree gchar *update_uri = NULL;
        g_autoptr(AsIcon) icon = NULL;
+       g_autoptr(GFile) file = NULL;
        g_autoptr(GsApp) app = NULL;
 
        app = gs_app_new (NULL);
@@ -386,6 +387,8 @@ gs_plugin_add_update_app (GsPlugin *plugin,
        gs_app_add_category (app, "System");
        gs_app_set_kind (app, AS_APP_KIND_FIRMWARE);
        gs_app_set_metadata (app, "fwupd::DeviceID", id);
+       file = g_file_new_for_path (filename_cache);
+       gs_app_set_local_file (app, file);
        gs_plugin_add_app (list, app);
 
        /* create icon */
@@ -907,15 +910,15 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
 {
        const gchar *install_method;
        const gchar *device_id;
-       const gchar *filename;
+       g_autofree gchar *filename = NULL;
        gboolean offline = FALSE;
 
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
-       filename = gs_app_get_source_id_default (app);
-       if (filename == NULL) {
+       /* not set */
+       if (gs_app_get_local_file (app) == NULL) {
                g_set_error (error,
                             GS_PLUGIN_ERROR,
                             GS_PLUGIN_ERROR_FAILED,
@@ -923,6 +926,7 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
                             filename);
                return FALSE;
        }
+       filename = g_file_get_path (gs_app_get_local_file (app));
 
        /* limit to single device? */
        device_id = gs_app_get_metadata_item (app, "fwupd::DeviceID");
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index 7282575..aad76d8 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -299,6 +299,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
        g_autoptr (PkResults) results = NULL;
        g_autofree gchar *basename = NULL;
        g_autofree gchar *content_type = NULL;
+       g_autofree gchar *filename = NULL;
        g_autofree gchar *license_spdx = NULL;
        g_auto(GStrv) files = NULL;
        g_auto(GStrv) split = NULL;
@@ -322,7 +323,8 @@ gs_plugin_file_to_app (GsPlugin *plugin,
        data.ptask = NULL;
 
        /* get details */
-       files = g_strsplit (g_file_get_path (file), "\t", -1);
+       filename = g_file_get_path (file);
+       files = g_strsplit (filename, "\t", -1);
        pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), G_MAXUINT);
        results = pk_client_get_details_local (PK_CLIENT (plugin->priv->task),
                                               files,
@@ -338,7 +340,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
                g_set_error (error,
                             GS_PLUGIN_ERROR,
                             GS_PLUGIN_ERROR_FAILED,
-                            "no details for %s", g_file_get_path (file));
+                            "no details for %s", filename);
                return FALSE;
        }
        if (array->len > 1) {
@@ -346,7 +348,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
                             GS_PLUGIN_ERROR,
                             GS_PLUGIN_ERROR_FAILED,
                             "too many details [%i] for %s",
-                            array->len, g_file_get_path (file));
+                            array->len, filename);
                return FALSE;
        }
 
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 189e1f1..98e7f5f 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -326,6 +326,8 @@ gs_plugin_app_install (GsPlugin *plugin,
        g_autoptr(PkResults) results = NULL;
        g_autoptr(GPtrArray) array_package_ids = NULL;
        g_auto(GStrv) package_ids = NULL;
+       g_autoptr(GPtrArray) array_package_ids = NULL;
+       g_autoptr(PkResults) results = NULL;
 
        data.app = app;
        data.plugin = plugin;
@@ -449,7 +451,8 @@ gs_plugin_app_install (GsPlugin *plugin,
                                             "local package, but no filename");
                        return FALSE;
                }
-               package_ids = g_strsplit (package_id, "\t", -1);
+               local_filename = g_file_get_path (gs_app_get_local_file (app));
+               package_ids = g_strsplit (local_filename, "\t", -1);
                gs_app_set_state (app, AS_APP_STATE_INSTALLING);
                results = pk_task_install_files_sync (plugin->priv->task,
                                                      package_ids,
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index cf9c6ff..863c997 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -1298,10 +1298,8 @@ gs_plugin_app_install (GsPlugin *plugin,
 
        /* use the source for local apps */
        if (gs_app_get_state (app) == AS_APP_STATE_AVAILABLE_LOCAL) {
-               g_autoptr(GFile) file = NULL;
-               file = g_file_new_for_path (gs_app_get_source_default (app));
                xref = xdg_app_installation_install_bundle (plugin->priv->installation,
-                                                           file,
+                                                           gs_app_get_local_file (app),
                                                            gs_plugin_xdg_app_progress_cb,
                                                            &helper,
                                                            cancellable, error);
@@ -1483,10 +1481,6 @@ gs_plugin_file_to_app (GsPlugin *plugin,
                gs_app_set_icon (app, icon);
        }
 
-
-       /* set the source so we can install it higher up */
-       gs_app_add_source (app, g_file_get_path (file));
-
        /* not quite true: this just means we can update this specific app */
        if (xdg_app_bundle_ref_get_origin (xref_bundle))
                gs_app_add_quirk (app, AS_APP_QUIRK_HAS_SOURCE);


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