2 Handle events in application.
3 Interface functions: init/deinit; start/stop
5 Copyright (C) 2011 The Free Software Foundation, Inc.
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,
30 #include "lib/global.h"
31 #include "lib/event.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 /* --------------------------------------------------------------------------------------------- */
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")));
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")));
76 /* --------------------------------------------------------------------------------------------- */
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")));
89 g_tree_destroy (mc_event_grouplist
);
90 mc_event_grouplist
= NULL
;
94 /* --------------------------------------------------------------------------------------------- */
97 mc_event_mass_add (event_init_t
* events
, GError
** mcerror
)
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
))
113 /* --------------------------------------------------------------------------------------------- */
116 mc_event_present (const gchar
*event_group_name
, const gchar
*event_name
)
119 GPtrArray
*callbacks
;
121 if (mc_event_grouplist
== NULL
|| event_group_name
== NULL
|| event_name
== NULL
)
124 event_group
= mc_event_get_event_group_by_name (event_group_name
, FALSE
, NULL
);
125 if (event_group
== NULL
)
128 callbacks
= mc_event_get_event_by_name (event_group
, event_name
, FALSE
, NULL
);
129 if (callbacks
== NULL
)
135 /* --------------------------------------------------------------------------------------------- */