Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
confirmpage.cpp
Go to the documentation of this file.
1 
2 
3 
4 #include <QGridLayout>
5 #include <QFileDialog>
6 #include <QVBoxLayout>
7 #include <QProgressDialog>
8 
10 #include "xwidgets/xgroupboxes.h"
11 
12 
13 #include "airports/airportsdata.h"
14 #include "aircraft/aircraftdata.h"
15 
16 /*! \class ConfirmPage
17  * @author: Peter Morgan
18  * \brief The page that actually writes paths out, and reloads the cache.
19  *
20  * The validatePage() function is where the write is actually done.
21  */
22 
23 
25  QWizardPage(parent)
26 {
27 
28  mainObject = mob;
29 
30  setTitle("Finish Setup");
31  setSubTitle("Click the finish button to run");
32 
33 
34  QVBoxLayout *mainLayout = new QVBoxLayout();
35  setLayout(mainLayout);
36 
37 
38  XGroupVBox *grpFgExe = new XGroupVBox("FlightGear Executable");
39  mainLayout->addWidget(grpFgExe);
42  lblFgExePath = new QLabel();
43  grpFgExe->addWidget(lblFgExePath);
44 
45 
46 
47  XGroupVBox *grpFgRoot = new XGroupVBox("FlightGear Data");
48  mainLayout->addWidget(grpFgRoot);
50  grpFgRoot->addWidget(lblFgRootUsingDefault);
51  lblFgRootPath = new QLabel();
52  grpFgRoot->addWidget(lblFgRootPath);
53 
54 
55  //= Terrasync
56  XGroupVBox *grpTerrasync = new XGroupVBox("TerraSync");
57  mainLayout->addWidget(grpTerrasync);
58  lblUsingTerraSync = new QLabel();
59  grpTerrasync->addWidget(lblUsingTerraSync);
60  lblTerraSyncPath = new QLabel();
61  grpTerrasync->addWidget(lblTerraSyncPath);
62 
63 
64 
65  //= Import Cache Data ============
66  XGroupGBox *grpImports = new XGroupGBox("Reload cached data");
67  mainLayout->addWidget(grpImports);
68 
69  //== Aircraft ==
70  int row = 0;
71  checkBoxImportAircaft = new QCheckBox("Import Aircraft");
72  grpImports->addWidget(checkBoxImportAircaft, row, 0, 1, 2);
73  checkBoxImportAircaft->setChecked(true);
74 
75 
76  //== Airports ==
77  row++;
78  checkBoxImportAirports = new QCheckBox("Import Airports");
79  grpImports->addWidget(checkBoxImportAirports, row, 0, 1, 2);
80  checkBoxImportAirports->setChecked(true);
81  connect(checkBoxImportAirports, SIGNAL(clicked()), this, SLOT(on_import_airports()));
82 
83  //= IACO Only
84  row++;
85  radioIcaoOnly = new QRadioButton();
86  grpImports->addWidget(radioIcaoOnly, row, 1, 1, 1);
87  radioIcaoOnly->setText("Import major airports only");
88  radioIcaoOnly->setChecked(true);
89 
90  //= All Airports
91  row++;
92  radioAllAirports = new QRadioButton();
93  grpImports->addWidget(radioAllAirports, row, 1, 1, 1);
94  radioAllAirports->setText("Import all airports, seaports, heliports");
95 
96  grpImports->gridLayout->setColumnStretch(0, 1);
97  grpImports->gridLayout->setColumnStretch(1, 10);
98 
99  connect(this, SIGNAL(setx(QString,bool,QString)), mainObject->X, SLOT(set_option(QString,bool,QString)) );
100  connect(mainObject->X, SIGNAL(on_upx(QString,bool,QString)), this, SLOT(on_upx(QString,bool,QString)));
101 
102 }
103 
104 
106  radioIcaoOnly->setEnabled(checkBoxImportAirports->isChecked());
107  radioAllAirports->setEnabled(checkBoxImportAirports->isChecked());
108 }
109 
110 //===================================================
111 //= initializePage
113 {
114 
115  if(field("fgfs_use_default").toBool()){
116  lblFgExeUsingDefault->setText("Using Default Path");
117  lblFgExePath->setText(mainObject->X->fgfs_default_path());
118  }else{
119  lblFgExeUsingDefault->setText("Using Custom Path");
120  lblFgExePath->setText(field("fgfs_custom_path").toString());
121  }
122 
123  if(field("fgroot_use_default").toBool()){
124  lblFgRootUsingDefault->setText("Using Default Data Path");
125  lblFgRootPath->setText(mainObject->X->fgroot_default_path());
126  }else{
127  lblFgRootUsingDefault->setText("Using Custom Data Path");
128  lblFgRootPath->setText(field("fgroot_custom_path").toString());
129  }
130 
131  if(field("terrasync_enabled").toBool()){
132  lblUsingTerraSync->setText("Using Terrasync");
133  lblTerraSyncPath->setText(field("terrasync_path").toString());
134  }else{
135  lblUsingTerraSync->setText("No Terrasync");
136  lblTerraSyncPath->setText("");
137  }
138 
139  //= Check is an airport update is required ie fg root has changed
140  bool airports_update = false;
141  if(field("fgroot_use_default").toBool() != mainObject->X->fgroot_use_default()){
142  // not the same as last time
143  airports_update = true;
144 
145  }else if(field("fgfs_use_default").toBool() &&
146  field("fgroot_custom_path").toString() != mainObject->X->getx("fgroot_custom_path")){
147  // custom path has changed
148  airports_update = true;
149  }
150  checkBoxImportAirports->setText(airports_update ? "Import Airports - recommended" : "Import Airports");
151  checkBoxImportAirports->setChecked(airports_update);
152 
153  //= Check is an aircraft update is required ie fgdata changed
154  bool aircraft_update = false;
155  if(field("terrasync_enabled").toBool() != mainObject->X->terrasync_enabled()){
156  // not the same as last time
157  aircraft_update = true;
158 
159  }else if(field("terrasync_enabled").toBool() &&
160  field("terrasync_path").toString() != mainObject->X->terrasync_sync_data_path()){
161  // terrasync path changed
162  aircraft_update = true;
163  }
164  checkBoxImportAircaft->setText(aircraft_update ? "Import Aircraft - recommended" : "Import Aircraft");
165  checkBoxImportAircaft->setChecked(aircraft_update);
166 
167  radioIcaoOnly->setChecked(mainObject->settings->value("last_import_icao_checked", "1").toBool());
169  return;
170 }
171 
172 
173 //===================================================
174 //= validate - and Write out main settings
176 {
177 
178  emit setx("fgfs_custom_path", field("fgfs_use_custom").toBool(), field("fgfs_custom_path").toString());
179 
180  emit setx("fgroot_custom_path", field("fgroot_use_custom").toBool(), field("fgroot_custom_path").toString());
181 
182  //emit setx("terrasync_enabled", field("terrasync_enabled").toBool(), "");
183  emit setx("terrasync_path", field("terrasync_enabled").toBool() == true, field("terrasync_path").toString());
184 
185  mainObject->settings->setValue("last_import_icao_checked", radioIcaoOnly->isChecked());
186 
187  mainObject->settings->sync();
188 
189  QProgressDialog progress(this);
190  progress.setFixedWidth(400);
191  progress.setWindowIcon(QIcon(":/icon/import"));
192 
193  bool cancelled = false;
194  if(checkBoxImportAirports->isChecked()){
195  cancelled = AirportsData::import(progress, mainObject, radioIcaoOnly->isChecked());
196  }
197  if(cancelled){
198  return false;
199  }
200  if(cancelled == false && checkBoxImportAircaft->isChecked()){
201  AircraftData::import(progress, mainObject);
202  }
203  mainObject->X->write_ini();
204 
205  return true;
206 }
207 
A QGroupBox with a QVBoxLyout layout.
Definition: xgroupboxes.h:19
QCheckBox * checkBoxImportAircaft
Definition: confirmpage.h:38
QRadioButton * radioAllAirports
Definition: confirmpage.h:36
QCheckBox * checkBoxImportAirports
Definition: confirmpage.h:34
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
bool validatePage()
ConfirmPage(MainObject *mob, QWidget *parent=0)
Definition: confirmpage.cpp:24
QLabel * lblUsingTerraSync
Definition: confirmpage.h:31
QLabel * lblFgRootPath
Definition: confirmpage.h:29
void initializePage()
bool fgroot_use_default()
QLabel * lblFgExeUsingDefault
Definition: confirmpage.h:25
A QGroupBox with a QGridLayout layout.
Definition: xgroupboxes.h:59
static bool import(QProgressDialog &progress, MainObject *mainObject)
QRadioButton * radioIcaoOnly
Definition: confirmpage.h:35
void setx(QString option, bool enabled, QString value)
QGridLayout * gridLayout
Definition: xgroupboxes.h:65
QLabel * lblTerraSyncPath
Definition: confirmpage.h:32
void addWidget(QWidget *w, int row, int col, int row_span, int col_span)
Definition: xgroupboxes.cpp:71
void addWidget(QWidget *w)
Definition: xgroupboxes.cpp:21
XSettingsModel * X
Definition: mainobject.h:86
void on_import_airports()
MainObject * mainObject
Definition: confirmpage.h:23
QLabel * lblFgRootUsingDefault
Definition: confirmpage.h:28
QLabel * lblFgExePath
Definition: confirmpage.h:26
bool terrasync_enabled()
Sert terrasync enabled/disabled.
XSettings * settings
Definition: mainobject.h:85
static bool import(QProgressDialog &progress, MainObject *mainObject)
QString getx(QString option)