diff --git a/configure.ac b/configure.ac index 691a7a916..0391aeb58 100644 --- a/configure.ac +++ b/configure.ac @@ -564,6 +564,7 @@ src/mcconfig/Makefile src/search/Makefile src/tty/Makefile src/viewer/Makefile +src/event/Makefile edit/Makefile syntax/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 969422cda..abb8a423e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = mcconfig search tty viewer filehighlight +SUBDIRS = mcconfig search tty viewer filehighlight event AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS) @@ -43,10 +43,11 @@ MCCONFIGLIB = mcconfig/libmcconfig.la SEARCHLIB = search/libsearch.la TTYLIB = tty/libmctty.la VIEWERLIB = viewer/libmcviewer.la +EVENTLIB = event/libmcevent.la FILEHIGHLIGHTLIB=filehighlight/libmcfilehighlight.la mc_LDADD = $(EDITLIB) $(VFSLIB) $(FILEHIGHLIGHTLIB) \ - $(MCCONFIGLIB) $(SEARCHLIB) $(TTYLIB) $(VIEWERLIB) \ + $(MCCONFIGLIB) $(SEARCHLIB) $(TTYLIB) $(VIEWERLIB) $(EVENTLIB)\ $(INTLLIBS) $(MCLIBS) $(SLANGLIB) $(LIBICONV) $(GLIB_LIBS) CHARSET_SRC = charsets.c charsets.h selcodepage.c selcodepage.h diff --git a/src/event/Makefile.am b/src/event/Makefile.am new file mode 100644 index 000000000..9171a07d6 --- /dev/null +++ b/src/event/Makefile.am @@ -0,0 +1,13 @@ + +noinst_LTLIBRARIES = libmcevent.la + +libmcevent_la_SOURCES = \ + callback.c \ + event.h \ + event.c \ + internal.h + +libmcevent_la_CFLAGS=-I../ -I$(top_srcdir)/src \ + $(GLIB_CFLAGS) \ + -DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\" + diff --git a/src/event/callback.c b/src/event/callback.c new file mode 100644 index 000000000..55507d1b2 --- /dev/null +++ b/src/event/callback.c @@ -0,0 +1,79 @@ +/* + Handle any events in application. + Interface functions: callbacks handle + + Copyright (C) 2009 The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2009. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include "event.h" +#include "internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mcevent_add_cb(const gchar *event_name , mcevent_callback_func event_callback, gpointer some_callback_data) +{ + mcevent_t *event; + + if (mcevent_hashlist == NULL || event_name == NULL || event_callback == NULL) + return FALSE; + + event = g_new0(mcevent_t, 1); + if (event == NULL) + return FALSE; + + event->name = g_strdup(event_name); + event->cb = event_callback; + event->data = some_callback_data; + + if (mcevent_get_handler(event_name) != NULL) + mcevent_del_cb(event_name); + + g_hash_table_insert (mcevent_hashlist, (gpointer) event_name, (gpointer) event); + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mcevent_del_cb(const gchar *event_name) +{ + if (mcevent_hashlist == NULL || event_name == NULL) + return FALSE; + + return g_hash_table_remove (mcevent_hashlist, (gpointer) event_name); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/event/event.c b/src/event/event.c new file mode 100644 index 000000000..c61c2754e --- /dev/null +++ b/src/event/event.c @@ -0,0 +1,140 @@ +/* + Handle any events in application. + Interface functions: init/deinit; start/stop + + Copyright (C) 2009 The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2009. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include "event.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +GHashTable *mcevent_hashlist = NULL; + + +/*** file scope functions ************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ + +static void +mcevent_hash_destroy_key (gpointer data) +{ +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +mcevent_hash_destroy_value (gpointer data) +{ + mcevent_t *event = (mcevent_t *) data; + g_free(event->name); + g_free (event); +} + +/* --------------------------------------------------------------------------------------------- */ + + +/*** public functions ****************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ + +gboolean mcevent_init(void) +{ + mcevent_hashlist = + g_hash_table_new_full (g_str_hash, g_str_equal, + mcevent_hash_destroy_key, + mcevent_hash_destroy_value); + if (mcevent_hashlist == NULL) + return FALSE; + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +void mcevent_deinit(void) +{ + if (mcevent_hashlist == NULL) + return; + + g_hash_table_destroy (mcevent_hashlist); + mcevent_hashlist = NULL; +} + +/* --------------------------------------------------------------------------------------------- */ + +void mcevent_run(void) +{ +/* start GMainLoop */ +} + +/* --------------------------------------------------------------------------------------------- */ + +void mcevent_stop(void) +{ +/* stop GMainLoop */ + +} + +/* --------------------------------------------------------------------------------------------- */ + +GList * +mcevent_get_list (void) +{ + if (mcevent_hashlist == NULL) + return NULL; + + return g_hash_table_get_keys (mcevent_hashlist); +} + +/* --------------------------------------------------------------------------------------------- */ + +mcevent_t * +mcevent_get_handler(const gchar *event_name) +{ + if (event_name == NULL || mcevent_hashlist == NULL) + return NULL; + + return (mcevent_t *) g_hash_table_lookup (mcevent_hashlist, (gpointer) event_name); +} + +/* --------------------------------------------------------------------------------------------- */ + +gboolean mcevent_raise(const gchar *event_name, gpointer event_data) +{ + mcevent_t *event = mcevent_get_handler(event_name); + + if (event == NULL) + return FALSE; + + return (*event->cb) (event, event_data); +} + +/* --------------------------------------------------------------------------------------------- */ + diff --git a/src/event/event.h b/src/event/event.h new file mode 100644 index 000000000..54885f4a6 --- /dev/null +++ b/src/event/event.h @@ -0,0 +1,48 @@ +#ifndef MC__EVENT_H +#define MC__EVENT_H + +#include + +#include "../src/global.h" /* */ + + +/*** typedefs(not structures) and defined constants **********************************************/ +struct mcevent_struct; + + +typedef gboolean (*mcevent_callback_func) (struct mcevent_struct *, gpointer); + + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +typedef struct mcevent_struct +{ + gchar *name; + mcevent_callback_func cb; + gpointer data; +} mcevent_t; + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + + +/* event.c: */ +gboolean mcevent_init(void); +void mcevent_deinit(void); +void mcevent_run(void); +void mcevent_stop(void); + +GList *mcevent_get_list (void); +mcevent_t *mcevent_get_handler(const gchar *); +gboolean mcevent_raise(const gchar *, gpointer); + + +/* callback.c: */ +gboolean mcevent_add_cb(const gchar *, mcevent_callback_func, gpointer); +gboolean mcevent_del_cb(const gchar *); + + +#endif diff --git a/src/event/internal.h b/src/event/internal.h new file mode 100644 index 000000000..f57eeb1f7 --- /dev/null +++ b/src/event/internal.h @@ -0,0 +1,16 @@ +#ifndef MC_EVENT_INTERNAL_H +#define MC_EVENT_INTERNAL_H + +/*** typedefs(not structures) and defined constants ********************/ + +/*** enums *************************************************************/ + +/*** structures declarations (and typedefs of structures)***************/ + +/*** global variables defined in .c file *******************************/ + +extern GHashTable *mcevent_hashlist; + +/*** declarations of public functions **********************************/ + +#endif