set.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. /*** file scope macro definitions **************************************/
  22. /*** file scope type declarations **************************************/
  23. /*** file scope variables **********************************************/
  24. /*** file scope functions **********************************************/
  25. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  26. static gchar *
  27. mc_config_normalize_before_save (const gchar * value)
  28. {
  29. GIConv conv;
  30. GString *buffer;
  31. if (mc_global.utf8_display)
  32. return g_strdup (value);
  33. conv = str_crt_conv_to ("UTF-8");
  34. if (conv == INVALID_CONV)
  35. return g_strdup (value);
  36. buffer = g_string_new ("");
  37. if (str_convert (conv, value, buffer) == ESTR_FAILURE)
  38. {
  39. g_string_free (buffer, TRUE);
  40. return g_strdup (value);
  41. }
  42. str_close_conv (conv);
  43. return g_string_free (buffer, FALSE);
  44. }
  45. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  46. /*** public functions **************************************************/
  47. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  48. void
  49. mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
  50. const gchar * param, const gchar * value)
  51. {
  52. if (!mc_config || !group || !param || !value)
  53. return;
  54. g_key_file_set_string (mc_config->handle, group, param, value);
  55. }
  56. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  57. void
  58. mc_config_set_string (const mc_config_t * mc_config, const gchar * group,
  59. const gchar * param, const gchar * value)
  60. {
  61. gchar *buffer;
  62. if (!mc_config || !group || !param || !value)
  63. return;
  64. buffer = mc_config_normalize_before_save (value);
  65. g_key_file_set_string (mc_config->handle, group, param, buffer);
  66. g_free (buffer);
  67. }
  68. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  69. void
  70. mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
  71. const gchar * param, gboolean value)
  72. {
  73. if (!mc_config || !group || !param)
  74. return;
  75. g_key_file_set_boolean (mc_config->handle, group, param, value);
  76. }
  77. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  78. void
  79. mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
  80. {
  81. if (!mc_config || !group || !param)
  82. return;
  83. g_key_file_set_integer (mc_config->handle, group, param, value);
  84. }
  85. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  86. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  87. void
  88. mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
  89. const gchar * param, const gchar * const value[], gsize length)
  90. {
  91. if (!mc_config || !group || !param || !value || length == 0)
  92. return;
  93. g_key_file_set_string_list (mc_config->handle, group, param, value, length);
  94. }
  95. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  96. void
  97. mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
  98. const gchar * param, gboolean value[], gsize length)
  99. {
  100. if (!mc_config || !group || !param || !value || length == 0)
  101. return;
  102. g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
  103. }
  104. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  105. void
  106. mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
  107. const gchar * param, int value[], gsize length)
  108. {
  109. if (!mc_config || !group || !param || !value || length == 0)
  110. return;
  111. g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
  112. }
  113. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */