Don't focus widget that doesn't have the WOP_SELECTABLE option.
[midnight-commander.git] / lib / mcconfig / set.c
blob0c79448b0bd6e9957aa00d878fee74d61e077f50
1 /*
2 Configure module for the Midnight Commander
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
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.
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.
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/>.
23 #include <config.h>
25 #include "lib/global.h"
26 #include "lib/strutil.h"
27 #include "lib/mcconfig.h"
29 /*** global variables **************************************************/
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;
45 gboolean ok;
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 ok = (str_convert (conv, value, buffer) != ESTR_FAILURE);
57 str_close_conv (conv);
59 if (!ok)
61 g_string_free (buffer, TRUE);
62 return g_strdup (value);
65 return g_string_free (buffer, FALSE);
68 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
69 /*** public functions **************************************************/
70 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
72 void
73 mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
74 const gchar * param, const gchar * value)
76 if (!mc_config || !group || !param || !value)
77 return;
79 g_key_file_set_string (mc_config->handle, group, param, value);
82 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
84 void
85 mc_config_set_string_raw_value (mc_config_t * mc_config, const gchar * group,
86 const gchar * param, const gchar * value)
88 if (!mc_config || !group || !param || !value)
89 return;
91 g_key_file_set_value (mc_config->handle, group, param, value);
94 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
96 void
97 mc_config_set_string (const mc_config_t * mc_config, const gchar * group,
98 const gchar * param, const gchar * value)
100 gchar *buffer;
102 if (!mc_config || !group || !param || !value)
103 return;
105 buffer = mc_config_normalize_before_save (value);
107 g_key_file_set_string (mc_config->handle, group, param, buffer);
109 g_free (buffer);
112 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
114 void
115 mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
116 const gchar * param, gboolean value)
118 if (!mc_config || !group || !param)
119 return;
121 g_key_file_set_boolean (mc_config->handle, group, param, value);
124 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
126 void
127 mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
129 if (!mc_config || !group || !param)
130 return;
132 g_key_file_set_integer (mc_config->handle, group, param, value);
135 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
136 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
138 void
139 mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
140 const gchar * param, const gchar * const value[], gsize length)
142 if (!mc_config || !group || !param || !value || length == 0)
143 return;
145 g_key_file_set_string_list (mc_config->handle, group, param, value, length);
148 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
151 void
152 mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
153 const gchar * param, gboolean value[], gsize length)
155 if (!mc_config || !group || !param || !value || length == 0)
156 return;
158 g_key_file_set_boolean_list (mc_config->handle, group, param, value, 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, length);
173 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */