diff options
author | Oz Linden <oz@lindenlab.com> | 2015-09-28 15:00:17 -0400 |
---|---|---|
committer | Oz Linden <oz@lindenlab.com> | 2015-09-28 15:00:17 -0400 |
commit | 453dee2d21477ad534fa9982b844c40adde9b93e (patch) | |
tree | f98fbe8c5bd501cd4618f52a4d02ebd4718b54cf /indra | |
parent | e1ce065b8b2f4a01a166ddd90ef7c873e04d0893 (diff) |
MAINT-5542: fix initialization of Default graphics preset so that it is selectable
Diffstat (limited to 'indra')
-rwxr-xr-x | indra/newview/llfloaterpreference.cpp | 6 | ||||
-rw-r--r-- | indra/newview/llpanelpresetspulldown.cpp | 17 | ||||
-rw-r--r-- | indra/newview/llpanelpresetspulldown.h | 1 | ||||
-rw-r--r-- | indra/newview/llpresetsmanager.cpp | 126 | ||||
-rw-r--r-- | indra/newview/llpresetsmanager.h | 3 |
5 files changed, 98 insertions, 55 deletions
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<std::string>::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<std::string> 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<std::string>::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<LLSDFormatter> 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<std::string>::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<LLSDFormatter> 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 '"<<name<<"' from '"<<full_path<<"'" << LL_ENDL; + if(gSavedSettings.loadFromFile(full_path, false, true) > 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 '"<<name<<"' from '"<<full_path<<"'" << LL_ENDL; + } } bool LLPresetsManager::deletePreset(const std::string& subdirectory, const std::string& name) diff --git a/indra/newview/llpresetsmanager.h b/indra/newview/llpresetsmanager.h index a47c07dfba..ce640b49b1 100644 --- a/indra/newview/llpresetsmanager.h +++ b/indra/newview/llpresetsmanager.h @@ -71,6 +71,9 @@ public: ~LLPresetsManager(); preset_list_signal_t mPresetListChangeSignal; + + private: + LOG_CLASS(LLPresetsManager); }; #endif // LL_PRESETSMANAGER_H |