2 Handle events in application.
3 Interface functions: init/deinit; start/stop
6 The Free Software Foundation, Inc.
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/>.
29 #include "lib/global.h"
30 #include "lib/event.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 /* --------------------------------------------------------------------------------------------- */
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")));
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")));
73 /* --------------------------------------------------------------------------------------------- */
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")));
84 g_tree_destroy (mc_event_grouplist
);
85 mc_event_grouplist
= NULL
;
89 /* --------------------------------------------------------------------------------------------- */
92 mc_event_mass_add (event_init_t
* events
, GError
** mcerror
)
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
))
108 /* --------------------------------------------------------------------------------------------- */
111 mc_event_present (const gchar
* event_group_name
, const gchar
* event_name
)
114 GPtrArray
*callbacks
;
116 if (mc_event_grouplist
== NULL
|| event_group_name
== NULL
|| event_name
== NULL
)
119 event_group
= mc_event_get_event_group_by_name (event_group_name
, FALSE
, NULL
);
120 if (event_group
== NULL
)
123 callbacks
= mc_event_get_event_by_name (event_group
, event_name
, FALSE
, NULL
);
124 if (callbacks
== NULL
)
130 /* --------------------------------------------------------------------------------------------- */