Debian Codegraph @

docs/html/files/system.c

raw
1 #include <packagekit-glib/packagekit.h>
2
3 int
4 main (int argc, char *argv[])
5 {
6 guint i;
7 guint length;
8 gboolean ret;
9 GError *error = NULL;
10 const PkPackageObj *obj;
11 PkPackageList *list = NULL;
12 PkControl *control = NULL;
13 PkClient *client = NULL;
14 PkBitfield roles;
15
16 /* find out if we can do GetUpdates */
17 control = pk_control_new ();
18 roles = pk_control_get_actions (control, NULL);
19 if (!pk_bitfield_contain (roles, PK_ROLE_ENUM_GET_UPDATES)) {
20 g_warning ("Backend does not support GetUpdates()");
21 goto out;
22 }
23
24 /* create a new client instance */
25 client = pk_client_new ();
26
27 /* save all the results as we are not using an async callback */
28 pk_client_set_use_buffer (client, TRUE, NULL);
29
30 /* block for the results, does not require gtk_main() or anything */
31 pk_client_set_synchronous (client, TRUE, NULL);
32
33 /* get the update list (but only return the newest updates) */
34 ret = pk_client_get_updates (client, PK_FILTER_ENUM_NEWEST, &error);
35 if (!ret) {
36 g_warning ("failed: %s", error->message);
37 g_error_free (error);
38 goto out;
39 }
40
41 /* get the buffered package list */
42 list = pk_client_get_package_list (client);
43 if (list == NULL) {
44 g_warning ("failed to get buffered list");
45 goto out;
46 }
47
48 length = pk_package_list_get_size (list);
49 for (i=0; i<length; i++) {
50 /* get each package to be updated, and print to the screen */
51 obj = pk_package_list_get_obj (list, i);
52 g_print ("%i. %s-%s.%s\t%s\n", i, obj->id->name, obj->id->version, obj->id->arch, obj->summary);
53 }
54
55 out:
56 /* free any GObjects we used */
57 if (list != NULL)
58 g_object_unref (list);
59 if (control != NULL)
60 g_object_unref (control);
61 if (client != NULL)
62 g_object_unref (client);
63 return 0;
64 }
65