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-2019
   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 /*** file scope variables ************************************************************************/
  37 
  38 /* --------------------------------------------------------------------------------------------- */
  39 /*** file scope functions ************************************************************************/
  40 /* --------------------------------------------------------------------------------------------- */
  41 
  42 static gchar *
  43 mc_config_normalize_before_save (const gchar * value)
     /* [previous][next][first][last][top][bottom][index][help]  */
  44 {
  45     GIConv conv;
  46     GString *buffer;
  47     gboolean ok;
  48 
  49     if (mc_global.utf8_display)
  50         return g_strdup (value);
  51 
  52     conv = str_crt_conv_to ("UTF-8");
  53     if (conv == INVALID_CONV)
  54         return g_strdup (value);
  55 
  56     buffer = g_string_new ("");
  57 
  58     ok = (str_convert (conv, value, buffer) != ESTR_FAILURE);
  59     str_close_conv (conv);
  60 
  61     if (!ok)
  62     {
  63         g_string_free (buffer, TRUE);
  64         return g_strdup (value);
  65     }
  66 
  67     return g_string_free (buffer, FALSE);
  68 }
  69 
  70 /* --------------------------------------------------------------------------------------------- */
  71 /*** public functions ****************************************************************************/
  72 /* --------------------------------------------------------------------------------------------- */
  73 
  74 void
  75 mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
  76                           const gchar * param, const gchar * value)
  77 {
  78     if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
  79         g_key_file_set_string (mc_config->handle, group, param, value);
  80 }
  81 
  82 /* --------------------------------------------------------------------------------------------- */
  83 
  84 void
  85 mc_config_set_string_raw_value (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
  86                                 const gchar * param, const gchar * value)
  87 {
  88     if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
  89         g_key_file_set_value (mc_config->handle, group, param, value);
  90 }
  91 
  92 /* --------------------------------------------------------------------------------------------- */
  93 
  94 void
  95 mc_config_set_string (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
  96                       const gchar * param, const gchar * value)
  97 {
  98     if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
  99     {
 100         gchar *buffer;
 101 
 102         buffer = mc_config_normalize_before_save (value);
 103         g_key_file_set_string (mc_config->handle, group, param, buffer);
 104         g_free (buffer);
 105     }
 106 }
 107 
 108 /* --------------------------------------------------------------------------------------------- */
 109 
 110 void
 111 mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 112                     const gchar * param, gboolean value)
 113 {
 114     if (mc_config != NULL && group != NULL && param != NULL)
 115         g_key_file_set_boolean (mc_config->handle, group, param, value);
 116 }
 117 
 118 /* --------------------------------------------------------------------------------------------- */
 119 
 120 void
 121 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]  */
 122 {
 123     if (mc_config != NULL && group != NULL && param != NULL)
 124         g_key_file_set_integer (mc_config->handle, group, param, value);
 125 }
 126 
 127 /* --------------------------------------------------------------------------------------------- */
 128 
 129 void
 130 mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 131                            const gchar * param, const gchar * const value[], gsize length)
 132 {
 133     if (mc_config != NULL && group != NULL && param != NULL && value != NULL && length != 0)
 134         g_key_file_set_string_list (mc_config->handle, group, param, value, length);
 135 }
 136 
 137 /* --------------------------------------------------------------------------------------------- */
 138 
 139 void
 140 mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 141                          const gchar * param, gboolean value[], gsize length)
 142 {
 143     if (mc_config != NULL && group != NULL && param != NULL && value != NULL && length != 0)
 144         g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
 145 }
 146 
 147 /* --------------------------------------------------------------------------------------------- */
 148 
 149 void
 150 mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
     /* [previous][next][first][last][top][bottom][index][help]  */
 151                         const gchar * param, int value[], gsize length)
 152 {
 153     if (mc_config != NULL && group != NULL && param != NULL && value != NULL && length != 0)
 154         g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
 155 }
 156 
 157 /* --------------------------------------------------------------------------------------------- */

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