optionsWidget.cc 38.3 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40
41
\*===========================================================================*/

42
43
44
45
46
#ifdef _MSC_VER
  #if (_MSC_VER <= 1916)
    #define  QT_NO_FLOAT16_OPERATORS
  #endif
#endif
47

Dirk Wilden's avatar
Dirk Wilden committed
48
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
49
#include <OpenFlipper/INIFile/INIFile.hh>
50
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
51
#include <OpenFlipper/common/GlobalOptions.hh>
52
#include <ACG/GL/ShaderCache.hh>
Dirk Wilden's avatar
Dirk Wilden committed
53

54
#include "optionsWidget.hh"
55
56
57
#include <QColorDialog>
#include <QOpenGLContext>
#include <QMessageBox>
58

Dirk Wilden's avatar
Dirk Wilden committed
59
OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, InverseKeyMap& _invKeys, QWidget *parent)
Jan Möbius's avatar
Jan Möbius committed
60
61
  : QWidget(parent),
    plugins_(_plugins),
Dirk Wilden's avatar
Dirk Wilden committed
62
    coreKeys_(_core),
63
    keys_(_invKeys),
64
    progressDialog_(NULL),
65
    restartRequired_(false),
66
    exitOnClose_(false)
67
68
{
  setupUi(this);
Dirk Wilden's avatar
Dirk Wilden committed
69

Dirk Wilden's avatar
Dirk Wilden committed
70
  connect(okButton,SIGNAL(clicked()),this,SLOT(slotOk()));
71
72
  connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
  connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
Jan Möbius's avatar
Jan Möbius committed
73
  connect(checkUpdateButton,SIGNAL(clicked()),this,SLOT(slotCheckUpdates()));
74
75
  connect(updateButton,SIGNAL(clicked()),this,SLOT(slotGetUpdates()));
  updateButton->setEnabled(false);
76

77
78
  // Files
  connect(pbReloadShaders,SIGNAL(clicked()),this,SLOT(slotReloadShaders()));
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  
  // OpenGL versions
  VersionComboBox->clear();
  VersionComboBox->addItem("4.6",QVariant::fromValue(QPair<int, int>(4,6)));
  VersionComboBox->addItem("4.5",QVariant::fromValue(QPair<int, int>(4,5)));
  VersionComboBox->addItem("4.4",QVariant::fromValue(QPair<int, int>(4,4)));
  VersionComboBox->addItem("4.3",QVariant::fromValue(QPair<int, int>(4,3)));
  VersionComboBox->addItem("4.2",QVariant::fromValue(QPair<int, int>(4,2)));
  VersionComboBox->addItem("4.1",QVariant::fromValue(QPair<int, int>(4,1)));
  VersionComboBox->addItem("4.0",QVariant::fromValue(QPair<int, int>(4,0)));
  VersionComboBox->addItem("3.3",QVariant::fromValue(QPair<int, int>(3,3)));
  VersionComboBox->addItem("3.2",QVariant::fromValue(QPair<int, int>(3,2)));
  VersionComboBox->addItem("3.1",QVariant::fromValue(QPair<int, int>(3,1)));
  VersionComboBox->addItem("3.0",QVariant::fromValue(QPair<int, int>(3,0)));
  VersionComboBox->addItem("2.1",QVariant::fromValue(QPair<int, int>(2,1)));
  VersionComboBox->addItem("2.0",QVariant::fromValue(QPair<int, int>(2,0)));
  VersionComboBox->addItem("1.5",QVariant::fromValue(QPair<int, int>(1,5)));
  VersionComboBox->addItem("1.4",QVariant::fromValue(QPair<int, int>(1,4)));
  VersionComboBox->addItem("1.3",QVariant::fromValue(QPair<int, int>(1,3)));
  VersionComboBox->addItem("1.2",QVariant::fromValue(QPair<int, int>(1,2)));
  VersionComboBox->addItem("1.1",QVariant::fromValue(QPair<int, int>(1,1)));
  VersionComboBox->addItem("1.0",QVariant::fromValue(QPair<int, int>(1,0)));
  
102
  // Viewer Settings
Dirk Wilden's avatar
Dirk Wilden committed
103
  connect( restrictFPS, SIGNAL(toggled(bool)), FPS, SLOT(setEnabled(bool)) );
104
105
106
107
  connect( viewerList, SIGNAL(currentRowChanged(int)), this, SLOT(updateViewerSettings(int)) );
  connect( availDrawModes, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(viewerSettingsChanged(QListWidgetItem*)) );
  connect( projectionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(viewerSettingsChanged(int)));
  connect( directionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(viewerSettingsChanged(int)));
108
  connect( lockRotationBox, SIGNAL(stateChanged(int)), this, SLOT(viewerSettingsChanged(int)));
109

110
111
112
113
114
115
116
  // Switch stacked widget of stereo settings
  connect(stereoOpengl, SIGNAL(clicked()),
          this, SLOT(switchStackedWidget()));
  connect(stereoAnaglyph, SIGNAL(clicked()),
          this, SLOT(switchStackedWidget()));
  connect(stereoCustomAnaglyph, SIGNAL(clicked()),
          this, SLOT(switchStackedWidget()));
117
118
119
120
121
122
  
  connect(focalDistance, SIGNAL(sliderReleased()),
          this, SLOT(slotPreviewStereoSettings()));
  connect(eyeDistance, SIGNAL(editingFinished()),
          this, SLOT(slotPreviewStereoSettings()));

123
  ACG::SceneGraph::DrawModes::ModeFlagSet mode(2);
Dirk Wilden's avatar
Dirk Wilden committed
124
  for (uint i=1; i < 22; i++) {
125
    std::vector< QString > dm = drawModeToDescriptions( ACG::SceneGraph::DrawModes::DrawMode(mode) );
Jan Möbius's avatar
Jan Möbius committed
126

127
    if ( !dm.empty() && dm[0].trimmed() != ""){
Dirk Wilden's avatar
Dirk Wilden committed
128
      QListWidgetItem* item = new QListWidgetItem(dm[0]);
Jan Möbius's avatar
Jan Möbius committed
129

Dirk Wilden's avatar
Dirk Wilden committed
130
      item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
131

132
      item->setCheckState(Qt::Unchecked);
Dirk Wilden's avatar
Dirk Wilden committed
133
134
135

      availDrawModes->addItem( item );
    }
136

Dirk Wilden's avatar
Dirk Wilden committed
137
    mode = mode<<1;
138
  }
Dirk Wilden's avatar
Dirk Wilden committed
139

140
141
142
143
  defaultProjectionMode_.resize(4);
  defaultViewingDirections_.resize(4);
  defaultRotationLocks_.resize(4);

144
145
  for ( int i=0; i < PluginFunctions::viewers(); i++ ){
    viewerList->addItem("Viewer " + QString::number(i+1) );
146
    defaultDrawModes_.push_back( ACG::SceneGraph::DrawModes::DEFAULT );
147
  }
Jan Möbius's avatar
Jan Möbius committed
148

Dirk Wilden's avatar
Dirk Wilden committed
149
150
151
  pluginOptionsLayout = new QVBoxLayout;
  pluginOptions->setLayout( pluginOptionsLayout );

152
  networkMan_ = new QNetworkAccessManager(this);
Jan Möbius's avatar
Jan Möbius committed
153

Jan Möbius's avatar
Jan Möbius committed
154
  // http specific connections
155
156
157
158
  connect(networkMan_, SIGNAL(finished(QNetworkReply *)),
        this, SLOT(httpRequestFinished(QNetworkReply *)));
  connect(networkMan_,SIGNAL(authenticationRequired(QNetworkReply* , QAuthenticator *)),
        this,SLOT(authentication(QNetworkReply *, QAuthenticator*)));
Jan Möbius's avatar
Jan Möbius committed
159

160
161
  //colordialog
  connect(backgroundButton, SIGNAL(clicked()), this, SLOT(getBackgroundColor()) );
162
  connect(defaultColorButton, SIGNAL(clicked()), this, SLOT(getDefaultColor()) );
163
164
165
166
  
  // Clear settings and ini buttons
  connect(clearSettingsButton, SIGNAL(clicked()), this, SLOT(slotClearSettings()));
  connect(clearINIButton,      SIGNAL(clicked()), this, SLOT(slotClearINI()));
167
168
169
170
171
172

  // Disable update tab if app store compliant build
  #ifdef OPENFLIPPER_BUILD_APP_STORE_COMPLIANT
    //tabWidget->setTabEnabled(tabWidget->count()-1,false);
    tabWidget->removeTab(tabWidget->count()-1);
  #endif
173
174
175
}

