]> Dogcows Code - chaz/openbox/blob - openbox/actions.c
dont build the old action stuff.
[chaz/openbox] / openbox / actions.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 actions.h for the Openbox window manager
4 Copyright (c) 2007 Dana Jansens
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "actions.h"
20 #include "gettext.h"
21
22 static void actions_definition_ref(ObActionsDefinition *def);
23 static void actions_definition_unref(ObActionsDefinition *def);
24
25 struct _ObActionsDefinition {
26 guint ref;
27
28 gchar *name;
29 gboolean allow_interactive;
30
31 ObActionsDataSetupFunc setup;
32 ObActionsDataFreeFunc free;
33 ObActionsRunFunc run;
34 };
35
36 struct _ObActionsAct {
37 guint ref;
38
39 ObActionsDefinition *def;
40
41 gpointer options;
42 };
43
44 static GSList *registered = NULL;
45
46
47 void actions_startup(gboolean reconfig)
48 {
49 if (reconfig) return;
50
51
52 }
53
54 void actions_shutdown(gboolean reconfig)
55 {
56 if (reconfig) return;
57
58 /* free all the registered actions */
59 while (registered) {
60 actions_definition_unref(registered->data);
61 registered = g_slist_delete_link(registered, registered);
62 }
63 }
64
65 gboolean actions_register(const gchar *name,
66 gboolean allow_interactive,
67 ObActionsDataSetupFunc setup,
68 ObActionsDataFreeFunc free,
69 ObActionsRunFunc run)
70 {
71 GSList *it;
72 ObActionsDefinition *def;
73
74 for (it = registered; it; it = g_slist_next(it)) {
75 def = it->data;
76 if (!g_ascii_strcasecmp(name, def->name)) /* already registered */
77 return FALSE;
78 }
79
80 def = g_new(ObActionsDefinition, 1);
81 def->ref = 1;
82 def->name = g_strdup(name);
83 def->allow_interactive = allow_interactive;
84 def->setup = setup;
85 def->free = free;
86 def->run = run;
87 return TRUE;
88 }
89
90 static void actions_definition_ref(ObActionsDefinition *def)
91 {
92 ++def->ref;
93 }
94
95 static void actions_definition_unref(ObActionsDefinition *def)
96 {
97 if (def && --def->ref == 0) {
98 g_free(def->name);
99 g_free(def);
100 }
101 }
102
103 ObActionsAct* actions_parse_string(const gchar *name)
104 {
105 GSList *it;
106 ObActionsDefinition *def;
107 ObActionsAct *act = NULL;
108
109 /* find the requested action */
110 for (it = registered; it; it = g_slist_next(it)) {
111 def = it->data;
112 if (!g_ascii_strcasecmp(name, def->name))
113 break;
114 def = NULL;
115 }
116
117 /* if we found the action */
118 if (def) {
119 act = g_new(ObActionsAct, 1);
120 act->ref = 1;
121 act->def = def;
122 actions_definition_ref(act->def);
123 act->options = NULL;
124 } else
125 g_message(_("Invalid action '%s' requested. No such action exists."),
126 name);
127
128 return act;
129 }
130
131 ObActionsAct* actions_parse(ObParseInst *i,
132 xmlDocPtr doc,
133 xmlNodePtr node)
134 {
135 gchar *name;
136 ObActionsAct *act = NULL;
137
138 if (parse_attr_string("name", node, &name)) {
139 if ((act = actions_parse_string(name)))
140 /* there is more stuff to parse here */
141 act->options = act->def->setup(i, doc, node->children);
142
143 g_free(name);
144 }
145
146 return act;
147 }
148
149 void actions_act_ref(ObActionsAct *act)
150 {
151 ++act->ref;
152 }
153
154 void actions_act_unref(ObActionsAct *act)
155 {
156 if (act && --act->ref == 0) {
157 /* free the action specific options */
158 act->def->free(act->options);
159 /* unref the definition */
160 actions_definition_unref(act->def);
161 g_free(act);
162 }
163 }
This page took 0.047316 seconds and 5 git commands to generate.