[gnome-software/wip/ubuntu-3-20: 10/57] Add gs_app_set_local_file()



commit d3e81d6e52f3231d0f64eb06a4a04f1efc133014
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/plugins/gs-plugin-fwupd.c              |   10 +++++++---
 src/plugins/gs-plugin-packagekit-refine.c  |    2 +-
 src/plugins/gs-plugin-packagekit-refresh.c |    1 -
 src/plugins/gs-plugin-packagekit.c         |    9 +++++----
 src/plugins/gs-plugin-xdg-app.c            |    8 +-------
 8 files changed, 55 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 23f19e2..db4d960 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);
@@ -999,6 +1004,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 3cd4e9a..2290b30 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -182,6 +182,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 f0f4051..c43dc69 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3827,6 +3827,7 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
        const gchar *function_name = "gs_plugin_filename_to_app";
        gboolean ret = TRUE;
        GError *error = NULL;
+       GList *l;
        GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
        GsPlugin *plugin;
        GsPluginFilenameToAppFunc plugin_func = NULL;
@@ -3864,6 +3865,13 @@ gs_plugin_loader_filename_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,
@@ -3909,6 +3917,9 @@ gs_plugin_loader_filename_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_filename_to_app_async (GsPluginLoader *plugin_loader,
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index fbe7d6a..4e1b65a 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -278,6 +278,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);
@@ -388,6 +389,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 */
@@ -905,15 +908,15 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
                         GError **error)
 {
        const gchar *install_method;
-       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,
@@ -921,6 +924,7 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
                             filename);
                return FALSE;
        }
+       filename = g_file_get_path (gs_app_get_local_file (app));
 
        /* only offline supported */
        install_method = gs_app_get_metadata_item (app, "fwupd::InstallMethod");
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 3246178..b4125fa 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -304,7 +304,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 97d84d3..f64de01 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -352,7 +352,6 @@ gs_plugin_filename_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", filename);
        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 a3efa40..54d2861 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -326,6 +326,7 @@ 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_autofree gchar *local_filename = NULL;
 
        data.app = app;
        data.plugin = plugin;
@@ -439,15 +440,15 @@ gs_plugin_app_install (GsPlugin *plugin,
 
                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,
@@ -463,7 +464,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
 
                /* 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 ddc9ead..f9c891d 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);
@@ -1487,10 +1485,6 @@ gs_plugin_filename_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, filename);
-
        /* 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]