window-settings-basic.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <wx/msgdlg.h>
  15. #include "window-settings-basic.hpp"
  16. OBSBasicSettings::OBSBasicSettings(wxWindow *parent)
  17. : OBSBasicSettingsBase(parent)
  18. {
  19. unique_ptr<BasicSettingsData> data(CreateBasicGeneralSettings(this));
  20. settings = move(data);
  21. }
  22. void OBSBasicSettings::PageChanged(wxListbookEvent &event)
  23. {
  24. wxWindow *curPage = settingsList->GetCurrentPage();
  25. if (!curPage)
  26. return;
  27. int id = curPage->GetId();
  28. BasicSettingsData *ptr = NULL;
  29. switch (id) {
  30. case ID_SETTINGS_GENERAL:
  31. ptr = CreateBasicGeneralSettings(this);
  32. break;
  33. case ID_SETTINGS_VIDEO:
  34. ptr = CreateBasicVideoSettings(this);
  35. break;
  36. }
  37. settings = move(unique_ptr<BasicSettingsData>(ptr));
  38. }
  39. bool OBSBasicSettings::ConfirmChanges()
  40. {
  41. if (settings && settings->DataChanged()) {
  42. int confirm = wxMessageBox(WXStr("Settings.Confirm"),
  43. WXStr("Settings.ConfirmTitle"),
  44. wxYES_NO | wxCANCEL);
  45. if (confirm == wxCANCEL) {
  46. return false;
  47. } else if (confirm == wxYES) {
  48. settings->Apply();
  49. return true;
  50. }
  51. }
  52. return true;
  53. }
  54. void OBSBasicSettings::PageChanging(wxListbookEvent &event)
  55. {
  56. if (!ConfirmChanges())
  57. event.Veto();
  58. }
  59. void OBSBasicSettings::OnClose(wxCloseEvent &event)
  60. {
  61. if (!ConfirmChanges())
  62. event.Veto();
  63. else
  64. EndModal(0);
  65. }
  66. void OBSBasicSettings::OKClicked(wxCommandEvent &event)
  67. {
  68. if (settings && settings->DataChanged())
  69. settings->Apply();
  70. EndModal(0);
  71. }
  72. void OBSBasicSettings::CancelClicked(wxCommandEvent &event)
  73. {
  74. EndModal(0);
  75. }
  76. void OBSBasicSettings::ApplyClicked(wxCommandEvent &event)
  77. {
  78. if (settings && settings->DataChanged())
  79. settings->Apply();
  80. }