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
66
67
68
69
70
71
72
73
74
75
|
#include <glib.h>
#include <gtk/gtk.h>
#include "logout-dialog.h"
#include "ck-pk-helper.h"
static LogoutDialogAction type = LOGOUT_DIALOG_LOGOUT;
static gboolean
option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error)
{
type = LOGOUT_DIALOG_LOGOUT;
return TRUE;
}
static gboolean
option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error)
{
type = LOGOUT_DIALOG_SHUTDOWN;
return TRUE;
}
static gboolean
option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error)
{
type = LOGOUT_DIALOG_RESTART;
return TRUE;
}
static GOptionEntry options[] = {
{"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL},
{"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Shutdown the entire system", NULL},
{"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL},
{NULL}
};
int
main (int argc, char * argv[])
{
gtk_init(&argc, &argv);
GError * error = NULL;
GOptionContext * context = g_option_context_new(" - logout of the current session");
g_option_context_add_main_entries(context, options, "gtk-logout-helper");
g_option_context_add_group(context, gtk_get_option_group(TRUE));
g_option_context_set_help_enabled(context, TRUE);
if (!g_option_context_parse(context, &argc, &argv, &error)) {
g_debug("Option parsing failed: %s", error->message);
g_error_free(error);
return 1;
}
GtkWidget * dialog = NULL;
if (!pk_require_auth(type)) {
dialog = logout_dialog_new(type);
}
if (dialog != NULL) {
GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_hide(dialog);
if (response == GTK_RESPONSE_HELP) {
type = LOGOUT_DIALOG_RESTART;
response = GTK_RESPONSE_OK;
}
if (response != GTK_RESPONSE_OK) {
return 0;
}
}
return 0;
}
|