Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
xsettingsmodel.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // xsettingsmodel.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 <QDebug>
11 #include <QDesktopServices>
12 #include <QFile>
13 #include <QDir>
14 #include <QFileDialog>
15 
17 #include "utilities/utilities.h"
18 
19 
20 /*! \class XSettingsModel
21  * \brief The XSettingsModel is an extended QStandardItemModel, and the main "setting and state" for FGx
22  *
23  *
24  * @authors: Peter Morgan
25  */
26 
27 
28 
30  QStandardItemModel(parent)
31 {
32  mainObject = mob;
33 
34  _loading = false;
35 
36  setColumnCount(7);
37 
38  QStringList headers;
39  headers << "Option" << "Ena" << "Val" << "Default" << "Level" << "Description" << "Class";
40  setHorizontalHeaderLabels(headers);
41 
42 
43 
44  //=================================================================================
45  // This list will be the main issue and debates for a long time probably, said pete
46  //=================================================================================
47 
48 
49  //==================
50  add_option("profile", false, "", "", 0, "", "profiles");
51 
52  //==================
53  add_option("fgfs_path", false,"","",0,"","paths");
54  add_option("fgroot_path", false,"","",0,"","paths");
55  add_option("terrasync_enabled", false,"","",0,"","paths");
56  add_option("terrasync_exe_path", false,"","",0,"","paths");
57  add_option("terrasync_data_path", false,"","",0,"","paths");
58  add_option("custom_scenery_enabled", false,"","",0,"","paths");
59  add_option("custom_scenery_path", false,"","",0,"","paths");
60  add_option("fgcom_exe_path", false, "", "", 0, "", "paths");
61  add_option("jsdemo_enabled", false, "", "", 0, "", "paths");
62  add_option("jsdemo_exe_path", false, "", "", 0, "", "paths");
63 
64 
65 
66  add_option("extra_args", false,"","",0,"","expert");
67  add_option("extra_env", false,"","",0,"","expert");
68 
69  add_option("runtime", false,"","",0,"","expert");
70  add_option("--log-level=", false,"","",0,"","expert");
71 
72  add_option("first_launcher_close", false, "", "", 0, "Check for launcher window close", "Launcher Window");
73 
74  // Coordinates
75  add_option( "use_coordinates",false, "", "",3,"","Coordinates");
76  add_option( "--vor=",false, "", "",3,"","Coordinates");
77  add_option( "--ndb=",false, "", "",3,"","Coordinates");
78  add_option( "--fix=",false, "", "",3,"","Coordinates");
79  add_option( "--lat=",false, "", "",3,"","Coordinates");
80  add_option( "--lon=",false, "", "",3,"","Coordinates");
81  add_option( "--offset-distance=",false, "", "",3,"","Coordinates");
82  add_option( "--altitude=",false, "", "",3,"","Coordinates");
83  add_option( "--heading=",false, "", "",3,"","Coordinates");
84 
85  //==
86 
87  add_option( "show_mpmap", false, "", "",10,"Follow in MpMap","Map");
88 
89  add_option( "--enable-auto-coordination",false, "", "",10,"Enabled Rudder and Airelon","Control");
90 
91  add_option( "--callsign=", true,"CALLSIG", "", 1 ,"Your Callsign","Core");
92 
93  //= Season
94  add_option("--season=", false,"","summer",1,"Season", "time");
95 
96  //= Time
97  add_option("--timeofday=", false,"","realtime",1,"Time of day", "time");
98 
99  //= Weather
100  add_option("weather", true, "","none",2,"Weather Flag","weather");
101  add_option("--enable-real-weather-fetch", false, "","",1,"Enable Real Weather","weather");
102  add_option("--disable-real-weather-fetch", false, "","",1,"Disable Real Weather","weather");
103  add_option("--metar=", false,"","",1,"","weather");
104 
105  //= Rendering
106  add_option( "--prop:/sim/rendering/multi-sample-buffers=",false, "", "",1,"","Rendering");
107  add_option( "--prop:/sim/rendering/multi-samples=",false, "", "",1,"","Rendering");
108 
109  add_option( "--prop:/sim/rendering/shaders/quality-level-internal=",true, "", "3",1,"","Rendering");
110 
111  add_option( "--prop:/sim/rendering/shaders/skydome=",false, "", "", 1, "", "Rendering");
112 
113  add_option( "--prop:/sim/rendering/rembrandt/enabled=",true, "", "0",1,"","Rendering");
114  add_option( "--prop:/sim/rendering/shadows/map-size=",true, "", "4096",1,"","Rendering");
115  add_option( "--prop:/sim/rendering/shadows/num-cascades=",true, "", "4",1,"","Rendering");
116 
117  add_option( "--materials-file=",false, "", "", 1, "", "Rendering");
118 
119  add_option( "--prop:/sim/rendering/clouds3d-enable=",true, "", "",1,"","Rendering");
120  add_option( "--prop:/sim/rendering/clouds3d-vis-range=",true, "", "10000",1,"","Rendering");
121  add_option( "--prop:/sim/rendering/clouds3d-density=",true, "", "0.25",1,"","Rendering");
122 
123  add_option("--geometry=", false, "", "", 1, "Screen Size","");
124  add_option( "--enable-fullscreen",false, "", "", 1 ,"Enable Full Screen at Startup","Startup");
125  add_option( "--disable-splash-screen", false, "", "", 1 ,"Enable Splash Screen at Startup","Startup");
126  add_option( "--prop:/sim/menubar/native=",false, "", "", 1, "OSX switch for native/pui menubar", "Rendering");
127 
128 
129 
130  //= MultiPlayer
131  add_option( "--multiplay=in", false,"", ",10,localhost,20",2,"Multiplayer In","MultiPlayer");
132  add_option( "--multiplay=out", false, "", ",10,localhost,20",2,"Multiplayer In","MultiPlayer");
133 
134  //= FGCom Related
135  add_option( "fgcom_server",false, "", "fgcom.flightgear.org.uk:16661",3,"FgCom","FgCom");
136  add_option( "fgcom_enabled", false, "", "",10,"FgCom Socket","FgCom");
137 
138  //= Local Servers
139  add_option( "--telnet=",false, "", "",3,"Enable Telnet","servers");
140  add_option( "--httpd=",false, "", "",3,"Enable Httpd","servers");
141  add_option( "--jpg-httpd=",false, "", "",3,"Enable Screenshot","servers");
142 
143  //-- Radio
144  add_option( "--nav1=",false, "", "",3,"","Radio");
145  add_option( "--nav2=",false, "", "",3,"","Radio");
146  add_option( "--adf1=",false, "", "",3,"","Radio");
147  add_option( "--adf2=",false, "", "",3,"","Radio");
148  add_option( "--com1=",false, "", "",3,"","Radio");
149  add_option( "--com2=",false, "", "",3,"","Radio");
150 
151  //== Aircraft
152  add_option( "--aircraft=", false,"", "", 1 ,"Aircraft","Aircraft");
153  add_option( "--fg-aircraft=", false,"", "", 1 ,"Custom Aircraft Folder","Aircraft");
154  add_option( "custom_hangar_enabled",false, "", "",1,"Custom Hangar Checked","Aircraft");
155 
156  //-- Fuel
157  //add_option( "use_default_fuel",true,"","",3,"","Aircraft");
158  add_option( "--enable-fuel-freeze",false,"","",3,"","Aircraft");
159  add_option( "--prop:/consumables/fuels/tank[1]/level-gal=",false, "", "",9,"","Fuel");
160  add_option( "--prop:/consumables/fuels/tank[2]/level-gal=",false, "", "",9,"","Fuel");
161  add_option( "--prop:/consumables/fuels/tank[3]/level-gal=",false, "", "",9,"","Fuel");
162 
163  //= Airport Tab
164  add_option( "start_postition", true, "","0",0,"Start Location", "Airport");
165  add_option( "--airport=", false,"", "", 1 ,"Airport","Airport");
166  add_option( "--runway=", false,"", "", 1 ,"Runway","Airport");
167  add_option( "--parking-id=", false,"", "", 1 ,"Parking","Airport");
168  add_option("runway_stand", false, "", "",1,"Flag to whether runway or stand", "Airport" );
169 
170 
171 
172 }
173 
174 
175 
176 //==================================================
177 // == Add an Option
178 void XSettingsModel::add_option( QString option, bool enabled, QString value, QString preset, int level, QString description, QString area)
179 {
180  Q_UNUSED(value); //= Uses preset intead
181  QList<QStandardItem *>items;
182  items << new QStandardItem(option)
183  << new QStandardItem(enabled ? "1" : "0")
184  << new QStandardItem(preset)
185  << new QStandardItem(preset)
186  << new QStandardItem(QString::number(level))
187  << new QStandardItem(description)
188  << new QStandardItem(area);
189  appendRow(items);
190 
191 }
192 
193 
194 
195 //==================================================
196 // == Set An Option
197 void XSettingsModel::set_option(QString option, bool enabled, QString value)
198 {
199  //qDebug() << "set " << option << _loading;
200  if(_loading){
201  return;
202  }
203  //= Find item matching the "option"
204  QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
205  //qDebug() << "opts" << items;
206 
207  //TODO handle error if not found
208  if (items.size() == 0) {
209  outLog("set_option:setx called with INVALID option ["+option+"]");
210  return;
211  }
212 
213  //= Get/update the "enabled" item in the same row
214  QStandardItem *eItem = item(items[0]->row(),C_ENABLED);
215  eItem->setText(enabled ? "1" : "0");
216 
217 
218  //= Get/update the "value" item in the same row
219  QStandardItem *vItem = item(items[0]->row(),C_VALUE);
220  vItem->setText(value);
221 
222  set_row_bg(items[0]->row(), enabled ? QColor(200,255,200) : QColor(240,240,240));
223 
224  //= Announce the change
225  //emit upx(option, enabled, value);
226  emit updated(get_fgfs_list());
227 }
228 
229 //==================================================
230 // == Set An Option Enabled or Disabled
231 void XSettingsModel::set_enabled(QString option, bool enabled)
232 {
233  //qDebug() << "set " << option << _loading;
234  if(_loading){
235  return;
236  }
237  //= Find item matching the "option"
238  QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
239  //qDebug() << "opts" << items;
240 
241  //TODO handle error if not found
242 
243  //= Get/update the "enabled" item in the same row
244  QStandardItem *eItem = item(items[0]->row(),C_ENABLED);
245  eItem->setText(enabled ? "1" : "0");
246 
247  set_row_bg(items[0]->row(), enabled ? QColor(200,255,200) : QColor(240,240,240));
248 
249  QStandardItem *vItem = item(items[0]->row(),C_VALUE);
250 
251  emit upx(option, enabled, vItem->text());
252  emit updated(get_fgfs_list());
253 }
254 
255 //==================================================
256 // == Set An Option's Value
257 void XSettingsModel::set_value(QString option, QString value)
258 {
259  //qDebug() << "set " << option << _loading;
260  if(_loading){
261  return;
262  }
263  //= Find item matching the "option"
264  QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
265  //qDebug() << "opts" << items;
266 
267  //TODO handle error if not found
268 
269  //= Get/update the "enabled" item in the same row
270  QStandardItem *vItem = item(items[0]->row(),C_VALUE);
271  vItem->setText(value);
272 
273  QStandardItem *eItem = item(items[0]->row(),C_ENABLED);
274 
275 
276 
277  emit upx(option, eItem->text() == "1", value);
278  emit updated(get_fgfs_list());
279 }
280 
281 
282 
283 QModelIndex XSettingsModel::get_index(QString option)
284 {
285  QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
286  return indexFromItem(items[0]);
287 }
288 
289 //==================================================
290 // == Get Option
291 //==================================================
292 QString XSettingsModel::getx(QString option)
293 {
294  QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
295 
296  // Get the item in the same row in the enabled field
297  QStandardItem *xItem = item(items[0]->row(),C_VALUE);
298  return xItem->text();
299 
300 }
301 
302 QString XSettingsModel::getx(QString option, bool return_default)
303 {
304  //=PETE - I dont think this is being used...
305  Q_UNUSED(return_default);
306  XOpt opt = get_opt(option);
307  if(opt.value.length() == 0){
308  return opt.default_value;
309  }
310  return opt.value;
311 }
312 
313 QString XSettingsModel::getx(QString option, QString default_string)
314 {
315  QString v = getx(option);
316  if(v.length() == 0){
317  return default_string;
318  }
319  return v;
320 
321 }
322 
323 //==================================================
324 // == Get Option enabled
325 bool XSettingsModel::get_ena(QString option)
326 {
327  QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
328 
329  // Get the item in the same row in the enabled field
330  QStandardItem *xItem = item(items[0]->row(),C_ENABLED);
331  return xItem->text() == "1";
332 
333 }
334 
336 {
337  QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
338  return XOpt(item(items[0]->row(), C_OPTION)->text(),
339  item(items[0]->row(), C_ENABLED)->text() == "1",
340  item(items[0]->row(), C_VALUE)->text(),
341  item(items[0]->row(), C_DEFAULT)->text()
342  );
343 }
344 
345 
346 //==================================================
347 // == Read Default Ini File: First Startup and Reset
348 /** \brief Read Values from ini
349  */
350 
352 {
353  QString defaultSettings("");
354  switch (mainObject->runningOs()) {
355  case OS_MAC:
356  defaultSettings = ":/default/osx_default.ini";
357  break;
358  case OS_WINDOWS:
359  defaultSettings = ":/default/win_default.ini";
360  break;
361  case OS_LINUX:
362  defaultSettings = ":/default/x_default.ini";
363  break;
364  default:
365  outLog("*** FGx shout: No default settings for this system");
366  break;
367  }
368 
369  QSettings settings(defaultSettings,QSettings::IniFormat);
370 
371  bool ena;
372  for(int row_idx=0; row_idx < rowCount(); row_idx++){
373  //= loop rows and load each "option" as an [ini section] with enabled, value as values
374  settings.beginGroup(item(row_idx, C_OPTION)->text());
375  ena = settings.value("enabled").toBool() ;
376  item(row_idx, C_ENABLED)->setText( ena ? "1" : "0");
377  QString val = settings.value("value").toString();
378  if(val == ""){
379  val = item(row_idx, C_DEFAULT)->text();
380  }
381  item(row_idx, C_VALUE)->setText(val );
382  set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240));
383  //= Broadcast changes
384  emit upx(item(row_idx, C_OPTION)->text(),
385  item(row_idx, C_ENABLED)->text() == "1",
386  item(row_idx, C_VALUE)->text()
387  );
388  settings.endGroup();
389  }
390  //qDebug() << "Read ini";
391  emit updated(get_fgfs_list());
392 
393 }
394 
395 //=============================================
396 // == Load Last Profile
397 /** \brief Opens last used profile
398  */
399 
401 {
402  _loading = true;
403 
404  QString filename = profile;
405  QSettings settings(filename,QSettings::IniFormat);
406 
407  outLog("*** FGx loading last used profile:"+filename);
408 
409  bool ena;
410  for(int row_idx=0; row_idx < rowCount(); row_idx++){
411  //= loop rows and load each "option" as an [ini section] with enabled, value as values
412  settings.beginGroup(item(row_idx, C_OPTION)->text());
413  ena = settings.value("enabled").toBool() ;
414  item(row_idx, C_ENABLED)->setText( ena ? "1" : "0");
415  QString val = settings.value("value").toString();
416  if(val == ""){
417  val = item(row_idx, C_DEFAULT)->text();
418  }
419  item(row_idx, C_VALUE)->setText(val );
420  set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240));
421  //= Broadcast changes
422  emit upx(item(row_idx, C_OPTION)->text(),
423  item(row_idx, C_ENABLED)->text() == "1",
424  item(row_idx, C_VALUE)->text()
425  );
426  settings.endGroup();
427  }
428  _loading = false;
429  emit updated(get_fgfs_list());
430 
431 }
432 
433 //========================================
434 // == get last used Profile file name
435 //========================================
437 {
438  QString key("lastprofile");
439  QSettings lastused;
440  QString previous = lastused.value(key,
441  "NewProfile.ini").toString();
442  return previous;
443 }
444 
445 //========================================
446 // == set last used Profile file name
447 //========================================
448 void XSettingsModel::setLastUsed(QString previous)
449 {
450  QString key("lastprofile");
451  QSettings lastused;
452  lastused.setValue(key,previous);
453 }
454 
455 //=============================================
456 // == Load Profile
457 /** \brief Opens Profile Dialog for loading a .ini File
458  */
459 
461 {
462  _loading = true;
463  // get lastused profile name
464  QString previous = getLastUsed(); // or default if none
465 
466 #ifdef USE_ALTERNATE_GETFILE
467  QString filename = util_getFileName(0, "Load Profiles", previous, QStringList("*.ini") );
468 #else // !#ifdef USE_ALTERNATE_GETFILE
469  QString filename = QFileDialog::getOpenFileName(0, "Load Profiles", previous, "Profile files (*.ini)" );
470 #endif // #ifdef USE_ALTERNATE_GETFILE y/n
471 
472  QFile file;
473  if ((filename.length() == 0) || (!file.exists(filename))) {
474  outLog("*** Profile load abandonned!");
475  _loading = false;
476  return false; // NO LOAD POSSIBLE
477  }
478 
479  QSettings settings(filename,QSettings::IniFormat);
480 
481  bool ena;
482  for(int row_idx=0; row_idx < rowCount(); row_idx++){
483  //= loop rows and load each "option" as an [ini section] with enabled, value as values
484  settings.beginGroup(item(row_idx, C_OPTION)->text());
485  ena = settings.value("enabled").toBool() ;
486  item(row_idx, C_ENABLED)->setText( ena ? "1" : "0");
487  QString val = settings.value("value").toString();
488  if(val == ""){
489  val = item(row_idx, C_DEFAULT)->text();
490  }
491  item(row_idx, C_VALUE)->setText(val );
492  set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240));
493  //= Broadcast changes
494  emit upx(item(row_idx, C_OPTION)->text(),
495  item(row_idx, C_ENABLED)->text() == "1",
496  item(row_idx, C_VALUE)->text()
497  );
498  settings.endGroup();
499  }
500  emit updated(get_fgfs_list());
501  outLog("*** Profile loaded: "+filename);
502 
503  setLastUsed(filename); // store lastused profile name
504  return true;
505 
506 }
507 
508 //=============================================
509 // == Save Profile
510 /** \brief Opens Profile Dialog for loading a .ini File
511  */
512 
514 {
515  // get lastused profile name
516  QString previous = getLastUsed(); // or default if none
517 
518 #ifdef USE_ALTERNATE_GETFILE
519  QString filename = util_getFileName(0, "Save Profiles", previous, QStringList("*.ini"));
520 #else // !#ifdef USE_ALTERNATE_GETFILE
521  QString filename = QFileDialog::getSaveFileName(0, "Save Profiles", previous, "Profile files (*.ini)" );
522 #endif // #ifdef USE_ALTERNATE_GETFILE y/n
523 
524  if (filename.length() == 0) {
525  outLog("*** Profile write abandoneed");
526  return false;
527  }
528 
529  QSettings settings(filename,QSettings::IniFormat);
530 
531  // selected profile filename will be stored in settings
532  set_option("profile", true, filename);
533 
534  setLastUsed(filename);
535 
536  //= loop rows and save each "option" as an [ini section] with enabled, value as values
537  for(int row_idx=0; row_idx < rowCount(); row_idx++){
538  settings.beginGroup(item(row_idx, C_OPTION)->text());
539  settings.setValue( "enabled", item(row_idx, C_ENABLED)->text());
540  settings.setValue( "value", item(row_idx, C_VALUE)->text());
541  settings.endGroup();
542  }
543 
544  outLog("*** Profile written to disk: "+filename);
545  return true;
546 }
547 
548 
549 //==========================================================
550 //= Get Options
551 //==========================================================
553 {
554  //= Read --options from tree
555  QStringList args;
556  QString str("");
557 
558  for(int row_idx=0; row_idx < rowCount(); row_idx++){
559 
560  if(item(row_idx, C_ENABLED)->text() == "1"){
561  QString op = item(row_idx, C_OPTION)->text();
562  QString opval = item(row_idx, C_VALUE)->text();
563  str = "";
564  if(op.startsWith("--")){
565  if(op == "--geometry=" && opval == "0x0" ){
566  // skip geometry if empty 0 vals
567  } else {
568  str.append(item(row_idx, C_OPTION)->text()).append(opval);
569  }
570  }
571  if(str.length() > 0){
572  if (str.indexOf(QChar(' ')) > 0) {
573  str = "\""+str+"\""; // encase in QUOTE if it contains a SPACE char
574  }
575  args << str;
576  }
577  }
578  }
579 
580  // Process unique items, like fgcom socket
581  if(fgcom_enabled()){
582  // This option needs an overhaul once. Server and port separated. It is never needed
583  // as server:port for fgfs or fgcom. It’s just splitted everywhere ...
584  // For the fgfs command line option we only need the port, for starting fgcom
585  // we need the server and the port, but this can come to separated setting values (?)
586  // Anyway ... took an age this one.
587  QString serverandport(getx("fgcom_server"));
588  QString portonly(serverandport.split(":").at(1));
589  args << QString("--generic=socket,out,10,localhost,%1,udp,fgcom").arg(portonly);
590  }
591 
592  //txtFgComPort->setText( value.split(":").at(1));
593 
594  //= add Extra args
595  XOpt opt = get_opt("extra_args");
596  if (opt.enabled && (opt.value.length() > 0)) {
597  QStringList parts = opt.value.split("\n");
598  if(parts.count() > 0){
599  for(int i=0; i < parts.count(); i++){
600  QString part = parts.at(i).trimmed();
601  if(part.length() > 0){
602  args << part;
603  }
604  }
605  }
606  }
607 
608  //== FgRoot
609  str = fgroot();
610  if (str.length() > 0) {
611  // only ADDED if we have a FGROOT
612  // Maybe the user sets FG_ROOT in the environment, so do NOT need any here
613  str = "--fg-root="+str;
614  if (str.indexOf(QChar(' ')) > 0) {
615  str = "\""+str+"\""; // encase in QUOTE if it contains a SPACE char
616  }
617  args << str;
618  }
619 
620  //= Terrasync and custom scenery path
621  // setup the DIFFERENT path separators!!!
622  QString path_sep = ":"; // normal unix path separator
623 #ifdef Q_OS_WIN
624  path_sep = ";"; // oops, switch the WINDOWS spearator
625 #endif
626  // FIX20120410 - For Windows, and most other OSes, put paths with a SPACE in quotes
627  // TODO - should check if paths are not BLANK, and are valid paths before blithly adding them
628  // Helps no one to add BLANK or INVALID paths
630  str = "--fg-scenery=";
631  str.append(terrasync_data_path()).append(path_sep).append(scenery_path());
632  if (str.indexOf(QChar(' ')) > 0) {
633  str = "\""+str+"\""; // encase in QUOTE if it contains a SPACE char
634  }
635  args << str;
636  args << QString("--atlas=socket,out,5,localhost,5505,udp");
637  }
638 
639  else if (terrasync_enabled() && custom_scenery_enabled()) {
640  str = "--fg-scenery=";
641  str.append(custom_scenery_path()).append(path_sep).append(terrasync_data_path()).append(path_sep).append(scenery_path());
642  if (str.indexOf(QChar(' ')) > 0) {
643  str = "\""+str+"\""; // encase in QUOTE if it contains a SPACE char
644  }
645  args << str;
646  args << QString("--atlas=socket,out,5,localhost,5505,udp");
647  }
648 
649  else if (!terrasync_enabled() && custom_scenery_enabled()) {
650  str = "--fg-scenery=";
651  str.append(custom_scenery_path()).append(path_sep).append(scenery_path());
652  if (str.indexOf(QChar(' ')) > 0) {
653  str = "\""+str+"\""; // encase in QUOTE if it contains a SPACE char
654  }
655  args << str;
656  }
657 
658  else if (!terrasync_enabled() && !custom_scenery_enabled()) {
659  str = "--fg-scenery=";
660  str.append(scenery_path());
661  if (str.indexOf(QChar(' ')) > 0) {
662  str = "\""+str+"\""; // encase in QUOTE if it contains a SPACE char
663  }
664  args << str;
665  }
666 
667  return args;
668 }
669 
670 
672 {
673  //TODO append the commands here
674  QStringList args;
675  QString fgfs = fgfs_path();
676  if (fgfs.indexOf((QChar(' ')) > 0)) {
677  fgfs = "\""+fgfs+"\""; // Quote it if it contains a SPACE
678  }
679  args << fgfs;
680  args << get_fgfs_args();
681  return args;
682 }
683 
685 {
686  QString fgfs = fgfs_path();
687  QFile file(fgfs);
688  if (file.exists()) {
689  outLog("XSettingsModel::get_fgfs_command_string: Found valid file ["+fgfs+"]");
690  } else {
691  outLog("XSettingsModel::get_fgfs_command_string: File ["+fgfs+"] NOT valid!");
692  }
693  if (fgfs.indexOf((QChar(' ')) > 0)) {
694  fgfs = "\""+fgfs+"\""; // quote it if it contains a SPACE
695  }
696  fgfs.append(" ");
697  fgfs.append( get_fgfs_args().join(" ") );
698  return fgfs;
699 }
700 
701 
702 //========================================================
703 //** Get Enviroment
704 
706 
707  QStringList args;
708  if (!mainObject->X->get_ena("extra_env")) {
709  return args;
710  }
711  QString extra = getx("extra_env");
712  if (extra.length() > 0) {
713  QStringList parts = extra.split("\n");
714  if(parts.count() > 0){
715  for(int i=0; i < parts.count(); i++){
716  QString part = parts.at(i).trimmed();
717  if(part.length() > 0){
718  args << part;
719  }
720  }
721  }
722  }
723  return args;
724 }
725 
726 //===========================================================================
727 //== Get recent profile
728 //===========================================================================
729 /** \brief Path to fgfs executable
730  */
732  return QString(getx("profile"));
733 
734 }
735 
736 
737 //===========================================================================
738 //== fgfs Executable
739 //===========================================================================
740 /** \brief Path to fgfs executable
741  */
743  QSettings firstsettings;
744 
745  if(!firstsettings.value("firststartup").toBool()){
746  // OSX: prepending current app path for firststartup
747  if(mainObject->runningOs() == OS_MAC) {
748  return QDir::currentPath().append("/").append(getx("fgfs_path"));
749  }else {
750  return QString(getx("fgfs_path"));
751  }
752  // Not firststartup
753  }else {
754  return QString(getx("fgfs_path"));
755  }
756 
757 
758 }
759 
760 //===========================================================================
761 //== terrasync enabled/disabled
762 //===========================================================================
763 /** \brief Sert terrasync enabled/disabled
764  */
766  return get_ena("terrasync_enabled");
767 
768 }
769 
770 
771 //===========================================================================
772 //== terrasync Executable
773 //===========================================================================
774 /** \brief Path to terrasync executable
775  */
777  QSettings firstsettings;
778 
779  if(!firstsettings.value("firststartup").toBool()){
780  // OSX: prepending current app path for firststartup
781  if(mainObject->runningOs() == OS_MAC) {
782  return QDir::currentPath().append("/").append(getx("terrasync_exe_path"));
783  }else {
784  return QString(getx("terrasync_exe_path"));
785  }
786  // Not firststartup
787  }else {
788  return QString(getx("terrasync_exe_path"));
789  }
790 
791 }
792 
793 //===========================================================================
794 //== terrasync Data Path
795 //===========================================================================
796 /** \brief Path to terrasync executable
797  */
799  return QString(getx("terrasync_data_path"));
800 }
801 
802 //===========================================================================
803 //** Return FGCom enabled/disabled
804 //===========================================================================
805 
807  return get_ena("fgcom_enabled");
808 }
809 
810 
811 //===========================================================================
812 //== fgcom Executable
813 //===========================================================================
814 /** \brief Path to fgcom executable
815  */
817  QSettings firstsettings;
818 
819  if(!firstsettings.value("firststartup").toBool()){
820  // OSX: prepending current app path for firststartup
821  if(mainObject->runningOs() == OS_MAC) {
822  return QDir::currentPath().append("/").append(getx("fgcom_exe_path"));
823  }else {
824  return QString(getx("fgcom_exe_path"));
825  }
826  // Not firststartup
827  }else {
828  return QString(getx("fgcom_exe_path"));
829  }
830 
831 
832 }
833 
834 
835 //===========================================================================
836 //== js_demo path
837 //===========================================================================
838 
840  QSettings firstsettings;
841 
842  if(!firstsettings.value("firststartup").toBool()){
843  // OSX: prepending current app path for firststartup
844  if(mainObject->runningOs() == OS_MAC) {
845  return QDir::currentPath().append("/").append(getx("jsdemo_exe_path"));
846  }else {
847  return QString(getx("jsdemo_exe_path"));
848  }
849  // Not firststartup
850  }else {
851  return QString(getx("jsdemo_exe_path"));
852  }
853 
854 }
855 
856 
857 
858 //===========================================================================
859 //== fgroot path
860 //===========================================================================
861 /** \return The absolute path to FG_ROOT ie /fgdata directory */
863  QSettings firstsettings;
864 
865  if(!firstsettings.value("firststartup").toBool()){
866  // OSX: prepending current app path for firststartup
867  if(mainObject->runningOs() == OS_MAC) {
868  return QDir::currentPath().append("/").append(getx("fgroot_path"));
869  }else {
870  return QString(getx("fgroot_path"));
871  }
872  // Not firststartup
873  }else {
874  return QString(getx("fgroot_path"));
875  }
876 }
877 
878 
879 /** \brief Path to FG_ROOT with appended path
880  *
881  * Returns the path to the FG_ROOT. If the default install
882  * is selected, then that is returned, otherwise the custom selected fg_data path.
883  * The file is appended with the append_path
884  * \return The absolute path.
885  */
886 
887 QString XSettingsModel::fgroot(QString append_path){
888  return this->fgroot().append(append_path);
889 }
890 
891 //===========================================================================
892 //** Paths Sane
893 //===========================================================================
894 /** \brief Checks whether the executablem FG_ROOT paths are sane.
895  *
896  * \return true if sane
897  */
899  if(!QFile::exists(fgfs_path())){
900  return false;
901  }
902  if(!QFile::exists(fgroot())){
903  return false;
904  }
905  return true;
906 }
907 
908 
909 //===========================================================================
910 //** Aircraft Path
911 //===========================================================================
912 /** \brief The path to the /Aircraft directory
913  *
914  * \return fgroot/Aircraft absolute path --fg-aircraft path in case
915  */
917 
918  return fgroot().append("/Aircraft");
919 
920 }
921 
922 /** \brief Path to the /Aircraft directory with a dir appended.
923  *
924  * \return absolute path.
925  */
926 QString XSettingsModel::aircraft_path(QString dir){
927  return fgroot().append("/Aircraft/").append(dir);
928 }
929 
930 
931 //===========================================================================
932 //** Airports path
933 //===========================================================================
934 /** \brief Return the absolute path to the /Airports directory
935  *
936  * \return If TerraSync is enabled, then returns a terrasync folder, otherwise the default.
937  */
939  QString rpath;
940  //= Using terrasync
941  if(terrasync_enabled()){
942  //if(mainObject->runningOs() == MainObject::MAC){ // what the h. says gral to himself
943  // rpath = QDir::homePath();
944  // rpath.append("/Documents/TerrasyncScenery");
945  //}else{
946  // Use the terra sync path
947  rpath = terrasync_data_path().append("/Airports");
948  }
949 
950  else{ // Otherwise return the FG_ROOT airports/
951  rpath = fgroot().append("/Scenery/Airports");
952  }
953  //outLog("*** FGx settings: Airports path: " + rpath + " ***");
954  return rpath;
955 }
956 
957 //===========================================================================
958 //** Scenery Path - TODO x/win
959 //===========================================================================
960 /** \brief Returns the absolute path to the /Scenery file
961  *
962  * \return The absolute path.
963  */
965 
966  return fgroot("/Scenery");
967 }
968 
969 //===========================================================================
970 //** Custom scenery
971 //===========================================================================
973  return getx("custom_scenery_path");
974 }
975 
977  return get_ena("custom_scenery_enabled");
978 }
979 
980 void XSettingsModel::set_row_bg(int row_idx, QColor bg_color)
981 {
982  for(int col_idx=0; col_idx < columnCount(); col_idx++)
983  {
984  item(row_idx, col_idx)->setBackground(bg_color);
985  }
986 }
987 
988 // return a list of valid scenery directories
990 {
991  QStringList list;
992  QString path, msg;
993  QDir dir;
994  QFile file;
995  int i, ind, j;
996 #ifdef Q_OS_WIN
997  QChar psep(';');
998 #else
999  QChar psep(':');
1000 #endif
1001 
1002  // 1 - get FG_ROOT/Scenery
1003  path = fgroot("/Scenery");
1004  ind = path.indexOf(QChar('"'));
1005  if (ind == 0)
1006  path = path.mid(1,msg.length()-2);
1007  if ( !list.contains(path) ) {
1008  if (dir.exists(path)) {
1009  list += path;
1010  }
1011  }
1012  // 2 - if terrasync enabled
1013  if (terrasync_enabled()) {
1014  path = terrasync_data_path();
1015  ind = path.indexOf(QChar('"'));
1016  if (ind == 0)
1017  path = path.mid(1,msg.length()-2);
1018  if ( !list.contains(path) ) {
1019  if (dir.exists(path)) {
1020  list += path;
1021  }
1022  }
1023  }
1024  // 3 - if custom scenery enabled
1025  if (custom_scenery_enabled()) {
1026  path = custom_scenery_path();
1027  ind = path.indexOf(QChar('"'));
1028  if (ind == 0)
1029  path = path.mid(1,msg.length()-2);
1030  if ( !list.contains(path) ) {
1031  if (dir.exists(path)) {
1032  list += path;
1033  }
1034  }
1035  }
1036 
1037  // 4 - check fgfs command for any others, avoiding DUPLICATION
1038  QStringList fgfs_args = get_fgfs_args();
1039  for (i = 0; i < fgfs_args.size(); i++) {
1040  msg = fgfs_args.at(i);
1041  ind = msg.indexOf(QChar('"'));
1042  if (ind == 0)
1043  msg = msg.mid(1,msg.length()-2);
1044  if (msg.indexOf("--fg-scenery=") == 0) {
1045  msg = msg.mid(13);
1046  ind = msg.indexOf(QChar('"'));
1047  if (ind == 0)
1048  msg = msg.mid(1,msg.length()-2);
1049  QStringList path_list = msg.split(psep);
1050  for (j = 0; j < path_list.size(); j++) {
1051  path = path_list.at(j);
1052  ind = path.indexOf(QChar('"'));
1053  if (ind == 0)
1054  path = path.mid(1,msg.length()-2);
1055  if ( !list.contains(path) ) {
1056  if (dir.exists(path)) {
1057  list += path;
1058  }
1059  }
1060  }
1061  }
1062  }
1063  return list;
1064 }
1065 
void set_option(QString option, bool enabled, QString value)
QStringList getSceneryDirs()
QString default_value
Definition: xopt.h:21
QString jsdemo_exe_path()
bool paths_sane()
Checks whether the executablem FG_ROOT paths are sane.
QStringList get_fgfs_args()
QString value
Definition: xopt.h:19
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
bool load_profile()
Opens Profile Dialog for loading a .ini File.
static int runningOs()
What OS is running.
Definition: mainobject.cpp:367
QString fgcom_exe_path()
Path to fgcom executable.
QString scenery_path()
Returns the absolute path to the /Scenery file.
void add_option(QString option, bool enabled, QString value, QString preset, int level, QString description, QString area)
QString get_fgfs_command_string()
Definition: xopt.h:14
bool get_ena(QString option)
void set_enabled(QString option, bool enabled)
QString aircraft_path()
The path to the /Aircraft directory.
void load_last_profile(QString profile)
Opens last used profile.
QString profile()
Path to fgfs executable.
void set_value(QString option, QString value)
void read_default_ini()
Read Values from ini.
QStringList get_fgfs_env()
QString getLastUsed()
XSettingsModel * X
Definition: mainobject.h:86
QString fgfs_path()
Path to fgfs executable.
void upx(QString option, bool enabled, QString value)
void set_row_bg(int row_idx, QColor bgcolor)
bool save_profile()
Opens Profile Dialog for loading a .ini File.
void updated(QStringList lines)
QString airports_path()
Return the absolute path to the /Airports directory.
QStringList get_fgfs_list()
bool custom_scenery_enabled()
QModelIndex get_index(QString option)
bool terrasync_enabled()
Sert terrasync enabled/disabled.
QString terrasync_exe_path()
Path to terrasync executable.
XSettingsModel(MainObject *mob, QObject *parent=0)
QString terrasync_data_path()
Path to terrasync executable.
QString custom_scenery_path()
XOpt get_opt(QString option)
void setLastUsed(QString previous)
MainObject * mainObject
QString getx(QString option)
bool enabled
Definition: xopt.h:20