[gnome-software/wip/rancell/ubuntu-3-20-3: 1/55] Add gs_app_set_local_file()



commit e66af46fed0d3edbc31e2226b98bc2d0014e9edd
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                     |    4 ++++
 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, 48 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 6effba8..6358120 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);
@@ -998,6 +1003,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 *
@@ -2308,6 +2333,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 e128f0c..4aa7273 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3617,6 +3617,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;
@@ -3699,6 +3700,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 b968005..abf1f16 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 */
@@ -903,15 +906,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,
@@ -919,6 +922,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 1edeb72..e97ef13 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 9b1e99e..3135424 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -354,7 +354,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 8fd1a30..7bc2438 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;
@@ -441,15 +442,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,
@@ -466,7 +467,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]