diff options
Diffstat (limited to 'linden/indra/llxml/llcontrol.cpp')
-rw-r--r-- | linden/indra/llxml/llcontrol.cpp | 86 |
1 files changed, 73 insertions, 13 deletions
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) | |||
101 | 101 | ||
102 | LLControlVariable::LLControlVariable(const LLString& name, eControlType type, | 102 | LLControlVariable::LLControlVariable(const LLString& name, eControlType type, |
103 | LLSD initial, const LLString& comment, | 103 | LLSD initial, const LLString& comment, |
104 | BOOL persist) | 104 | bool persist) |
105 | : mName(name), | 105 | : mName(name), |
106 | mComment(comment), | 106 | mComment(comment), |
107 | mType(type), | 107 | mType(type), |
@@ -121,7 +121,7 @@ LLControlVariable::~LLControlVariable() | |||
121 | { | 121 | { |
122 | } | 122 | } |
123 | 123 | ||
124 | void LLControlVariable::setValue(const LLSD& value, bool saved_value) | 124 | LLSD LLControlVariable::getComparableValue(const LLSD& value) |
125 | { | 125 | { |
126 | // *FIX:MEP - The following is needed to make the LLSD::ImplString | 126 | // *FIX:MEP - The following is needed to make the LLSD::ImplString |
127 | // work with boolean controls... | 127 | // work with boolean controls... |
@@ -131,11 +131,11 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value) | |||
131 | BOOL temp; | 131 | BOOL temp; |
132 | if(LLString::convertToBOOL(value.asString(), temp)) | 132 | if(LLString::convertToBOOL(value.asString(), temp)) |
133 | { | 133 | { |
134 | storable_value = temp; | 134 | storable_value = (bool)temp; |
135 | } | 135 | } |
136 | else | 136 | else |
137 | { | 137 | { |
138 | storable_value = FALSE; | 138 | storable_value = false; |
139 | } | 139 | } |
140 | } | 140 | } |
141 | else | 141 | else |
@@ -143,6 +143,12 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value) | |||
143 | storable_value = value; | 143 | storable_value = value; |
144 | } | 144 | } |
145 | 145 | ||
146 | return storable_value; | ||
147 | } | ||
148 | |||
149 | void LLControlVariable::setValue(const LLSD& value, bool saved_value) | ||
150 | { | ||
151 | LLSD storable_value = getComparableValue(value); | ||
146 | bool value_changed = llsd_compare(getValue(), storable_value) == FALSE; | 152 | bool value_changed = llsd_compare(getValue(), storable_value) == FALSE; |
147 | if(saved_value) | 153 | if(saved_value) |
148 | { | 154 | { |
@@ -184,12 +190,46 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value) | |||
184 | } | 190 | } |
185 | } | 191 | } |
186 | 192 | ||
193 | void LLControlVariable::setDefaultValue(const LLSD& value) | ||
194 | { | ||
195 | // Set the control variables value and make it | ||
196 | // the default value. If the active value is changed, | ||
197 | // send the signal. | ||
198 | // *NOTE: Default values are not saved, only read. | ||
199 | |||
200 | LLSD comparable_value = getComparableValue(value); | ||
201 | bool value_changed = (llsd_compare(getValue(), comparable_value) == FALSE); | ||
202 | resetToDefault(false); | ||
203 | mValues[0] = comparable_value; | ||
204 | if(value_changed) | ||
205 | { | ||
206 | firePropertyChanged(); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | void LLControlVariable::setPersist(bool state) | ||
211 | { | ||
212 | mPersist = state; | ||
213 | } | ||
214 | |||
215 | void LLControlVariable::setComment(const std::string& comment) | ||
216 | { | ||
217 | mComment = comment; | ||
218 | } | ||
219 | |||
187 | void LLControlVariable::resetToDefault(bool fire_signal) | 220 | void LLControlVariable::resetToDefault(bool fire_signal) |
188 | { | 221 | { |
189 | //The first setting is always the default | 222 | //The first setting is always the default |
190 | //Pop to it and fire off the listener | 223 | //Pop to it and fire off the listener |
191 | while(mValues.size() > 1) mValues.pop_back(); | 224 | while(mValues.size() > 1) |
192 | if(fire_signal) firePropertyChanged(); | 225 | { |
226 | mValues.pop_back(); | ||
227 | } | ||
228 | |||
229 | if(fire_signal) | ||
230 | { | ||
231 | firePropertyChanged(); | ||
232 | } | ||
193 | } | 233 | } |
194 | 234 | ||
195 | bool LLControlVariable::isSaveValueDefault() | 235 | bool LLControlVariable::isSaveValueDefault() |
@@ -206,10 +246,10 @@ LLSD LLControlVariable::getSaveValue() const | |||
206 | return mValues[0]; | 246 | return mValues[0]; |
207 | } | 247 | } |
208 | 248 | ||
209 | LLControlVariable* LLControlGroup::getControl(const LLString& name) | 249 | LLPointer<LLControlVariable> LLControlGroup::getControl(const LLString& name) |
210 | { | 250 | { |
211 | ctrl_name_table_t::iterator iter = mNameTable.find(name); | 251 | ctrl_name_table_t::iterator iter = mNameTable.find(name); |
212 | return iter == mNameTable.end() ? NULL : iter->second; | 252 | return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second; |
213 | } | 253 | } |
214 | 254 | ||
215 | 255 | ||
@@ -238,7 +278,6 @@ LLControlGroup::~LLControlGroup() | |||
238 | 278 | ||
239 | void LLControlGroup::cleanup() | 279 | void LLControlGroup::cleanup() |
240 | { | 280 | { |
241 | for_each(mNameTable.begin(), mNameTable.end(), DeletePairedPointer()); | ||
242 | mNameTable.clear(); | 281 | mNameTable.clear(); |
243 | } | 282 | } |
244 | 283 | ||
@@ -264,6 +303,7 @@ BOOL LLControlGroup::declareControl(const LLString& name, eControlType type, con | |||
264 | mNameTable[name]->setValue(initial_val); | 303 | mNameTable[name]->setValue(initial_val); |
265 | return TRUE; | 304 | return TRUE; |
266 | } | 305 | } |
306 | |||
267 | // if not, create the control and add it to the name table | 307 | // if not, create the control and add it to the name table |
268 | LLControlVariable* control = new LLControlVariable(name, type, initial_val, comment, persist); | 308 | LLControlVariable* control = new LLControlVariable(name, type, initial_val, comment, persist); |
269 | mNameTable[name] = control; | 309 | mNameTable[name] = control; |
@@ -983,7 +1023,7 @@ U32 LLControlGroup::saveToFile(const LLString& filename, BOOL nondefault_only) | |||
983 | return num_saved; | 1023 | return num_saved; |
984 | } | 1024 | } |
985 | 1025 | ||
986 | U32 LLControlGroup::loadFromFile(const LLString& filename) | 1026 | U32 LLControlGroup::loadFromFile(const LLString& filename, bool set_default_values) |
987 | { | 1027 | { |
988 | LLString name; | 1028 | LLString name; |
989 | LLSD settings; | 1029 | LLSD settings; |
@@ -1006,7 +1046,7 @@ U32 LLControlGroup::loadFromFile(const LLString& filename) | |||
1006 | } | 1046 | } |
1007 | 1047 | ||
1008 | U32 validitems = 0; | 1048 | U32 validitems = 0; |
1009 | int persist = 1; | 1049 | bool persist = false; |
1010 | for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) | 1050 | for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) |
1011 | { | 1051 | { |
1012 | name = (*itr).first; | 1052 | name = (*itr).first; |
@@ -1021,11 +1061,31 @@ U32 LLControlGroup::loadFromFile(const LLString& filename) | |||
1021 | LLControlVariable* existing_control = getControl(name); | 1061 | LLControlVariable* existing_control = getControl(name); |
1022 | if(existing_control) | 1062 | if(existing_control) |
1023 | { | 1063 | { |
1024 | // Check persistence. If not persisted, we shouldn't be loading. | 1064 | if(set_default_values) |
1025 | if(existing_control->isPersisted()) | ||
1026 | { | 1065 | { |
1066 | // Override all previously set properties of this control. | ||
1067 | // ... except for type. The types must match. | ||
1068 | eControlType new_type = typeStringToEnum(control_map["Type"].asString()); | ||
1069 | if(existing_control->isType(new_type)) | ||
1070 | { | ||
1071 | existing_control->setDefaultValue(control_map["Value"]); | ||
1072 | existing_control->setPersist(persist); | ||
1073 | existing_control->setComment(control_map["Comment"].asString()); | ||
1074 | } | ||
1075 | else | ||
1076 | { | ||
1077 | llerrs << "Mismatched type of control variable '" | ||
1078 | << name << "' found while loading '" | ||
1079 | << filename << "'." << llendl; | ||
1080 | } | ||
1081 | } | ||
1082 | else if(existing_control->isPersisted()) | ||
1083 | { | ||
1084 | |||
1027 | existing_control->setValue(control_map["Value"]); | 1085 | existing_control->setValue(control_map["Value"]); |
1028 | } | 1086 | } |
1087 | // *NOTE: If not persisted and not setting defaults, | ||
1088 | // the value should not get loaded. | ||
1029 | } | 1089 | } |
1030 | else | 1090 | else |
1031 | { | 1091 | { |