[gnome-software/wip/ubuntu-xenial] Add gs_app_set_local_file()



commit 776aaed955b1a6bf888435b4599e1ce6712f7cca
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-refine.c  |    2 +-
 src/plugins/gs-plugin-packagekit-refresh.c |   11 ++++++-----
 src/plugins/gs-plugin-packagekit.c         |   13 +++++++------
 src/plugins/gs-plugin-xdg-app.c            |    8 +-------
 9 files changed, 64 insertions(+), 22 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 4e194df..2770a03 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -103,6 +103,7 @@ struct _GsApp
        AsAppQuirk               quirk;
        gboolean                 licence_is_free;
        GsApp                   *runtime;
+       GFile                   *local_file;
 };
 
 enum {
@@ -248,6 +249,10 @@ gs_app_to_string (GsApp *app)
                tmp = g_ptr_array_index (app->source_ids, i);
                g_string_append_printf (str, "\tsource-id-%02i:\t%s\n", i, 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)
                g_string_append_printf (str, "\turl{homepage}:\t%s\n", tmp);
@@ -930,6 +935,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 *
@@ -2334,6 +2359,8 @@ gs_app_finalize (GObject *object)
        g_ptr_array_unref (app->categories);
        if (app->keywords != NULL)
                g_ptr_array_unref (app->keywords);
+       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 a7590b0..032f791 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -175,6 +175,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 f05ce6a..3bace24 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3671,6 +3671,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;
@@ -3709,6 +3710,13 @@ gs_plugin_loader_file_to_app_thread_cb (GTask *task,
        /* dedupe applications we already know about */
        gs_plugin_loader_list_dedupe (plugin_loader, state->list);
 
+       /* 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,
@@ -3754,6 +3762,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 a769131..2ae6aa8 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -710,6 +710,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 d3b2b14..a80f3cc 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 */
@@ -931,15 +934,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), "fwupd") != 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,
@@ -947,6 +950,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-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 1e88f24..a838875 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -314,7 +314,7 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
        packages = pk_results_get_package_array (results);
        for (l = list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
-               if (gs_app_get_metadata_item (app, "PackageKit::local-filename") != NULL)
+               if (gs_app_get_local_file (app) != NULL)
                        continue;
                gs_plugin_packagekit_resolve_packages_app (plugin, packages, app);
        }
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index afb2f78..d027d25 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -286,6 +286,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;
@@ -309,7 +310,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,
@@ -325,7 +327,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) {
@@ -333,7 +335,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;
        }
 
@@ -342,7 +344,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
        app = gs_app_new (NULL);
        package_id = pk_details_get_package_id (item);
        split = pk_package_id_split (package_id);
-       basename = g_path_get_basename (g_file_get_path (file));
+       basename = g_path_get_basename (filename);
        gs_app_set_management_plugin (app, "PackageKit");
        gs_app_set_kind (app, AS_APP_KIND_GENERIC);
        gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
@@ -352,7 +354,6 @@ gs_plugin_file_to_app (GsPlugin *plugin,
        else
                gs_app_set_name (app, GS_APP_QUALITY_LOWEST, split[PK_PACKAGE_ID_NAME]);
        gs_app_set_version (app, split[PK_PACKAGE_ID_VERSION]);
-       gs_app_set_metadata (app, "PackageKit::local-filename", g_file_get_path (file));
        gs_app_set_origin (app, basename);
        gs_app_add_source (app, split[PK_PACKAGE_ID_NAME]);
        gs_app_add_source_id (app, package_id);
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 8bbe1e5..2ce848d 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -326,9 +326,10 @@ gs_plugin_app_install (GsPlugin *plugin,
        const gchar *package_id;
        guint i, j;
        g_autoptr(PkError) error_code = NULL;
-       g_autoptr(PkResults) results = NULL;
-       g_autoptr(GPtrArray) array_package_ids = NULL;
+       g_autofree gchar *local_filename = 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;
@@ -434,15 +435,15 @@ gs_plugin_app_install (GsPlugin *plugin,
                        return FALSE;
                break;
        case AS_APP_STATE_AVAILABLE_LOCAL:
-               package_id = gs_app_get_metadata_item (app, "PackageKit::local-filename");
-               if (package_id == NULL) {
+               if (gs_app_get_local_file (app) == NULL) {
                        g_set_error_literal (error,
                                             GS_PLUGIN_ERROR,
                                             GS_PLUGIN_ERROR_NOT_SUPPORTED,
                                             "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,
@@ -453,7 +454,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                        return FALSE;
 
                /* get the new icon from the package */
-               gs_app_set_metadata (app, "PackageKit::local-filename", NULL);
+               gs_app_set_local_file (app, NULL);
                gs_app_set_icon (app, NULL);
                gs_app_set_pixbuf (app, NULL);
                break;
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index d597770..94674a3 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -1340,10 +1340,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);
@@ -1517,10 +1515,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]