optionsWidget.cc 27.6 KB
Newer Older
1
2
3
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
39
40
41
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
42
43
44
45
46
47
48




#include "optionsWidget.hh"
#include <iostream>
#include <OpenFlipper/common/GlobalOptions.hh>
Dirk Wilden's avatar
Dirk Wilden committed
49
50
#include <ACG/Scenegraph/DrawModes.hh>
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
51
#include <OpenFlipper/INIFile/INIFile.hh>
52
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Dirk Wilden's avatar
Dirk Wilden committed
53

54
#include <QColorDialog>
55
#include <QMessageBox>
56

Dirk Wilden's avatar
Dirk Wilden committed
57
OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, InverseKeyMap& _invKeys, QWidget *parent)
Jan Möbius's avatar
Jan Möbius committed
58
59
  : QWidget(parent),
    plugins_(_plugins),
Dirk Wilden's avatar
Dirk Wilden committed
60
61
    coreKeys_(_core),
    keys_(_invKeys)
Jan Möbius's avatar
Jan Möbius committed
62

63
64
{
  setupUi(this);
Dirk Wilden's avatar
Dirk Wilden committed
65

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

  // Viewer Settings
Dirk Wilden's avatar
Dirk Wilden committed
74
  connect( restrictFPS, SIGNAL(toggled(bool)), FPS, SLOT(setEnabled(bool)) );
75
76
77
78
79
  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)));

80
81
82
83
84
85
86
87
88
89
  // 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()));
  connect(stereoPhilips, SIGNAL(clicked()),
          this, SLOT(switchStackedWidget()));

90
91
92
93
94
  connect(headerFactor, SIGNAL(valueChanged(int)),
          this, SLOT(updateSliderCounter(int)));
  connect(headerOffsetCC, SIGNAL(valueChanged(int)),
          this, SLOT(updateSliderCounter(int)));

Dirk Wilden's avatar
Dirk Wilden committed
95
96
  uint mode = 2;
  for (uint i=1; i < 22; i++) {
97
    std::vector< QString > dm = drawModeToDescriptions( mode );
Jan Möbius's avatar
Jan Möbius committed
98

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

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

104
      item->setCheckState(Qt::Unchecked);
Dirk Wilden's avatar
Dirk Wilden committed
105
106
107

      availDrawModes->addItem( item );
    }
108

Dirk Wilden's avatar
Dirk Wilden committed
109
    mode = mode<<1;
110
  }
Dirk Wilden's avatar
Dirk Wilden committed
111

112
113
114
115
116
  for ( int i=0; i < PluginFunctions::viewers(); i++ ){
    viewerList->addItem("Viewer " + QString::number(i+1) );
    defaultDrawModes_.push_back( 0 );
    defaultProjectionMode_.push_back( 0 );
    defaultViewingDirections_.push_back( 0 );
117
  }
Jan Möbius's avatar
Jan Möbius committed
118

Dirk Wilden's avatar
Dirk Wilden committed
119
120
121
  pluginOptionsLayout = new QVBoxLayout;
  pluginOptions->setLayout( pluginOptionsLayout );

Jan Möbius's avatar
Jan Möbius committed
122
  http = new QHttp(this);
Jan Möbius's avatar
Jan Möbius committed
123

Jan Möbius's avatar
Jan Möbius committed
124
125
126
127
128
129
130
  // http specific connections
  connect(http, SIGNAL(requestFinished(int, bool)),
        this, SLOT(httpRequestFinished(int, bool)));
  connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
        this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
  connect(http, SIGNAL(dataReadProgress(int, int)),
          this, SLOT(updateDataReadProgress(int, int)));
Jan Möbius's avatar
Jan Möbius committed
131

Jan Möbius's avatar
Jan Möbius committed
132
133
134

  progressDialog = new QProgressDialog(this);
  connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
135
136
137
138


  //colordialog
  connect(backgroundButton, SIGNAL(clicked()), this, SLOT(getBackgroundColor()) );
139
  connect(baseColorButton, SIGNAL(clicked()), this, SLOT(getBaseColor()) );
140
141
142
}

void OptionsWidget::getBackgroundColor(){
143
  QColor newColor = QColorDialog::getColor ( OpenFlipper::Options::defaultBackgroundColor() );
144

145
  OpenFlipper::Options::defaultBackgroundColor( newColor) ;
146
147

  QPixmap color(16,16);
148
  color.fill( OpenFlipper::Options::defaultBackgroundColor() );
149
  backgroundButton->setIcon( QIcon(color) );
150
151
}

152
153
154
155
156
157
158
159
160
161
void OptionsWidget::getBaseColor(){
  QColor newColor = QColorDialog::getColor ( OpenFlipper::Options::defaultBaseColor() );

  OpenFlipper::Options::defaultBaseColor( newColor) ;

  QPixmap color(16,16);
  color.fill( OpenFlipper::Options::defaultBaseColor() );
  baseColorButton->setIcon( QIcon(color) );
}

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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)
	mode.push_back( availDrawModes->item(i)->text() );

    defaultDrawModes_[         viewerList->currentRow() ] = descriptionsToDrawMode(mode);
    defaultProjectionMode_[    viewerList->currentRow() ] = projectionBox->currentIndex();
    defaultViewingDirections_[ viewerList->currentRow() ] = directionBox->currentIndex();
  }
};

182
183
184
185
186
187
188
189
190
191
192
193
194
195
void OptionsWidget::switchStackedWidget() {

    // Show right stacked widget of stereo settings
    if (stereoCustomAnaglyph->isChecked()) {
        stackedWidget->setCurrentIndex(0);
    } else if (stereoAnaglyph->isChecked()) {
        stackedWidget->setCurrentIndex(0);
    } else if (stereoPhilips->isChecked()) {
        stackedWidget->setCurrentIndex(1);
    } else {
        stackedWidget->setCurrentIndex(0);
    }
}

196
197
198
199
200
201
void OptionsWidget::updateSliderCounter(int /*_tmpParam*/) {
    // Update labels that display the current values
    factorCounter->setNum(headerFactor->value());
    offsetCounter->setNum(headerOffsetCC->value());
}

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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);
    }
  }

  projectionBox->setCurrentIndex( defaultProjectionMode_[_row] );
  directionBox->setCurrentIndex(  defaultViewingDirections_[_row] );

  updatingViewerSettings_ = false;
}

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

Jan Möbius's avatar
Jan Möbius committed
228
  //general
Dirk Wilden's avatar
Dirk Wilden committed
229
230
231
  fullscreen->setChecked( OpenFlipper::Options::fullScreen() );
  splash->setChecked( OpenFlipper::Options::splash() );
  toolbox->setChecked( !OpenFlipper::Options::hideToolbox() );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
232
233
234
235

  loggerHidden->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden);
  loggerNormal->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Normal);
  loggerInScene->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene);
Dirk Wilden's avatar
Dirk Wilden committed
236
  enableLogFile->setChecked( OpenFlipper::Options::logFileEnabled() );
Jan Möbius's avatar
Jan Möbius committed
237

Dirk Wilden's avatar
Dirk Wilden committed
238
239
  //paths
  logFile->setText( OpenFlipper::Options::logFile() );
Dirk Wilden's avatar
Dirk Wilden committed
240

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
241
  //stereo
242
243
244
245
246
247
248
249

  // 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
250
251
  stereoAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan);
  stereoCustomAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom);
252
  stereoPhilips->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::Philips);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
253

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
254
255
256
  eyeDistance->setValue (OpenFlipper::Options::eyeDistance());
  focalDistance->setValue (OpenFlipper::Options::focalDistance() * 1000);

257
258
259
260
261
262
263
264
  // Philips stereo mode part
  headerContentType->setCurrentIndex(OpenFlipper::Options::stereoPhilipsContent());
  headerFactor->setValue(OpenFlipper::Options::stereoPhilipsFactor());
  headerOffsetCC->setValue(OpenFlipper::Options::stereoPhilipsOffset());
  factorCounter->setNum(OpenFlipper::Options::stereoPhilipsFactor());
  offsetCounter->setNum(OpenFlipper::Options::stereoPhilipsOffset());
  headerSelect->setCurrentIndex(OpenFlipper::Options::stereoPhilipsSelect());

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  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]);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
287
288
289
290
  noMousePick->setChecked (!OpenFlipper::Options::stereoMousePick());

  nativeMouse->setChecked (!OpenFlipper::Options::glMouse());

Dirk Wilden's avatar
Dirk Wilden committed
291
292
293
  // plugin options
  initPluginOptions();

294
295
296
297
298
  // updates
  updateUser->setText( OpenFlipper::Options::updateUsername() );
  updatePass->setText( OpenFlipper::Options::updatePassword() );
  updateURL->setText( OpenFlipper::Options::updateUrl( ) );

Jan Möbius's avatar
Jan Möbius committed
299
300
301
  // debugging
  slotDebugging->setChecked(OpenFlipper::Options::doSlotDebugging());

Ellen Dekkers's avatar
Ellen Dekkers committed
302
  renderPicking->setChecked(OpenFlipper::Options::renderPicking());
303
304
305
  int itemIndex = pickingRenderMode->findText( OpenFlipper::Options::pickingRenderMode() );
  if (  itemIndex != -1 )
    pickingRenderMode->setCurrentIndex(itemIndex);
306

Dirk Wilden's avatar
Dirk Wilden committed
307
  //keyBindings
Dirk Wilden's avatar
Dirk Wilden committed
308
  initKeyTree();
309

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

Dirk Wilden's avatar
Dirk Wilden committed
312
313
  connect(keyTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
          this,    SLOT(keyTreeItemChanged( QTreeWidgetItem*, QTreeWidgetItem*)) );
Dirk Wilden's avatar
Dirk Wilden committed
314

Dirk Wilden's avatar
Dirk Wilden committed
315
316
  connect(keyTree, SIGNAL(itemDoubleClicked (QTreeWidgetItem*, int)),
          this,    SLOT(keyTreeDoubleClicked( QTreeWidgetItem*, int)) );
Dirk Wilden's avatar
Dirk Wilden committed
317
318


Dirk Wilden's avatar
Dirk Wilden committed
319
  connect(shortcutButton, SIGNAL(keyChanged()), this, SLOT(updateShortcut()) );
320
  connect(presetsButton, SIGNAL(clicked()), this, SLOT(restoreKeyPresets()) );
321
322


323
324
325
  //Init Viewer Settings
  wZoomFactor->setText( QString::number(OpenFlipper::Options::wheelZoomFactor(), 'f') );
  wZoomFactorShift->setText( QString::number(OpenFlipper::Options::wheelZoomFactorShift(), 'f') );
326

327
328
329
330
331
332
333
334
335
336
337
338
339
  wheelBox->setChecked( OpenFlipper::Options::showWheelsAtStartup() );

  restrictFPS->setChecked( OpenFlipper::Options::restrictFrameRate() );
  FPS->setValue( OpenFlipper::Options::maxFrameRate() );

  QPixmap color(16,16);
  color.fill( OpenFlipper::Options::defaultBackgroundColor() );
  backgroundButton->setIcon( QIcon(color) );

  color.fill( OpenFlipper::Options::defaultBaseColor() );
  baseColorButton->setIcon( QIcon(color) );

  randomBaseColor->setChecked( OpenFlipper::Options::randomBaseColor() );
340

341
342
343
344
345
346
  viewerList->setCurrentRow(0);

  for ( int i=0; i < PluginFunctions::viewers(); i++ ){
    defaultDrawModes_[i] = OpenFlipper::Options::defaultDrawMode(i);
    defaultProjectionMode_[i] = OpenFlipper::Options::defaultProjectionMode(i);
    defaultViewingDirections_[i] = OpenFlipper::Options::defaultViewingDirection(i);
347
  }
Jan Möbius's avatar
Jan Möbius committed
348

349
350
  updateViewerSettings(0);

351
  viewerLayout->setCurrentIndex( OpenFlipper::Options::defaultViewerLayout() );
352

353
354
  gridVisible->setChecked (OpenFlipper::Options::gridVisible());

355
356
357
358
359
360
361
  if (OpenFlipper::Options::translation() == "en_US")
    translation->setCurrentIndex(0);
  else if (OpenFlipper::Options::translation() == "de_DE")
    translation->setCurrentIndex(1);
  else
    translation->setCurrentIndex(2);

Jan Möbius's avatar
Jan Möbius committed
362
363
364
365
366
367
  updateVersionsTable();

}

void OptionsWidget::updateVersionsTable() {

368
369
  updatedPlugins_.clear();

Jan Möbius's avatar
Jan Möbius committed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
  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();
  updateList->setRowCount( 1 + plugins_.size() );
  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
406
    if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) ) {
Jan Möbius's avatar
Jan Möbius committed
407
      currentBrush.setColor(Qt::red);
408
409
      updatedPlugins_ << "Core";
    } else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) )
410
      currentBrush.setColor(Qt::blue);
Jan Möbius's avatar
Jan Möbius committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
    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
443
      if ( isNewer(plugins_[i].version,latestVersion) ) {
444
         currentBrush.setColor(Qt::red);
445
446
447
         QFileInfo pluginFile(plugins_[i].path );
         updatedPlugins_ << pluginFile.fileName();
      } else if ( isNewer(latestVersion,plugins_[i].version) )
448
         currentBrush.setColor(Qt::blue);
Jan Möbius's avatar
Jan Möbius committed
449
      else
450
         currentBrush.setColor(Qt::green);
Jan Möbius's avatar
Jan Möbius committed
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475

      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();

476
477
  updateButton->setEnabled(!updatedPlugins_.empty());

478
479
}

Dirk Wilden's avatar
Dirk Wilden committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
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;
    }
}

521
void OptionsWidget::slotApply() {
Dirk Wilden's avatar
Dirk Wilden committed
522

Jan Möbius's avatar
Jan Möbius committed
523
  //general
Dirk Wilden's avatar
Dirk Wilden committed
524
525
526
  OpenFlipper::Options::fullScreen( fullscreen->isChecked() );
  OpenFlipper::Options::splash( splash->isChecked() );
  OpenFlipper::Options::hideToolbox( !toolbox->isChecked() );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
527
  if (loggerHidden->isChecked())
Jan Möbius's avatar
Jan Möbius committed
528
    OpenFlipper::Options::loggerState( OpenFlipper::Options::Hidden );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
529
530
531
532
  else if (loggerInScene->isChecked())
    OpenFlipper::Options::loggerState( OpenFlipper::Options::InScene );
  else
    OpenFlipper::Options::loggerState( OpenFlipper::Options::Normal );
Dirk Wilden's avatar
Dirk Wilden committed
533
534
535
536
  OpenFlipper::Options::logFileEnabled( enableLogFile->isChecked() );

  //paths
  OpenFlipper::Options::logFile( logFile->text() );
Dirk Wilden's avatar
Dirk Wilden committed
537
538
539
540
541

  //viewer
  OpenFlipper::Options::wheelZoomFactor( wZoomFactor->text().toDouble() );
  OpenFlipper::Options::wheelZoomFactorShift( wZoomFactorShift->text().toDouble() );

542
  OpenFlipper::Options::restrictFrameRate( restrictFPS->isChecked() );
543
544
  OpenFlipper::Options::showWheelsAtStartup( wheelBox->isChecked() );

545
546
  OpenFlipper::Options::maxFrameRate( FPS->value() );

547
548
  OpenFlipper::Options::randomBaseColor( randomBaseColor->isChecked() );

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
549
550
551
552
553
  //stereo
  if (stereoCustomAnaglyph->isChecked ())
     OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
  else if (stereoAnaglyph->isChecked ())
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
554
555
  else if (stereoPhilips->isChecked() )
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::Philips);
556
  else
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
557
558
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
559
560
561
  OpenFlipper::Options::eyeDistance(eyeDistance->value ());
  OpenFlipper::Options::focalDistance((float)focalDistance->value () / 1000);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
562
563
  OpenFlipper::Options::stereoMousePick(!noMousePick->isChecked ());

564
565
566
567
568
569
  // Set option entries for philips stereo mode
  OpenFlipper::Options::stereoPhilipsContent(headerContentType->currentIndex());
  OpenFlipper::Options::stereoPhilipsFactor(headerFactor->value());
  OpenFlipper::Options::stereoPhilipsOffset(headerOffsetCC->value());
  OpenFlipper::Options::stereoPhilipsSelect(headerSelect->currentIndex());

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
  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);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
595
  OpenFlipper::Options::glMouse(!nativeMouse->isChecked ());
596

597
598
599
600
601
  // updates
  OpenFlipper::Options::updateUrl( updateURL->text() );
  OpenFlipper::Options::updateUsername( updateUser->text() );
  OpenFlipper::Options::updatePassword( updatePass->text() );

Jan Möbius's avatar
Jan Möbius committed
602
603
604
  // Debugging
  OpenFlipper::Options::doSlotDebugging(slotDebugging->isChecked());

605
606
607
  OpenFlipper::Options::renderPicking(renderPicking->isChecked());
  OpenFlipper::Options::pickingRenderMode( pickingRenderMode->currentText() );

608
609
610
611
612
613
  //viewer defaults
  for (int i=0; i < PluginFunctions::viewers(); i++){
    OpenFlipper::Options::defaultDrawMode(         defaultDrawModes_[i],         i );
    OpenFlipper::Options::defaultProjectionMode(   defaultProjectionMode_[i],    i );
    OpenFlipper::Options::defaultViewingDirection( defaultViewingDirections_[i], i );
  }
Dirk Wilden's avatar
Dirk Wilden committed
614

615
  OpenFlipper::Options::defaultViewerLayout( viewerLayout->currentIndex() );
616
  OpenFlipper::Options::gridVisible( gridVisible->isChecked() );
617
618
619
620
621
622
623

  switch ( translation->currentIndex() ){
    case 0 : OpenFlipper::Options::translation("en_US");  break;
    case 1 : OpenFlipper::Options::translation("de_DE");  break;
    default: OpenFlipper::Options::translation("locale"); break;
  }

Dirk Wilden's avatar
Dirk Wilden committed
624
625
  applyShortcuts();

626
  emit applyOptions();
Dirk Wilden's avatar
Dirk Wilden committed
627
  emit saveOptions();
Dirk Wilden's avatar
Dirk Wilden committed
628
}
629

Dirk Wilden's avatar
Dirk Wilden committed
630
631
void OptionsWidget::slotOk(){
  slotApply();
632
633
634
635
636
637
  hide();
}

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

Jan Möbius's avatar
Jan Möbius committed
639
640
641
642
643
void OptionsWidget::slotCheckUpdates() {

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

  downloadType = VERSIONS_FILE;
644
645
646
  QString ServerMainURL = updateURL->text();
  if ( !ServerMainURL.endsWith("/") )
     ServerMainURL += "/";
Jan Möbius's avatar
Jan Möbius committed
647

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

650
  startDownload(ServerMainURL);
Jan Möbius's avatar
Jan Möbius committed
651
652
653
}

void OptionsWidget::slotGetUpdates() {
654
655
656
657
658
659
660
661
   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
662
   pluginPath_ = "Plugins/";
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693

   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
694
      downloadType = PLUGIN;
695
696
697
698
699
700
701
702
703
704

      startDownload(url + pluginPath_ + currentUpdateName_);
   }

}

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


Jan Möbius's avatar
Jan Möbius committed
705
706
707
708
709
710
711
712
713
714
715
716
717

   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() ) {
718
      statusLabel->setText(tr("Download failed!"));
Jan Möbius's avatar
Jan Möbius committed
719
      slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
720
      return;
721
   } else {
Jan Möbius's avatar
Jan Möbius committed
722
      if ( ! targetFileInfo.exists() ) {
723
         statusLabel->setText(tr("plugin target does not exist"));
Jan Möbius's avatar
Jan Möbius committed
724
         slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
725
726
727
         return;
      }

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

Jan Möbius's avatar
Jan Möbius committed
730
      // Remove the old plugin
Jan Möbius's avatar
Jan Möbius committed
731
732
      QFile targetFile(targetName);
      targetFile.remove();
733

Jan Möbius's avatar
Jan Möbius committed
734
      // copy new to old
Jan Möbius's avatar
Jan Möbius committed
735
736
      QFile::copy(sourceName,targetName);

Jan Möbius's avatar
Jan Möbius committed
737
738
739
740
      // remove downloaded file
      QFile sourceFile(sourceName);
      sourceFile.remove();

741
      statusLabel->setText(tr("updated ") + currentUpdateName_);
742
   }
Jan Möbius's avatar
Jan Möbius committed
743
744

   slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
745
746
}

747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
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;
  }

790
  statusLabel->setText(tr("Checking for new versions"));
791
792
793

  bool newerVersionsAvailable = false;

794
  QString systemString = "";
795
  if ( OpenFlipper::Options::isWindows() ) {
796
797
798
799
800
801
802
803
804
805
806
807
808
    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
809
    }
810
811
812
813
814
  }

  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
815
      if ( isNewer(  plugins_[i].version, latestVersion ) )
816
        newerVersionsAvailable = true;
817
    }
818
819
820
  }

  if ( newerVersionsAvailable ) {
821
    statusLabel->setText(tr("Updates found"));
822
  } else {
823
    statusLabel->setText(tr("No updates found"));
824
825
826
  }

  ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
827
828

  updateVersionsTable();
829
}