set.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. {
  34. buffer = g_string_new(value);
  35. }
  36. else
  37. {
  38. conv = str_crt_conv_to ("UTF-8");
  39. if (conv == INVALID_CONV)
  40. return g_strdup(value);
  41. buffer = g_string_new ("");
  42. if (str_convert (conv, value, buffer) == ESTR_FAILURE)
  43. {
  44. g_string_free(buffer, TRUE);
  45. buffer = g_string_new(value);
  46. }
  47. str_close_conv (conv);
  48. }
  49. return g_string_free(buffer, FALSE);
  50. }
  51. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  52. /*** public functions **************************************************/
  53. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  54. void
  55. mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
  56. const gchar * param, const gchar * value)
  57. {
  58. gchar *buffer;
  59. if (!mc_config || !group || !param || !value)
  60. return;
  61. buffer = mc_config_normalize_before_save(value);
  62. g_key_file_set_value (mc_config->handle, group, param, buffer);
  63. g_free(buffer);
  64. }
  65. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  66. void
  67. mc_config_set_string (mc_config_t * mc_config, const gchar * group,
  68. const gchar * param, const gchar * value)
  69. {
  70. gchar *buffer;
  71. if (!mc_config || !group || !param || !value)
  72. return;
  73. buffer = mc_config_normalize_before_save(value);
  74. g_key_file_set_string (mc_config->handle, group, param, buffer);
  75. g_free(buffer);
  76. }
  77. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  78. void
  79. mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
  80. const gchar * param, gboolean value)
  81. {
  82. if (!mc_config || !group || !param )
  83. return;
  84. g_key_file_set_boolean (mc_config->handle, group, param, value);
  85. }
  86. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  87. void
  88. mc_config_set_int (mc_config_t * mc_config, const gchar * group,
  89. 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[],
  100. gsize length)
  101. {
  102. if (!mc_config || !group || !param || !value || length == 0)
  103. return;
  104. g_key_file_set_string_list (mc_config->handle, group, param, value,
  105. length);
  106. }
  107. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  108. void
  109. mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
  110. const gchar * param, gboolean value[], gsize length)
  111. {
  112. if (!mc_config || !group || !param || !value || length == 0)
  113. return;
  114. g_key_file_set_boolean_list (mc_config->handle, group, param, value,
  115. length);
  116. }
  117. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  118. void
  119. mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
  120. const gchar * param, int value[], gsize length)
  121. {
  122. if (!mc_config || !group || !param || !value || length == 0)
  123. return;
  124. g_key_file_set_integer_list (mc_config->handle, group, param, value,
  125. length);
  126. }
  127. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */