Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
coresettingswidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // coresettingswidget.cpp
3 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
4 // (c) 2010-2012
5 // Yves Sablonier, Pete Morgan
6 // Geoff McLane
7 // GNU GPLv2, see main.cpp and shipped licence.txt for further information
8 
9 #include "app_config.h"
10 //#include <QtDebug>
11 
12 #include <QProcess>
13 
14 #include <QVBoxLayout>
15 #include <QHBoxLayout>
16 #include <QLabel>
17 #include <QRadioButton>
18 #include <QPushButton>
19 #include <QFileDialog>
20 #include <QWhatsThis>
21 #include <QColor>
22 
24 #include "xwidgets/xgroupboxes.h"
25 #include "utilities/helpers.h"
26 #include "utilities/utilities.h"
28 
30  QWidget(parent)
31 {
32 
33  mainObject = mOb;
34 
35  fgrootcheck = false;
36 
37  QHBoxLayout *mainLayout = new QHBoxLayout();
38  setLayout(mainLayout);
39 
40  QVBoxLayout *layoutLeft = new QVBoxLayout();
41  mainLayout->addLayout(layoutLeft, 1);
42 
43  QVBoxLayout *layoutMiddle = new QVBoxLayout();
44  mainLayout->addLayout(layoutMiddle, 1);
45 
46  QVBoxLayout *layoutRight = new QVBoxLayout();
47  mainLayout->addLayout(layoutRight, 1);
48 
49 
50  //==================================================================
51  //= Image
52 
53  QHBoxLayout *imgBox = new QHBoxLayout();
54  imgBox->setAlignment(Qt::AlignBottom|Qt::AlignCenter);
55  layoutLeft->addLayout(imgBox);
56 
57 
58 
59 
60  //==================================================================
61  //= Set Callsign
62  XGroupVBox *grpCallsign = new XGroupVBox(tr("Callsign"));
63  layoutLeft->addWidget(grpCallsign);
64 
65  txtCallSign = new QLineEdit(this);
66  txtCallSign->setText("");
67  txtCallSign->setMaxLength(7);
68  grpCallsign->addWidget(txtCallSign);
69  connect(txtCallSign, SIGNAL(textChanged(QString)), this, SLOT(on_callsign_changed(QString)) );
70  grpCallsign->setWhatsThis(tr("<b>Your Callsign</b><br>Edit your callsign (max. 7 letters). This will be your uniqe callsign \
71  used by FlightGear. For local offline flight or in multiplayer mode."));
72 
73 
74 
75  layoutLeft->addStretch(10);
76 
77 
78 
79  //===========================================================================
80  //= Paths
81  QVBoxLayout *layoutPaths = new QVBoxLayout();
82  layoutMiddle->addLayout(layoutPaths);
83 
84  //----------------------------------------------
85  //= FlightGear box
86 
87  XGroupVBox *grpFgfs = new XGroupVBox("FlightGear program and data");
88  layoutPaths->addWidget(grpFgfs,2);
89 
90  //----------------------------------------------
91  //= FlightGear executable (fgfs)
92 
93  labelFgfsProgram = new QLabel("Path to FlightGear program (fgfs):");
94  labelFgfsCheck = new QLabel("");
95 
96  //#lineEditFgFsPath = new QLineEdit("");
97  //lineEditFgFsPath->setFixedSize(QSize(240,20));
98  comboFgFsPath = new QComboBox();
99  comboFgFsPath->setFixedSize(QSize(240,20));
100  comboFgFsPath->setEditable(true);
101 
102  buttonSetFgfsPath = new QToolButton();
103  buttonSetFgfsPath->setFixedSize(20,20);
104  buttonSetFgfsPath->setIcon(QIcon(":/icon/path"));
105  grpFgfs->addWidget(labelFgfsProgram);
106 
107 
108  QHBoxLayout *fgfsPathBox = new QHBoxLayout();
109  fgfsPathBox->addWidget(comboFgFsPath);
110  fgfsPathBox->addWidget(labelFgfsCheck);
111  fgfsPathBox->addWidget(buttonSetFgfsPath);
112  grpFgfs->addLayout(fgfsPathBox);
113  comboFgFsPath->setEditText( mainObject->X->fgfs_path() );
114 
115  // "Set" clicked
116  connect( buttonSetFgfsPath, SIGNAL(clicked()),this, SLOT(on_select_fgfsbutton()) );
117 
118  //Check if path exists, set pixmap, emit setting
119  connect(comboFgFsPath, SIGNAL(textChanged(QString)), this, SLOT(fgfs_check_path()));
120  connect(comboFgFsPath, SIGNAL(textChanged(QString)), this, SLOT(on_fgfs_path(QString)));
121  connect(buttonSetFgfsPath, SIGNAL(clicked()), this, SLOT(fgfs_set_path()));
122 
123  //----------------------------------------------
124  //= FlightGear Root Data Directory (/fgdata)
125 
126  labelFgRootData = new QLabel("Path to FlightGear data directory (fgdata): ");
127  labelFgRootCheck = new QLabel("");
128  lineEditFgRootPath = new QLineEdit("");
129  lineEditFgRootPath->setFixedSize(QSize(240,20));
130  buttonSetFgRootPath = new QToolButton();
131  buttonSetFgRootPath->setFixedSize(20,20);
132  buttonSetFgRootPath->setIcon(QIcon(":/icon/path"));
133  grpFgfs->addWidget(labelFgRootData);
134 
135  QHBoxLayout *fgfsRootBox = new QHBoxLayout();
136  fgfsRootBox->addWidget(lineEditFgRootPath);
137  fgfsRootBox->addWidget(labelFgRootCheck);
138  fgfsRootBox->addWidget(buttonSetFgRootPath);
139  grpFgfs->addLayout(fgfsRootBox);
140  lineEditFgRootPath->setText( mainObject->X->fgroot() );
141 
142  // "Set" clicked
143  connect( buttonSetFgRootPath, SIGNAL(clicked()),this, SLOT(on_select_fgrootbutton()) );
144 
145  //Check if path exists and set pixmap
146  connect(lineEditFgRootPath, SIGNAL(textChanged(QString)), this, SLOT(fgroot_check_path()));
147  connect(lineEditFgRootPath, SIGNAL(textChanged(QString)), this, SLOT(on_fgroot_path(QString)));
148  connect(buttonSetFgRootPath, SIGNAL(clicked()), this, SLOT(fgroot_set_path()));
149 
150 
151  //----------------------------------------------
152  //= Scenery box
153 
154  XGroupVBox *grpScene = new XGroupVBox("Scenery program and data");
155  layoutPaths->addWidget(grpScene,2);
156 
157  //----------------------------------------------
158  //= Terrasync Executable (terrasync)
159 
160  checkBoxUseTerrasync = new QCheckBox("Use online scenery download tool (Terrasync)");
161  grpScene->addWidget(checkBoxUseTerrasync);
162  connect(checkBoxUseTerrasync, SIGNAL(clicked()), this, SLOT(on_terrasync_enabled()));
163 
164  labelTerrasyncCheck = new QLabel("");
165  labelTerrasyncCheck->setEnabled(false);
166  lineEditTerraSyncExePath = new QLineEdit("");
167  lineEditTerraSyncExePath->setFixedSize(QSize(240,20));
168  lineEditTerraSyncExePath->setEnabled(false);
169  buttonSetTerrasyncExePath = new QToolButton();
170  buttonSetTerrasyncExePath->setFixedSize(20,20);
171  buttonSetTerrasyncExePath->setIcon(QIcon(":/icon/path"));
172  buttonSetTerrasyncExePath->setEnabled(false);
173 
174  QHBoxLayout *terraProgramBox = new QHBoxLayout();
175  terraProgramBox->addWidget(lineEditTerraSyncExePath);
176  terraProgramBox->addWidget(labelTerrasyncCheck);
177  terraProgramBox->addWidget(buttonSetTerrasyncExePath);
178  grpScene->addLayout(terraProgramBox);
180 
181  // "Set" clicked
182  connect( buttonSetTerrasyncExePath, SIGNAL(clicked()),this, SLOT(on_select_terrasyncexebutton()) );
183 
184  //Check if path exists and set pixmap
185  connect(lineEditTerraSyncExePath, SIGNAL(textChanged(QString)), this, SLOT(terrasync_exe_check_path()));
186  connect(lineEditTerraSyncExePath, SIGNAL(textChanged(QString)), this, SLOT(on_terrasync_path(QString)));
187  // connect(buttonSetTerrasyncExePath, SIGNAL(textChanged(QString)), this, SLOT(terrasyncexe_set_path()));
188 
189 
190  //----------------------------------------------
191  //= Terrasync Directory (custom, but set by default)
192 
193  labelTerrasyncData = new QLabel("Path to terrasync scenery: ");
195  labelTerrasyncDataCheck->setEnabled(false);
196  lineEditTerraSyncDataPath = new QLineEdit("");
197  lineEditTerraSyncDataPath->setFixedSize(QSize(240,20));
198  lineEditTerraSyncDataPath->setEnabled(false);
199  buttonSetTerrasyncDataPath = new QToolButton();
200  buttonSetTerrasyncDataPath->setFixedSize(20,20);
201  buttonSetTerrasyncDataPath->setIcon(QIcon(":/icon/path"));
202  buttonSetTerrasyncDataPath->setEnabled(false);
203  grpScene->addWidget(labelTerrasyncData);
204 
205  QHBoxLayout *terraDataBox = new QHBoxLayout();
206  terraDataBox->addWidget(lineEditTerraSyncDataPath);
207  terraDataBox->addWidget(labelTerrasyncDataCheck);
208  terraDataBox->addWidget(buttonSetTerrasyncDataPath);
209  grpScene->addLayout(terraDataBox);
210 
212 
213  // "Set" clicked
214  connect( buttonSetTerrasyncDataPath, SIGNAL(clicked()),this, SLOT(on_select_terrasyncdatabutton()) );
215 
216  //Check if path exists and set pixmap
217  connect(lineEditTerraSyncDataPath, SIGNAL(textChanged(QString)), this, SLOT(terrasync_data_check_path()));
218  connect(lineEditTerraSyncDataPath, SIGNAL(textChanged(QString)), this, SLOT(on_terrasync_data_path(QString)));
219  // connect(buttonSetTerrasyncDataPath, SIGNAL(textChanged(QString)), this, SLOT(terrasyncdata_set_path()));
220 
221  layoutMiddle->addStretch(20);
222 
223 
224  //----------------------------------------------
225  //= Custom Scenery Directory (always custom)
226 
227  checkBoxUseCustomScenery = new QCheckBox("Use custom scenery");
229  connect(checkBoxUseCustomScenery, SIGNAL(clicked()), this, SLOT(on_custom_scenery_enabled()));
230 
231  labelCustomScene = new QLabel("Path(s) to custom scenery directories:");
232  labelCustomSceneCheck = new QLabel("");
233  labelCustomSceneCheck->setEnabled(false);
234  lineEditCustomScenePath = new QLineEdit("");
235  lineEditCustomScenePath->setFixedSize(QSize(240,20));
236  lineEditCustomScenePath->setEnabled(false);
237  buttonSetCustomSceneryPath = new QToolButton();
238  buttonSetCustomSceneryPath->setFixedSize(20,20);
239  buttonSetCustomSceneryPath->setIcon(QIcon(":/icon/path"));
240  buttonSetCustomSceneryPath->setEnabled(false);
241  grpScene->addWidget(labelCustomScene);
242 
243  QHBoxLayout *customSceneBox = new QHBoxLayout();
244  customSceneBox->addWidget(lineEditCustomScenePath);
245  customSceneBox->addWidget(labelCustomSceneCheck);
246  customSceneBox->addWidget(buttonSetCustomSceneryPath);
247  grpScene->addLayout(customSceneBox);
248 
250 
251  // "Set" clicked
252  connect( buttonSetCustomSceneryPath, SIGNAL(clicked()),this, SLOT(on_select_customscenerybutton()) );
253 
254  //Check if path exists and set pixmap
255  //connect(lineEditCustomScenePath, SIGNAL(textChanged(QString)), this, SLOT(custom_scenery_check_path()));
256  connect(lineEditCustomScenePath, SIGNAL(textChanged(QString)), this, SLOT(on_custom_scenery_path(QString)));
257  // connect(buttonSetCustomSceneryPath, SIGNAL(textChanged(QString)), this, SLOT(customscenery_set_path()));
258 
259 
260  //===========================================================================
261  //= Input
262  QVBoxLayout *layoutInput = new QVBoxLayout();
263  layoutRight->addLayout(layoutInput);
264 
265  //==================================================================
266  //= Map Features
267  XGroupVBox *grpMapFeatures = new XGroupVBox("Map Features");
268  layoutRight->addWidget(grpMapFeatures);
269 
270  checkBoxShowMpMap = new QCheckBox("Show Map in Browser");
271  grpMapFeatures->addWidget(checkBoxShowMpMap);
272  connect(checkBoxShowMpMap, SIGNAL(clicked()), this, SLOT(on_show_mp_map()));
273 
274  comboMpMapServer = new QComboBox();
275  //#comboMpMapServer->addItem("mpmap01.flightgear.org", "http://mpmap01.flightgear.org"); // Olivers is down
276  comboMpMapServer->addItem("mpmap02.flightgear.org", "http://mpmap02.flightgear.org");
277  comboMpMapServer->setCurrentIndex(0);
278  grpMapFeatures->addWidget(comboMpMapServer);
279  connect(comboMpMapServer, SIGNAL(currentIndexChanged(int)), this, SLOT(on_show_mp_map()));
280  layoutRight->addStretch(20);
281 
282  //----------------------------------------------
283  //= FGCom Executable (fgcom)
284 
285  //labelFGComExeInfo = new QLabel(tr("FGCom executable (fgcom):"));
286  //grpFgPaths->addWidget(labelFGComExeInfo, 1);
287 
288  //lineEditFGComExePath = new QLineEdit("");
289  //lineEditFGComExePath->setStyleSheet(style_paths);
290  //lineEditFGComExePath->setFixedSize(QSize(280,20));
291  //grpFgPaths->addWidget(lineEditFGComExePath);
292 
293  //lineEditFGComExePath->setText(mainObject->X->fgcom_exe_path());
294 
295 
296 
297  //==================================================================
298  //= Controls
299 
300  XGroupVBox *grpBoxControls = new XGroupVBox(tr("FGx Controls Pre-check"));
301  grpBoxControls->setStyleSheet("XGroupVBox::title { color: #000000; background-color: #eeeeee }");
302  layoutInput->addWidget(grpBoxControls);
303  grpBoxControls->addWidget(new QLabel("Joystick:"));
304 
305  labelInputs = new QLabel("");
306  //labelInputs->setStyleSheet(style_paths);
307  grpBoxControls->addWidget(labelInputs);
308  grpBoxControls->setWhatsThis("<b>Controls</b><br><br>FlightGear use auto-detection to detect your input devices. This is just a pre-check of what FlightGear will see.");
309 
310  layoutInput->addStretch(20);
311 
312  this->add_fgfs_paths();
313 
314  connect(this, SIGNAL(setx(QString,bool,QString)), mainObject->X, SLOT(set_option(QString,bool,QString)) );
315  connect(mainObject->X, SIGNAL(upx(QString,bool,QString)), this, SLOT(on_upx(QString,bool,QString)));
316 
317 }
318 
319 
321  if(txtCallSign->text().trimmed().length() == 0){
322  txtCallSign->setFocus();
323  return QString("Callsign is empty");
324  }
325  return QString("");
326 }
327 
328 
329 
330 
331 //==============================================
332 //== Initialize
334  load_joysticks();
335 }
336 
337 
338 //==============================================
339 //== Load Joysticks
341  labelInputs->setText("");
342  QString find = "Joystick ";
343  QString none = "not detected";
344  QString results;
345  QProcess process;
346  int count = 0;
347  QString startJSDemoPath;
348  QStringList args;
349  startJSDemoPath = mainObject->X->getx("jsdemo_exe_path");
350  // TODO Fix this macro
351 #ifdef Q_OS_MAC
352  outLog("*** FGx Joystick Pre-Check jsdemo OSX-path defined: "+startJSDemoPath);
353 #else // #elif defined(Q_OS_UNIX)
354  // TODO Check maybe this could be used for ALL ports?
355  if (startJSDemoPath.length() == 0) {
356  // see if it can be found...
357  startJSDemoPath = mainObject->X->fgfs_path();
358  if (startJSDemoPath.length()) { // we have a path to 'fgfs'
359  startJSDemoPath = util_getBasePath(startJSDemoPath);
360  startJSDemoPath.append("js_demo");
361 #ifdef Q_OS_WIN
362  startJSDemoPath.append(".exe"); // add the windows thing
363 #endif // Q_OS_WIN
364  if (QFile::exists(startJSDemoPath)) { // if file exists,
365  emit setx("jsdemo_exe_path",true,startJSDemoPath); // update profile
366  }
367  } else {
368  startJSDemoPath = "js_demo";
369  }
370  }
371  // This will do NOTHING is no 'environment' defined
372  QStringList extra_env = mainObject->X->get_fgfs_env();
373  if (extra_env.size()) {
374  //= append new env vars
375  QStringList env = QProcess::systemEnvironment();
376  env << extra_env;
377  process.setEnvironment(env);
378  }
379 #endif
380  process.start(startJSDemoPath, args, QIODevice::ReadOnly);
381  if(process.waitForStarted()){
382  process.waitForFinished(3000);
383  QString ok_result = process.readAllStandardOutput();
384  QString error_result = process.readAllStandardError();
385  outLog("*** FGx jsdemo joystick pre-check result: "+ok_result);
386  if (error_result > 0) {
387  outLog("*** FGx jsdemo error results: "+error_result);
388  }
389  //Q_UNUSED(error_result);
390  //* take result and split into parts
391  QStringList entries = ok_result.trimmed().split("\n");
392  for(int i=2; i < entries.count(); i++){ //First 2 lines are crap
393  QString line = entries.at(i).trimmed();
394  if (line.indexOf(find) == 0) {
395  line = line.mid(find.size()+2).trimmed();
396  if (line.at(0) == QChar('"'))
397  line = line.mid(1);
398  if (line.at(line.size()-1) == QChar('"'))
399  line = line.mid(0,line.size()-1);
400  if (line != none) {
401  results += "Found \""+line+"\"\n";
402  if (count == 0)
403  labelInputs->setText(line);
404  count++;
405  }
406  }
407  }
408  } else {
409  results = "FGx Error: Unable to run '"+startJSDemoPath+"' to get Joystick list!\n";
410  }
411  outLog("*** FGx reports: Joystick detection results\n"+results+" ***"); // show results in LOG
412  if (count == 0) {
413  labelInputs->setEnabled(false);
414  labelInputs->setText("No Joystick detected. Check logs");
415  }
416 }
417 
418 
419 
420 //=====================================
421 // Callsign Changed
423 {
424  emit( setx("--callsign=", true, txt ));
425  mainObject->launcherWindow->on_upx("--callsign=", true, txt); // change text in headerwidget
426 }
427 
428 
429 //=====================================
430 // Show Mp Map
432  comboMpMapServer->setEnabled(checkBoxShowMpMap->isChecked());
433  emit setx( "show_mpmap",
434  checkBoxShowMpMap->isChecked(),
435  comboMpMapServer->itemData(comboMpMapServer->currentIndex()).toString()
436  );
437 }
438 
439 //=====================================
440 // Emit fgfs path
442 {
443  emit( mainObject->X->set_option("fgfs_path", true, txt));
444 }
445 
446 //=====================================
447 // Emit fgroot path
449 {
450  emit( setx("fgroot_path", true, txt));
451 }
452 
453 //=====================================
454 // Emit terrasync path
456 {
457  emit( setx("terrasync_exe_path", true, txt));
458 }
459 
460 //=====================================
461 // Emit terrasync data path
463 {
464  emit( setx("terrasync_data_path", true, txt));
465 }
466 
467 //=====================================
468 // Emit Custom Scenery path
470 {
471  emit( setx("custom_scenery_path", true, txt));
472 }
473 
474 
475 //=====================================
476 // Terrasync enabled
478 {
479  emit( setx("terrasync_enabled", checkBoxUseTerrasync->isChecked(), ""));
481 }
482 
484 {
485  lineEditTerraSyncExePath->setEnabled(checkBoxUseTerrasync->checkState());
486  lineEditTerraSyncDataPath->setEnabled(checkBoxUseTerrasync->checkState());
487  buttonSetTerrasyncExePath->setEnabled(checkBoxUseTerrasync->checkState());
488  buttonSetTerrasyncDataPath->setEnabled(checkBoxUseTerrasync->checkState());
489  labelTerrasyncCheck->setEnabled(checkBoxUseTerrasync->checkState());
490  labelTerrasyncDataCheck->setEnabled(checkBoxUseTerrasync->checkState());
491 }
492 
493 //=====================================
494 // Custom Scenery enabled
496 {
497  emit( setx("custom_scenery_enabled", checkBoxUseCustomScenery->isChecked(), ""));
499 }
500 
502 {
503  lineEditCustomScenePath->setEnabled(checkBoxUseCustomScenery->checkState());
504  buttonSetCustomSceneryPath->setEnabled(checkBoxUseCustomScenery->checkState());
505  labelCustomSceneCheck->setEnabled(checkBoxUseCustomScenery->checkState());
506 }
507 
508 
509 
510 //======================================================================
511 // Update Settings
512 //======================================================================
513 
515  emit setx("fgfs_path", true, comboFgFsPath->currentText());
516 }
517 
519  emit setx("fgroot_path", true, comboFgFsPath->currentText());
520 }
521 
523  emit setx("terrasync_exe_path", true, lineEditTerraSyncExePath->text());
524 }
525 
527  emit setx("terrasync_data_path", true, lineEditTerraSyncDataPath->text());
528 }
529 
531  emit setx("custom_scenery_path", true, lineEditCustomScenePath->text());
532 }
533 
534 
535 void CoreSettingsWidget::on_upx( QString option, bool enabled, QString value)
536 {
537  QString valueLeft(""), valueRight("");
538 
539  if(option == "--callsign="){
540  txtCallSign->setText(value);
541 
542  }else if(option == "show_mpmap"){
543  checkBoxShowMpMap->setChecked(enabled);
544  comboMpMapServer->setCurrentIndex(comboMpMapServer->findData(value));
545 
546  }else if(option == "fgfs_path"){
547  comboFgFsPath->setEditText(mainObject->X->fgfs_path());
548 
549  }else if(option == "fgroot_path"){
550  lineEditFgRootPath->setText(mainObject->X->fgroot());
551 
552  }else if (option == "terrasync_enabled") {
553  checkBoxUseTerrasync->setChecked(enabled);
555 
556  }else if (option == "custom_scenery_enabled") {
557  checkBoxUseCustomScenery->setChecked(enabled);
559 
560  }else if(option == "terrasync_exe_path"){
562 
563  }else if(option == "terrasync_data_path"){
565 
566  }else if(option == "custom_scenery_path"){
567  lineEditCustomScenePath->setText(enabled ? value : mainObject->X->custom_scenery_path());
568  }
569 }
570 
571 
572 //======================================================================
573 // Check paths and give some feedback
574 //======================================================================
575 
577 {
578  bool fgfs_exists = QFile::exists(comboFgFsPath->currentText());
579  if (fgfs_exists) {
580  labelFgfsCheck->setPixmap(QPixmap(":/icon/ok"));
581  } else {
582  labelFgfsCheck->setPixmap(QPixmap(":/icon/not-ok"));
583  }
584 
585 }
586 
588 {
589  // NEW: check if "version" file exists in folder.
590  // Without this file also fgfs won’t start
591  // Needs a version check later ...
592  bool fgroot_exists = QFile::exists(lineEditFgRootPath->text()+"/version");
593  if (fgroot_exists) {
594  labelFgRootCheck->setPixmap(QPixmap(":/icon/ok"));
595  fgrootcheck = true;
596  } else {
597  labelFgRootCheck->setPixmap(QPixmap(":/icon/not-ok"));
598  fgrootcheck = false;
599  }
600 
601 }
602 
604 {
605  bool terrasync_exe_exists = QFile::exists(lineEditTerraSyncExePath->text());
606  if (terrasync_exe_exists) {
607  labelTerrasyncCheck->setPixmap(QPixmap(":/icon/ok"));
608  } else {
609  labelTerrasyncCheck->setPixmap(QPixmap(":/icon/not-ok"));
610  }
611 
612 }
613 
614 
615 // Path check now NOT special case...
617 {
618  QDir dir(lineEditTerraSyncDataPath->text());
619  QString valid = ":/icon/not-ok";
620  if (dir.exists())
621  valid = ":/icon/ok";
622  labelTerrasyncDataCheck->setPixmap(QPixmap(valid));
623 }
624 
626 {
627  QDir custom_scenery_dir(lineEditCustomScenePath->text());
628  bool custom_scenery_exists = custom_scenery_dir.exists();
629  if (custom_scenery_exists) {
630  labelCustomSceneCheck->setPixmap(QPixmap(":/icon/ok"));
631  } else {
632  labelCustomSceneCheck->setPixmap(QPixmap(":/icon/not-ok"));
633  }
634 
635 }
636 
637 //======================================================================
638 // Set paths with buttons
639 //======================================================================
640 
642 
643 {
644 #ifdef USE_ALTERNATE_GETFILE
645  QString filePathFgfs = util_getFileName((QWidget *)this, tr("Select FlightGear binary (fgfs)"),
646  comboFgFsPath->text());
647 #else // !#ifdef USE_ALTERNATE_GETFILE
648  QString filePathFgfs = QFileDialog::getOpenFileName(this, tr("Select FlightGear binary (fgfs)"),
649  comboFgFsPath->currentText());
650 #endif // #ifdef USE_ALTERNATE_GETFILE y/n
651  if(filePathFgfs.length() > 0){
652  comboFgFsPath->setEditText(filePathFgfs);
653  }
654 
655  fgfs_check_path();
656 }
657 
659 
660 {
661 #ifdef USE_ALTERNATE_GETFILE
662  QString dirPathFgRoot = util_getDirName(this, tr("Select FlightGear data directory (fgdata)"),
663  lineEditFgRootPath->text());
664 #else // !#ifdef USE_ALTERNATE_GETFILE
665  QString dirPathFgRoot = QFileDialog::getExistingDirectory(this, tr("Select FlightGear data directory (fgdata)"),
666  lineEditFgRootPath->text(), QFileDialog::ShowDirsOnly);
667 #endif // #ifdef USE_ALTERNATE_GETFILE y/n
668 
669  if(dirPathFgRoot.length() > 0){
670  lineEditFgRootPath->setText(dirPathFgRoot);
671  }
673  if (fgrootcheck == true) {
674  reload_lists();
675  }
676 }
677 
679 {
680  QString title = tr("Select Terrasync binary (terrasync)");
681  QString previous = lineEditTerraSyncExePath->text(); // get current
682  if (previous.length() == 0) { // try harder to help user
683  previous = comboFgFsPath->currentText(); // if they have already set 'fgfs'
684  previous = util_getBasePath(previous);
685  previous.append("terrasync"); // add default exe name
686 #ifdef Q_OS_WIN
687  previous.append(".exe"); // add windows extension
688 #endif
689  }
690 #ifdef USE_ALTERNATE_GETFILE
691  QString filePathTerrasync = util_getFileName((QWidget *)this, title, previous);
692 #else // !#ifdef USE_ALTERNATE_GETFILE
693  QString filePathTerrasync = QFileDialog::getOpenFileName(this, title, previous);
694 #endif // #ifdef USE_ALTERNATE_GETFILE y/n
695 
696  if(filePathTerrasync.length() > 0){
697  lineEditTerraSyncExePath->setText(filePathTerrasync);
698  }
699 
701 }
702 
704 
705 {
706 #ifdef USE_ALTERNATE_GETFILE
707  QString dirPathTerrasyncData = util_getDirName(this, tr("Select Terrasync data directory"),
708  lineEditTerraSyncDataPath->text());
709 #else // !#ifdef USE_ALTERNATE_GETFILE
710  QString dirPathTerrasyncData = QFileDialog::getExistingDirectory(this, tr("Select Terrasync data directory"),
711  lineEditTerraSyncDataPath->text(), QFileDialog::ShowDirsOnly);
712 #endif // #ifdef USE_ALTERNATE_GETFILE y/n
713 
714  if(dirPathTerrasyncData.length() > 0){
715  lineEditTerraSyncDataPath->setText(dirPathTerrasyncData);
716  }
718 }
719 
721 
722 {
723 #ifdef USE_ALTERNATE_GETFILE
724  QString dirPathCustomScenery = util_getDirName(this, tr("Select custom scenery data directory"),
725  lineEditCustomScenePath->text());
726 #else // !#ifdef USE_ALTERNATE_GETFILE
727  QString dirPathCustomScenery = QFileDialog::getExistingDirectory(this, tr("Select custom scenery data directory"),
728  lineEditCustomScenePath->text(), QFileDialog::ShowDirsOnly);
729 #endif // #ifdef USE_ALTERNATE_GETFILE y/n
730 
731  if(dirPathCustomScenery.length() > 0){
732  if (lineEditCustomScenePath->text() > 0) {
733  QString currentPaths = lineEditCustomScenePath->text().append(":");
734  lineEditCustomScenePath->setText(currentPaths.append(dirPathCustomScenery));
735  }
736  else {
737  lineEditCustomScenePath->setText(dirPathCustomScenery);
738  }
739  }
741 }
742 
743 
744 // Reloading aircraft and airport lists
745 // needed from setting new fgdata path and from clicking reset button on launcherWindow
746 
750  // and get the airport names, and potentially start apt.dat thread load...
752 }
753 
754 // RandInt for choosing an image
755 int CoreSettingsWidget::randInt(int low, int high)
756 {
757  // Random number between low and high
758  return qrand() % ((high + 1) - low) + low;
759 }
760 
761 /** Detects possible paths for fgfs
762  * @todo Add Windows and OSX paths
763 */
765 
766  QString which;
767  QStringList lst;
768  if(this->mainObject->runningOs() == OS_LINUX){
769  //= LINUX
770  lst.append("/usr/bin/fgfs");
771  lst.append("/usr/local/bin/fgfs");
772 
773  which = this->which_fgfs();
774  if(which != "" && lst.indexOf(which) == -1){
775  lst.append(which);
776  }
777  }
778  if(this->mainObject->runningOs() == OS_WINDOWS){
779  // @TODO add predictable paths
780 
781  }
782 
783  lst.sort();
784 
785 
786  for(int i = 0; i < lst.size(); i++){
787 
788  //= get path and check it exists
789  QString path = lst.at(i);
790  QFileInfo info(path);
791  bool exists = false;
792  if(info.exists() && info.isFile()){
793  exists = true;
794  }
795 
796  //= add to combo
797  int idx = comboFgFsPath->findText(path, Qt::MatchExactly); // maybe we need case insensitive ??
798  if(idx == -1){
799  comboFgFsPath->addItem(path);
800  }
801  idx = comboFgFsPath->findText(path, Qt::MatchExactly); // refind the new the index
802 
803  //= set color of item
804  QColor color;
805  color.setNamedColor(exists ? "green" : "red");
806  comboFgFsPath->setItemData(idx, color, Qt::ForegroundRole);
807 
808  //= if it exists, then we need to select
809  if(which != ""){
810  idx = comboFgFsPath->findText(which, Qt::MatchExactly);
811  comboFgFsPath->setEditText(comboFgFsPath->itemText(idx));
812  }
813  }
814 
815 }
816 
817 /** detects runs "which fgms" and returns result on nix */
819 
820  QString command = "which fgfs";
821 
822  QProcess *process = new QProcess(this);
823  process->start(command);
824 
825  if(process->waitForStarted()){
826 
827  process->waitForFinished();
828  QByteArray result = process->readAllStandardOutput();
829  //QByteArray errorResult = process->readAllStandardError();
830  QString exe = QString(result).trimmed();
831 
832  if(exe.length() == 0){
833 
834  }else{
835  return exe;
836  }
837  }
838  return QString("");
839 }
void set_option(QString option, bool enabled, QString value)
A QGroupBox with a QVBoxLyout layout.
Definition: xgroupboxes.h:19
QCheckBox * checkBoxShowMpMap
void on_terrasync_data_path(QString)
void setx(QString option, bool enabled, QString value)
QToolButton * buttonSetCustomSceneryPath
void on_callsign_changed(QString)
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
QToolButton * buttonSetTerrasyncDataPath
AircraftWidget * aircraftWidget
static int runningOs()
What OS is running.
Definition: mainobject.cpp:367
void add_fgfs_paths()
Detects possible paths for fgfs.
QComboBox * comboMpMapServer
void on_terrasync_path(QString)
QString which_fgfs()
detects runs "which fgms" and returns result on nix
QLineEdit * lineEditCustomScenePath
CoreSettingsWidget(MainObject *mOb, QWidget *parent=0)
int randInt(int low, int high)
void addWidget(QWidget *w)
Definition: xgroupboxes.cpp:21
void on_upx(QString option, bool enabled, QString value)
QStringList get_fgfs_env()
QToolButton * buttonSetFgfsPath
XSettingsModel * X
Definition: mainobject.h:86
QString fgfs_path()
Path to fgfs executable.
QToolButton * buttonSetTerrasyncExePath
LauncherWindow * launcherWindow
Definition: mainobject.h:89
QLabel * labelTerrasyncDataCheck
AirportsWidget * airportsWidget
QToolButton * buttonSetFgRootPath
void on_fgroot_path(QString)
QString terrasync_exe_path()
Path to terrasync executable.
QString terrasync_data_path()
Path to terrasync executable.
void on_custom_scenery_path(QString)
void on_upx(QString option, bool enabled, QString value)
QString custom_scenery_path()
QLineEdit * lineEditTerraSyncExePath
QLineEdit * lineEditTerraSyncDataPath
void addLayout(QBoxLayout *lay)
Definition: xgroupboxes.cpp:27
QCheckBox * checkBoxUseCustomScenery
QString getx(QString option)
QLineEdit * lineEditFgRootPath
QCheckBox * checkBoxUseTerrasync