optionHandling.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include "Core.hh"
00057
00058 #include <ACG/Scenegraph/DrawModes.hh>
00059
00060 #include "OpenFlipper/INIFile/INIFile.hh"
00061 #include "OpenFlipper/common/GlobalOptions.hh"
00062 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00063
00064
00065
00066 void Core::applyOptions(){
00067
00068 if ( OpenFlipper::Options::gui() ) {
00069
00070
00071 coreWidget_->initViewModes();
00072
00073
00074 if (OpenFlipper::Options::defaultToolboxMode() != "")
00075 coreWidget_->slotChangeView(OpenFlipper::Options::defaultToolboxMode(), QStringList(), QStringList());
00076
00077 if ( OpenFlipper::Options::fullScreen() )
00078 coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
00079 else
00080 coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
00081
00082
00083 coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
00084
00085
00086 coreWidget_->setGlCursor( OpenFlipper::Options::glMouse() );
00087
00088
00089 ACG::SceneGraph::PickTarget target;
00090 if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") {
00091 target = ACG::SceneGraph::PICK_ANYTHING;
00092 } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_VERTEX") {
00093 target = ACG::SceneGraph::PICK_VERTEX;
00094 } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_EDGE") {
00095 target = ACG::SceneGraph::PICK_EDGE;
00096 } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FACE") {
00097 target = ACG::SceneGraph::PICK_FACE;
00098 } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_VERTEX") {
00099 target = ACG::SceneGraph::PICK_FRONT_VERTEX;
00100 } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_EDGE") {
00101 target = ACG::SceneGraph::PICK_FRONT_EDGE;
00102 } else {
00103 target = ACG::SceneGraph::PICK_ANYTHING;
00104 }
00105
00106
00107 for (int i=0; i < PluginFunctions::viewers(); i++){
00108
00109 PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
00110 PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
00111
00112
00113
00114 if ( PluginFunctions::objectCount() > 0 ){
00115 if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
00116 PluginFunctions::orthographicProjection(i);
00117 else
00118 PluginFunctions::perspectiveProjection(i);
00119 }
00120 }
00121
00122 if ( OpenFlipper::Options::multiView() )
00123 coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
00124
00125
00126
00127
00128
00129
00130
00131 QColor c = OpenFlipper::Options::defaultBackgroundColor() ;
00132
00133 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00134
00135 PluginFunctions::viewerProperties(i).wheelZoomFactor(OpenFlipper::Options::wheelZoomFactor());
00136 PluginFunctions::viewerProperties(i).wheelZoomFactorShift(OpenFlipper::Options::wheelZoomFactorShift());
00137
00138
00139 PluginFunctions::viewerProperties(i).renderPicking(OpenFlipper::Options::renderPicking(), target );
00140 }
00141
00142
00143 if (OpenFlipper::Options::hideToolbox()) {
00144
00145 coreWidget_->showToolbox (false);
00146 }
00147
00148
00149 if (logFile_ != 0){
00150
00151 if (OpenFlipper::Options::logFile() != logFile_->fileName() ){
00152 logFile_->close();
00153 delete logFile_;
00154 logFile_ = 0;
00155 if (logStream_ != 0){
00156 delete logStream_;
00157 logStream_ = 0;
00158 }
00159 }
00160 }
00161
00162 updateView();
00163
00164 }
00165 }
00166
00167 void Core::saveOptions(){
00168 QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
00169 OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini";
00170
00171 INIFile ini;
00172 if ( ! ini.connect( inifile ,false) ) {
00173 emit log(LOGERR,tr("Failed to connect to users ini file"));
00174
00175 if ( ! ini.connect( inifile,true) ) {
00176 emit log(LOGERR,tr("Can not create user ini file"));
00177 } else {
00178 writeApplicationOptions(ini);
00179 ini.disconnect();
00180 }
00181 } else {
00182 writeApplicationOptions(ini);
00183 ini.disconnect();
00184 }
00185 }
00186
00187 void Core::setupOptions() {
00188
00189
00190 QDir configDir = QDir::home();
00191
00192 if ( ! configDir.cd(".OpenFlipper") ) {
00193 emit log(LOGOUT,tr("Creating config Dir ~/.OpenFlipper"));
00194 configDir.mkdir(".OpenFlipper");
00195 if ( ! configDir.cd(".OpenFlipper") ) {
00196 emit log(LOGERR,tr("Unable to create config dir ~/.OpenFlipper"));
00197 return;
00198 }
00199
00200 }
00201
00202
00203 QDir iconCacheDir = configDir;
00204
00205
00206 if ( ! iconCacheDir.exists("Icons") ){
00207 configDir.mkdir("Icons");
00208 emit log(LOGOUT,tr("Creating Icon Cache Dir ~/.OpenFlipper/Icons"));
00209 }
00210
00211 OpenFlipper::Options::configDir(configDir);
00212
00213
00214 QDir tempDir = QDir(qApp->applicationDirPath());
00215 #ifdef OPENFLIPPER_APPDIR
00216 tempDir.cd(OPENFLIPPER_APPDIR);
00217 #else
00218 tempDir.cd(".." + OpenFlipper::Options::dirSeparator() );
00219 #endif
00220 OpenFlipper::Options::applicationDir(tempDir.absolutePath());
00221
00222
00223 #ifdef OPENFLIPPER_PLUGINDIR
00224 tempDir.cd(OPENFLIPPER_PLUGINDIR);
00225 #else
00226 tempDir.cd("Plugins");
00227
00228 #if defined(WIN32)
00229 tempDir.cd("Windows");
00230 #elif defined(ARCH_DARWIN)
00231 tempDir.cd("Darwin");
00232 #else
00233 tempDir.cd("Linux");
00234 #endif
00235
00236 if ( OpenFlipper::Options::is64bit() )
00237 tempDir.cd("64");
00238 else
00239 tempDir.cd("32");
00240
00241 #ifdef WIN32
00242 #ifndef NDEBUG
00243 #define DEBUG
00244 #endif
00245 #endif
00246
00247 #ifdef DEBUG
00248 tempDir.cd("Debug");
00249 #else
00250 tempDir.cd("Release");
00251 #endif
00252 #endif
00253
00254 OpenFlipper::Options::pluginDir(tempDir.absolutePath());
00255
00256
00257 tempDir = QDir(OpenFlipper::Options::applicationDir());
00258 #ifdef OPENFLIPPER_DATADIR
00259 tempDir.cd(OPENFLIPPER_DATADIR);
00260 #endif
00261 tempDir.cd("Shaders");
00262 OpenFlipper::Options::shaderDir(tempDir.absolutePath());
00263
00264
00265
00266 tempDir = QDir(OpenFlipper::Options::applicationDir());
00267 #ifdef OPENFLIPPER_DATADIR
00268 tempDir.cd(OPENFLIPPER_DATADIR);
00269 #endif
00270 tempDir.cd("Textures");
00271 OpenFlipper::Options::textureDir(tempDir.absolutePath());
00272
00273
00274 tempDir = QDir(OpenFlipper::Options::applicationDir());
00275 #ifdef OPENFLIPPER_DATADIR
00276 tempDir.cd(OPENFLIPPER_DATADIR);
00277 #endif
00278 tempDir.cd("Scripts");
00279 OpenFlipper::Options::scriptDir(tempDir.absolutePath());
00280
00281
00282 tempDir = QDir(OpenFlipper::Options::applicationDir());
00283 #ifdef OPENFLIPPER_DATADIR
00284 tempDir.cd(OPENFLIPPER_DATADIR);
00285 #endif
00286 tempDir.cd("Icons");
00287 OpenFlipper::Options::iconDir(tempDir.absolutePath());
00288
00289
00290 tempDir = QDir(OpenFlipper::Options::applicationDir());
00291 #ifdef OPENFLIPPER_DATADIR
00292 tempDir.cd(OPENFLIPPER_DATADIR);
00293 #endif
00294 tempDir.cd("Translations");
00295 OpenFlipper::Options::translationsDir(tempDir.absolutePath());
00296
00297
00298 tempDir = QDir(OpenFlipper::Options::applicationDir());
00299 #ifdef OPENFLIPPER_DATADIR
00300 tempDir.cd(OPENFLIPPER_DATADIR);
00301 #endif
00302 tempDir.cd("Fonts");
00303 OpenFlipper::Options::fontsDir(tempDir.absolutePath());
00304
00305
00306 tempDir = QDir(OpenFlipper::Options::applicationDir());
00307 #ifdef OPENFLIPPER_DATADIR
00308 tempDir.cd(OPENFLIPPER_DATADIR);
00309 #endif
00310 tempDir.cd("Licenses");
00311 OpenFlipper::Options::licenseDir(tempDir.absolutePath());
00312
00313
00314 tempDir = QDir(OpenFlipper::Options::applicationDir());
00315 #ifdef OPENFLIPPER_DATADIR
00316 tempDir.cd(OPENFLIPPER_DATADIR);
00317 #endif
00318 tempDir.cd("Help");
00319 OpenFlipper::Options::helpDir(tempDir.absolutePath());
00320
00321
00322 tempDir = QDir(OpenFlipper::Options::applicationDir());
00323 #ifdef OPENFLIPPER_DATADIR
00324 tempDir.cd(OPENFLIPPER_DATADIR);
00325 #endif
00326 OpenFlipper::Options::dataDir(tempDir.absolutePath());
00327
00328 QStringList optionFiles;
00329
00330
00331
00332
00333 QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00334 if ( globalIni.exists() )
00335 optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00336
00337
00338
00339
00340 QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00341 if ( localIni.exists() )
00342 optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00343
00344
00345 OpenFlipper::Options::optionFiles(optionFiles);
00346
00347
00348
00349
00350
00351 OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
00352
00353
00354 OpenFlipper::Options::currentDir( QDir::home() );
00355
00356
00357
00358
00359
00360
00361 for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
00362
00363 INIFile _ini;
00364
00365 if ( ! _ini.connect(optionFiles[i],false) ) {
00366 emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
00367 continue;
00368 }
00369
00370 readApplicationOptions(_ini);
00371
00372 _ini.disconnect();
00373 }
00374
00375 }
00376
00378 void Core::restoreKeyBindings(){
00379
00380 QStringList optionFiles;
00381
00382
00383
00384
00385 QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00386 if ( globalIni.exists() )
00387 optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00388
00389
00390
00391
00392 QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00393 if ( localIni.exists() )
00394 optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00395
00396
00397 OpenFlipper::Options::optionFiles(optionFiles);
00398
00399
00400
00401
00402
00403
00404 for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
00405
00406 INIFile _ini;
00407
00408 if ( ! _ini.connect(optionFiles[i],false) ) {
00409 emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
00410 continue;
00411 }
00412
00413 if ( OpenFlipper::Options::gui() )
00414 coreWidget_->loadKeyBindings(_ini);
00415
00416 _ini.disconnect();
00417 }
00418 }
00419
00420