root/lib/event/event.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. mc_event_init
  2. mc_event_deinit
  3. mc_event_mass_add
  4. mc_event_present

   1 /*
   2    Handle  events in application.
   3    Interface functions: init/deinit; start/stop
   4 
   5    Copyright (C) 2011-2019
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Slava Zanko <slavazanko@gmail.com>, 2011.
  10 
  11    This file is part of the Midnight Commander.
  12 
  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.
  17 
  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.
  22 
  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/>.
  25  */
  26 
  27 #include <config.h>
  28 
  29 #include "lib/global.h"
  30 #include "lib/util.h"
  31 #include "lib/event.h"
  32 
  33 #include "internal.h"
  34 
  35 /*** global variables ****************************************************************************/
  36 
  37 /*** file scope macro definitions ****************************************************************/
  38 
  39 /*** file scope type declarations ****************************************************************/
  40 
  41 /*** file scope variables ************************************************************************/
  42 
  43 GTree *mc_event_grouplist = NULL;
  44 
  45 /*** file scope functions ************************************************************************/
  46 /* --------------------------------------------------------------------------------------------- */
  47 /*** public functions ****************************************************************************/
  48 /* --------------------------------------------------------------------------------------------- */
  49 
  50 gboolean
  51 mc_event_init (GError ** mcerror)
     /* [previous][next][first][last][top][bottom][index][help]  */
  52 {
  53     mc_return_val_if_error (mcerror, FALSE);
  54 
  55     if (mc_event_grouplist != NULL)
  56     {
  57         mc_propagate_error (mcerror, 0, "%s", _("Event system already initialized"));
  58         return FALSE;
  59     }
  60 
  61     mc_event_grouplist =
  62         g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp,
  63                          NULL, (GDestroyNotify) g_free, (GDestroyNotify) g_tree_destroy);
  64 
  65     if (mc_event_grouplist == NULL)
  66     {
  67         mc_propagate_error (mcerror, 0, "%s", _("Failed to initialize event system"));
  68         return FALSE;
  69     }
  70 
  71     return TRUE;
  72 }
  73 
  74 /* --------------------------------------------------------------------------------------------- */
  75 
  76 gboolean
  77 mc_event_deinit (GError ** mcerror)
     /* [previous][next][first][last][top][bottom][index][help]  */
  78 {
  79     mc_return_val_if_error (mcerror, FALSE);
  80 
  81     if (mc_event_grouplist == NULL)
  82     {
  83         mc_propagate_error (mcerror, 0, "%s", _("Event system not initialized"));
  84         return FALSE;
  85     }
  86 
  87     g_tree_destroy (mc_event_grouplist);
  88     mc_event_grouplist = NULL;
  89     return TRUE;
  90 }
  91 
  92 /* --------------------------------------------------------------------------------------------- */
  93 
  94 gboolean
  95 mc_event_mass_add (const event_init_t * events, GError ** mcerror)
     /* [previous][next][first][last][top][bottom][index][help]  */
  96 {
  97     size_t array_index;
  98 
  99     mc_return_val_if_error (mcerror, FALSE);
 100 
 101     for (array_index = 0; events[array_index].event_group_name != NULL; array_index++)
 102     {
 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))
 106         {
 107             return FALSE;
 108         }
 109     }
 110     return TRUE;
 111 }
 112 
 113 /* --------------------------------------------------------------------------------------------- */
 114 
 115 gboolean
 116 mc_event_present (const gchar * event_group_name, const gchar * event_name)
     /* [previous][next][first][last][top][bottom][index][help]  */
 117 {
 118     GTree *event_group;
 119     GPtrArray *callbacks;
 120 
 121     if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL)
 122         return FALSE;
 123 
 124     event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL);
 125     if (event_group == NULL)
 126         return FALSE;
 127 
 128     callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL);
 129     if (callbacks == NULL)
 130         return FALSE;
 131 
 132     return TRUE;
 133 }
 134 
 135 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */