2 Handle events in application.
3 Interface functions: init/deinit; start/stop
5 Copyright (C) 2011-2016
6 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"
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 mc_return_val_if_error (mcerror
, FALSE
);
55 if (mc_event_grouplist
!= NULL
)
57 mc_propagate_error (mcerror
, 0, "%s", _("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 mc_propagate_error (mcerror
, 0, "%s", _("Failed to initialize event system"));
74 /* --------------------------------------------------------------------------------------------- */
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"));
87 g_tree_destroy (mc_event_grouplist
);
88 mc_event_grouplist
= NULL
;
92 /* --------------------------------------------------------------------------------------------- */
95 mc_event_mass_add (event_init_t
* events
, GError
** mcerror
)
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
))
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 /* --------------------------------------------------------------------------------------------- */