SettingsComponent.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. bool migrateTvMode = false;
  164. QJsonObject json = loadJson(path);
  165. int version = json["version"].toInt(0);
  166. // Migrate to settings version 4
  167. if (version == 3 && m_settingsVersion == 4)
  168. {
  169. // We only need to make sure that old users have the
  170. // webmode set to "tv" so that we don't flip their
  171. // interface unnecessarly
  172. migrateTvMode = true;
  173. }
  174. else if (version != m_settingsVersion)
  175. {
  176. QString backup = path + ".broken";
  177. QFile::remove(backup);
  178. QFile::rename(path, backup);
  179. if (version == 0)
  180. QLOG_ERROR() << "Could not read config file.";
  181. else
  182. QLOG_ERROR() << "Config version is" << version << "but" << m_settingsVersion << "expected. Moving old config to" << backup;
  183. // Overwrite/create it with the defaults.
  184. if (storage)
  185. saveStorage();
  186. else
  187. saveSettings();
  188. return;
  189. }
  190. QJsonObject jsonSections = json["sections"].toObject();
  191. for(const QString& section : jsonSections.keys())
  192. {
  193. QJsonObject jsonSection = jsonSections[section].toObject();
  194. SettingsSection* sec = getSection(section);
  195. if (!sec && storage)
  196. {
  197. sec = new SettingsSection(section, PLATFORM_ANY, -1, this);
  198. sec->setHidden(true);
  199. sec->setStorage(true);
  200. m_sections.insert(section, sec);
  201. }
  202. else if (!sec)
  203. {
  204. QLOG_ERROR() << "Trying to load section:" << section << "from config file, but we don't want that.";
  205. continue;
  206. }
  207. for(const QString& setting : jsonSection.keys())
  208. sec->setValue(setting, jsonSection.value(setting).toVariant());
  209. }
  210. if (migrateTvMode)
  211. getSection(SETTINGS_SECTION_MAIN)->setValue("webMode", "tv");
  212. }
  213. ///////////////////////////////////////////////////////////////////////////////////////////////////
  214. void SettingsComponent::saveSettings()
  215. {
  216. if (m_oldestPreviousVersion.isEmpty())
  217. {
  218. QLOG_ERROR() << "Not writing settings: uninitialized.\n";
  219. return;
  220. }
  221. QVariantMap sections;
  222. for(SettingsSection* section : m_sections.values())
  223. {
  224. if (!section->isStorage())
  225. sections.insert(section->sectionName(), section->allValues());
  226. }
  227. QJsonObject json;
  228. json.insert("sections", QJsonValue::fromVariant(sections));
  229. json.insert("version", m_settingsVersion);
  230. writeJson(Paths::dataDir("plexmediaplayer.conf"), json);
  231. }
  232. ///////////////////////////////////////////////////////////////////////////////////////////////////
  233. void SettingsComponent::saveStorage()
  234. {
  235. QVariantMap storage;
  236. for(SettingsSection* section : m_sections.values())
  237. {
  238. if (section->isStorage())
  239. storage.insert(section->sectionName(), section->allValues());
  240. }
  241. QJsonObject storagejson;
  242. storagejson.insert("sections", QJsonValue::fromVariant(storage));
  243. storagejson.insert("version", m_settingsVersion);
  244. writeJson(Paths::dataDir("storage.json"), storagejson, false);
  245. }
  246. ///////////////////////////////////////////////////////////////////////////////////////////////////
  247. void SettingsComponent::saveSection(SettingsSection* section)
  248. {
  249. if (section && section->isStorage())
  250. saveStorage();
  251. else
  252. saveSettings();
  253. }
  254. ///////////////////////////////////////////////////////////////////////////////////////////////////
  255. QVariant SettingsComponent::value(const QString& sectionID, const QString &key)
  256. {
  257. SettingsSection* section = getSection(sectionID);
  258. if (!section)
  259. {
  260. QLOG_ERROR() << "Section" << sectionID << "is unknown";
  261. return QVariant();
  262. }
  263. return section->value(key);
  264. }
  265. ///////////////////////////////////////////////////////////////////////////////////////////////////
  266. void SettingsComponent::setValue(const QString& sectionID, const QString &key, const QVariant &value)
  267. {
  268. SettingsSection* section = getSection(sectionID);
  269. if (!section)
  270. {
  271. QLOG_ERROR() << "Section" << sectionID << "is unknown";
  272. return;
  273. }
  274. section->setValue(key, value);
  275. saveSection(section);
  276. }
  277. ///////////////////////////////////////////////////////////////////////////////////////////////////
  278. void SettingsComponent::setValues(const QVariantMap& options)
  279. {
  280. Q_ASSERT(options.contains("key"));
  281. Q_ASSERT(options.contains("value"));
  282. QString key = options["key"].toString();
  283. QVariant values = options["value"];
  284. if (values.type() == QVariant::Map || values.isNull())
  285. {
  286. SettingsSection* section = getSection(key);
  287. if (!section)
  288. {
  289. // let's create this section since it's most likely created by the webclient
  290. section = new SettingsSection(key, PLATFORM_ANY, -1, this);
  291. section->setHidden(true);
  292. section->setStorage(true);
  293. m_sections.insert(key, section);
  294. }
  295. if (values.isNull())
  296. section->resetValues();
  297. else
  298. section->setValues(values);
  299. saveSection(section);
  300. }
  301. else if (values.type() == QVariant::String)
  302. {
  303. setValue(SETTINGS_SECTION_WEBCLIENT, key, values);
  304. }
  305. else
  306. {
  307. QLOG_WARN() << "the values sent was not a map, string or empty value. it will be ignored";
  308. // return so we don't call save()
  309. return;
  310. }
  311. }
  312. ///////////////////////////////////////////////////////////////////////////////////////////////////
  313. void SettingsComponent::removeValue(const QString &sectionOrKey)
  314. {
  315. SettingsSection* section = getSection(sectionOrKey);
  316. if (section)
  317. {
  318. // we want to remove a full section
  319. // dont remove the section, but remove all keys
  320. section->resetValues();
  321. saveSection(section);
  322. }
  323. else
  324. {
  325. // we want to remove a root key from webclient
  326. // which is stored in webclient section
  327. section = m_sections[SETTINGS_SECTION_WEBCLIENT];
  328. section->resetValue(sectionOrKey);
  329. saveSection(section);
  330. }
  331. }
  332. ///////////////////////////////////////////////////////////////////////////////////////////////////
  333. void SettingsComponent::resetToDefault(const QString &sectionID)
  334. {
  335. SettingsSection* section = getSection(sectionID);
  336. if (section)
  337. {
  338. section->resetValues();
  339. saveSection(section);
  340. }
  341. }
  342. ///////////////////////////////////////////////////////////////////////////////////////////////////
  343. void SettingsComponent::resetToDefaultAll()
  344. {
  345. for(SettingsSection *section : m_sections)
  346. {
  347. section->resetValues();
  348. saveSection(section);
  349. }
  350. }
  351. /////////////////////////////////////////////////////////////////////////////////////////
  352. struct SectionOrderIndex
  353. {
  354. inline bool operator ()(SettingsSection* a, SettingsSection* b)
  355. {
  356. return a->orderIndex() < b->orderIndex();
  357. }
  358. };
  359. ///////////////////////////////////////////////////////////////////////////////////////////////////
  360. QVariantList SettingsComponent::settingDescriptions()
  361. {
  362. QJsonArray desc;
  363. QList<SettingsSection*> sectionList = m_sections.values();
  364. std::sort(sectionList.begin(), sectionList.end(), SectionOrderIndex());
  365. for(SettingsSection* section : sectionList)
  366. {
  367. if (!section->isHidden())
  368. desc.push_back(QJsonValue::fromVariant(section->descriptions()));
  369. }
  370. return desc.toVariantList();
  371. }
  372. /////////////////////////////////////////////////////////////////////////////////////////
  373. bool SettingsComponent::loadDescription()
  374. {
  375. QJsonParseError err;
  376. auto doc = Utils::OpenJsonDocument(":/settings/settings_description.json", &err);
  377. if (doc.isNull())
  378. {
  379. QLOG_ERROR() << "Failed to read settings description:" << err.errorString();
  380. throw FatalException("Failed to read settings description!");
  381. }
  382. if (!doc.isArray())
  383. {
  384. QLOG_ERROR() << "The object needs to be an array";
  385. return false;
  386. }
  387. m_sectionIndex = 0;
  388. for(const QJsonValue& val : doc.array())
  389. {
  390. if (!val.isObject())
  391. {
  392. QLOG_ERROR() << "Hoped to find sections in the root array, but they where not JSON objects";
  393. return false;
  394. }
  395. QJsonObject section = val.toObject();
  396. if (!section.contains("section"))
  397. {
  398. QLOG_ERROR() << "A section needs to contain the section keyword.";
  399. return false;
  400. }
  401. if (section["section"] == "__meta__")
  402. m_settingsVersion = section.value("version").toInt();
  403. else
  404. parseSection(section);
  405. }
  406. return true;
  407. }
  408. /////////////////////////////////////////////////////////////////////////////////////////
  409. void SettingsComponent::parseSection(const QJsonObject& sectionObject)
  410. {
  411. QString sectionName = sectionObject.value("section").toString();
  412. if (!sectionObject.contains("values") || !sectionObject.value("values").isArray())
  413. {
  414. QLOG_ERROR() << "section object:" << sectionName << "did not contain a values array";
  415. return;
  416. }
  417. int platformMask = platformMaskFromObject(sectionObject);
  418. auto section = new SettingsSection(sectionName, (quint8)platformMask, m_sectionIndex ++, this);
  419. section->setHidden(sectionObject.value("hidden").toBool(false));
  420. section->setStorage(sectionObject.value("storage").toBool(false));
  421. auto values = sectionObject.value("values").toArray();
  422. int order = 0;
  423. for(auto val : values)
  424. {
  425. if (!val.isObject())
  426. continue;
  427. QJsonObject valobj = val.toObject();
  428. if (!valobj.contains("value") || !valobj.contains("default") || valobj.value("value").isNull())
  429. continue;
  430. QJsonValue defaults = valobj.value("default");
  431. QVariant defaultval = defaults.toVariant();
  432. if (defaults.isArray())
  433. {
  434. defaultval = QVariant();
  435. // Whichever default matches the current platform first is used.
  436. for(const auto& v : defaults.toArray())
  437. {
  438. auto vobj = v.toObject();
  439. int defPlatformMask = platformMaskFromObject(vobj);
  440. if ((defPlatformMask & Utils::CurrentPlatform()) == Utils::CurrentPlatform())
  441. {
  442. defaultval = vobj.value("value").toVariant();
  443. break;
  444. }
  445. }
  446. }
  447. int vPlatformMask = platformMaskFromObject(valobj);
  448. SettingsValue* setting = new SettingsValue(valobj.value("value").toString(), defaultval, (quint8)vPlatformMask, this);
  449. setting->setHasDescription(true);
  450. setting->setHidden(valobj.value("hidden").toBool(false));
  451. setting->setIndexOrder(order ++);
  452. if (valobj.contains("input_type"))
  453. setting->setInputType(valobj.value("input_type").toString());
  454. if (valobj.contains("possible_values") && valobj.value("possible_values").isArray())
  455. {
  456. auto list = valobj.value("possible_values").toArray();
  457. for(const auto& v : list)
  458. {
  459. int platform = PLATFORM_ANY;
  460. auto vl = v.toArray();
  461. if (vl.size() < 2)
  462. continue;
  463. if (vl.size() == 3 && vl.at(2).isObject())
  464. {
  465. // platform options
  466. QJsonObject options = vl.at(2).toObject();
  467. platform = platformMaskFromObject(options);
  468. }
  469. if ((platform & Utils::CurrentPlatform()) == Utils::CurrentPlatform())
  470. setting->addPossibleValue(vl.at(1).toString(), vl.at(0).toVariant());
  471. }
  472. }
  473. section->registerSetting(setting);
  474. }
  475. m_sections.insert(sectionName, section);
  476. }
  477. /////////////////////////////////////////////////////////////////////////////////////////
  478. int SettingsComponent::platformMaskFromObject(const QJsonObject& object)
  479. {
  480. int platformMask = PLATFORM_ANY;
  481. // only include the listed platforms
  482. if (object.contains("platforms"))
  483. {
  484. // start by resetting it to no platforms
  485. platformMask = PLATFORM_UNKNOWN;
  486. QJsonValue platforms = object.value("platforms");
  487. // platforms can be both array or a single string
  488. if (platforms.isArray())
  489. {
  490. for(const QJsonValue& pl : platforms.toArray())
  491. {
  492. if (!pl.isString())
  493. continue;
  494. platformMask |= platformFromString(pl.toString());
  495. }
  496. }
  497. else
  498. {
  499. platformMask = platformFromString(platforms.toString());
  500. }
  501. }
  502. else if (object.contains("platforms_excluded"))
  503. {
  504. QJsonValue val = object.value("platforms_excluded");
  505. if (val.isArray())
  506. {
  507. for(const QJsonValue& pl : val.toArray())
  508. {
  509. if (!pl.isString())
  510. continue;
  511. platformMask &= ~platformFromString(pl.toString());
  512. }
  513. }
  514. else
  515. {
  516. platformMask &= ~platformFromString(val.toString());
  517. }
  518. }
  519. return platformMask;
  520. }
  521. /////////////////////////////////////////////////////////////////////////////////////////
  522. Platform SettingsComponent::platformFromString(const QString& platformString)
  523. {
  524. if (platformString == "osx")
  525. return PLATFORM_OSX;
  526. else if (platformString == "windows")
  527. return PLATFORM_WINDOWS;
  528. else if (platformString == "linux")
  529. return PLATFORM_LINUX;
  530. else if (platformString == "oe")
  531. return PLATFORM_OE;
  532. else if (platformString == "oe_rpi")
  533. return PLATFORM_OE_RPI;
  534. else if (platformString == "oe_x86")
  535. return PLATFORM_OE_X86;
  536. else if (platformString == "any")
  537. return PLATFORM_ANY;
  538. return PLATFORM_UNKNOWN;
  539. }
  540. /////////////////////////////////////////////////////////////////////////////////////////
  541. bool SettingsComponent::componentInitialize()
  542. {
  543. if (!loadDescription())
  544. return false;
  545. // Must be called before we possibly write the config file.
  546. setupVersion();
  547. load();
  548. // add our AudioSettingsController that will inspect audio settings and react.
  549. // then run the signal the first time to make sure that we set the proper visibility
  550. // on the items from the start.
  551. //
  552. auto ctrl = new AudioSettingsController(this);
  553. QVariantMap val;
  554. val.insert("devicetype", value(SETTINGS_SECTION_AUDIO, "devicetype"));
  555. val.insert("advanced", value(SETTINGS_SECTION_AUDIO, "advanced"));
  556. ctrl->valuesUpdated(val);
  557. connect(ctrl, &AudioSettingsController::settingsUpdated, this, &SettingsComponent::groupUpdate);
  558. return true;
  559. }
  560. /////////////////////////////////////////////////////////////////////////////////////////
  561. void SettingsComponent::setupVersion()
  562. {
  563. QSettings settings;
  564. m_oldestPreviousVersion = settings.value(OLDEST_PREVIOUS_VERSION_KEY).toString();
  565. if (m_oldestPreviousVersion.isEmpty())
  566. {
  567. // Version key was not present. It could still be a pre-1.1 PMP install,
  568. // so here we try to find out whether this is the very first install, or
  569. // if an older one exists.
  570. QFile configFile(Paths::dataDir("plexmediaplayer.conf"));
  571. if (configFile.exists())
  572. m_oldestPreviousVersion = "legacy";
  573. else
  574. m_oldestPreviousVersion = Version::GetVersionString();
  575. settings.setValue(OLDEST_PREVIOUS_VERSION_KEY, m_oldestPreviousVersion);
  576. }
  577. }
  578. /////////////////////////////////////////////////////////////////////////////////////////
  579. void SettingsComponent::setUserRoleList(const QStringList& userRoles)
  580. {
  581. QVariantList values;
  582. // stable is always available
  583. QVariantMap stable;
  584. stable.insert("value", 0);
  585. stable.insert("title", "Stable");
  586. values << stable;
  587. for(const QString& role : userRoles)
  588. {
  589. QVariantMap channel;
  590. int value = 0;
  591. QString title;
  592. if (role == "ninja")
  593. {
  594. value = 4;
  595. title = "Ninja";
  596. }
  597. else if (role == "plexpass")
  598. {
  599. value = 8;
  600. title = "PlexPass";
  601. }
  602. else if (role == "employee")
  603. {
  604. value = 2;
  605. title = "Employee";
  606. }
  607. channel.insert("value", value);
  608. channel.insert("title", title);
  609. values << channel;
  610. }
  611. updatePossibleValues(SETTINGS_SECTION_MAIN, "updateChannel", values);
  612. }
  613. /////////////////////////////////////////////////////////////////////////////////////////
  614. bool SettingsComponent::resetAndSaveOldConfiguration()
  615. {
  616. QFile settingsFile(Paths::dataDir("plexmediaplayer.conf"));
  617. return settingsFile.rename(Paths::dataDir("plexmediaplayer.conf.old"));
  618. }
  619. /////////////////////////////////////////////////////////////////////////////////////////
  620. QString SettingsComponent::getWebClientUrl(bool desktop)
  621. {
  622. QString url;
  623. #ifdef KONVERGO_OPENELEC
  624. desktop = false;
  625. #endif
  626. if (desktop)
  627. url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_desktop").toString();
  628. else
  629. url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_tv").toString();
  630. // Transition to the new value so that old users are not screwed.
  631. if (url == "qrc:/konvergo/index.html")
  632. {
  633. SettingsComponent::Get().setValue(SETTINGS_SECTION_PATH, "startupurl", "bundled");
  634. url = "bundled";
  635. }
  636. if (url == "bundled")
  637. {
  638. auto path = Paths::webClientPath(desktop ? "desktop" : "tv");
  639. if (path.startsWith("/"))
  640. url = "file://" + path;
  641. url = "file:///" + path;
  642. }
  643. QLOG_DEBUG() << "Using web-client URL: " << url;
  644. return url;
  645. }
  646. /////////////////////////////////////////////////////////////////////////////////////////
  647. void SettingsComponent::setCommandLineValues(const QStringList& values)
  648. {
  649. QLOG_DEBUG() << values;
  650. for (const QString& value : values)
  651. {
  652. if (value == "fullscreen")
  653. setValue(SETTINGS_SECTION_MAIN, "fullscreen", true);
  654. else if (value == "windowed")
  655. setValue(SETTINGS_SECTION_MAIN, "fullscreen", false);
  656. else if (value == "desktop")
  657. setValue(SETTINGS_SECTION_MAIN, "layout", "desktop");
  658. else if (value == "tv")
  659. setValue(SETTINGS_SECTION_MAIN, "layout", "tv");
  660. else if (value == "auto-layout")
  661. setValue(SETTINGS_SECTION_MAIN, "layout", "auto");
  662. }
  663. auto layout = value(SETTINGS_SECTION_MAIN, "layout").toString();
  664. if (layout != "auto")
  665. setValue(SETTINGS_SECTION_MAIN, "webMode", layout);
  666. }