[gnome-software/gnome-3-20] Add gs_plugin_refine_app() to the loader and port the plugins
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-3-20] Add gs_plugin_refine_app() to the loader and port the plugins
- Date: Thu, 14 Apr 2016 17:30:10 +0000 (UTC)
commit 0e7ef4b1cb8da8f0da6bba49281e48f83b404531
Author: Richard Hughes <richard hughsie com>
Date: Thu Apr 14 13:45:55 2016 +0100
Add gs_plugin_refine_app() to the loader and port the plugins
A lot of the plugins were just traversing the list, which lead to duplicated
code. Leave the old function in place for plugins like PackageKit that have to
batch up all the requests into one transaction for efficiency.
src/gs-plugin-loader.c | 53 +++++++++---
src/gs-plugin.h | 10 +++
src/plugins/gs-plugin-appstream.c | 26 +++----
src/plugins/gs-plugin-dummy.c | 117 ++++++++++++---------------
src/plugins/gs-plugin-epiphany.c | 46 ++++-------
src/plugins/gs-plugin-hardcoded-blacklist.c | 32 ++------
src/plugins/gs-plugin-icons.c | 44 +++-------
src/plugins/gs-plugin-limba.c | 48 ++++-------
src/plugins/gs-plugin-menu-spec-refine.c | 46 ++++-------
src/plugins/gs-plugin-odrs.c | 61 +++++---------
src/plugins/gs-plugin-packagekit-origin.c | 47 +++--------
src/plugins/gs-plugin-provenance.c | 50 ++++--------
src/plugins/gs-plugin-self-test.c | 24 ++----
src/plugins/gs-plugin-ubuntu-reviews.c | 33 +++-----
src/plugins/gs-plugin-xdg-app.c | 37 +++-----
15 files changed, 265 insertions(+), 409 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index a7033d8..0d286d3 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -185,9 +185,8 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
GPtrArray *related;
GsApp *app;
GsPlugin *plugin;
- GsPluginRefineFunc plugin_func = NULL;
+ const gchar *function_name_app = "gs_plugin_refine_app";
const gchar *function_name = "gs_plugin_refine";
- gboolean exists;
gboolean ret = TRUE;
guint i;
g_autoptr(GsAppList) addons_list = NULL;
@@ -201,18 +200,20 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
/* run each plugin */
for (i = 0; i < priv->plugins->len; i++) {
+ GsPluginRefineAppFunc plugin_app_func = NULL;
+ GsPluginRefineFunc plugin_func = NULL;
g_autoptr(AsProfileTask) ptask = NULL;
- g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
if (!plugin->enabled)
continue;
- /* load the symbol */
- exists = g_module_symbol (plugin->module,
- function_name,
- (gpointer *) &plugin_func);
- if (!exists)
+ /* load the possible symbols */
+ g_module_symbol (plugin->module, function_name,
+ (gpointer *) &plugin_func);
+ g_module_symbol (plugin->module, function_name_app,
+ (gpointer *) &plugin_app_func);
+ if (plugin_func == NULL && plugin_app_func == NULL)
continue;
/* profile the plugin runtime */
@@ -228,12 +229,36 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
function_name_parent,
function_name);
}
- ret = plugin_func (plugin, list, flags, cancellable, &error_local);
- if (!ret) {
- g_warning ("failed to call %s on %s: %s",
- function_name, plugin->name,
- error_local->message);
- continue;
+
+ /* run the batched plugin symbol then the per-app plugin */
+ if (plugin_func != NULL) {
+ g_autoptr(GError) error_local = NULL;
+ g_rw_lock_reader_lock (&plugin->rwlock);
+ ret = plugin_func (plugin, list, flags,
+ cancellable, &error_local);
+ g_rw_lock_reader_unlock (&plugin->rwlock);
+ if (!ret) {
+ g_warning ("failed to call %s on %s: %s",
+ function_name, plugin->name,
+ error_local->message);
+ continue;
+ }
+ }
+ if (plugin_app_func != NULL) {
+ for (l = *list; l != NULL; l = l->next) {
+ g_autoptr(GError) error_local = NULL;
+ app = GS_APP (l->data);
+ g_rw_lock_reader_lock (&plugin->rwlock);
+ ret = plugin_app_func (plugin, app, flags,
+ cancellable, &error_local);
+ g_rw_lock_reader_unlock (&plugin->rwlock);
+ if (!ret) {
+ g_warning ("failed to call %s on %s: %s",
+ function_name_app, plugin->name,
+ error_local->message);
+ continue;
+ }
+ }
}
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
}
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index dbab3c6..7e13f6a 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -159,6 +159,11 @@ typedef gboolean (*GsPluginRefineFunc) (GsPlugin *plugin,
GsPluginRefineFlags flags,
GCancellable *cancellable,
GError **error);
+typedef gboolean (*GsPluginRefineAppFunc) (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error);
typedef gboolean (*GsPluginRefreshFunc ) (GsPlugin *plugin,
guint cache_age,
GsPluginRefreshFlags flags,
@@ -267,6 +272,11 @@ gboolean gs_plugin_refine (GsPlugin *plugin,
GsPluginRefineFlags flags,
GCancellable *cancellable,
GError **error);
+gboolean gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error);
gboolean gs_plugin_launch (GsPlugin *plugin,
GsApp *app,
GCancellable *cancellable,
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 428752f..a9bb7b1 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -326,27 +326,23 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
}
/**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
*/
gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean found = FALSE;
- GList *l;
- GsApp *app;
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (!gs_plugin_refine_from_id (plugin, app, &found, error))
+ /* find by ID then package name */
+ if (!gs_plugin_refine_from_id (plugin, app, &found, error))
+ return FALSE;
+ if (!found) {
+ if (!gs_plugin_refine_from_pkgname (plugin, app, error))
return FALSE;
- if (!found) {
- if (!gs_plugin_refine_from_pkgname (plugin, app, error))
- return FALSE;
- }
}
/* sucess */
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 750c527..f5a92c1 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -140,87 +140,74 @@ gs_plugin_add_popular (GsPlugin *plugin,
}
/**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
*/
gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
- GsApp *app;
- GList *l;
-
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (gs_app_get_name (app) == NULL) {
- if (g_strcmp0 (gs_app_get_id (app), "gnome-boxes") == 0) {
- gs_app_set_license (app, GS_APP_QUALITY_NORMAL,
- "GPL-2.0+");
- gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
- "Boxes");
- gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
- "http://www.gimp.org/");
- gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
- "A simple GNOME 3 application "
- "to access remote or virtual systems");
- gs_app_set_description (app, GS_APP_QUALITY_NORMAL,
- "<p>long description!</p>");
- }
+ /* pkgname */
+ if (gs_app_get_name (app) == NULL) {
+ if (g_strcmp0 (gs_app_get_id (app), "gnome-boxes") == 0) {
+ gs_app_set_license (app, GS_APP_QUALITY_NORMAL,
+ "GPL-2.0+");
+ gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
+ "Boxes");
+ gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
+ "http://www.gimp.org/");
+ gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
+ "A simple GNOME 3 application "
+ "to access remote or virtual systems");
+ gs_app_set_description (app, GS_APP_QUALITY_NORMAL,
+ "<p>long description!</p>");
}
}
/* add fake review */
if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) {
- for (l = *list; l != NULL; l = l->next) {
- g_autoptr(GsReview) review1 = NULL;
- g_autoptr(GsReview) review2 = NULL;
- g_autoptr(GDateTime) dt = NULL;
- app = GS_APP (l->data);
- dt = g_date_time_new_now_utc ();
-
- /* set first review */
- review1 = gs_review_new ();
- gs_review_set_rating (review1, 50);
- gs_review_set_reviewer (review1, "Angela Avery");
- gs_review_set_summary (review1, "Steep learning curve, but worth it");
- gs_review_set_text (review1, "Best overall 3D application I've ever used overall 3D
application I've ever used. Best overall 3D application I've ever used overall 3D application I've ever used.
Best overall 3D application I've ever used overall 3D application I've ever used. Best overall 3D application
I've ever used overall 3D application I've ever used.");
- gs_review_set_version (review1, "3.16.4");
- gs_review_set_date (review1, dt);
- gs_app_add_review (app, review1);
-
- /* set self review */
- review2 = gs_review_new ();
- gs_review_set_rating (review2, 100);
- gs_review_set_reviewer (review2, "Just Myself");
- gs_review_set_summary (review2, "I like this application");
- gs_review_set_text (review2, "I'm not very wordy myself.");
- gs_review_set_version (review2, "3.16.3");
- gs_review_set_date (review2, dt);
- gs_review_set_flags (review2, GS_REVIEW_FLAG_SELF);
- gs_app_add_review (app, review2);
- }
+ g_autoptr(GsReview) review1 = NULL;
+ g_autoptr(GsReview) review2 = NULL;
+ g_autoptr(GDateTime) dt = NULL;
+
+ dt = g_date_time_new_now_utc ();
+
+ /* set first review */
+ review1 = gs_review_new ();
+ gs_review_set_rating (review1, 50);
+ gs_review_set_reviewer (review1, "Angela Avery");
+ gs_review_set_summary (review1, "Steep learning curve, but worth it");
+ gs_review_set_text (review1, "Best overall 3D application I've ever used overall 3D
application I've ever used. Best overall 3D application I've ever used overall 3D application I've ever used.
Best overall 3D application I've ever used overall 3D application I've ever used. Best overall 3D application
I've ever used overall 3D application I've ever used.");
+ gs_review_set_version (review1, "3.16.4");
+ gs_review_set_date (review1, dt);
+ gs_app_add_review (app, review1);
+
+ /* set self review */
+ review2 = gs_review_new ();
+ gs_review_set_rating (review2, 100);
+ gs_review_set_reviewer (review2, "Just Myself");
+ gs_review_set_summary (review2, "I like this application");
+ gs_review_set_text (review2, "I'm not very wordy myself.");
+ gs_review_set_version (review2, "3.16.3");
+ gs_review_set_date (review2, dt);
+ gs_review_set_flags (review2, GS_REVIEW_FLAG_SELF);
+ gs_app_add_review (app, review2);
}
/* add fake ratings */
if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS) {
- for (l = *list; l != NULL; l = l->next) {
- g_autoptr(GArray) ratings = NULL;
- const gint data[] = { 0, 10, 20, 30, 15, 2 };
- ratings = g_array_sized_new (FALSE, FALSE, sizeof (gint), 6);
- g_array_append_vals (ratings, data, 6);
- app = GS_APP (l->data);
- gs_app_set_review_ratings (app, ratings);
- }
+ g_autoptr(GArray) ratings = NULL;
+ const gint data[] = { 0, 10, 20, 30, 15, 2 };
+ ratings = g_array_sized_new (FALSE, FALSE, sizeof (gint), 6);
+ g_array_append_vals (ratings, data, 6);
+ gs_app_set_review_ratings (app, ratings);
}
/* add a rating */
if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING) {
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- gs_app_set_rating (app, 66);
- }
+ gs_app_set_rating (app, 66);
}
return TRUE;
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index da43a89..b4690cb 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -262,13 +262,27 @@ gs_plugin_app_remove (GsPlugin *plugin, GsApp *app,
/**
* gs_plugin_refine_app:
*/
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
+ const gchar *tmp;
g_autofree gchar *fn = NULL;
g_autofree gchar *hash = NULL;
g_autofree gchar *id_nonfull = NULL;
+ /* only process this app if was created by this plugin */
+ if (gs_app_get_kind (app) != AS_APP_KIND_WEB_APP)
+ return TRUE;
+ tmp = gs_app_get_source_id_default (app);
+ if (tmp != NULL)
+ return TRUE;
+
+ gs_app_set_size (app, 4096);
+
id_nonfull = _gs_app_get_id_nonfull (app);
hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, gs_app_get_name (app), -1);
fn = g_strdup_printf ("%s/epiphany/app-%s-%s/%s-%s.desktop",
@@ -288,34 +302,6 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
}
/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GList *l;
- GsApp *app;
- const gchar *tmp;
-
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (gs_app_get_kind (app) != AS_APP_KIND_WEB_APP)
- continue;
- gs_app_set_size (app, 4096);
- tmp = gs_app_get_source_id_default (app);
- if (tmp != NULL)
- continue;
- if (!gs_plugin_refine_app (plugin, app, error))
- return FALSE;
- }
- return TRUE;
-}
-
-/**
* gs_plugin_launch:
*/
gboolean
diff --git a/src/plugins/gs-plugin-hardcoded-blacklist.c b/src/plugins/gs-plugin-hardcoded-blacklist.c
index 9b6741f..e9de91b 100644
--- a/src/plugins/gs-plugin-hardcoded-blacklist.c
+++ b/src/plugins/gs-plugin-hardcoded-blacklist.c
@@ -52,8 +52,12 @@ gs_plugin_order_after (GsPlugin *plugin)
/**
* gs_plugin_refine_app:
*/
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
guint i;
const gchar *app_globs[] = {
@@ -84,27 +88,3 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
return TRUE;
}
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GList *l;
- GsApp *app;
- g_autoptr(AsProfileTask) ptask = NULL;
-
- /* are any of the packages on the blacklist? */
- ptask = as_profile_start_literal (plugin->profile, "hardcoded-blacklist");
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (!gs_plugin_refine_app (plugin, app, error))
- return FALSE;
- }
- return TRUE;
-}
diff --git a/src/plugins/gs-plugin-icons.c b/src/plugins/gs-plugin-icons.c
index 62ae8de..16fd3b6 100644
--- a/src/plugins/gs-plugin-icons.c
+++ b/src/plugins/gs-plugin-icons.c
@@ -112,15 +112,25 @@ gs_plugin_icons_download (GsPlugin *plugin, const gchar *uri, const gchar *filen
}
/**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
*/
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
AsIcon *ic;
const gchar *fn;
gchar *found;
+ /* invalid */
+ if (gs_app_get_pixbuf (app) != NULL)
+ return TRUE;
+ if (gs_app_get_icon (app) == NULL)
+ return TRUE;
+
/* not applicable */
ic = gs_app_get_icon (app);
if (as_icon_get_url (ic) == NULL)
@@ -142,31 +152,3 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
as_icon_set_kind (ic, AS_ICON_KIND_LOCAL);
return gs_app_load_icon (app, plugin->scale, error);
}
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GError *error_local = NULL;
- GList *l;
- GsApp *app;
-
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (gs_app_get_pixbuf (app) != NULL)
- continue;
- if (gs_app_get_icon (app) == NULL)
- continue;
- if (!gs_plugin_refine_app (plugin, app, &error_local)) {
- g_warning ("ignoring: %s", error_local->message);
- g_clear_error (&error_local);
- }
- }
- return TRUE;
-}
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index 127c908..3c1f1c9 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -67,11 +67,25 @@ gs_plugin_destroy (GsPlugin *plugin)
/**
* gs_plugin_refine_app:
*/
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
LiPkgInfo *pki;
g_autoptr(GError) error_local = NULL;
+ g_autoptr(AsProfileTask) ptask = NULL;
+
+ /* not us */
+ if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
+ return TRUE;
+
+ /* profile */
+ ptask = as_profile_start (plugin->profile,
+ "limba::refine{%s}",
+ gs_app_get_id (app));
/* sanity check */
if (gs_app_get_source_default (app) == NULL)
@@ -103,36 +117,6 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
}
/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GList *l;
- GsApp *app;
- g_autoptr(AsProfileTask) ptask = NULL;
-
- ptask = as_profile_start_literal (plugin->profile, "limba::refine");
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
-
- /* not us */
- if (g_strcmp0 (gs_app_get_management_plugin (app), "limba") != 0)
- continue;
-
- if (!gs_plugin_refine_app (plugin, app, error))
- return FALSE;
- }
-
- /* sucess */
- return TRUE;
-}
-
-/**
* GsPluginHelper:
* Helper structure for Limba callbacks.
*/
diff --git a/src/plugins/gs-plugin-menu-spec-refine.c b/src/plugins/gs-plugin-menu-spec-refine.c
index 379a5f2..c6fb49c 100644
--- a/src/plugins/gs-plugin-menu-spec-refine.c
+++ b/src/plugins/gs-plugin-menu-spec-refine.c
@@ -93,13 +93,24 @@ gs_plugin_refine_app_category (GsPlugin *plugin,
/**
* gs_plugin_refine_app:
*/
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
const MenuSpecData *msdata;
gboolean ret = FALSE;
gchar *tmp;
guint i;
+ const gchar *EMPTY[] = { "", NULL };
+
+ /* nothing to do here */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
+ return TRUE;
+ if (gs_app_get_menu_path (app) != NULL)
+ return TRUE;
/* find a top level category the app has */
msdata = menu_spec_get_data ();
@@ -114,35 +125,10 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app)
break;
}
}
- return ret;
-}
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GList *l;
- GsApp *app;
- const gchar *EMPTY[] = { "", NULL };
+ /* don't keep searching for this */
+ if (!ret)
+ gs_app_set_menu_path (app, (gchar **) EMPTY);
- /* nothing to do here */
- if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
- return TRUE;
-
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (gs_app_get_menu_path (app) == NULL) {
- if (!gs_plugin_refine_app (plugin, app)) {
- /* don't keep searching for this */
- gs_app_set_menu_path (app, (gchar **) EMPTY);
- }
- }
- }
return TRUE;
}
diff --git a/src/plugins/gs-plugin-odrs.c b/src/plugins/gs-plugin-odrs.c
index db30de0..f58bb96 100644
--- a/src/plugins/gs-plugin-odrs.c
+++ b/src/plugins/gs-plugin-odrs.c
@@ -650,56 +650,37 @@ gs_plugin_refine_reviews (GsPlugin *plugin,
}
/**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
*/
gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
- GsApp *app;
- GList *l;
+ /* not valid */
+ if (gs_app_get_kind (app) == AS_APP_KIND_ADDON)
+ return TRUE;
+ if (gs_app_get_id_no_prefix (app) == NULL)
+ return TRUE;
/* add reviews if possible */
if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) {
- for (l = *list; l != NULL; l = l->next) {
- g_autoptr(GError) error_local = NULL;
- app = GS_APP (l->data);
- if (gs_app_get_reviews(app)->len > 0)
- continue;
- if (gs_app_get_id_no_prefix (app) == NULL)
- continue;
- if (gs_app_get_kind (app) == AS_APP_KIND_ADDON)
- continue;
- if (!gs_plugin_refine_reviews (plugin, app,
- cancellable,
- &error_local)) {
- g_warning ("Failed to get reviews: %s",
- error_local->message);
- }
- }
+ if (gs_app_get_reviews(app)->len > 0)
+ return TRUE;
+ if (!gs_plugin_refine_reviews (plugin, app,
+ cancellable, error))
+ return FALSE;
}
/* add ratings if possible */
if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS) {
- for (l = *list; l != NULL; l = l->next) {
- g_autoptr(GError) error_local = NULL;
- app = GS_APP (l->data);
- if (gs_app_get_review_ratings(app) != NULL)
- continue;
- if (gs_app_get_id_no_prefix (app) == NULL)
- continue;
- if (gs_app_get_kind (app) == AS_APP_KIND_ADDON)
- continue;
- if (!gs_plugin_refine_ratings (plugin, app,
- cancellable,
- &error_local)) {
- g_warning ("Failed to get ratings: %s",
- error_local->message);
- }
- }
+ if (gs_app_get_review_ratings(app) != NULL)
+ return TRUE;
+ if (!gs_plugin_refine_ratings (plugin, app,
+ cancellable, error))
+ return FALSE;
}
return TRUE;
diff --git a/src/plugins/gs-plugin-packagekit-origin.c b/src/plugins/gs-plugin-packagekit-origin.c
index 0529762..df86d49 100644
--- a/src/plugins/gs-plugin-packagekit-origin.c
+++ b/src/plugins/gs-plugin-packagekit-origin.c
@@ -127,17 +127,22 @@ gs_plugin_packagekit_origin_ensure_sources (GsPlugin *plugin,
}
/**
- * gs_plugin_packagekit_origin_refine_app:
- **/
-static gboolean
-gs_plugin_packagekit_origin_refine_app (GsPlugin *plugin,
- GsApp *app,
- GCancellable *cancellable,
- GError **error)
+ * gs_plugin_refine_app:
+ */
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
const gchar *origin_id;
const gchar *origin_ui;
+ /* only run when required */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) == 0)
+ return TRUE;
+
if (g_strcmp0 (gs_app_get_management_plugin (app), "packagekit") != 0)
return TRUE;
if (gs_app_get_origin (app) == NULL)
@@ -168,31 +173,3 @@ gs_plugin_packagekit_origin_refine_app (GsPlugin *plugin,
gs_app_set_origin_ui (app, origin_ui);
return TRUE;
}
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GList *l;
- GsApp *app;
-
- /* only run when required */
- if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) == 0)
- return TRUE;
-
- /* for each app */
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (!gs_plugin_packagekit_origin_refine_app (plugin, app,
- cancellable,
- error))
- return FALSE;
- }
- return TRUE;
-}
diff --git a/src/plugins/gs-plugin-provenance.c b/src/plugins/gs-plugin-provenance.c
index 48a0be7..1c61ab5 100644
--- a/src/plugins/gs-plugin-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -117,66 +117,50 @@ gs_utils_strv_fnmatch (gchar **strv, const gchar *str)
}
/**
- * gs_plugin_provenance_refine_app:
+ * gs_plugin_refine_app:
*/
-static void
-gs_plugin_provenance_refine_app (GsPlugin *plugin, GsApp *app)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
const gchar *origin;
gchar **sources;
+ /* not required */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
+ return TRUE;
+ if (gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE))
+ return TRUE;
+
/* nothing to search */
sources = plugin->priv->sources;
if (sources == NULL || sources[0] == NULL) {
gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
- return;
+ return TRUE;
}
/* simple case */
origin = gs_app_get_origin (app);
if (origin != NULL && gs_utils_strv_fnmatch (sources, origin)) {
gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
- return;
+ return TRUE;
}
/* this only works for packages */
origin = gs_app_get_source_id_default (app);
if (origin == NULL)
- return;
+ return TRUE;
origin = g_strrstr (origin, ";");
if (origin == NULL)
- return;
+ return TRUE;
if (g_str_has_prefix (origin + 1, "installed:"))
origin += 10;
if (gs_utils_strv_fnmatch (sources, origin + 1)) {
gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
- return;
- }
-}
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GList *l;
- GsApp *app;
-
- /* not required */
- if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
return TRUE;
-
- /* refine apps */
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE))
- continue;
- gs_plugin_provenance_refine_app (plugin, app);
}
return TRUE;
}
diff --git a/src/plugins/gs-plugin-self-test.c b/src/plugins/gs-plugin-self-test.c
index 37b85d4..98f3792 100644
--- a/src/plugins/gs-plugin-self-test.c
+++ b/src/plugins/gs-plugin-self-test.c
@@ -45,24 +45,18 @@ gs_plugin_initialize (GsPlugin *plugin)
}
/**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
*/
gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
- GsApp *app;
- GList *l;
-
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) {
- gs_app_set_state (app, AS_APP_STATE_INSTALLED);
- gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
- }
+ if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) {
+ gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+ gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
}
return TRUE;
}
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index de1e305..888a524 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -653,28 +653,21 @@ refine_reviews (GsPlugin *plugin, GsApp *app, GError **error)
}
gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
- GList *l;
- gboolean ret = TRUE;
-
- for (l = *list; l != NULL; l = l->next) {
- GsApp *app = GS_APP (l->data);
-
- if ((flags & (GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS)) != 0) {
- if (!refine_rating (plugin, app, error))
- return FALSE;
- }
- if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) != 0) {
- if (!refine_reviews (plugin, app, error))
- return FALSE;
- }
+ if ((flags & (GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING | GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS))
!= 0) {
+ if (!refine_rating (plugin, app, error))
+ return FALSE;
+ }
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) != 0) {
+ if (!refine_reviews (plugin, app, error))
+ return FALSE;
}
- return ret;
+ return TRUE;
}
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 99c7bda..0484d2b 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -1089,14 +1089,14 @@ gs_plugin_refine_item_size (GsPlugin *plugin,
}
/**
- * gs_plugin_refine_item:
+ * gs_plugin_xdg_app_refine_app:
*/
static gboolean
-gs_plugin_refine_item (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_xdg_app_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
g_autoptr(AsProfileTask) ptask = NULL;
@@ -1142,24 +1142,15 @@ gs_plugin_refine_item (GsPlugin *plugin,
}
/**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
*/
gboolean
-gs_plugin_refine (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GList *l;
- GsApp *app;
-
- for (l = *list; l != NULL; l = l->next) {
- app = GS_APP (l->data);
- if (!gs_plugin_refine_item (plugin, app, flags, cancellable, error))
- return FALSE;
- }
- return TRUE;
+gs_plugin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{ return gs_plugin_xdg_app_refine_app (plugin, app, flags, cancellable, error);
}
/**
@@ -1236,7 +1227,7 @@ gs_plugin_app_install (GsPlugin *plugin,
return TRUE;
/* ensure we have metadata and state */
- if (!gs_plugin_refine_item (plugin, app, 0, cancellable, error))
+ if (!gs_plugin_xdg_app_refine_app (plugin, app, 0, cancellable, error))
return FALSE;
/* use helper: FIXME: new()&ref? */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]