Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
/*
|
|
|
|
Handle events in application.
|
|
|
|
Interface functions: init/deinit; start/stop
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2011-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
|
|
|
|
Written by:
|
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011.
|
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
2011-10-15 14:56:47 +04:00
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
2014-07-15 16:53:06 +04:00
|
|
|
#include "lib/util.h"
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
#include "lib/event.h"
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
GTree *mc_event_grouplist = NULL;
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
gboolean
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_event_init (GError **mcerror)
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
{
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_val_if_error (mcerror, FALSE);
|
|
|
|
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
if (mc_event_grouplist != NULL)
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
mc_propagate_error (mcerror, 0, "%s", _("Event system already initialized"));
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mc_event_grouplist =
|
|
|
|
g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp,
|
|
|
|
NULL, (GDestroyNotify) g_free, (GDestroyNotify) g_tree_destroy);
|
|
|
|
|
|
|
|
if (mc_event_grouplist == NULL)
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
mc_propagate_error (mcerror, 0, "%s", _("Failed to initialize event system"));
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
gboolean
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_event_deinit (GError **mcerror)
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
{
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_val_if_error (mcerror, FALSE);
|
|
|
|
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
if (mc_event_grouplist == NULL)
|
|
|
|
{
|
2016-01-03 14:13:02 +03:00
|
|
|
mc_propagate_error (mcerror, 0, "%s", _("Event system not initialized"));
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_tree_destroy (mc_event_grouplist);
|
|
|
|
mc_event_grouplist = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
gboolean
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_event_mass_add (const event_init_t *events, GError **mcerror)
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
{
|
|
|
|
size_t array_index;
|
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_val_if_error (mcerror, FALSE);
|
|
|
|
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
for (array_index = 0; events[array_index].event_group_name != NULL; array_index++)
|
|
|
|
{
|
|
|
|
if (!mc_event_add (events[array_index].event_group_name,
|
|
|
|
events[array_index].event_name,
|
|
|
|
events[array_index].cb, events[array_index].init_data, mcerror))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
gboolean
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_event_present (const gchar *event_group_name, const gchar *event_name)
|
Added new engine for universal event system.
Example:
gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data)
{
... /* some action for handle event */
return TRUE; /* got chance to run other callbacks for this event or */
return FALSE; /* break execution for other callbacks */
}
mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL);
mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL);
/*
Last add - first run. In this case execution order is
* third_callback
* mkdir_log_callback
* mkdir_callback
if third_callback fuctions will return FALSE, then other callbacks
(mkdir_log_callback and mkdir_callback) never run!
*/
... /* some code */
/* for example, after pressing F7 */
mc_event_raise("filesystem", "mkdir", "some event_data... path to directory");
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2011-01-17 01:01:38 +03:00
|
|
|
{
|
|
|
|
GTree *event_group;
|
|
|
|
GPtrArray *callbacks;
|
|
|
|
|
|
|
|
if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL);
|
|
|
|
if (event_group == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL);
|
|
|
|
if (callbacks == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|