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); } } }
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; }
// static LLView* LLComboBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { std::string name("combo_box"); node->getAttributeString("name", name); std::string label(""); node->getAttributeString("label", label); LLRect rect; createRect(node, rect, parent, LLRect()); BOOL allow_text_entry = FALSE; node->getAttributeBOOL("allow_text_entry", allow_text_entry); S32 max_chars = 20; node->getAttributeS32("max_chars", max_chars); LLUICtrlCallback callback = NULL; LLComboBox* combo_box = new LLComboBox(name, rect, label, callback, NULL); combo_box->setAllowTextEntry(allow_text_entry, max_chars); combo_box->initFromXML(node, parent); const std::string& contents = node->getValue(); if (contents.find_first_not_of(" \n\t") != contents.npos) { llerrs << "Legacy combo box item format used! Please convert to <combo_item> tags!" << llendl; } else { LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { if (child->hasName("combo_item")) { std::string label = child->getTextContents(); std::string value = label; child->getAttributeString("value", value); combo_box->add(label, LLSD(value) ); } } } combo_box->selectFirstItem(); return combo_box; }
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 LLView* LLFlyoutButton::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { std::string name = "flyout_button"; node->getAttributeString("name", name); std::string label(""); node->getAttributeString("label", label); LLRect rect; createRect(node, rect, parent, LLRect()); LLUICtrlCallback callback = NULL; LLFlyoutButton* flyout_button = new LLFlyoutButton(name, rect, label, callback, NULL); std::string list_position; node->getAttributeString("list_position", list_position); if (list_position == "below") { flyout_button->mListPosition = BELOW; } else if (list_position == "above") { flyout_button->mListPosition = ABOVE; } flyout_button->initFromXML(node, parent); LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { if (child->hasName("flyout_button_item")) { std::string label = child->getTextContents(); std::string value = label; child->getAttributeString("value", value); flyout_button->add(label, LLSD(value) ); } } flyout_button->updateLayout(); return flyout_button; }
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; }
//static LLView* LLFlyoutButton::fromXML(LLXMLNodePtr node, LLView* parent, LLUICtrlFactory* factory) { std::string label(""); node->getAttributeString("label", label); LLRect rect; createRect(node, rect, parent, LLRect()); LLFlyoutButton* flyout_button = new LLFlyoutButton("flyout_button", rect, label); std::string list_position; node->getAttributeString("list_position", list_position); if (list_position == "below") { flyout_button->mListPosition = BELOW; } else if (list_position == "above") { flyout_button->mListPosition = ABOVE; } if (LLFontGL* font = selectFont(node)) flyout_button->mActionButton->setFont(font); flyout_button->initFromXML(node, parent); for (LLXMLNodePtr child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { if (child->hasName(LL_FLYOUT_BUTTON_ITEM_TAG)) { std::string label(child->getTextContents()); child->getAttributeString("label", label); std::string value(label); child->getAttributeString("value", value); flyout_button->add(label, LLSD(value)); } } flyout_button->updateLayout(); return flyout_button; }
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; }
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; }
// static LLView* LLComboBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { std::string name("combo_box"); node->getAttributeString("name", name); std::string label(""); node->getAttributeString("label", label); LLRect rect; createRect(node, rect, parent, LLRect()); BOOL allow_text_entry = FALSE; node->getAttributeBOOL("allow_text_entry", allow_text_entry); S32 max_chars = 20; node->getAttributeS32("max_chars", max_chars); LLUICtrlCallback callback = NULL; LLComboBox* combo_box = new LLComboBox(name, rect, label, callback, NULL); combo_box->setAllowTextEntry(allow_text_entry, max_chars); combo_box->initFromXML(node, parent); const std::string& contents = node->getValue(); if (contents.find_first_not_of(" \n\t") != contents.npos) { llerrs << "Legacy combo box item format used! Please convert to <combo_item> tags!" << llendl; } else { LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { if (child->hasName("combo_item")) { std::string label = child->getTextContents(); std::string value = label; child->getAttributeString("value", value); LLScrollListItem * item=combo_box->add(label, LLSD(value) ); if(item && child->hasAttribute("tool_tip")) { std::string tool_tip = label; child->getAttributeString("tool_tip", tool_tip); item->setToolTip(tool_tip); } } } } // if providing user text entry or descriptive label // don't select an item under the hood if (!combo_box->acceptsTextInput() && combo_box->mLabel.empty()) { combo_box->selectFirstItem(); } return combo_box; }
// static LLView* LLRadioGroup::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) { std::string name("radio_group"); node->getAttributeString("name", name); U32 initial_value = 0; node->getAttributeU32("initial_value", initial_value); BOOL draw_border = TRUE; node->getAttributeBOOL("draw_border", draw_border); LLRect rect; createRect(node, rect, parent, LLRect()); LLRadioGroup* radio_group = new LLRadioGroup(name, rect, initial_value, NULL, NULL, draw_border); const std::string& contents = node->getValue(); LLRect group_rect = radio_group->getRect(); LLFontGL *font = LLView::selectFont(node); if (contents.find_first_not_of(" \n\t") != contents.npos) { // ...old school default vertical layout typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep("\t\n"); tokenizer tokens(contents, sep); tokenizer::iterator token_iter = tokens.begin(); const S32 HPAD = 4, VPAD = 4; S32 cur_y = group_rect.getHeight() - VPAD; while(token_iter != tokens.end()) { const std::string& line = *token_iter; LLRect rect(HPAD, cur_y, group_rect.getWidth() - (2 * HPAD), cur_y - 15); cur_y -= VPAD + 15; radio_group->addRadioButton(std::string("radio"), line, rect, font); ++token_iter; } llwarns << "Legacy radio group format used! Please convert to use <radio_item> tags!" << llendl; } else { // ...per pixel layout LLXMLNodePtr child; for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling()) { if (child->hasName("radio_item")) { LLRect item_rect; createRect(child, item_rect, radio_group, rect); std::string radioname("radio"); child->getAttributeString("name", radioname); std::string item_label = child->getTextContents(); LLRadioCtrl* radio = radio_group->addRadioButton(radioname, item_label, item_rect, font); radio->initFromXML(child, radio_group); } } } radio_group->initFromXML(node, parent); return radio_group; }
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; }