COA stuff rolled into gSavedSettings.

Added common script<->client command junk.
This commit is contained in:
unknown
2010-10-19 18:50:47 -05:00
parent 4e854ffd2b
commit 4929460c66
28 changed files with 1732 additions and 1718 deletions

View File

@@ -59,6 +59,26 @@
//this defines the current version of the settings file
const S32 CURRENT_VERSION = 101;
//Currently global. Would be better in LLControlGroup... except that that requires LLControlVars to know their parent group.
//Could also pass the setting to each COA var too.. but that's not much better.
//Can't use llcachedcontrol as an alternative as that drags in LLCachedControl constructors that refer to gSavedSettings.. which'll break
// the crashlogger which also includes llxml.lib (unresolved externals).
//So, a global it is!
bool gCOAEnabled = false;
inline LLControlVariable *LLControlVariable::getCOAActive()
{
//if no coa connection, return 'this'
//if per account is ON and this IS a parent, return child var
//if per account is ON and this IS NOT a parent, return 'this'
//if per account is OFF and this IS NOT a parent, return parent var
//if per account is OFF and this IS a parent, return 'this'
if(getCOAConnection() && gCOAEnabled == isCOAParent())
return getCOAConnection();
else
return this;
}
bool LLControlVariable::llsd_compare(const LLSD& a, const LLSD & b)
{
bool result = false;
@@ -102,12 +122,16 @@ bool LLControlVariable::llsd_compare(const LLSD& a, const LLSD & b)
LLControlVariable::LLControlVariable(const std::string& name, eControlType type,
LLSD initial, const std::string& comment,
bool persist, bool hidefromsettingseditor)
bool persist, bool hidefromsettingseditor, bool IsCOA)
: mName(name),
mComment(comment),
mType(type),
mPersist(persist),
mHideFromSettingsEditor(hidefromsettingseditor)
mHideFromSettingsEditor(hidefromsettingseditor),
mSignal(new signal_t),
mIsCOA(IsCOA),
mIsCOAParent(false),
mCOAConnectedVar(NULL)
{
if (mPersist && mComment.empty())
{
@@ -188,7 +212,8 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value)
if(value_changed)
{
mSignal(storable_value);
if(getCOAActive() == this)
(*mSignal)(storable_value);
}
}
@@ -205,6 +230,7 @@ void LLControlVariable::setDefaultValue(const LLSD& value)
mValues[0] = comparable_value;
if(value_changed)
{
if(getCOAActive() == this)
firePropertyChanged();
}
}
@@ -235,6 +261,7 @@ void LLControlVariable::resetToDefault(bool fire_signal)
if(fire_signal)
{
if(getCOAActive() == this)
firePropertyChanged();
}
}
@@ -276,7 +303,13 @@ LLPointer<LLControlVariable> LLControlGroup::getControl(const std::string& name)
gSettingsCallMap.push_back(std::pair<std::string, U32>(name.c_str(),1));
}
#endif //PROF_CTRL_CALLS
return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second;
//return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second;
LLControlVariable *pFoundVar = (iter != mNameTable.end()) ? iter->second : NULL;
if(pFoundVar)
return pFoundVar->getCOAActive();
else
return LLPointer<LLControlVariable>();
}
@@ -322,7 +355,7 @@ std::string LLControlGroup::typeEnumToString(eControlType typeenum)
return mTypeString[typeenum];
}
BOOL LLControlGroup::declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist, BOOL hidefromsettingseditor)
BOOL LLControlGroup::declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist, BOOL hidefromsettingseditor, bool IsCOA)
{
LLControlVariable* existing_control = getControl(name);
if (existing_control)
@@ -335,6 +368,7 @@ BOOL LLControlGroup::declareControl(const std::string& name, eControlType type,
LLSD cur_value = existing_control->getValue(); // get the current value
existing_control->setDefaultValue(initial_val); // set the default to the declared value
existing_control->setValue(cur_value); // now set to the loaded value
existing_control->setIsCOA(IsCOA);
}
}
else
@@ -345,7 +379,7 @@ BOOL LLControlGroup::declareControl(const std::string& name, eControlType type,
}
// if not, create the control and add it to the name table
LLControlVariable* control = new LLControlVariable(name, type, initial_val, comment, persist, hidefromsettingseditor);
LLControlVariable* control = new LLControlVariable(name, type, initial_val, comment, persist, hidefromsettingseditor, IsCOA);
mNameTable[name] = control;
return TRUE;
}
@@ -1061,6 +1095,9 @@ U32 LLControlGroup::saveToFile(const std::string& filename, BOOL nondefault_only
U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_values)
{
if(mIncludedFiles.find(filename) != mIncludedFiles.end())
return 0; //Already included this file.
std::string name;
LLSD settings;
LLSD control_map;
@@ -1089,6 +1126,24 @@ U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_v
name = (*itr).first;
control_map = (*itr).second;
if(name == "Include")
{
if(control_map.isArray())
{
#if LL_WINDOWS
size_t pos = filename.find_last_of("\\");
#else
size_t pos = filename.find_last_of("/");
#endif
if(pos!=std::string::npos)
{
const std::string dir = filename.substr(0,++pos);
for(LLSD::array_const_iterator array_itr = control_map.beginArray(); array_itr != control_map.endArray(); ++array_itr)
validitems+=loadFromFile(dir+(*array_itr).asString(),set_default_values);
}
}
continue;
}
if(control_map.has("Persist"))
{
persist = control_map["Persist"].asInteger();
@@ -1139,13 +1194,16 @@ U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_v
}
else
{
bool IsCOA = control_map.has("IsCOA") && !!control_map["IsCOA"].asInteger();
declareControl(name,
typeStringToEnum(control_map["Type"].asString()),
control_map["Value"],
control_map["Comment"].asString(),
persist,
hidefromsettingseditor
hidefromsettingseditor,
IsCOA
);
}
++validitems;
@@ -1175,6 +1233,53 @@ void LLControlGroup::applyToAll(ApplyFunctor* func)
}
}
void LLControlGroup::connectCOAVars(LLControlGroup &OtherGroup)
{
LLControlVariable *pCOAVar = NULL;
for (ctrl_name_table_t::iterator iter = mNameTable.begin();
iter != mNameTable.end(); iter++)
{
if(iter->second->isCOA())
{
LLControlVariable *pParent = iter->second;
LLControlVariable *pChild = OtherGroup.getControl(pParent->getName());
if(!pChild)
{
OtherGroup.declareControl(
pParent->getName(),
pParent->type(),
pParent->getDefault(),
pParent->getComment(),
pParent->isPersisted(),
true);
pChild = OtherGroup.getControl(pParent->getName());
}
if(pChild)
{
pParent->setCOAConnect(pChild,true);
pChild->setCOAConnect(pParent,false);
}
}
else if(iter->second->getName() == "AscentStoreSettingsPerAccount")
pCOAVar = iter->second;
}
if(pCOAVar)
{
pCOAVar->getSignal()->connect(boost::bind(&LLControlGroup::handleCOASettingChange, this, _1));
pCOAVar->firePropertyChanged();
}
}
void LLControlGroup::updateCOASetting(bool coa_enabled)
{
for (ctrl_name_table_t::iterator iter = mNameTable.begin();
iter != mNameTable.end(); iter++)
{
if(iter->second->getCOAConnection())
iter->second->getCOAActive()->firePropertyChanged();
}
}
//============================================================================
// First-use
@@ -1224,6 +1329,12 @@ void LLControlGroup::resetWarnings()
}
}
bool LLControlGroup::handleCOASettingChange(const LLSD& newvalue)
{
gCOAEnabled = !!newvalue.asInteger(); //TODO. De-globalize this.
updateCOASetting(gCOAEnabled);
return true;
}
//============================================================================
#ifdef TEST_HARNESS

