[gnome-software/wip/rancell/ubuntu-3-20-rebase: 2/52] Add gs_app_set_local_file()
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/ubuntu-3-20-rebase: 2/52] Add gs_app_set_local_file()
- Date: Sat, 17 Jun 2017 08:56:40 +0000 (UTC)
commit 331b3f43ea114d375d79211ed3768998179fe117
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 | 13 +++++++------
src/plugins/gs-plugin-xdg-app.c | 8 +-------
8 files changed, 57 insertions(+), 18 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index c300875..1929b18 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 {
@@ -245,6 +246,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);
@@ -922,6 +927,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 *
@@ -2288,6 +2313,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 3ae9e20..7f03df3 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -170,6 +170,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 f07d60d..656cf2a 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3610,6 +3610,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;
@@ -3648,6 +3649,13 @@ gs_plugin_loader_filename_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,
@@ -3693,6 +3701,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 a2bfd9a..5fb858a 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 */
@@ -927,15 +930,15 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
GError **error)
{
const gchar *install_method;
- const gchar *filename;
+ g_autofree gchar *filename = NULL;
gboolean offline = TRUE;
/* 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,
@@ -943,6 +946,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 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 551b035..551ae18 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -378,7 +378,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 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 18528aa..e61e92a 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);
@@ -1559,10 +1557,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]