26#include <QDesktopServices>
35#include "ui_SetupRootDialog.h"
47 return QString(
"fg-root-") + QString(FLIGHTGEAR_VERSION).replace(
'.',
'-');
50SetupRootDialog::SetupRootDialog(PromptState prompt) :
54 m_ui.reset(
new Ui::SetupRootDialog);
57 connect(m_ui->browseButton, &QPushButton::clicked,
58 this, &SetupRootDialog::onBrowse);
59 connect(m_ui->downloadButton, &QPushButton::clicked,
60 this, &SetupRootDialog::onDownload);
61 connect(m_ui->buttonBox, &QDialogButtonBox::rejected,
62 this, &QDialog::reject);
63 connect(m_ui->useDefaultsButton, &QPushButton::clicked,
64 this, &SetupRootDialog::onUseDefaults);
67 bool ok = defaultRootAcceptable();
68 m_ui->useDefaultsButton->setEnabled(ok);
69 m_ui->useDefaultLabel->setEnabled(ok);
71 m_ui->versionLabel->setText(tr(
"FlightGear version %1").arg(FLIGHTGEAR_VERSION));
72 m_ui->bigIcon->setPixmap(QPixmap(
":/app-icon-large"));
78 SetupRootDialog::PromptState prompt =
79 usingDefaultRoot ? DefaultPathCheckFailed : ExplicitPathCheckFailed;
91 if (dlg.result() != QDialog::Accepted) {
102 QString path = settings.value(
rootPathKey()).toString();
104 if (ask || (path == QStringLiteral(
"!ask"))) {
105 bool ok =
runDialog(ManualChoiceRequested);
110 sgpath =
globals->get_fg_root();
114 if (path.isEmpty()) {
118 if (validatePath(path) && validateVersion(path)) {
119 sgpath = SGPath::fromUtf8(path.toStdString());
126 if (defaultRootAcceptable()) {
139 sgpath =
globals->get_fg_root();
150bool SetupRootDialog::validatePath(QString path)
155 QStringList files = QStringList()
158 <<
"Materials/base/materials-base.xml"
160 <<
"Timezone/zone.tab";
167 Q_FOREACH(QString s, files) {
176bool SetupRootDialog::validateVersion(QString path)
179 return (ver == FLIGHTGEAR_VERSION);
182bool SetupRootDialog::defaultRootAcceptable()
185 QString defaultRoot = QString::fromStdString(r.utf8Str());
186 return validatePath(defaultRoot) && validateVersion(defaultRoot);
194void SetupRootDialog::onBrowse()
196 m_browsedPath = QFileDialog::getExistingDirectory(
this,
197 tr(
"Choose FlightGear data folder"));
198 if (m_browsedPath.isEmpty()) {
202 if (!validatePath(m_browsedPath)) {
203 m_promptState = ChoseInvalidLocation;
208 if (!validateVersion(m_browsedPath)) {
209 m_promptState = ChoseInvalidVersion;
222void SetupRootDialog::onDownload()
224 QString templateUrl =
"https://sourceforge.net/projects/flightgear/files/release-%1/FlightGear-%2-data.txz";
225 QString majorMinorVersion = QString(
"%1.%2").arg(FLIGHTGEAR_MAJOR_VERSION).arg(FLIGHTGEAR_MINOR_VERSION);
226 QUrl downloadUrl(templateUrl.arg(majorMinorVersion).arg(VERSION));
227 QDesktopServices::openUrl(downloadUrl);
230void SetupRootDialog::onUseDefaults()
233 m_browsedPath = QString::fromStdString(r.utf8Str());
240void SetupRootDialog::updatePromptText()
244 switch (m_promptState) {
245 case DefaultPathCheckFailed:
246 t = tr(
"This copy of FlightGear does not include the base data files. " \
247 "Please select a suitable folder containing a previously downloaded set of files.");
250 case ExplicitPathCheckFailed:
251 t = tr(
"The requested location '%1' does not appear to be a valid set of data files for FlightGear").arg(curRoot);
254 case VersionCheckFailed:
257 t = tr(
"Detected incompatible version of the data files: version %1 found, but this is FlightGear %2. " \
258 "(At location: '%3') " \
259 "Please install or select a matching set of data files.").arg(curVer).arg(QString::fromLatin1(FLIGHTGEAR_VERSION)).arg(curRoot);
263 case ManualChoiceRequested:
264 t = tr(
"Please select or download a copy of the FlightGear data files.");
267 case ChoseInvalidLocation:
268 t = tr(
"The choosen location (%1) does not appear to contain FlightGear data files. Please try another location.").arg(m_browsedPath);
271 case ChoseInvalidVersion:
274 t = tr(
"The choosen location (%1) contains files for version %2, but this is FlightGear %3. " \
275 "Please update or try another location").arg(m_browsedPath).arg(curVer).arg(QString::fromLatin1(FLIGHTGEAR_VERSION));
280 m_ui->promptText->setText(t);
const SGPath & get_fg_root() const
void set_fg_root(const SGPath &root)
static flightgear::SetupRootResult restoreUserSelectedRoot(SGPath &path)
static QString rootPathKey()
static bool runDialog(bool usingDefaultRoot)
static void askRootOnNextLaunch()
SGPath platformDefaultRoot() const
static Options * sharedInstance()
static void setPoseAsStandaloneApp(bool b)
string fgBasePackageVersion(const SGPath &base_path)
bool checkKeyboardModifiersForSettingFGRoot()