From 6e91a9cc3d5a610198cf526a76e2ab642f10ecd7 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:59 -0500 Subject: Second Life viewer sources 1.20.13 --- linden/indra/llxml/llcontrol.cpp | 86 ++++++++++++++++++++++++++++++++++------ linden/indra/llxml/llcontrol.h | 30 +++++++++----- 2 files changed, 92 insertions(+), 24 deletions(-) (limited to 'linden/indra/llxml') diff --git a/linden/indra/llxml/llcontrol.cpp b/linden/indra/llxml/llcontrol.cpp index 09719a5..f88ac69 100644 --- a/linden/indra/llxml/llcontrol.cpp +++ b/linden/indra/llxml/llcontrol.cpp @@ -101,7 +101,7 @@ bool LLControlVariable::llsd_compare(const LLSD& a, const LLSD & b) LLControlVariable::LLControlVariable(const LLString& name, eControlType type, LLSD initial, const LLString& comment, - BOOL persist) + bool persist) : mName(name), mComment(comment), mType(type), @@ -121,7 +121,7 @@ LLControlVariable::~LLControlVariable() { } -void LLControlVariable::setValue(const LLSD& value, bool saved_value) +LLSD LLControlVariable::getComparableValue(const LLSD& value) { // *FIX:MEP - The following is needed to make the LLSD::ImplString // work with boolean controls... @@ -131,11 +131,11 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value) BOOL temp; if(LLString::convertToBOOL(value.asString(), temp)) { - storable_value = temp; + storable_value = (bool)temp; } else { - storable_value = FALSE; + storable_value = false; } } else @@ -143,6 +143,12 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value) storable_value = value; } + return storable_value; +} + +void LLControlVariable::setValue(const LLSD& value, bool saved_value) +{ + LLSD storable_value = getComparableValue(value); bool value_changed = llsd_compare(getValue(), storable_value) == FALSE; if(saved_value) { @@ -184,12 +190,46 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value) } } +void LLControlVariable::setDefaultValue(const LLSD& value) +{ + // Set the control variables value and make it + // the default value. If the active value is changed, + // send the signal. + // *NOTE: Default values are not saved, only read. + + LLSD comparable_value = getComparableValue(value); + bool value_changed = (llsd_compare(getValue(), comparable_value) == FALSE); + resetToDefault(false); + mValues[0] = comparable_value; + if(value_changed) + { + firePropertyChanged(); + } +} + +void LLControlVariable::setPersist(bool state) +{ + mPersist = state; +} + +void LLControlVariable::setComment(const std::string& comment) +{ + mComment = comment; +} + void LLControlVariable::resetToDefault(bool fire_signal) { //The first setting is always the default //Pop to it and fire off the listener - while(mValues.size() > 1) mValues.pop_back(); - if(fire_signal) firePropertyChanged(); + while(mValues.size() > 1) + { + mValues.pop_back(); + } + + if(fire_signal) + { + firePropertyChanged(); + } } bool LLControlVariable::isSaveValueDefault() @@ -206,10 +246,10 @@ LLSD LLControlVariable::getSaveValue() const return mValues[0]; } -LLControlVariable* LLControlGroup::getControl(const LLString& name) +LLPointer LLControlGroup::getControl(const LLString& name) { ctrl_name_table_t::iterator iter = mNameTable.find(name); - return iter == mNameTable.end() ? NULL : iter->second; + return iter == mNameTable.end() ? LLPointer() : iter->second; } @@ -238,7 +278,6 @@ LLControlGroup::~LLControlGroup() void LLControlGroup::cleanup() { - for_each(mNameTable.begin(), mNameTable.end(), DeletePairedPointer()); mNameTable.clear(); } @@ -264,6 +303,7 @@ BOOL LLControlGroup::declareControl(const LLString& name, eControlType type, con mNameTable[name]->setValue(initial_val); return TRUE; } + // if not, create the control and add it to the name table LLControlVariable* control = new LLControlVariable(name, type, initial_val, comment, persist); mNameTable[name] = control; @@ -983,7 +1023,7 @@ U32 LLControlGroup::saveToFile(const LLString& filename, BOOL nondefault_only) return num_saved; } -U32 LLControlGroup::loadFromFile(const LLString& filename) +U32 LLControlGroup::loadFromFile(const LLString& filename, bool set_default_values) { LLString name; LLSD settings; @@ -1006,7 +1046,7 @@ U32 LLControlGroup::loadFromFile(const LLString& filename) } U32 validitems = 0; - int persist = 1; + bool persist = false; for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) { name = (*itr).first; @@ -1021,11 +1061,31 @@ U32 LLControlGroup::loadFromFile(const LLString& filename) LLControlVariable* existing_control = getControl(name); if(existing_control) { - // Check persistence. If not persisted, we shouldn't be loading. - if(existing_control->isPersisted()) + if(set_default_values) { + // Override all previously set properties of this control. + // ... except for type. The types must match. + eControlType new_type = typeStringToEnum(control_map["Type"].asString()); + if(existing_control->isType(new_type)) + { + existing_control->setDefaultValue(control_map["Value"]); + existing_control->setPersist(persist); + existing_control->setComment(control_map["Comment"].asString()); + } + else + { + llerrs << "Mismatched type of control variable '" + << name << "' found while loading '" + << filename << "'." << llendl; + } + } + else if(existing_control->isPersisted()) + { + existing_control->setValue(control_map["Value"]); } + // *NOTE: If not persisted and not setting defaults, + // the value should not get loaded. } else { diff --git a/linden/indra/llxml/llcontrol.h b/linden/indra/llxml/llcontrol.h index 91545ce..2500ae0 100644 --- a/linden/indra/llxml/llcontrol.h +++ b/linden/indra/llxml/llcontrol.h @@ -83,7 +83,7 @@ typedef enum e_control_type TYPE_COUNT } eControlType; -class LLControlVariable +class LLControlVariable : public LLRefCount { friend class LLControlGroup; typedef boost::signal signal_t; @@ -92,7 +92,7 @@ private: LLString mName; LLString mComment; eControlType mType; - BOOL mPersist; + bool mPersist; std::vector mValues; signal_t mSignal; @@ -100,7 +100,7 @@ private: public: LLControlVariable(const LLString& name, eControlType type, LLSD initial, const LLString& comment, - BOOL persist = TRUE); + bool persist = true); virtual ~LLControlVariable(); @@ -108,33 +108,41 @@ public: const LLString& getComment() const { return mComment; } eControlType type() { return mType; } - BOOL isType(eControlType tp) { return tp == mType; } + bool isType(eControlType tp) { return tp == mType; } - void resetToDefault(bool fire_signal = TRUE); + void resetToDefault(bool fire_signal = false); signal_t* getSignal() { return &mSignal; } bool isDefault() { return (mValues.size() == 1); } bool isSaveValueDefault(); bool isPersisted() { return mPersist; } - void set(const LLSD& val) { setValue(val); } LLSD get() const { return getValue(); } - LLSD getDefault() const { return mValues.front(); } LLSD getValue() const { return mValues.back(); } + LLSD getDefault() const { return mValues.front(); } LLSD getSaveValue() const; + + void set(const LLSD& val) { setValue(val); } void setValue(const LLSD& value, bool saved_value = TRUE); + void setDefaultValue(const LLSD& value); + void setPersist(bool state); + void setComment(const std::string& comment); + void firePropertyChanged() { mSignal(mValues.back()); } - bool llsd_compare(const LLSD& a, const LLSD& b); +private: + LLSD getComparableValue(const LLSD& value); + bool llsd_compare(const LLSD& a, const LLSD & b); + }; //const U32 STRING_CACHE_SIZE = 10000; class LLControlGroup { protected: - typedef std::map ctrl_name_table_t; + typedef std::map > ctrl_name_table_t; ctrl_name_table_t mNameTable; std::set mWarnings; LLString mTypeString[TYPE_COUNT]; @@ -146,7 +154,7 @@ public: ~LLControlGroup(); void cleanup(); - LLControlVariable* getControl(const LLString& name); + LLPointer getControl(const LLString& name); struct ApplyFunctor { @@ -213,7 +221,7 @@ public: // as the given type. U32 loadFromFileLegacy(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING); U32 saveToFile(const LLString& filename, BOOL nondefault_only); - U32 loadFromFile(const LLString& filename); + U32 loadFromFile(const LLString& filename, bool default_values = false); void resetToDefaults(); -- cgit v1.1