Ticket #121: Fixed IPV4 FTP connection scheme
[midnight-commander.git] / lib / mcconfig / set.c
blobdaa2f70255a6b9978d9fbafd282571aa6c8b69e1
1 /* Configure module for the Midnight Commander
2 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <config.h>
22 #include "lib/global.h"
23 #include "lib/strutil.h"
24 #include "lib/mcconfig.h"
26 /*** global variables **************************************************/
28 extern int utf8_display;
30 /*** file scope macro definitions **************************************/
32 /*** file scope type declarations **************************************/
34 /*** file scope variables **********************************************/
36 /*** file scope functions **********************************************/
37 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39 static gchar *
40 mc_config_normalize_before_save(const gchar * value)
42 GIConv conv;
43 GString *buffer;
45 if (utf8_display)
47 buffer = g_string_new(value);
49 else
51 conv = str_crt_conv_to ("UTF-8");
52 if (conv == INVALID_CONV)
53 return g_strdup(value);
55 buffer = g_string_new ("");
57 if (str_convert (conv, value, buffer) == ESTR_FAILURE)
59 g_string_free(buffer, TRUE);
60 buffer = g_string_new(value);
63 str_close_conv (conv);
66 return g_string_free(buffer, FALSE);
69 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
70 /*** public functions **************************************************/
71 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
73 void
74 mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
75 const gchar * param, const gchar * value)
77 gchar *buffer;
79 if (!mc_config || !group || !param || !value)
80 return;
82 buffer = mc_config_normalize_before_save(value);
84 g_key_file_set_value (mc_config->handle, group, param, buffer);
86 g_free(buffer);
89 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
91 void
92 mc_config_set_string (mc_config_t * mc_config, const gchar * group,
93 const gchar * param, const gchar * value)
95 gchar *buffer;
97 if (!mc_config || !group || !param || !value)
98 return;
100 buffer = mc_config_normalize_before_save(value);
102 g_key_file_set_string (mc_config->handle, group, param, buffer);
104 g_free(buffer);
107 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
109 void
110 mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
111 const gchar * param, gboolean value)
113 if (!mc_config || !group || !param )
114 return;
116 g_key_file_set_boolean (mc_config->handle, group, param, value);
119 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
121 void
122 mc_config_set_int (mc_config_t * mc_config, const gchar * group,
123 const gchar * param, int value)
125 if (!mc_config || !group || !param )
126 return;
128 g_key_file_set_integer (mc_config->handle, group, param, value);
131 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
132 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
134 void
135 mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
136 const gchar * param, const gchar * const value[],
137 gsize length)
139 if (!mc_config || !group || !param || !value || length == 0)
140 return;
142 g_key_file_set_string_list (mc_config->handle, group, param, value,
143 length);
146 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
149 void
150 mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
151 const gchar * param, gboolean value[], gsize length)
153 if (!mc_config || !group || !param || !value || length == 0)
154 return;
156 g_key_file_set_boolean_list (mc_config->handle, group, param, value,
157 length);
160 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
162 void
163 mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
164 const gchar * param, int value[], gsize length)
166 if (!mc_config || !group || !param || !value || length == 0)
167 return;
169 g_key_file_set_integer_list (mc_config->handle, group, param, value,
170 length);
173 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */