[gnome-software] trivial: Add gs_app_set_scope()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Add gs_app_set_scope()
- Date: Tue, 9 Aug 2016 16:22:45 +0000 (UTC)
commit 0321bf4fa9249c5ce469b8d0c49d2af0eb733291
Author: Richard Hughes <richard hughsie com>
Date: Tue Aug 9 14:58:48 2016 +0100
trivial: Add gs_app_set_scope()
src/gs-app.c | 34 ++++++++++++++++++++++++++++-
src/gs-app.h | 3 ++
src/plugins/gs-flatpak.c | 17 +++++++++++++-
src/plugins/gs-plugin-dummy.c | 1 +
src/plugins/gs-plugin-packagekit-refine.c | 20 +++++++++++++++++
src/plugins/gs-plugin-shell-extensions.c | 1 +
src/plugins/gs-plugin-snap.c | 1 +
7 files changed, 75 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 0ae6583..441752e 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -100,6 +100,7 @@ struct _GsApp
AsAppKind kind;
AsAppState state;
AsAppState state_recover;
+ AsAppScope scope;
guint progress;
GHashTable *metadata;
GPtrArray *addons; /* of GsApp */
@@ -257,6 +258,8 @@ gs_app_to_string (GsApp *app)
gs_app_kv_lpad (str, "id", app->id);
if (app->unique_id != NULL)
gs_app_kv_lpad (str, "unique-id", app->unique_id);
+ if (app->scope != AS_APP_SCOPE_UNKNOWN)
+ gs_app_kv_lpad (str, "scope", as_app_scope_to_string (app->scope));
if ((app->kudos & GS_APP_KUDO_MY_LANGUAGE) > 0)
gs_app_kv_lpad (str, "kudo", "my-language");
if ((app->kudos & GS_APP_KUDO_RECENT_RELEASE) > 0)
@@ -523,6 +526,35 @@ gs_app_set_id (GsApp *app, const gchar *id)
}
/**
+ * gs_app_get_scope:
+ * @app: a #GsApp
+ *
+ * Gets the scope of the application.
+ *
+ * Returns: the #AsAppScope, e.g. %AS_APP_SCOPE_USER
+ **/
+AsAppScope
+gs_app_get_scope (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), AS_APP_SCOPE_UNKNOWN);
+ return app->scope;
+}
+
+/**
+ * gs_app_set_scope:
+ * @app: a #GsApp
+ * @scope: a #AsAppScope, e.g. AS_APP_SCOPE_SYSTEM
+ *
+ * This sets the scope of the application.
+ **/
+void
+gs_app_set_scope (GsApp *app, AsAppScope scope)
+{
+ g_return_if_fail (GS_IS_APP (app));
+ app->scope = scope;
+}
+
+/**
* gs_app_get_state:
* @app: a #GsApp
*
@@ -840,7 +872,7 @@ gs_app_get_unique_id (GsApp *app)
/* hmm, do what we can */
if (app->unique_id == NULL) {
g_debug ("autogenerating unique-id for %s", app->id);
- app->unique_id = as_utils_unique_id_build (AS_APP_SCOPE_UNKNOWN,
+ app->unique_id = as_utils_unique_id_build (app->scope,
AS_BUNDLE_KIND_UNKNOWN,
app->origin,
app->kind,
diff --git a/src/gs-app.h b/src/gs-app.h
index f6e1672..b979389 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -109,6 +109,9 @@ void gs_app_set_kind (GsApp *app,
AsAppState gs_app_get_state (GsApp *app);
void gs_app_set_state (GsApp *app,
AsAppState state);
+AsAppScope gs_app_get_scope (GsApp *app);
+void gs_app_set_scope (GsApp *app,
+ AsAppScope scope);
void gs_app_set_state_recover (GsApp *app);
guint gs_app_get_progress (GsApp *app);
void gs_app_set_progress (GsApp *app,
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 324e667..14dce42 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -230,6 +230,15 @@ gs_app_set_flatpak_kind (GsApp *app, FlatpakRefKind kind)
}
static void
+gs_plugin_refine_item_scope (GsFlatpak *self, GsApp *app)
+{
+ if (gs_app_get_scope (app) == AS_APP_SCOPE_UNKNOWN) {
+ gboolean is_user = flatpak_installation_get_is_user (self->installation);
+ gs_app_set_scope (app, is_user ? AS_APP_SCOPE_USER : AS_APP_SCOPE_SYSTEM);
+ }
+}
+
+static void
gs_flatpak_set_metadata (GsFlatpak *self, GsApp *app, FlatpakRef *xref)
{
gs_app_set_management_plugin (app, gs_plugin_get_name (self->plugin));
@@ -238,6 +247,7 @@ gs_flatpak_set_metadata (GsFlatpak *self, GsApp *app, FlatpakRef *xref)
gs_app_set_flatpak_arch (app, flatpak_ref_get_arch (xref));
gs_app_set_flatpak_branch (app, flatpak_ref_get_branch (xref));
gs_app_set_flatpak_commit (app, flatpak_ref_get_commit (xref));
+ gs_plugin_refine_item_scope (self, app);
}
static void
@@ -1132,8 +1142,10 @@ gs_flatpak_set_app_metadata (GsFlatpak *self,
/* create runtime */
if (gs_app_get_runtime (app) == NULL) {
app_runtime = gs_appstream_create_runtime (self->plugin, app, runtime);
- if (app_runtime != NULL)
+ if (app_runtime != NULL) {
+ gs_plugin_refine_item_scope (self, app_runtime);
gs_app_set_runtime (app, app_runtime);
+ }
}
return TRUE;
@@ -1292,6 +1304,9 @@ gs_flatpak_refine_app (GsFlatpak *self,
/* flatpak apps can always be removed */
gs_app_remove_quirk (app, AS_APP_QUIRK_COMPULSORY);
+ /* scope is fast, do unconditionally */
+ gs_plugin_refine_item_scope (self, app);
+
/* AppStream sets the source to appname/arch/branch */
if (!gs_refine_item_metadata (self, app, cancellable, error)) {
g_prefix_error (error, "failed to get metadata: ");
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index c0abc5c..21f7a0f 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -305,6 +305,7 @@ gs_plugin_add_popular (GsPlugin *plugin,
/* add again, this time with a prefix so it gets deduplicated */
app2 = gs_app_new ("zeus.desktop");
+ gs_app_set_scope (app2, AS_APP_SCOPE_USER);
gs_app_set_unique_id (app2, "user/dummy/*/*/zeus.desktop/*");
gs_app_set_metadata (app2, "GnomeSoftware::Creator",
gs_plugin_get_name (plugin));
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index ca98f05..8397446 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -929,3 +929,23 @@ gs_plugin_refine (GsPlugin *plugin,
out:
return ret;
}
+
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(AsProfileTask) ptask = NULL;
+
+ /* only process this app if was created by this plugin */
+ if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
+ return TRUE;
+
+ /* the scope is always system-wide */
+ if (gs_app_get_scope (app) == AS_APP_SCOPE_UNKNOWN)
+ gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM);
+
+ return TRUE;
+}
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index 1806697..0539e22 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -131,6 +131,7 @@ gs_plugin_shell_extensions_add_app (GsPlugin *plugin,
id,
NULL); /* branch */
gs_app_set_id (app, id);
+ gs_app_set_scope (app, AS_APP_SCOPE_USER);
gs_app_set_unique_id (app, unique_id);
gs_app_set_metadata (app, "GnomeSoftware::Creator",
gs_plugin_get_name (plugin));
diff --git a/src/plugins/gs-plugin-snap.c b/src/plugins/gs-plugin-snap.c
index 4940ff4..1f98bc2 100644
--- a/src/plugins/gs-plugin-snap.c
+++ b/src/plugins/gs-plugin-snap.c
@@ -343,6 +343,7 @@ get_apps (GsPlugin *plugin,
id,
NULL); /* branch */
app = gs_app_new (id);
+ gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM);
gs_app_set_unique_id (app, unique_id);
gs_app_set_management_plugin (app, "snap");
gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]