121
139
if (current_temporary_authorizations != NULL)
142
#ifdef HAVE_APPINDICATOR
143
if (app_indicator == NULL)
145
GtkWidget *item, *menu;
147
app_indicator = app_indicator_new ("PolicyKit-gnome",
148
"gtk-dialog-authentication",
149
APP_INDICATOR_CATEGORY_SYSTEM_SERVICES);
151
item = gtk_menu_item_new_with_label (_("Drop all elevated privileges"));
152
g_signal_connect (item,
154
G_CALLBACK (on_menu_item_activate),
156
menu = gtk_menu_new ();
157
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
158
gtk_widget_show_all (menu);
160
app_indicator_set_menu (app_indicator,
162
app_indicator_set_status (app_indicator,
163
APP_INDICATOR_STATUS_ACTIVE);
124
166
if (status_icon == NULL)
126
168
status_icon = gtk_status_icon_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION);
198
251
update_temporary_authorization_icon (authority);
254
// session management support for auto-restart
255
#define SM_DBUS_NAME "org.gnome.SessionManager"
256
#define SM_DBUS_PATH "/org/gnome/SessionManager"
257
#define SM_DBUS_INTERFACE "org.gnome.SessionManager"
258
#define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
260
static DBusGConnection *bus_connection;
261
static DBusGProxy *sm_proxy;
262
static DBusGProxy *client_proxy = NULL;
264
static GMainLoop *loop;
268
stop_cb (gpointer data)
270
g_main_loop_quit (loop);
274
end_session_response (gboolean is_okay, const gchar *reason)
277
GError *error = NULL;
279
ret = dbus_g_proxy_call (client_proxy, "EndSessionResponse",
281
G_TYPE_BOOLEAN, is_okay,
282
G_TYPE_STRING, reason,
287
g_warning ("Failed to send session response %s", error->message);
288
g_error_free (error);
295
query_end_session_cb (guint flags, gpointer data)
297
end_session_response (TRUE, NULL);
301
end_session_cb (guint flags, gpointer data)
303
end_session_response (TRUE, NULL);
304
g_main_loop_quit (loop);
309
register_client_to_gnome_session (void)
313
const char *startup_id;
317
startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
318
app_id = "polkit-gnome-authentication-agent-1.desktop";
321
bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
322
if (bus_connection == NULL) {
323
g_message ("Failed to connect to the session bus: %s",
325
g_error_free (error);
329
sm_proxy = dbus_g_proxy_new_for_name (bus_connection,
333
if (sm_proxy == NULL) {
334
g_message("Failed to get session manager");
339
res = dbus_g_proxy_call (sm_proxy,
342
G_TYPE_STRING, app_id,
343
G_TYPE_STRING, startup_id,
345
DBUS_TYPE_G_OBJECT_PATH, &client_id,
348
g_warning ("Failed to register client: %s", error->message);
349
g_error_free (error);
353
// implement the signals to fix "policykit agent not responding"
354
// error (LP: #623819)
355
client_proxy = dbus_g_proxy_new_for_name (bus_connection,
358
SM_CLIENT_DBUS_INTERFACE);
360
dbus_g_proxy_add_signal (client_proxy, "Stop", G_TYPE_INVALID);
361
dbus_g_proxy_connect_signal (client_proxy, "Stop",
362
G_CALLBACK (stop_cb), NULL, NULL);
364
dbus_g_proxy_add_signal (client_proxy, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID);
365
dbus_g_proxy_connect_signal (client_proxy, "QueryEndSession",
366
G_CALLBACK (query_end_session_cb), NULL, NULL);
368
dbus_g_proxy_add_signal (client_proxy, "EndSession", G_TYPE_UINT, G_TYPE_INVALID);
369
dbus_g_proxy_connect_signal (client_proxy, "EndSession",
370
G_CALLBACK (end_session_cb), NULL, NULL);
202
376
main (int argc, char **argv)
206
379
PolkitAgentListener *listener;