// virtual LLXMLNodePtr LLFlyoutButton::getXML(bool save_children) const { LLXMLNodePtr node = LLComboBox::getXML(); node->setName(LL_FLYOUT_BUTTON_TAG); LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull();) { if (child->hasName("combo_item")) { child->setName(LL_FLYOUT_BUTTON_ITEM_TAG); //setName does a delete and add, so we have to start over child = node->getFirstChild(); } else { child = child->getNextSibling(); } } return node; }
bool LLNotificationTemplates::loadTemplates() { LL_INFOS() << "Reading notifications template" << LL_ENDL; // Passing findSkinnedFilenames(constraint=LLDir::ALL_SKINS) makes it // output all relevant pathnames instead of just the ones from the most // specific skin. std::vector<std::string> search_paths = gDirUtilp->findSkinnedFilenames(LLDir::XUI, "notifications.xml", LLDir::ALL_SKINS); std::string base_filename = search_paths.front(); LLXMLNodePtr root; BOOL success = LLXMLNode::getLayeredXMLNode(root, search_paths); if (!success || root.isNull() || !root->hasName( "notifications" )) { LL_ERRS() << "Problem reading XML from UI Notifications file: " << base_filename << LL_ENDL; return false; } clearTemplates(); for (LLXMLNodePtr item = root->getFirstChild(); item.notNull(); item = item->getNextSibling()) { if (item->hasName("global")) { std::string global_name; if (item->getAttributeString("name", global_name)) { mGlobalStrings[global_name] = item->getTextContents(); } continue; } if (item->hasName("template")) { // store an xml template; templates must have a single node (can contain // other nodes) std::string name; item->getAttributeString("name", name); LLXMLNodePtr ptr = item->getFirstChild(); mXmlTemplates[name] = ptr; continue; } if (!item->hasName("notification")) { LL_WARNS() << "Unexpected entity " << item->getName()->mString << " found in notifications.xml [language=]" << LLUI::getLanguage() << LL_ENDL; continue; } } return true; }
bool LLNotificationTemplates::loadTemplates() { const std::string xml_filename = "notifications.xml"; LLXMLNodePtr root; BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); if (!success || root.isNull() || !root->hasName( "notifications" )) { llerrs << "Problem reading UI Notifications file: " << xml_filename << llendl; return false; } clearTemplates(); for (LLXMLNodePtr item = root->getFirstChild(); item.notNull(); item = item->getNextSibling()) { if (item->hasName("global")) { std::string global_name; if (item->getAttributeString("name", global_name)) { mGlobalStrings[global_name] = item->getTextContents(); } continue; } if (item->hasName("template")) { // store an xml template; templates must have a single node (can contain // other nodes) std::string name; item->getAttributeString("name", name); LLXMLNodePtr ptr = item->getFirstChild(); mXmlTemplates[name] = ptr; continue; } if (!item->hasName("notification")) { llwarns << "Unexpected entity " << item->getName()->mString << " found in " << xml_filename << llendl; continue; } } return true; }
void LLPanel::initChildrenXML(LLXMLNodePtr node, LLUICtrlFactory* factory) { std::string kidstring(node->getName()->mString); kidstring += ".string"; LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { // look for string declarations for programmatic text if (child->hasName("string") || child->hasName(kidstring)) { std::string string_name; child->getAttributeString("name", string_name); if (!string_name.empty()) { std::string contents = child->getTextContents(); child->getAttributeString("value", contents); mUIStrings[string_name] = contents; } } else { factory->createWidget(this, child); } } }
void replaceSubstitutionStrings(LLXMLNodePtr node, StringMap& replacements) { //llwarns << "replaceSubstitutionStrings" << llendl; // walk the list of attributes looking for replacements for (LLXMLAttribList::iterator it=node->mAttributes.begin(); it != node->mAttributes.end(); ++it) { std::string value = it->second->getValue(); if (value[0] == '$') { value.erase(0, 1); // trim off the $ std::string replacement; StringMap::const_iterator found = replacements.find(value); if (found != replacements.end()) { replacement = found->second; //llwarns << "replaceSubstituionStrings: value: " << value << " repl: " << replacement << llendl; it->second->setValue(replacement); } else { llwarns << "replaceSubstituionStrings FAILURE: value: " << value << " repl: " << replacement << llendl; } } } // now walk the list of children and call this recursively. for (LLXMLNodePtr child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { replaceSubstitutionStrings(child, replacements); } }
//static bool LLUITrans::parseStrings(const std::string& xml_filename) { LLXMLNodePtr root; BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); if (!success || root.isNull() || !root->hasName( "strings" )) { llwarns << "Problem reading strings: " << xml_filename << llendl; return false; } for (LLXMLNode* string = root->getFirstChild(); string != NULL; string = string->getNextSibling()) { if (!string->hasName("string")) { continue; } std::string string_name; if (! string->getAttributeString("name", string_name)) { llwarns << "Unable to parse string with no name" << llendl; continue; } LLUITransTemplate xml_template(string_name, string->getTextContents()); sStringTemplates[xml_template.mName] = xml_template; } return true; }
void LLUICtrlFactory::setupPaths() { std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_SKINS, "paths.xml"); LLXMLNodePtr root; BOOL success = LLXMLNode::parseFile(filename, root, NULL); sXUIPaths.clear(); if (success) { LLXMLNodePtr path; for (path = root->getFirstChild(); path.notNull(); path = path->getNextSibling()) { LLUIString path_val_ui(path->getValue()); std::string language = LLUI::getLanguage(); path_val_ui.setArg("[LANGUAGE]", language); if (std::find(sXUIPaths.begin(), sXUIPaths.end(), path_val_ui.getString()) == sXUIPaths.end()) { sXUIPaths.push_back(path_val_ui.getString()); } } } else // parsing failed { std::string slash = gDirUtilp->getDirDelimiter(); std::string dir = "xui" + slash + "en-us"; llwarns << "XUI::config file unable to open: " << filename << llendl; sXUIPaths.push_back(dir); } }
bool LLFontRegistry::initFromXML(LLXMLNodePtr node) { LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { std::string child_name; child->getAttributeString("name",child_name); if (child->hasName("font")) { LLFontDescriptor desc; bool font_succ = fontDescInitFromXML(child, desc); LLFontDescriptor norm_desc = desc.normalize(); if (font_succ) { // if this is the first time we've seen this font name, // create a new template map entry for it. const LLFontDescriptor *match_desc = getMatchingFontDesc(desc); if (match_desc == NULL) { // Create a new entry (with no corresponding font). mFontMap[norm_desc] = NULL; } // otherwise, find the existing entry and combine data. else { // Prepend files from desc. // A little roundabout because the map key is const, // so we have to fetch it, make a new map key, and // replace the old entry. string_vec_t match_file_names = match_desc->getFileNames(); match_file_names.insert(match_file_names.begin(), desc.getFileNames().begin(), desc.getFileNames().end()); LLFontDescriptor new_desc = *match_desc; new_desc.getFileNames() = match_file_names; mFontMap.erase(*match_desc); mFontMap[new_desc] = NULL; } } } else if (child->hasName("font_size")) { std::string size_name; F32 size_value; if (child->getAttributeString("name",size_name) && child->getAttributeF32("size",size_value)) { mFontSizes[size_name] = size_value; } } } return true; }
LLNotificationForm::LLNotificationForm(const std::string& name, const LLXMLNodePtr xml_node) : mFormData(LLSD::emptyArray()), mIgnore(IGNORE_NO), mInvertSetting(false) { if (!xml_node->hasName("form")) { llwarns << "Bad xml node for form: " << xml_node->getName() << llendl; } LLXMLNodePtr child = xml_node->getFirstChild(); while(child) { child = LLNotificationTemplates::instance().checkForXMLTemplate(child); LLSD item_entry; std::string element_name = child->getName()->mString; if (element_name == "ignore") { bool save_option = false; child->getAttribute_bool("save_option", save_option); if (!save_option) { mIgnore = IGNORE_WITH_DEFAULT_RESPONSE; } else { // remember last option chosen by user and automatically respond with that in the future mIgnore = IGNORE_WITH_LAST_RESPONSE; LLUI::sIgnoresGroup->declareLLSD(std::string("Default") + name, "", std::string("Default response for notification " + name)); } child->getAttributeString("text", mIgnoreMsg); mIgnoreSetting = LLUI::sIgnoresGroup->addWarning(name); } else { // flatten xml form entry into single LLSD map with type==name item_entry["type"] = element_name; const LLXMLAttribList::iterator attrib_end = child->mAttributes.end(); for(LLXMLAttribList::iterator attrib_it = child->mAttributes.begin(); attrib_it != attrib_end; ++attrib_it) { item_entry[std::string(attrib_it->second->getName()->mString)] = attrib_it->second->getValue(); } item_entry["value"] = child->getTextContents(); mFormData.append(item_entry); } child = child->getNextSibling(); } }
//static bool LLTrans::parseStrings(const std::string& xml_filename, const std::set<std::string>& default_args) { LLXMLNodePtr root; BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); if (!success || root.isNull() || !root->hasName( "strings" )) { LL_ERRS() << "Problem reading strings: " << xml_filename << LL_ENDL; return false; } sDefaultArgs.clear(); for (LLXMLNode* string = root->getFirstChild(); string != NULL; string = string->getNextSibling()) { if (!string->hasName("string")) { continue; } std::string string_name; if (! string->getAttributeString("name", string_name)) { LL_WARNS() << "Unable to parse string with no name" << LL_ENDL; continue; } std::string contents; //value is used for strings with preceeding spaces. If not present, fall back to getTextContents() if(!string->getAttributeString("value",contents)) contents=string->getTextContents(); LLTransTemplate xml_template(string_name, contents); sStringTemplates[xml_template.mName] = xml_template; std::set<std::string>::const_iterator iter = default_args.find(xml_template.mName); if (iter != default_args.end()) { std::string name = *iter; if (name[0] != '[') name = llformat("[%s]",name.c_str()); sDefaultArgs[name] = xml_template.mText; } } return true; }
// Checked: 2010-03-09 (RLVa-1.2.0a) | Added: RLVa-1.1.0h void RlvStrings::initClass() { static bool fInitialized = false; if (!fInitialized) { LLXMLNodePtr xmlRoot; if ( (!LLUICtrlFactory::getLayeredXMLNode("rlva_strings.xml", xmlRoot)) || (xmlRoot.isNull()) || (!xmlRoot->hasName("rlva_strings")) ) { RLV_ERRS << "Problem reading RLVa string XML file" << RLV_ENDL; return; } for (LLXMLNode* pNode = xmlRoot->getFirstChild(); pNode != NULL; pNode = pNode->getNextSibling()) { if (pNode->hasName("strings")) { std::string strName; for (LLXMLNode* pStringNode = pNode->getFirstChild(); pStringNode != NULL; pStringNode = pStringNode->getNextSibling()) { if ( (!pStringNode->hasName("string")) || (!pStringNode->getAttributeString("name", strName)) ) continue; m_StringMap[strName] = pStringNode->getTextContents(); } } else if (pNode->hasName("anonyms")) { for (LLXMLNode* pAnonymNode = pNode->getFirstChild(); pAnonymNode != NULL; pAnonymNode = pAnonymNode->getNextSibling()) { if (!pAnonymNode->hasName("anonym")) continue; m_Anonyms.push_back(pAnonymNode->getTextContents()); } } } if ( (m_StringMap.empty()) || (m_Anonyms.empty()) ) { RLV_ERRS << "Problem parsing RLVa string XML file" << RLV_ENDL; return; } fInitialized = true; } }
bool ViewerVersion::initViewerVersion() { std::string file_path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "viewerversion.xml"); if (!gDirUtilp->fileExists(file_path)) { llwarns << "Unable to find viewerversion.xml in app_settings folder" << llendl; return false; } else { LLXMLNodePtr root; if (!LLXMLNode::parseFile(file_path, root, NULL)) { llwarns << "Unable to parse version file: " << file_path << llendl; return false; } if (root.isNull()) // shouldn't ever happen { llwarns << "Error while trying to read viewerversion.xml" << llendl; return false; } LLXMLNodePtr child_nodep = root->getFirstChild(); while (child_nodep.notNull()) { child_nodep->getAttributeS32("version_major", sVersionMajor); child_nodep->getAttributeS32("version_minor", sVersionMinor); child_nodep->getAttributeS32("version_patch", sVersionPatch); child_nodep->getAttributeString("version_test", sVersionTest); child_nodep = child_nodep->getNextSibling(); } llinfos << "Version set to: " << sVersionMajor << "." << sVersionMinor << "." << sVersionPatch << " " << sVersionTest << llendl; return true; } }
bool fontDescInitFromXML(LLXMLNodePtr node, LLFontDescriptor& desc) { if (node->hasName("font")) { std::string attr_name; if (node->getAttributeString("name",attr_name)) { desc.setName(attr_name); } std::string attr_style; if (node->getAttributeString("font_style",attr_style)) { desc.setStyle(LLFontGL::getStyleFromString(attr_style)); } desc.setSize(s_template_string); } LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { std::string child_name; child->getAttributeString("name",child_name); if (child->hasName("file")) { std::string font_file_name = child->getTextContents(); desc.getFileNames().push_back(font_file_name); } else if (child->hasName("os")) { if (child_name == currentOsName()) { fontDescInitFromXML(child, desc); } } } return true; }
//static void LLUICtrlFactory::createChildren(LLView* viewp, LLXMLNodePtr node, const widget_registry_t& registry, LLXMLNodePtr output_node) { LLFastTimer ft(FTM_CREATE_CHILDREN); if (node.isNull()) return; for (LLXMLNodePtr child_node = node->getFirstChild(); child_node.notNull(); child_node = child_node->getNextSibling()) { LLXMLNodePtr outputChild; if (output_node) { outputChild = output_node->createChild("", FALSE); } if (!instance().createFromXML(child_node, viewp, LLStringUtil::null, registry, outputChild)) { // child_node is not a valid child for the current parent std::string child_name = std::string(child_node->getName()->mString); if (LLDefaultChildRegistry::instance().getValue(child_name)) { // This means that the registry assocaited with the parent widget does not have an entry // for the child widget // You might need to add something like: // static ParentWidgetRegistry::Register<ChildWidgetType> register("child_widget_name"); llwarns << child_name << " is not a valid child of " << node->getName()->mString << llendl; } else { llwarns << "Could not create widget named " << child_node->getName()->mString << llendl; } } if (outputChild && !outputChild->mChildren && outputChild->mAttributes.empty() && outputChild->getValue().empty()) { output_node->deleteChild(outputChild); } } }
//static bool LLAlertDialog::parseAlerts(const LLString& xml_filename, LLControlGroup* settings, BOOL settings_only) { LLXMLNodePtr root; BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); if (!success || root.isNull() || !root->hasName( "alerts" )) { llerrs << "Problem reading UI Alerts file: " << xml_filename << llendl; return false; } BOOL add_settings = FALSE; if (settings) { sSettings = settings; add_settings = TRUE; } llassert(sSettings); for (LLXMLNode* alert = root->getFirstChild(); alert != NULL; alert = alert->getNextSibling()) { if (alert->hasName("global")) { LLString global_name; if (alert->getAttributeString("name", global_name)) { if (global_name == "skipnexttime") { sStringSkipNextTime = alert->getTextContents(); } else if (global_name == "alwayschoose") { sStringAlwaysChoose = alert->getTextContents(); } } continue; } if (!alert->hasName("alert")) { continue; } LLAlertDialogTemplate* xml_template = settings_only ? NULL : new LLAlertDialogTemplate; // name= LLString alert_name; if (alert->getAttributeString("name", alert_name)) { if (xml_template) { xml_template->mLabel = alert_name; } } else { llwarns << "Unable to parse alert with no name" << llendl; delete xml_template; continue; } // title= LLString title; if (alert->getAttributeString("title", title)) { if (xml_template) { xml_template->mTitle = title; } } // modal= BOOL modal; if (alert->getAttributeBOOL("modal", modal)) { if (xml_template) { xml_template->mModal = modal; } } // caution= BOOL caution; if (alert->getAttributeBOOL("caution", caution)) { if (xml_template) { xml_template->mCaution = caution; } } // unique= BOOL unique; if (alert->getAttributeBOOL("unique", unique)) { if (xml_template) { xml_template->mUnique = unique; } } S32 default_option = 0; BOOL nodefault; if (alert->getAttributeBOOL("nodefault", nodefault)) { if (nodefault) { if (xml_template) { xml_template->mDefaultOption = -1; } default_option = -1; } } S32 btn_idx = 0; for (LLXMLNode* child = alert->getFirstChild(); child != NULL; child = child->getNextSibling()) { // <message> if (child->hasName("message")) { if (xml_template) { xml_template->mMessage = child->getTextContents(); } } // <option> if (child->hasName("option")) { LLString label = child->getTextContents(); BOOL is_default = FALSE; child->getAttributeBOOL("default", is_default); LLString ignore_text; if (!child->getAttributeString("ignore", ignore_text)) { ignore_text = label; } if (xml_template) { xml_template->addOption(label, ignore_text, is_default); } if (is_default) { default_option = btn_idx; } btn_idx++; } // <editline> if (child->hasName("editline")) { if (xml_template) { xml_template->mEditLineText = child->getTextContents(); if (xml_template->mEditLineText.empty()) { xml_template->mEditLineText = " "; } } } // <ignore> if (child->hasName("ignore")) { LLString ignore_text = child->getTextContents(); // label= LLString name; child->getAttributeString("name", name); //always set to alert_name for the sake of i18n //if (name.empty()) name = alert_name; if (xml_template) { xml_template->mIgnorable = LLAlertDialog::IGNORE_USE_DEFAULT; xml_template->mIgnoreListText = ignore_text; xml_template->mIgnoreLabel = name; } if (!ignore_text.empty()) { if (add_settings) { settings->addWarning(name); } if (xml_template) { sIgnorableTemplates[name] = xml_template; // will override any previous entry } } // save_option= BOOL save_option = FALSE; child->getAttributeBOOL("save_option", save_option); if (save_option) { if (xml_template) { xml_template->mIgnorable = LLAlertDialog::IGNORE_USE_SAVED; } if (add_settings) { settings->declareS32("Default" + name, default_option, "Default option number for this alert dialog"); } } } // <url> if (child->hasName("url")) { S32 url_option = 0; child->getAttributeS32("option", url_option); if (xml_template) { xml_template->mURL = child->getTextContents(); xml_template->mURLOption = url_option; } } } if (xml_template) { xml_template->mDefaultOption = default_option; sAlertTemplates[xml_template->mLabel] = xml_template; } } return true; }
// static bool LLMIMETypes::parseMIMETypes(const std::string& xml_filename) { LLXMLNodePtr root; bool success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); if (!success) { // If fails, check if we can read the file from the app_settings folder std::string settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, xml_filename); success = LLUICtrlFactory::getLayeredXMLNode(settings_filename, root); #if LL_WINDOWS // On the windows dev builds, unpackaged, the mime_types.xml file will be located in // indra/build-vc**/newview/<config>/app_settings. if (!success) { settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_EXECUTABLE, "app_settings", xml_filename); success = LLUICtrlFactory::getLayeredXMLNode(settings_filename, root); } #endif } if ( ! success || root.isNull() || ! root->hasName( "mimetypes" ) ) { llwarns << "Unable to read MIME type file: " << xml_filename << llendl; return false; } for (LLXMLNode* node = root->getFirstChild(); node != NULL; node = node->getNextSibling()) { if (node->hasName("defaultlabel")) { sDefaultLabel = node->getTextContents(); } else if (node->hasName("defaultwidget")) { sDefaultWidgetType = node->getTextContents(); } else if (node->hasName("defaultimpl")) { sDefaultImpl = node->getTextContents(); } else if (node->hasName("mimetype") || node->hasName("scheme")) { std::string mime_type; node->getAttributeString("name", mime_type); LLMIMEInfo info; for (LLXMLNode* child = node->getFirstChild(); child != NULL; child = child->getNextSibling()) { if (child->hasName("label")) { info.mLabel = child->getTextContents(); } else if (child->hasName("widgettype")) { info.mWidgetType = child->getTextContents(); } else if (child->hasName("impl")) { info.mImpl = child->getTextContents(); } } sMap[mime_type] = info; } else if (node->hasName("widgetset")) { std::string set_name; node->getAttributeString("name", set_name); LLMIMEWidgetSet info; for (LLXMLNode* child = node->getFirstChild(); child != NULL; child = child->getNextSibling()) { if (child->hasName("label")) { info.mLabel = child->getTextContents(); } if (child->hasName("icon")) { info.mIcon = child->getTextContents(); } if (child->hasName("default_type")) { info.mDefaultMimeType = child->getTextContents(); } if (child->hasName("tooltip")) { info.mToolTip = child->getTextContents(); } if (child->hasName("playtip")) { info.mPlayTip = child->getTextContents(); } if (child->hasName("allow_resize")) { BOOL allow_resize = FALSE; child->getBoolValue( 1, &allow_resize ); info.mAllowResize = (bool)allow_resize; } if (child->hasName("allow_looping")) { BOOL allow_looping = FALSE; child->getBoolValue( 1, &allow_looping ); info.mAllowLooping = (bool)allow_looping; } } sWidgetMap[set_name] = info; } } sXMLFilename = xml_filename; return true; }
bool LLNotifications::loadTemplates() { const std::string xml_filename = "notifications.xml"; LLXMLNodePtr root; BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); if (!success || root.isNull() || !root->hasName( "notifications" )) { llerrs << "Problem reading UI Notifications file: " << xml_filename << llendl; return false; } clearTemplates(); for (LLXMLNodePtr item = root->getFirstChild(); item.notNull(); item = item->getNextSibling()) { // we do this FIRST so that item can be changed if we // encounter a usetemplate -- we just replace the // current xml node and keep processing item = checkForXMLTemplate(item); if (item->hasName("global")) { std::string global_name; if (item->getAttributeString("name", global_name)) { mGlobalStrings[global_name] = item->getTextContents(); } continue; } if (item->hasName("template")) { // store an xml template; templates must have a single node (can contain // other nodes) std::string name; item->getAttributeString("name", name); LLXMLNodePtr ptr = item->getFirstChild(); mXmlTemplates[name] = ptr; continue; } if (!item->hasName("notification")) { llwarns << "Unexpected entity " << item->getName()->mString << " found in " << xml_filename << llendl; continue; } // now we know we have a notification entry, so let's build it LLNotificationTemplatePtr pTemplate(new LLNotificationTemplate()); if (!item->getAttributeString("name", pTemplate->mName)) { llwarns << "Unable to parse notification with no name" << llendl; continue; } //llinfos << "Parsing " << pTemplate->mName << llendl; pTemplate->mMessage = item->getTextContents(); pTemplate->mDefaultFunctor = pTemplate->mName; item->getAttributeString("type", pTemplate->mType); item->getAttributeString("icon", pTemplate->mIcon); item->getAttributeString("label", pTemplate->mLabel); item->getAttributeU32("duration", pTemplate->mExpireSeconds); item->getAttributeU32("expireOption", pTemplate->mExpireOption); std::string priority; item->getAttributeString("priority", priority); pTemplate->mPriority = NOTIFICATION_PRIORITY_NORMAL; if (!priority.empty()) { if (priority == "low") pTemplate->mPriority = NOTIFICATION_PRIORITY_LOW; if (priority == "normal") pTemplate->mPriority = NOTIFICATION_PRIORITY_NORMAL; if (priority == "high") pTemplate->mPriority = NOTIFICATION_PRIORITY_HIGH; if (priority == "critical") pTemplate->mPriority = NOTIFICATION_PRIORITY_CRITICAL; } item->getAttributeString("functor", pTemplate->mDefaultFunctor); BOOL persist = false; item->getAttributeBOOL("persist", persist); pTemplate->mPersist = persist; std::string sound; item->getAttributeString("sound", sound); if (!sound.empty()) { // TODO: test for bad sound effect name / missing effect pTemplate->mSoundEffect = LLUUID(LLUI::sConfigGroup->getString(sound.c_str())); } for (LLXMLNodePtr child = item->getFirstChild(); !child.isNull(); child = child->getNextSibling()) { child = checkForXMLTemplate(child); // <url> if (child->hasName("url")) { pTemplate->mURL = child->getTextContents(); child->getAttributeU32("option", pTemplate->mURLOption); } if (child->hasName("unique")) { pTemplate->mUnique = true; for (LLXMLNodePtr formitem = child->getFirstChild(); !formitem.isNull(); formitem = formitem->getNextSibling()) { if (formitem->hasName("context")) { std::string key; formitem->getAttributeString("key", key); pTemplate->mUniqueContext.push_back(key); //llwarns << "adding " << key << " to unique context" << llendl; } else { llwarns << "'unique' has unrecognized subelement " << formitem->getName()->mString << llendl; } } } // <form> if (child->hasName("form")) { pTemplate->mForm = LLNotificationFormPtr(new LLNotificationForm(pTemplate->mName, child)); } } addTemplate(pTemplate->mName, pTemplate); } //std::ostringstream ostream; //root->writeToOstream(ostream, "\n "); //llwarns << ostream.str() << llendl; return true; }
// Checked: 2010-03-09 (RLVa-1.2.0a) | Added: RLVa-1.1.0h void RlvStrings::initClass() { static bool fInitialized = false; if (!fInitialized) { LLXMLNodePtr xmlRoot; if ( (!LLUICtrlFactory::getLayeredXMLNode("rlva_strings.xml", xmlRoot)) || (xmlRoot.isNull()) || (!xmlRoot->hasName("rlva_strings")) ) { RLV_ERRS << "Problem reading RLVa string XML file" << RLV_ENDL; return; } for (LLXMLNode* pNode = xmlRoot->getFirstChild(); pNode != NULL; pNode = pNode->getNextSibling()) { if (pNode->hasName("strings")) { std::string strName; for (LLXMLNode* pStringNode = pNode->getFirstChild(); pStringNode != NULL; pStringNode = pStringNode->getNextSibling()) { if ( (!pStringNode->hasName("string")) || (!pStringNode->getAttributeString("name", strName)) ) continue; m_StringMap[strName] = pStringNode->getTextContents(); } } else if (pNode->hasName("anonyms")) { for (LLXMLNode* pAnonymNode = pNode->getFirstChild(); pAnonymNode != NULL; pAnonymNode = pAnonymNode->getNextSibling()) { if (!pAnonymNode->hasName("anonym")) continue; m_Anonyms.push_back(pAnonymNode->getTextContents()); } } #ifdef RLV_EXTENSION_NOTIFY_BEHAVIOUR else if (pNode->hasName("behaviour-notifications")) { std::string strBhvr, strType; ERlvBehaviour eBhvr; for (LLXMLNode* pNotifyNode = pNode->getFirstChild(); pNotifyNode != NULL; pNotifyNode = pNotifyNode->getNextSibling()) { if ( (!pNotifyNode->hasName("notification")) || (!pNotifyNode->getAttributeString("type", strType)) || (!pNotifyNode->getAttributeString("behaviour", strBhvr)) || ((eBhvr = RlvCommand::getBehaviourFromString(strBhvr)) == RLV_BHVR_UNKNOWN) ) { continue; } if ("add" == strType) m_BhvrAddMap.insert(std::pair<ERlvBehaviour, std::string>(eBhvr, pNotifyNode->getTextContents())); else if ("rem" == strType) m_BhvrRemMap.insert(std::pair<ERlvBehaviour, std::string>(eBhvr, pNotifyNode->getTextContents())); } } #endif // RLV_EXTENSION_NOTIFY_BEHAVIOUR } if ( (m_StringMap.empty()) || (m_Anonyms.empty()) ) { RLV_ERRS << "Problem parsing RLVa string XML file" << RLV_ENDL; return; } fInitialized = true; } }
bool LLXUIParser::readXUIImpl(LLXMLNodePtr nodep, const std::string& scope, LLInitParam::BaseBlock& block) { typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep("."); bool values_parsed = false; // submit attributes for current node values_parsed |= readAttributes(nodep, block); // treat text contents of xml node as "value" parameter std::string text_contents = nodep->getSanitizedValue(); if (!text_contents.empty()) { mCurReadNode = nodep; mNameStack.push_back(std::make_pair(std::string("value"), newParseGeneration())); // child nodes are not necessarily valid parameters (could be a child widget) // so don't complain once we've recursed bool silent = mCurReadDepth > 0; if (!block.submitValue(mNameStack, *this, true)) { mNameStack.pop_back(); block.submitValue(mNameStack, *this, silent); } else { mNameStack.pop_back(); } } // then traverse children // child node must start with last name of parent node (our "scope") // for example: "<button><button.param nested_param1="foo"><param.nested_param2 nested_param3="bar"/></button.param></button>" // which equates to the following nesting: // button // param // nested_param1 // nested_param2 // nested_param3 mCurReadDepth++; for(LLXMLNodePtr childp = nodep->getFirstChild(); childp.notNull();) { std::string child_name(childp->getName()->mString); S32 num_tokens_pushed = 0; // for non "dotted" child nodes check to see if child node maps to another widget type // and if not, treat as a child element of the current node // e.g. <button><rect left="10"/></button> will interpret <rect> as "button.rect" // since there is no widget named "rect" if (child_name.find(".") == std::string::npos) { mNameStack.push_back(std::make_pair(child_name, newParseGeneration())); num_tokens_pushed++; } else { // parse out "dotted" name into individual tokens tokenizer name_tokens(child_name, sep); tokenizer::iterator name_token_it = name_tokens.begin(); if(name_token_it == name_tokens.end()) { childp = childp->getNextSibling(); continue; } // check for proper nesting if(!scope.empty() && *name_token_it != scope) { childp = childp->getNextSibling(); continue; } // now ignore first token ++name_token_it; // copy remaining tokens on to our running token list for(tokenizer::iterator token_to_push = name_token_it; token_to_push != name_tokens.end(); ++token_to_push) { mNameStack.push_back(std::make_pair(*token_to_push, newParseGeneration())); num_tokens_pushed++; } } // recurse and visit children XML nodes if(readXUIImpl(childp, mNameStack.empty() ? scope : mNameStack.back().first, block)) { // child node successfully parsed, remove from DOM values_parsed = true; LLXMLNodePtr node_to_remove = childp; childp = childp->getNextSibling(); nodep->deleteChild(node_to_remove); } else { childp = childp->getNextSibling(); } while(num_tokens_pushed-- > 0) { mNameStack.pop_back(); } } mCurReadDepth--; return values_parsed; }
bool LLNotifications::loadNotifications() { LL_INFOS() << "Reading notifications template" << LL_ENDL; // Passing findSkinnedFilenames(constraint=LLDir::ALL_SKINS) makes it // output all relevant pathnames instead of just the ones from the most // specific skin. std::vector<std::string> search_paths = gDirUtilp->findSkinnedFilenames(LLDir::XUI, "notifications.xml", LLDir::ALL_SKINS); std::string base_filename = search_paths.front(); LLXMLNodePtr root; BOOL success = LLXMLNode::getLayeredXMLNode(root, search_paths); if (!success || root.isNull() || !root->hasName( "notifications" )) { LL_ERRS() << "Problem reading XML from UI Notifications file: " << base_filename << LL_ENDL; return false; } for (LLXMLNodePtr item = root->getFirstChild(); item.notNull(); item = item->getNextSibling()) { // we do this FIRST so that item can be changed if we // encounter a usetemplate -- we just replace the // current xml node and keep processing item = LLNotificationTemplates::instance().checkForXMLTemplate(item); if (!item->hasName("notification")) continue; // now we know we have a notification entry, so let's build it LLNotificationTemplatePtr pTemplate(new LLNotificationTemplate()); if (!item->getAttributeString("name", pTemplate->mName)) { LL_WARNS() << "Unable to parse notification with no name" << LL_ENDL; continue; } //LL_INFOS() << "Parsing " << pTemplate->mName << LL_ENDL; pTemplate->mMessage = item->getTextContents(); pTemplate->mDefaultFunctor = pTemplate->mName; item->getAttributeString("type", pTemplate->mType); item->getAttributeString("icon", pTemplate->mIcon); item->getAttributeString("label", pTemplate->mLabel); item->getAttributeU32("duration", pTemplate->mExpireSeconds); item->getAttributeU32("expireOption", pTemplate->mExpireOption); std::string priority; item->getAttributeString("priority", priority); pTemplate->mPriority = NOTIFICATION_PRIORITY_NORMAL; if (!priority.empty()) { if (priority == "low") pTemplate->mPriority = NOTIFICATION_PRIORITY_LOW; if (priority == "normal") pTemplate->mPriority = NOTIFICATION_PRIORITY_NORMAL; if (priority == "high") pTemplate->mPriority = NOTIFICATION_PRIORITY_HIGH; if (priority == "critical") pTemplate->mPriority = NOTIFICATION_PRIORITY_CRITICAL; } item->getAttributeString("functor", pTemplate->mDefaultFunctor); BOOL persist = false; item->getAttributeBOOL("persist", persist); pTemplate->mPersist = persist; std::string sound; item->getAttributeString("sound", sound); if (!sound.empty()) { // TODO: test for bad sound effect name / missing effect pTemplate->mSoundEffect = LLUUID(LLUI::sConfigGroup->findString(sound.c_str())); } for (LLXMLNodePtr child = item->getFirstChild(); !child.isNull(); child = child->getNextSibling()) { child = LLNotificationTemplates::instance().checkForXMLTemplate(child); // <url> if (child->hasName("url")) { pTemplate->mURL = child->getTextContents(); child->getAttributeU32("option", pTemplate->mURLOption); } if (child->hasName("unique")) { pTemplate->mUnique = true; for (LLXMLNodePtr formitem = child->getFirstChild(); !formitem.isNull(); formitem = formitem->getNextSibling()) { if (formitem->hasName("context")) { std::string key; formitem->getAttributeString("key", key); pTemplate->mUniqueContext.push_back(key); //LL_WARNS() << "adding " << key << " to unique context" << LL_ENDL; } else { LL_WARNS() << "'unique' has unrecognized subelement " << formitem->getName()->mString << LL_ENDL; } } } // <form> if (child->hasName("form")) { pTemplate->mForm = LLNotificationFormPtr(new LLNotificationForm(pTemplate->mName, child)); } } LLNotificationTemplates::instance().addTemplate(pTemplate->mName, pTemplate); } //std::ostringstream ostream; //root->writeToOstream(ostream, "\n "); //LL_WARNS() << ostream.str() << LL_ENDL; return true; }
//static bool LLNotifyBox::parseNotify(const std::string& xml_filename) { LLXMLNodePtr root; BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); if (!success || root.isNull() || !root->hasName( "notifications" )) { llerrs << "Problem reading UI Notify file: " << xml_filename << llendl; return false; } for (LLXMLNode* notify = root->getFirstChild(); notify != NULL; notify = notify->getNextSibling()) { if (!notify->hasName("notify")) { continue; } BOOL unique = FALSE; notify->getAttributeBOOL("unique", unique); F32 duration = gSavedSettings.getF32("NotifyTipDuration"); notify->getAttributeF32("duration", duration); LLPointer<LLNotifyBoxTemplate> xml_template = new LLNotifyBoxTemplate(unique, duration); // label= std::string notify_name; if (notify->getAttributeString("name", notify_name)) { xml_template->mLabel = notify_name; } else { llwarns << "Unable to parse notify with no name" << llendl; continue; } // modal= BOOL tip; if (notify->getAttributeBOOL("tip", tip)) { xml_template->mIsTip = tip; } // parse a bool attribute named "caution" to determine // whether this notification gets cautionary special handling BOOL caution = FALSE; if (notify->getAttributeBOOL("caution", caution)) { if (xml_template) { xml_template->mIsCaution = caution; } } S32 btn_idx = 0; for (LLXMLNode* child = notify->getFirstChild(); child != NULL; child = child->getNextSibling()) { // <message> if (child->hasName("message")) { xml_template->mMessage = child->getTextContents(); } // <option> if (child->hasName("option")) { std::string label = child->getValue(); BOOL is_default = FALSE; child->getAttributeBOOL("default", is_default); std::string ignore_text; if (!child->getAttributeString("ignore", ignore_text)) { ignore_text = label; } xml_template->addOption(label, is_default); btn_idx++; } } //*TODO:translate if (xml_template->mOptions.empty()) { xml_template->addOption("OK", FALSE); } sNotifyTemplates[xml_template->mLabel] = xml_template; } return true; }