From 453dee2d21477ad534fa9982b844c40adde9b93e Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Mon, 28 Sep 2015 15:00:17 -0400 Subject: MAINT-5542: fix initialization of Default graphics preset so that it is selectable --- indra/newview/llfloaterpreference.cpp | 6 +- indra/newview/llpanelpresetspulldown.cpp | 17 ++++- indra/newview/llpanelpresetspulldown.h | 1 + indra/newview/llpresetsmanager.cpp | 126 +++++++++++++++++++------------ indra/newview/llpresetsmanager.h | 3 + 5 files changed, 98 insertions(+), 55 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp index 898e5d5e1f..340959880c 100755 --- a/indra/newview/llfloaterpreference.cpp +++ b/indra/newview/llfloaterpreference.cpp @@ -2422,8 +2422,10 @@ BOOL LLPanelPreferenceGraphics::postBuild() resetDirtyChilds(); setPresetText(); - LLPresetsManager::instance().setPresetListChangeCallback(boost::bind(&LLPanelPreferenceGraphics::onPresetsListChange, this)); - + LLPresetsManager* presetsMgr = LLPresetsManager::getInstance(); + presetsMgr->setPresetListChangeCallback(boost::bind(&LLPanelPreferenceGraphics::onPresetsListChange, this)); + presetsMgr->createMissingDefault(); // a no-op after the first time, but that's ok + return LLPanelPreference::postBuild(); } diff --git a/indra/newview/llpanelpresetspulldown.cpp b/indra/newview/llpanelpresetspulldown.cpp index a0bd8f5ad0..ed67c34bd6 100644 --- a/indra/newview/llpanelpresetspulldown.cpp +++ b/indra/newview/llpanelpresetspulldown.cpp @@ -59,9 +59,10 @@ LLPanelPresetsPulldown::LLPanelPresetsPulldown() BOOL LLPanelPresetsPulldown::postBuild() { - LLPresetsManager::instance().setPresetListChangeCallback(boost::bind(&LLPanelPresetsPulldown::populatePanel, this)); + LLPresetsManager* presetsMgr = LLPresetsManager::getInstance(); + presetsMgr->setPresetListChangeCallback(boost::bind(&LLPanelPresetsPulldown::populatePanel, this)); // Make sure there is a default preference file - LLPresetsManager::getInstance()->createMissingDefault(); + presetsMgr->createMissingDefault(); populatePanel(); @@ -82,7 +83,8 @@ void LLPanelPresetsPulldown::populatePanel() for (std::list::const_iterator it = mPresetNames.begin(); it != mPresetNames.end(); ++it) { const std::string& name = *it; - + LL_DEBUGS() << "adding '" << name << "'" << LL_ENDL; + LLSD row; row["columns"][0]["column"] = "preset_name"; row["columns"][0]["value"] = name; @@ -151,11 +153,20 @@ void LLPanelPresetsPulldown::onRowClick(const LLSD& user_data) { std::string name = item->getColumn(1)->getValue().asString(); + LL_DEBUGS() << "selected '" << name << "'" << LL_ENDL; LLPresetsManager::getInstance()->loadPreset(PRESETS_GRAPHIC, name); setVisible(FALSE); } + else + { + LL_DEBUGS() << "none selected" << LL_ENDL; + } } + else + { + LL_DEBUGS() << "no scroll" << LL_ENDL; + } } void LLPanelPresetsPulldown::onGraphicsButtonClick(const LLSD& user_data) diff --git a/indra/newview/llpanelpresetspulldown.h b/indra/newview/llpanelpresetspulldown.h index edecad05a2..e1e2c26a86 100644 --- a/indra/newview/llpanelpresetspulldown.h +++ b/indra/newview/llpanelpresetspulldown.h @@ -54,6 +54,7 @@ class LLPanelPresetsPulldown : public LLPanel LLFrameTimer mHoverTimer; static const F32 sAutoCloseFadeStartTimeSec; static const F32 sAutoCloseTotalTimeSec; + LOG_CLASS(LLPanelPresetsPulldown); }; #endif // LL_LLPANELPRESETSPULLDOWN_H diff --git a/indra/newview/llpresetsmanager.cpp b/indra/newview/llpresetsmanager.cpp index c84baeba78..8aad37e505 100644 --- a/indra/newview/llpresetsmanager.cpp +++ b/indra/newview/llpresetsmanager.cpp @@ -54,19 +54,18 @@ void LLPresetsManager::triggerChangeSignal() void LLPresetsManager::createMissingDefault() { - std::string default_file = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, PRESETS_DIR, PRESETS_GRAPHIC, "default.xml"); + std::string default_file = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, PRESETS_DIR, PRESETS_GRAPHIC, PRESETS_DEFAULT + ".xml"); if (!gDirUtilp->fileExists(default_file)) { - LL_WARNS() << "No " << default_file << " found -- creating one" << LL_ENDL; + LL_INFOS() << "No default preset found -- creating one at " << default_file << LL_ENDL; - // Write current graphic settings to default.xml + // Write current graphic settings as the default savePreset(PRESETS_GRAPHIC, PRESETS_DEFAULT); - - if (gSavedSettings.getString("PresetGraphicActive").empty()) - { - gSavedSettings.setString("PresetGraphicActive", PRESETS_DEFAULT); - } } + else + { + LL_DEBUGS() << "default preset exists; no-op" << LL_ENDL; + } } std::string LLPresetsManager::getPresetsDir(const std::string& subdirectory) @@ -106,6 +105,8 @@ void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir, preset_nam std::string path = gDirUtilp->add(dir, file); std::string name = gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true); + LL_DEBUGS() << " Found preset '" << name << "'" << LL_ENDL; + if (PRESETS_DEFAULT != name) { mPresetNames.push_back(name); @@ -135,8 +136,7 @@ void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir, preset_nam bool LLPresetsManager::savePreset(const std::string& subdirectory, const std::string& name) { - llassert(!name.empty()); - + bool saved = false; std::vector name_list; if(PRESETS_GRAPHIC == subdirectory) @@ -147,53 +147,73 @@ bool LLPresetsManager::savePreset(const std::string& subdirectory, const std::st if (instance) { instance->getControlNames(name_list); + LL_DEBUGS() << "saving preset '" << name << "'; " << name_list.size() << " names" << LL_ENDL; name_list.push_back("PresetGraphicActive"); } + else + { + LL_WARNS() << "preferences floater instance not found" << LL_ENDL; + } } - - if(PRESETS_CAMERA == subdirectory) + else if(PRESETS_CAMERA == subdirectory) { name_list = boost::assign::list_of ("Placeholder"); } - - // make an empty llsd - LLSD paramsData(LLSD::emptyMap()); - - for (std::vector::iterator it = name_list.begin(); it != name_list.end(); ++it) - { - std::string ctrl_name = *it; - LLControlVariable* ctrl = gSavedSettings.getControl(ctrl_name).get(); - std::string comment = ctrl->getComment(); - std::string type = gSavedSettings.typeEnumToString(ctrl->type()); - LLSD value = ctrl->getValue(); - - paramsData[ctrl_name]["Comment"] = comment; - paramsData[ctrl_name]["Persist"] = 1; - paramsData[ctrl_name]["Type"] = type; - paramsData[ctrl_name]["Value"] = value; - } - - std::string pathName(getPresetsDir(subdirectory) + gDirUtilp->getDirDelimiter() + LLURI::escape(name) + ".xml"); - - // write to file - llofstream presetsXML(pathName.c_str()); - if (!presetsXML.is_open()) - { - LL_WARNS("Presets") << "Cannot open for output preset file " << pathName << LL_ENDL; - return false; - } - - LLPointer formatter = new LLSDXMLFormatter(); - formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); - presetsXML.close(); - - gSavedSettings.setString("PresetGraphicActive", name); - - // signal interested parties - triggerChangeSignal(); - - return true; + else + { + LL_ERRS() << "Invalid presets directory '" << subdirectory << "'" << LL_ENDL; + } + + if (name_list.size() > 1) // if the active preset name is the only thing in the list, don't save the list + { + // make an empty llsd + LLSD paramsData(LLSD::emptyMap()); + + for (std::vector::iterator it = name_list.begin(); it != name_list.end(); ++it) + { + std::string ctrl_name = *it; + LLControlVariable* ctrl = gSavedSettings.getControl(ctrl_name).get(); + std::string comment = ctrl->getComment(); + std::string type = gSavedSettings.typeEnumToString(ctrl->type()); + LLSD value = ctrl->getValue(); + + paramsData[ctrl_name]["Comment"] = comment; + paramsData[ctrl_name]["Persist"] = 1; + paramsData[ctrl_name]["Type"] = type; + paramsData[ctrl_name]["Value"] = value; + } + + std::string pathName(getPresetsDir(subdirectory) + gDirUtilp->getDirDelimiter() + LLURI::escape(name) + ".xml"); + + // write to file + llofstream presetsXML(pathName.c_str()); + if (presetsXML.is_open()) + { + + LLPointer formatter = new LLSDXMLFormatter(); + formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY); + presetsXML.close(); + saved = true; + + LL_DEBUGS() << "saved preset '" << name << "'; " << paramsData.size() << " parameters" << LL_ENDL; + + gSavedSettings.setString("PresetGraphicActive", name); + + // signal interested parties + triggerChangeSignal(); + } + else + { + LL_WARNS("Presets") << "Cannot open for output preset file " << pathName << LL_ENDL; + } + } + else + { + LL_INFOS() << "No settings found; preferences floater has not yet been created" << LL_ENDL; + } + + return saved; } void LLPresetsManager::setPresetNamesInComboBox(const std::string& subdirectory, LLComboBox* combo, EDefaultOptions default_option) @@ -228,6 +248,8 @@ void LLPresetsManager::loadPreset(const std::string& subdirectory, const std::st { std::string full_path(getPresetsDir(subdirectory) + gDirUtilp->getDirDelimiter() + LLURI::escape(name) + ".xml"); + LL_DEBUGS() << "attempting to load preset '"< 0) { if(PRESETS_GRAPHIC == subdirectory) @@ -242,6 +264,10 @@ void LLPresetsManager::loadPreset(const std::string& subdirectory, const std::st } triggerChangeSignal(); } + else + { + LL_WARNS() << "failed to load preset '"<