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 : qAsConst(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 : qAsConst(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 : qAsConst(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 : qAsConst(
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 : qAsConst(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 : qAsConst(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);
526 else if (e.tagName() ==
"setting" && includeAllChildren)
528 QMap<QString,QString> m;
529 m[
"value"] = e.attribute(
"value");
530 m[
"setting_type"] = e.attribute(
"setting_type");
531 m[
"label"] = e.attribute(
"label");
532 m[
"help_text"] = e.attribute(
"help_text");
533 m[
"data_type"] = e.attribute(
"data_type");
538 LOG(VB_GENERAL, LOG_ERR,
LOC +
539 "Setting has invalid or missing data_type attribute.");
543 QStringList data_list;
544 QStringList display_list;
548 if (!e.hasChildNodes())
550 LOG(VB_GENERAL, LOG_ERR,
LOC +
551 "Setting missing selection items.");
555 QDomNode n2 = e.firstChild();
558 const QDomElement e2 = n2.toElement();
559 if (e2.tagName() !=
"option")
561 LOG(VB_GENERAL, LOG_ERR,
LOC +
562 "Setting selection contains invalid tags.");
565 QString display = e2.attribute(
"display");
566 QString data = e2.attribute(
"data");
569 LOG(VB_GENERAL, LOG_ERR,
LOC +
570 "Setting selection item missing data.");
573 display = (display.isEmpty()) ? data : display;
574 data_list.push_back(data);
575 display_list.push_back(display);
577 n2 = n2.nextSibling();
583 m[
"range_min"] = e.attribute(
"range_min");
584 m[
"range_max"] = e.attribute(
"range_max");
587 QMap<QString,QString>::const_iterator it = m.cbegin();
588 for (; it != m.cend(); ++it)
592 LOG(VB_GENERAL, LOG_ERR,
LOC +
593 QString(
"Setting has invalid or missing %1 attribute")
599 m[
"default_data"] = e.attribute(
"default_data");
600 m[
"placeholder_text"] = e.attribute(
"placeholder_text");
606 LOG(VB_GENERAL, LOG_ERR,
LOC +
607 "Setting has invalid setting_type attribute.");
611 long long range_min = m[
"range_min"].toLongLong();
612 long long range_max = m[
"range_max"].toLongLong();
613 if (range_max < range_min)
615 LOG(VB_GENERAL, LOG_ERR,
LOC +
616 "Setting has invalid range attributes");
621 m[
"value"], m[
"default_data"], stype,
622 m[
"label"], m[
"help_text"], dtype,
623 data_list, display_list, range_min, range_max,
624 m[
"placeholder_text"]);
626 settings.push_back(s);
628 else if (group.isEmpty())
630 LOG(VB_GENERAL, LOG_ERR,
LOC +
631 QString(
"Unknown element: %1").arg(e.tagName()));
645 const QString &group)
650 if (!f.open(QIODevice::ReadOnly))
652 LOG(VB_GENERAL, LOG_ERR, QString(
"parse_settings: Can't open: '%1'")
661 if (!doc.setContent(&f,
false, &errorMsg, &errorLine, &errorColumn))
663 LOG(VB_GENERAL, LOG_ERR, QString(
"parse_settings: ") +
664 QString(
"Parsing: %1 at line: %2 column: %3")
665 .arg(
filename).arg(errorLine).arg(errorColumn) +
666 QString(
"\n\t\t\t%1").arg(errorMsg));
673 bool foundGroup =
false;
674 bool includeAllChildren = group.isEmpty();
676 includeAllChildren, foundGroup);
685 "SELECT value, data "
687 "WHERE hostname = '" +
hostname +
"' AND "
688 " value in (" + list +
")";
692 if (!query.
exec(qstr))
702 "SELECT value, data "
704 "WHERE hostname IS NULL AND "
705 " value in (" + list +
")";
709 if (!query.
exec(qstr))
721 const QMap<QString,QString> ¶ms,
724 QMap<QString,QString>::const_iterator it = params.begin();
725 for (; it != params.end(); ++it)
727 if (it.key().startsWith(
"__"))
730 if (result.isEmpty())
735 result += QString(R
"("%1": "DEBUG: New value for '%2' would be '%3'")")
736 .arg(it.key(), it.key(), *it);
739 if (!result.isEmpty())
743 return result.isEmpty();