1
0

settings-basic-general.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "obs-app.hpp"
  15. #include "settings-basic.hpp"
  16. #include "window-settings-basic.hpp"
  17. #include "platform.hpp"
  18. class GeneralSettings : public BasicSettingsData {
  19. ConfigFile localeIni;
  20. int AddLanguage(const char *tag);
  21. void FillLanguageList(const char *currentLang);
  22. public:
  23. GeneralSettings(OBSBasicSettings *window);
  24. virtual void Apply();
  25. };
  26. class LanguageInfo : public wxClientData {
  27. public:
  28. const char *tag;
  29. const char *name;
  30. const char *subLang;
  31. bool isDefault;
  32. inline LanguageInfo(config_t config, const char *tag)
  33. : wxClientData (),
  34. tag (tag),
  35. name (config_get_string(config, tag, "Name")),
  36. subLang (config_get_string(config, tag, "SubLang")),
  37. isDefault (config_get_bool(config, tag, "DefaultSubLang"))
  38. {
  39. }
  40. };
  41. int GeneralSettings::AddLanguage(const char *tag)
  42. {
  43. LanguageInfo *info = new LanguageInfo(localeIni, tag);
  44. return window->languageList->Append(wxString(info->name, wxConvUTF8),
  45. info);
  46. }
  47. void GeneralSettings::FillLanguageList(const char *currentLang)
  48. {
  49. size_t numSections = config_num_sections(localeIni);
  50. for (size_t i = 0; i < numSections; i++) {
  51. const char *lang = config_get_section(localeIni, i);
  52. int idx = AddLanguage(lang);
  53. if (strcmp(lang, currentLang) == 0)
  54. window->languageList->SetSelection(idx);
  55. }
  56. }
  57. GeneralSettings::GeneralSettings(OBSBasicSettings *window)
  58. : BasicSettingsData (window)
  59. {
  60. string path;
  61. if (!GetDataFilePath("locale/locale.ini", path))
  62. throw "Could not find locale/locale.ini path";
  63. if (localeIni.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
  64. throw "Could not open locale.ini";
  65. const char *currentLang = config_get_string(GetGlobalConfig(),
  66. "General", "Language");
  67. FillLanguageList(currentLang);
  68. }
  69. void GeneralSettings::Apply()
  70. {
  71. }
  72. BasicSettingsData *CreateBasicGeneralSettings(OBSBasicSettings *window)
  73. {
  74. BasicSettingsData *data = NULL;
  75. try {
  76. data = new GeneralSettings(window);
  77. } catch (const char *error) {
  78. blog(LOG_ERROR, "CreateBasicGeneralSettings failed: %s", error);
  79. }
  80. return data;
  81. }