2 #include <QDomDocument>
4 #include <QNetworkInterface>
18 const QString &
filename,
const QString &group,
19 bool includeAllChildren,
bool &foundGroup);
24 for (
uint i = 0; i < level; i++)
34 for (
const auto *val : std::as_const(settings))
42 const auto *setting =
dynamic_cast<const MythSetting*
>(val);
43 if (setting && (setting->m_stype == stype))
44 list += QString(
",'%1'").arg(setting->m_value);
46 if (!list.isEmpty() && (list[0] == QChar(
',')))
59 for (
auto *setting : std::as_const(group->m_settings))
65 if (setting && (setting->m_stype == stype))
67 QMap<QString,QString>::const_iterator it = map.find(setting->m_value);
71 bool do_option_check =
false;
75 setting->m_display_list = setting->m_data_list;
76 do_option_check =
true;
80 do_option_check =
true;
84 setting->m_data_list = setting->m_display_list =
86 do_option_check =
true;
90 setting->m_data_list.clear();
92 setting->m_data_list.push_back(list.name);
93 setting->m_display_list = setting->m_data_list;
94 do_option_check =
true;
99 if (!setting->m_data_list.empty() &&
100 !setting->m_data_list.contains(setting->m_data.toLower(),
101 Qt::CaseInsensitive))
104 long long idata = setting->m_data.toLongLong(&ok);
108 for (
int i = setting->m_data_list.size() - 1; i >= 0; i--)
110 if (idata < setting->m_data_list[i].toLongLong())
114 setting->m_data = setting->m_data_list[sel];
119 (setting->m_data_list.contains(
120 setting->m_default_data, Qt::CaseInsensitive)) ?
121 setting->m_default_data : setting->m_data_list[0];
131 QMap<QString,QString> map;
133 map[query.
value(0).toString()] = query.
value(1).toString();
135 for (
auto *setting : std::as_const(settings))
144 QString(
"<div class=\"group\" id=\"%1\">\r\n").arg(
m_unique_label);
147 ret +=
indent(depth+1) + QString(
"<h%1 class=\"config\">%2</h%3>\r\n")
151 for (
const auto *setting : std::as_const(
m_settings))
152 ret += setting->ToHTML(depth+1);
154 ret +=
indent(depth) +
"</div>";
161 QString ret =
indent(level) +
162 QString(
"<div class=\"setting\" id=\"%1_div\">\r\n").arg(
m_value);
194 QString(
"<p class=\"setting_paragraph\"><label class=\"setting_label\" "
195 "for=\"%1\">%2</label>")
198 QString(
"<input class=\"setting_input\" name=\"%1\" id=\"%1\" type=\"number\""
199 " value='%2' step='1' size='%3'/>\r\n")
202 QString(
"<a class=\"setting_helplink ui-icon ui-icon-help\" href=\"javascript:showSettingHelp('%1')"
203 "\"></a></label></p>\r\n").arg(
m_value);
205 QString(
"<div class=\"form_error\""
206 "id=\"%1_error\"></div><div style=\"display:none;"
207 "position:absolute;left:-4000px\" "
208 "id=\"%1_default\">%2</div>\r\n")
213 QString(
"<p class=\"setting_paragraph\"><label class=\"setting_label\" "
214 "for=\"%1\">%2</label>")
217 QString(
"<input class=\"setting_input\" name=\"%1\" id=\"%1\" type=\"number\""
218 " value='%2' min='%3' max='%4' step='1' size='%5'/>\r\n")
221 QString(
"<a class=\"setting_helplink ui-icon ui-icon-help\" href=\"javascript:showSettingHelp('%1')"
222 "\"></a></label></p>\r\n").arg(
m_value);
224 QString(
"<div class=\"form_error\""
225 "id=\"%1_error\"></div><div style=\"display:none;"
226 "position:absolute;left:-4000px\" "
227 "id=\"%1_default\">%2</div>\r\n")
237 QString(
"<p class=\"setting_paragraph\"><label class=\"setting_label\" "
238 "for=\"%1\">%2</label>")
241 QString(
"<input class=\"setting_input\" name=\"%1\" id=\"%1\" type=\"text\""
242 " value=\"%2\" size='%3' placeholder=\"%4\"/>\r\n")
245 QString(
"<a class=\"setting_helplink ui-icon ui-icon-help\" href=\"javascript:showSettingHelp('%1')"
246 "\"></a></label></p>\r\n").arg(
m_value);
248 QString(
"<div class=\"form_error\""
249 "id=\"%1_error\"></div><div style=\"display:none;"
250 "position:absolute;left:-4000px\" "
251 "id=\"%1_default\">%2</div>\r\n")
256 QString(
"<p class=\"setting_paragraph\">"
257 "<input class=\"setting_input\" name=\"%1_input\" id=\"%1\" type=\"checkbox\""
258 " value=\"1\" %2/><label class=\"setting_label_checkbox\" for=\"%1\">%3</label>")
261 QString(
"<a class=\"setting_helplink ui-icon ui-icon-help\" href=\"javascript:showSettingHelp('%1'"
262 ")\"></a></p><div class=\"form_error\""
263 " id=\"%1_error\"></div>").arg(
m_value);
265 QString(
"<div style=\"display:none;"
266 "position:absolute;left:-4000px\" "
267 "id=\"%1_default\">%2</div>")
275 QString(
"<p class=\"setting_paragraph\"><label class=\"setting_label\" "
276 "for=\"%1\">%2</label>")
279 QString(
"<select class=\"setting_select\" name=\"%1_input\" id=\"%1\">\r\n")
285 QString(
"<option value=\"%1\" %2>%3</option>\r\n")
291 ret +=
indent(level) +
"</select>" +
292 QString(
"<a class=\"setting_helplink ui-icon ui-icon-help\" href=\"javascript:showSettingHelp('%1')"
293 "\"></a></p>\r\n").arg(
m_value);
295 QString(
"<div class=\"form_error\""
296 "id=\"%1_error\"></div><div style=\"display:none;"
297 "position:absolute;left:-4000px\" "
298 "id=\"%1_default\">%2</div>\r\n")
305 ret +=
indent(level) +
"</div>\r\n";
312 QString s = str.toLower();
324 QString s = str.toLower();
329 if (s ==
"integer_range")
339 if (s ==
"frequency_table")
343 if (s ==
"ipaddress")
345 if (s ==
"localipaddress")
349 if (s ==
"timeofday")
353 LOG(VB_GENERAL, LOG_ERR, QString(
"Unknown type: %1").arg(str));
360 QMap<QString,QString> result;
365 "SELECT value, data "
367 "WHERE hostname = '" +
hostname +
"' AND "
368 " value in (" + list +
")";
372 if (!query.
exec(qstr))
379 result[query.
value(0).toString()] = query.
value(1).toString();
384 "SELECT value, data "
386 "WHERE hostname IS NULL AND "
387 " value in (" + list +
")";
391 if (!query.
exec(qstr))
398 result[query.
value(0).toString()] = query.
value(1).toString();
408 if (
type ==
"LocalIPAddress")
410 QList<QHostAddress> list = QNetworkInterface::allAddresses();
411 for (
const auto & addr : std::as_const(list))
413 if (addr.toString().contains(
":"))
415 sList << addr.toString();
419 sList <<
"127.0.0.1";
429 QMap<QString,QString>::const_iterator it = map.begin();
430 for (; it != map.end(); ++it)
432 if (result.isEmpty())
438 result +=
"\"" + it.key() +
"\": \"" + it.value() +
"\"";
441 if (!result.isEmpty())
450 const QStringList &sList)
454 for (
const auto & item : std::as_const(sList))
456 if (result.isEmpty())
457 result += QString(
"{ \"%1\" : [ ").arg(key);
462 result +=
"\"" + item +
"\"";
465 if (!result.isEmpty())
474 const QString &
filename,
const QString &group,
475 bool includeAllChildren,
bool &foundGroup)
477 #define LOC QString("parse_dom(%1@~%2), error: ") \
478 .arg(filename).arg(e.lineNumber())
480 bool mFoundGroup =
false;
482 QDomNode n = element.firstChild();
485 const QDomElement e = n.toElement();
492 if (e.tagName() ==
"group")
494 QString m_human_label = e.attribute(
"human_label");
495 QString m_unique_label = e.attribute(
"unique_label");
496 QString m_ecma_script = e.attribute(
"ecma_script");
498 bool tmpFoundGroup =
false;
499 bool tmpIncludeAllChildren = includeAllChildren;
500 if (group.isEmpty() || m_unique_label == group)
503 tmpIncludeAllChildren =
true;
507 m_human_label, m_unique_label, m_ecma_script);
509 if ((e.hasChildNodes()) &&
517 if (tmpFoundGroup || tmpIncludeAllChildren)
519 settings.push_back(g);
528 else if (e.tagName() ==
"setting" && includeAllChildren)
530 QMap<QString,QString> m;
531 m[
"value"] = e.attribute(
"value");
532 m[
"setting_type"] = e.attribute(
"setting_type");
533 m[
"label"] = e.attribute(
"label");
534 m[
"help_text"] = e.attribute(
"help_text");
535 m[
"data_type"] = e.attribute(
"data_type");
540 LOG(VB_GENERAL, LOG_ERR,
LOC +
541 "Setting has invalid or missing data_type attribute.");
545 QStringList data_list;
546 QStringList display_list;
550 if (!e.hasChildNodes())
552 LOG(VB_GENERAL, LOG_ERR,
LOC +
553 "Setting missing selection items.");
557 QDomNode n2 = e.firstChild();
560 const QDomElement e2 = n2.toElement();
561 if (e2.tagName() !=
"option")
563 LOG(VB_GENERAL, LOG_ERR,
LOC +
564 "Setting selection contains invalid tags.");
567 QString display = e2.attribute(
"display");
568 QString data = e2.attribute(
"data");
571 LOG(VB_GENERAL, LOG_ERR,
LOC +
572 "Setting selection item missing data.");
575 display = (display.isEmpty()) ? data : display;
576 data_list.push_back(data);
577 display_list.push_back(display);
579 n2 = n2.nextSibling();
585 m[
"range_min"] = e.attribute(
"range_min");
586 m[
"range_max"] = e.attribute(
"range_max");
589 QMap<QString,QString>::const_iterator it = m.cbegin();
590 for (; it != m.cend(); ++it)
594 LOG(VB_GENERAL, LOG_ERR,
LOC +
595 QString(
"Setting has invalid or missing %1 attribute")
601 m[
"default_data"] = e.attribute(
"default_data");
602 m[
"placeholder_text"] = e.attribute(
"placeholder_text");
608 LOG(VB_GENERAL, LOG_ERR,
LOC +
609 "Setting has invalid setting_type attribute.");
613 long long range_min = m[
"range_min"].toLongLong();
614 long long range_max = m[
"range_max"].toLongLong();
615 if (range_max < range_min)
617 LOG(VB_GENERAL, LOG_ERR,
LOC +
618 "Setting has invalid range attributes");
623 m[
"value"], m[
"default_data"], stype,
624 m[
"label"], m[
"help_text"], dtype,
625 data_list, display_list, range_min, range_max,
626 m[
"placeholder_text"]);
628 settings.push_back(s);
630 else if (group.isEmpty())
632 LOG(VB_GENERAL, LOG_ERR,
LOC +
633 QString(
"Unknown element: %1").arg(e.tagName()));
647 const QString &group)
652 if (!f.open(QIODevice::ReadOnly))
654 LOG(VB_GENERAL, LOG_ERR, QString(
"parse_settings: Can't open: '%1'")
659 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
664 if (!doc.setContent(&f,
false, &errorMsg, &errorLine, &errorColumn))
666 LOG(VB_GENERAL, LOG_ERR, QString(
"parse_settings: ") +
667 QString(
"Parsing: %1 at line: %2 column: %3")
668 .arg(
filename).arg(errorLine).arg(errorColumn) +
669 QString(
"\n\t\t\t%1").arg(errorMsg));
674 auto parseResult = doc.setContent(&f);
677 LOG(VB_GENERAL, LOG_ERR, QString(
"parse_settings: ") +
678 QString(
"Parsing: %1 at line: %2 column: %3")
679 .arg(
filename).arg(parseResult.errorLine)
680 .arg(parseResult.errorColumn) +
681 QString(
"\n\t\t\t%1").arg(parseResult.errorMessage));
689 bool foundGroup =
false;
690 bool includeAllChildren = group.isEmpty();
692 includeAllChildren, foundGroup);
701 "SELECT value, data "
703 "WHERE hostname = '" +
hostname +
"' AND "
704 " value in (" + list +
")";
708 if (!query.
exec(qstr))
718 "SELECT value, data "
720 "WHERE hostname IS NULL AND "
721 " value in (" + list +
")";
725 if (!query.
exec(qstr))
737 const QMap<QString,QString> ¶ms,
740 QMap<QString,QString>::const_iterator it = params.begin();
741 for (; it != params.end(); ++it)
743 if (it.key().startsWith(
"__"))
746 if (result.isEmpty())
751 result += QString(R
"("%1": "DEBUG: New value for '%2' would be '%3'")")
752 .arg(it.key(), it.key(), *it);
755 if (!result.isEmpty())
759 return result.isEmpty();