diff options
author | Jacek Antonelli | 2008-08-15 23:45:59 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:59 -0500 |
commit | 6e91a9cc3d5a610198cf526a76e2ab642f10ecd7 (patch) | |
tree | b023869f9daa7f61ea3ab27112d37524bdd88de4 /linden/indra/llxml | |
parent | Second Life viewer sources 1.20.12 (diff) | |
download | meta-impy-6e91a9cc3d5a610198cf526a76e2ab642f10ecd7.zip meta-impy-6e91a9cc3d5a610198cf526a76e2ab642f10ecd7.tar.gz meta-impy-6e91a9cc3d5a610198cf526a76e2ab642f10ecd7.tar.bz2 meta-impy-6e91a9cc3d5a610198cf526a76e2ab642f10ecd7.tar.xz |
Second Life viewer sources 1.20.13
Diffstat (limited to 'linden/indra/llxml')
-rw-r--r-- | linden/indra/llxml/llcontrol.cpp | 86 | ||||
-rw-r--r-- | linden/indra/llxml/llcontrol.h | 30 |
2 files changed, 92 insertions, 24 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 | { |
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 | |||
83 | TYPE_COUNT | 83 | TYPE_COUNT |
84 | } eControlType; | 84 | } eControlType; |
85 | 85 | ||
86 | class LLControlVariable | 86 | class LLControlVariable : public LLRefCount |
87 | { | 87 | { |
88 | friend class LLControlGroup; | 88 | friend class LLControlGroup; |
89 | typedef boost::signal<void(const LLSD&)> signal_t; | 89 | typedef boost::signal<void(const LLSD&)> signal_t; |
@@ -92,7 +92,7 @@ private: | |||
92 | LLString mName; | 92 | LLString mName; |
93 | LLString mComment; | 93 | LLString mComment; |
94 | eControlType mType; | 94 | eControlType mType; |
95 | BOOL mPersist; | 95 | bool mPersist; |
96 | std::vector<LLSD> mValues; | 96 | std::vector<LLSD> mValues; |
97 | 97 | ||
98 | signal_t mSignal; | 98 | signal_t mSignal; |
@@ -100,7 +100,7 @@ private: | |||
100 | public: | 100 | public: |
101 | LLControlVariable(const LLString& name, eControlType type, | 101 | LLControlVariable(const LLString& name, eControlType type, |
102 | LLSD initial, const LLString& comment, | 102 | LLSD initial, const LLString& comment, |
103 | BOOL persist = TRUE); | 103 | bool persist = true); |
104 | 104 | ||
105 | virtual ~LLControlVariable(); | 105 | virtual ~LLControlVariable(); |
106 | 106 | ||
@@ -108,33 +108,41 @@ public: | |||
108 | const LLString& getComment() const { return mComment; } | 108 | const LLString& getComment() const { return mComment; } |
109 | 109 | ||
110 | eControlType type() { return mType; } | 110 | eControlType type() { return mType; } |
111 | BOOL isType(eControlType tp) { return tp == mType; } | 111 | bool isType(eControlType tp) { return tp == mType; } |
112 | 112 | ||
113 | void resetToDefault(bool fire_signal = TRUE); | 113 | void resetToDefault(bool fire_signal = false); |
114 | 114 | ||
115 | signal_t* getSignal() { return &mSignal; } | 115 | signal_t* getSignal() { return &mSignal; } |
116 | 116 | ||
117 | bool isDefault() { return (mValues.size() == 1); } | 117 | bool isDefault() { return (mValues.size() == 1); } |
118 | bool isSaveValueDefault(); | 118 | bool isSaveValueDefault(); |
119 | bool isPersisted() { return mPersist; } | 119 | bool isPersisted() { return mPersist; } |
120 | void set(const LLSD& val) { setValue(val); } | ||
121 | LLSD get() const { return getValue(); } | 120 | LLSD get() const { return getValue(); } |
122 | LLSD getDefault() const { return mValues.front(); } | ||
123 | LLSD getValue() const { return mValues.back(); } | 121 | LLSD getValue() const { return mValues.back(); } |
122 | LLSD getDefault() const { return mValues.front(); } | ||
124 | LLSD getSaveValue() const; | 123 | LLSD getSaveValue() const; |
124 | |||
125 | void set(const LLSD& val) { setValue(val); } | ||
125 | void setValue(const LLSD& value, bool saved_value = TRUE); | 126 | void setValue(const LLSD& value, bool saved_value = TRUE); |
127 | void setDefaultValue(const LLSD& value); | ||
128 | void setPersist(bool state); | ||
129 | void setComment(const std::string& comment); | ||
130 | |||
126 | void firePropertyChanged() | 131 | void firePropertyChanged() |
127 | { | 132 | { |
128 | mSignal(mValues.back()); | 133 | mSignal(mValues.back()); |
129 | } | 134 | } |
130 | bool llsd_compare(const LLSD& a, const LLSD& b); | 135 | private: |
136 | LLSD getComparableValue(const LLSD& value); | ||
137 | bool llsd_compare(const LLSD& a, const LLSD & b); | ||
138 | |||
131 | }; | 139 | }; |
132 | 140 | ||
133 | //const U32 STRING_CACHE_SIZE = 10000; | 141 | //const U32 STRING_CACHE_SIZE = 10000; |
134 | class LLControlGroup | 142 | class LLControlGroup |
135 | { | 143 | { |
136 | protected: | 144 | protected: |
137 | typedef std::map<LLString, LLControlVariable* > ctrl_name_table_t; | 145 | typedef std::map<LLString, LLPointer<LLControlVariable> > ctrl_name_table_t; |
138 | ctrl_name_table_t mNameTable; | 146 | ctrl_name_table_t mNameTable; |
139 | std::set<LLString> mWarnings; | 147 | std::set<LLString> mWarnings; |
140 | LLString mTypeString[TYPE_COUNT]; | 148 | LLString mTypeString[TYPE_COUNT]; |
@@ -146,7 +154,7 @@ public: | |||
146 | ~LLControlGroup(); | 154 | ~LLControlGroup(); |
147 | void cleanup(); | 155 | void cleanup(); |
148 | 156 | ||
149 | LLControlVariable* getControl(const LLString& name); | 157 | LLPointer<LLControlVariable> getControl(const LLString& name); |
150 | 158 | ||
151 | struct ApplyFunctor | 159 | struct ApplyFunctor |
152 | { | 160 | { |
@@ -213,7 +221,7 @@ public: | |||
213 | // as the given type. | 221 | // as the given type. |
214 | U32 loadFromFileLegacy(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING); | 222 | U32 loadFromFileLegacy(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING); |
215 | U32 saveToFile(const LLString& filename, BOOL nondefault_only); | 223 | U32 saveToFile(const LLString& filename, BOOL nondefault_only); |
216 | U32 loadFromFile(const LLString& filename); | 224 | U32 loadFromFile(const LLString& filename, bool default_values = false); |
217 | void resetToDefaults(); | 225 | void resetToDefaults(); |
218 | 226 | ||
219 | 227 | ||