view packagekit.c @ 1:483f5fe9d2b2

change icon and tooltip of the tray icon
author Pavol Rusnak <stick@gk2.sk>
date Mon, 26 Sep 2011 18:59:14 +0200
parents f5e03fc667f8
children 847ae02bc13b
line wrap: on
line source

#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);
}