From 2d30206e8d6b5312641f8970a7be9ae1a2583695 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sun, 9 Sep 2007 16:57:56 +0100 Subject: [PATCH] allow us to get the actions from the console client --- client/pk-console.c | 17 +++++++++++++++++ libpackagekit/pk-enum-list.c | 26 ++++++++++++++++++++++++++ libpackagekit/pk-enum-list.h | 7 ++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/client/pk-console.c b/client/pk-console.c index af452da44..9c73e4b75 100644 --- a/client/pk-console.c +++ b/client/pk-console.c @@ -31,6 +31,7 @@ #include #include #include +#include /** * pk_console_package_cb: @@ -138,6 +139,8 @@ pk_console_parse_multiple_commands (PkTaskClient *tclient, GPtrArray *array) const gchar *value = NULL; const gchar *details = NULL; guint remove; + PkEnumList *elist; + gchar *text; mode = g_ptr_array_index (array, 0); if (array->len > 1) { @@ -253,6 +256,20 @@ pk_console_parse_multiple_commands (PkTaskClient *tclient, GPtrArray *array) pk_task_client_set_sync (tclient, TRUE); pk_task_client_get_updates (tclient); remove = 2; + } else if (strcmp (value, "actions") == 0) { + /* get backend actions */ + text = pk_task_client_get_actions (tclient); + + /* push into a PkEnumList */ + elist = pk_enum_list_new (); + pk_enum_list_set_type (elist, PK_ENUM_LIST_TYPE_ACTION); + pk_enum_list_from_string (elist, text); + pk_enum_list_print (elist); + + /* don't leak */ + g_free (text); + g_object_unref (elist); + remove = 2; } else { pk_console_usage ("invalid get type"); } diff --git a/libpackagekit/pk-enum-list.c b/libpackagekit/pk-enum-list.c index a0d42f0a7..f652d46bf 100644 --- a/libpackagekit/pk-enum-list.c +++ b/libpackagekit/pk-enum-list.c @@ -150,6 +150,32 @@ pk_enum_list_to_string (PkEnumList *elist) return g_string_free (string, FALSE); } +/** + * pk_enum_list_print: + **/ +gboolean +pk_enum_list_print (PkEnumList *elist) +{ + guint i; + guint value; + const gchar *text = NULL; + + if (elist->priv->type == PK_ENUM_LIST_TYPE_ACTION) { + g_print ("Printing actions:\n"); + } + for (i=0; ipriv->data->len; i++) { + value = GPOINTER_TO_UINT (g_ptr_array_index (elist->priv->data, i)); + if (elist->priv->type == PK_ENUM_LIST_TYPE_ACTION) { + text = pk_action_enum_to_text (value); + } else { + pk_error ("unknown type %i (did you use pk_enum_list_set_type?)", elist->priv->type); + } + g_print ("%s\n", text); + } + + return TRUE; +} + /** * pk_enum_list_append: **/ diff --git a/libpackagekit/pk-enum-list.h b/libpackagekit/pk-enum-list.h index 65ec9cd4e..58efa143e 100644 --- a/libpackagekit/pk-enum-list.h +++ b/libpackagekit/pk-enum-list.h @@ -58,11 +58,12 @@ gboolean pk_enum_list_set_type (PkEnumList *elist, PkEnumListType type); gboolean pk_enum_list_from_string (PkEnumList *elist, const gchar *enums); -gchar *pk_enum_list_to_string (PkEnumList *alist); -gboolean pk_enum_list_contains (PkEnumList *alist, +gchar *pk_enum_list_to_string (PkEnumList *elist); +gboolean pk_enum_list_contains (PkEnumList *elist, guint value); -gboolean pk_enum_list_append (PkEnumList *alist, +gboolean pk_enum_list_append (PkEnumList *elist, guint value); +gboolean pk_enum_list_print (PkEnumList *elist); gboolean pk_enum_list_append_multiple (PkEnumList *elist, guint value, ...);