]> Dogcows Code - chaz/openbox/blob - openbox/actions/session.c
Merge branch 'backport' into work
[chaz/openbox] / openbox / actions / session.c
1 #include "openbox/actions.h"
2 #include "openbox/prompt.h"
3 #include "openbox/session.h"
4 #include "gettext.h"
5
6 typedef struct {
7 gboolean prompt;
8 gboolean silent;
9 } Options;
10
11 static gpointer setup_func(xmlNodePtr node);
12 static gboolean logout_func(ObActionsData *data, gpointer options);
13
14 void action_session_startup(void)
15 {
16 actions_register("SessionLogout", setup_func, NULL, logout_func,
17 NULL, NULL);
18 }
19
20 static gpointer setup_func(xmlNodePtr node)
21 {
22 xmlNodePtr n;
23 Options *o;
24
25 o = g_new0(Options, 1);
26 o->prompt = TRUE;
27
28 if ((n = obt_parse_find_node(node, "prompt")))
29 o->prompt = obt_parse_node_bool(n);
30
31 return o;
32 }
33
34 static gboolean prompt_cb(ObPrompt *p, gint result, gpointer data)
35 {
36 if (result) {
37 #ifdef USE_SM
38 Options *o = data;
39 session_request_logout(o->silent);
40 #else
41 /* TRANSLATORS: Don't translate the word "SessionLogout" as it's the
42 name of the action you write in rc.xml */
43 g_message(_("The SessionLogout action is not available since Openbox was built without session management support"));
44 #endif
45 }
46 return TRUE; /* call cleanup func */
47 }
48
49 static void prompt_cleanup(ObPrompt *p, gpointer data)
50 {
51 g_free(data);
52 prompt_unref(p);
53 }
54
55 /* Always return FALSE because its not interactive */
56 static gboolean logout_func(ObActionsData *data, gpointer options)
57 {
58 Options *o = options;
59
60 if (o->prompt) {
61 Options *o2;
62 ObPrompt *p;
63 ObPromptAnswer answers[] = {
64 { _("Cancel"), 0 },
65 { _("Log Out"), 1 }
66 };
67
68 o2 = g_memdup(o, sizeof(Options));
69 p = prompt_new(_("Are you sure you want to log out?"),
70 _("Log Out"),
71 answers, 2, 0, 0, prompt_cb, prompt_cleanup, o2);
72 prompt_show(p, NULL, FALSE);
73 }
74 else
75 prompt_cb(NULL, 1, o);
76
77 return FALSE;
78 }
This page took 0.039095 seconds and 5 git commands to generate.