root/lib/mcconfig/set.c

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

DEFINITIONS

This source file includes following definitions.
  1. mc_config_normalize_before_save
  2. mc_config_set_string_raw
  3. mc_config_set_string_raw_value
  4. mc_config_set_string
  5. mc_config_set_bool
  6. mc_config_set_int
  7. mc_config_set_string_list
  8. mc_config_set_bool_list
  9. mc_config_set_int_list

   1 /*
   2    Configure module for the Midnight Commander
   3 
   4    Copyright (C) 1994-2024
   5    Free Software Foundation, Inc.
   6 
   7    This file is part of the Midnight Commander.
   8 
   9    The Midnight Commander is free software: you can redistribute it
  10    and/or modify it under the terms of the GNU General Public License as
  11    published by the Free Software Foundation, either version 3 of the License,
  12    or (at your option) any later version.
  13 
  14    The Midnight Commander is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18 
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21  */
  22 
  23 #include <config.h>
  24 
  25 #include "lib/global.h"
  26 #include "lib/strutil.h"
  27 
  28 #include "lib/mcconfig.h"
  29 
  30 /*** global variables ****************************************************************************/
  31 
  32 /*** file scope macro definitions ****************************************************************/
  33 
  34 /*** file scope type declarations ****************************************************************/
  35 
  36 /*** forward declarations (file scope functions) *************************************************/
  37 
  38 /*** file scope variables ************************************************************************/
  39 
  40 /* --------------------------------------------------------------------------------------------- */
  41 /*** file scope functions ************************************************************************/
  42 /* --------------------------------------------------------------------------------------------- */
  43 
  44 static gchar *
  45 mc_config_normalize_before_save (const gchar * value)
     /* [previous][next][first][last][top][bottom][index][help]  */
  46 {
  47     GIConv conv;
  48     GString *buffer;
  49     gboolean ok;
  50 
  51     if (mc_global.utf8_display)
  52         return g_strdup (value);
  53 
  54     conv = str_crt_conv_to ("UTF-8");
  55     if (conv == INVALID_CONV)
  56         return g_strdup (value);
  57 
  58     buffer = g_string_new ("");
  59 
  60     ok = (str_convert (conv, value, buffer) != ESTR_FAILURE);
  61     str_close_conv (conv);
  62 
  63     if (!ok)
  64     {
  65         g_string_free (buffer, TRUE);
  66         return g_strdup (value);
  67     }
  68 
  69     return g_string_free (buffer, FALSE);
  70 }
  71 
  72 /* --------------------------------------------------------------------------------------------- */
  73 /*** public functions ****************************************************************************/
  74 /* --------------------------------------------------------------------------------------------- */
  75 
  76 void
  77 mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
  78                           const gchar * param, const gchar * value)
  79 {
  80     if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
  81         g_key_file_set_string (mc_config->handle, group, param, value);
  82 }
  83 
  84 /* --------------------------------------------------------------------------------------------- */
  85 
  86 void
  87 mc_config_set_string_raw_value (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
  88                                 const gchar * param, const gchar * value)
  89 {
  90     if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
  91         g_key_file_set_value (mc_config->handle, group, param, value);
  92 }
  93 
  94 /* --------------------------------------------------------------------------------------------- */
  95 
  96 void
  97 mc_config_set_string (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
  98                       const gchar * param, const gchar * value)
  99 {
 100     if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
 101     {
 102         gchar *buffer;
 103 
 104         buffer = mc_config_normalize_before_save (value);
 105         g_key_file_set_string (mc_config->handle, group, param, buffer);
 106         g_free (buffer);
 107     }
 108 }
 109 
 110 /* --------------------------------------------------------------------------------------------- */
 111 
 112 void
 113 mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 114                     const gchar * param, gboolean value)
 115 {
 116     if (mc_config != NULL && group != NULL && param != NULL)
 117         g_key_file_set_boolean (mc_config->handle, group, param, value);
 118 }
 119 
 120 /* --------------------------------------------------------------------------------------------- */
 121 
 122 void
 123 mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
     /* [previous][next][first][last][top][bottom][index][help]  */
 124 {
 125     if (mc_config != NULL && group != NULL && param != NULL)
 126         g_key_file_set_integer (mc_config->handle, group, param, value);
 127 }
 128 
 129 /* --------------------------------------------------------------------------------------------- */
 130 
 131 void
 132 mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 133                            const gchar * param, const gchar * const value[], gsize length)
 134 {
 135     if (mc_config != NULL && group != NULL && param != NULL && value != NULL && length != 0)
 136         g_key_file_set_string_list (mc_config->handle, group, param, value, length);
 137 }
 138 
 139 /* --------------------------------------------------------------------------------------------- */
 140 
 141 void
 142 mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 143                          const gchar * param, gboolean value[], gsize length)
 144 {
 145     if (mc_config != NULL && group != NULL && param != NULL && value != NULL && length != 0)
 146         g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
 147 }
 148 
 149 /* --------------------------------------------------------------------------------------------- */
 150 
 151 void
 152 mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 153                         const gchar * param, int value[], gsize length)
 154 {
 155     if (mc_config != NULL && group != NULL && param != NULL && value != NULL && length != 0)
 156         g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
 157 }
 158 
 159 /* --------------------------------------------------------------------------------------------- */

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