some first structural stuff for new actions
[mikachu/openbox.git] / 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
21 static void actions_unregister(ObActionsDefinition *def);
22
23 struct _ObActionsDefinition {
24     gchar *name;
25     gboolean interactive;
26
27     ObActionsDataParseFunc parse;
28     ObActionsDataFreeFunc free;
29     ObActionsRunFunc run;
30
31     gpointer action_data;
32 };
33
34 static GSList *registered = NULL;
35
36
37 void actions_startup(gboolean reconfig)
38 {
39     if (reconfig) return;
40
41     
42 }
43
44 void actions_shutdown(gboolean reconfig)
45 {
46     if (reconfig) return;
47
48     /* free all the registered actions */
49     while (registered) {
50         actions_unregister(registered->data);
51         registered = g_slist_delete_link(registered, registered);
52     }
53 }
54
55 gboolean actions_register(const gchar *name,
56                           gboolean interactive,
57                           ObActionsDataSetupFunc setup,
58                           ObActionsDataParseFunc parse,
59                           ObActionsDataFreeFunc free,
60                           ObActionsRunFunc run)
61 {
62     GSList *it;
63     ObActionsDefinition *def;
64
65     for (it = registered; it; it = g_slist_next(it)) {
66         def = it->data;
67         if (!g_ascii_strcasecmp(name, def->name)) /* already registered */
68             return FALSE;
69     }
70
71     def = g_new(ObActionsDefinition, 1);
72     def->name = g_strdup(name);
73     def->interactive = interactive;
74     def->parse = parse;
75     def->free = free;
76     def->run = run;
77     def->action_data = setup();
78     return TRUE;
79 }
80
81 static void actions_unregister(ObActionsDefinition *def)
82 {
83     if (def) {
84         def->free(def->action_data);
85         g_free(def->name);
86         g_free(def);
87     }
88 }