Implementation of getting last editing/viewing position of file.
[midnight-commander.git] / lib / event / event.c
blobdeba8a18bfa716c4693da3c0eabb66a4068434e7
1 /*
2 Handle events in application.
3 Interface functions: init/deinit; start/stop
5 Copyright (C) 2011
6 The 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/event.h"
32 #include "internal.h"
34 /*** global variables ****************************************************************************/
36 /*** file scope macro definitions ****************************************************************/
38 /*** file scope type declarations ****************************************************************/
40 /*** file scope variables ************************************************************************/
42 GTree *mc_event_grouplist = NULL;
44 /*** file scope functions ************************************************************************/
45 /* --------------------------------------------------------------------------------------------- */
46 /*** public functions ****************************************************************************/
47 /* --------------------------------------------------------------------------------------------- */
49 gboolean
50 mc_event_init (GError ** mcerror)
52 if (mc_event_grouplist != NULL)
54 g_propagate_error (mcerror,
55 g_error_new (MC_ERROR, 1, _("Event system already initialized")));
56 return FALSE;
59 mc_event_grouplist =
60 g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp,
61 NULL, (GDestroyNotify) g_free, (GDestroyNotify) g_tree_destroy);
63 if (mc_event_grouplist == NULL)
65 g_propagate_error (mcerror,
66 g_error_new (MC_ERROR, 2, _("Failed to initialize event system")));
67 return FALSE;
70 return TRUE;
73 /* --------------------------------------------------------------------------------------------- */
75 gboolean
76 mc_event_deinit (GError ** mcerror)
78 if (mc_event_grouplist == NULL)
80 g_propagate_error (mcerror, g_error_new (MC_ERROR, 1, _("Event system not initialized")));
81 return FALSE;
84 g_tree_destroy (mc_event_grouplist);
85 mc_event_grouplist = NULL;
86 return TRUE;
89 /* --------------------------------------------------------------------------------------------- */
91 gboolean
92 mc_event_mass_add (event_init_t * events, GError ** mcerror)
94 size_t array_index;
96 for (array_index = 0; events[array_index].event_group_name != NULL; array_index++)
98 if (!mc_event_add (events[array_index].event_group_name,
99 events[array_index].event_name,
100 events[array_index].cb, events[array_index].init_data, mcerror))
102 return FALSE;
105 return TRUE;
108 /* --------------------------------------------------------------------------------------------- */
110 gboolean
111 mc_event_present (const gchar * event_group_name, const gchar * event_name)
113 GTree *event_group;
114 GPtrArray *callbacks;
116 if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL)
117 return FALSE;
119 event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL);
120 if (event_group == NULL)
121 return FALSE;
123 callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL);
124 if (callbacks == NULL)
125 return FALSE;
127 return TRUE;
130 /* --------------------------------------------------------------------------------------------- */