Debian Codegraph @

src/polkitbackend/polkitbackendactionlookup.c

raw
1 /*
2 * Copyright (C) 2008 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 * Author: David Zeuthen <[email protected]>
20 */
21
22 #include <errno.h>
23 #include <pwd.h>
24 #include <string.h>
25
26 #define _POLKIT_BACKEND_ACTION_LOOKUP_NO_DEPRECATED_WARNING
27
28 #include <polkit/polkit.h>
29 #include <polkit/polkitprivate.h>
30 #include "polkitbackendactionlookup.h"
31
32 #include "polkitbackendprivate.h"
33
34 /**
35 * SECTION:polkitbackendactionlookup
36 * @title: PolkitBackendActionLookup
37 * @short_description: Interface used to provide data to authentication dialogs
38 * @stability: Unstable
39 *
40 * An interface that is used by backends to provide localized data
41 * shown in authentication dialogs.
42 *
43 * This inteface is intended for mechanisms to customize the message
44 * to show - a mechanism can provide a #GIOModule that registers one
45 * or more extensions that implement this interface. Every time an
46 * authentication dialog is shown, the registered extensions are
47 * consulted in priority order.
48 *
49 * This is useful if your mechanism wants to put up a message such as
50 * "Authentication is required to install 'Totem Movie Player'",
51 * e.g. messages that include more information than just the action
52 * name.
53 *
54 * Code implementing this interface <emphasis>cannot</emphasis> block
55 * or do any IO when methods are invoked. If information is needed to
56 * format the message or details, prepare it in advance and pass it as
57 * part of the @details object when doing the
58 * polkit_authority_check_authorization() call. Then the code in this
59 * interface can use that information to return localized data.
60 *
61 * Note that setlocale() and the <literal>LANG</literal> environment
62 * variable will be set up to match the locale of the authentication
63 * agent that is the receiver of the information. This means that code
64 * implementing this interface can use dgettext() or similar machinery
65 * to look up translations.
66 */
67
68 static void
69 base_init (gpointer g_iface)
70 {
71 }
72
73 GType
74 polkit_backend_action_lookup_get_type (void)
75 {
76 static volatile gsize g_define_type_id__volatile = 0;
77
78 if (g_once_init_enter ((gsize*) &g_define_type_id__volatile))
79 {
80 static const GTypeInfo info =
81 {
82 sizeof (PolkitBackendActionLookupIface),
83 base_init, /* base_init */
84 NULL, /* base_finalize */
85 NULL, /* class_init */
86 NULL, /* class_finalize */
87 NULL, /* class_data */
88 0, /* instance_size */
89 0, /* n_preallocs */
90 NULL, /* instance_init */
91 NULL /* value_table */
92 };
93
94 GType iface_type =
95 g_type_register_static (G_TYPE_INTERFACE, "PolkitBackendActionLookup", &info, 0);
96
97 g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT);
98 g_once_init_leave (&g_define_type_id__volatile, iface_type);
99 }
100
101 return g_define_type_id__volatile;
102 }
103
104 /**
105 * polkit_backend_action_lookup_get_message:
106 * @lookup: A #PolkitBackendActionLookup.
107 * @action_id: The action to get the message for.
108 * @details: Details passed to polkit_authority_check_authorization().
109 * @action_description: A #PolkitActionDescription object for @action_id.
110 *
111 * Computes a message to show in an authentication dialog for
112 * @action_id and @details.
113 *
114 * Returns: A localized string to show in the authentication dialog or %NULL. Caller must free this string.
115 **/
116 gchar *
117 polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
118 const gchar *action_id,
119 PolkitDetails *details,
120 PolkitActionDescription *action_description)
121 {
122 PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);
123
124 if (iface->get_message == NULL)
125 return NULL;
126 else
127 return iface->get_message (lookup, action_id, details, action_description);
128 }
129
130 /**
131 * polkit_backend_action_lookup_get_icon_name:
132 * @lookup: A #PolkitBackendActionLookup.
133 * @action_id: The action to get the themed icon for.
134 * @details: Details passed to polkit_authority_check_authorization().
135 * @action_description: A #PolkitActionDescription object for @action_id.
136 *
137 * Computes a themed icon name to show in an authentication dialog for
138 * @action_id and @details.
139 *
140 * Returns: A themed icon name or %NULL. Caller must free this string.
141 **/
142 gchar *
143 polkit_backend_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
144 const gchar *action_id,
145 PolkitDetails *details,
146 PolkitActionDescription *action_description)
147 {
148 PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);
149
150 if (iface->get_icon_name == NULL)
151 return NULL;
152 else
153 return iface->get_icon_name (lookup, action_id, details, action_description);
154 }
155
156 /**
157 * polkit_backend_action_lookup_get_details:
158 * @lookup: A #PolkitBackendActionLookup.
159 * @action_id: The action to get the details for.
160 * @details: Details passed to polkit_authority_check_authorization().
161 * @action_description: A #PolkitActionDescription object for @action_id.
162 *
163 * Computes localized details to show in an authentication dialog for
164 * @action_id and @details.
165 *
166 * Returns: A #PolkitDetails object with localized details or %NULL. Caller must free the result.
167 **/
168 PolkitDetails *
169 polkit_backend_action_lookup_get_details (PolkitBackendActionLookup *lookup,
170 const gchar *action_id,
171 PolkitDetails *details,
172 PolkitActionDescription *action_description)
173 {
174 PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);
175
176 if (iface->get_details == NULL)
177 return NULL;
178 else
179 return iface->get_details (lookup, action_id, details, action_description);
180 }
181