Merge branch '3729_vfs_date_fixes'
[midnight-commander.git] / lib / event / event.c
blob4f4b83077241b0e64fa0a9deade3ed18939af2c8
1 /*
2 Handle events in application.
3 Interface functions: init/deinit; start/stop
5 Copyright (C) 2011-2016
6 Free Software Foundation, Inc.
8 Written by:
9 Slava Zanko <slavazanko@gmail.com>, 2011.
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <config.h>
29 #include "lib/global.h"
30 #include "lib/util.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 mc_return_val_if_error (mcerror, FALSE);
55 if (mc_event_grouplist != NULL)
57 mc_propagate_error (mcerror, 0, "%s", _("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 mc_propagate_error (mcerror, 0, "%s", _("Failed to initialize event system"));
68 return FALSE;
71 return TRUE;
74 /* --------------------------------------------------------------------------------------------- */
76 gboolean
77 mc_event_deinit (GError ** mcerror)
79 mc_return_val_if_error (mcerror, FALSE);
81 if (mc_event_grouplist == NULL)
83 mc_propagate_error (mcerror, 0, "%s", _("Event system not initialized"));
84 return FALSE;
87 g_tree_destroy (mc_event_grouplist);
88 mc_event_grouplist = NULL;
89 return TRUE;
92 /* --------------------------------------------------------------------------------------------- */
94 gboolean
95 mc_event_mass_add (event_init_t * events, GError ** mcerror)
97 size_t array_index;
99 mc_return_val_if_error (mcerror, FALSE);
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 /* --------------------------------------------------------------------------------------------- */