void OptionsWidget::getBackgroundColor(){
176
  QColor newColor = QColorDialog::getColor ( OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>() );
177

178
179
  backgroundColor_ = newColor;
  
180
  QPixmap color(16,16);
181
  color.fill( newColor );
182
  backgroundButton->setIcon( QIcon(color) );
183
184
}

185
186
void OptionsWidget::getDefaultColor(){
  QColor newColor = QColorDialog::getColor ( OpenFlipper::Options::defaultColor() );
187

188
  OpenFlipper::Options::defaultColor( newColor) ;
189
190

  QPixmap color(16,16);
191
192
  color.fill( OpenFlipper::Options::defaultColor() );
  defaultColorButton->setIcon( QIcon(color) );
193
194
}

195
196
197
198
199
200
201
202
203
204
205
206
void OptionsWidget::viewerSettingsChanged(QListWidgetItem* /*_item*/){
  viewerSettingsChanged(0);
};

void OptionsWidget::viewerSettingsChanged(int /*_index*/){

  if ( !updatingViewerSettings_ ){
    //viewer defaults
    std::vector< QString > mode;

    for (int i=0; i < availDrawModes->count(); i++)
      if (availDrawModes->item(i)->checkState() == Qt::Checked)
207
        mode.push_back( availDrawModes->item(i)->text() );
208
209

    defaultDrawModes_[         viewerList->currentRow() ] = descriptionsToDrawMode(mode);
210
    defaultProjectionMode_[    viewerList->currentRow() ] = projectionBox->currentIndex() ;
211
    defaultViewingDirections_[ viewerList->currentRow() ] = directionBox->currentIndex();
212
213
214
215
216
217
    defaultRotationLocks_[ viewerList->currentRow() ]     = lockRotationBox->isChecked();

    if ( lockRotationBox->isChecked() )
      std::cerr << "locked" << std::endl;
    else
      std::cerr << "unlocked" << std::endl;
218
219
220
  }
};

221
222
223
224
225
void OptionsWidget::switchStackedWidget() {

    // Show right stacked widget of stereo settings
    if (stereoCustomAnaglyph->isChecked()) {
        stackedWidget->setCurrentIndex(0);
226
        customAnaGlyphSettings->setVisible(true);
Jan Möbius's avatar
Typo    
Jan Möbius committed
227
    } else {
228
        stackedWidget->setCurrentIndex(0);
229
        customAnaGlyphSettings->setVisible(false);
230
    }
231
232
233
    
    // Preview new settings
    slotPreviewStereoSettings();
234
235
}

236
void OptionsWidget::slotTranslationIndexChanged(int /*_index*/) {
237
  restartRequired_ = true;
238
239
}

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
void OptionsWidget::updateViewerSettings(int _row){

  updatingViewerSettings_ = true;

  for (int i = 0 ; i < availDrawModes->count(); ++i )
    availDrawModes->item( i )->setCheckState(Qt::Unchecked) ;

  //Check the drawModes from StandardDrawMode
  std::vector< QString > dm = drawModeToDescriptions( defaultDrawModes_[_row] );

  for (uint i=0; i < dm.size(); i++){
    if ( !dm.empty() ) {
      QList< QListWidgetItem* > found = availDrawModes->findItems(dm[i],Qt::MatchExactly);
      for(int k=0; k < found.count(); k++)
        (found[k])->setCheckState(Qt::Checked);
    }
  }

258
259
260
261
262
  if ( defaultProjectionMode_[_row] )
    projectionBox->setCurrentIndex( 1 );
  else
    projectionBox->setCurrentIndex( 0 );

263
264
  directionBox->setCurrentIndex(  defaultViewingDirections_[_row] );

265
266
  lockRotationBox->setChecked( defaultRotationLocks_[_row] );

267
268
269
  updatingViewerSettings_ = false;
}

