[gnome-software] Allow refining the update-severity using PackageKit
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Allow refining the update-severity using PackageKit
- Date: Mon, 28 Sep 2015 11:35:46 +0000 (UTC)
commit c3c95bb36bbdd2389e5809f5733f696c77390eaf
Author: Richard Hughes <richard hughsie com>
Date: Mon Sep 28 09:43:28 2015 +0100
Allow refining the update-severity using PackageKit
src/gs-plugin.h | 1 +
src/plugins/gs-plugin-packagekit-refine.c | 71 +++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 2d7f215..b5b7005 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -100,6 +100,7 @@ typedef enum {
GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH = 1 << 12,
GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS = 1 << 13,
GS_PLUGIN_REFINE_FLAGS_ALLOW_PACKAGES = 1 << 14,
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_SEVERITY = 1 << 15,
GS_PLUGIN_REFINE_FLAGS_LAST
} GsPluginRefineFlags;
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 612d551..774fed3 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -533,6 +533,67 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
}
/**
+ * gs_plugin_packagekit_refine_update_severity:
+ */
+static gboolean
+gs_plugin_packagekit_refine_update_severity (GsPlugin *plugin,
+ GList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GList *l;
+ GsApp *app;
+ const gchar *package_id;
+ PkBitfield filter;
+ g_autoptr(PkPackageSack) sack = NULL;
+ g_autoptr(PkResults) results = NULL;
+
+ /* get the list of updates */
+ filter = pk_bitfield_value (PK_FILTER_ENUM_NONE);
+ results = pk_client_get_updates (plugin->priv->client,
+ filter,
+ cancellable,
+ gs_plugin_packagekit_progress_cb, plugin,
+ error);
+ if (results == NULL)
+ return FALSE;
+
+ /* set the update severity for the app */
+ sack = pk_results_get_package_sack (results);
+ for (l = list; l != NULL; l = l->next) {
+ g_autoptr (PkPackage) pkg = NULL;
+ app = GS_APP (l->data);
+ package_id = gs_app_get_source_id_default (app);
+ if (package_id == NULL)
+ continue;
+ pkg = pk_package_sack_find_by_id (sack, package_id);
+ if (pkg == NULL)
+ continue;
+ switch (pk_package_get_info (pkg)) {
+ case PK_INFO_ENUM_AVAILABLE:
+ case PK_INFO_ENUM_NORMAL:
+ case PK_INFO_ENUM_ENHANCEMENT:
+ case PK_INFO_ENUM_BUGFIX:
+ case PK_INFO_ENUM_LOW:
+ gs_app_set_update_severity (app, GS_APP_UPDATE_SEVERITY_NORMAL);
+ break;
+ case PK_INFO_ENUM_SECURITY:
+ gs_app_set_update_severity (app, GS_APP_UPDATE_SEVERITY_SECURITY);
+ break;
+ case PK_INFO_ENUM_IMPORTANT:
+ gs_app_set_update_severity (app, GS_APP_UPDATE_SEVERITY_IMPORTANT);
+ break;
+ default:
+ gs_app_set_update_severity (app, GS_APP_UPDATE_SEVERITY_UNKNOWN);
+ g_warning ("unhandled info state %s",
+ pk_info_enum_to_string (pk_package_get_info (pkg)));
+ break;
+ }
+ }
+ return TRUE;
+}
+
+/**
* gs_plugin_refine_app_needs_details:
*/
static gboolean
@@ -794,6 +855,16 @@ gs_plugin_refine (GsPlugin *plugin,
if (!ret)
goto out;
}
+
+ /* get the update severity */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_SEVERITY) > 0) {
+ ret = gs_plugin_packagekit_refine_update_severity (plugin,
+ *list,
+ cancellable,
+ error);
+ if (!ret)
+ goto out;
+ }
out:
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]