Mercurial > projects > pk-update-icon
diff packagekit.c @ 0:f5e03fc667f8
initial commit
author | Pavol Rusnak <stick@gk2.sk> |
---|---|
date | Mon, 26 Sep 2011 18:52:04 +0200 |
parents | |
children | 847ae02bc13b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/packagekit.c Mon Sep 26 18:52:04 2011 +0200 @@ -0,0 +1,48 @@ +#include <packagekit-glib2/packagekit.h> +#include "packagekit.h" + +void process(PkPackage *pkg, struct UpdatesInfo *info) +{ + PkInfoEnum e = pk_package_get_info(pkg); + switch (e) { + case PK_INFO_ENUM_LOW: + case PK_INFO_ENUM_ENHANCEMENT: + case PK_INFO_ENUM_NORMAL: + info->normal++; + break; + case PK_INFO_ENUM_BUGFIX: + case PK_INFO_ENUM_IMPORTANT: + case PK_INFO_ENUM_SECURITY: + info->critical++; + break; + default: + break; + } +} + +void query_packagekit(struct UpdatesInfo *info) +{ + PkClient *client = NULL; + PkResults *res = NULL; + GPtrArray *list = NULL; + GFunc process_func = (GFunc)process; + client = pk_client_new(); + res = pk_client_get_updates(client, pk_bitfield_value(PK_FILTER_ENUM_NEWEST), NULL, NULL, NULL, NULL); + if (!res) { + goto out; + } + list = pk_results_get_package_array(res); + if (!list) { + goto out; + } + info->normal = 0; + info->critical = 0; + g_ptr_array_foreach(list, process_func, info); +out: + if (list != NULL) + g_ptr_array_unref(list); + if(res != NULL) + g_object_unref(res); + if(client != NULL) + g_object_unref(client); +}