Dirk Wilden's avatar
Dirk Wilden committed
270
void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
Dirk Wilden's avatar
Dirk Wilden committed
271

Jan Möbius's avatar
Jan Möbius committed
272
  //general
Jan Möbius's avatar
Jan Möbius committed
273
  fullscreen->setChecked( OpenFlipperSettings().value("Core/Gui/fullscreen",false).toBool() );
274
  splash->setChecked( OpenFlipperSettings().value("Core/Gui/splash",true).toBool() );
Jan Möbius's avatar
Jan Möbius committed
275
276
  toolbox->setChecked( !OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() );
  
Dirk Wilden's avatar
Dirk Wilden committed
277
278
279
280
281
282
283
  iconSmall->setChecked(false);
  iconNormal->setChecked(false);
  iconDefault->setChecked(false);
  
  switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
    case 1  : iconSmall->setChecked(true); break;
    case 2  : iconNormal->setChecked(true); break;
Jan Möbius's avatar
Jan Möbius committed
284
    default : iconDefault->setChecked(true); break;
Dirk Wilden's avatar
Dirk Wilden committed
285
286
  }
  
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
287
288
289
  loggerHidden->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden);
  loggerNormal->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Normal);
  loggerInScene->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene);
Jan Möbius's avatar
Jan Möbius committed
290
  enableLogFile->setChecked( OpenFlipperSettings().value("Core/Log/logFileEnabled",true).toBool() );
Jan Möbius's avatar
Jan Möbius committed
291

292
293
  //OpenGL
  samples_spinBox->setValue(OpenFlipper::Options::samples());
294
295
296
297
298
299
300
  QPalette warning = samplesWarning->palette();
  samplesWarning->setText(QString::number(QOpenGLContext::currentContext()->format().samples()));
  if(OpenFlipper::Options::samples() != QOpenGLContext::currentContext()->format().samples())
    warning.setColor(samplesWarning->foregroundRole(),Qt::red);
  else
    warning.setColor(samplesWarning->foregroundRole(),Qt::black);
  samplesWarning->setPalette(warning);
301
  
302
  stereoCheckBox->setChecked(OpenFlipper::Options::glStereoRequested());
303
304
305
306
  QPalette stereoWarn = stereoWarning->palette();
  QString stereoValue;
  QOpenGLContext::currentContext()->format().stereo() ? stereoValue = "true" : stereoValue = "false";
  stereoWarning->setText(stereoValue);
307
  QOpenGLContext::currentContext()->format().stereo() == OpenFlipper::Options::glStereoRequested() ? 
308
309
310
311
        stereoWarn.setColor(stereoWarning->foregroundRole(), Qt::black) : 
        stereoWarn.setColor(stereoWarning->foregroundRole(), Qt::red);
  stereoWarning->setPalette(stereoWarn);
  
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
  VersionComboBox->setCurrentIndex( VersionComboBox->findData(QVariant::fromValue(OpenFlipper::Options::glVersion())));
  QPalette version = versionWarning->palette();
  versionWarning->setText(QString("%1.%2").arg(QOpenGLContext::currentContext()->format().version().first)
                          .arg(QOpenGLContext::currentContext()->format().version().second));
  if(OpenFlipper::Options::glVersion() != QOpenGLContext::currentContext()->format().version())
    version.setColor(versionWarning->foregroundRole(),Qt::red);
  else
    version.setColor(versionWarning->foregroundRole(),Qt::black);
  versionWarning->setPalette(version);
  
  QPalette profile = profileWarning->palette();
  profileComboBox->setCurrentIndex(OpenFlipper::Options::coreProfile()?0:1);
  if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CoreProfile)
    profileWarning->setText("Core");
  if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CompatibilityProfile)
    profileWarning->setText("Compatibility");
  if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::NoProfile)
    profileWarning->setText("None");
  if(OpenFlipper::Options::coreProfile() && QOpenGLContext::currentContext()->format().profile() != QSurfaceFormat::CoreProfile)
    profile.setColor(profileWarning->foregroundRole(),Qt::red);
  else
    profile.setColor(profileWarning->foregroundRole(),Qt::black);
  profileWarning->setPalette(profile);
335

Jan Möbius's avatar
Jan Möbius committed
336
  //Files
Jan Möbius's avatar
Jan Möbius committed
337
  logFile->setText( OpenFlipperSettings().value("Core/Log/logFile").toString()  );
Jan Möbius's avatar
Jan Möbius committed
338
  maxRecentBox->setValue( OpenFlipperSettings().value("Core/File/MaxRecent",15).toInt() );
339
  rbReloadShaders->setChecked(OpenFlipperSettings().value("Core/File/ReloadShaders",false).toBool()) ;
340
  leShaderOutputDir->setText(OpenFlipperSettings().value("Core/File/ShaderOutputDir","").toString());
341
342
  allTarget->setChecked( OpenFlipperSettings().value("Core/File/AllTarget",false).toBool() );

Dirk Wilden's avatar
Dirk Wilden committed
343

344
  // UI settings
345
  toolBoxOrientation->setCurrentIndex((OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool() ? 0 : 1));
346
  
347
  pickToolbarInScene->setChecked(OpenFlipperSettings().value("Core/Gui/ToolBars/PickToolbarInScene",true).toBool());
348

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
349
  //stereo
350
351
352
353
354
355
356
357

  // Grey out OpenGL stereo mode option if not available
  if(!OpenFlipper::Options::glStereo()) {
      stereoOpengl->setDisabled(true);
  } else {
      stereoOpengl->setChecked(OpenFlipper::Options::stereoMode() == OpenFlipper::Options::OpenGL);
  }

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
358
359
360
  stereoAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan);
  stereoCustomAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom);

361
  eyeDistance->setValue ( OpenFlipperSettings().value("Core/Stereo/EyeDistance").toDouble() );
362
  focalDistance->setValue ( OpenFlipperSettings().value("Core/Stereo/FocalDistance").toDouble()  * 1000);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
363

364
  // Show right stacked widget
365
  customAnaGlyphSettings->setVisible(false);
366
367
368
369
370

  stackedWidget->setCurrentIndex(0);

  if (stereoCustomAnaglyph->isChecked())
    customAnaGlyphSettings->setVisible(true);
371

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
  std::vector<float> mat = OpenFlipper::Options::anaglyphLeftEyeColorMatrix ();
  lcm0->setValue (mat[0]);
  lcm1->setValue (mat[1]);
  lcm2->setValue (mat[2]);
  lcm3->setValue (mat[3]);
  lcm4->setValue (mat[4]);
  lcm5->setValue (mat[5]);
  lcm6->setValue (mat[6]);
  lcm7->setValue (mat[7]);
  lcm8->setValue (mat[8]);

  mat = OpenFlipper::Options::anaglyphRightEyeColorMatrix ();
  rcm0->setValue (mat[0]);
  rcm1->setValue (mat[1]);
  rcm2->setValue (mat[2]);
  rcm3->setValue (mat[3]);
  rcm4->setValue (mat[4]);
  rcm5->setValue (mat[5]);
  rcm6->setValue (mat[6]);
  rcm7->setValue (mat[7]);
  rcm8->setValue (mat[8]);

394
  noMousePick->setChecked ( !OpenFlipperSettings().value("Core/Gui/glViewer/stereoMousePick",true).toBool() );
Jan Möbius's avatar
Jan Möbius committed
395
  nativeMouse->setChecked ( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
396

Dirk Wilden's avatar
Dirk Wilden committed
397
398
399
  // plugin options
  initPluginOptions();

400
  // updates
401
402
403
  updateUser->setText( OpenFlipperSettings().value("Core/Update/UserName","anonymous").toString() );
  updatePass->setText( OpenFlipperSettings().value("Core/Update/Pass","anonymous").toString() );
  updateURL->setText( OpenFlipperSettings().value("Core/Update/URL","http://").toString() );
404

Jan Möbius's avatar
Jan Möbius committed
405
406
407
  // debugging
  slotDebugging->setChecked(OpenFlipper::Options::doSlotDebugging());

Dirk Wilden's avatar
Dirk Wilden committed
408
  //keyBindings
Dirk Wilden's avatar
Dirk Wilden committed
409
  initKeyTree();
410

Dirk Wilden's avatar
Dirk Wilden committed
411
  keyTree->disconnect(); //to be sure..disconnect every slot
Dirk Wilden's avatar
Dirk Wilden committed
412

Dirk Wilden's avatar
Dirk Wilden committed
413
414
  connect(keyTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
          this,    SLOT(keyTreeItemChanged( QTreeWidgetItem*, QTreeWidgetItem*)) );
Dirk Wilden's avatar
Dirk Wilden committed
415

Dirk Wilden's avatar
Dirk Wilden committed
416
417
  connect(keyTree, SIGNAL(itemDoubleClicked (QTreeWidgetItem*, int)),
          this,    SLOT(keyTreeDoubleClicked( QTreeWidgetItem*, int)) );
Dirk Wilden's avatar
Dirk Wilden committed
418
419


Dirk Wilden's avatar
Dirk Wilden committed
420
  connect(shortcutButton, SIGNAL(keyChanged()), this, SLOT(updateShortcut()) );
421
  connect(presetsButton, SIGNAL(clicked()), this, SLOT(restoreKeyPresets()) );
422
423


424
  //Init Viewer Settings
425
426
  wZoomFactor->setValue( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor").toDouble() );
  wZoomFactorShift->setValue( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift").toDouble() );
427
  invertMouseWheelBox->setChecked( OpenFlipperSettings().value("Core/Mouse/Wheel/Invert").toBool() );
428

Jan Möbius's avatar
Jan Möbius committed
429
  wheelBox->setChecked( OpenFlipperSettings().value("Core/Gui/glViewer/showControlWheels").toBool() );
430
431
  
  // Projection settings
432
  fieldOfView->setValue(OpenFlipperSettings().value("Core/Projection/FOVY", 45.0).toDouble() );
433

434
435
  restrictFPS->setChecked( OpenFlipperSettings().value("Core/Gui/glViewer/restrictFrameRate",false).toBool() );
  FPS->setValue( OpenFlipperSettings().value("Core/Gui/glViewer/maxFrameRate",35).toInt() );
436
437
  
  minimalSceneSize->setValue( OpenFlipperSettings().value("Core/Gui/glViewer/minimalSceneSize",0.1).toDouble());
438
439

  QPixmap color(16,16);
440
  color.fill( OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>() );
441
  backgroundColor_ = OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
442
443
  backgroundButton->setIcon( QIcon(color) );

444
445
  color.fill( OpenFlipper::Options::defaultColor() );
  defaultColorButton->setIcon( QIcon(color) );
446

447
  randomDefaultColor->setChecked( OpenFlipper::Options::randomDefaultColor() );
448

449
450
451
452
  viewerList->setCurrentRow(0);

  for ( int i=0; i < PluginFunctions::viewers(); i++ ){
    defaultDrawModes_[i] = OpenFlipper::Options::defaultDrawMode(i);
453
    defaultProjectionMode_[i] = OpenFlipper::Options::defaultPerspectiveProjectionMode(i);
454
    defaultViewingDirections_[i] = OpenFlipper::Options::defaultViewingDirection(i);
455
    defaultRotationLocks_[i] = OpenFlipper::Options::defaultLockRotation(i);
456
  }
Jan Möbius's avatar
Jan Möbius committed
457

458
459
  updateViewerSettings(0);

460
  viewerLayout->setCurrentIndex( OpenFlipper::Options::defaultViewerLayout() );
461

462
  if (OpenFlipperSettings().value("Core/Language/Translation","en_US").toString() == "en_US")
463
    translation->setCurrentIndex(0);
464
  else if (OpenFlipperSettings().value("Core/Language/Translation","en_US").toString() == "de_DE")
465
466
467
    translation->setCurrentIndex(1);
  else
    translation->setCurrentIndex(2);
468
469
470
  
  // Listen to changes...
  connect(translation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotTranslationIndexChanged(int)));
471

Jan Möbius's avatar
Jan Möbius committed
472
473
474
475
476
477
  updateVersionsTable();

}

void OptionsWidget::updateVersionsTable() {

478
479
  updatedPlugins_.clear();

Jan Möbius's avatar
Jan Möbius committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
  QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
                     ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;

  INIFile ini;

  ini.connect(fileName,false);

  QString systemString = "";

  if ( OpenFlipper::Options::isWindows() ) {
    systemString = "VersionWindows";
  } else if (OpenFlipper::Options::isLinux()) {
    systemString = "VersionLinux";
  } else {
    std::cerr << "Unsupported platform for update" << std::endl;
    return;
  }

  updateList->clear();
499
  updateList->setRowCount( int(1 + plugins_.size()) );
Jan Möbius's avatar
Jan Möbius committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
  updateList->setColumnCount(3);

  QStringList header;

  header << "Component" << "current Version" << "latest Version" ;
  updateList->setHorizontalHeaderLabels(header);

  QBrush currentBrush(Qt::white);

  QTableWidgetItem * newItem = 0;

  QString coreVersion;

  if ( ini.is_connected() && ini.get_entry(coreVersion, "Core" , systemString ) ) {

    // Newer Version available
516
    if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) ) {
Jan Möbius's avatar
Jan Möbius committed
517
      currentBrush.setColor(Qt::red);
518
519
      updatedPlugins_ << "Core";
    } else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) )
