summaryrefslogtreecommitdiff
path: root/indra/newview/llpresetsmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpresetsmanager.cpp')
-rw-r--r--indra/newview/llpresetsmanager.cpp126
1 files changed, 76 insertions, 50 deletions
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)