2
|
1 /*
|
|
2 * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
|
|
3 *
|
|
4 * Licensed under the GNU General Public License Version 2
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 */
|
|
20
|
0
|
21 #include <packagekit-glib2/packagekit.h>
|
|
22 #include "packagekit.h"
|
|
23
|
|
24 void process(PkPackage *pkg, struct UpdatesInfo *info)
|
|
25 {
|
|
26 PkInfoEnum e = pk_package_get_info(pkg);
|
|
27 switch (e) {
|
|
28 case PK_INFO_ENUM_LOW:
|
|
29 case PK_INFO_ENUM_ENHANCEMENT:
|
|
30 case PK_INFO_ENUM_NORMAL:
|
|
31 info->normal++;
|
|
32 break;
|
|
33 case PK_INFO_ENUM_BUGFIX:
|
|
34 case PK_INFO_ENUM_IMPORTANT:
|
|
35 case PK_INFO_ENUM_SECURITY:
|
|
36 info->critical++;
|
|
37 break;
|
|
38 default:
|
|
39 break;
|
|
40 }
|
|
41 }
|
|
42
|
|
43 void query_packagekit(struct UpdatesInfo *info)
|
|
44 {
|
|
45 PkClient *client = NULL;
|
|
46 PkResults *res = NULL;
|
|
47 GPtrArray *list = NULL;
|
|
48 GFunc process_func = (GFunc)process;
|
|
49 client = pk_client_new();
|
|
50 res = pk_client_get_updates(client, pk_bitfield_value(PK_FILTER_ENUM_NEWEST), NULL, NULL, NULL, NULL);
|
|
51 if (!res) {
|
|
52 goto out;
|
|
53 }
|
|
54 list = pk_results_get_package_array(res);
|
|
55 if (!list) {
|
|
56 goto out;
|
|
57 }
|
|
58 info->normal = 0;
|
|
59 info->critical = 0;
|
|
60 g_ptr_array_foreach(list, process_func, info);
|
|
61 out:
|
|
62 if (list != NULL)
|
|
63 g_ptr_array_unref(list);
|
|
64 if(res != NULL)
|
|
65 g_object_unref(res);
|
|
66 if(client != NULL)
|
|
67 g_object_unref(client);
|
|
68 }
|