Moved dir $(srcdir)/syntax into $(srcdir)/misc/syntax
[midnight-commander.git] / src / mcconfig / set.c
blob5994125d5d64ce78ead8f7f66f7b55e6b8c4c9a1
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 "global.h"
24 #include "mcconfig.h"
25 #include "../src/strutil.h"
27 /*** global variables **************************************************/
29 extern int utf8_display;
31 /*** file scope macro definitions **************************************/
33 /*** file scope type declarations **************************************/
35 /*** file scope variables **********************************************/
37 /*** file scope functions **********************************************/
38 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
40 static gchar *
41 mc_config_normalize_before_save(const gchar * value)
43 GIConv conv;
44 GString *buffer;
46 if (utf8_display)
48 buffer = g_string_new(value);
50 else
52 conv = str_crt_conv_to ("UTF-8");
53 if (conv == INVALID_CONV)
54 return g_strdup(value);
56 buffer = g_string_new ("");
58 if (str_convert (conv, value, buffer) == ESTR_FAILURE)
60 g_string_free(buffer, TRUE);
61 buffer = g_string_new(value);
64 str_close_conv (conv);
67 return g_string_free(buffer, FALSE);
70 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
71 /*** public functions **************************************************/
72 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
74 void
75 mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
76 const gchar * param, const gchar * value)
78 gchar *buffer;
80 if (!mc_config || !group || !param || !value)
81 return;
83 buffer = mc_config_normalize_before_save(value);
85 g_key_file_set_value (mc_config->handle, group, param, buffer);
87 g_free(buffer);
90 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
92 void
93 mc_config_set_string (mc_config_t * mc_config, const gchar * group,
94 const gchar * param, const gchar * value)
96 gchar *buffer;
98 if (!mc_config || !group || !param || !value)
99 return;
101 buffer = mc_config_normalize_before_save(value);
103 g_key_file_set_string (mc_config->handle, group, param, buffer);
105 g_free(buffer);
108 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
110 void
111 mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
112 const gchar * param, gboolean value)
114 if (!mc_config || !group || !param )
115 return;
117 g_key_file_set_boolean (mc_config->handle, group, param, value);
120 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
122 void
123 mc_config_set_int (mc_config_t * mc_config, const gchar * group,
124 const gchar * param, int value)
126 if (!mc_config || !group || !param )
127 return;
129 g_key_file_set_integer (mc_config->handle, group, param, value);
132 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
133 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
135 void
136 mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
137 const gchar * param, const gchar * const value[],
138 gsize length)
140 if (!mc_config || !group || !param || !value || length == 0)
141 return;
143 g_key_file_set_string_list (mc_config->handle, group, param, value,
144 length);
147 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
150 void
151 mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
152 const gchar * param, gboolean value[], gsize length)
154 if (!mc_config || !group || !param || !value || length == 0)
155 return;
157 g_key_file_set_boolean_list (mc_config->handle, group, param, value,
158 length);
161 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
163 void
164 mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
165 const gchar * param, int value[], gsize length)
167 if (!mc_config || !group || !param || !value || length == 0)
168 return;
170 g_key_file_set_integer_list (mc_config->handle, group, param, value,
171 length);
174 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */