window-basic-settings.cpp 2.4 KB

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