void ChannelEditor::SetText(const InfoMap &map) { if (map.contains("callsign")) m_callsignEdit->SetText(map.value("callsign")); if (map.contains("channum")) m_channumEdit->SetText(map.value("channum")); if (map.contains("channame")) m_channameEdit->SetText(map.value("channame")); if (map.contains("XMLTV")) m_xmltvidEdit->SetText(map.value("XMLTV")); }
void MythUIText::SetTextFromMap(const InfoMap &map) { QString newText = GetTemplateText(); if (newText.isEmpty()) newText = GetDefaultText(); QRegExp regexp("%(([^\\|%]+)?\\||\\|(.))?([\\w#]+)(\\|(.+))?%"); regexp.setMinimal(true); if (!newText.isEmpty() && newText.contains(regexp)) { int pos = 0; QString translatedTemplate = qApp->translate("ThemeUI", newText.toUtf8()); QString tempString = translatedTemplate; bool replaced = map.contains(objectName()); while ((pos = regexp.indexIn(translatedTemplate, pos)) != -1) { QString key = regexp.cap(4).toLower().trimmed(); QString replacement; if (map.contains(key)) { replaced = true; } if (!map.value(key).isEmpty()) { replacement = QString("%1%2%3%4") .arg(regexp.cap(2)) .arg(regexp.cap(3)) .arg(map.value(key)) .arg(regexp.cap(6)); } tempString.replace(regexp.cap(0), replacement); pos += regexp.matchedLength(); } if (replaced) { SetText(tempString); } } else if (map.contains(objectName())) { SetText(map.value(objectName())); } }