This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathSettingsComponent.cpp
816 lines (712 loc) · 24.6 KB
/
SettingsComponent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
#include "SettingsComponent.h"
#include "SettingsSection.h"
#include "Paths.h"
#include "utils/Utils.h"
#include "QsLog.h"
#include "AudioSettingsController.h"
#include "Names.h"
#include <QSaveFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QList>
#include <QSettings>
#include "input/InputComponent.h"
#include "system/SystemComponent.h"
#include "Version.h"
#define OLDEST_PREVIOUS_VERSION_KEY "oldestPreviousVersion"
///////////////////////////////////////////////////////////////////////////////////////////////////
SettingsComponent::SettingsComponent(QObject *parent) : ComponentBase(parent), m_settingsVersion(-1)
{
}
/////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::componentPostInitialize()
{
InputComponent::Get().registerHostCommand("cycle_setting", this, "cycleSettingCommand");
InputComponent::Get().registerHostCommand("set_setting", this, "setSettingCommand");
}
/////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::cycleSettingCommand(const QString& args)
{
QString settingName = args;
QStringList sub = settingName.split(".");
if (sub.size() != 2)
{
QLOG_ERROR() << "Setting must be in the form section.name but got:" << settingName;
return;
}
QString sectionID = sub[0];
QString valueName = sub[1];
SettingsSection* section = getSection(sectionID);
if (!section)
{
QLOG_ERROR() << "Section" << sectionID << "is unknown";
return;
}
QVariantList values = section->possibleValues(valueName);
// If no possible values are defined, check the type of the default value.
// In the case it's a boolean simply negate the current value to cycle through.
// Otherwise log an error message, that it's not possible to cycle through the value.
if (values.size() == 0)
{
if (section->defaultValue(valueName).type() == QVariant::Bool)
{
QVariant currentValue = section->value(valueName);
auto nextValue = currentValue.toBool() ? false : true;
setValue(sectionID, valueName, nextValue);
QLOG_DEBUG() << "Setting" << settingName << "to " << (nextValue ? "Enabled" : "Disabled");
emit SystemComponent::Get().settingsMessage(valueName, nextValue ? "Enabled" : "Disabled");
return;
}
else
{
QLOG_ERROR() << "Setting" << settingName << "is unknown or is not cycleable.";
return;
}
}
QVariant currentValue = section->value(valueName);
int nextValueIndex = 0;
for (int n = 0; n < values.size(); n++)
{
if (currentValue == values[n].toMap()["value"])
{
nextValueIndex = n + 1;
break;
}
}
if (nextValueIndex >= values.size())
nextValueIndex = 0;
auto nextSetting = values[nextValueIndex].toMap();
auto nextValue = nextSetting["value"];
QLOG_DEBUG() << "Setting" << settingName << "to" << nextValue;
setValue(sectionID, valueName, nextValue);
emit SystemComponent::Get().settingsMessage(valueName, nextSetting["title"].toString());
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::setSettingCommand(const QString& args)
{
int spaceIndex = args.indexOf(" ");
if (spaceIndex < 0)
{
QLOG_ERROR() << "No value provided to settings set command.";
return;
}
QString settingName = args.mid(0, spaceIndex);
QString settingValue = args.mid(spaceIndex + 1);
int subIndex = settingName.indexOf(".");
if (subIndex < 0 || subIndex == args.size() - 1)
{
QLOG_ERROR() << "Setting must be in the form section.name but got:" << settingName;
return;
}
QString sectionID = settingName.mid(0, subIndex);
QString valueName = settingName.mid(subIndex + 1);
SettingsSection* section = getSection(sectionID);
if (!section)
{
QLOG_ERROR() << "Section" << sectionID << "is unknown";
return;
}
QString jsonString = "{\"value\": " + settingValue + "}";
QJsonParseError err;
QVariant value = QJsonDocument::fromJson(jsonString.toUtf8(), &err).object()["value"].toVariant();
printf("val: '%s'\n", settingValue.toUtf8().data());
if (!value.isValid())
{
QLOG_ERROR() << "Invalid settings value:" << settingValue << "(if it's a string, make sure to quote it)";
return;
}
QLOG_DEBUG() << "Setting" << settingName << "to" << value;
setValue(sectionID, valueName, value);
emit SystemComponent::Get().settingsMessage(valueName, value.toString());
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::updatePossibleValues(const QString §ionID, const QString &key, const QVariantList &possibleValues)
{
SettingsSection* section = getSection(sectionID);
if (!section)
{
QLOG_ERROR() << "Section" << sectionID << "is unknown";
return;
}
section->updatePossibleValues(key, possibleValues);
QLOG_DEBUG() << "Updated possible values for:" << key << "to" << possibleValues;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
QVariant SettingsComponent::allValues(const QString& section)
{
if (section.isEmpty())
{
QVariantMap all;
for(const QString& sname : m_sections.keys())
all[sname] = m_sections[sname]->allValues();
return all;
}
else if (m_sections.contains(section))
{
return m_sections[section]->allValues();
}
else
{
// look for the value in the webclient section
return m_sections[SETTINGS_SECTION_WEBCLIENT]->value(section);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
static void writeFile(const QString& filename, const QByteArray& data)
{
QSaveFile file(filename);
file.open(QIODevice::WriteOnly | QIODevice::Text);
file.write(data);
if (!file.commit())
{
QLOG_ERROR() << "Could not write" << filename;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
static QJsonObject loadJson(const QString& filename)
{
// Checking existence before opening is technically a race condition, but
// it looks like Qt doesn't let us distinguish errors on opening.
if (!QFile(filename).exists())
return QJsonObject();
QJsonParseError err;
QJsonDocument json = Utils::OpenJsonDocument(filename, &err);
if (json.isNull())
{
QLOG_ERROR() << "Could not open" << filename << "due to" << err.errorString();
}
return json.object();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
static void writeJson(const QString& filename, const QJsonObject& data, bool pretty = true)
{
QJsonDocument json(data);
writeFile(filename, json.toJson(pretty ? QJsonDocument::Indented : QJsonDocument::Compact));
}
/////////////////////////////////////////////////////////////////////////////////////////
QVariant SettingsComponent::readPreinitValue(const QString& sectionID, const QString& key)
{
QJsonObject json = loadJson(Paths::dataDir("plexmediaplayer.conf"));
return json["sections"].toObject()[sectionID].toObject()[key].toVariant();
}
/////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::load()
{
loadConf(Paths::dataDir("plexmediaplayer.conf"), false);
loadConf(Paths::dataDir("storage.json"), true);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::loadConf(const QString& path, bool storage)
{
bool migrateTvMode = false;
QJsonObject json = loadJson(path);
int version = json["version"].toInt(0);
// Migrate to settings version 4
if (version == 3 && m_settingsVersion == 4)
{
// We only need to make sure that old users have the
// webmode set to "tv" so that we don't flip their
// interface unnecessarly
migrateTvMode = true;
}
else if (version != m_settingsVersion)
{
QString backup = path + ".broken";
QFile::remove(backup);
QFile::rename(path, backup);
if (version == 0)
QLOG_ERROR() << "Could not read config file.";
else
QLOG_ERROR() << "Config version is" << version << "but" << m_settingsVersion << "expected. Moving old config to" << backup;
// Overwrite/create it with the defaults.
if (storage)
saveStorage();
else
saveSettings();
return;
}
QJsonObject jsonSections = json["sections"].toObject();
for(const QString& section : jsonSections.keys())
{
QJsonObject jsonSection = jsonSections[section].toObject();
SettingsSection* sec = getSection(section);
if (!sec && storage)
{
sec = new SettingsSection(section, PLATFORM_ANY, -1, this);
sec->setHidden(true);
sec->setStorage(true);
m_sections.insert(section, sec);
}
else if (!sec)
{
QLOG_ERROR() << "Trying to load section:" << section << "from config file, but we don't want that.";
continue;
}
for(const QString& setting : jsonSection.keys())
sec->setValue(setting, jsonSection.value(setting).toVariant());
}
if (migrateTvMode)
getSection(SETTINGS_SECTION_MAIN)->setValue("webMode", "tv");
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::saveSettings()
{
if (m_oldestPreviousVersion.isEmpty())
{
QLOG_ERROR() << "Not writing settings: uninitialized.\n";
return;
}
QVariantMap sections;
for(SettingsSection* section : m_sections.values())
{
if (!section->isStorage())
sections.insert(section->sectionName(), section->allValues());
}
QJsonObject json;
json.insert("sections", QJsonValue::fromVariant(sections));
json.insert("version", m_settingsVersion);
writeJson(Paths::dataDir("plexmediaplayer.conf"), json);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::saveStorage()
{
QVariantMap storage;
for(SettingsSection* section : m_sections.values())
{
if (section->isStorage())
storage.insert(section->sectionName(), section->allValues());
}
QJsonObject storagejson;
storagejson.insert("sections", QJsonValue::fromVariant(storage));
storagejson.insert("version", m_settingsVersion);
writeJson(Paths::dataDir("storage.json"), storagejson, false);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::saveSection(SettingsSection* section)
{
if (section && section->isStorage())
saveStorage();
else
saveSettings();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
QVariant SettingsComponent::value(const QString& sectionID, const QString &key)
{
SettingsSection* section = getSection(sectionID);
if (!section)
{
QLOG_ERROR() << "Section" << sectionID << "is unknown";
return QVariant();
}
return section->value(key);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::setValue(const QString& sectionID, const QString &key, const QVariant &value)
{
SettingsSection* section = getSection(sectionID);
if (!section)
{
QLOG_ERROR() << "Section" << sectionID << "is unknown";
return;
}
section->setValue(key, value);
saveSection(section);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::setValues(const QVariantMap& options)
{
Q_ASSERT(options.contains("key"));
Q_ASSERT(options.contains("value"));
QString key = options["key"].toString();
QVariant values = options["value"];
if (values.type() == QVariant::Map || values.isNull())
{
SettingsSection* section = getSection(key);
if (!section)
{
// let's create this section since it's most likely created by the webclient
section = new SettingsSection(key, PLATFORM_ANY, -1, this);
section->setHidden(true);
section->setStorage(true);
m_sections.insert(key, section);
}
if (values.isNull())
section->resetValues();
else
section->setValues(values);
saveSection(section);
}
else if (values.type() == QVariant::String)
{
setValue(SETTINGS_SECTION_WEBCLIENT, key, values);
}
else
{
QLOG_WARN() << "the values sent was not a map, string or empty value. it will be ignored";
// return so we don't call save()
return;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::removeValue(const QString §ionOrKey)
{
SettingsSection* section = getSection(sectionOrKey);
if (section)
{
// we want to remove a full section
// dont remove the section, but remove all keys
section->resetValues();
saveSection(section);
}
else
{
// we want to remove a root key from webclient
// which is stored in webclient section
section = m_sections[SETTINGS_SECTION_WEBCLIENT];
section->resetValue(sectionOrKey);
saveSection(section);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::resetToDefault(const QString §ionID)
{
SettingsSection* section = getSection(sectionID);
if (section)
{
section->resetValues();
saveSection(section);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::resetToDefaultAll()
{
for(SettingsSection *section : m_sections)
{
section->resetValues();
saveSection(section);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
struct SectionOrderIndex
{
inline bool operator ()(SettingsSection* a, SettingsSection* b)
{
return a->orderIndex() < b->orderIndex();
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////
QVariantList SettingsComponent::settingDescriptions()
{
QJsonArray desc;
QList<SettingsSection*> sectionList = m_sections.values();
std::sort(sectionList.begin(), sectionList.end(), SectionOrderIndex());
for(SettingsSection* section : sectionList)
{
if (!section->isHidden())
desc.push_back(QJsonValue::fromVariant(section->descriptions()));
}
return desc.toVariantList();
}
/////////////////////////////////////////////////////////////////////////////////////////
bool SettingsComponent::loadDescription()
{
QJsonParseError err;
auto doc = Utils::OpenJsonDocument(":/settings/settings_description.json", &err);
if (doc.isNull())
{
QLOG_ERROR() << "Failed to read settings description:" << err.errorString();
throw FatalException("Failed to read settings description!");
}
if (!doc.isArray())
{
QLOG_ERROR() << "The object needs to be an array";
return false;
}
m_sectionIndex = 0;
for(const QJsonValue& val : doc.array())
{
if (!val.isObject())
{
QLOG_ERROR() << "Hoped to find sections in the root array, but they where not JSON objects";
return false;
}
QJsonObject section = val.toObject();
if (!section.contains("section"))
{
QLOG_ERROR() << "A section needs to contain the section keyword.";
return false;
}
if (section["section"] == "__meta__")
m_settingsVersion = section.value("version").toInt();
else
parseSection(section);
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::parseSection(const QJsonObject& sectionObject)
{
QString sectionName = sectionObject.value("section").toString();
if (!sectionObject.contains("values") || !sectionObject.value("values").isArray())
{
QLOG_ERROR() << "section object:" << sectionName << "did not contain a values array";
return;
}
int platformMask = platformMaskFromObject(sectionObject);
auto section = new SettingsSection(sectionName, (quint8)platformMask, m_sectionIndex ++, this);
section->setHidden(sectionObject.value("hidden").toBool(false));
section->setStorage(sectionObject.value("storage").toBool(false));
auto values = sectionObject.value("values").toArray();
int order = 0;
for(auto val : values)
{
if (!val.isObject())
continue;
QJsonObject valobj = val.toObject();
if (!valobj.contains("value") || !valobj.contains("default") || valobj.value("value").isNull())
continue;
QJsonValue defaults = valobj.value("default");
QVariant defaultval = defaults.toVariant();
if (defaults.isArray())
{
defaultval = QVariant();
// Whichever default matches the current platform first is used.
for(const auto& v : defaults.toArray())
{
auto vobj = v.toObject();
int defPlatformMask = platformMaskFromObject(vobj);
if ((defPlatformMask & Utils::CurrentPlatform()) == Utils::CurrentPlatform())
{
defaultval = vobj.value("value").toVariant();
break;
}
}
}
int vPlatformMask = platformMaskFromObject(valobj);
SettingsValue* setting = new SettingsValue(valobj.value("value").toString(), defaultval, (quint8)vPlatformMask, this);
setting->setHasDescription(true);
setting->setHidden(valobj.value("hidden").toBool(false));
setting->setIndexOrder(order ++);
if (valobj.contains("input_type"))
setting->setInputType(valobj.value("input_type").toString());
if (valobj.contains("possible_values") && valobj.value("possible_values").isArray())
{
auto list = valobj.value("possible_values").toArray();
for(const auto& v : list)
{
int platform = PLATFORM_ANY;
auto vl = v.toArray();
if (vl.size() < 2)
continue;
if (vl.size() == 3 && vl.at(2).isObject())
{
// platform options
QJsonObject options = vl.at(2).toObject();
platform = platformMaskFromObject(options);
}
if ((platform & Utils::CurrentPlatform()) == Utils::CurrentPlatform())
setting->addPossibleValue(vl.at(1).toString(), vl.at(0).toVariant());
}
}
section->registerSetting(setting);
}
m_sections.insert(sectionName, section);
}
/////////////////////////////////////////////////////////////////////////////////////////
int SettingsComponent::platformMaskFromObject(const QJsonObject& object)
{
int platformMask = PLATFORM_ANY;
// only include the listed platforms
if (object.contains("platforms"))
{
// start by resetting it to no platforms
platformMask = PLATFORM_UNKNOWN;
QJsonValue platforms = object.value("platforms");
// platforms can be both array or a single string
if (platforms.isArray())
{
for(const QJsonValue& pl : platforms.toArray())
{
if (!pl.isString())
continue;
platformMask |= platformFromString(pl.toString());
}
}
else
{
platformMask = platformFromString(platforms.toString());
}
}
else if (object.contains("platforms_excluded"))
{
QJsonValue val = object.value("platforms_excluded");
if (val.isArray())
{
for(const QJsonValue& pl : val.toArray())
{
if (!pl.isString())
continue;
platformMask &= ~platformFromString(pl.toString());
}
}
else
{
platformMask &= ~platformFromString(val.toString());
}
}
return platformMask;
}
/////////////////////////////////////////////////////////////////////////////////////////
Platform SettingsComponent::platformFromString(const QString& platformString)
{
if (platformString == "osx")
return PLATFORM_OSX;
else if (platformString == "windows")
return PLATFORM_WINDOWS;
else if (platformString == "linux")
return PLATFORM_LINUX;
else if (platformString == "oe")
return PLATFORM_OE;
else if (platformString == "oe_rpi")
return PLATFORM_OE_RPI;
else if (platformString == "oe_x86")
return PLATFORM_OE_X86;
else if (platformString == "any")
return PLATFORM_ANY;
return PLATFORM_UNKNOWN;
}
/////////////////////////////////////////////////////////////////////////////////////////
bool SettingsComponent::componentInitialize()
{
if (!loadDescription())
return false;
// Must be called before we possibly write the config file.
setupVersion();
load();
// add our AudioSettingsController that will inspect audio settings and react.
// then run the signal the first time to make sure that we set the proper visibility
// on the items from the start.
//
auto ctrl = new AudioSettingsController(this);
QVariantMap val;
val.insert("devicetype", value(SETTINGS_SECTION_AUDIO, "devicetype"));
ctrl->valuesUpdated(val);
connect(ctrl, &AudioSettingsController::settingsUpdated, this, &SettingsComponent::groupUpdate);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::setupVersion()
{
QSettings settings;
m_oldestPreviousVersion = settings.value(OLDEST_PREVIOUS_VERSION_KEY).toString();
if (m_oldestPreviousVersion.isEmpty())
{
// Version key was not present. It could still be a pre-1.1 PMP install,
// so here we try to find out whether this is the very first install, or
// if an older one exists.
QFile configFile(Paths::dataDir("plexmediaplayer.conf"));
if (configFile.exists())
m_oldestPreviousVersion = "legacy";
else
m_oldestPreviousVersion = Version::GetVersionString();
settings.setValue(OLDEST_PREVIOUS_VERSION_KEY, m_oldestPreviousVersion);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::setUserRoleList(const QStringList& userRoles)
{
QVariantList values;
// Channel names and values are aligned with values expected by plex.tv.
// See: https://github.com/plexinc/plex-media-player-private/issues/642
// Public is always available as the default value.
QVariantMap publicChannel;
publicChannel.insert("value", 0);
publicChannel.insert("title", "Public");
values << publicChannel;
if (userRoles.contains("plexpass")) {
QVariantMap betaChannel;
betaChannel.insert("value", 8);
betaChannel.insert("title", "Beta");
values << betaChannel;
}
if (userRoles.contains("ninja")) {
QVariantMap alphaChannel;
alphaChannel.insert("value", 4);
alphaChannel.insert("title", "Alpha");
values << alphaChannel;
}
if (userRoles.contains("employee")) {
QVariantMap qaChannel;
qaChannel.insert("value", 2);
qaChannel.insert("title", "QA");
values << qaChannel;
}
updatePossibleValues(SETTINGS_SECTION_MAIN, "updateChannel", values);
}
/////////////////////////////////////////////////////////////////////////////////////////
bool SettingsComponent::resetAndSaveOldConfiguration()
{
QFile settingsFile(Paths::dataDir("plexmediaplayer.conf"));
return settingsFile.rename(Paths::dataDir("plexmediaplayer.conf.old"));
}
/////////////////////////////////////////////////////////////////////////////////////////
QString SettingsComponent::getWebClientUrl(bool desktop)
{
QString url;
#ifdef KONVERGO_OPENELEC
desktop = false;
#endif
if (desktop)
url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_desktop").toString();
else
url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_tv").toString();
// Transition to the new value so that old users are not screwed.
if (url == "qrc:/konvergo/index.html")
{
SettingsComponent::Get().setValue(SETTINGS_SECTION_PATH, "startupurl", "bundled");
url = "bundled";
}
if (url == "bundled")
{
auto path = Paths::webClientPath(desktop ? "desktop" : "tv");
if (path.startsWith("/"))
url = "file://" + path;
url = "file:///" + path;
}
QLOG_DEBUG() << "Using web-client URL: " << url;
return url;
}
/////////////////////////////////////////////////////////////////////////////////////////
void SettingsComponent::setCommandLineValues(const QStringList& values)
{
QLOG_DEBUG() << values;
QString mode = ""; // unset, different from "auto"
for (const QString& value : values)
{
if (value == "fullscreen")
setValue(SETTINGS_SECTION_MAIN, "fullscreen", true);
else if (value == "windowed")
setValue(SETTINGS_SECTION_MAIN, "fullscreen", false);
else if (value == "desktop")
mode = "desktop";
else if (value == "tv")
mode = "tv";
else if (value == "auto-layout")
mode = "auto";
}
if (mode == "desktop")
{
setValue(SETTINGS_SECTION_MAIN, "layout", "auto");
setValue(SETTINGS_SECTION_MAIN, "webMode", "desktop");
}
else if (mode == "tv")
{
setValue(SETTINGS_SECTION_MAIN, "layout", "tv");
setValue(SETTINGS_SECTION_MAIN, "webMode", "tv");
}
else if (mode == "auto")
{
setValue(SETTINGS_SECTION_MAIN, "layout", "auto");
}
}