520
      currentBrush.setColor(Qt::blue);
Jan Möbius's avatar
Jan Möbius committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
    else
      currentBrush.setColor(Qt::green);

    newItem = new QTableWidgetItem( coreVersion );

  } else {

    // No local Information available
    currentBrush.setColor(Qt::yellow);

    newItem = new QTableWidgetItem( "Not Available" );
  }

  newItem->setBackground(currentBrush);
  updateList->setItem(0, 2, newItem);

  newItem = new QTableWidgetItem( OpenFlipper::Options::coreVersion() );
  newItem->setBackground(currentBrush);
  updateList->setItem(0, 1, newItem);

  newItem = new QTableWidgetItem( "Core" );
  newItem->setBackground(currentBrush);
  updateList->setItem(0, 0, newItem);


  for ( uint i = 0 ; i < plugins_.size(); ++i ) {
    QString latestVersion;

    if ( ini.is_connected() && ini.get_entry(latestVersion, plugins_[i].name , systemString ) ) {


      // Newer Version available
553
      if ( isNewer(plugins_[i].version,latestVersion) ) {
554
         currentBrush.setColor(Qt::red);
555
556
557
         QFileInfo pluginFile(plugins_[i].path );
         updatedPlugins_ << pluginFile.fileName();
      } else if ( isNewer(latestVersion,plugins_[i].version) )
558
         currentBrush.setColor(Qt::blue);
Jan Möbius's avatar
Jan Möbius committed
559
      else
560
         currentBrush.setColor(Qt::green);
Jan Möbius's avatar
Jan Möbius committed
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

      newItem = new QTableWidgetItem( latestVersion );

    } else {

      // No local Information available
      currentBrush.setColor(Qt::yellow);

      newItem = new QTableWidgetItem( "Not Available" );
    }

    newItem->setBackground(currentBrush);
    updateList->setItem( i + 1 , 2, newItem);

    newItem = new QTableWidgetItem( plugins_[i].version );
    newItem->setBackground(currentBrush);
    updateList->setItem( i + 1 , 1, newItem);

    newItem = new QTableWidgetItem( plugins_[i].name );
    newItem->setBackground(currentBrush);
    updateList->setItem( i + 1 , 0, newItem);
  }

  updateList->resizeColumnsToContents();

586
587
  updateButton->setEnabled(!updatedPlugins_.empty());

588
589
}

Dirk Wilden's avatar
Dirk Wilden committed
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
void OptionsWidget::initPluginOptions(){

  pluginList->disconnect();

  connect(pluginList, SIGNAL( currentTextChanged(const QString&) ), this, SLOT( slotShowPluginOptions(const QString&) ) );

  //init list of plugins
  pluginList->clear();

  for ( uint i = 0 ; i < plugins_.size(); ++i )
    if (plugins_[i].optionsWidget != 0){

      pluginList->addItem( plugins_[i].name );
    }

  if ( pluginList->count() > 0)
    pluginList->setCurrentRow(0);
}

void OptionsWidget::slotShowPluginOptions(const QString& _pluginName ){

  //remove old children
  for (int i = 0; i < pluginOptionsLayout->count(); ++i){
    QWidget* w = pluginOptionsLayout->itemAt(i)->widget();

    if (w != 0)
      w->setParent(0);

    pluginOptionsLayout->removeItem( pluginOptionsLayout->itemAt(i) );
  }

  //find the new optionsWidget
  for ( uint i = 0 ; i < plugins_.size(); ++i )
    if (plugins_[i].optionsWidget != 0 && plugins_[i].name == _pluginName){

      pluginOptionsLayout->addWidget( plugins_[i].optionsWidget );
      pluginOptionsLayout->addStretch();
      return;
    }
}

