set.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. Configure module for the Midnight Commander
  3. Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
  4. 2007, 2009, 2011
  5. The Free Software Foundation, Inc.
  6. This file is part of the Midnight Commander.
  7. The Midnight Commander is free software: you can redistribute it
  8. and/or modify it under the terms of the GNU General Public License as
  9. published by the Free Software Foundation, either version 3 of the License,
  10. or (at your option) any later version.
  11. The Midnight Commander is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. 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, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <config.h>
  19. #include "lib/global.h"
  20. #include "lib/strutil.h"
  21. #include "lib/mcconfig.h"
  22. /*** global variables **************************************************/
  23. /*** file scope macro definitions **************************************/
  24. /*** file scope type declarations **************************************/
  25. /*** file scope variables **********************************************/
  26. /*** file scope functions **********************************************/
  27. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  28. static gchar *
  29. mc_config_normalize_before_save (const gchar * value)
  30. {
  31. GIConv conv;
  32. GString *buffer;
  33. if (mc_global.utf8_display)
  34. return g_strdup (value);
  35. conv = str_crt_conv_to ("UTF-8");
  36. if (conv == INVALID_CONV)
  37. return g_strdup (value);
  38. buffer = g_string_new ("");
  39. if (str_convert (conv, value, buffer) == ESTR_FAILURE)
  40. {
  41. g_string_free (buffer, TRUE);
  42. return g_strdup (value);
  43. }
  44. str_close_conv (conv);
  45. return g_string_free (buffer, FALSE);
  46. }
  47. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  48. /*** public functions **************************************************/
  49. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  50. void
  51. mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
  52. const gchar * param, const gchar * value)
  53. {
  54. if (!mc_config || !group || !param || !value)
  55. return;
  56. g_key_file_set_string (mc_config->handle, group, param, value);
  57. }
  58. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  59. void
  60. mc_config_set_string (const mc_config_t * mc_config, const gchar * group,
  61. const gchar * param, const gchar * value)
  62. {
  63. gchar *buffer;
  64. if (!mc_config || !group || !param || !value)
  65. return;
  66. buffer = mc_config_normalize_before_save (value);
  67. g_key_file_set_string (mc_config->handle, group, param, buffer);
  68. g_free (buffer);
  69. }
  70. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  71. void
  72. mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
  73. const gchar * param, gboolean value)
  74. {
  75. if (!mc_config || !group || !param)
  76. return;
  77. g_key_file_set_boolean (mc_config->handle, group, param, value);
  78. }
  79. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  80. void
  81. mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
  82. {
  83. if (!mc_config || !group || !param)
  84. return;
  85. g_key_file_set_integer (mc_config->handle, group, param, value);
  86. }
  87. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  88. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  89. void
  90. mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
  91. const gchar * param, const gchar * const value[], gsize length)
  92. {
  93. if (!mc_config || !group || !param || !value || length == 0)
  94. return;
  95. g_key_file_set_string_list (mc_config->handle, group, param, value, length);
  96. }
  97. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  98. void
  99. mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
  100. const gchar * param, gboolean value[], gsize length)
  101. {
  102. if (!mc_config || !group || !param || !value || length == 0)
  103. return;
  104. g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
  105. }
  106. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  107. void
  108. mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
  109. const gchar * param, int value[], gsize length)
  110. {
  111. if (!mc_config || !group || !param || !value || length == 0)
  112. return;
  113. g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
  114. }
  115. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */