5 #include "SetupRootDialog.hxx"
8 #include <QDesktopServices>
11 #include <QMessageBox>
16 #include "ui_SetupRootDialog.h"
18 #include <Main/globals.hxx>
19 #include <Main/fg_init.hxx>
20 #include <Include/version.h>
22 SetupRootDialog::SetupRootDialog(bool usedDefaultPath) :
25 m_ui.reset(new Ui::SetupRootDialog);
28 connect(m_ui->browseButton, &QPushButton::clicked,
29 this, &SetupRootDialog::onBrowse);
30 connect(m_ui->downloadButton, &QPushButton::clicked,
31 this, &SetupRootDialog::onDownload);
32 connect(m_ui->buttonBox, &QDialogButtonBox::rejected,
33 this, &QDialog::reject);
35 m_promptState = usedDefaultPath ? DefaultPathCheckFailed : ExplicitPathCheckFailed;
36 std::string ver = fgBasePackageVersion(globals->get_fg_root());
38 Q_ASSERT(ver != FLIGHTGEAR_VERSION); // otherwise what are we doing in here?!
39 m_promptState = VersionCheckFailed;
42 m_ui->versionLabel->setText(tr("FlightGear version %1").arg(FLIGHTGEAR_VERSION));
43 m_ui->bigIcon->setPixmap(QPixmap(":/app-icon-large"));
47 bool SetupRootDialog::restoreUserSelectedRoot()
50 QString path = settings.value("fg-root").toString();
51 if (validatePath(path) && validateVersion(path)) {
52 qDebug() << "Restoring FG-root:" << path;
53 globals->set_fg_root(path.toStdString());
60 bool SetupRootDialog::validatePath(QString path)
62 // check assorted files exist in the root location, to avoid any chance of
63 // selecting an incomplete base package. This is probably overkill but does
65 QStringList files = QStringList()
68 << "Materials/base/materials-base.xml"
70 << "Timezone/zone.tab";
77 Q_FOREACH(QString s, files) {
86 bool SetupRootDialog::validateVersion(QString path)
88 std::string ver = fgBasePackageVersion(SGPath(path.toStdString()));
89 return (ver == FLIGHTGEAR_VERSION);
92 SetupRootDialog::~SetupRootDialog()
97 void SetupRootDialog::onBrowse()
99 m_browsedPath = QFileDialog::getExistingDirectory(this,
100 tr("Choose FlightGear data folder"));
101 if (m_browsedPath.isEmpty()) {
105 if (!validatePath(m_browsedPath)) {
106 m_promptState = ChoseInvalidLocation;
111 if (!validateVersion(m_browsedPath)) {
112 m_promptState = ChoseInvalidVersion;
117 globals->set_fg_root(m_browsedPath.toStdString());
120 settings.setValue("fg-root", m_browsedPath);
122 accept(); // we're done
125 void SetupRootDialog::onDownload()
127 QUrl downloadUrl("http://download.flightgear.org/flightgear/Shared/");
128 QDesktopServices::openUrl(downloadUrl);
131 void SetupRootDialog::updatePromptText()
134 QString curRoot = QString::fromStdString(globals->get_fg_root());
135 switch (m_promptState) {
136 case DefaultPathCheckFailed:
137 t = tr("This copy of FlightGear does not include the base data files. " \
138 "Please select a suitable folder containing a previously download set of files.");
141 case ExplicitPathCheckFailed:
142 t = tr("The requested location '%1' does not appear to be a valid set of data files for FlightGear").arg(curRoot);
145 case VersionCheckFailed:
147 QString curVer = QString::fromStdString(fgBasePackageVersion(globals->get_fg_root()));
148 t = tr("Detected incompatible version of the data files: version %1 found, but this is FlightGear %2. " \
149 "(At location: '%3') " \
150 "Please install or select a matching set of data files.").arg(curVer).arg(QString::fromLatin1(FLIGHTGEAR_VERSION)).arg(curRoot);
154 case ChoseInvalidLocation:
155 t = tr("The choosen location (%1) does not appear to contain FlightGear data files. Please try another location.").arg(m_browsedPath);
158 case ChoseInvalidVersion:
160 QString curVer = QString::fromStdString(fgBasePackageVersion(m_browsedPath.toStdString()));
161 t = tr("The choosen location (%1) contains files for version %2, but this is FlightGear %3. " \
162 "Please update or try another location").arg(m_browsedPath).arg(curVer).arg(QString::fromLatin1(FLIGHTGEAR_VERSION));
167 m_ui->promptText->setText(t);