set.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. */
  16. #include <config.h>
  17. #include "lib/global.h"
  18. #include "lib/strutil.h"
  19. #include "lib/mcconfig.h"
  20. /*** global variables **************************************************/
  21. extern int utf8_display;
  22. /*** file scope macro definitions **************************************/
  23. /*** file scope type declarations **************************************/
  24. /*** file scope variables **********************************************/
  25. /*** file scope functions **********************************************/
  26. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  27. static gchar *
  28. mc_config_normalize_before_save (const gchar * value)
  29. {
  30. GIConv conv;
  31. GString *buffer;
  32. if (utf8_display)
  33. return g_strdup (value);
  34. conv = str_crt_conv_to ("UTF-8");
  35. if (conv == INVALID_CONV)
  36. return g_strdup (value);
  37. buffer = g_string_new ("");
  38. if (str_convert (conv, value, buffer) == ESTR_FAILURE)
  39. {
  40. g_string_free (buffer, TRUE);
  41. return g_strdup (value);
  42. }
  43. str_close_conv (conv);
  44. return g_string_free (buffer, FALSE);
  45. }
  46. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  47. /*** public functions **************************************************/
  48. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  49. void
  50. mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
  51. const gchar * param, const gchar * value)
  52. {
  53. if (!mc_config || !group || !param || !value)
  54. return;
  55. g_key_file_set_string (mc_config->handle, group, param, value);
  56. }
  57. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  58. void
  59. mc_config_set_string_raw_value (mc_config_t * mc_config, const gchar * group,
  60. const gchar * param, const gchar * value)
  61. {
  62. if (!mc_config || !group || !param || !value)
  63. return;
  64. g_key_file_set_value (mc_config->handle, group, param, value);
  65. }
  66. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  67. void
  68. mc_config_set_string (mc_config_t * mc_config, const gchar * group,
  69. const gchar * param, const gchar * value)
  70. {
  71. gchar *buffer;
  72. if (!mc_config || !group || !param || !value)
  73. return;
  74. buffer = mc_config_normalize_before_save (value);
  75. g_key_file_set_string (mc_config->handle, group, param, buffer);
  76. g_free (buffer);
  77. }
  78. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  79. void
  80. mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
  81. const gchar * param, gboolean value)
  82. {
  83. if (!mc_config || !group || !param)
  84. return;
  85. g_key_file_set_boolean (mc_config->handle, group, param, value);
  86. }
  87. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  88. void
  89. mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
  90. {
  91. if (!mc_config || !group || !param)
  92. return;
  93. g_key_file_set_integer (mc_config->handle, group, param, value);
  94. }
  95. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  96. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  97. void
  98. mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
  99. const gchar * param, const gchar * const value[], gsize length)
  100. {
  101. if (!mc_config || !group || !param || !value || length == 0)
  102. return;
  103. g_key_file_set_string_list (mc_config->handle, group, param, value, length);
  104. }
  105. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  106. void
  107. mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
  108. const gchar * param, gboolean value[], gsize length)
  109. {
  110. if (!mc_config || !group || !param || !value || length == 0)
  111. return;
  112. g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
  113. }
  114. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  115. void
  116. mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
  117. const gchar * param, int value[], gsize length)
  118. {
  119. if (!mc_config || !group || !param || !value || length == 0)
  120. return;
  121. g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
  122. }
  123. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */