File: system.c

package info (click to toggle)
packagekit 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,704 kB
  • sloc: ansic: 56,209; cpp: 13,919; python: 4,970; xml: 4,945; sh: 313; perl: 60; makefile: 57
file content (65 lines) | stat: -rw-r--r-- 1,692 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <packagekit-glib/packagekit.h>

int
main (int argc, char *argv[])
{
	guint i;
	guint length;
	gboolean ret;
	GError *error = NULL;
	const PkPackageObj *obj;
	PkPackageList *list = NULL;
	PkControl *control = NULL;
	PkClient *client = NULL;
	PkBitfield roles;

	/* find out if we can do GetUpdates */
	control = pk_control_new ();
	roles = pk_control_get_actions (control, NULL);
	if (!pk_bitfield_contain (roles, PK_ROLE_ENUM_GET_UPDATES)) {
		g_warning ("Backend does not support GetUpdates()");
		goto out;
	}

	/* create a new client instance */
	client = pk_client_new ();

	/* save all the results as we are not using an async callback */
	pk_client_set_use_buffer (client, TRUE, NULL);

	/* block for the results, does not require gtk_main() or anything */
	pk_client_set_synchronous (client, TRUE, NULL);

	/* get the update list (but only return the newest updates) */
	ret = pk_client_get_updates (client, PK_FILTER_ENUM_NEWEST, &error);
	if (!ret) {
		g_warning ("failed: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* get the buffered package list */
	list = pk_client_get_package_list (client);
	if (list == NULL) {
		g_warning ("failed to get buffered list");
		goto out;
	}

	length = pk_package_list_get_size (list);
	for (i=0; i<length; i++) {
		/* get each package to be updated, and print to the screen */
		obj = pk_package_list_get_obj (list, i);
		g_print ("%i. %s-%s.%s\t%s\n", i, obj->id->name, obj->id->version, obj->id->arch, obj->summary);
	}

out:
	/* free any GObjects we used */
	if (list != NULL)
		g_object_unref (list);
	if (control != NULL)
		g_object_unref (control);
	if (client != NULL)
		g_object_unref (client);
	return 0;
}