SettingsComponent.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. #include "SettingsComponent.h"
  2. #include "SettingsSection.h"
  3. #include "Paths.h"
  4. #include "utils/Utils.h"
  5. #include "QsLog.h"
  6. #include "AudioSettingsController.h"
  7. #include "Names.h"
  8. #include <QSaveFile>
  9. #include <QJsonDocument>
  10. #include <QJsonObject>
  11. #include <QJsonArray>
  12. #include <QList>
  13. #include <QSettings>
  14. #include "input/InputComponent.h"
  15. #include "system/SystemComponent.h"
  16. #include "Version.h"
  17. #define OLDEST_PREVIOUS_VERSION_KEY "oldestPreviousVersion"
  18. ///////////////////////////////////////////////////////////////////////////////////////////////////
  19. SettingsComponent::SettingsComponent(QObject *parent) : ComponentBase(parent), m_settingsVersion(-1)
  20. {
  21. }
  22. /////////////////////////////////////////////////////////////////////////////////////////
  23. void SettingsComponent::componentPostInitialize()
  24. {
  25. InputComponent::Get().registerHostCommand("cycle_setting", this, "cycleSetting");
  26. }
  27. /////////////////////////////////////////////////////////////////////////////////////////
  28. void SettingsComponent::cycleSetting(const QString& args)
  29. {
  30. QString settingName = args;
  31. QStringList sub = settingName.split(".");
  32. if (sub.size() != 2)
  33. {
  34. QLOG_ERROR() << "Setting must be in the form section.name but got:" << settingName;
  35. return;
  36. }
  37. QString sectionID = sub[0];
  38. QString valueName = sub[1];
  39. SettingsSection* section = getSection(sectionID);
  40. if (!section)
  41. {
  42. QLOG_ERROR() << "Section" << sectionID << "is unknown";
  43. return;
  44. }
  45. QVariantList values = section->possibleValues(valueName);
  46. // If no possible values are defined, check the type of the default value.
  47. // In the case it's a boolean simply negate the current value to cycle through.
  48. // Otherwise log an error message, that it's not possible to cycle through the value.
  49. if (values.size() == 0)
  50. {
  51. if (section->defaultValue(valueName).type() == QVariant::Bool)
  52. {
  53. QVariant currentValue = section->value(valueName);
  54. auto nextValue = currentValue.toBool() ? false : true;
  55. setValue(sectionID, valueName, nextValue);
  56. QLOG_DEBUG() << "Setting" << settingName << "to " << (nextValue ? "Enabled" : "Disabled");
  57. emit SystemComponent::Get().settingsMessage(valueName, nextValue ? "Enabled" : "Disabled");
  58. return;
  59. }
  60. else
  61. {
  62. QLOG_ERROR() << "Setting" << settingName << "is unknown or is not cycleable.";
  63. return;
  64. }
  65. }
  66. QVariant currentValue = section->value(valueName);
  67. int nextValueIndex = 0;
  68. for (int n = 0; n < values.size(); n++)
  69. {
  70. if (currentValue == values[n].toMap()["value"])
  71. {
  72. nextValueIndex = n + 1;
  73. break;
  74. }
  75. }
  76. if (nextValueIndex >= values.size())
  77. nextValueIndex = 0;
  78. auto nextSetting = values[nextValueIndex].toMap();
  79. auto nextValue = nextSetting["value"];
  80. QLOG_DEBUG() << "Setting" << settingName << "to" << nextValue;
  81. setValue(sectionID, valueName, nextValue);
  82. emit SystemComponent::Get().settingsMessage(valueName, nextSetting["title"].toString());
  83. }
  84. ///////////////////////////////////////////////////////////////////////////////////////////////////
  85. void SettingsComponent::updatePossibleValues(const QString &sectionID, const QString &key, const QVariantList &possibleValues)
  86. {
  87. SettingsSection* section = getSection(sectionID);
  88. if (!section)
  89. {
  90. QLOG_ERROR() << "Section" << sectionID << "is unknown";
  91. return;
  92. }
  93. section->updatePossibleValues(key, possibleValues);
  94. QLOG_DEBUG() << "Updated possible values for:" << key << "to" << possibleValues;
  95. }
  96. ///////////////////////////////////////////////////////////////////////////////////////////////////
  97. QVariant SettingsComponent::allValues(const QString& section)
  98. {
  99. if (section.isEmpty())
  100. {
  101. QVariantMap all;
  102. for(const QString& sname : m_sections.keys())
  103. all[sname] = m_sections[sname]->allValues();
  104. return all;
  105. }
  106. else if (m_sections.contains(section))
  107. {
  108. return m_sections[section]->allValues();
  109. }
  110. else
  111. {
  112. // look for the value in the webclient section
  113. return m_sections[SETTINGS_SECTION_WEBCLIENT]->value(section);
  114. }
  115. }
  116. ///////////////////////////////////////////////////////////////////////////////////////////////////
  117. static void writeFile(const QString& filename, const QByteArray& data)
  118. {
  119. QSaveFile file(filename);
  120. file.open(QIODevice::WriteOnly | QIODevice::Text);
  121. file.write(data);
  122. if (!file.commit())
  123. {
  124. QLOG_ERROR() << "Could not write" << filename;
  125. }
  126. }
  127. ///////////////////////////////////////////////////////////////////////////////////////////////////
  128. static QJsonObject loadJson(const QString& filename)
  129. {
  130. // Checking existence before opening is technically a race condition, but
  131. // it looks like Qt doesn't let us distinguish errors on opening.
  132. if (!QFile(filename).exists())
  133. return QJsonObject();
  134. QJsonParseError err;
  135. QJsonDocument json = Utils::OpenJsonDocument(filename, &err);
  136. if (json.isNull())
  137. {
  138. QLOG_ERROR() << "Could not open" << filename << "due to" << err.errorString();
  139. }
  140. return json.object();
  141. }
  142. ///////////////////////////////////////////////////////////////////////////////////////////////////
  143. static void writeJson(const QString& filename, const QJsonObject& data, bool pretty = true)
  144. {
  145. QJsonDocument json(data);
  146. writeFile(filename, json.toJson(pretty ? QJsonDocument::Indented : QJsonDocument::Compact));
  147. }
  148. /////////////////////////////////////////////////////////////////////////////////////////
  149. QVariant SettingsComponent::readPreinitValue(const QString& sectionID, const QString& key)
  150. {
  151. QJsonObject json = loadJson(Paths::dataDir("plexmediaplayer.conf"));
  152. return json["sections"].toObject()[sectionID].toObject()[key].toVariant();
  153. }
  154. /////////////////////////////////////////////////////////////////////////////////////////
  155. void SettingsComponent::load()
  156. {
  157. loadConf(Paths::dataDir("plexmediaplayer.conf"), false);
  158. loadConf(Paths::dataDir("storage.json"), true);
  159. }
  160. ///////////////////////////////////////////////////////////////////////////////////////////////////
  161. void SettingsComponent::loadConf(const QString& path, bool storage)
  162. {
  163. QJsonObject json = loadJson(path);
  164. int version = json["version"].toInt(0);
  165. if (version != m_settingsVersion)
  166. {
  167. QString backup = path + ".broken";
  168. QFile::remove(backup);
  169. QFile::rename(path, backup);
  170. if (version == 0)
  171. QLOG_ERROR() << "Could not read config file.";
  172. else
  173. QLOG_ERROR() << "Config version is" << version << "but" << m_settingsVersion << "expected. Moving old config to" << backup;
  174. // Overwrite/create it with the defaults.
  175. if (storage)
  176. saveStorage();
  177. else
  178. saveSettings();
  179. return;
  180. }
  181. QJsonObject jsonSections = json["sections"].toObject();
  182. for(const QString& section : jsonSections.keys())
  183. {
  184. QJsonObject jsonSection = jsonSections[section].toObject();
  185. SettingsSection* sec = getSection(section);
  186. if (!sec && storage)
  187. {
  188. sec = new SettingsSection(section, PLATFORM_ANY, -1, this);
  189. sec->setHidden(true);
  190. sec->setStorage(true);
  191. m_sections.insert(section, sec);
  192. }
  193. else if (!sec)
  194. {
  195. QLOG_ERROR() << "Trying to load section:" << section << "from config file, but we don't want that.";
  196. continue;
  197. }
  198. for(const QString& setting : jsonSection.keys())
  199. sec->setValue(setting, jsonSection.value(setting).toVariant());
  200. }
  201. }
  202. ///////////////////////////////////////////////////////////////////////////////////////////////////
  203. void SettingsComponent::saveSettings()
  204. {
  205. if (m_oldestPreviousVersion.isEmpty())
  206. {
  207. QLOG_ERROR() << "Not writing settings: uninitialized.\n";
  208. return;
  209. }
  210. QVariantMap sections;
  211. for(SettingsSection* section : m_sections.values())
  212. {
  213. if (!section->isStorage())
  214. sections.insert(section->sectionName(), section->allValues());
  215. }
  216. QJsonObject json;
  217. json.insert("sections", QJsonValue::fromVariant(sections));
  218. json.insert("version", m_settingsVersion);
  219. writeJson(Paths::dataDir("plexmediaplayer.conf"), json);
  220. }
  221. ///////////////////////////////////////////////////////////////////////////////////////////////////
  222. void SettingsComponent::saveStorage()
  223. {
  224. QVariantMap storage;
  225. for(SettingsSection* section : m_sections.values())
  226. {
  227. if (section->isStorage())
  228. storage.insert(section->sectionName(), section->allValues());
  229. }
  230. QJsonObject storagejson;
  231. storagejson.insert("sections", QJsonValue::fromVariant(storage));
  232. storagejson.insert("version", m_settingsVersion);
  233. writeJson(Paths::dataDir("storage.json"), storagejson, false);
  234. }
  235. ///////////////////////////////////////////////////////////////////////////////////////////////////
  236. void SettingsComponent::saveSection(SettingsSection* section)
  237. {
  238. if (section && section->isStorage())
  239. saveStorage();
  240. else
  241. saveSettings();
  242. }
  243. ///////////////////////////////////////////////////////////////////////////////////////////////////
  244. QVariant SettingsComponent::value(const QString& sectionID, const QString &key)
  245. {
  246. SettingsSection* section = getSection(sectionID);
  247. if (!section)
  248. {
  249. QLOG_ERROR() << "Section" << sectionID << "is unknown";
  250. return QVariant();
  251. }
  252. return section->value(key);
  253. }
  254. ///////////////////////////////////////////////////////////////////////////////////////////////////
  255. void SettingsComponent::setValue(const QString& sectionID, const QString &key, const QVariant &value)
  256. {
  257. SettingsSection* section = getSection(sectionID);
  258. if (!section)
  259. {
  260. QLOG_ERROR() << "Section" << sectionID << "is unknown";
  261. return;
  262. }
  263. section->setValue(key, value);
  264. saveSection(section);
  265. }
  266. ///////////////////////////////////////////////////////////////////////////////////////////////////
  267. void SettingsComponent::setValues(const QVariantMap& options)
  268. {
  269. Q_ASSERT(options.contains("key"));
  270. Q_ASSERT(options.contains("value"));
  271. QString key = options["key"].toString();
  272. QVariant values = options["value"];
  273. if (values.type() == QVariant::Map || values.isNull())
  274. {
  275. SettingsSection* section = getSection(key);
  276. if (!section)
  277. {
  278. // let's create this section since it's most likely created by the webclient
  279. section = new SettingsSection(key, PLATFORM_ANY, -1, this);
  280. section->setHidden(true);
  281. section->setStorage(true);
  282. m_sections.insert(key, section);
  283. }
  284. if (values.isNull())
  285. section->resetValues();
  286. else
  287. section->setValues(values);
  288. saveSection(section);
  289. }
  290. else if (values.type() == QVariant::String)
  291. {
  292. setValue(SETTINGS_SECTION_WEBCLIENT, key, values);
  293. }
  294. else
  295. {
  296. QLOG_WARN() << "the values sent was not a map, string or empty value. it will be ignored";
  297. // return so we don't call save()
  298. return;
  299. }
  300. }
  301. ///////////////////////////////////////////////////////////////////////////////////////////////////
  302. void SettingsComponent::removeValue(const QString &sectionOrKey)
  303. {
  304. SettingsSection* section = getSection(sectionOrKey);
  305. if (section)
  306. {
  307. // we want to remove a full section
  308. // dont remove the section, but remove all keys
  309. section->resetValues();
  310. saveSection(section);
  311. }
  312. else
  313. {
  314. // we want to remove a root key from webclient
  315. // which is stored in webclient section
  316. section = m_sections[SETTINGS_SECTION_WEBCLIENT];
  317. section->resetValue(sectionOrKey);
  318. saveSection(section);
  319. }
  320. }
  321. ///////////////////////////////////////////////////////////////////////////////////////////////////
  322. void SettingsComponent::resetToDefault(const QString &sectionID)
  323. {
  324. SettingsSection* section = getSection(sectionID);
  325. if (section)
  326. {
  327. section->resetValues();
  328. saveSection(section);
  329. }
  330. }
  331. ///////////////////////////////////////////////////////////////////////////////////////////////////
  332. void SettingsComponent::resetToDefaultAll()
  333. {
  334. for(SettingsSection *section : m_sections)
  335. {
  336. section->resetValues();
  337. saveSection(section);
  338. }
  339. }
  340. /////////////////////////////////////////////////////////////////////////////////////////
  341. struct SectionOrderIndex
  342. {
  343. inline bool operator ()(SettingsSection* a, SettingsSection* b)
  344. {
  345. return a->orderIndex() < b->orderIndex();
  346. }
  347. };
  348. ///////////////////////////////////////////////////////////////////////////////////////////////////
  349. QVariantList SettingsComponent::settingDescriptions()
  350. {
  351. QJsonArray desc;
  352. QList<SettingsSection*> sectionList = m_sections.values();
  353. std::sort(sectionList.begin(), sectionList.end(), SectionOrderIndex());
  354. for(SettingsSection* section : sectionList)
  355. {
  356. if (!section->isHidden())
  357. desc.push_back(QJsonValue::fromVariant(section->descriptions()));
  358. }
  359. return desc.toVariantList();
  360. }
  361. /////////////////////////////////////////////////////////////////////////////////////////
  362. bool SettingsComponent::loadDescription()
  363. {
  364. QJsonParseError err;
  365. auto doc = Utils::OpenJsonDocument(":/settings/settings_description.json", &err);
  366. if (doc.isNull())
  367. {
  368. QLOG_ERROR() << "Failed to read settings description:" << err.errorString();
  369. throw FatalException("Failed to read settings description!");
  370. }
  371. if (!doc.isArray())
  372. {
  373. QLOG_ERROR() << "The object needs to be an array";
  374. return false;
  375. }
  376. m_sectionIndex = 0;
  377. for(const QJsonValue& val : doc.array())
  378. {
  379. if (!val.isObject())
  380. {
  381. QLOG_ERROR() << "Hoped to find sections in the root array, but they where not JSON objects";
  382. return false;
  383. }
  384. QJsonObject section = val.toObject();
  385. if (!section.contains("section"))
  386. {
  387. QLOG_ERROR() << "A section needs to contain the section keyword.";
  388. return false;
  389. }
  390. if (section["section"] == "__meta__")
  391. m_settingsVersion = section.value("version").toInt();
  392. else
  393. parseSection(section);
  394. }
  395. return true;
  396. }
  397. /////////////////////////////////////////////////////////////////////////////////////////
  398. void SettingsComponent::parseSection(const QJsonObject& sectionObject)
  399. {
  400. QString sectionName = sectionObject.value("section").toString();
  401. if (!sectionObject.contains("values") || !sectionObject.value("values").isArray())
  402. {
  403. QLOG_ERROR() << "section object:" << sectionName << "did not contain a values array";
  404. return;
  405. }
  406. int platformMask = platformMaskFromObject(sectionObject);
  407. auto section = new SettingsSection(sectionName, (quint8)platformMask, m_sectionIndex ++, this);
  408. section->setHidden(sectionObject.value("hidden").toBool(false));
  409. section->setStorage(sectionObject.value("storage").toBool(false));
  410. auto values = sectionObject.value("values").toArray();
  411. int order = 0;
  412. for(auto val : values)
  413. {
  414. if (!val.isObject())
  415. continue;
  416. QJsonObject valobj = val.toObject();
  417. if (!valobj.contains("value") || !valobj.contains("default") || valobj.value("value").isNull())
  418. continue;
  419. QJsonValue defaults = valobj.value("default");
  420. QVariant defaultval = defaults.toVariant();
  421. if (defaults.isArray())
  422. {
  423. defaultval = QVariant();
  424. // Whichever default matches the current platform first is used.
  425. for(const auto& v : defaults.toArray())
  426. {
  427. auto vobj = v.toObject();
  428. int defPlatformMask = platformMaskFromObject(vobj);
  429. if ((defPlatformMask & Utils::CurrentPlatform()) == Utils::CurrentPlatform())
  430. {
  431. defaultval = vobj.value("value").toVariant();
  432. break;
  433. }
  434. }
  435. }
  436. int vPlatformMask = platformMaskFromObject(valobj);
  437. SettingsValue* setting = new SettingsValue(valobj.value("value").toString(), defaultval, (quint8)vPlatformMask, this);
  438. setting->setHasDescription(true);
  439. setting->setHidden(valobj.value("hidden").toBool(false));
  440. setting->setIndexOrder(order ++);
  441. if (valobj.contains("input_type"))
  442. setting->setInputType(valobj.value("input_type").toString());
  443. if (valobj.contains("possible_values") && valobj.value("possible_values").isArray())
  444. {
  445. auto list = valobj.value("possible_values").toArray();
  446. for(const auto& v : list)
  447. {
  448. int platform = PLATFORM_ANY;
  449. auto vl = v.toArray();
  450. if (vl.size() < 2)
  451. continue;
  452. if (vl.size() == 3 && vl.at(2).isObject())
  453. {
  454. // platform options
  455. QJsonObject options = vl.at(2).toObject();
  456. platform = platformMaskFromObject(options);
  457. }
  458. if ((platform & Utils::CurrentPlatform()) == Utils::CurrentPlatform())
  459. setting->addPossibleValue(vl.at(1).toString(), vl.at(0).toVariant());
  460. }
  461. }
  462. section->registerSetting(setting);
  463. }
  464. m_sections.insert(sectionName, section);
  465. }
  466. /////////////////////////////////////////////////////////////////////////////////////////
  467. int SettingsComponent::platformMaskFromObject(const QJsonObject& object)
  468. {
  469. int platformMask = PLATFORM_ANY;
  470. // only include the listed platforms
  471. if (object.contains("platforms"))
  472. {
  473. // start by resetting it to no platforms
  474. platformMask = PLATFORM_UNKNOWN;
  475. QJsonValue platforms = object.value("platforms");
  476. // platforms can be both array or a single string
  477. if (platforms.isArray())
  478. {
  479. for(const QJsonValue& pl : platforms.toArray())
  480. {
  481. if (!pl.isString())
  482. continue;
  483. platformMask |= platformFromString(pl.toString());
  484. }
  485. }
  486. else
  487. {
  488. platformMask = platformFromString(platforms.toString());
  489. }
  490. }
  491. else if (object.contains("platforms_excluded"))
  492. {
  493. QJsonValue val = object.value("platforms_excluded");
  494. if (val.isArray())
  495. {
  496. for(const QJsonValue& pl : val.toArray())
  497. {
  498. if (!pl.isString())
  499. continue;
  500. platformMask &= ~platformFromString(pl.toString());
  501. }
  502. }
  503. else
  504. {
  505. platformMask &= ~platformFromString(val.toString());
  506. }
  507. }
  508. return platformMask;
  509. }
  510. /////////////////////////////////////////////////////////////////////////////////////////
  511. Platform SettingsComponent::platformFromString(const QString& platformString)
  512. {
  513. if (platformString == "osx")
  514. return PLATFORM_OSX;
  515. else if (platformString == "windows")
  516. return PLATFORM_WINDOWS;
  517. else if (platformString == "linux")
  518. return PLATFORM_LINUX;
  519. else if (platformString == "oe")
  520. return PLATFORM_OE;
  521. else if (platformString == "oe_rpi")
  522. return PLATFORM_OE_RPI;
  523. else if (platformString == "oe_x86")
  524. return PLATFORM_OE_X86;
  525. else if (platformString == "any")
  526. return PLATFORM_ANY;
  527. return PLATFORM_UNKNOWN;
  528. }
  529. /////////////////////////////////////////////////////////////////////////////////////////
  530. bool SettingsComponent::componentInitialize()
  531. {
  532. if (!loadDescription())
  533. return false;
  534. // Must be called before we possibly write the config file.
  535. setupVersion();
  536. load();
  537. // add our AudioSettingsController that will inspect audio settings and react.
  538. // then run the signal the first time to make sure that we set the proper visibility
  539. // on the items from the start.
  540. //
  541. auto ctrl = new AudioSettingsController(this);
  542. QVariantMap val;
  543. val.insert("devicetype", value(SETTINGS_SECTION_AUDIO, "devicetype"));
  544. val.insert("advanced", value(SETTINGS_SECTION_AUDIO, "advanced"));
  545. ctrl->valuesUpdated(val);
  546. connect(ctrl, &AudioSettingsController::settingsUpdated, this, &SettingsComponent::groupUpdate);
  547. return true;
  548. }
  549. /////////////////////////////////////////////////////////////////////////////////////////
  550. void SettingsComponent::setupVersion()
  551. {
  552. QSettings settings;
  553. m_oldestPreviousVersion = settings.value(OLDEST_PREVIOUS_VERSION_KEY).toString();
  554. if (m_oldestPreviousVersion.isEmpty())
  555. {
  556. // Version key was not present. It could still be a pre-1.1 PMP install,
  557. // so here we try to find out whether this is the very first install, or
  558. // if an older one exists.
  559. QFile configFile(Paths::dataDir("plexmediaplayer.conf"));
  560. if (configFile.exists())
  561. m_oldestPreviousVersion = "legacy";
  562. else
  563. m_oldestPreviousVersion = Version::GetVersionString();
  564. settings.setValue(OLDEST_PREVIOUS_VERSION_KEY, m_oldestPreviousVersion);
  565. }
  566. }
  567. /////////////////////////////////////////////////////////////////////////////////////////
  568. void SettingsComponent::setUserRoleList(const QStringList& userRoles)
  569. {
  570. QVariantList values;
  571. // stable is always available
  572. QVariantMap stable;
  573. stable.insert("value", 0);
  574. stable.insert("title", "Stable");
  575. values << stable;
  576. for(const QString& role : userRoles)
  577. {
  578. QVariantMap channel;
  579. int value = 0;
  580. QString title;
  581. if (role == "ninja")
  582. {
  583. value = 4;
  584. title = "Ninja";
  585. }
  586. else if (role == "plexpass")
  587. {
  588. value = 8;
  589. title = "PlexPass";
  590. }
  591. else if (role == "employee")
  592. {
  593. value = 2;
  594. title = "Employee";
  595. }
  596. channel.insert("value", value);
  597. channel.insert("title", title);
  598. values << channel;
  599. }
  600. updatePossibleValues(SETTINGS_SECTION_MAIN, "updateChannel", values);
  601. }
  602. /////////////////////////////////////////////////////////////////////////////////////////
  603. bool SettingsComponent::resetAndSaveOldConfiguration()
  604. {
  605. QFile settingsFile(Paths::dataDir("plexmediaplayer.conf"));
  606. return settingsFile.rename(Paths::dataDir("plexmediaplayer.conf.old"));
  607. }
  608. /////////////////////////////////////////////////////////////////////////////////////////
  609. QString SettingsComponent::getWebClientUrl()
  610. {
  611. auto mode = SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode").toString();
  612. QString url;
  613. if (url == "desktop")
  614. url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_desktop").toString();
  615. else
  616. url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_tv").toString();
  617. // Transition to the new value so that old users are not screwed.
  618. if (url == "qrc:/konvergo/index.html")
  619. {
  620. SettingsComponent::Get().setValue(SETTINGS_SECTION_PATH, "startupurl", "bundled");
  621. url = "bundled";
  622. }
  623. if (url == "bundled")
  624. {
  625. auto path = Paths::webClientPath(mode);
  626. if (path.startsWith("/"))
  627. url = "file://" + path;
  628. url = "file:///" + path;
  629. }
  630. QLOG_DEBUG() << "Using web-client URL: " << url;
  631. return url;
  632. }