]> Dogcows Code - chaz/openbox/blob - openbox/actions/exit.c
strip leading/trailing whitespace off stuff when reading it from the configs
[chaz/openbox] / openbox / actions / exit.c
1 #include "openbox/actions.h"
2 #include "openbox/openbox.h"
3 #include "openbox/prompt.h"
4 #include "gettext.h"
5
6 typedef struct {
7 gboolean prompt;
8 } Options;
9
10 static gpointer setup_func(xmlNodePtr node);
11 static gboolean run_func(ObActionsData *data, gpointer options);
12
13 void action_exit_startup(void)
14 {
15 actions_register("Exit", setup_func, NULL, run_func, NULL, NULL);
16 }
17
18 static gpointer setup_func(xmlNodePtr node)
19 {
20 xmlNodePtr n;
21 Options *o;
22
23 o = g_new0(Options, 1);
24 o->prompt = TRUE;
25
26 if ((n = obt_parse_find_node(node, "prompt")))
27 o->prompt = obt_parse_node_bool(n);
28
29 return o;
30 }
31
32 static gboolean prompt_cb(ObPrompt *p, gint result, gpointer data)
33 {
34 if (result)
35 ob_exit(0);
36 return TRUE; /* call the cleanup func */
37 }
38
39 static void prompt_cleanup(ObPrompt *p, gpointer data)
40 {
41 prompt_unref(p);
42 }
43
44 /* Always return FALSE because its not interactive */
45 static gboolean run_func(ObActionsData *data, gpointer options)
46 {
47 Options *o = options;
48
49 if (o->prompt) {
50 ObPrompt *p;
51 ObPromptAnswer answers[] = {
52 { _("Cancel"), 0 },
53 { _("Exit"), 1 }
54 };
55
56 p = prompt_new(_("Are you sure you want to exit Openbox?"),
57 _("Exit Openbox"),
58 answers, 2, 0, 0, prompt_cb, prompt_cleanup, NULL);
59 prompt_show(p, NULL, FALSE);
60 }
61 else
62 ob_exit(0);
63
64 return FALSE;
65 }
This page took 0.044106 seconds and 4 git commands to generate.