static gboolean gs_plugin_app_set_usage_app (GsPlugin *plugin, GsApp *app, gboolean is_install, GError **error) { GPtrArray *sources; const gchar *pkgname; gboolean ret; guint i; /* get the package name */ sources = gs_app_get_sources (app); if (sources->len == 0) return TRUE; /* tell fedora-tagger about this package */ for (i = 0; i < sources->len; i++) { pkgname = g_ptr_array_index (sources, i); ret = gs_plugin_app_set_usage_pkg (plugin, pkgname, is_install, error); if (!ret) return FALSE; } return TRUE; }
/** * gs_plugin_refine: */ gboolean gs_plugin_refine (GsPlugin *plugin, GList **list, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GList *l; GPtrArray *sources; GsApp *app; const gchar *pkgname; gboolean ret; gint rating; gint confidence; guint i; /* nothing to do here */ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING) == 0) return TRUE; /* already loaded */ if (g_once_init_enter (&plugin->priv->loaded)) { ret = gs_plugin_fedora_tagger_load_db (plugin, error); g_once_init_leave (&plugin->priv->loaded, TRUE); if (!ret) return FALSE; } /* add any missing ratings data */ for (l = *list; l != NULL; l = l->next) { app = GS_APP (l->data); if (gs_app_get_rating (app) != -1) continue; sources = gs_app_get_sources (app); for (i = 0; i < sources->len; i++) { pkgname = g_ptr_array_index (sources, i); ret = gs_plugin_resolve_app (plugin, pkgname, &rating, &confidence, error); if (!ret) return FALSE; if (rating != -1) { g_debug ("fedora-tagger setting rating on %s to %i%% [%i]", pkgname, rating, confidence); gs_app_set_rating (app, rating); gs_app_set_rating_confidence (app, confidence); gs_app_set_rating_kind (app, GS_APP_RATING_KIND_SYSTEM); if (confidence > 50 && rating > 80) { g_debug ("%s is popular [confidence %i]", gs_app_get_source_default (app), confidence); gs_app_add_kudo (app, GS_APP_KUDO_POPULAR); } } } } return TRUE; }
/** * gs_plugin_app_set_rating: */ gboolean gs_plugin_app_set_rating (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GPtrArray *sources; const gchar *pkgname; gboolean ret; guint i; /* get the package name */ sources = gs_app_get_sources (app); if (sources->len == 0) { g_warning ("no pkgname for %s", gs_app_get_id (app)); return TRUE; } /* ensure networking is set up */ if (!gs_plugin_setup_networking (plugin, error)) return FALSE; /* set rating for each package */ for (i = 0; i < sources->len; i++) { pkgname = g_ptr_array_index (sources, i); ret = gs_plugin_app_set_rating_pkg (plugin, pkgname, gs_app_get_rating (app), error); if (!ret) return FALSE; } return TRUE; }
static gboolean refine_reviews (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GPtrArray *sources; guint i, j; /* Skip if already has reviews */ if (gs_app_get_reviews (app)->len > 0) return TRUE; sources = gs_app_get_sources (app); for (i = 0; i < sources->len; i++) { const gchar *package_name; package_name = g_ptr_array_index (sources, i); for (j = 0; j < N_PAGES; j++) { gboolean ret; ret = download_reviews (plugin, app, package_name, j, cancellable, error); if (!ret) return FALSE; } } return TRUE; }
static gboolean refine_rating (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); GPtrArray *sources; guint i; /* Load database once */ if (g_once_init_enter (&priv->db_loaded)) { gboolean ret = load_database (plugin, cancellable, error); g_once_init_leave (&priv->db_loaded, TRUE); if (!ret) return FALSE; } /* Skip if already has a rating */ if (gs_app_get_rating (app) != -1) return TRUE; sources = gs_app_get_sources (app); for (i = 0; i < sources->len; i++) { const gchar *package_name; gint rating; gint review_ratings[6]; gboolean ret; /* Otherwise use the statistics */ package_name = g_ptr_array_index (sources, i); ret = get_review_stats (plugin, package_name, &rating, review_ratings, error); if (!ret) return FALSE; if (rating != -1) { g_autoptr(GArray) ratings = NULL; g_debug ("ubuntu-reviews setting rating on %s to %i%%", package_name, rating); gs_app_set_rating (app, rating); ratings = g_array_sized_new (FALSE, FALSE, sizeof (gint), 6); g_array_append_vals (ratings, review_ratings, 6); gs_app_set_review_ratings (app, ratings); if (rating > 80) gs_app_add_kudo (app, GS_APP_KUDO_POPULAR); } } return TRUE; }
/** * gs_appstream_refine_app: */ gboolean gs_appstream_refine_app (GsPlugin *plugin, GsApp *app, AsApp *item, GError **error) { AsRelease *rel; GHashTable *urls; GPtrArray *pkgnames; GPtrArray *kudos; const gchar *tmp; guint i; /* set the kind to be more precise */ if (gs_app_get_kind (app) == AS_APP_KIND_UNKNOWN || gs_app_get_kind (app) == AS_APP_KIND_GENERIC) { gs_app_set_kind (app, as_app_get_kind (item)); } /* is installed already */ if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) { switch (as_app_get_source_kind (item)) { case AS_APP_SOURCE_KIND_APPDATA: case AS_APP_SOURCE_KIND_DESKTOP: gs_app_set_kind (app, AS_APP_KIND_DESKTOP); gs_app_set_state (app, AS_APP_STATE_INSTALLED); break; case AS_APP_SOURCE_KIND_METAINFO: gs_app_set_state (app, AS_APP_STATE_INSTALLED); break; case AS_APP_SOURCE_KIND_APPSTREAM: gs_app_set_state (app, as_app_get_state (item)); break; default: break; } } /* set management plugin automatically */ gs_refine_item_management_plugin (app, item); /* set id */ if (as_app_get_id (item) != NULL && gs_app_get_id (app) == NULL) gs_app_set_id (app, as_app_get_id (item)); /* set name */ tmp = as_app_get_name (item, NULL); if (tmp != NULL) { if (g_str_has_prefix (tmp, "(Nightly) ")) { tmp += 10; if (gs_app_get_metadata_item (app, "X-XdgApp-Tags") == NULL) gs_app_set_metadata (app, "X-XdgApp-Tags", "nightly"); } gs_app_set_name (app, GS_APP_QUALITY_HIGHEST, tmp); } /* set summary */ tmp = as_app_get_comment (item, NULL); if (tmp != NULL) { gs_app_set_summary (app, GS_APP_QUALITY_HIGHEST, tmp); } /* add urls */ urls = as_app_get_urls (item); if (g_hash_table_size (urls) > 0 && gs_app_get_url (app, AS_URL_KIND_HOMEPAGE) == NULL) { GList *l; g_autoptr(GList) keys = NULL; keys = g_hash_table_get_keys (urls); for (l = keys; l != NULL; l = l->next) { gs_app_set_url (app, as_url_kind_from_string (l->data), g_hash_table_lookup (urls, l->data)); } } /* set licence */ if (as_app_get_project_license (item) != NULL && gs_app_get_license (app) == NULL) gs_app_set_license (app, GS_APP_QUALITY_HIGHEST, as_app_get_project_license (item)); /* set keywords */ if (as_app_get_keywords (item, NULL) != NULL && gs_app_get_keywords (app) == NULL) { gs_app_set_keywords (app, as_app_get_keywords (item, NULL)); gs_app_add_kudo (app, GS_APP_KUDO_HAS_KEYWORDS); } /* set origin */ if (as_app_get_origin (item) != NULL && gs_app_get_origin (app) == NULL) { gs_app_set_origin (app, as_app_get_origin (item)); } /* set description */ tmp = as_app_get_description (item, NULL); if (tmp != NULL) { g_autofree gchar *from_xml = NULL; from_xml = as_markup_convert_simple (tmp, error); if (from_xml == NULL) { g_prefix_error (error, "trying to parse '%s': ", tmp); return FALSE; } gs_app_set_description (app, GS_APP_QUALITY_HIGHEST, from_xml); } /* set icon */ if (as_app_get_icon_default (item) != NULL && gs_app_get_pixbuf (app) == NULL) gs_refine_item_pixbuf (plugin, app, item); /* set categories */ if (as_app_get_categories (item) != NULL && gs_app_get_categories (app)->len == 0) gs_app_set_categories (app, as_app_get_categories (item)); /* set project group */ if (as_app_get_project_group (item) != NULL && gs_app_get_project_group (app) == NULL) gs_app_set_project_group (app, as_app_get_project_group (item)); /* this is a core application for the desktop and cannot be removed */ if (_as_app_has_compulsory_for_desktop (item, "GNOME") && gs_app_get_kind (app) == AS_APP_KIND_DESKTOP) gs_app_add_quirk (app, AS_APP_QUIRK_COMPULSORY); /* set id kind */ if (gs_app_get_kind (app) == AS_APP_KIND_UNKNOWN) gs_app_set_kind (app, as_app_get_kind (item)); /* copy all the metadata */ gs_appstream_copy_metadata (app, item); /* set package names */ pkgnames = as_app_get_pkgnames (item); if (pkgnames->len > 0 && gs_app_get_sources(app)->len == 0) gs_app_set_sources (app, pkgnames); /* set addons */ gs_appstream_refine_add_addons (plugin, app, item); /* set screenshots */ gs_appstream_refine_add_screenshots (app, item); /* are the screenshots perfect */ if (gs_appstream_are_screenshots_perfect (item)) gs_app_add_kudo (app, GS_APP_KUDO_PERFECT_SCREENSHOTS); /* was this application released recently */ if (gs_appstream_is_recent_release (item)) gs_app_add_kudo (app, GS_APP_KUDO_RECENT_RELEASE); /* add kudos */ if (as_app_get_language (item, plugin->locale) > 50) gs_app_add_kudo (app, GS_APP_KUDO_MY_LANGUAGE); /* add new-style kudos */ kudos = as_app_get_kudos (item); for (i = 0; i < kudos->len; i++) { tmp = g_ptr_array_index (kudos, i); switch (as_kudo_kind_from_string (tmp)) { case AS_KUDO_KIND_SEARCH_PROVIDER: gs_app_add_kudo (app, GS_APP_KUDO_SEARCH_PROVIDER); break; case AS_KUDO_KIND_USER_DOCS: gs_app_add_kudo (app, GS_APP_KUDO_INSTALLS_USER_DOCS); break; case AS_KUDO_KIND_APP_MENU: gs_app_add_kudo (app, GS_APP_KUDO_USES_APP_MENU); break; case AS_KUDO_KIND_MODERN_TOOLKIT: gs_app_add_kudo (app, GS_APP_KUDO_MODERN_TOOLKIT); break; case AS_KUDO_KIND_NOTIFICATIONS: gs_app_add_kudo (app, GS_APP_KUDO_USES_NOTIFICATIONS); break; case AS_KUDO_KIND_HIGH_CONTRAST: gs_app_add_kudo (app, GS_APP_KUDO_HIGH_CONTRAST); break; case AS_KUDO_KIND_HI_DPI_ICON: gs_app_add_kudo (app, GS_APP_KUDO_HI_DPI_ICON); break; default: g_debug ("no idea how to handle kudo '%s'", tmp); break; } } /* is there any update information */ rel = as_app_get_release_default (item); if (rel != NULL) { tmp = as_release_get_description (rel, NULL); if (tmp != NULL) { g_autofree gchar *desc = NULL; desc = as_markup_convert (tmp, AS_MARKUP_CONVERT_FORMAT_MARKDOWN, error); if (desc == NULL) return FALSE; gs_app_set_update_details (app, desc); } gs_app_set_update_urgency (app, as_release_get_urgency (rel)); gs_app_set_update_version (app, as_release_get_version (rel)); } return TRUE; }