View File

@@ -72,7 +72,7 @@ const BOOL NO_PERSIST = FALSE;
// Saved at end of session
class LLControlGroup; //Defined further down
extern LLControlGroup gSavedSettings; //Default control group used in LLCachedControl
extern LLControlGroup *gCOASavedSettings; //Used in LLCachedCOAControl
extern LLControlGroup gSavedPerAccountSettings; //For ease
typedef enum e_control_type
{
@@ -104,12 +104,16 @@ private:
bool mHideFromSettingsEditor;
std::vector<LLSD> mValues;
signal_t mSignal;
boost::shared_ptr<signal_t> mSignal; //Signals are non-copyable. Therefore, using a pointer so vars can 'share' signals for COA
//COA stuff:
bool mIsCOA; //To have COA connection set.
bool mIsCOAParent; //if true, use if settingsperaccount is false.
LLControlVariable *mCOAConnectedVar;//Because the two vars refer to eachother, LLPointer would be a circular refrence..
public:
LLControlVariable(const std::string& name, eControlType type,
LLSD initial, const std::string& comment,
bool persist = true, bool hidefromsettingseditor = false);
bool persist = true, bool hidefromsettingseditor = false, bool IsCOA = false);
virtual ~LLControlVariable();
@@ -121,7 +125,7 @@ public:
void resetToDefault(bool fire_signal = false);
signal_t* getSignal() { return &mSignal; }
signal_t* getSignal() { return mSignal.get(); }
bool isDefault() { return (mValues.size() == 1); }
bool isSaveValueDefault();
@@ -141,7 +145,21 @@ public:
void firePropertyChanged()
{
mSignal(mValues.back());
(*mSignal)(mValues.back());
}
//COA stuff
bool isCOA() const { return mIsCOA; }
bool isCOAParent() const { return mIsCOAParent; }
LLControlVariable *getCOAConnection() const { return mCOAConnectedVar; }
LLControlVariable *getCOAActive();
void setIsCOA(bool IsCOA) { mIsCOA=IsCOA; }
void setCOAConnect(LLControlVariable *pConnect, bool IsParent)
{
mIsCOAParent=IsParent;
mCOAConnectedVar=pConnect;
if(!IsParent)
mSignal = pConnect->mSignal; //Share a single signal.
}
private:
LLSD getComparableValue(const LLSD& value);
@@ -160,6 +178,7 @@ protected:
eControlType typeStringToEnum(const std::string& typestr);
std::string typeEnumToString(eControlType typeenum);
std::set<std::string> mIncludedFiles; //To prevent perpetual recursion.
public:
LLControlGroup();
~LLControlGroup();
@@ -173,8 +192,8 @@ public:
virtual void apply(const std::string& name, LLControlVariable* control) = 0;
};
void applyToAll(ApplyFunctor* func);
BOOL declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist, BOOL hidefromsettingseditor = FALSE);
BOOL declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist, BOOL hidefromsettingseditor = FALSE, bool IsCOA = false);
BOOL declareU32(const std::string& name, U32 initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareS32(const std::string& name, S32 initial_val, const std::string& comment, BOOL persist = TRUE);
BOOL declareF32(const std::string& name, F32 initial_val, const std::string& comment, BOOL persist = TRUE);
@@ -245,6 +264,12 @@ public:
// Resets all ignorables
void resetWarnings();
//COA stuff
void connectToCOA(LLControlVariable *pConnecter, const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist);
void connectCOAVars(LLControlGroup &OtherGroup);
void updateCOASetting(bool coa_enabled);
bool handleCOASettingChange(const LLSD& newvalue);
};
//! Helper function for LLCachedControl
@@ -260,6 +285,7 @@ eControlType get_control_type(const T& in, LLSD& out)
//! An LLCachedControl instance to connect to a LLControlVariable
//! without have to manually create and bind a listener to a local
//! object.
template <class T>
class LLCachedControl
{
@@ -279,11 +305,10 @@ public:
LLControlGroup &group = gSavedSettings)
{Init(name,default_value,comment,group);} //for default (gSavedSettings)
private:
//Pulled out of ctor due to problems with initializer lists in template classes
void Init( const std::string& name,
const T& default_value,
const std::string& comment,
LLControlGroup &group )
LLControlGroup &group)
{
mControlGroup = &group;
mControl = mControlGroup->getControl(name);
@@ -303,6 +328,8 @@ private:
handleValueChange(mControl->getValue());
}
if(mConnection.connected())
mConnection.disconnect();
// Add a listener to the controls signal...
// and store the connection...
mConnection = mControl->getSignal()->connect(
@@ -325,6 +352,8 @@ public:
}
operator const T&() const { return mCachedValue; }
/* Sometimes implicit casting doesn't work.
For instance, something like "LLCachedControl<LLColor4> color("blah",LLColor4()); color.getValue();"
will not compile as it will look for the function getValue() in LLCachedControl, which doesn't exist.
@@ -334,10 +363,6 @@ public:
*/
const T &get() const { return mCachedValue; }
LLPointer<LLControlVariable> getControl() const
{
return mControl;
}
private:
void declareTypedControl(LLControlGroup& group,
const std::string& name,
@@ -375,48 +400,6 @@ private:
}
};
//Easiest way without messing with LLCachedControl even more..
template <class T>
class LLCachedCOAControl
{
LLCachedControl<T> *mCachedControl;
boost::signals::connection mCOAConnection;
const std::string mName;
const std::string mComment;
const T mDefault;
public:
LLCachedCOAControl(const std::string& name, const T& default_value,const std::string& comment = "Declared In Code")
: mName(name),mDefault(default_value),mComment(comment)
{
mCachedControl = new LLCachedControl<T>(mName,mDefault,gCOASavedSettings,mComment);
static LLCachedControl<bool> settings_per_account("AscentStoreSettingsPerAccount",false);
mCOAConnection = settings_per_account.getControl()->getSignal()->connect(
boost::bind(&LLCachedCOAControl<T>::handleCOAValueChange, this, _1));
}
~LLCachedCOAControl()
{
if(mCachedControl)
delete mCachedControl;
if(mCOAConnection.connected())
mCOAConnection.disconnect();
}
LLCachedCOAControl& operator =(const T& newvalue)
{
mCachedControl = newvalue;
return *this;
}
bool handleCOAValueChange(const LLSD& newvalue)
{
if(mCachedControl)
delete mCachedControl;
mCachedControl = new LLCachedControl<T>(mName,mDefault,gCOASavedSettings,mComment);
return true;
}
operator const T&() const { return *mCachedControl; }
const T &get() const { return *mCachedControl; }
};
//Following is actually defined in newview/llviewercontrol.cpp, but extern access is fine (Unless GCC bites me)
template <> eControlType get_control_type<U32>(const U32& in, LLSD& out);
template <> eControlType get_control_type<S32>(const S32& in, LLSD& out);