Ticket #2572: Patchfs with filenames containing whitespaces.
[midnight-commander.git] / lib / event / event.c
blob305ed0117ef4036e56747514cc0089b3b20c9f52
1 /*
2 Handle events in application.
3 Interface functions: init/deinit; start/stop
5 Copyright (C) 2011 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2011.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software; you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be
18 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 MA 02110-1301, USA.
28 #include <config.h>
30 #include "lib/global.h"
31 #include "lib/event.h"
33 #include "internal.h"
35 /*** global variables ****************************************************************************/
37 /*** file scope macro definitions ****************************************************************/
39 /*** file scope type declarations ****************************************************************/
41 /*** file scope variables ************************************************************************/
43 GTree *mc_event_grouplist = NULL;
45 /*** file scope functions ************************************************************************/
46 /* --------------------------------------------------------------------------------------------- */
47 /*** public functions ****************************************************************************/
48 /* --------------------------------------------------------------------------------------------- */
50 gboolean
51 mc_event_init (GError ** mcerror)
53 if (mc_event_grouplist != NULL)
55 g_propagate_error (mcerror,
56 g_error_new (MC_ERROR, 1,
57 _("Event system already initialized")));
58 return FALSE;
61 mc_event_grouplist =
62 g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp,
63 NULL, (GDestroyNotify) g_free, (GDestroyNotify) g_tree_destroy);
65 if (mc_event_grouplist == NULL)
67 g_propagate_error (mcerror,
68 g_error_new (MC_ERROR, 2,
69 _("Failed to initialize event system")));
70 return FALSE;
73 return TRUE;
76 /* --------------------------------------------------------------------------------------------- */
78 gboolean
79 mc_event_deinit (GError ** mcerror)
81 if (mc_event_grouplist == NULL)
83 g_propagate_error (mcerror,
84 g_error_new (MC_ERROR, 1,
85 _("Event system not initialized")));
86 return FALSE;
89 g_tree_destroy (mc_event_grouplist);
90 mc_event_grouplist = NULL;
91 return TRUE;
94 /* --------------------------------------------------------------------------------------------- */
96 gboolean
97 mc_event_mass_add (event_init_t * events, GError ** mcerror)
99 size_t array_index;
101 for (array_index = 0; events[array_index].event_group_name != NULL; array_index++)
103 if (!mc_event_add (events[array_index].event_group_name,
104 events[array_index].event_name,
105 events[array_index].cb, events[array_index].init_data, mcerror))
107 return FALSE;
110 return TRUE;
113 /* --------------------------------------------------------------------------------------------- */
115 gboolean
116 mc_event_present (const gchar *event_group_name, const gchar *event_name)
118 GTree *event_group;
119 GPtrArray *callbacks;
121 if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL)
122 return FALSE;
124 event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL);
125 if (event_group == NULL)
126 return FALSE;
128 callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL);
129 if (callbacks == NULL)
130 return FALSE;
132 return TRUE;
135 /* --------------------------------------------------------------------------------------------- */