2013-05-08 01:33:42 +00:00
|
|
|
#include "usersettings.hpp"
|
|
|
|
|
2014-05-05 10:56:03 +00:00
|
|
|
#include <QSettings>
|
2013-06-15 11:40:18 +00:00
|
|
|
#include <QFile>
|
2014-04-23 03:19:53 +00:00
|
|
|
|
2013-05-08 01:33:42 +00:00
|
|
|
#include <components/files/configurationmanager.hpp>
|
2014-09-14 02:48:00 +00:00
|
|
|
#include <components/settings/settings.hpp>
|
2014-09-17 21:52:54 +00:00
|
|
|
#include <components/contentselector/model/naturalsort.hpp>
|
2014-09-14 02:48:00 +00:00
|
|
|
|
2013-05-08 01:33:42 +00:00
|
|
|
#include <boost/version.hpp>
|
2013-06-15 11:40:18 +00:00
|
|
|
|
2014-09-17 21:52:54 +00:00
|
|
|
#include <OgreRoot.h>
|
|
|
|
|
2014-04-23 03:19:53 +00:00
|
|
|
#include "setting.hpp"
|
|
|
|
#include "support.hpp"
|
2014-09-14 02:48:00 +00:00
|
|
|
#include <QTextCodec>
|
2014-05-05 10:56:03 +00:00
|
|
|
#include <QDebug>
|
2014-04-23 03:19:53 +00:00
|
|
|
|
2013-05-08 01:33:42 +00:00
|
|
|
/**
|
|
|
|
* Workaround for problems with whitespaces in paths in older versions of Boost library
|
|
|
|
*/
|
|
|
|
#if (BOOST_VERSION <= 104600)
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline boost::filesystem::path lexical_cast<boost::filesystem::path, std::string>(const std::string& arg)
|
|
|
|
{
|
|
|
|
return boost::filesystem::path(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace boost */
|
|
|
|
#endif /* (BOOST_VERSION <= 104600) */
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
namespace CSMSettings
|
|
|
|
{
|
|
|
|
|
|
|
|
UserSettings *UserSettings::mUserSettingsInstance = 0;
|
2013-05-08 01:33:42 +00:00
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
UserSettings::UserSettings (const Files::ConfigurationManager& configurationManager)
|
2014-09-14 02:48:00 +00:00
|
|
|
: mCfgMgr (configurationManager)
|
|
|
|
, mSettingDefinitions(NULL)
|
|
|
|
, mSettingCfgDefinitions(NULL)
|
2013-05-08 01:33:42 +00:00
|
|
|
{
|
2013-06-12 10:36:35 +00:00
|
|
|
assert(!mUserSettingsInstance);
|
2013-05-12 01:55:36 +00:00
|
|
|
mUserSettingsInstance = this;
|
2013-06-15 11:40:18 +00:00
|
|
|
|
2014-04-23 03:19:53 +00:00
|
|
|
buildSettingModelDefaults();
|
2014-09-15 21:44:07 +00:00
|
|
|
|
|
|
|
// for overriding opencs.ini settings with those from settings.cfg
|
2014-09-15 09:33:38 +00:00
|
|
|
mSettingCfgDefinitions = new QSettings(QSettings::IniFormat, QSettings::UserScope, "", QString(), this);
|
2013-07-18 01:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
void UserSettings::buildSettingModelDefaults()
|
2013-07-18 01:19:01 +00:00
|
|
|
{
|
2014-09-21 21:50:35 +00:00
|
|
|
QString page;
|
2014-09-21 10:55:52 +00:00
|
|
|
|
2014-09-24 12:41:49 +00:00
|
|
|
page = "Objects";
|
2013-06-15 11:40:18 +00:00
|
|
|
{
|
2014-09-21 21:50:35 +00:00
|
|
|
QString section = "Group1";
|
|
|
|
|
|
|
|
Setting *numLights = createSetting (Type_SpinBox, page, "num lights");
|
|
|
|
numLights->setDefaultValue(8);
|
|
|
|
numLights->setEditorSetting(true);
|
2014-09-22 06:24:06 +00:00
|
|
|
numLights->setColumnSpan (1);
|
2014-09-21 21:50:35 +00:00
|
|
|
numLights->setMinimum (0);
|
|
|
|
numLights->setMaximum (100); // FIXME: not sure what the max value should be
|
2014-09-22 02:19:18 +00:00
|
|
|
numLights->setWidgetWidth (10);
|
2014-09-23 23:33:19 +00:00
|
|
|
numLights->setViewLocation(1, 2);
|
2014-09-22 02:19:18 +00:00
|
|
|
|
2014-09-24 12:41:49 +00:00
|
|
|
Setting *shaders = createSetting (Type_CheckBox, page, "shaders");
|
|
|
|
shaders->setDeclaredValues(QStringList() << "true" << "false");
|
|
|
|
shaders->setDefaultValue("true");
|
|
|
|
shaders->setEditorSetting(true);
|
|
|
|
shaders->setSpecialValueText("Enable Shaders");
|
|
|
|
shaders->setWidgetWidth(25);
|
|
|
|
shaders->setColumnSpan (3);
|
|
|
|
shaders->setStyleSheet ("QGroupBox { border: 0px; }");
|
|
|
|
shaders->setViewLocation(2, 1);
|
2014-09-21 21:50:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 12:33:49 +00:00
|
|
|
page = "Scene";
|
|
|
|
{
|
|
|
|
Setting *fastFactor = createSetting (Type_SpinBox, page, "fast factor");
|
|
|
|
fastFactor->setDefaultValue(4);
|
|
|
|
fastFactor->setEditorSetting(false);
|
|
|
|
fastFactor->setColumnSpan (1);
|
2014-09-24 01:55:22 +00:00
|
|
|
// FIXME: setMinimum or setSpecialVlueText appears to be broken, possibly due
|
|
|
|
// to there being an empty string default for special value text.
|
|
|
|
fastFactor->setMinimum (1);
|
|
|
|
fastFactor->setSpecialValueText("1"); // workaround for above
|
2014-09-23 12:33:49 +00:00
|
|
|
fastFactor->setMaximum (100); // FIXME: not sure what the max value should be
|
|
|
|
fastFactor->setWidgetWidth (10);
|
|
|
|
fastFactor->setViewLocation(1, 2);
|
|
|
|
|
|
|
|
Setting *farClipDist = createSetting (Type_SpinBox, page, "far clip distance");
|
|
|
|
farClipDist->setDefaultValue(300000);
|
|
|
|
farClipDist->setEditorSetting(false);
|
|
|
|
farClipDist->setColumnSpan (1);
|
|
|
|
farClipDist->setMinimum (0);
|
|
|
|
farClipDist->setMaximum (1000000); // FIXME: not sure what the max value should be
|
|
|
|
farClipDist->setWidgetWidth (10);
|
|
|
|
farClipDist->setViewLocation(2, 2);
|
|
|
|
|
|
|
|
Setting *timerStart = createSetting (Type_SpinBox, page, "timer start");
|
|
|
|
timerStart->setDefaultValue(20);
|
|
|
|
timerStart->setEditorSetting(false);
|
|
|
|
timerStart->setColumnSpan (1);
|
|
|
|
timerStart->setMinimum (0);
|
|
|
|
timerStart->setMaximum (100); // FIXME: not sure what the max value should be
|
|
|
|
timerStart->setWidgetWidth (10);
|
|
|
|
timerStart->setViewLocation(3, 2);
|
|
|
|
}
|
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
#if 0
|
|
|
|
page = "Window Size";
|
|
|
|
{
|
|
|
|
Setting *width = createSetting (Type_LineEdit, page, "Width");
|
|
|
|
Setting *height = createSetting (Type_LineEdit, page, "Height");
|
2014-04-23 03:19:53 +00:00
|
|
|
|
|
|
|
width->setWidgetWidth (5);
|
2014-05-03 23:58:43 +00:00
|
|
|
height->setWidgetWidth (8);
|
2014-04-23 03:19:53 +00:00
|
|
|
|
|
|
|
width->setDefaultValues (QStringList() << "1024");
|
|
|
|
height->setDefaultValues (QStringList() << "768");
|
|
|
|
|
|
|
|
width->setEditorSetting (true);
|
|
|
|
height->setEditorSetting (true);
|
|
|
|
|
|
|
|
height->setViewLocation (2,2);
|
|
|
|
width->setViewLocation (2,1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Create the proxy setting for predefined values
|
|
|
|
*/
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *preDefined = createSetting (Type_ComboBox, page,
|
2014-05-03 23:58:43 +00:00
|
|
|
"Pre-Defined");
|
|
|
|
|
|
|
|
preDefined->setDeclaredValues (QStringList() << "640 x 480"
|
|
|
|
<< "800 x 600" << "1024 x 768" << "1440 x 900");
|
2014-04-23 03:19:53 +00:00
|
|
|
|
|
|
|
preDefined->setViewLocation (1, 1);
|
|
|
|
preDefined->setWidgetWidth (10);
|
|
|
|
preDefined->setColumnSpan (2);
|
|
|
|
|
|
|
|
preDefined->addProxy (width,
|
|
|
|
QStringList() << "640" << "800" << "1024" << "1440"
|
|
|
|
);
|
|
|
|
|
|
|
|
preDefined->addProxy (height,
|
|
|
|
QStringList() << "480" << "600" << "768" << "900"
|
|
|
|
);
|
2013-06-15 11:40:18 +00:00
|
|
|
}
|
2014-09-24 12:41:49 +00:00
|
|
|
#endif
|
2013-06-15 11:40:18 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
page = "Display Format";
|
2013-05-08 01:33:42 +00:00
|
|
|
{
|
2014-04-23 03:19:53 +00:00
|
|
|
QString defaultValue = "Icon and Text";
|
2013-05-08 01:33:42 +00:00
|
|
|
|
2014-04-23 03:19:53 +00:00
|
|
|
QStringList values = QStringList()
|
|
|
|
<< defaultValue << "Icon Only" << "Text Only";
|
2013-05-08 01:33:42 +00:00
|
|
|
|
2014-04-27 02:32:36 +00:00
|
|
|
Setting *rsd = createSetting (Type_RadioButton,
|
2014-09-21 21:50:35 +00:00
|
|
|
page, "Record Status Display");
|
2013-05-08 01:33:42 +00:00
|
|
|
|
2014-04-27 02:32:36 +00:00
|
|
|
Setting *ritd = createSetting (Type_RadioButton,
|
2014-09-21 21:50:35 +00:00
|
|
|
page, "Referenceable ID Type Display");
|
2014-05-03 23:58:43 +00:00
|
|
|
|
|
|
|
rsd->setDeclaredValues (values);
|
|
|
|
ritd->setDeclaredValues (values);
|
2013-05-08 01:33:42 +00:00
|
|
|
|
2014-04-23 03:19:53 +00:00
|
|
|
rsd->setEditorSetting (true);
|
|
|
|
ritd->setEditorSetting (true);
|
2013-06-27 02:18:21 +00:00
|
|
|
}
|
2014-04-23 03:19:53 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
page = "Proxy Selection Test";
|
2013-06-27 02:18:21 +00:00
|
|
|
{
|
2014-05-03 23:58:43 +00:00
|
|
|
/******************************************************************
|
|
|
|
* There are three types of values:
|
|
|
|
*
|
|
|
|
* Declared values
|
|
|
|
*
|
|
|
|
* Pre-determined values, typically for
|
|
|
|
* combobox drop downs and boolean (radiobutton / checkbox) labels.
|
|
|
|
* These values represent the total possible list of values that
|
|
|
|
* may define a setting. No other values are allowed.
|
|
|
|
*
|
|
|
|
* Defined values
|
|
|
|
*
|
|
|
|
* Values which represent the actual, current value of
|
2014-05-08 02:59:26 +00:00
|
|
|
* a setting. For settings with declared values, this must be one
|
|
|
|
* or several declared values, as appropriate.
|
2014-05-03 23:58:43 +00:00
|
|
|
*
|
2014-05-08 02:59:26 +00:00
|
|
|
* Proxy values
|
|
|
|
* Values the proxy master updates the proxy slave when
|
|
|
|
* it's own definition is set / changed. These are definitions for
|
|
|
|
* proxy slave settings, but must match any declared values the
|
|
|
|
* proxy slave has, if any.
|
2014-05-03 23:58:43 +00:00
|
|
|
*******************************************************************/
|
2014-05-05 11:26:00 +00:00
|
|
|
/*
|
2014-05-03 23:58:43 +00:00
|
|
|
//create setting objects, specifying the basic widget type,
|
|
|
|
//the page name, and the view name
|
2014-05-05 11:26:00 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *masterBoolean = createSetting (Type_RadioButton, page,
|
2014-05-04 03:02:16 +00:00
|
|
|
"Master Proxy");
|
2014-04-23 03:19:53 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *slaveBoolean = createSetting (Type_CheckBox, page,
|
2014-05-04 03:02:16 +00:00
|
|
|
"Proxy Checkboxes");
|
2014-04-23 03:19:53 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *slaveSingleText = createSetting (Type_LineEdit, page,
|
2014-05-04 03:02:16 +00:00
|
|
|
"Proxy TextBox 1");
|
2014-04-23 03:19:53 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *slaveMultiText = createSetting (Type_LineEdit, page,
|
2014-05-04 03:02:16 +00:00
|
|
|
"ProxyTextBox 2");
|
2014-05-03 23:58:43 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *slaveAlphaSpinbox = createSetting (Type_SpinBox, page,
|
2014-05-04 03:02:16 +00:00
|
|
|
"Alpha Spinbox");
|
2014-05-03 23:58:43 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *slaveIntegerSpinbox = createSetting (Type_SpinBox, page,
|
2014-05-04 03:02:16 +00:00
|
|
|
"Int Spinbox");
|
2014-05-03 23:58:43 +00:00
|
|
|
|
|
|
|
Setting *slaveDoubleSpinbox = createSetting (Type_DoubleSpinBox,
|
2014-09-21 21:50:35 +00:00
|
|
|
page, "Double Spinbox");
|
2014-05-03 23:58:43 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *slaveSlider = createSetting (Type_Slider, page, "Slider");
|
2014-05-04 02:50:08 +00:00
|
|
|
|
2014-09-21 21:50:35 +00:00
|
|
|
Setting *slaveDial = createSetting (Type_Dial, page, "Dial");
|
2014-05-04 03:02:16 +00:00
|
|
|
|
2014-05-03 23:58:43 +00:00
|
|
|
//set declared values for selected views
|
|
|
|
masterBoolean->setDeclaredValues (QStringList()
|
|
|
|
<< "Profile One" << "Profile Two"
|
|
|
|
<< "Profile Three" << "Profile Four");
|
|
|
|
|
|
|
|
slaveBoolean->setDeclaredValues (QStringList()
|
|
|
|
<< "One" << "Two" << "Three" << "Four" << "Five");
|
|
|
|
|
|
|
|
slaveAlphaSpinbox->setDeclaredValues (QStringList()
|
|
|
|
<< "One" << "Two" << "Three" << "Four");
|
|
|
|
|
2014-04-23 03:19:53 +00:00
|
|
|
|
|
|
|
masterBoolean->addProxy (slaveBoolean, QList <QStringList>()
|
|
|
|
<< (QStringList() << "One" << "Three")
|
|
|
|
<< (QStringList() << "One" << "Three")
|
|
|
|
<< (QStringList() << "One" << "Three" << "Five")
|
|
|
|
<< (QStringList() << "Two" << "Four")
|
|
|
|
);
|
|
|
|
|
|
|
|
masterBoolean->addProxy (slaveSingleText, QList <QStringList>()
|
|
|
|
<< (QStringList() << "Text A")
|
|
|
|
<< (QStringList() << "Text B")
|
|
|
|
<< (QStringList() << "Text A")
|
|
|
|
<< (QStringList() << "Text C")
|
|
|
|
);
|
|
|
|
|
|
|
|
masterBoolean->addProxy (slaveMultiText, QList <QStringList>()
|
|
|
|
<< (QStringList() << "One" << "Three")
|
|
|
|
<< (QStringList() << "One" << "Three")
|
|
|
|
<< (QStringList() << "One" << "Three" << "Five")
|
|
|
|
<< (QStringList() << "Two" << "Four")
|
|
|
|
);
|
|
|
|
|
2014-05-03 23:58:43 +00:00
|
|
|
masterBoolean->addProxy (slaveAlphaSpinbox, QList <QStringList>()
|
|
|
|
<< (QStringList() << "Four")
|
|
|
|
<< (QStringList() << "Three")
|
|
|
|
<< (QStringList() << "Two")
|
|
|
|
<< (QStringList() << "One"));
|
|
|
|
|
|
|
|
masterBoolean->addProxy (slaveIntegerSpinbox, QList <QStringList> ()
|
|
|
|
<< (QStringList() << "0")
|
|
|
|
<< (QStringList() << "7")
|
|
|
|
<< (QStringList() << "14")
|
|
|
|
<< (QStringList() << "21"));
|
|
|
|
|
|
|
|
masterBoolean->addProxy (slaveDoubleSpinbox, QList <QStringList> ()
|
|
|
|
<< (QStringList() << "0.17")
|
|
|
|
<< (QStringList() << "0.34")
|
|
|
|
<< (QStringList() << "0.51")
|
|
|
|
<< (QStringList() << "0.68"));
|
|
|
|
|
2014-05-04 02:50:08 +00:00
|
|
|
masterBoolean->addProxy (slaveSlider, QList <QStringList> ()
|
|
|
|
<< (QStringList() << "25")
|
|
|
|
<< (QStringList() << "50")
|
|
|
|
<< (QStringList() << "75")
|
|
|
|
<< (QStringList() << "100")
|
|
|
|
);
|
|
|
|
|
2014-05-04 03:02:16 +00:00
|
|
|
masterBoolean->addProxy (slaveDial, QList <QStringList> ()
|
|
|
|
<< (QStringList() << "25")
|
|
|
|
<< (QStringList() << "50")
|
|
|
|
<< (QStringList() << "75")
|
|
|
|
<< (QStringList() << "100")
|
|
|
|
);
|
|
|
|
|
2014-04-23 03:19:53 +00:00
|
|
|
//settings with proxies are not serialized by default
|
|
|
|
//other settings non-serialized for demo purposes
|
|
|
|
slaveBoolean->setSerializable (false);
|
|
|
|
slaveSingleText->setSerializable (false);
|
|
|
|
slaveMultiText->setSerializable (false);
|
2014-05-03 23:58:43 +00:00
|
|
|
slaveAlphaSpinbox->setSerializable (false);
|
|
|
|
slaveIntegerSpinbox->setSerializable (false);
|
|
|
|
slaveDoubleSpinbox->setSerializable (false);
|
2014-05-04 02:50:08 +00:00
|
|
|
slaveSlider->setSerializable (false);
|
2014-05-05 11:26:00 +00:00
|
|
|
slaveDial->setSerializable (false);
|
2014-04-23 03:19:53 +00:00
|
|
|
|
|
|
|
slaveBoolean->setDefaultValues (QStringList()
|
|
|
|
<< "One" << "Three" << "Five");
|
|
|
|
|
|
|
|
slaveSingleText->setDefaultValue ("Text A");
|
|
|
|
|
|
|
|
slaveMultiText->setDefaultValues (QStringList()
|
|
|
|
<< "One" << "Three" << "Five");
|
|
|
|
|
|
|
|
slaveSingleText->setWidgetWidth (24);
|
|
|
|
slaveMultiText->setWidgetWidth (24);
|
2014-05-03 23:58:43 +00:00
|
|
|
|
|
|
|
slaveAlphaSpinbox->setDefaultValue ("Two");
|
|
|
|
slaveAlphaSpinbox->setWidgetWidth (20);
|
|
|
|
//slaveAlphaSpinbox->setPrefix ("No. ");
|
|
|
|
//slaveAlphaSpinbox->setSuffix ("!");
|
|
|
|
slaveAlphaSpinbox->setWrapping (true);
|
|
|
|
|
2014-05-04 03:02:16 +00:00
|
|
|
slaveIntegerSpinbox->setDefaultValue (14);
|
2014-05-03 23:58:43 +00:00
|
|
|
slaveIntegerSpinbox->setMinimum (0);
|
|
|
|
slaveIntegerSpinbox->setMaximum (58);
|
|
|
|
slaveIntegerSpinbox->setPrefix ("$");
|
|
|
|
slaveIntegerSpinbox->setSuffix (".00");
|
|
|
|
slaveIntegerSpinbox->setWidgetWidth (10);
|
|
|
|
slaveIntegerSpinbox->setSpecialValueText ("Nothing!");
|
|
|
|
|
2014-05-04 03:02:16 +00:00
|
|
|
slaveDoubleSpinbox->setDefaultValue (0.51);
|
2014-05-03 23:58:43 +00:00
|
|
|
slaveDoubleSpinbox->setSingleStep(0.17);
|
|
|
|
slaveDoubleSpinbox->setMaximum(4.0);
|
2014-05-04 02:50:08 +00:00
|
|
|
|
|
|
|
slaveSlider->setMinimum (0);
|
|
|
|
slaveSlider->setMaximum (100);
|
2014-05-04 03:02:16 +00:00
|
|
|
slaveSlider->setDefaultValue (75);
|
2014-05-04 02:50:08 +00:00
|
|
|
slaveSlider->setWidgetWidth (100);
|
|
|
|
slaveSlider->setTicksAbove (true);
|
2014-05-04 03:02:16 +00:00
|
|
|
slaveSlider->setTickInterval (25);
|
|
|
|
|
|
|
|
slaveDial->setMinimum (0);
|
|
|
|
slaveDial->setMaximum (100);
|
|
|
|
slaveDial->setSingleStep (5);
|
|
|
|
slaveDial->setDefaultValue (75);
|
|
|
|
slaveDial->setTickInterval (25);
|
|
|
|
*/
|
2014-05-03 23:58:43 +00:00
|
|
|
}
|
2013-05-08 01:33:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
UserSettings::~UserSettings()
|
2013-05-08 01:33:42 +00:00
|
|
|
{
|
2014-04-23 03:19:53 +00:00
|
|
|
mUserSettingsInstance = 0;
|
2013-06-15 11:40:18 +00:00
|
|
|
}
|
2014-05-05 11:26:00 +00:00
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
void UserSettings::loadSettings (const QString &fileName)
|
2013-07-18 01:19:01 +00:00
|
|
|
{
|
2014-05-05 11:26:00 +00:00
|
|
|
QString userFilePath = QString::fromUtf8
|
2014-05-05 11:07:41 +00:00
|
|
|
(mCfgMgr.getUserConfigPath().string().c_str());
|
2013-07-18 01:19:01 +00:00
|
|
|
|
2014-05-05 11:07:41 +00:00
|
|
|
QString globalFilePath = QString::fromUtf8
|
|
|
|
(mCfgMgr.getGlobalPath().string().c_str());
|
2013-05-08 01:33:42 +00:00
|
|
|
|
2014-05-05 11:07:41 +00:00
|
|
|
QString otherFilePath = globalFilePath;
|
|
|
|
|
|
|
|
//test for local only if global fails (uninstalled copy)
|
2014-05-07 02:58:50 +00:00
|
|
|
if (!QFile (globalFilePath + fileName).exists())
|
2014-05-05 11:07:41 +00:00
|
|
|
{
|
2014-05-07 02:58:50 +00:00
|
|
|
//if global is invalid, use the local path
|
|
|
|
otherFilePath = QString::fromUtf8
|
|
|
|
(mCfgMgr.getLocalPath().string().c_str());
|
2013-06-22 12:43:28 +00:00
|
|
|
}
|
2014-05-07 02:58:50 +00:00
|
|
|
|
2014-05-05 11:07:41 +00:00
|
|
|
QSettings::setPath
|
2014-05-05 11:26:00 +00:00
|
|
|
(QSettings::IniFormat, QSettings::UserScope, userFilePath);
|
2014-05-05 11:07:41 +00:00
|
|
|
|
|
|
|
QSettings::setPath
|
|
|
|
(QSettings::IniFormat, QSettings::SystemScope, otherFilePath);
|
2013-07-18 01:19:01 +00:00
|
|
|
|
2014-05-06 12:33:32 +00:00
|
|
|
mSettingDefinitions = new QSettings
|
2014-05-05 10:56:03 +00:00
|
|
|
(QSettings::IniFormat, QSettings::UserScope, "opencs", QString(), this);
|
2014-09-14 02:48:00 +00:00
|
|
|
|
2014-09-15 09:33:38 +00:00
|
|
|
// prepare to use the settings from settings.cfg
|
2014-09-14 02:48:00 +00:00
|
|
|
const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg";
|
|
|
|
const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg";
|
|
|
|
|
|
|
|
Settings::Manager settings;
|
|
|
|
// prefer local
|
|
|
|
if (boost::filesystem::exists(localdefault))
|
|
|
|
settings.loadDefault(localdefault);
|
|
|
|
else if (boost::filesystem::exists(globaldefault))
|
|
|
|
settings.loadDefault(globaldefault);
|
|
|
|
else
|
|
|
|
std::cerr<< "No default settings file found! Make sure the file \"settings-default.cfg\" was properly installed."<< std::endl;
|
|
|
|
|
|
|
|
// load user settings if they exist, otherwise just load the default settings as user settings
|
|
|
|
const std::string settingspath = mCfgMgr.getUserConfigPath().string() + "/settings.cfg";
|
|
|
|
if (boost::filesystem::exists(settingspath))
|
|
|
|
settings.loadUser(settingspath);
|
|
|
|
else if (boost::filesystem::exists(localdefault))
|
|
|
|
settings.loadUser(localdefault);
|
|
|
|
else if (boost::filesystem::exists(globaldefault))
|
|
|
|
settings.loadUser(globaldefault);
|
|
|
|
|
|
|
|
std::string renderSystem = settings.getString("render system", "Video");
|
|
|
|
if(renderSystem == "")
|
|
|
|
{
|
|
|
|
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
|
|
|
renderSystem = "Direct3D9 Rendering Subsystem";
|
|
|
|
#else
|
|
|
|
renderSystem = "OpenGL Rendering Subsystem";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
mSettingCfgDefinitions->setValue("Video/render system", renderSystem.c_str());
|
2014-09-18 12:17:37 +00:00
|
|
|
|
|
|
|
std::string currShader = settings.getString("shader mode", "General");
|
|
|
|
// can't call Ogre::Root at this point as it hasn't been initialised
|
|
|
|
QString rend = renderSystem.c_str();
|
|
|
|
bool openGL = rend.contains(QRegExp("^OpenGL", Qt::CaseInsensitive));
|
|
|
|
bool glES = rend.contains(QRegExp("^OpenGL ES", Qt::CaseInsensitive));
|
|
|
|
|
2014-09-17 21:52:54 +00:00
|
|
|
// force shader language based on render system
|
2014-09-18 12:17:37 +00:00
|
|
|
if(currShader == ""
|
|
|
|
|| (openGL && currShader == "hlsl")
|
|
|
|
|| (!openGL && currShader == "glsl")
|
|
|
|
|| (glES && currShader != "glsles"))
|
|
|
|
{
|
|
|
|
QString shader = openGL ? (glES ? "glsles" : "glsl") : "hlsl";
|
2014-09-21 21:50:35 +00:00
|
|
|
mSettingDefinitions->setValue("shader mode", shader); //no group means "General" group
|
2014-09-18 12:17:37 +00:00
|
|
|
}
|
2014-09-15 09:33:38 +00:00
|
|
|
|
|
|
|
// check if override entry exists (default: override)
|
|
|
|
if(!mSettingDefinitions->childGroups().contains("Video", Qt::CaseInsensitive))
|
|
|
|
mSettingDefinitions->setValue("Video/use settings.cfg", "true");
|
2014-05-08 02:59:26 +00:00
|
|
|
}
|
2014-05-05 10:56:03 +00:00
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
QStringList UserSettings::getOgreRenderers()
|
2014-09-18 12:17:37 +00:00
|
|
|
{
|
2014-09-18 22:29:06 +00:00
|
|
|
if(mOgreRenderers.empty())
|
|
|
|
{
|
|
|
|
Ogre::RenderSystemList renderers = Ogre::Root::getSingleton().getAvailableRenderers();
|
|
|
|
Ogre::RenderSystemList::iterator it = renderers.begin();
|
|
|
|
for(; it != renderers.end(); ++it)
|
|
|
|
mOgreRenderers.append((*it)->getName().c_str());
|
|
|
|
}
|
2014-09-18 12:17:37 +00:00
|
|
|
|
2014-09-18 22:29:06 +00:00
|
|
|
return mOgreRenderers;
|
2014-09-18 12:17:37 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
QStringList UserSettings::getOgreOptions(const QString &key, const QString &renderer)
|
2014-09-17 21:52:54 +00:00
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
2014-09-18 22:29:06 +00:00
|
|
|
Ogre::RenderSystem *rend = Ogre::Root::getSingleton().getRenderSystemByName(renderer.toStdString());
|
2014-09-18 12:17:37 +00:00
|
|
|
if(!rend)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Ogre::ConfigOptionMap& renderOpt = rend->getConfigOptions();
|
2014-09-17 21:52:54 +00:00
|
|
|
Ogre::ConfigOptionMap::iterator it = renderOpt.begin();
|
|
|
|
|
|
|
|
uint row = 0;
|
|
|
|
for(; it != renderOpt.end(); ++it, ++row)
|
|
|
|
{
|
|
|
|
Ogre::StringVector::iterator opt_it = it->second.possibleValues.begin();
|
|
|
|
uint idx = 0;
|
|
|
|
|
|
|
|
for(; opt_it != it->second.possibleValues.end(); ++opt_it, ++idx)
|
|
|
|
{
|
|
|
|
if(strcmp (key.toStdString().c_str(), it->first.c_str()) == 0)
|
|
|
|
{
|
|
|
|
result << ((key == "FSAA") ? QString("MSAA ") : QString(""))
|
|
|
|
+ QString::fromStdString((*opt_it).c_str()).simplified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort ascending
|
|
|
|
qSort(result.begin(), result.end(), naturalSortLessThanCI);
|
|
|
|
|
|
|
|
// Replace the zero option with Off
|
|
|
|
int index = result.indexOf("MSAA 0");
|
|
|
|
|
|
|
|
if(index != -1)
|
|
|
|
result.replace(index, QObject::tr("Off"));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
QStringList UserSettings::getShaderLanguageByRenderer(const QString &renderer)
|
2014-09-17 21:52:54 +00:00
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
|
|
|
|
if(renderer == "Direct3D9 Rendering Subsystem")
|
|
|
|
result.append("HLSL");
|
|
|
|
else if(renderer == "OpenGL Rendering Subsystem")
|
|
|
|
result.append("GLSL");
|
2014-09-18 12:17:37 +00:00
|
|
|
else if(renderer.contains(QRegExp("^OpenGL ES", Qt::CaseInsensitive)))
|
2014-09-17 21:52:54 +00:00
|
|
|
result.append("GLSLES");
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
bool UserSettings::hasSettingDefinitions (const QString &viewKey) const
|
2014-05-08 02:59:26 +00:00
|
|
|
{
|
|
|
|
return (mSettingDefinitions->contains (viewKey));
|
2013-07-18 01:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
void UserSettings::setDefinitions (const QString &key, const QStringList &list)
|
2013-06-15 11:40:18 +00:00
|
|
|
{
|
2014-05-08 02:59:26 +00:00
|
|
|
mSettingDefinitions->setValue (key, list);
|
|
|
|
}
|
2014-04-23 03:19:53 +00:00
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
void UserSettings::saveDefinitions() const
|
2014-05-08 02:59:26 +00:00
|
|
|
{
|
2014-05-06 12:33:32 +00:00
|
|
|
mSettingDefinitions->sync();
|
2013-06-15 11:40:18 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
QString UserSettings::settingValue (const QString &settingKey)
|
2013-06-15 11:40:18 +00:00
|
|
|
{
|
2014-09-14 02:48:00 +00:00
|
|
|
QStringList defs;
|
2014-04-25 12:16:40 +00:00
|
|
|
|
2014-09-14 02:48:00 +00:00
|
|
|
// check if video settings are overriden
|
2014-09-16 09:50:25 +00:00
|
|
|
if(settingKey.contains(QRegExp("^Video\\b", Qt::CaseInsensitive)) &&
|
|
|
|
mSettingDefinitions->value("Video/use settings.cfg") == "true" &&
|
|
|
|
settingKey.contains(QRegExp("^Video/\\brender|antialiasing|vsync|fullscreen\\b", Qt::CaseInsensitive)))
|
2014-09-14 02:48:00 +00:00
|
|
|
{
|
|
|
|
if (!mSettingCfgDefinitions->contains (settingKey))
|
|
|
|
return QString();
|
|
|
|
else
|
|
|
|
defs = mSettingCfgDefinitions->value (settingKey).toStringList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!mSettingDefinitions->contains (settingKey))
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
defs = mSettingDefinitions->value (settingKey).toStringList();
|
|
|
|
}
|
2013-06-15 11:40:18 +00:00
|
|
|
|
2014-05-08 02:59:26 +00:00
|
|
|
if (defs.isEmpty())
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
return defs.at(0);
|
2013-06-08 22:34:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
UserSettings& UserSettings::instance()
|
2013-06-12 10:36:35 +00:00
|
|
|
{
|
2013-06-27 02:18:21 +00:00
|
|
|
assert(mUserSettingsInstance);
|
|
|
|
return *mUserSettingsInstance;
|
2013-06-12 10:36:35 +00:00
|
|
|
}
|
2014-05-06 12:33:32 +00:00
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
void UserSettings::updateUserSetting(const QString &settingKey, const QStringList &list)
|
2014-05-06 12:33:32 +00:00
|
|
|
{
|
2014-05-08 02:59:26 +00:00
|
|
|
mSettingDefinitions->setValue (settingKey ,list);
|
2014-05-06 12:33:32 +00:00
|
|
|
|
|
|
|
emit userSettingUpdated (settingKey, list);
|
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
Setting *UserSettings::findSetting (const QString &pageName, const QString &settingName)
|
2014-05-06 12:33:32 +00:00
|
|
|
{
|
|
|
|
foreach (Setting *setting, mSettings)
|
|
|
|
{
|
|
|
|
if (setting->name() == settingName)
|
|
|
|
{
|
|
|
|
if (setting->page() == pageName)
|
|
|
|
return setting;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
void UserSettings::removeSetting (const QString &pageName, const QString &settingName)
|
2014-05-06 12:33:32 +00:00
|
|
|
{
|
|
|
|
if (mSettings.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QList <Setting *>::iterator removeIterator = mSettings.begin();
|
|
|
|
|
|
|
|
while (removeIterator != mSettings.end())
|
|
|
|
{
|
|
|
|
if ((*removeIterator)->name() == settingName)
|
|
|
|
{
|
|
|
|
if ((*removeIterator)->page() == pageName)
|
|
|
|
{
|
|
|
|
mSettings.erase (removeIterator);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeIterator++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
SettingPageMap UserSettings::settingPageMap() const
|
2014-05-06 12:33:32 +00:00
|
|
|
{
|
|
|
|
SettingPageMap pageMap;
|
|
|
|
|
|
|
|
foreach (Setting *setting, mSettings)
|
|
|
|
pageMap[setting->page()].append (setting);
|
|
|
|
|
|
|
|
return pageMap;
|
|
|
|
}
|
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
Setting *UserSettings::createSetting
|
|
|
|
(SettingType typ, const QString &page, const QString &name)
|
2014-05-06 12:33:32 +00:00
|
|
|
{
|
|
|
|
//get list of all settings for the current setting name
|
|
|
|
if (findSetting (page, name))
|
|
|
|
{
|
|
|
|
qWarning() << "Duplicate declaration encountered: "
|
|
|
|
<< (name + '/' + page);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Setting *setting = new Setting (typ, name, page);
|
|
|
|
|
|
|
|
|
|
|
|
//add declaration to the model
|
|
|
|
mSettings.append (setting);
|
|
|
|
|
|
|
|
return setting;
|
|
|
|
}
|
2014-05-08 02:59:26 +00:00
|
|
|
|
2014-09-21 10:55:52 +00:00
|
|
|
QStringList UserSettings::definitions (const QString &viewKey) const
|
2014-05-08 02:59:26 +00:00
|
|
|
{
|
|
|
|
if (mSettingDefinitions->contains (viewKey))
|
|
|
|
return mSettingDefinitions->value (viewKey).toStringList();
|
|
|
|
|
|
|
|
return QStringList();
|
|
|
|
}
|
2014-09-21 10:55:52 +00:00
|
|
|
|
|
|
|
}
|