Commit 9e30ba01 authored by David Zeuthen's avatar David Zeuthen

bring back annotations

parent 82714f27
......@@ -41,6 +41,10 @@ struct _PolkitActionDescription
GObject parent_instance;
_PolkitActionDescription *real;
gchar **annotation_keys;
GIcon *icon;
};
struct _PolkitActionDescriptionClass
......@@ -63,6 +67,11 @@ polkit_action_description_finalize (GObject *object)
action_description = POLKIT_ACTION_DESCRIPTION (object);
g_object_unref (action_description->real);
g_strfreev (action_description->annotation_keys);
if (action_description->icon != NULL)
g_object_unref (action_description->icon);
}
static void
......@@ -124,18 +133,72 @@ GIcon *
polkit_action_description_get_icon (PolkitActionDescription *action_description)
{
const gchar *icon_name;
GIcon *icon;
GError *error;
if (action_description->icon != NULL)
goto out;
icon_name = _polkit_action_description_get_icon_name (action_description->real);
if (icon_name == NULL)
goto out;
error = NULL;
icon = g_icon_new_for_string (icon_name, &error);
if (icon_name == NULL)
action_description->icon = g_icon_new_for_string (icon_name, &error);
if (action_description->icon == NULL)
{
g_warning ("polkit_action_description_get_icon: %s", error->message);
g_error_free (error);
}
return icon;
out:
return action_description->icon;
}
const gchar *
polkit_action_description_get_annotation (PolkitActionDescription *action_description,
const gchar *key)
{
EggDBusHashMap *annotations;
annotations = _polkit_action_description_get_annotations (action_description->real);
return egg_dbus_hash_map_lookup (annotations, key);
}
static gboolean
collect_keys (EggDBusHashMap *hash_map,
gpointer key,
gpointer value,
gpointer user_data)
{
GPtrArray *p = user_data;
g_ptr_array_add (p, g_strdup (key));
return FALSE;
}
const gchar * const *
polkit_action_description_get_annotation_keys (PolkitActionDescription *action_description)
{
EggDBusHashMap *annotations;
GPtrArray *p;
if (action_description->annotation_keys != NULL)
goto out;
annotations = _polkit_action_description_get_annotations (action_description->real);
p = g_ptr_array_new ();
egg_dbus_hash_map_foreach (annotations, collect_keys, p);
g_ptr_array_add (p, NULL);
action_description->annotation_keys = (gchar **) g_ptr_array_free (p, FALSE);
out:
return (const gchar * const *) action_description->annotation_keys;
}
......@@ -40,13 +40,16 @@ typedef struct _PolkitActionDescription PolkitActionDescription;
#endif
typedef struct _PolkitActionDescriptionClass PolkitActionDescriptionClass;
GType polkit_action_description_get_type (void) G_GNUC_CONST;
const gchar *polkit_action_description_get_action_id (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_description (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_message (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_vendor_name (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_vendor_url (PolkitActionDescription *action_description);
GIcon *polkit_action_description_get_icon (PolkitActionDescription *action_description);
GType polkit_action_description_get_type (void) G_GNUC_CONST;
const gchar *polkit_action_description_get_action_id (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_description (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_message (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_vendor_name (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_vendor_url (PolkitActionDescription *action_description);
GIcon *polkit_action_description_get_icon (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_annotation (PolkitActionDescription *action_description,
const gchar *key);
const gchar * const *polkit_action_description_get_annotation_keys (PolkitActionDescription *action_description);
G_END_DECLS
......
......@@ -44,11 +44,10 @@ GType polkit_authority_get_type (void) G_GNUC_CONST;
PolkitAuthority *polkit_authority_get (void);
GList *polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
const gchar *locale,
GCancellable *cancellable,
GError **error);
GList *polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
const gchar *locale,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* __POLKIT_AUTHORITY_H */
......@@ -19,19 +19,24 @@
* Author: David Zeuthen <davidz@redhat.com>
*/
#include <string.h>
#include <polkit/polkit.h>
static PolkitAuthority *authority;
static gboolean opt_list_actions = FALSE;
static gchar *opt_show_action = NULL;
static GOptionEntry option_entries[] = {
{"list-actions", 'l', 0, G_OPTION_ARG_NONE, &opt_list_actions, "List registered actions", NULL },
{"show-action", 's', 0, G_OPTION_ARG_STRING, &opt_show_action, "Show details for an action", "Action ID" },
{NULL, },
};
static gboolean list_actions (void);
static gboolean show_action (const gchar *action_id);
int
main (int argc, char *argv[])
{
......@@ -60,6 +65,10 @@ main (int argc, char *argv[])
{
ret = list_actions ();
}
else if (opt_show_action != NULL)
{
ret = show_action (opt_show_action);
}
else
{
gchar *s;
......@@ -77,9 +86,104 @@ main (int argc, char *argv[])
g_option_context_free (option_ctx);
out:
g_free (opt_show_action);
return ret ? 0 : 1;
}
static void
print_action (PolkitActionDescription *action)
{
const gchar *vendor;
const gchar *vendor_url;
GIcon *icon;
const gchar * const *annotation_keys;
guint n;
vendor = polkit_action_description_get_vendor_name (action);
vendor_url = polkit_action_description_get_vendor_url (action);
icon = polkit_action_description_get_icon (action);
g_print ("action_id: %s\n", polkit_action_description_get_action_id (action));
g_print ("description: %s\n", polkit_action_description_get_description (action));
g_print ("message: %s\n", polkit_action_description_get_message (action));
if (vendor != NULL)
g_print ("vendor: %s\n", vendor);
if (vendor_url != NULL)
g_print ("vendor_url: %s\n", vendor_url);
if (icon != NULL)
{
gchar *s;
s = g_icon_to_string (icon);
g_print ("icon: %s\n", s);
g_free (s);
}
annotation_keys = polkit_action_description_get_annotation_keys (action);
for (n = 0; annotation_keys[n] != NULL; n++)
{
const gchar *key;
const gchar *value;
key = annotation_keys[n];
value = polkit_action_description_get_annotation (action, key);
g_print ("annotation: %s -> %s\n", key, value);
}
}
static gboolean
show_action (const gchar *action_id)
{
gboolean ret;
GError *error;
GList *actions;
GList *l;
ret = FALSE;
error = NULL;
actions = polkit_authority_enumerate_actions_sync (authority,
NULL,
NULL,
&error);
if (error != NULL)
{
g_printerr ("Error enumerating actions: %s\n", error->message);
g_error_free (error);
goto out;
}
for (l = actions; l != NULL; l = l->next)
{
PolkitActionDescription *action = POLKIT_ACTION_DESCRIPTION (l->data);
const gchar *id;
id = polkit_action_description_get_action_id (action);
if (strcmp (id, action_id) == 0)
{
print_action (action);
break;
}
}
g_list_foreach (actions, (GFunc) g_object_unref, NULL);
g_list_free (actions);
if (l != NULL)
{
ret = TRUE;
}
else
{
g_printerr ("Error: No action with action id %s\n", action_id);
}
out:
return ret;
}
static gboolean
list_actions (void)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment