]> git.mxchange.org Git - flightgear.git/blob - src/GUI/QtLauncher.cxx
Work on the launcher
[flightgear.git] / src / GUI / QtLauncher.cxx
1 // QtLauncher.cxx - GUI launcher dialog using Qt5
2 //
3 // Written by James Turner, started December 2014.
4 //
5 // Copyright (C) 2014 James Turner <zakalawe@mac.com>
6 //
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.
11 //
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.
16 //
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.
20
21 #include "QtLauncher.hxx"
22 #include "QtLauncher_private.hxx"
23
24 // Qt
25 #include <QProgressDialog>
26 #include <QCoreApplication>
27 #include <QAbstractListModel>
28 #include <QDir>
29 #include <QFileInfo>
30 #include <QPixmap>
31 #include <QTimer>
32 #include <QDebug>
33 #include <QCompleter>
34 #include <QListView>
35 #include <QSettings>
36 #include <QSortFilterProxyModel>
37 #include <QMenu>
38 #include <QDesktopServices>
39 #include <QUrl>
40 #include <QAction>
41 #include <QFileDialog>
42 #include <QMessageBox>
43 #include <QDateTime>
44 #include <QApplication>
45 #include <QSpinBox>
46 #include <QDoubleSpinBox>
47
48 // Simgear
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>
57
58 #include "ui_Launcher.h"
59 #include "EditRatingsFilterDialog.hxx"
60 #include "AircraftItemDelegate.hxx"
61 #include "AircraftModel.hxx"
62 #include "PathsDialog.hxx"
63
64 #include <Main/globals.hxx>
65 #include <Navaids/NavDataCache.hxx>
66 #include <Airports/airport.hxx>
67 #include <Airports/dynamics.hxx> // for parking
68 #include <Navaids/navrecord.hxx>
69
70 #include <Main/options.hxx>
71 #include <Main/fg_init.hxx>
72 #include <Viewer/WindowBuilder.hxx>
73 #include <Network/HTTPClient.hxx>
74
75 using namespace flightgear;
76 using namespace simgear::pkg;
77
78 const int MAX_RECENT_AIRPORTS = 32;
79 const int MAX_RECENT_AIRCRAFT = 20;
80
81 namespace { // anonymous namespace
82
83 void initNavCache()
84 {
85     QString baseLabel = QT_TR_NOOP("Initialising navigation data, this may take several minutes");
86     NavDataCache* cache = NavDataCache::createInstance();
87     if (cache->isRebuildRequired()) {
88         QProgressDialog rebuildProgress(baseLabel,
89                                        QString() /* cancel text */,
90                                        0, 100);
91         rebuildProgress.setWindowModality(Qt::WindowModal);
92         rebuildProgress.show();
93
94         NavDataCache::RebuildPhase phase = cache->rebuild();
95
96         while (phase != NavDataCache::REBUILD_DONE) {
97             // sleep to give the rebuild thread more time
98             SGTimeStamp::sleepForMSec(50);
99             phase = cache->rebuild();
100
101             switch (phase) {
102             case NavDataCache::REBUILD_AIRPORTS:
103                 rebuildProgress.setLabelText(QT_TR_NOOP("Loading airport data"));
104                 break;
105
106             case NavDataCache::REBUILD_FIXES:
107                 rebuildProgress.setLabelText(QT_TR_NOOP("Loading waypoint data"));
108                 break;
109
110             case NavDataCache::REBUILD_NAVAIDS:
111                 rebuildProgress.setLabelText(QT_TR_NOOP("Loading navigation data"));
112                 break;
113
114
115             case NavDataCache::REBUILD_POIS:
116                 rebuildProgress.setLabelText(QT_TR_NOOP("Loading point-of-interest data"));
117                 break;
118
119             default:
120                 rebuildProgress.setLabelText(baseLabel);
121             }
122
123             if (phase == NavDataCache::REBUILD_UNKNOWN) {
124                 rebuildProgress.setValue(0);
125                 rebuildProgress.setMaximum(0);
126             } else {
127                 rebuildProgress.setValue(cache->rebuildPhaseCompletionPercentage());
128                 rebuildProgress.setMaximum(100);
129             }
130
131             QCoreApplication::processEvents();
132         }
133     }
134 }
135
136 class ArgumentsTokenizer
137 {
138 public:
139     class Arg
140     {
141     public:
142         explicit Arg(QString k, QString v = QString()) : arg(k), value(v) {}
143
144         QString arg;
145         QString value;
146     };
147
148     QList<Arg> tokenize(QString in) const
149     {
150         int index = 0;
151         const int len = in.count();
152         QChar c, nc;
153         State state = Start;
154         QString key, value;
155         QList<Arg> result;
156
157         for (; index < len; ++index) {
158             c = in.at(index);
159             nc = index < (len - 1) ? in.at(index + 1) : QChar();
160
161             switch (state) {
162             case Start:
163                 if (c == QChar('-')) {
164                     if (nc == QChar('-')) {
165                         state = Key;
166                         key.clear();
167                         ++index;
168                     } else {
169                         // should we pemit single hyphen arguments?
170                         // choosing to fail for now
171                         return QList<Arg>();
172                     }
173                 } else if (c.isSpace()) {
174                     break;
175                 }
176                 break;
177
178             case Key:
179                 if (c == QChar('=')) {
180                     state = Value;
181                     value.clear();
182                 } else if (c.isSpace()) {
183                     state = Start;
184                     result.append(Arg(key));
185                 } else {
186                     // could check for illegal charatcers here
187                     key.append(c);
188                 }
189                 break;
190
191             case Value:
192                 if (c == QChar('"')) {
193                     state = Quoted;
194                 } else if (c.isSpace()) {
195                     state = Start;
196                     result.append(Arg(key, value));
197                 } else {
198                     value.append(c);
199                 }
200                 break;
201
202             case Quoted:
203                 if (c == QChar('\\')) {
204                     // check for escaped double-quote inside quoted value
205                     if (nc == QChar('"')) {
206                         ++index;
207                     }
208                 } else if (c == QChar('"')) {
209                     state = Value;
210                 } else {
211                     value.append(c);
212                 }
213                 break;
214             } // of state switch
215         } // of character loop
216
217         // ensure last argument isn't lost
218         if (state == Key) {
219             result.append(Arg(key));
220         } else if (state == Value) {
221             result.append(Arg(key, value));
222         }
223
224         return result;
225     }
226
227 private:
228     enum State {
229         Start = 0,
230         Key,
231         Value,
232         Quoted
233     };
234 };
235
236 } // of anonymous namespace
237
238 class AirportSearchModel : public QAbstractListModel
239 {
240     Q_OBJECT
241 public:
242     AirportSearchModel() :
243         m_searchActive(false)
244     {
245     }
246
247     void setSearch(QString t)
248     {
249         beginResetModel();
250
251         m_airports.clear();
252         m_ids.clear();
253
254         std::string term(t.toUpper().toStdString());
255         // try ICAO lookup first
256         FGAirportRef ref = FGAirport::findByIdent(term);
257
258         if (ref) {
259             m_ids.push_back(ref->guid());
260             m_airports.push_back(ref);
261             endResetModel();
262             return;
263         }
264
265         m_search.reset(new NavDataCache::ThreadedGUISearch(term));
266         QTimer::singleShot(100, this, SLOT(onSearchResultsPoll()));
267         m_searchActive = true;
268     }
269
270     bool isSearchActive() const
271     {
272         return m_searchActive;
273     }
274
275     virtual int rowCount(const QModelIndex&) const
276     {
277         // if empty, return 1 for special 'no matches'?
278         return m_ids.size();
279     }
280
281     virtual QVariant data(const QModelIndex& index, int role) const
282     {
283         if (!index.isValid())
284             return QVariant();
285
286         FGAirportRef apt = m_airports[index.row()];
287         if (!apt.valid()) {
288             apt = FGPositioned::loadById<FGAirport>(m_ids[index.row()]);
289             m_airports[index.row()] = apt;
290         }
291
292         if (role == Qt::DisplayRole) {
293             QString name = QString::fromStdString(apt->name());
294             return QString("%1: %2").arg(QString::fromStdString(apt->ident())).arg(name);
295         }
296
297         if (role == Qt::EditRole) {
298             return QString::fromStdString(apt->ident());
299         }
300
301         if (role == Qt::UserRole) {
302             return static_cast<qlonglong>(m_ids[index.row()]);
303         }
304
305         return QVariant();
306     }
307
308     QString firstIdent() const
309     {
310         if (m_ids.empty())
311             return QString();
312
313         if (!m_airports.front().valid()) {
314             m_airports[0] = FGPositioned::loadById<FGAirport>(m_ids.front());
315         }
316
317         return QString::fromStdString(m_airports.front()->ident());
318     }
319
320 Q_SIGNALS:
321     void searchComplete();
322
323 private slots:
324     void onSearchResultsPoll()
325     {
326         PositionedIDVec newIds = m_search->results();
327
328         beginInsertRows(QModelIndex(), m_ids.size(), newIds.size() - 1);
329         for (unsigned int i=m_ids.size(); i < newIds.size(); ++i) {
330             m_ids.push_back(newIds[i]);
331             m_airports.push_back(FGAirportRef()); // null ref
332         }
333         endInsertRows();
334
335         if (m_search->isComplete()) {
336             m_searchActive = false;
337             m_search.reset();
338             emit searchComplete();
339         } else {
340             QTimer::singleShot(100, this, SLOT(onSearchResultsPoll()));
341         }
342     }
343
344 private:
345     PositionedIDVec m_ids;
346     mutable std::vector<FGAirportRef> m_airports;
347     bool m_searchActive;
348     QScopedPointer<NavDataCache::ThreadedGUISearch> m_search;
349 };
350
351 class AircraftProxyModel : public QSortFilterProxyModel
352 {
353     Q_OBJECT
354 public:
355     AircraftProxyModel(QObject* pr) :
356         QSortFilterProxyModel(pr),
357         m_ratingsFilter(true)
358     {
359         for (int i=0; i<4; ++i) {
360             m_ratings[i] = 3;
361         }
362     }
363
364     void setRatings(int* ratings)
365     {
366         ::memcpy(m_ratings, ratings, sizeof(int) * 4);
367         invalidate();
368     }
369
370 public slots:
371     void setRatingFilterEnabled(bool e)
372     {
373         if (e == m_ratingsFilter) {
374             return;
375         }
376
377         m_ratingsFilter = e;
378         invalidate();
379     }
380
381 protected:
382     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
383     {
384         if (!QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) {
385             return false;
386         }
387
388         if (m_ratingsFilter) {
389             QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
390             for (int i=0; i<4; ++i) {
391                 if (m_ratings[i] > index.data(AircraftRatingRole + i).toInt()) {
392                     return false;
393                 }
394             }
395         }
396
397         return true;
398     }
399
400 private:
401     bool m_ratingsFilter;
402     int m_ratings[4];
403 };
404
405 static void initQtResources()
406 {
407     Q_INIT_RESOURCE(resources);
408 }
409
410 namespace flightgear
411 {
412
413 void initApp(int& argc, char** argv)
414 {
415     static bool qtInitDone = false;
416     if (!qtInitDone) {
417         qtInitDone = true;
418
419         QApplication* app = new QApplication(argc, argv);
420         app->setOrganizationName("FlightGear");
421         app->setApplicationName("FlightGear");
422         app->setOrganizationDomain("flightgear.org");
423
424         // avoid double Apple menu and other weirdness if both Qt and OSG
425         // try to initialise various Cocoa structures.
426         flightgear::WindowBuilder::setPoseAsStandaloneApp(false);
427
428         Qt::KeyboardModifiers mods = app->queryKeyboardModifiers();
429         if (mods & Qt::AltModifier) {
430             qWarning() << "Alt pressed during launch";
431
432             // wipe out our settings
433             QSettings settings;
434             settings.clear();
435
436
437             Options::sharedInstance()->addOption("restore-defaults", "");
438         }
439     }
440 }
441
442 bool runLauncherDialog()
443 {
444     sglog().setLogLevels( SG_ALL, SG_INFO );
445
446
447     initQtResources(); // can't be called inside a namespaceb
448
449     // startup the nav-cache now. This pre-empts normal startup of
450     // the cache, but no harm done. (Providing scenery paths are consistent)
451
452     initNavCache();
453
454
455     fgInitPackageRoot();
456
457     // startup the HTTP system now since packages needs it
458     FGHTTPClient* http = new FGHTTPClient;
459     globals->add_subsystem("http", http);
460     // we guard against re-init in the global phase; bind and postinit
461     // will happen as normal
462     http->init();
463
464
465     // setup scenery paths now, especially TerraSync path for airport
466     // parking locations (after they're downloaded)
467
468     QtLauncher dlg;
469     dlg.exec();
470     if (dlg.result() != QDialog::Accepted) {
471         return false;
472     }
473
474     return true;
475 }
476
477 bool runInAppLauncherDialog()
478 {
479     QtLauncher dlg;
480     dlg.setInAppMode();
481     dlg.exec();
482     if (dlg.result() != QDialog::Accepted) {
483         return false;
484     }
485
486     return true;
487 }
488
489 } // of namespace flightgear
490
491 QtLauncher::QtLauncher() :
492     QDialog(),
493     m_ui(NULL),
494     m_subsystemIdleTimer(NULL),
495     m_inAppMode(false)
496 {
497     m_ui.reset(new Ui::Launcher);
498     m_ui->setupUi(this);
499
500 #if QT_VERSION >= 0x050300
501     // don't require Qt 5.3
502     m_ui->commandLineArgs->setPlaceholderText("--option=value --prop:/sim/name=value");
503 #endif
504
505 #if QT_VERSION >= 0x050200
506     m_ui->aircraftFilter->setClearButtonEnabled(true);
507 #endif
508
509     for (int i=0; i<4; ++i) {
510         m_ratingFilters[i] = 3;
511     }
512
513     m_subsystemIdleTimer = new QTimer(this);
514     m_subsystemIdleTimer->setInterval(0);
515     connect(m_subsystemIdleTimer, &QTimer::timeout,
516             this, &QtLauncher::onSubsytemIdleTimeout);
517     m_subsystemIdleTimer->start();
518
519     m_airportsModel = new AirportSearchModel;
520     m_ui->searchList->setModel(m_airportsModel);
521     connect(m_ui->searchList, &QListView::clicked,
522             this, &QtLauncher::onAirportChoiceSelected);
523     connect(m_airportsModel, &AirportSearchModel::searchComplete,
524             this, &QtLauncher::onAirportSearchComplete);
525
526     // create and configure the proxy model
527     m_aircraftProxy = new AircraftProxyModel(this);
528     connect(m_ui->ratingsFilterCheck, &QAbstractButton::toggled,
529             m_aircraftProxy, &AircraftProxyModel::setRatingFilterEnabled);
530     connect(m_ui->aircraftFilter, &QLineEdit::textChanged,
531             m_aircraftProxy, &QSortFilterProxyModel::setFilterFixedString);
532
533     connect(m_ui->runwayCombo, SIGNAL(currentIndexChanged(int)),
534             this, SLOT(updateAirportDescription()));
535     connect(m_ui->parkingCombo, SIGNAL(currentIndexChanged(int)),
536             this, SLOT(updateAirportDescription()));
537     connect(m_ui->runwayRadio, SIGNAL(toggled(bool)),
538             this, SLOT(updateAirportDescription()));
539     connect(m_ui->parkingRadio, SIGNAL(toggled(bool)),
540             this, SLOT(updateAirportDescription()));
541     connect(m_ui->onFinalCheckbox, SIGNAL(toggled(bool)),
542             this, SLOT(updateAirportDescription()));
543
544
545     connect(m_ui->airportDiagram, &AirportDiagram::clickedRunway,
546             this, &QtLauncher::onAirportDiagramClicked);
547
548     connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun()));
549     connect(m_ui->quitButton, SIGNAL(clicked()), this, SLOT(onQuit()));
550     connect(m_ui->airportEdit, SIGNAL(returnPressed()),
551             this, SLOT(onSearchAirports()));
552
553     connect(m_ui->airportHistory, &QPushButton::clicked,
554             this, &QtLauncher::onPopupAirportHistory);
555     connect(m_ui->aircraftHistory, &QPushButton::clicked,
556           this, &QtLauncher::onPopupAircraftHistory);
557
558     QAction* qa = new QAction(this);
559     qa->setShortcut(QKeySequence("Ctrl+Q"));
560     connect(qa, &QAction::triggered, this, &QtLauncher::onQuit);
561     addAction(qa);
562
563     connect(m_ui->editRatingFilter, &QPushButton::clicked,
564             this, &QtLauncher::onEditRatingsFilter);
565
566     QIcon historyIcon(":/history-icon");
567     m_ui->aircraftHistory->setIcon(historyIcon);
568     m_ui->airportHistory->setIcon(historyIcon);
569
570     m_ui->searchIcon->setPixmap(QPixmap(":/search-icon"));
571
572     connect(m_ui->timeOfDayCombo, SIGNAL(currentIndexChanged(int)),
573             this, SLOT(updateSettingsSummary()));
574     connect(m_ui->seasonCombo, SIGNAL(currentIndexChanged(int)),
575             this, SLOT(updateSettingsSummary()));
576     connect(m_ui->fetchRealWxrCheckbox, SIGNAL(toggled(bool)),
577             this, SLOT(updateSettingsSummary()));
578     connect(m_ui->rembrandtCheckbox, SIGNAL(toggled(bool)),
579             this, SLOT(updateSettingsSummary()));
580     connect(m_ui->terrasyncCheck, SIGNAL(toggled(bool)),
581             this, SLOT(updateSettingsSummary()));
582     connect(m_ui->startPausedCheck, SIGNAL(toggled(bool)),
583             this, SLOT(updateSettingsSummary()));
584     connect(m_ui->msaaCheckbox, SIGNAL(toggled(bool)),
585             this, SLOT(updateSettingsSummary()));
586
587     connect(m_ui->rembrandtCheckbox, SIGNAL(toggled(bool)),
588             this, SLOT(onRembrandtToggled(bool)));
589     connect(m_ui->terrasyncCheck, &QCheckBox::toggled,
590             this, &QtLauncher::onToggleTerrasync);
591     updateSettingsSummary();
592
593     m_aircraftModel = new AircraftItemModel(this, RootRef(globals->packageRoot()));
594     m_aircraftProxy->setSourceModel(m_aircraftModel);
595
596     m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
597     m_aircraftProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
598     m_aircraftProxy->setSortRole(Qt::DisplayRole);
599     m_aircraftProxy->setDynamicSortFilter(true);
600
601     m_ui->aircraftList->setModel(m_aircraftProxy);
602     m_ui->aircraftList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
603     AircraftItemDelegate* delegate = new AircraftItemDelegate(m_ui->aircraftList);
604     m_ui->aircraftList->setItemDelegate(delegate);
605     m_ui->aircraftList->setSelectionMode(QAbstractItemView::SingleSelection);
606     connect(m_ui->aircraftList, &QListView::clicked,
607             this, &QtLauncher::onAircraftSelected);
608     connect(delegate, &AircraftItemDelegate::variantChanged,
609             this, &QtLauncher::onAircraftSelected);
610     connect(delegate, &AircraftItemDelegate::requestInstall,
611             this, &QtLauncher::onRequestPackageInstall);
612     connect(delegate, &AircraftItemDelegate::cancelDownload,
613             this, &QtLauncher::onCancelDownload);
614
615     connect(m_aircraftModel, &AircraftItemModel::aircraftInstallCompleted,
616             this, &QtLauncher::onAircraftInstalledCompleted);
617     connect(m_aircraftModel, &AircraftItemModel::aircraftInstallFailed,
618             this, &QtLauncher::onAircraftInstallFailed);
619
620     connect(m_ui->pathsButton, &QPushButton::clicked,
621             this, &QtLauncher::onEditPaths);
622
623
624     connect(m_ui->trueBearing, &QCheckBox::toggled, this, &QtLauncher::onOffsetBearingTrueChanged);
625     connect(m_ui->offsetRadioButton, &QRadioButton::toggled,
626             this, &QtLauncher::onOffsetRadioToggled);
627     connect(m_ui->trueBearing, &QCheckBox::toggled, this, &QtLauncher::onOffsetDataChanged);
628     connect(m_ui->offsetBearingSpinbox, SIGNAL(valueChanged(int)), this, SLOT(onOffsetDataChanged()));
629     connect(m_ui->offsetNmSpinbox, SIGNAL(valueChanged(double)),
630             this, SLOT(onOffsetDataChanged()));
631
632     restoreSettings();
633
634     QSettings settings;
635     m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
636     m_aircraftModel->scanDirs();
637 }
638
639 QtLauncher::~QtLauncher()
640 {
641
642 }
643
644 void QtLauncher::setInAppMode()
645 {
646   m_inAppMode = true;
647   m_ui->tabWidget->removeTab(2);
648   m_ui->runButton->setText(tr("Apply"));
649   m_ui->quitButton->setText(tr("Cancel"));
650
651   disconnect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun()));
652   connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onApply()));
653 }
654
655 bool QtLauncher::runLauncherDialog()
656 {
657     sglog().setLogLevels( SG_ALL, SG_INFO );
658     Q_INIT_RESOURCE(resources);
659
660     static bool qtInitDone = false;
661     static int s_argc;
662     if (!qtInitDone) {
663         qtInitDone = true;
664         s_argc = argc; // QApplication only stores a reference to argc,
665         // and may crash if it is freed
666         // http://doc.qt.io/qt-5/qguiapplication.html#QGuiApplication
667
668         QApplication* app = new QApplication(s_argc, argv);
669         app->setOrganizationName("FlightGear");
670         app->setApplicationName("FlightGear");
671         app->setOrganizationDomain("flightgear.org");
672
673         // avoid double Apple menu and other weirdness if both Qt and OSG
674         // try to initialise various Cocoa structures.
675         flightgear::WindowBuilder::setPoseAsStandaloneApp(false);
676
677         Qt::KeyboardModifiers mods = app->queryKeyboardModifiers();
678         if (mods & Qt::AltModifier) {
679             qWarning() << "Alt pressed during launch";
680
681             // wipe out our settings
682             QSettings settings;
683             settings.clear();
684
685             Options::sharedInstance()->addOption("restore-defaults", "");
686         }
687     }
688
689     // startup the nav-cache now. This preempts normal startup of
690     // the cache, but no harm done. (Providing scenery paths are consistent)
691
692     initNavCache();
693
694   // setup scenery paths now, especially TerraSync path for airport
695   // parking locations (after they're downloaded)
696
697     QtLauncher dlg;
698     dlg.exec();
699     if (dlg.result() != QDialog::Accepted) {
700         return false;
701     }
702 }
703
704 void QtLauncher::restoreSettings()
705 {
706     QSettings settings;
707     m_ui->rembrandtCheckbox->setChecked(settings.value("enable-rembrandt", false).toBool());
708     m_ui->terrasyncCheck->setChecked(settings.value("enable-terrasync", true).toBool());
709     m_ui->fullScreenCheckbox->setChecked(settings.value("start-fullscreen", false).toBool());
710     m_ui->msaaCheckbox->setChecked(settings.value("enable-msaa", false).toBool());
711     m_ui->fetchRealWxrCheckbox->setChecked(settings.value("enable-realwx", true).toBool());
712     m_ui->startPausedCheck->setChecked(settings.value("start-paused", false).toBool());
713     m_ui->timeOfDayCombo->setCurrentIndex(settings.value("timeofday", 0).toInt());
714     m_ui->seasonCombo->setCurrentIndex(settings.value("season", 0).toInt());
715
716     // full paths to -set.xml files
717     m_recentAircraft = QUrl::fromStringList(settings.value("recent-aircraft").toStringList());
718
719     if (!m_recentAircraft.empty()) {
720         m_selectedAircraft = m_recentAircraft.front();
721     } else {
722         // select the default C172p
723     }
724
725     updateSelectedAircraft();
726
727     // ICAO identifiers
728     m_recentAirports = settings.value("recent-airports").toStringList();
729     if (!m_recentAirports.empty()) {
730         setAirport(FGAirport::findByIdent(m_recentAirports.front().toStdString()));
731     }
732     updateAirportDescription();
733
734     // rating filters
735     m_ui->ratingsFilterCheck->setChecked(settings.value("ratings-filter", true).toBool());
736     int index = 0;
737     Q_FOREACH(QVariant v, settings.value("min-ratings").toList()) {
738         m_ratingFilters[index++] = v.toInt();
739     }
740
741     m_aircraftProxy->setRatingFilterEnabled(m_ui->ratingsFilterCheck->isChecked());
742     m_aircraftProxy->setRatings(m_ratingFilters);
743
744     m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString());
745 }
746
747 void QtLauncher::saveSettings()
748 {
749     QSettings settings;
750     settings.setValue("enable-rembrandt", m_ui->rembrandtCheckbox->isChecked());
751     settings.setValue("enable-terrasync", m_ui->terrasyncCheck->isChecked());
752     settings.setValue("enable-msaa", m_ui->msaaCheckbox->isChecked());
753     settings.setValue("start-fullscreen", m_ui->fullScreenCheckbox->isChecked());
754     settings.setValue("enable-realwx", m_ui->fetchRealWxrCheckbox->isChecked());
755     settings.setValue("start-paused", m_ui->startPausedCheck->isChecked());
756     settings.setValue("ratings-filter", m_ui->ratingsFilterCheck->isChecked());
757     settings.setValue("recent-aircraft", QUrl::toStringList(m_recentAircraft));
758     settings.setValue("recent-airports", m_recentAirports);
759     settings.setValue("timeofday", m_ui->timeOfDayCombo->currentIndex());
760     settings.setValue("season", m_ui->seasonCombo->currentIndex());
761     settings.setValue("additional-args", m_ui->commandLineArgs->toPlainText());
762 }
763
764 void QtLauncher::setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const
765 {
766     flightgear::Options* opt = flightgear::Options::sharedInstance();
767     std::string stdName(name.toStdString());
768     if (cbox->isChecked()) {
769         opt->addOption("enable-" + stdName, "");
770     } else {
771         opt->addOption("disable-" + stdName, "");
772     }
773 }
774
775 void QtLauncher::onRun()
776 {
777     accept();
778
779     flightgear::Options* opt = flightgear::Options::sharedInstance();
780     setEnableDisableOptionFromCheckbox(m_ui->terrasyncCheck, "terrasync");
781     setEnableDisableOptionFromCheckbox(m_ui->fetchRealWxrCheckbox, "real-weather-fetch");
782     setEnableDisableOptionFromCheckbox(m_ui->rembrandtCheckbox, "rembrandt");
783     setEnableDisableOptionFromCheckbox(m_ui->fullScreenCheckbox, "fullscreen");
784     setEnableDisableOptionFromCheckbox(m_ui->startPausedCheck, "freeze");
785
786     // MSAA is more complex
787     if (!m_ui->rembrandtCheckbox->isChecked()) {
788         if (m_ui->msaaCheckbox->isChecked()) {
789             globals->get_props()->setIntValue("/sim/rendering/multi-sample-buffers", 1);
790             globals->get_props()->setIntValue("/sim/rendering/multi-samples", 4);
791         } else {
792             globals->get_props()->setIntValue("/sim/rendering/multi-sample-buffers", 0);
793         }
794     }
795
796     // aircraft
797     if (!m_selectedAircraft.isEmpty()) {
798         if (m_selectedAircraft.isLocalFile()) {
799             QFileInfo setFileInfo(m_selectedAircraft.toLocalFile());
800             opt->addOption("aircraft-dir", setFileInfo.dir().absolutePath().toStdString());
801             QString setFile = setFileInfo.fileName();
802             Q_ASSERT(setFile.endsWith("-set.xml"));
803             setFile.truncate(setFile.count() - 8); // drop the '-set.xml' portion
804             opt->addOption("aircraft", setFile.toStdString());
805         } else if (m_selectedAircraft.scheme() == "package") {
806             PackageRef pkg = packageForAircraftURI(m_selectedAircraft);
807             // no need to set aircraft-dir, handled by the corresponding code
808             // in fgInitAircraft
809             opt->addOption("aircraft", pkg->qualifiedId());
810         } else {
811             qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft;
812         }
813
814       // manage aircraft history
815         if (m_recentAircraft.contains(m_selectedAircraft))
816           m_recentAircraft.removeOne(m_selectedAircraft);
817         m_recentAircraft.prepend(m_selectedAircraft);
818         if (m_recentAircraft.size() > MAX_RECENT_AIRCRAFT)
819           m_recentAircraft.pop_back();
820     }
821
822     // airport / location
823     if (m_selectedAirport) {
824         opt->addOption("airport", m_selectedAirport->ident());
825     }
826
827     if (m_ui->runwayRadio->isChecked()) {
828         int index = m_ui->runwayCombo->itemData(m_ui->runwayCombo->currentIndex()).toInt();
829         if ((index >= 0) && m_selectedAirport) {
830             // explicit runway choice
831             opt->addOption("runway", m_selectedAirport->getRunwayByIndex(index)->ident());
832         }
833
834         if (m_ui->onFinalCheckbox->isChecked()) {
835             opt->addOption("glideslope", "3.0");
836             opt->addOption("offset-distance", "10.0"); // in nautical miles
837         }
838     } else if (m_ui->parkingRadio->isChecked()) {
839         // parking selection
840         opt->addOption("parkpos", m_ui->parkingCombo->currentText().toStdString());
841     }
842
843     // time of day
844     if (m_ui->timeOfDayCombo->currentIndex() != 0) {
845         QString dayval = m_ui->timeOfDayCombo->currentText().toLower();
846         opt->addOption("timeofday", dayval.toStdString());
847     }
848
849     if (m_ui->seasonCombo->currentIndex() != 0) {
850         QString dayval = m_ui->timeOfDayCombo->currentText().toLower();
851         opt->addOption("season", dayval.toStdString());
852     }
853
854     QSettings settings;
855     QString downloadDir = settings.value("download-dir").toString();
856     if (!downloadDir.isEmpty()) {
857         QDir d(downloadDir);
858         if (!d.exists()) {
859             int result = QMessageBox::question(this, tr("Create download folder?"),
860                                   tr("The selected location for downloads does not exist. Create it?"),
861                                                QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
862             if (result == QMessageBox::Cancel) {
863                 return;
864             }
865
866             if (result == QMessageBox::Yes) {
867                 d.mkpath(downloadDir);
868             }
869         }
870
871         qDebug() << "Download dir is:" << downloadDir;
872         opt->addOption("download-dir", downloadDir.toStdString());
873     }
874
875     // scenery paths
876     Q_FOREACH(QString path, settings.value("scenery-paths").toStringList()) {
877         opt->addOption("fg-scenery", path.toStdString());
878     }
879
880     // aircraft paths
881     Q_FOREACH(QString path, settings.value("aircraft-paths").toStringList()) {
882         // can't use fg-aircraft for this, as it is processed before the launcher is run
883         globals->append_aircraft_path(path.toStdString());
884     }
885
886     // additional arguments
887     ArgumentsTokenizer tk;
888     Q_FOREACH(ArgumentsTokenizer::Arg a, tk.tokenize(m_ui->commandLineArgs->toPlainText())) {
889         if (a.arg.startsWith("prop:")) {
890             QString v = a.arg.mid(5) + "=" + a.value;
891             opt->addOption("prop", v.toStdString());
892         } else {
893             opt->addOption(a.arg.toStdString(), a.value.toStdString());
894         }
895     }
896
897     saveSettings();
898 }
899
900 void QtLauncher::onApply()
901 {
902     accept();
903
904     // aircraft
905     if (!m_selectedAircraft.isEmpty()) {
906         std::string aircraftPropValue,
907             aircraftDir;
908
909         if (m_selectedAircraft.isLocalFile()) {
910             QFileInfo setFileInfo(m_selectedAircraft.toLocalFile());
911             QString setFile = setFileInfo.fileName();
912             Q_ASSERT(setFile.endsWith("-set.xml"));
913             setFile.truncate(setFile.count() - 8); // drop the '-set.xml' portion
914             aircraftDir = setFileInfo.dir().absolutePath().toStdString();
915             aircraftPropValue = setFile.toStdString();
916         } else if (m_selectedAircraft.scheme() == "package") {
917             PackageRef pkg = packageForAircraftURI(m_selectedAircraft);
918             // no need to set aircraft-dir, handled by the corresponding code
919             // in fgInitAircraft
920             aircraftPropValue = pkg->qualifiedId();
921         } else {
922             qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft;
923         }
924
925         // manage aircraft history
926         if (m_recentAircraft.contains(m_selectedAircraft))
927             m_recentAircraft.removeOne(m_selectedAircraft);
928         m_recentAircraft.prepend(m_selectedAircraft);
929         if (m_recentAircraft.size() > MAX_RECENT_AIRCRAFT)
930             m_recentAircraft.pop_back();
931
932         globals->get_props()->setStringValue("/sim/aircraft", aircraftPropValue);
933         globals->get_props()->setStringValue("/sim/aircraft-dir", aircraftDir);
934     }
935
936
937     saveSettings();
938 }
939
940 void QtLauncher::onQuit()
941 {
942     reject();
943 }
944
945 void QtLauncher::onSearchAirports()
946 {
947     QString search = m_ui->airportEdit->text();
948     m_airportsModel->setSearch(search);
949
950     if (m_airportsModel->isSearchActive()) {
951         m_ui->searchStatusText->setText(QString("Searching for '%1'").arg(search));
952         m_ui->locationStack->setCurrentIndex(2);
953     } else if (m_airportsModel->rowCount(QModelIndex()) == 1) {
954         QString ident = m_airportsModel->firstIdent();
955         setAirport(FGAirport::findByIdent(ident.toStdString()));
956         m_ui->locationStack->setCurrentIndex(0);
957     }
958 }
959
960 void QtLauncher::onAirportSearchComplete()
961 {
962     int numResults = m_airportsModel->rowCount(QModelIndex());
963     if (numResults == 0) {
964         m_ui->searchStatusText->setText(QString("No matching airports for '%1'").arg(m_ui->airportEdit->text()));
965     } else if (numResults == 1) {
966         QString ident = m_airportsModel->firstIdent();
967         setAirport(FGAirport::findByIdent(ident.toStdString()));
968         m_ui->locationStack->setCurrentIndex(0);
969     } else {
970         m_ui->locationStack->setCurrentIndex(1);
971     }
972 }
973
974 void QtLauncher::onAirportChanged()
975 {
976     m_ui->runwayCombo->setEnabled(m_selectedAirport);
977     m_ui->parkingCombo->setEnabled(m_selectedAirport);
978     m_ui->airportDiagram->setAirport(m_selectedAirport);
979
980     m_ui->runwayRadio->setChecked(true); // default back to runway mode
981     // unelss multiplayer is enabled ?
982
983     if (!m_selectedAirport) {
984         m_ui->airportDescription->setText(QString());
985         m_ui->airportDiagram->setEnabled(false);
986         return;
987     }
988
989     m_ui->airportDiagram->setEnabled(true);
990
991     m_ui->runwayCombo->clear();
992     m_ui->runwayCombo->addItem("Automatic", -1);
993     for (unsigned int r=0; r<m_selectedAirport->numRunways(); ++r) {
994         FGRunwayRef rwy = m_selectedAirport->getRunwayByIndex(r);
995         // add runway with index as data role
996         m_ui->runwayCombo->addItem(QString::fromStdString(rwy->ident()), r);
997
998         m_ui->airportDiagram->addRunway(rwy);
999     }
1000
1001     m_ui->parkingCombo->clear();
1002     FGAirportDynamics* dynamics = m_selectedAirport->getDynamics();
1003     PositionedIDVec parkings = NavDataCache::instance()->airportItemsOfType(
1004                                                                             m_selectedAirport->guid(),
1005                                                                             FGPositioned::PARKING);
1006     if (parkings.empty()) {
1007         m_ui->parkingCombo->setEnabled(false);
1008         m_ui->parkingRadio->setEnabled(false);
1009     } else {
1010         m_ui->parkingCombo->setEnabled(true);
1011         m_ui->parkingRadio->setEnabled(true);
1012         Q_FOREACH(PositionedID parking, parkings) {
1013             FGParking* park = dynamics->getParking(parking);
1014             m_ui->parkingCombo->addItem(QString::fromStdString(park->getName()),
1015                                         static_cast<qlonglong>(parking));
1016
1017             m_ui->airportDiagram->addParking(park);
1018         }
1019     }
1020 }
1021
1022 void QtLauncher::onOffsetRadioToggled(bool on)
1023 {
1024     m_ui->offsetNmSpinbox->setEnabled(on);
1025     m_ui->offsetBearingSpinbox->setEnabled(on);
1026     m_ui->trueBearing->setEnabled(on);
1027     m_ui->offsetBearingLabel->setEnabled(on);
1028     m_ui->offsetDistanceLabel->setEnabled(on);
1029 }
1030
1031 void QtLauncher::onAirportDiagramClicked(FGRunwayRef rwy)
1032 {
1033     if (rwy) {
1034         m_ui->runwayRadio->setChecked(true);
1035         int rwyIndex = m_ui->runwayCombo->findText(QString::fromStdString(rwy->ident()));
1036         m_ui->runwayCombo->setCurrentIndex(rwyIndex);
1037     }
1038
1039     updateAirportDescription();
1040 }
1041
1042 void QtLauncher::onToggleTerrasync(bool enabled)
1043 {
1044     if (enabled) {
1045         QSettings settings;
1046         QString downloadDir = settings.value("download-dir").toString();
1047         if (downloadDir.isEmpty()) {
1048             downloadDir = QString::fromStdString(flightgear::defaultDownloadDir());
1049         }
1050
1051         QFileInfo info(downloadDir);
1052         if (!info.exists()) {
1053             QMessageBox msg;
1054             msg.setWindowTitle(tr("Create download folder?"));
1055             msg.setText(tr("The download folder '%1' does not exist, create it now? "
1056                            "Click 'change location' to choose another folder "
1057                            "to store downloaded files").arg(downloadDir));
1058             msg.addButton(QMessageBox::Yes);
1059             msg.addButton(QMessageBox::Cancel);
1060             msg.addButton(tr("Change location"), QMessageBox::ActionRole);
1061             int result = msg.exec();
1062
1063             if (result == QMessageBox::Cancel) {
1064                 m_ui->terrasyncCheck->setChecked(false);
1065                 return;
1066             }
1067
1068             if (result == QMessageBox::ActionRole) {
1069                 onEditPaths();
1070                 return;
1071             }
1072
1073             QDir d(downloadDir);
1074             d.mkpath(downloadDir);
1075         }
1076     } // of is enabled
1077 }
1078
1079 void QtLauncher::onAircraftInstalledCompleted(QModelIndex index)
1080 {
1081     maybeUpdateSelectedAircraft(index);
1082 }
1083
1084 void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage)
1085 {
1086     qWarning() << Q_FUNC_INFO << index.data(AircraftURIRole) << errorMessage;
1087
1088     QMessageBox msg;
1089     msg.setWindowTitle(tr("Aircraft installation failed"));
1090     msg.setText(tr("An error occurred installing the aircraft %1: %2").
1091                 arg(index.data(Qt::DisplayRole).toString()).arg(errorMessage));
1092     msg.addButton(QMessageBox::Ok);
1093     msg.exec();
1094
1095     maybeUpdateSelectedAircraft(index);
1096 }
1097
1098 void QtLauncher::updateAirportDescription()
1099 {
1100     if (!m_selectedAirport) {
1101         m_ui->airportDescription->setText(QString("No airport selected"));
1102         return;
1103     }
1104
1105     QString ident = QString::fromStdString(m_selectedAirport->ident()),
1106         name = QString::fromStdString(m_selectedAirport->name());
1107     QString locationOnAirport;
1108     if (m_ui->runwayRadio->isChecked()) {
1109         bool onFinal = m_ui->onFinalCheckbox->isChecked();
1110         int comboIndex = m_ui->runwayCombo->currentIndex();
1111         QString runwayName = (comboIndex == 0) ?
1112             "active runway" :
1113             QString("runway %1").arg(m_ui->runwayCombo->currentText());
1114
1115         if (onFinal) {
1116             locationOnAirport = QString("on 10-mile final to %1").arg(runwayName);
1117         } else {
1118             locationOnAirport = QString("on %1").arg(runwayName);
1119         }
1120
1121         int runwayIndex = m_ui->runwayCombo->itemData(comboIndex).toInt();
1122         FGRunwayRef rwy = (runwayIndex >= 0) ?
1123             m_selectedAirport->getRunwayByIndex(runwayIndex) : FGRunwayRef();
1124         m_ui->airportDiagram->setSelectedRunway(rwy);
1125     } else if (m_ui->parkingRadio->isChecked()) {
1126         locationOnAirport =  QString("at parking position %1").arg(m_ui->parkingCombo->currentText());
1127     }
1128
1129     m_ui->airportDescription->setText(QString("%2 (%1): %3").arg(ident).arg(name).arg(locationOnAirport));
1130 }
1131
1132 void QtLauncher::onAirportChoiceSelected(const QModelIndex& index)
1133 {
1134     m_ui->locationStack->setCurrentIndex(0);
1135     setAirport(FGPositioned::loadById<FGAirport>(index.data(Qt::UserRole).toULongLong()));
1136 }
1137
1138 void QtLauncher::onOffsetBearingTrueChanged(bool on)
1139 {
1140     m_ui->offsetBearingLabel->setText(on ? tr("True bearing:") :
1141                                       tr("Magnetic bearing:"));
1142 }
1143
1144 void QtLauncher::onAircraftSelected(const QModelIndex& index)
1145 {
1146     m_selectedAircraft = index.data(AircraftURIRole).toUrl();
1147     updateSelectedAircraft();
1148 }
1149
1150 void QtLauncher::onRequestPackageInstall(const QModelIndex& index)
1151 {
1152     QString pkg = index.data(AircraftPackageIdRole).toString();
1153     simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString());
1154     if (pref->isInstalled()) {
1155         InstallRef install = pref->existingInstall();
1156         if (install && install->hasUpdate()) {
1157             globals->packageRoot()->scheduleToUpdate(install);
1158         }
1159     } else {
1160         pref->install();
1161     }
1162 }
1163
1164 void QtLauncher::onCancelDownload(const QModelIndex& index)
1165 {
1166     QString pkg = index.data(AircraftPackageIdRole).toString();
1167     simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString());
1168     simgear::pkg::InstallRef i = pref->existingInstall();
1169     i->cancelDownload();
1170 }
1171
1172 void QtLauncher::maybeUpdateSelectedAircraft(QModelIndex index)
1173 {
1174     QUrl u = index.data(AircraftURIRole).toUrl();
1175     if (u == m_selectedAircraft) {
1176         // potentially enable the run button now!
1177         updateSelectedAircraft();
1178     }
1179 }
1180
1181 void QtLauncher::updateSelectedAircraft()
1182 {
1183     QModelIndex index = m_aircraftModel->indexOfAircraftURI(m_selectedAircraft);
1184     if (index.isValid()) {
1185         QPixmap pm = index.data(Qt::DecorationRole).value<QPixmap>();
1186         m_ui->thumbnail->setPixmap(pm);
1187         m_ui->aircraftDescription->setText(index.data(Qt::DisplayRole).toString());
1188
1189         int status = index.data(AircraftPackageStatusRole).toInt();
1190         bool canRun = (status == PackageInstalled);
1191         m_ui->runButton->setEnabled(canRun);
1192     } else {
1193         m_ui->thumbnail->setPixmap(QPixmap());
1194         m_ui->aircraftDescription->setText("");
1195         m_ui->runButton->setEnabled(false);
1196     }
1197 }
1198
1199 void QtLauncher::onPopupAirportHistory()
1200 {
1201     if (m_recentAirports.isEmpty()) {
1202         return;
1203     }
1204
1205     QMenu m;
1206     Q_FOREACH(QString aptCode, m_recentAirports) {
1207         FGAirportRef apt = FGAirport::findByIdent(aptCode.toStdString());
1208         QString name = QString::fromStdString(apt->name());
1209         QAction* act = m.addAction(QString("%1 - %2").arg(aptCode).arg(name));
1210         act->setData(aptCode);
1211     }
1212
1213     QPoint popupPos = m_ui->airportHistory->mapToGlobal(m_ui->airportHistory->rect().bottomLeft());
1214     QAction* triggered = m.exec(popupPos);
1215     if (triggered) {
1216         FGAirportRef apt = FGAirport::findByIdent(triggered->data().toString().toStdString());
1217         setAirport(apt);
1218         m_ui->airportEdit->clear();
1219         m_ui->locationStack->setCurrentIndex(0);
1220     }
1221 }
1222
1223 QModelIndex QtLauncher::proxyIndexForAircraftURI(QUrl uri) const
1224 {
1225   return m_aircraftProxy->mapFromSource(sourceIndexForAircraftURI(uri));
1226 }
1227
1228 QModelIndex QtLauncher::sourceIndexForAircraftURI(QUrl uri) const
1229 {
1230     AircraftItemModel* sourceModel = qobject_cast<AircraftItemModel*>(m_aircraftProxy->sourceModel());
1231     Q_ASSERT(sourceModel);
1232     return sourceModel->indexOfAircraftURI(uri);
1233 }
1234
1235 void QtLauncher::onPopupAircraftHistory()
1236 {
1237     if (m_recentAircraft.isEmpty()) {
1238         return;
1239     }
1240
1241     QMenu m;
1242     Q_FOREACH(QUrl uri, m_recentAircraft) {
1243         QModelIndex index = sourceIndexForAircraftURI(uri);
1244         if (!index.isValid()) {
1245             // not scanned yet
1246             continue;
1247         }
1248         QAction* act = m.addAction(index.data(Qt::DisplayRole).toString());
1249         act->setData(uri);
1250     }
1251
1252     QPoint popupPos = m_ui->aircraftHistory->mapToGlobal(m_ui->aircraftHistory->rect().bottomLeft());
1253     QAction* triggered = m.exec(popupPos);
1254     if (triggered) {
1255         m_selectedAircraft = triggered->data().toUrl();
1256         QModelIndex index = proxyIndexForAircraftURI(m_selectedAircraft);
1257         m_ui->aircraftList->selectionModel()->setCurrentIndex(index,
1258                                                               QItemSelectionModel::ClearAndSelect);
1259         m_ui->aircraftFilter->clear();
1260         updateSelectedAircraft();
1261     }
1262 }
1263
1264 void QtLauncher::setAirport(FGAirportRef ref)
1265 {
1266     if (m_selectedAirport == ref)
1267         return;
1268
1269     m_selectedAirport = ref;
1270     onAirportChanged();
1271
1272     if (ref.valid()) {
1273         // maintain the recent airport list
1274         QString icao = QString::fromStdString(ref->ident());
1275         if (m_recentAirports.contains(icao)) {
1276             // move to front
1277             m_recentAirports.removeOne(icao);
1278             m_recentAirports.push_front(icao);
1279         } else {
1280             // insert and trim list if necessary
1281             m_recentAirports.push_front(icao);
1282             if (m_recentAirports.size() > MAX_RECENT_AIRPORTS) {
1283                 m_recentAirports.pop_back();
1284             }
1285         }
1286     }
1287
1288     updateAirportDescription();
1289 }
1290
1291 void QtLauncher::onEditRatingsFilter()
1292 {
1293     EditRatingsFilterDialog dialog(this);
1294     dialog.setRatings(m_ratingFilters);
1295
1296     dialog.exec();
1297     if (dialog.result() == QDialog::Accepted) {
1298         QVariantList vl;
1299         for (int i=0; i<4; ++i) {
1300             m_ratingFilters[i] = dialog.getRating(i);
1301             vl.append(m_ratingFilters[i]);
1302         }
1303         m_aircraftProxy->setRatings(m_ratingFilters);
1304
1305         QSettings settings;
1306         settings.setValue("min-ratings", vl);
1307     }
1308 }
1309
1310 void QtLauncher::updateSettingsSummary()
1311 {
1312     QStringList summary;
1313     if (m_ui->timeOfDayCombo->currentIndex() > 0) {
1314         summary.append(QString(m_ui->timeOfDayCombo->currentText().toLower()));
1315     }
1316
1317     if (m_ui->seasonCombo->currentIndex() > 0) {
1318         summary.append(QString(m_ui->seasonCombo->currentText().toLower()));
1319     }
1320
1321     if (m_ui->rembrandtCheckbox->isChecked()) {
1322         summary.append("Rembrandt enabled");
1323     } else if (m_ui->msaaCheckbox->isChecked()) {
1324         summary.append("anti-aliasing");
1325     }
1326
1327     if (m_ui->fetchRealWxrCheckbox->isChecked()) {
1328         summary.append("live weather");
1329     }
1330
1331     if (m_ui->terrasyncCheck->isChecked()) {
1332         summary.append("automatic scenery downloads");
1333     }
1334
1335     if (m_ui->startPausedCheck->isChecked()) {
1336         summary.append("paused");
1337     }
1338
1339     QString s = summary.join(", ");
1340     s[0] = s[0].toUpper();
1341     m_ui->settingsDescription->setText(s);
1342 }
1343
1344 void QtLauncher::onRembrandtToggled(bool b)
1345 {
1346     // Rembrandt and multi-sample are exclusive
1347     m_ui->msaaCheckbox->setEnabled(!b);
1348 }
1349
1350 void QtLauncher::onSubsytemIdleTimeout()
1351 {
1352     globals->get_subsystem_mgr()->update(0.0);
1353 }
1354
1355 void QtLauncher::onEditPaths()
1356 {
1357     PathsDialog dlg(this, globals->packageRoot());
1358     dlg.exec();
1359     if (dlg.result() == QDialog::Accepted) {
1360         // re-scan the aircraft list
1361         QSettings settings;
1362         m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList());
1363         m_aircraftModel->scanDirs();
1364     }
1365 }
1366
1367 simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const
1368 {
1369     if (uri.scheme() != "package") {
1370         qWarning() << "invalid URL scheme:" << uri;
1371         return simgear::pkg::PackageRef();
1372     }
1373
1374     QString ident = uri.path();
1375     return globals->packageRoot()->getPackageById(ident.toStdString());
1376 }
1377
1378 void QtLauncher::onOffsetDataChanged()
1379 {
1380     qDebug() << "implement me";
1381 }
1382
1383 #include "QtLauncher.moc"