631
void OptionsWidget::slotApply() {
Dirk Wilden's avatar
Dirk Wilden committed
632

Jan Möbius's avatar
Jan Möbius committed
633
  //general
Jan Möbius's avatar
Jan Möbius committed
634
  OpenFlipperSettings().setValue("Core/Gui/fullscreen",fullscreen->isChecked());
635
  OpenFlipperSettings().setValue("Core/Gui/splash",splash->isChecked());
Jan Möbius's avatar
Jan Möbius committed
636
637
  OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",!toolbox->isChecked());
  
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
638
  if (loggerHidden->isChecked())
Jan Möbius's avatar
Jan Möbius committed
639
    OpenFlipper::Options::loggerState( OpenFlipper::Options::Hidden );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
640
641
642
643
  else if (loggerInScene->isChecked())
    OpenFlipper::Options::loggerState( OpenFlipper::Options::InScene );
  else
    OpenFlipper::Options::loggerState( OpenFlipper::Options::Normal );
Jan Möbius's avatar
Jan Möbius committed
644
645
646
  
  OpenFlipperSettings().setValue("Core/Log/logFileEnabled",enableLogFile->isChecked());
  OpenFlipperSettings().setValue("Core/Log/logFile",logFile->text());
Dirk Wilden's avatar
Dirk Wilden committed
647

648
649
  //OpenGL settings
  OpenFlipperSettings().setValue("Core/OpenGL/Samples",samples_spinBox->value());
650
651
  OpenFlipper::Options::glVersion(VersionComboBox->currentData().value<QPair<int,int>>());
  OpenFlipper::Options::coreProfile(profileComboBox->currentIndex() == 0);
652
  OpenFlipper::Options::glStereo(stereoCheckBox->isChecked());
653
654

  //Paths settings
Jan Möbius's avatar
Jan Möbius committed
655
  OpenFlipperSettings().setValue("Core/File/MaxRecent",maxRecentBox->value() ) ;
656
657
  OpenFlipperSettings().setValue("Core/File/ReloadShaders",rbReloadShaders->isChecked() ) ;
  ACG::ShaderCache::getInstance()->setTimeCheck(rbReloadShaders->isChecked());
658
659
660
  OpenFlipperSettings().setValue("Core/File/ShaderOutputDir",leShaderOutputDir->text() ) ;
  ACG::ShaderCache::getInstance()->setDebugOutputDir(leShaderOutputDir->text().toUtf8());

661
662
  OpenFlipperSettings().setValue("Core/File/AllTarget",allTarget->isChecked());

663
664
  
  // Toolbox orientation
Jan Möbius's avatar
Jan Möbius committed
665
  OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/ToolBoxOnTheRight", (toolBoxOrientation->currentIndex() == 0));
666
667
  
  // Render picking toolbar into scene
668
  if ( OpenFlipperSettings().value("Core/Gui/ToolBars/PickToolbarInScene",true).toBool() != pickToolbarInScene->isChecked() )  {
669
670
671
    OpenFlipperSettings().setValue("Core/Gui/ToolBars/PickToolbarInScene", pickToolbarInScene->isChecked());
    restartRequired_ = true;
  }
672

Dirk Wilden's avatar
Dirk Wilden committed
673
674
675
676
677
678
679
  if ( iconDefault->isChecked() )
    OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 0);
  else if ( iconSmall->isChecked() )
    OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 1);
  else if ( iconNormal->isChecked() )
    OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 2);
  
Dirk Wilden's avatar
Dirk Wilden committed
680
  //viewer
681
682
  OpenFlipperSettings().setValue("Core/Mouse/Wheel/ZoomFactor", wZoomFactor->value());
  OpenFlipperSettings().setValue("Core/Mouse/Wheel/ZoomFactorShift", wZoomFactorShift->value());
683
684
  OpenFlipperSettings().setValue("Core/Mouse/Wheel/Invert", invertMouseWheelBox->isChecked());

685
  // Projection settings
686
687
  OpenFlipperSettings().setValue("Core/Projection/FOVY", fieldOfView->value());
  OpenFlipperSettings().setValue("Core/Gui/glViewer/minimalSceneSize",minimalSceneSize->value());
Dirk Wilden's avatar
Dirk Wilden committed
688

Jan Möbius's avatar
Jan Möbius committed
689
  OpenFlipperSettings().setValue("Core/Gui/glViewer/showControlWheels", wheelBox->isChecked() );
690

691
692
  OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", restrictFPS->isChecked());
  OpenFlipperSettings().setValue("Core/Gui/glViewer/maxFrameRate", FPS->value() );
693

694
  OpenFlipper::Options::randomDefaultColor( randomDefaultColor->isChecked() );
695

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
696
697
698
699
700
  //stereo
  if (stereoCustomAnaglyph->isChecked ())
     OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
  else if (stereoAnaglyph->isChecked ())
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
701
  else
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
702
703
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);

704
  OpenFlipperSettings().setValue("Core/Stereo/EyeDistance",eyeDistance->value ());
705
  OpenFlipperSettings().setValue("Core/Stereo/FocalDistance",double(focalDistance->value() / 1000.0));
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
706

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
  std::vector<float> mat (9, 0);
  mat[0] = lcm0->value ();
  mat[1] = lcm1->value ();
  mat[2] = lcm2->value ();
  mat[3] = lcm3->value ();
  mat[4] = lcm4->value ();
  mat[5] = lcm5->value ();
  mat[6] = lcm6->value ();
  mat[7] = lcm7->value ();
  mat[8] = lcm8->value ();

  OpenFlipper::Options::anaglyphLeftEyeColorMatrix (mat);

  mat[0] = rcm0->value ();
  mat[1] = rcm1->value ();
  mat[2] = rcm2->value ();
  mat[3] = rcm3->value ();
  mat[4] = rcm4->value ();
  mat[5] = rcm5->value ();
  mat[6] = rcm6->value ();
  mat[7] = rcm7->value ();
  mat[8] = rcm8->value ();

  OpenFlipper::Options::anaglyphRightEyeColorMatrix (mat);
731
732
  
  OpenFlipperSettings().setValue("Core/Gui/glViewer/stereoMousePick",!noMousePick->isChecked ());
Jan Möbius's avatar
Jan Möbius committed
733
  OpenFlipperSettings().setValue("Core/Gui/glViewer/nativeMouse",nativeMouse->isChecked ());
734

735
  // updates
736
737
738
  OpenFlipperSettings().setValue("Core/Update/UserName", updateUser->text());
  OpenFlipperSettings().setValue("Core/Update/Pass",updatePass->text());
  OpenFlipperSettings().setValue("Core/Update/URL",updateURL->text());
739

Jan Möbius's avatar
Jan Möbius committed
740
741
742
  // Debugging
  OpenFlipper::Options::doSlotDebugging(slotDebugging->isChecked());

743
744
745
  //viewer defaults
  for (int i=0; i < PluginFunctions::viewers(); i++){
    OpenFlipper::Options::defaultDrawMode(         defaultDrawModes_[i],         i );
746
    OpenFlipper::Options::defaultPerspectiveProjectionMode(   defaultProjectionMode_[i],    i );
747
    OpenFlipper::Options::defaultViewingDirection( defaultViewingDirections_[i], i );
748
    OpenFlipper::Options::defaultLockRotation( defaultRotationLocks_[i], i );
749
  }
Dirk Wilden's avatar
Dirk Wilden committed
750

751
  OpenFlipper::Options::defaultViewerLayout( viewerLayout->currentIndex() );
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
  
  // Restrict fps if desired
  if(restrictFPS->isChecked()) {
      OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", true);
      OpenFlipperSettings().setValue("Core/Gui/glViewer/maxFrameRate",FPS->value());
  } else {
      OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", false);
  }
  
  // Set background color
  OpenFlipperSettings().setValue("Core/Gui/glViewer/defaultBackgroundColor", backgroundColor_);
  
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i )
      PluginFunctions::viewerProperties(i).backgroundColor(ACG::Vec4f(((double) backgroundColor_.redF()),
                                                                      ((double) backgroundColor_.greenF()),
                                                                      ((double) backgroundColor_.blueF()),
                                                                        1.0));
769

770
771
772
773
774
775
776
777
  switch ( translation->currentIndex() ){
    case 0 : OpenFlipperSettings().setValue("Core/Language/Translation","en_US");  break;
    case 1 : OpenFlipperSettings().setValue("Core/Language/Translation","de_DE");  break;
    default: OpenFlipperSettings().setValue("Core/Language/Translation","locale"); break;
  }

  // Show warning message that restart is required if language or in scene toolbar has been changed...
  if(restartRequired_) {
778
779
780
781
    int restart = QMessageBox::information(this, tr("Restart required!"),
                      tr("The changes will take effect after next restart. Do you want to close OpenFlipper now?"),
                      QMessageBox::Yes | QMessageBox::No);
                    
782
    if(restart == QMessageBox::Yes) exitOnClose_ = true;
783
  }
784

Dirk Wilden's avatar
Dirk Wilden committed
785
786
  applyShortcuts();

787
  emit applyOptions();
Dirk Wilden's avatar
Dirk Wilden committed
788
  emit saveOptions();
789
790
791
792

  // Make sure all settings are written before we quit!
  OpenFlipperSettings().sync();

793
  // Close OpenFlipper if demanded
794
  if(exitOnClose_)  QCoreApplication::quit();
Dirk Wilden's avatar
Dirk Wilden committed
795
}
796

Dirk Wilden's avatar
Dirk Wilden committed
797
798
void OptionsWidget::slotOk(){
  slotApply();
799
800
801
802
803
804
  hide();
}

void OptionsWidget::slotCancel() {
  hide();
}
Jan Möbius's avatar
Jan Möbius committed
805

Jan Möbius's avatar
Jan Möbius committed
806
807
808
809
810
void OptionsWidget::slotCheckUpdates() {

   // http://www.graphics.rwth-aachen.de/restricted/OpenFlipper-SIL/

  downloadType = VERSIONS_FILE;
811
812
813
  QString ServerMainURL = updateURL->text();
  if ( !ServerMainURL.endsWith("/") )
     ServerMainURL += "/";
Jan Möbius's avatar
Jan Möbius committed
814

815
  ServerMainURL += "Versions.ini";
Jan Möbius's avatar
Jan Möbius committed
816

817
  startDownload(ServerMainURL);
Jan Möbius's avatar
Jan Möbius committed
818
819
820
}

void OptionsWidget::slotGetUpdates() {
821
822
823
824
825
826
827
828
   std::cerr << "Not implemented yet: Get updates" << std::endl;
   QString url = updateURL->text();

   if ( !url.endsWith("/") )
     url += "/";


   pluginPath_.clear();
Jan Möbius's avatar
Jan Möbius committed
829
   pluginPath_ = "Plugins/";
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860

   if ( OpenFlipper::Options::isWindows() ) {
      pluginPath_ += "Windows/";
   } else if ( OpenFlipper::Options::isLinux() ) {
      pluginPath_ += "Linux/";
   } else {
      std::cerr << "Unknown operating system type, aborting update" << std::endl;
      return;
   }

   if ( OpenFlipper::Options::is64bit() ) {
      pluginPath_ += "64/";
   } else if ( OpenFlipper::Options::is32bit() ) {
      pluginPath_ += "32/";
   } else {
      std::cerr << "Unknown architecture type, aborting update" << std::endl;
      return;
   }

   pluginPath_ += "Release/";

   if ( !updatedPlugins_.empty() && updatedPlugins_[0] == "Core" ) {
      std::cerr << "Core update not supported!" << std::endl;
      return;
   }

   if ( !updatedPlugins_.empty() ) {
      currentUpdateName_ = updatedPlugins_[0];
      std::cerr << "Downloading " << (url + pluginPath_ + currentUpdateName_).toStdString() << std::endl;
      updatedPlugins_.pop_front();

Jan Möbius's avatar
Jan Möbius committed
861
      downloadType = PLUGIN;
862
863
864
865
866
867
868
869
870
871

      startDownload(url + pluginPath_ + currentUpdateName_);
   }

}

