1 // QtLauncher.cxx - GUI launcher dialog using Qt5
3 // Written by James Turner, started December 2014.
5 // Copyright (C) 2014 James Turner <zakalawe@mac.com>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "QtLauncher.hxx"
22 #include "QtLauncher_private.hxx"
25 #include <QProgressDialog>
26 #include <QCoreApplication>
27 #include <QAbstractListModel>
36 #include <QSortFilterProxyModel>
38 #include <QDesktopServices>
41 #include <QFileDialog>
42 #include <QMessageBox>
44 #include <QApplication>
46 #include <QDoubleSpinBox>
49 #include <simgear/timing/timestamp.hxx>
50 #include <simgear/props/props_io.hxx>
51 #include <simgear/structure/exception.hxx>
52 #include <simgear/structure/subsystem_mgr.hxx>
53 #include <simgear/misc/sg_path.hxx>
54 #include <simgear/package/Catalog.hxx>
55 #include <simgear/package/Package.hxx>
56 #include <simgear/package/Install.hxx>
58 #include "ui_Launcher.h"
59 #include "EditRatingsFilterDialog.hxx"
60 #include "AircraftItemDelegate.hxx"
61 #include "AircraftModel.hxx"
62 #include "PathsDialog.hxx"
64 #include <Main/globals.hxx>
65 #include <Navaids/NavDataCache.hxx>
66 #include <Navaids/navrecord.hxx>
68 #include <Main/options.hxx>
69 #include <Main/fg_init.hxx>
70 #include <Viewer/WindowBuilder.hxx>
71 #include <Network/HTTPClient.hxx>
73 using namespace flightgear;
74 using namespace simgear::pkg;
76 const int MAX_RECENT_AIRCRAFT = 20;
78 namespace { // anonymous namespace
82 QString baseLabel = QT_TR_NOOP("Initialising navigation data, this may take several minutes");
83 NavDataCache* cache = NavDataCache::createInstance();
84 if (cache->isRebuildRequired()) {
85 QProgressDialog rebuildProgress(baseLabel,
86 QString() /* cancel text */,
88 rebuildProgress.setWindowModality(Qt::WindowModal);
89 rebuildProgress.show();
91 NavDataCache::RebuildPhase phase = cache->rebuild();
93 while (phase != NavDataCache::REBUILD_DONE) {
94 // sleep to give the rebuild thread more time
95 SGTimeStamp::sleepForMSec(50);
96 phase = cache->rebuild();
99 case NavDataCache::REBUILD_AIRPORTS:
100 rebuildProgress.setLabelText(QT_TR_NOOP("Loading airport data"));
103 case NavDataCache::REBUILD_FIXES:
104 rebuildProgress.setLabelText(QT_TR_NOOP("Loading waypoint data"));
107 case NavDataCache::REBUILD_NAVAIDS:
108 rebuildProgress.setLabelText(QT_TR_NOOP("Loading navigation data"));
112 case NavDataCache::REBUILD_POIS:
113 rebuildProgress.setLabelText(QT_TR_NOOP("Loading point-of-interest data"));
117 rebuildProgress.setLabelText(baseLabel);
120 if (phase == NavDataCache::REBUILD_UNKNOWN) {
121 rebuildProgress.setValue(0);
122 rebuildProgress.setMaximum(0);
124 rebuildProgress.setValue(cache->rebuildPhaseCompletionPercentage());
125 rebuildProgress.setMaximum(100);
128 QCoreApplication::processEvents();
133 class ArgumentsTokenizer
139 explicit Arg(QString k, QString v = QString()) : arg(k), value(v) {}
145 QList<Arg> tokenize(QString in) const
148 const int len = in.count();
154 for (; index < len; ++index) {
156 nc = index < (len - 1) ? in.at(index + 1) : QChar();
160 if (c == QChar('-')) {
161 if (nc == QChar('-')) {
166 // should we pemit single hyphen arguments?
167 // choosing to fail for now
170 } else if (c == QChar('#')) {
173 } else if (c.isSpace()) {
179 if (c == QChar('=')) {
182 } else if (c.isSpace()) {
184 result.append(Arg(key));
186 // could check for illegal charatcers here
192 if (c == QChar('"')) {
194 } else if (c.isSpace()) {
196 result.append(Arg(key, value));
203 if (c == QChar('\\')) {
204 // check for escaped double-quote inside quoted value
205 if (nc == QChar('"')) {
208 } else if (c == QChar('"')) {
216 if ((c == QChar('\n')) || (c == QChar('\r'))) {
220 // nothing to do, eat comment chars
224 } // of character loop
226 // ensure last argument isn't lost
228 result.append(Arg(key));
229 } else if (state == Value) {
230 result.append(Arg(key, value));
246 } // of anonymous namespace
248 class AircraftProxyModel : public QSortFilterProxyModel
252 AircraftProxyModel(QObject* pr) :
253 QSortFilterProxyModel(pr),
254 m_ratingsFilter(true)
256 for (int i=0; i<4; ++i) {
261 void setRatings(int* ratings)
263 ::memcpy(m_ratings, ratings, sizeof(int) * 4);
268 void setRatingFilterEnabled(bool e)
270 if (e == m_ratingsFilter) {
279 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
281 if (!QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) {
285 if (m_ratingsFilter) {
286 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
287 for (int i=0; i<4; ++i) {
288 if (m_ratings[i] > index.data(AircraftRatingRole + i).toInt()) {
298 bool m_ratingsFilter;
302 static void initQtResources()
304 Q_INIT_RESOURCE(resources);
310 void initApp(int& argc, char** argv)
312 sglog().setLogLevels( SG_ALL, SG_INFO );
313 initQtResources(); // can't be called from a namespace
315 static bool qtInitDone = false;
320 s_argc = argc; // QApplication only stores a reference to argc,
321 // and may crash if it is freed
322 // http://doc.qt.io/qt-5/qguiapplication.html#QGuiApplication
324 QApplication* app = new QApplication(s_argc, argv);
325 app->setOrganizationName("FlightGear");
326 app->setApplicationName("FlightGear");
327 app->setOrganizationDomain("flightgear.org");
329 // avoid double Apple menu and other weirdness if both Qt and OSG
330 // try to initialise various Cocoa structures.
331 flightgear::WindowBuilder::setPoseAsStandaloneApp(false);
333 Qt::KeyboardModifiers mods = app->queryKeyboardModifiers();
334 if (mods & Qt::AltModifier) {
335 qWarning() << "Alt pressed during launch";
337 // wipe out our settings
342 Options::sharedInstance()->addOption("restore-defaults", "");
347 bool runLauncherDialog()
349 sglog().setLogLevels( SG_ALL, SG_INFO );
351 initQtResources(); // can't be called inside a namespaceb
353 // startup the nav-cache now. This pre-empts normal startup of
354 // the cache, but no harm done. (Providing scenery paths are consistent)
360 // startup the HTTP system now since packages needs it
361 FGHTTPClient* http = new FGHTTPClient;
362 globals->add_subsystem("http", http);
363 // we guard against re-init in the global phase; bind and postinit
364 // will happen as normal
367 // setup scenery paths now, especially TerraSync path for airport
368 // parking locations (after they're downloaded)
372 if (dlg.result() != QDialog::Accepted) {
379 bool runInAppLauncherDialog()
384 if (dlg.result() != QDialog::Accepted) {
391 } // of namespace flightgear
393 QtLauncher::QtLauncher() :
396 m_subsystemIdleTimer(NULL),
399 m_ui.reset(new Ui::Launcher);
402 #if QT_VERSION >= 0x050300
403 // don't require Qt 5.3
404 m_ui->commandLineArgs->setPlaceholderText("--option=value --prop:/sim/name=value");
407 #if QT_VERSION >= 0x050200
408 m_ui->aircraftFilter->setClearButtonEnabled(true);
411 for (int i=0; i<4; ++i) {
412 m_ratingFilters[i] = 3;
415 m_subsystemIdleTimer = new QTimer(this);
416 m_subsystemIdleTimer->setInterval(0);
417 connect(m_subsystemIdleTimer, &QTimer::timeout,
418 this, &QtLauncher::onSubsytemIdleTimeout);
419 m_subsystemIdleTimer->start();
421 // create and configure the proxy model
422 m_aircraftProxy = new AircraftProxyModel(this);
423 connect(m_ui->ratingsFilterCheck, &QAbstractButton::toggled,
424 m_aircraftProxy, &AircraftProxyModel::setRatingFilterEnabled);
425 connect(m_ui->aircraftFilter, &QLineEdit::textChanged,
426 m_aircraftProxy, &QSortFilterProxyModel::setFilterFixedString);
428 connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun()));
429 connect(m_ui->quitButton, SIGNAL(clicked()), this, SLOT(onQuit()));
431 connect(m_ui->aircraftHistory, &QPushButton::clicked,
432 this, &QtLauncher::onPopupAircraftHistory);
434 connect(m_ui->location, &LocationWidget::descriptionChanged,
435 m_ui->locationDescription, &QLabel::setText);
437 QAction* qa = new QAction(this);
438 qa->setShortcut(QKeySequence("Ctrl+Q"));
439 connect(qa, &QAction::triggered, this, &QtLauncher::onQuit);
442 connect(m_ui->editRatingFilter, &QPushButton::clicked,
443 this, &QtLauncher::onEditRatingsFilter);
445 QIcon historyIcon(":/history-icon");
446 m_ui->aircraftHistory->setIcon(historyIcon);
448 connect(m_ui->timeOfDayCombo, SIGNAL(currentIndexChanged(int)),
449 this, SLOT(updateSettingsSummary()));
450 connect(m_ui->seasonCombo, SIGNAL(currentIndexChanged(int)),
451 this, SLOT(updateSettingsSummary()));
452 connect(m_ui->fetchRealWxrCheckbox, SIGNAL(toggled(bool)),
453 this, SLOT(updateSettingsSummary()));
454 connect(m_ui->rembrandtCheckbox, SIGNAL(toggled(bool)),
455 this, SLOT(updateSettingsSummary()));
456 connect(m_ui->terrasyncCheck, SIGNAL(toggled(bool)),
457 this, SLOT(updateSettingsSummary()));
458 connect(m_ui->startPausedCheck, SIGNAL(toggled(bool)),
459 this, SLOT(updateSettingsSummary()));
460 connect(m_ui->msaaCheckbox, SIGNAL(toggled(bool)),
461 this, SLOT(updateSettingsSummary()));
463 connect(m_ui->rembrandtCheckbox, SIGNAL(toggled(bool)),
464 this, SLOT(onRembrandtToggled(bool)));
465 connect(m_ui->terrasyncCheck, &QCheckBox::toggled,
466 this, &QtLauncher::onToggleTerrasync);
467 updateSettingsSummary();
469 m_aircraftModel = new AircraftItemModel(this, RootRef(globals->packageRoot()));
470 m_aircraftProxy->setSourceModel(m_aircraftModel);
472 m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
473 m_aircraftProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
474 m_aircraftProxy->setSortRole(Qt::DisplayRole);
475 m_aircraftProxy->setDynamicSortFilter(true);
477 m_ui->aircraftList->setModel(m_aircraftProxy);
478 m_ui->aircraftList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
479 AircraftItemDelegate* delegate = new AircraftItemDelegate(m_ui->aircraftList);
480 m_ui->aircraftList->setItemDelegate(delegate);
481 m_ui->aircraftList->setSelectionMode(QAbstractItemView::SingleSelection);
482 connect(m_ui->aircraftList, &QListView::clicked,
483 this, &QtLauncher::onAircraftSelected);
484 connect(delegate, &AircraftItemDelegate::variantChanged,
485 this, &QtLauncher::onAircraftSelected);
486 connect(delegate, &AircraftItemDelegate::requestInstall,
487 this, &QtLauncher::onRequestPackageInstall);
488 connect(delegate, &AircraftItemDelegate::cancelDownload,
489 this, &QtLauncher::onCancelDownload);
491 connect(m_aircraftModel, &AircraftItemModel::aircraftInstallCompleted,
492 this, &QtLauncher::onAircraftInstalledCompleted);
493 connect(m_aircraftModel, &AircraftItemModel::aircraftInstallFailed,
494 this, &QtLauncher::onAircraftInstallFailed);
495 connect(m_aircraftModel, &AircraftItemModel::scanCompleted,
496 this, &QtLauncher::updateSelectedAircraft);
497 connect(m_ui->pathsButton, &QPushButton::clicked,
498 this, &QtLauncher::onEditPaths);
503 m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
504 m_aircraftModel->scanDirs();
507 QtLauncher::~QtLauncher()
512 void QtLauncher::setInAppMode()
515 m_ui->tabWidget->removeTab(2);
516 m_ui->runButton->setText(tr("Apply"));
517 m_ui->quitButton->setText(tr("Cancel"));
519 disconnect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun()));
520 connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onApply()));
523 void QtLauncher::restoreSettings()
526 m_ui->rembrandtCheckbox->setChecked(settings.value("enable-rembrandt", false).toBool());
527 m_ui->terrasyncCheck->setChecked(settings.value("enable-terrasync", true).toBool());
528 m_ui->fullScreenCheckbox->setChecked(settings.value("start-fullscreen", false).toBool());
529 m_ui->msaaCheckbox->setChecked(settings.value("enable-msaa", false).toBool());
530 m_ui->fetchRealWxrCheckbox->setChecked(settings.value("enable-realwx", true).toBool());
531 m_ui->startPausedCheck->setChecked(settings.value("start-paused", false).toBool());
532 m_ui->timeOfDayCombo->setCurrentIndex(settings.value("timeofday", 0).toInt());
533 m_ui->seasonCombo->setCurrentIndex(settings.value("season", 0).toInt());
535 // full paths to -set.xml files
536 m_recentAircraft = QUrl::fromStringList(settings.value("recent-aircraft").toStringList());
538 if (!m_recentAircraft.empty()) {
539 m_selectedAircraft = m_recentAircraft.front();
541 // select the default C172p
544 updateSelectedAircraft();
545 m_ui->location->restoreSettings();
548 m_ui->ratingsFilterCheck->setChecked(settings.value("ratings-filter", true).toBool());
550 Q_FOREACH(QVariant v, settings.value("min-ratings").toList()) {
551 m_ratingFilters[index++] = v.toInt();
554 m_aircraftProxy->setRatingFilterEnabled(m_ui->ratingsFilterCheck->isChecked());
555 m_aircraftProxy->setRatings(m_ratingFilters);
557 m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString());
560 void QtLauncher::saveSettings()
563 settings.setValue("enable-rembrandt", m_ui->rembrandtCheckbox->isChecked());
564 settings.setValue("enable-terrasync", m_ui->terrasyncCheck->isChecked());
565 settings.setValue("enable-msaa", m_ui->msaaCheckbox->isChecked());
566 settings.setValue("start-fullscreen", m_ui->fullScreenCheckbox->isChecked());
567 settings.setValue("enable-realwx", m_ui->fetchRealWxrCheckbox->isChecked());
568 settings.setValue("start-paused", m_ui->startPausedCheck->isChecked());
569 settings.setValue("ratings-filter", m_ui->ratingsFilterCheck->isChecked());
570 settings.setValue("recent-aircraft", QUrl::toStringList(m_recentAircraft));
572 settings.setValue("timeofday", m_ui->timeOfDayCombo->currentIndex());
573 settings.setValue("season", m_ui->seasonCombo->currentIndex());
574 settings.setValue("additional-args", m_ui->commandLineArgs->toPlainText());
576 m_ui->location->saveSettings();
577 qDebug() << "saving settings";
580 void QtLauncher::setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const
582 flightgear::Options* opt = flightgear::Options::sharedInstance();
583 std::string stdName(name.toStdString());
584 if (cbox->isChecked()) {
585 opt->addOption("enable-" + stdName, "");
587 opt->addOption("disable-" + stdName, "");
591 void QtLauncher::onRun()
595 flightgear::Options* opt = flightgear::Options::sharedInstance();
596 setEnableDisableOptionFromCheckbox(m_ui->terrasyncCheck, "terrasync");
597 setEnableDisableOptionFromCheckbox(m_ui->fetchRealWxrCheckbox, "real-weather-fetch");
598 setEnableDisableOptionFromCheckbox(m_ui->rembrandtCheckbox, "rembrandt");
599 setEnableDisableOptionFromCheckbox(m_ui->fullScreenCheckbox, "fullscreen");
600 // setEnableDisableOptionFromCheckbox(m_ui->startPausedCheck, "freeze");
602 bool startPaused = m_ui->startPausedCheck->isChecked() ||
603 m_ui->location->shouldStartPaused();
605 qDebug() << "will start paused";
606 opt->addOption("enable-freeze", "");
609 // MSAA is more complex
610 if (!m_ui->rembrandtCheckbox->isChecked()) {
611 if (m_ui->msaaCheckbox->isChecked()) {
612 globals->get_props()->setIntValue("/sim/rendering/multi-sample-buffers", 1);
613 globals->get_props()->setIntValue("/sim/rendering/multi-samples", 4);
615 globals->get_props()->setIntValue("/sim/rendering/multi-sample-buffers", 0);
620 if (!m_selectedAircraft.isEmpty()) {
621 if (m_selectedAircraft.isLocalFile()) {
622 QFileInfo setFileInfo(m_selectedAircraft.toLocalFile());
623 opt->addOption("aircraft-dir", setFileInfo.dir().absolutePath().toStdString());
624 QString setFile = setFileInfo.fileName();
625 Q_ASSERT(setFile.endsWith("-set.xml"));
626 setFile.truncate(setFile.count() - 8); // drop the '-set.xml' portion
627 opt->addOption("aircraft", setFile.toStdString());
628 } else if (m_selectedAircraft.scheme() == "package") {
629 PackageRef pkg = packageForAircraftURI(m_selectedAircraft);
630 // no need to set aircraft-dir, handled by the corresponding code
632 opt->addOption("aircraft", pkg->qualifiedId());
634 qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft;
637 // manage aircraft history
638 if (m_recentAircraft.contains(m_selectedAircraft))
639 m_recentAircraft.removeOne(m_selectedAircraft);
640 m_recentAircraft.prepend(m_selectedAircraft);
641 if (m_recentAircraft.size() > MAX_RECENT_AIRCRAFT)
642 m_recentAircraft.pop_back();
645 m_ui->location->setLocationOptions();
648 if (m_ui->timeOfDayCombo->currentIndex() != 0) {
649 QString dayval = m_ui->timeOfDayCombo->currentText().toLower();
650 opt->addOption("timeofday", dayval.toStdString());
653 if (m_ui->seasonCombo->currentIndex() != 0) {
654 QString dayval = m_ui->timeOfDayCombo->currentText().toLower();
655 opt->addOption("season", dayval.toStdString());
659 QString downloadDir = settings.value("download-dir").toString();
660 if (!downloadDir.isEmpty()) {
663 int result = QMessageBox::question(this, tr("Create download folder?"),
664 tr("The selected location for downloads does not exist. Create it?"),
665 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
666 if (result == QMessageBox::Cancel) {
670 if (result == QMessageBox::Yes) {
671 d.mkpath(downloadDir);
675 qDebug() << "Download dir is:" << downloadDir;
676 opt->addOption("download-dir", downloadDir.toStdString());
680 Q_FOREACH(QString path, settings.value("scenery-paths").toStringList()) {
681 opt->addOption("fg-scenery", path.toStdString());
685 Q_FOREACH(QString path, settings.value("aircraft-paths").toStringList()) {
686 // can't use fg-aircraft for this, as it is processed before the launcher is run
687 globals->append_aircraft_path(path.toStdString());
690 // additional arguments
691 ArgumentsTokenizer tk;
692 Q_FOREACH(ArgumentsTokenizer::Arg a, tk.tokenize(m_ui->commandLineArgs->toPlainText())) {
693 if (a.arg.startsWith("prop:")) {
694 QString v = a.arg.mid(5) + "=" + a.value;
695 opt->addOption("prop", v.toStdString());
697 opt->addOption(a.arg.toStdString(), a.value.toStdString());
705 void QtLauncher::onApply()
710 if (!m_selectedAircraft.isEmpty()) {
711 std::string aircraftPropValue,
714 if (m_selectedAircraft.isLocalFile()) {
715 QFileInfo setFileInfo(m_selectedAircraft.toLocalFile());
716 QString setFile = setFileInfo.fileName();
717 Q_ASSERT(setFile.endsWith("-set.xml"));
718 setFile.truncate(setFile.count() - 8); // drop the '-set.xml' portion
719 aircraftDir = setFileInfo.dir().absolutePath().toStdString();
720 aircraftPropValue = setFile.toStdString();
721 } else if (m_selectedAircraft.scheme() == "package") {
722 PackageRef pkg = packageForAircraftURI(m_selectedAircraft);
723 // no need to set aircraft-dir, handled by the corresponding code
725 aircraftPropValue = pkg->qualifiedId();
727 qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft;
730 // manage aircraft history
731 if (m_recentAircraft.contains(m_selectedAircraft))
732 m_recentAircraft.removeOne(m_selectedAircraft);
733 m_recentAircraft.prepend(m_selectedAircraft);
734 if (m_recentAircraft.size() > MAX_RECENT_AIRCRAFT)
735 m_recentAircraft.pop_back();
737 globals->get_props()->setStringValue("/sim/aircraft", aircraftPropValue);
738 globals->get_props()->setStringValue("/sim/aircraft-dir", aircraftDir);
745 void QtLauncher::onQuit()
750 void QtLauncher::onToggleTerrasync(bool enabled)
754 QString downloadDir = settings.value("download-dir").toString();
755 if (downloadDir.isEmpty()) {
756 downloadDir = QString::fromStdString(flightgear::defaultDownloadDir());
759 QFileInfo info(downloadDir);
760 if (!info.exists()) {
762 msg.setWindowTitle(tr("Create download folder?"));
763 msg.setText(tr("The download folder '%1' does not exist, create it now? "
764 "Click 'change location' to choose another folder "
765 "to store downloaded files").arg(downloadDir));
766 msg.addButton(QMessageBox::Yes);
767 msg.addButton(QMessageBox::Cancel);
768 msg.addButton(tr("Change location"), QMessageBox::ActionRole);
769 int result = msg.exec();
771 if (result == QMessageBox::Cancel) {
772 m_ui->terrasyncCheck->setChecked(false);
776 if (result == QMessageBox::ActionRole) {
782 d.mkpath(downloadDir);
787 void QtLauncher::onAircraftInstalledCompleted(QModelIndex index)
789 maybeUpdateSelectedAircraft(index);
792 void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage)
794 qWarning() << Q_FUNC_INFO << index.data(AircraftURIRole) << errorMessage;
797 msg.setWindowTitle(tr("Aircraft installation failed"));
798 msg.setText(tr("An error occurred installing the aircraft %1: %2").
799 arg(index.data(Qt::DisplayRole).toString()).arg(errorMessage));
800 msg.addButton(QMessageBox::Ok);
803 maybeUpdateSelectedAircraft(index);
806 void QtLauncher::onAircraftSelected(const QModelIndex& index)
808 m_selectedAircraft = index.data(AircraftURIRole).toUrl();
809 updateSelectedAircraft();
812 void QtLauncher::onRequestPackageInstall(const QModelIndex& index)
814 QString pkg = index.data(AircraftPackageIdRole).toString();
815 simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString());
816 if (pref->isInstalled()) {
817 InstallRef install = pref->existingInstall();
818 if (install && install->hasUpdate()) {
819 globals->packageRoot()->scheduleToUpdate(install);
826 void QtLauncher::onCancelDownload(const QModelIndex& index)
828 QString pkg = index.data(AircraftPackageIdRole).toString();
829 simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString());
830 simgear::pkg::InstallRef i = pref->existingInstall();
834 void QtLauncher::maybeUpdateSelectedAircraft(QModelIndex index)
836 QUrl u = index.data(AircraftURIRole).toUrl();
837 if (u == m_selectedAircraft) {
838 // potentially enable the run button now!
839 updateSelectedAircraft();
843 void QtLauncher::updateSelectedAircraft()
845 QModelIndex index = m_aircraftModel->indexOfAircraftURI(m_selectedAircraft);
846 if (index.isValid()) {
847 QPixmap pm = index.data(Qt::DecorationRole).value<QPixmap>();
848 m_ui->thumbnail->setPixmap(pm);
849 m_ui->aircraftDescription->setText(index.data(Qt::DisplayRole).toString());
851 int status = index.data(AircraftPackageStatusRole).toInt();
852 bool canRun = (status == PackageInstalled);
853 m_ui->runButton->setEnabled(canRun);
855 LauncherAircraftType aircraftType = Airplane;
856 if (index.data(AircraftIsHelicopterRole).toBool()) {
857 aircraftType = Helicopter;
858 } else if (index.data(AircraftIsSeaplaneRole).toBool()) {
859 aircraftType = Seaplane;
862 m_ui->location->setAircraftType(aircraftType);
864 m_ui->thumbnail->setPixmap(QPixmap());
865 m_ui->aircraftDescription->setText("");
866 m_ui->runButton->setEnabled(false);
870 QModelIndex QtLauncher::proxyIndexForAircraftURI(QUrl uri) const
872 return m_aircraftProxy->mapFromSource(sourceIndexForAircraftURI(uri));
875 QModelIndex QtLauncher::sourceIndexForAircraftURI(QUrl uri) const
877 AircraftItemModel* sourceModel = qobject_cast<AircraftItemModel*>(m_aircraftProxy->sourceModel());
878 Q_ASSERT(sourceModel);
879 return sourceModel->indexOfAircraftURI(uri);
882 void QtLauncher::onPopupAircraftHistory()
884 if (m_recentAircraft.isEmpty()) {
889 Q_FOREACH(QUrl uri, m_recentAircraft) {
890 QModelIndex index = sourceIndexForAircraftURI(uri);
891 if (!index.isValid()) {
895 QAction* act = m.addAction(index.data(Qt::DisplayRole).toString());
899 QPoint popupPos = m_ui->aircraftHistory->mapToGlobal(m_ui->aircraftHistory->rect().bottomLeft());
900 QAction* triggered = m.exec(popupPos);
902 m_selectedAircraft = triggered->data().toUrl();
903 QModelIndex index = proxyIndexForAircraftURI(m_selectedAircraft);
904 m_ui->aircraftList->selectionModel()->setCurrentIndex(index,
905 QItemSelectionModel::ClearAndSelect);
906 m_ui->aircraftFilter->clear();
907 updateSelectedAircraft();
911 void QtLauncher::onEditRatingsFilter()
913 EditRatingsFilterDialog dialog(this);
914 dialog.setRatings(m_ratingFilters);
917 if (dialog.result() == QDialog::Accepted) {
919 for (int i=0; i<4; ++i) {
920 m_ratingFilters[i] = dialog.getRating(i);
921 vl.append(m_ratingFilters[i]);
923 m_aircraftProxy->setRatings(m_ratingFilters);
926 settings.setValue("min-ratings", vl);
930 void QtLauncher::updateSettingsSummary()
933 if (m_ui->timeOfDayCombo->currentIndex() > 0) {
934 summary.append(QString(m_ui->timeOfDayCombo->currentText().toLower()));
937 if (m_ui->seasonCombo->currentIndex() > 0) {
938 summary.append(QString(m_ui->seasonCombo->currentText().toLower()));
941 if (m_ui->rembrandtCheckbox->isChecked()) {
942 summary.append("Rembrandt enabled");
943 } else if (m_ui->msaaCheckbox->isChecked()) {
944 summary.append("anti-aliasing");
947 if (m_ui->fetchRealWxrCheckbox->isChecked()) {
948 summary.append("live weather");
951 if (m_ui->terrasyncCheck->isChecked()) {
952 summary.append("automatic scenery downloads");
955 if (m_ui->startPausedCheck->isChecked()) {
956 summary.append("paused");
959 QString s = summary.join(", ");
960 s[0] = s[0].toUpper();
961 m_ui->settingsDescription->setText(s);
964 void QtLauncher::onRembrandtToggled(bool b)
966 // Rembrandt and multi-sample are exclusive
967 m_ui->msaaCheckbox->setEnabled(!b);
970 void QtLauncher::onSubsytemIdleTimeout()
972 globals->get_subsystem_mgr()->update(0.0);
975 void QtLauncher::onEditPaths()
977 PathsDialog dlg(this, globals->packageRoot());
979 if (dlg.result() == QDialog::Accepted) {
980 // re-scan the aircraft list
982 m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
983 m_aircraftModel->scanDirs();
987 simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const
989 if (uri.scheme() != "package") {
990 qWarning() << "invalid URL scheme:" << uri;
991 return simgear::pkg::PackageRef();
994 QString ident = uri.path();
995 return globals->packageRoot()->getPackageById(ident.toStdString());
999 #include "QtLauncher.moc"