Ticket 1551: Update GPL version from 2 to 3
[midnight-commander.git] / lib / mcconfig / set.c
blob9678d28af33acbcbdd28184d5e7bbcde2a8fbcb9
1 /*
2 Configure module for the Midnight Commander
4 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
5 2007, 2009, 2011
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <config.h>
26 #include "lib/global.h"
27 #include "lib/strutil.h"
28 #include "lib/mcconfig.h"
30 /*** global variables **************************************************/
32 /*** file scope macro definitions **************************************/
34 /*** file scope type declarations **************************************/
36 /*** file scope variables **********************************************/
38 /*** file scope functions **********************************************/
39 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41 static gchar *
42 mc_config_normalize_before_save (const gchar * value)
44 GIConv conv;
45 GString *buffer;
47 if (mc_global.utf8_display)
48 return g_strdup (value);
50 conv = str_crt_conv_to ("UTF-8");
51 if (conv == INVALID_CONV)
52 return g_strdup (value);
54 buffer = g_string_new ("");
56 if (str_convert (conv, value, buffer) == ESTR_FAILURE)
58 g_string_free (buffer, TRUE);
59 return g_strdup (value);
62 str_close_conv (conv);
63 return g_string_free (buffer, FALSE);
66 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
67 /*** public functions **************************************************/
68 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
70 void
71 mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
72 const gchar * param, const gchar * value)
74 if (!mc_config || !group || !param || !value)
75 return;
77 g_key_file_set_string (mc_config->handle, group, param, value);
80 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
82 void
83 mc_config_set_string (const mc_config_t * mc_config, const gchar * group,
84 const gchar * param, const gchar * value)
86 gchar *buffer;
88 if (!mc_config || !group || !param || !value)
89 return;
91 buffer = mc_config_normalize_before_save (value);
93 g_key_file_set_string (mc_config->handle, group, param, buffer);
95 g_free (buffer);
98 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
100 void
101 mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
102 const gchar * param, gboolean value)
104 if (!mc_config || !group || !param)
105 return;
107 g_key_file_set_boolean (mc_config->handle, group, param, value);
110 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
112 void
113 mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
115 if (!mc_config || !group || !param)
116 return;
118 g_key_file_set_integer (mc_config->handle, group, param, value);
121 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
122 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
124 void
125 mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
126 const gchar * param, const gchar * const value[], gsize length)
128 if (!mc_config || !group || !param || !value || length == 0)
129 return;
131 g_key_file_set_string_list (mc_config->handle, group, param, value, length);
134 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
137 void
138 mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
139 const gchar * param, gboolean value[], gsize length)
141 if (!mc_config || !group || !param || !value || length == 0)
142 return;
144 g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
147 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
149 void
150 mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
151 const gchar * param, int value[], gsize length)
153 if (!mc_config || !group || !param || !value || length == 0)
154 return;
156 g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
159 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */