view packagekit.c @ 6:7539e6e1c299

fix desktop file and arguments order in Makefile
author Pavol Rusnak <stick@gk2.sk>
date Thu, 06 Oct 2011 16:02:19 +0200
parents 847ae02bc13b
children
line wrap: on
line source

/*
 * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
 *
 * Licensed under the GNU General Public License Version 2
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

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