]> Dogcows Code - chaz/openbox/blob - openbox/actions/exit.c
more using g_slice_new() instead of g_new()
[chaz/openbox] / openbox / actions / exit.c
1 #include "openbox/actions.h"
2 #include "openbox/openbox.h"
3 #include "openbox/prompt.h"
4 #include "openbox/session.h"
5 #include "gettext.h"
6
7 typedef struct {
8 gboolean prompt;
9 } Options;
10
11 static gpointer setup_func(xmlNodePtr node);
12 static void free_func(gpointer o);
13 static gboolean run_func(ObActionsData *data, gpointer options);
14
15 void action_exit_startup(void)
16 {
17 actions_register("Exit", setup_func, free_func, run_func);
18 actions_register("SessionLogout", setup_func, free_func, run_func);
19 }
20
21 static gpointer setup_func(xmlNodePtr node)
22 {
23 xmlNodePtr n;
24 Options *o;
25
26 o = g_slice_new0(Options);
27 o->prompt = TRUE;
28
29 if ((n = obt_xml_find_node(node, "prompt")))
30 o->prompt = obt_xml_node_bool(n);
31
32 return o;
33 }
34
35 static void free_func(gpointer o)
36 {
37 g_slice_free(Options, o);
38 }
39
40 static void do_exit(void)
41 {
42 if (session_connected())
43 session_request_logout(FALSE);
44 else
45 ob_exit(0);
46 }
47
48 static gboolean prompt_cb(ObPrompt *p, gint result, gpointer data)
49 {
50 if (result)
51 do_exit();
52 return TRUE; /* call the cleanup func */
53 }
54
55 static void prompt_cleanup(ObPrompt *p, gpointer data)
56 {
57 prompt_unref(p);
58 }
59
60
61 /* Always return FALSE because its not interactive */
62 static gboolean run_func(ObActionsData *data, gpointer options)
63 {
64 Options *o = options;
65
66 if (o->prompt) {
67 ObPrompt *p;
68 ObPromptAnswer answers[] = {
69 { _("Cancel"), 0 },
70 { _("Exit"), 1 }
71 };
72
73 if (session_connected())
74 p = prompt_new(_("Are you sure you want to log out?"),
75 _("Log Out"),
76 answers, 2, 0, 0, prompt_cb, prompt_cleanup, NULL);
77 else
78 p = prompt_new(_("Are you sure you want to exit Openbox?"),
79 _("Exit Openbox"),
80 answers, 2, 0, 0, prompt_cb, prompt_cleanup, NULL);
81
82 prompt_show(p, NULL, FALSE);
83 }
84 else
85 do_exit();
86
87 return FALSE;
88 }
This page took 0.032459 seconds and 4 git commands to generate.