Commit 3d950a69 authored by Jan Möbius's avatar Jan Möbius
Browse files

Started to switch to QSettings for program specific settings

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7734 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e34c74a5
......@@ -949,6 +949,7 @@ void Core::slotExit() {
if (logFile_)
logFile_->close();
OpenFlipper::Options::closeSettings();
qApp->quit();
}
......
......@@ -186,36 +186,6 @@ void Core::readApplicationOptions(INIFile& _ini) {
if ( _ini.get_entry( stereoMode, "Options" , "StereoMode") )
OpenFlipper::Options::stereoMode(static_cast<OpenFlipper::Options::StereoMode> (stereoMode));
//============================================================================
// Load stereo view settings
//============================================================================
float val;
if ( _ini.get_entry( val, "Options" , "EyeDistance") )
OpenFlipper::Options::eyeDistance(val);
if ( _ini.get_entry( val, "Options" , "FocalDistance") )
OpenFlipper::Options::focalDistance(val);
//============================================================================
// Load philips stereo mode settings
//============================================================================
int philipsContent = 0;
if ( _ini.get_entry( philipsContent, "Options" , "PhilipsContent") )
OpenFlipper::Options::stereoPhilipsContent(philipsContent);
int philipsFactor = 0;
if ( _ini.get_entry( philipsFactor, "Options" , "PhilipsFactor") )
OpenFlipper::Options::stereoPhilipsFactor(philipsFactor);
int philipsOffset = 0;
if ( _ini.get_entry( philipsOffset, "Options" , "PhilipsOffset") )
OpenFlipper::Options::stereoPhilipsOffset(philipsOffset);
int philipsSelect = 0;
if ( _ini.get_entry( philipsSelect, "Options" , "PhilipsSelect") )
OpenFlipper::Options::stereoPhilipsSelect(philipsSelect);
//============================================================================
// Load the custom anaglyph stereo mode color matrices
//============================================================================
......@@ -693,20 +663,11 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options", "StereoMode",OpenFlipper::Options::stereoMode() );
_ini.add_entry("Options" , "EyeDistance", OpenFlipper::Options::eyeDistance());
_ini.add_entry("Options" , "FocalDistance", OpenFlipper::Options::focalDistance());
_ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
_ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() );
_ini.add_entry("Options", "StereoMousePick", OpenFlipper::Options::stereoMousePick() );
// Philips stereo mode
_ini.add_entry("Options" , "PhilipsContent", OpenFlipper::Options::stereoPhilipsContent());
_ini.add_entry("Options" , "PhilipsFactor", OpenFlipper::Options::stereoPhilipsFactor());
_ini.add_entry("Options" , "PhilipsOffset", OpenFlipper::Options::stereoPhilipsOffset());
_ini.add_entry("Options" , "PhilipsSelect", OpenFlipper::Options::stereoPhilipsSelect());
_ini.add_entry("Options", "GlMouse", OpenFlipper::Options::glMouse() );
}
......
......@@ -57,10 +57,13 @@
// -------------------- ACG
#include <ACG/Scenegraph/DrawModes.hh>
#include "OpenFlipper/INIFile/INIFile.hh"
#include "OpenFlipper/common/GlobalOptions.hh"
#include <OpenFlipper/INIFile/INIFile.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <QCoreApplication>
//== IMPLEMENTATION ==========================================================
void Core::applyOptions(){
......@@ -189,145 +192,6 @@ void Core::setupOptions() {
// initialize the Settings:
OpenFlipper::Options::initializeSettings();
// Get the Main config dir in the home directory and possibly create it
QDir configDir = QDir::home();
if ( ! configDir.cd(".OpenFlipper") ) {
emit log(LOGOUT,tr("Creating config Dir ~/.OpenFlipper"));
configDir.mkdir(".OpenFlipper");
if ( ! configDir.cd(".OpenFlipper") ) {
emit log(LOGERR,tr("Unable to create config dir ~/.OpenFlipper"));
return;
}
}
// Create a local directory to cache icons
QDir iconCacheDir = configDir;
// Create a personal Icon cache dir to save for example user added icons
if ( ! iconCacheDir.exists("Icons") ){
configDir.mkdir("Icons");
emit log(LOGOUT,tr("Creating Icon Cache Dir ~/.OpenFlipper/Icons"));
}
OpenFlipper::Options::configDir(configDir);
// Remember the main application directory (assumed to be one above executable Path)
QDir tempDir = QDir(qApp->applicationDirPath());
#ifdef OPENFLIPPER_APPDIR
tempDir.cd(OPENFLIPPER_APPDIR);
#else
tempDir.cd(".." + OpenFlipper::Options::dirSeparator() );
#endif
OpenFlipper::Options::applicationDir(tempDir.absolutePath());
// Set the standard path to the plugins
#ifdef OPENFLIPPER_PLUGINDIR
tempDir.cd(OPENFLIPPER_PLUGINDIR);
#else
tempDir.cd("Plugins");
#if defined(WIN32)
tempDir.cd("Windows");
#elif defined(ARCH_DARWIN)
tempDir.cd("Darwin");
#else
tempDir.cd("Linux");
#endif
if ( OpenFlipper::Options::is64bit() )
tempDir.cd("64");
else
tempDir.cd("32");
#ifdef WIN32
#ifndef NDEBUG
#define DEBUG
#endif
#endif
#ifdef DEBUG
tempDir.cd("Debug");
#else
tempDir.cd("Release");
#endif
#endif
OpenFlipper::Options::pluginDir(tempDir.absolutePath());
// Set the Path to the shaders
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Shaders");
OpenFlipper::Options::shaderDir(tempDir.absolutePath());
// Set the Path to the textures
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Textures");
OpenFlipper::Options::textureDir(tempDir.absolutePath());
// Set the Path to the Scripts
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Scripts");
OpenFlipper::Options::scriptDir(tempDir.absolutePath());
// Set the Path to the Icons
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Icons");
OpenFlipper::Options::iconDir(tempDir.absolutePath());
// Set the Path to the translations
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Translations");
OpenFlipper::Options::translationsDir(tempDir.absolutePath());
// Set the Path to the Fonts
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Fonts");
OpenFlipper::Options::fontsDir(tempDir.absolutePath());
// Set the Path to the License files
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Licenses");
OpenFlipper::Options::licenseDir(tempDir.absolutePath());
// Set the Path to the Help
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
tempDir.cd("Help");
OpenFlipper::Options::helpDir(tempDir.absolutePath());
// Set the Path to the main data directory
tempDir = QDir(OpenFlipper::Options::applicationDir());
#ifdef OPENFLIPPER_DATADIR
tempDir.cd(OPENFLIPPER_DATADIR);
#endif
OpenFlipper::Options::dataDir(tempDir.absolutePath());
QStringList optionFiles;
// ==============================================================
......
......@@ -55,11 +55,17 @@
#include <stdlib.h>
#include <iostream>
#include <ACG/Scenegraph/DrawModes.hh>
#include <QDir>
#include <QCoreApplication>
#include <Plugin-SpaceNavigator/libspnav/spnav_magellan.h>
namespace OpenFlipper {
namespace Options {
/// Pointer to the internal settings object storing OpenFlippers program options ( and the pplugins Options)
static QSettings* settings_ = 0;
/// Stores the base Path of the application
static QDir applicationDir_;
......@@ -126,12 +132,6 @@ static bool glStereo_ = true;
/// Stereo mode
static StereoMode stereoMode_ = OpenGL;
/// get stereo eye distance (default = 7cm)
static float eyeDistance_ = 0.07f;
/// stereo focal distance relative to scene near plane (default = to center of scene)
static float focalDistance_ = 0.5;
/// vectroy containing left/right color matrices for custom anaglyph mode
static std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0);
static std::vector<float> anaglyphRightEyeColors_ = std::vector<float> (9, 0.0);
......@@ -139,18 +139,6 @@ static std::vector<float> anaglyphRightEyeColors_ = std::vector<float> (9, 0.0);
/// mouse cursor depth picking in stereo mode
static bool stereoMousePick_ = true;
/// philips stereo header content type
static int stereoPhilipsContent_ = 3; // Game
/// philips stereo header factor
static int stereoPhilipsFactor_ = 64;
/// philips stereo header offset
static int stereoPhilipsOffset_ = 128;
/// philips stereo header select
static int stereoPhilipsSelect_ = 0; // Display's defaults
/// Store the synchronization mode
static bool synchronization_ = false;
......@@ -370,96 +358,8 @@ QString currentTextureDirStr() { return currentTextureDir_.absolutePath(); }
QStringList optionFiles() { return optionFiles_; }
void applicationDir(QDir _dir) { applicationDir_ = _dir; }
void pluginDir(QDir _dir) { pluginDir_ = _dir; }
void shaderDir(QDir _dir) { shaderDir_ = _dir; }
void textureDir(QDir _dir) { textureDir_ = _dir; }
void licenseDir(QDir _dir) { licenseDir_ = _dir; }
void scriptDir(QDir _dir) { scriptDir_ = _dir; }
void iconDir(QDir _dir) { iconDir_ = _dir; }
void tanslationsDir(QDir _dir) { translationsDir_ = _dir; }
void fontsDir(QDir _dir) { fontsDir_ = _dir; }
void helpDir(QDir _dir) { helpDir_ = _dir; }
void dataDir(QDir _dir) { dataDir_ = _dir; }
void configDir(QDir _dir) { configDir_ = _dir; }
void currentDir(QDir _dir) { currentDir_ = _dir; }
void currentScriptDir(QDir _dir) { currentScriptDir_ = _dir; }
void currentTextureDir(QDir _dir) { currentTextureDir_ = _dir; }
void optionFiles(QStringList _list) { optionFiles_ = _list; }
bool applicationDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
applicationDir_ = tmp;
return true;
}
return false;
}
bool pluginDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
pluginDir_ = tmp;
return true;
}
return false;
}
bool shaderDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
shaderDir_ = tmp;
return true;
}
return false;
}
bool textureDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
textureDir_ = tmp;
return true;
}
return false;
}
bool licenseDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
licenseDir_ = tmp;
return true;
}
return false;
}
bool scriptDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
scriptDir_ = tmp;
return true;
}
return false;
}
bool iconDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
iconDir_ = tmp;
return true;
}
return false;
}
bool dataDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
dataDir_ = tmp;
return true;
}
return false;
}
QIcon& OpenFlipperIcon() {
if (OpenFlipperIcon_ == 0){
......@@ -472,41 +372,8 @@ QIcon& OpenFlipperIcon() {
return *OpenFlipperIcon_;
}
bool translationsDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
translationsDir_ = tmp;
return true;
}
return false;
}
bool fontsDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
fontsDir_ = tmp;
return true;
}
return false;
}
bool helpDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
helpDir_ = tmp;
return true;
}
return false;
}
bool configDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
configDir_ = tmp;
return true;
}
return false;
void currentDir(QDir _dir) {
currentDir_ = _dir;
}
bool currentDir(QString _dir) {
......@@ -518,6 +385,7 @@ bool currentDir(QString _dir) {
return false;
}
bool currentScriptDir(QString _dir) {
QDir tmp(_dir);
if (tmp.exists()) {
......@@ -591,28 +459,27 @@ StereoMode stereoMode( ) {
return stereoMode_;
}
/// Store stereo eye distance
void eyeDistance( float _eye )
{
eyeDistance_ = _eye;
/// get stereo eye distance (default = 7cm)
void eyeDistance( double _eye ) {
settings_->setValue("Core/Stereo/EyeDistance",_eye);
}
/// get stereo eye distance
float eyeDistance( )
double eyeDistance( )
{
return eyeDistance_;
return settings_->value("Core/Stereo/EyeDistance",0.07f).toDouble();
}
/// Store stereo focal distance relative to scene near plane
void focalDistance( float _focal )
{
focalDistance_ = _focal;
settings_->setValue("Core/Stereo/FocalDistance",_focal);
}
/// get stereo focal distance relative to scene near plane
float focalDistance( )
{
return focalDistance_;
return settings_->value("Core/Stereo/FocalDistance",0.5f).toDouble();
}
/// Store the 3x3 left eye color matrix values for custom anaglyph stereo mode
......@@ -651,54 +518,6 @@ bool stereoMousePick( ) {
return stereoMousePick_;
}
/// Store philips stereo header content type
void stereoPhilipsContent( int _content )
{
stereoPhilipsContent_ = _content;
}
/// get philips stereo header content type
int stereoPhilipsContent( )
{
return stereoPhilipsContent_;
}
/// Store philips stereo header factor
void stereoPhilipsFactor( int _factor )
{
stereoPhilipsFactor_ = _factor;
}
/// get philips stereo header factor
int stereoPhilipsFactor( )
{
return stereoPhilipsFactor_;
}
/// Store philips stereo header offset
void stereoPhilipsOffset( int _offset )
{
stereoPhilipsOffset_ = _offset;
}
/// get philips stereo header offset
int stereoPhilipsOffset( )
{
return stereoPhilipsOffset_;
}
/// Store philips stereo header select
void stereoPhilipsSelect( int _select )
{
stereoPhilipsSelect_ = _select;
}
/// get philips stereo header select
int stereoPhilipsSelect( )
{
return stereoPhilipsSelect_;
}
/// Store synchronization mode setting
void synchronization( bool _synchronization ) {
synchronization_ = _synchronization;
......@@ -1082,15 +901,192 @@ bool renderPicking( ) {
return renderPicking_;
}
/// Internal function called by the core to connect to the program options
DLLEXPORT
bool initializeSettings() {
std::cerr << "Initialize settings" << std::endl;
//==================================================================================================
// Get the Main config dir in the home directory and possibly create it
//==================================================================================================
configDir_ = QDir::home();
if ( ! configDir_.cd(".OpenFlipper") ) {
std::cerr << "Creating config Dir ~/.OpenFlipper" << std::endl;;
configDir_.mkdir(".OpenFlipper");
if ( ! configDir_.cd(".OpenFlipper") ) {
std::cerr << "Unable to create config dir ~/.OpenFlipper" << std::endl;
return false;
}
}
//==================================================================================================
// Setup settings.
//==================================================================================================
// This has to be done as early as possible to set the program options right
// Force ini format on all platforms
QSettings::setDefaultFormat ( QSettings::IniFormat );
// Force settings to be stored in the OpenFlipper config directory
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope , configDir_.absolutePath() );
// Finally attach the settings object.
settings_ = new QSettings(QSettings::IniFormat, QSettings::UserScope, "ACG","OpenFlipper");
//==================================================================================================
// Now create special directories in th OpenFlipper config dir
//==================================================================================================
// Create a personal Icon cache dir to save for example user added icons
if ( ! configDir_.exists("Icons") ){
configDir_.mkdir("Icons");
std::cerr << "Creating Icon Cache Dir ~/.OpenFlipper/Icons" << std::endl;
}
//==================================================================================================
// Setup main application dir
//==================================================================================================
// Remember the main application directory (assumed to be one above executable Path)
applicationDir_ = QCoreApplication::applicationDirPath();
/// \todo remove the else branch here which is only used by qmake
#ifdef OPENFLIPPER_APPDIR
// When using cmake, we get the absolute path to the Application directory via a define
applicationDir_.cd(OPENFLIPPER_APPDIR);
#else
// For qmake the path of the application will be one directory up.
// Remove this as we will remove qmake support!
applicationDir_.cd(".." + OpenFlipper::Options::dirSeparator() );
#endif
//==================================================================================================
// Setup directory containing plugins
//==================================================================================================
// start at application directory
pluginDir_ = applicationDir_;
/// \todo remove the qmake specific else branch here!
#ifdef OPENFLIPPER_PLUGINDIR
// cmake style: Path is directly given from define!
pluginDir_.cd(OPENFLIPPER_PLUGINDIR);
#else
// qmake stuff. Remove when removing qmake!
pluginDir_.cd("Plugins");
#if defined(WIN32)
pluginDir_.cd("Windows");
#elif defined(ARCH_DARWIN)
pluginDir_.cd("Darwin");
#else
pluginDir_.cd("Linux");
#endif
if ( OpenFlipper::Options::is64bit() )
pluginDir_.cd("64");
else
pluginDir_.cd("32");
#ifdef WIN32
#ifndef NDEBUG
#define DEBUG
#endif
#endif
#ifdef DEBUG
pluginDir_.cd("Debug");
#else
pluginDir_.cd("Release");
#endif
#endif
dataDir_ = OpenFlipper::Options::applicationDir();
#ifdef OPENFLIPPER_DATADIR
dataDir_.cd(OPENFLIPPER_DATADIR);
#else
dataDir_ = OpenFlipper::Options::applicationDir();
#endif