window-basic-settings.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 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.hpp>
  15. #include <util/util.hpp>
  16. #include <util/lexer.h>
  17. #include <sstream>
  18. #include <QLineEdit>
  19. #include <QMessageBox>
  20. #include <QCloseEvent>
  21. #include <QFileDialog>
  22. #include "obs-app.hpp"
  23. #include "platform.hpp"
  24. #include "properties-view.hpp"
  25. #include "qt-wrappers.hpp"
  26. #include "window-basic-main.hpp"
  27. #include "window-basic-settings.hpp"
  28. #include <util/platform.h>
  29. using namespace std;
  30. /* parses "[width]x[height]", string, i.e. 1024x768 */
  31. static bool ConvertResText(const char *res, uint32_t &cx, uint32_t &cy)
  32. {
  33. BaseLexer lex;
  34. base_token token;
  35. lexer_start(lex, res);
  36. /* parse width */
  37. if (!lexer_getbasetoken(lex, &token, IGNORE_WHITESPACE))
  38. return false;
  39. if (token.type != BASETOKEN_DIGIT)
  40. return false;
  41. cx = std::stoul(token.text.array);
  42. /* parse 'x' */
  43. if (!lexer_getbasetoken(lex, &token, IGNORE_WHITESPACE))
  44. return false;
  45. if (strref_cmpi(&token.text, "x") != 0)
  46. return false;
  47. /* parse height */
  48. if (!lexer_getbasetoken(lex, &token, IGNORE_WHITESPACE))
  49. return false;
  50. if (token.type != BASETOKEN_DIGIT)
  51. return false;
  52. cy = std::stoul(token.text.array);
  53. /* shouldn't be any more tokens after this */
  54. if (lexer_getbasetoken(lex, &token, IGNORE_WHITESPACE))
  55. return false;
  56. return true;
  57. }
  58. static inline bool WidgetChanged(QWidget *widget)
  59. {
  60. return widget->property("changed").toBool();
  61. }
  62. static inline void SetComboByName(QComboBox *combo, const char *name)
  63. {
  64. int idx = combo->findText(QT_UTF8(name));
  65. if (idx != -1)
  66. combo->setCurrentIndex(idx);
  67. }
  68. static inline void SetComboByValue(QComboBox *combo, const char *name)
  69. {
  70. int idx = combo->findData(QT_UTF8(name));
  71. if (idx != -1)
  72. combo->setCurrentIndex(idx);
  73. }
  74. static inline QString GetComboData(QComboBox *combo)
  75. {
  76. int idx = combo->currentIndex();
  77. if (idx == -1)
  78. return QString();
  79. return combo->itemData(idx).toString();
  80. }
  81. void OBSBasicSettings::HookWidget(QWidget *widget, const char *signal,
  82. const char *slot)
  83. {
  84. QObject::connect(widget, signal, this, slot);
  85. widget->setProperty("changed", QVariant(false));
  86. }
  87. #define COMBO_CHANGED SIGNAL(currentIndexChanged(int))
  88. #define EDIT_CHANGED SIGNAL(textChanged(const QString &))
  89. #define CBEDIT_CHANGED SIGNAL(editTextChanged(const QString &))
  90. #define CHECK_CHANGED SIGNAL(clicked(bool))
  91. #define SCROLL_CHANGED SIGNAL(valueChanged(int))
  92. #define GENERAL_CHANGED SLOT(GeneralChanged())
  93. #define OUTPUTS_CHANGED SLOT(OutputsChanged())
  94. #define AUDIO_RESTART SLOT(AudioChangedRestart())
  95. #define AUDIO_CHANGED SLOT(AudioChanged())
  96. #define VIDEO_RESTART SLOT(VideoChangedRestart())
  97. #define VIDEO_RES SLOT(VideoChangedResolution())
  98. #define VIDEO_CHANGED SLOT(VideoChanged())
  99. OBSBasicSettings::OBSBasicSettings(QWidget *parent)
  100. : QDialog (parent),
  101. main (qobject_cast<OBSBasic*>(parent)),
  102. ui (new Ui::OBSBasicSettings),
  103. generalChanged (false),
  104. outputsChanged (false),
  105. audioChanged (false),
  106. videoChanged (false),
  107. pageIndex (0),
  108. loading (true),
  109. streamProperties (nullptr)
  110. {
  111. string path;
  112. ui->setupUi(this);
  113. if (!GetDataFilePath("locale/locale.ini", path))
  114. throw "Could not find locale/locale.ini path";
  115. if (localeIni.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
  116. throw "Could not open locale.ini";
  117. HookWidget(ui->language, COMBO_CHANGED, GENERAL_CHANGED);
  118. HookWidget(ui->outputMode, COMBO_CHANGED, OUTPUTS_CHANGED);
  119. HookWidget(ui->simpleOutputPath, EDIT_CHANGED, OUTPUTS_CHANGED);
  120. HookWidget(ui->simpleOutputVBitrate, SCROLL_CHANGED, OUTPUTS_CHANGED);
  121. HookWidget(ui->simpleOutputABitrate, COMBO_CHANGED, OUTPUTS_CHANGED);
  122. HookWidget(ui->simpleOutReconnect, CHECK_CHANGED, OUTPUTS_CHANGED);
  123. HookWidget(ui->simpleOutRetryDelay, SCROLL_CHANGED, OUTPUTS_CHANGED);
  124. HookWidget(ui->simpleOutMaxRetries, SCROLL_CHANGED, OUTPUTS_CHANGED);
  125. HookWidget(ui->channelSetup, COMBO_CHANGED, AUDIO_RESTART);
  126. HookWidget(ui->sampleRate, COMBO_CHANGED, AUDIO_RESTART);
  127. HookWidget(ui->desktopAudioDevice1, COMBO_CHANGED, AUDIO_CHANGED);
  128. HookWidget(ui->desktopAudioDevice2, COMBO_CHANGED, AUDIO_CHANGED);
  129. HookWidget(ui->auxAudioDevice1, COMBO_CHANGED, AUDIO_CHANGED);
  130. HookWidget(ui->auxAudioDevice2, COMBO_CHANGED, AUDIO_CHANGED);
  131. HookWidget(ui->auxAudioDevice3, COMBO_CHANGED, AUDIO_CHANGED);
  132. HookWidget(ui->renderer, COMBO_CHANGED, VIDEO_RESTART);
  133. HookWidget(ui->adapter, COMBO_CHANGED, VIDEO_RESTART);
  134. HookWidget(ui->baseResolution, CBEDIT_CHANGED, VIDEO_RES);
  135. HookWidget(ui->outputResolution, CBEDIT_CHANGED, VIDEO_RES);
  136. HookWidget(ui->downscaleFilter, COMBO_CHANGED, VIDEO_CHANGED);
  137. HookWidget(ui->fpsType, COMBO_CHANGED, VIDEO_CHANGED);
  138. HookWidget(ui->fpsCommon, COMBO_CHANGED, VIDEO_CHANGED);
  139. HookWidget(ui->fpsInteger, SCROLL_CHANGED, VIDEO_CHANGED);
  140. HookWidget(ui->fpsInteger, SCROLL_CHANGED, VIDEO_CHANGED);
  141. HookWidget(ui->fpsNumerator, SCROLL_CHANGED, VIDEO_CHANGED);
  142. HookWidget(ui->fpsDenominator, SCROLL_CHANGED, VIDEO_CHANGED);
  143. //Apply button disabled until change.
  144. EnableApplyButton(false);
  145. LoadServiceTypes();
  146. LoadServiceInfo();
  147. LoadSettings(false);
  148. }
  149. void OBSBasicSettings::SaveCombo(QComboBox *widget, const char *section,
  150. const char *value)
  151. {
  152. if (WidgetChanged(widget))
  153. config_set_string(main->Config(), section, value,
  154. QT_TO_UTF8(widget->currentText()));
  155. }
  156. void OBSBasicSettings::SaveComboData(QComboBox *widget, const char *section,
  157. const char *value)
  158. {
  159. if (WidgetChanged(widget)) {
  160. QString str = GetComboData(widget);
  161. config_set_string(main->Config(), section, value,
  162. QT_TO_UTF8(str));
  163. }
  164. }
  165. void OBSBasicSettings::SaveCheckBox(QCheckBox *widget, const char *section,
  166. const char *value)
  167. {
  168. if (WidgetChanged(widget))
  169. config_set_bool(main->Config(), section, value,
  170. widget->isChecked());
  171. }
  172. void OBSBasicSettings::SaveEdit(QLineEdit *widget, const char *section,
  173. const char *value)
  174. {
  175. if (WidgetChanged(widget))
  176. config_set_string(main->Config(), section, value,
  177. QT_TO_UTF8(widget->text()));
  178. }
  179. void OBSBasicSettings::SaveSpinBox(QSpinBox *widget, const char *section,
  180. const char *value)
  181. {
  182. if (WidgetChanged(widget))
  183. config_set_int(main->Config(), section, value, widget->value());
  184. }
  185. void OBSBasicSettings::LoadServiceTypes()
  186. {
  187. const char *type;
  188. size_t idx = 0;
  189. while (obs_enum_service_types(idx++, &type)) {
  190. const char *name = obs_service_getdisplayname(type);
  191. QString qName = QT_UTF8(name);
  192. QString qType = QT_UTF8(type);
  193. ui->streamType->addItem(qName, qType);
  194. }
  195. type = obs_service_gettype(main->GetService());
  196. SetComboByValue(ui->streamType, type);
  197. }
  198. void OBSBasicSettings::LoadServiceInfo()
  199. {
  200. QLayout *layout = ui->streamContainer->layout();
  201. obs_service_t service = main->GetService();
  202. obs_data_t settings = obs_service_get_settings(service);
  203. obs_properties_t properties = obs_service_properties(service);
  204. delete streamProperties;
  205. streamProperties = new OBSPropertiesView(
  206. settings,
  207. properties,
  208. service,
  209. (PropertiesUpdateCallback)obs_service_update,
  210. 170);
  211. layout->addWidget(streamProperties);
  212. obs_data_release(settings);
  213. }
  214. void OBSBasicSettings::LoadLanguageList()
  215. {
  216. const char *currentLang = config_get_string(GetGlobalConfig(),
  217. "General", "Language");
  218. ui->language->clear();
  219. size_t numSections = config_num_sections(localeIni);
  220. for (size_t i = 0; i < numSections; i++) {
  221. const char *tag = config_get_section(localeIni, i);
  222. const char *name = config_get_string(localeIni, tag, "Name");
  223. int idx = ui->language->count();
  224. ui->language->addItem(QT_UTF8(name), QT_UTF8(tag));
  225. if (strcmp(tag, currentLang) == 0)
  226. ui->language->setCurrentIndex(idx);
  227. }
  228. ui->language->model()->sort(0);
  229. }
  230. void OBSBasicSettings::LoadGeneralSettings()
  231. {
  232. loading = true;
  233. LoadLanguageList();
  234. loading = false;
  235. }
  236. void OBSBasicSettings::LoadRendererList()
  237. {
  238. const char *renderer = config_get_string(GetGlobalConfig(), "Video",
  239. "Renderer");
  240. #ifdef _WIN32
  241. ui->renderer->addItem(QT_UTF8("Direct3D 11"));
  242. #endif
  243. ui->renderer->addItem(QT_UTF8("OpenGL"));
  244. int idx = ui->renderer->findText(QT_UTF8(renderer));
  245. if (idx == -1)
  246. idx = 0;
  247. ui->renderer->setCurrentIndex(idx);
  248. }
  249. Q_DECLARE_METATYPE(MonitorInfo);
  250. static string ResString(uint32_t cx, uint32_t cy)
  251. {
  252. stringstream res;
  253. res << cx << "x" << cy;
  254. return res.str();
  255. }
  256. /* some nice default output resolution vals */
  257. static const double vals[] =
  258. {
  259. 1.0,
  260. 1.25,
  261. (1.0/0.75),
  262. 1.5,
  263. (1.0/0.6),
  264. 1.75,
  265. 2.0,
  266. 2.25,
  267. 2.5,
  268. 2.75,
  269. 3.0
  270. };
  271. static const size_t numVals = sizeof(vals)/sizeof(double);
  272. void OBSBasicSettings::ResetDownscales(uint32_t cx, uint32_t cy)
  273. {
  274. ui->outputResolution->clear();
  275. for (size_t idx = 0; idx < numVals; idx++) {
  276. uint32_t downscaleCX = uint32_t(double(cx) / vals[idx]);
  277. uint32_t downscaleCY = uint32_t(double(cy) / vals[idx]);
  278. string res = ResString(downscaleCX, downscaleCY);
  279. ui->outputResolution->addItem(res.c_str());
  280. }
  281. ui->outputResolution->lineEdit()->setText(ResString(cx, cy).c_str());
  282. }
  283. void OBSBasicSettings::LoadResolutionLists()
  284. {
  285. uint32_t cx = config_get_uint(main->Config(), "Video", "BaseCX");
  286. uint32_t cy = config_get_uint(main->Config(), "Video", "BaseCY");
  287. vector<MonitorInfo> monitors;
  288. ui->baseResolution->clear();
  289. GetMonitors(monitors);
  290. for (MonitorInfo &monitor : monitors) {
  291. string res = ResString(monitor.cx, monitor.cy);
  292. ui->baseResolution->addItem(res.c_str());
  293. }
  294. ResetDownscales(cx, cy);
  295. ui->baseResolution->lineEdit()->setText(ResString(cx, cy).c_str());
  296. cx = config_get_uint(main->Config(), "Video", "OutputCX");
  297. cy = config_get_uint(main->Config(), "Video", "OutputCY");
  298. ui->outputResolution->lineEdit()->setText(ResString(cx, cy).c_str());
  299. }
  300. static inline void LoadFPSCommon(OBSBasic *main, Ui::OBSBasicSettings *ui)
  301. {
  302. const char *val = config_get_string(main->Config(), "Video",
  303. "FPSCommon");
  304. int idx = ui->fpsCommon->findText(val);
  305. if (idx == -1) idx = 3;
  306. ui->fpsCommon->setCurrentIndex(idx);
  307. }
  308. static inline void LoadFPSInteger(OBSBasic *main, Ui::OBSBasicSettings *ui)
  309. {
  310. uint32_t val = config_get_uint(main->Config(), "Video", "FPSInt");
  311. ui->fpsInteger->setValue(val);
  312. }
  313. static inline void LoadFPSFraction(OBSBasic *main, Ui::OBSBasicSettings *ui)
  314. {
  315. uint32_t num = config_get_uint(main->Config(), "Video", "FPSNum");
  316. uint32_t den = config_get_uint(main->Config(), "Video", "FPSDen");
  317. ui->fpsNumerator->setValue(num);
  318. ui->fpsDenominator->setValue(den);
  319. }
  320. void OBSBasicSettings::LoadFPSData()
  321. {
  322. LoadFPSCommon(main, ui.get());
  323. LoadFPSInteger(main, ui.get());
  324. LoadFPSFraction(main, ui.get());
  325. uint32_t fpsType = config_get_uint(main->Config(), "Video",
  326. "FPSType");
  327. if (fpsType > 2) fpsType = 0;
  328. ui->fpsType->setCurrentIndex(fpsType);
  329. ui->fpsTypes->setCurrentIndex(fpsType);
  330. }
  331. void OBSBasicSettings::LoadVideoSettings()
  332. {
  333. loading = true;
  334. if (video_output_active(obs_video())) {
  335. ui->videoPage->setEnabled(false);
  336. ui->videoMsg->setText(
  337. QTStr("Basic.Settings.Video.CurrentlyActive"));
  338. }
  339. LoadRendererList();
  340. LoadResolutionLists();
  341. LoadFPSData();
  342. loading = false;
  343. }
  344. void OBSBasicSettings::LoadSimpleOutputSettings()
  345. {
  346. const char *path = config_get_string(main->Config(), "SimpleOutput",
  347. "FilePath");
  348. int videoBitrate = config_get_uint(main->Config(), "SimpleOutput",
  349. "VBitrate");
  350. int audioBitrate = config_get_uint(main->Config(), "SimpleOutput",
  351. "ABitrate");
  352. bool reconnect = config_get_bool(main->Config(), "SimpleOutput",
  353. "Reconnect");
  354. int retryDelay = config_get_uint(main->Config(), "SimpleOutput",
  355. "RetryDelay");
  356. int maxRetries = config_get_uint(main->Config(), "SimpleOutput",
  357. "MaxRetries");
  358. ui->simpleOutputPath->setText(path);
  359. ui->simpleOutputVBitrate->setValue(videoBitrate);
  360. SetComboByName(ui->simpleOutputABitrate,
  361. std::to_string(audioBitrate).c_str());
  362. ui->simpleOutReconnect->setChecked(reconnect);
  363. ui->simpleOutRetryDelay->setValue(retryDelay);
  364. ui->simpleOutMaxRetries->setValue(maxRetries);
  365. }
  366. void OBSBasicSettings::LoadOutputSettings()
  367. {
  368. loading = true;
  369. LoadSimpleOutputSettings();
  370. loading = false;
  371. }
  372. static inline void LoadListValue(QComboBox *widget, const char *text,
  373. const char *val)
  374. {
  375. widget->addItem(QT_UTF8(text), QT_UTF8(val));
  376. }
  377. void OBSBasicSettings::LoadListValues(QComboBox *widget, obs_property_t prop,
  378. const char *configName)
  379. {
  380. size_t count = obs_property_list_item_count(prop);
  381. const char *deviceId = config_get_string(main->Config(), "Audio",
  382. configName);
  383. widget->addItem(QTStr("Disabled"), "disabled");
  384. for (size_t i = 0; i < count; i++) {
  385. const char *name = obs_property_list_item_name(prop, i);
  386. const char *val = obs_property_list_item_string(prop, i);
  387. LoadListValue(widget, name, val);
  388. }
  389. int idx = widget->findData(QVariant(QT_UTF8(deviceId)));
  390. if (idx == -1) {
  391. deviceId = config_get_default_string(main->Config(), "Audio",
  392. configName);
  393. idx = widget->findData(QVariant(QT_UTF8(deviceId)));
  394. }
  395. if (idx != -1)
  396. widget->setCurrentIndex(idx);
  397. }
  398. void OBSBasicSettings::LoadAudioDevices()
  399. {
  400. const char *input_id = App()->InputAudioSource();
  401. const char *output_id = App()->OutputAudioSource();
  402. obs_properties_t input_props = obs_get_source_properties(
  403. OBS_SOURCE_TYPE_INPUT, input_id);
  404. obs_properties_t output_props = obs_get_source_properties(
  405. OBS_SOURCE_TYPE_INPUT, output_id);
  406. if (input_props) {
  407. obs_property_t inputs = obs_properties_get(input_props,
  408. "device_id");
  409. LoadListValues(ui->auxAudioDevice1, inputs, "AuxDevice1");
  410. LoadListValues(ui->auxAudioDevice2, inputs, "AuxDevice2");
  411. LoadListValues(ui->auxAudioDevice3, inputs, "AuxDevice3");
  412. obs_properties_destroy(input_props);
  413. }
  414. if (output_props) {
  415. obs_property_t outputs = obs_properties_get(output_props,
  416. "device_id");
  417. LoadListValues(ui->desktopAudioDevice1, outputs,
  418. "DesktopDevice1");
  419. LoadListValues(ui->desktopAudioDevice2, outputs,
  420. "DesktopDevice2");
  421. obs_properties_destroy(output_props);
  422. }
  423. }
  424. void OBSBasicSettings::LoadAudioSettings()
  425. {
  426. uint32_t sampleRate = config_get_uint(main->Config(), "Audio",
  427. "SampleRate");
  428. const char *speakers = config_get_string(main->Config(), "Audio",
  429. "ChannelSetup");
  430. loading = true;
  431. const char *str;
  432. if (sampleRate == 22050)
  433. str = "22.05khz";
  434. else if (sampleRate == 48000)
  435. str = "48khz";
  436. else
  437. str = "44.1khz";
  438. int sampleRateIdx = ui->sampleRate->findText(str);
  439. if (sampleRateIdx != -1)
  440. ui->sampleRate->setCurrentIndex(sampleRateIdx);
  441. if (strcmp(speakers, "Mono") == 0)
  442. ui->channelSetup->setCurrentIndex(0);
  443. else
  444. ui->channelSetup->setCurrentIndex(1);
  445. LoadAudioDevices();
  446. loading = false;
  447. }
  448. void OBSBasicSettings::LoadSettings(bool changedOnly)
  449. {
  450. if (!changedOnly || generalChanged)
  451. LoadGeneralSettings();
  452. if (!changedOnly || outputsChanged)
  453. LoadOutputSettings();
  454. if (!changedOnly || audioChanged)
  455. LoadAudioSettings();
  456. if (!changedOnly || videoChanged)
  457. LoadVideoSettings();
  458. }
  459. void OBSBasicSettings::SaveGeneralSettings()
  460. {
  461. int languageIndex = ui->language->currentIndex();
  462. QVariant langData = ui->language->itemData(languageIndex);
  463. string language = langData.toString().toStdString();
  464. if (WidgetChanged(ui->language))
  465. config_set_string(GetGlobalConfig(), "General", "Language",
  466. language.c_str());
  467. }
  468. void OBSBasicSettings::SaveVideoSettings()
  469. {
  470. QString baseResolution = ui->baseResolution->currentText();
  471. QString outputResolution = ui->outputResolution->currentText();
  472. int fpsType = ui->fpsType->currentIndex();
  473. uint32_t cx = 0, cy = 0;
  474. /* ------------------- */
  475. if (WidgetChanged(ui->renderer))
  476. config_set_string(App()->GlobalConfig(), "Video", "Renderer",
  477. QT_TO_UTF8(ui->renderer->currentText()));
  478. if (WidgetChanged(ui->baseResolution) &&
  479. ConvertResText(QT_TO_UTF8(baseResolution), cx, cy)) {
  480. config_set_uint(main->Config(), "Video", "BaseCX", cx);
  481. config_set_uint(main->Config(), "Video", "BaseCY", cy);
  482. }
  483. if (WidgetChanged(ui->outputResolution) &&
  484. ConvertResText(QT_TO_UTF8(outputResolution), cx, cy)) {
  485. config_set_uint(main->Config(), "Video", "OutputCX", cx);
  486. config_set_uint(main->Config(), "Video", "OutputCY", cy);
  487. }
  488. if (WidgetChanged(ui->fpsType))
  489. config_set_uint(main->Config(), "Video", "FPSType", fpsType);
  490. SaveCombo(ui->fpsCommon, "Video", "FPSCommon");
  491. SaveSpinBox(ui->fpsInteger, "Video", "FPSInt");
  492. SaveSpinBox(ui->fpsNumerator, "Video", "FPSNum");
  493. SaveSpinBox(ui->fpsDenominator, "Video", "FPSDen");
  494. main->ResetVideo();
  495. }
  496. /* TODO: Temporary! */
  497. void OBSBasicSettings::SaveOutputSettings()
  498. {
  499. SaveSpinBox(ui->simpleOutputVBitrate, "SimpleOutput", "VBitrate");
  500. SaveCombo(ui->simpleOutputABitrate, "SimpleOutput", "ABitrate");
  501. SaveEdit(ui->simpleOutputPath, "SimpleOutput", "FilePath");
  502. SaveCheckBox(ui->simpleOutReconnect, "SimpleOutput", "Reconnect");
  503. SaveSpinBox(ui->simpleOutRetryDelay, "SimpleOutput", "RetryDelay");
  504. SaveSpinBox(ui->simpleOutMaxRetries, "SimpleOutput", "MaxRetries");
  505. }
  506. void OBSBasicSettings::SaveAudioSettings()
  507. {
  508. QString sampleRateStr = ui->sampleRate->currentText();
  509. int channelSetupIdx = ui->channelSetup->currentIndex();
  510. const char *channelSetup = (channelSetupIdx == 0) ? "Mono" : "Stereo";
  511. int sampleRate = 44100;
  512. if (sampleRateStr == "22.05khz")
  513. sampleRate = 22050;
  514. else if (sampleRateStr == "48khz")
  515. sampleRate = 48000;
  516. if (WidgetChanged(ui->sampleRate))
  517. config_set_uint(main->Config(), "Audio", "SampleRate",
  518. sampleRate);
  519. if (WidgetChanged(ui->channelSetup))
  520. config_set_string(main->Config(), "Audio", "ChannelSetup",
  521. channelSetup);
  522. SaveComboData(ui->desktopAudioDevice1, "Audio", "DesktopDevice1");
  523. SaveComboData(ui->desktopAudioDevice2, "Audio", "DesktopDevice2");
  524. SaveComboData(ui->auxAudioDevice1, "Audio", "AuxDevice1");
  525. SaveComboData(ui->auxAudioDevice2, "Audio", "AuxDevice2");
  526. SaveComboData(ui->auxAudioDevice3, "Audio", "AuxDevice3");
  527. main->ResetAudioDevices();
  528. }
  529. void OBSBasicSettings::SaveSettings()
  530. {
  531. if (generalChanged)
  532. SaveGeneralSettings();
  533. if (outputsChanged)
  534. SaveOutputSettings();
  535. if (audioChanged)
  536. SaveAudioSettings();
  537. if (videoChanged)
  538. SaveVideoSettings();
  539. config_save(main->Config());
  540. config_save(GetGlobalConfig());
  541. }
  542. bool OBSBasicSettings::QueryChanges()
  543. {
  544. QMessageBox::StandardButton button;
  545. button = QMessageBox::question(this,
  546. QTStr("Basic.Settings.ConfirmTitle"),
  547. QTStr("Basic.Settings.Confirm"),
  548. QMessageBox::Yes | QMessageBox::No |
  549. QMessageBox::Cancel);
  550. if (button == QMessageBox::Cancel)
  551. return false;
  552. else if (button == QMessageBox::Yes)
  553. SaveSettings();
  554. else
  555. LoadSettings(true);
  556. ClearChanged();
  557. return true;
  558. }
  559. void OBSBasicSettings::closeEvent(QCloseEvent *event)
  560. {
  561. if (Changed() && !QueryChanges())
  562. event->ignore();
  563. }
  564. void OBSBasicSettings::on_listWidget_itemSelectionChanged()
  565. {
  566. int row = ui->listWidget->currentRow();
  567. if (loading || row == pageIndex)
  568. return;
  569. pageIndex = row;
  570. }
  571. void OBSBasicSettings::on_buttonBox_clicked(QAbstractButton *button)
  572. {
  573. QDialogButtonBox::ButtonRole val = ui->buttonBox->buttonRole(button);
  574. if (val == QDialogButtonBox::ApplyRole ||
  575. val == QDialogButtonBox::AcceptRole) {
  576. SaveSettings();
  577. ClearChanged();
  578. }
  579. if (val == QDialogButtonBox::AcceptRole ||
  580. val == QDialogButtonBox::RejectRole) {
  581. ClearChanged();
  582. close();
  583. }
  584. }
  585. void OBSBasicSettings::on_streamType_currentIndexChanged(int idx)
  586. {
  587. QString val = ui->streamType->itemData(idx).toString();
  588. obs_service_t newService;
  589. if (loading)
  590. return;
  591. delete streamProperties;
  592. streamProperties = nullptr;
  593. newService = obs_service_create(QT_TO_UTF8(val), nullptr, nullptr);
  594. if (newService)
  595. main->SetService(newService);
  596. LoadServiceInfo();
  597. }
  598. void OBSBasicSettings::on_simpleOutputBrowse_clicked()
  599. {
  600. QString dir = QFileDialog::getExistingDirectory(this,
  601. QTStr("OpenDirectory"),
  602. ui->simpleOutputPath->text(),
  603. QFileDialog::ShowDirsOnly |
  604. QFileDialog::DontResolveSymlinks);
  605. if (dir.isEmpty())
  606. return;
  607. ui->simpleOutputPath->setText(dir);
  608. }
  609. static inline bool StreamExists(const char *name)
  610. {
  611. return obs_get_service_by_name(name) != nullptr;
  612. }
  613. #define INVALID_RES_STR "Basic.Settings.Video.InvalidResolution"
  614. static bool ValidResolutions(Ui::OBSBasicSettings *ui)
  615. {
  616. QString baseRes = ui->baseResolution->lineEdit()->text();
  617. QString outputRes = ui->outputResolution->lineEdit()->text();
  618. uint32_t cx, cy;
  619. if (!ConvertResText(QT_TO_UTF8(baseRes), cx, cy) ||
  620. !ConvertResText(QT_TO_UTF8(outputRes), cx, cy)) {
  621. ui->videoMsg->setText(QTStr(INVALID_RES_STR));
  622. return false;
  623. }
  624. ui->videoMsg->setText("");
  625. return true;
  626. }
  627. void OBSBasicSettings::on_baseResolution_editTextChanged(const QString &text)
  628. {
  629. if (!loading && ValidResolutions(ui.get())) {
  630. QString baseResolution = text;
  631. uint32_t cx, cy;
  632. ConvertResText(QT_TO_UTF8(baseResolution), cx, cy);
  633. ResetDownscales(cx, cy);
  634. }
  635. }
  636. void OBSBasicSettings::GeneralChanged()
  637. {
  638. if (!loading) {
  639. generalChanged = true;
  640. sender()->setProperty("changed", QVariant(true));
  641. EnableApplyButton(true);
  642. }
  643. }
  644. void OBSBasicSettings::OutputsChanged()
  645. {
  646. if (!loading) {
  647. outputsChanged = true;
  648. sender()->setProperty("changed", QVariant(true));
  649. EnableApplyButton(true);
  650. }
  651. }
  652. void OBSBasicSettings::AudioChanged()
  653. {
  654. if (!loading) {
  655. audioChanged = true;
  656. sender()->setProperty("changed", QVariant(true));
  657. EnableApplyButton(true);
  658. }
  659. }
  660. void OBSBasicSettings::AudioChangedRestart()
  661. {
  662. if (!loading) {
  663. audioChanged = true;
  664. ui->audioMsg->setText(QTStr("Basic.Settings.ProgramRestart"));
  665. sender()->setProperty("changed", QVariant(true));
  666. EnableApplyButton(true);
  667. }
  668. }
  669. void OBSBasicSettings::VideoChangedRestart()
  670. {
  671. if (!loading) {
  672. videoChanged = true;
  673. ui->videoMsg->setText(QTStr("Basic.Settings.ProgramRestart"));
  674. sender()->setProperty("changed", QVariant(true));
  675. EnableApplyButton(true);
  676. }
  677. }
  678. void OBSBasicSettings::VideoChangedResolution()
  679. {
  680. if (!loading && ValidResolutions(ui.get())) {
  681. videoChanged = true;
  682. sender()->setProperty("changed", QVariant(true));
  683. EnableApplyButton(true);
  684. }
  685. }
  686. void OBSBasicSettings::VideoChanged()
  687. {
  688. if (!loading) {
  689. videoChanged = true;
  690. sender()->setProperty("changed", QVariant(true));
  691. EnableApplyButton(true);
  692. }
  693. }