[gnome-software] Add gs_app_set_local_file()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add gs_app_set_local_file()
- Date: Mon, 25 Apr 2016 10:37:12 +0000 (UTC)
commit c3703586c0adf6b1a7e955be01484116d38342b6
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 | 12 +++++++-----
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(+), 24 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index b8ee746..c5fb4b5 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -106,6 +106,7 @@ struct _GsApp
AsAppQuirk quirk;
gboolean license_is_free;
GsApp *runtime;
+ GFile *local_file;
};
enum {
@@ -279,6 +280,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);
+ gs_app_kv_lpad (str, "local-filename", 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);
@@ -1006,6 +1011,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 *
@@ -2415,6 +2440,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 d1fd56f..86e750c 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -180,6 +180,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 8f8e3f9..7b8f2c2 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3805,6 +3805,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;
@@ -3843,6 +3844,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,
@@ -3888,6 +3896,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 752bce7..cae8df4 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -463,6 +463,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 7a8ad75..1268060 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -282,6 +282,7 @@ gs_plugin_add_update_app (GsPlugin *plugin,
g_autofree gchar *basename = NULL;
g_autofree gchar *checksum = NULL;
g_autofree gchar *filename_cache = NULL;
+ g_autoptr(GFile) file = NULL;
g_autoptr(GsApp) app = NULL;
/* update unsupported */
@@ -367,7 +368,8 @@ gs_plugin_add_update_app (GsPlugin *plugin,
}
/* actually add the application */
- gs_app_add_source_id (app, filename_cache);
+ file = g_file_new_for_path (filename_cache);
+ gs_app_set_local_file (app, file);
gs_app_list_add (list, app);
return TRUE;
@@ -636,11 +638,11 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
{
GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *device_id;
- const gchar *filename;
FwupdInstallFlags install_flags = 0;
+ g_autofree gchar *filename = NULL;
- 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,
@@ -648,6 +650,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");
@@ -756,7 +759,6 @@ gs_plugin_file_to_app (GsPlugin *plugin,
if (res == NULL)
return FALSE;
app = gs_plugin_fwupd_new_app_from_results (res);
- gs_app_add_source_id (app, g_file_get_path (file));
/* we have no update view for local files */
gs_app_set_version (app, gs_app_get_update_version (app));
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index d1641d5..9f60a54 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -324,7 +324,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 3673ed0..f7ba457 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -294,6 +294,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;
@@ -317,7 +318,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 (priv->task), G_MAXUINT);
results = pk_client_get_details_local (PK_CLIENT (priv->task),
files,
@@ -333,7 +335,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) {
@@ -341,7 +343,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;
}
@@ -350,7 +352,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);
@@ -360,7 +362,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 495eb89..e549c32 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -317,9 +317,10 @@ gs_plugin_app_install (GsPlugin *plugin,
ProgressData data;
const gchar *package_id;
guint i, j;
- 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;
@@ -436,15 +437,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 (priv->task,
package_ids,
@@ -461,7 +462,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 3f58e0b..155881c 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -1297,10 +1297,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 (priv->installation,
- file,
+ gs_app_get_local_file (app),
gs_plugin_xdg_app_progress_cb,
app,
cancellable, error);
@@ -1480,10 +1478,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]