void OptionsWidget::updateComponent() {
   std::cerr << "Todo : Update component" << std::endl;


Jan Möbius's avatar
Jan Möbius committed
872
873
874
875
876
877
878
879
880
881
882
883
884

   QString sourceName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
                                     ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + currentUpdateName_ ;

   QString targetName = OpenFlipper::Options::applicationDirStr() + "/" + pluginPath_ + currentUpdateName_;

   QFileInfo sourceFileInfo(sourceName);
   QFileInfo targetFileInfo(targetName);

   std::cerr << sourceName.toStdString() << std::endl;
   std::cerr << targetName.toStdString() << std::endl;

   if ( ! sourceFileInfo.exists() ) {
885
      statusLabel->setText(tr("Download failed!"));
Jan Möbius's avatar
Jan Möbius committed
886
      slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
887
      return;
888
   } else {
Jan Möbius's avatar
Jan Möbius committed
889
      if ( ! targetFileInfo.exists() ) {
890
         statusLabel->setText(tr("plugin target does not exist"));
Jan Möbius's avatar
Jan Möbius committed
891
         slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
892
893
894
         return;
      }

895
      statusLabel->setText(tr("Installing new file"));
Jan Möbius's avatar
Jan Möbius committed
896

Jan Möbius's avatar
Jan Möbius committed
897
      // Remove the old plugin
Jan Möbius's avatar
Jan Möbius committed
898
899
      QFile targetFile(targetName);
      targetFile.remove();
900

Jan Möbius's avatar
Jan Möbius committed
901
      // copy new to old
Jan Möbius's avatar
Jan Möbius committed
902
903
      QFile::copy(sourceName,targetName);

Jan Möbius's avatar
Jan Möbius committed
904
905
906
907
      // remove downloaded file
      QFile sourceFile(sourceName);
      sourceFile.remove();

908
      statusLabel->setText(tr("updated ") + currentUpdateName_);
909
   }
Jan Möbius's avatar
Jan Möbius committed
910
911

   slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
912
913
}

914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
bool OptionsWidget::isNewer(QString _current, QString _latest) {

  QStringList latestVersionParts  = _latest.split('.');
  QStringList currentVersionParts = _current.split('.');

  bool newer = false;

  for ( int i = 0 ; i < latestVersionParts.size(); ++i ) {

    if ( i+1 > currentVersionParts.size() ) {
      // Versions are identical up to now. But latest version has additional version => updated
      newer = true;
      break;
    }

    bool ok = false;
    double latest  = latestVersionParts[i].toInt(&ok);
    double current = currentVersionParts[i].toInt(&ok);

    if ( !ok )
      std::cerr << "Error when parsing version strings!" << std::endl;

    if ( latest > current ) {
      newer = true;
      break;
    }
  }

  return newer;

}

void OptionsWidget::compareVersions() {

  QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
                     ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;

  INIFile ini;
  if ( ! ini.connect(fileName,false) ) {
    std::cerr << "Failed to connect to Versions ini file" << std::endl;
    return;
  }

957
  statusLabel->setText(tr("Checking for new versions"));
958
959
960

  bool newerVersionsAvailable = false;

961
  QString systemString = "";
962
  if ( OpenFlipper::Options::isWindows() ) {
963
964
965
966
967
968
969
970
971
972
973
974
975
    systemString = "VersionWindows";
  } else if (OpenFlipper::Options::isLinux()) {
    systemString = "VersionLinux";
  } else {
    std::cerr << "Unsupported platform for update" << std::endl;
    return;
  }

  QString coreVersion;

  if ( ini.get_entry(coreVersion, "Core" , systemString )) {
    if ( isNewer( OpenFlipper::Options::coreVersion(), coreVersion ) ) {
      newerVersionsAvailable = true;
Jan Möbius's avatar
Jan Möbius committed
976
    }
977
978
979
980
981
  }

  for ( uint i = 0 ; i < plugins_.size(); ++i ) {
    QString latestVersion;
    if ( ini.get_entry(latestVersion, plugins_[i].name , systemString )) {
Jan Möbius's avatar
Jan Möbius committed
982
      if ( isNewer(  plugins_[i].version, latestVersion ) )
983
        newerVersionsAvailable = true;
984
    }
985
986
987
  }

  if ( newerVersionsAvailable ) {
988
    statusLabel->setText(tr("Updates found"));
989
  } else {
990
    statusLabel->setText(tr("No updates found"));
991
992
993
  }

  ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
994
995

  updateVersionsTable();
996
}
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012

void OptionsWidget::slotPreviewStereoSettings(int /*_tmpParam*/) {
    
  if (stereoCustomAnaglyph->isChecked ())
     OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
  else if (stereoAnaglyph->isChecked ())
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
  else
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);

  OpenFlipperSettings().setValue("Core/Stereo/EyeDistance", eyeDistance->value());
  OpenFlipperSettings().setValue("Core/Stereo/FocalDistance", double(focalDistance->value() / 1000.0));

  
  // Update all views
 emit applyOptions();
1013
1014
1015
1016
1017
1018
1019
1020
1021
}

void OptionsWidget::slotClearSettings() {
    
    OpenFlipperSettings().clear();
}

void OptionsWidget::slotClearINI() {
    
1022
1023
    QMessageBox::information(this, tr("Restart required!"),
                             tr("The changes will take effect after next restart."));
1024
    
1025
    OpenFlipper::Options::deleteIniFile(true);
1026
}
1027
1028
1029
1030
1031

void OptionsWidget::slotReloadShaders()
{
  ACG::ShaderCache::getInstance()->clearCache();
}