2018-03-22 12:24:57 +00:00
|
|
|
// LauncherController.hxx - GUI launcher dialog using Qt5
|
|
|
|
//
|
|
|
|
// Written by James Turner, started March 2018.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2018 James Turner <james@flightgear.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef LAUNCHERCONTROLLER_HXX
|
|
|
|
#define LAUNCHERCONTROLLER_HXX
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QModelIndex>
|
2018-07-02 10:49:34 +00:00
|
|
|
#include <QSize>
|
2018-03-22 12:24:57 +00:00
|
|
|
|
|
|
|
#include <simgear/package/Package.hxx>
|
|
|
|
#include <simgear/package/Catalog.hxx>
|
|
|
|
|
|
|
|
// forward decls
|
2018-06-22 11:09:35 +00:00
|
|
|
class QTimer;
|
|
|
|
class QWindow;
|
2018-03-22 12:24:57 +00:00
|
|
|
class AircraftProxyModel;
|
|
|
|
class QmlAircraftInfo;
|
|
|
|
class RecentAircraftModel;
|
|
|
|
class RecentLocationsModel;
|
|
|
|
class MPServersModel;
|
|
|
|
class AircraftItemModel;
|
|
|
|
class QQuickItem;
|
|
|
|
class LaunchConfig;
|
2018-05-07 15:41:10 +00:00
|
|
|
class LocationController;
|
2018-08-11 20:05:04 +00:00
|
|
|
class FlightPlanController;
|
2018-03-22 12:24:57 +00:00
|
|
|
|
|
|
|
class LauncherController : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(AircraftProxyModel* installedAircraftModel MEMBER m_installedAircraftModel CONSTANT)
|
2018-06-28 22:45:52 +00:00
|
|
|
Q_PROPERTY(AircraftProxyModel* aircraftWithUpdatesModel MEMBER m_aircraftWithUpdatesModel CONSTANT)
|
2018-03-22 12:24:57 +00:00
|
|
|
Q_PROPERTY(AircraftProxyModel* browseAircraftModel MEMBER m_browseAircraftModel CONSTANT)
|
|
|
|
Q_PROPERTY(AircraftProxyModel* searchAircraftModel MEMBER m_aircraftSearchModel CONSTANT)
|
|
|
|
|
|
|
|
Q_PROPERTY(AircraftItemModel* baseAircraftModel MEMBER m_aircraftModel CONSTANT)
|
|
|
|
|
2018-05-07 15:41:10 +00:00
|
|
|
Q_PROPERTY(LocationController* location MEMBER m_location CONSTANT)
|
2018-08-11 20:05:04 +00:00
|
|
|
Q_PROPERTY(FlightPlanController* flightPlan MEMBER m_flightPlan CONSTANT)
|
2018-05-07 15:41:10 +00:00
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
Q_PROPERTY(MPServersModel* mpServersModel MEMBER m_serversModel CONSTANT)
|
|
|
|
|
|
|
|
Q_PROPERTY(QUrl selectedAircraft READ selectedAircraft WRITE setSelectedAircraft NOTIFY selectedAircraftChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(QmlAircraftInfo* selectedAircraftInfo READ selectedAircraftInfo NOTIFY selectedAircraftChanged)
|
|
|
|
|
2018-06-27 22:06:39 +00:00
|
|
|
Q_PROPERTY(QString selectedAircraftState MEMBER m_aircraftState NOTIFY selectedAircraftStateChanged)
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
Q_PROPERTY(bool isSearchActive READ isSearchActive NOTIFY searchChanged)
|
|
|
|
Q_PROPERTY(QString settingsSearchTerm READ settingsSearchTerm WRITE setSettingsSearchTerm NOTIFY searchChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(QStringList settingsSummary READ settingsSummary WRITE setSettingsSummary NOTIFY summaryChanged)
|
|
|
|
Q_PROPERTY(QStringList environmentSummary READ environmentSummary WRITE setEnvironmentSummary NOTIFY summaryChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(QStringList combinedSummary READ combinedSummary NOTIFY summaryChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(QString versionString READ versionString CONSTANT)
|
|
|
|
|
|
|
|
Q_PROPERTY(RecentAircraftModel* aircraftHistory READ aircraftHistory CONSTANT)
|
|
|
|
Q_PROPERTY(RecentLocationsModel* locationHistory READ locationHistory CONSTANT)
|
|
|
|
|
|
|
|
Q_PROPERTY(bool canFly READ canFly NOTIFY canFlyChanged)
|
2018-05-07 15:41:10 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(AircraftType aircraftType READ aircraftType NOTIFY selectedAircraftChanged)
|
2018-07-02 10:49:34 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(QSize minimumWindowSize READ minWindowSize WRITE setMinWindowSize NOTIFY minWindowSizeChanged)
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
public:
|
2018-06-22 11:09:35 +00:00
|
|
|
explicit LauncherController(QObject *parent, QWindow* win);
|
2018-03-22 12:24:57 +00:00
|
|
|
|
|
|
|
void initQML();
|
|
|
|
|
|
|
|
Q_INVOKABLE bool validateMetarString(QString metar);
|
|
|
|
|
|
|
|
Q_INVOKABLE void requestInstallUpdate(QUrl aircraftUri);
|
|
|
|
|
|
|
|
Q_INVOKABLE void requestUninstall(QUrl aircraftUri);
|
|
|
|
|
|
|
|
Q_INVOKABLE void requestInstallCancel(QUrl aircraftUri);
|
|
|
|
|
|
|
|
Q_INVOKABLE void downloadDirChanged(QString path);
|
|
|
|
|
|
|
|
Q_INVOKABLE void requestUpdateAllAircraft();
|
|
|
|
|
|
|
|
Q_INVOKABLE void queryMPServers();
|
|
|
|
|
|
|
|
QUrl selectedAircraft() const;
|
|
|
|
|
|
|
|
// work around the fact, that this is not available on QQuickItem until 5.7
|
|
|
|
Q_INVOKABLE QPointF mapToGlobal(QQuickItem* item, const QPointF& pos) const;
|
|
|
|
|
|
|
|
QmlAircraftInfo* selectedAircraftInfo() const;
|
|
|
|
|
|
|
|
Q_INVOKABLE void restoreLocation(QVariant var);
|
|
|
|
|
|
|
|
Q_INVOKABLE bool matchesSearch(QString term, QStringList keywords) const;
|
|
|
|
|
|
|
|
bool isSearchActive() const;
|
|
|
|
|
|
|
|
QString settingsSearchTerm() const
|
|
|
|
{
|
|
|
|
return m_settingsSearchTerm;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList settingsSummary() const;
|
|
|
|
|
|
|
|
QStringList environmentSummary() const;
|
|
|
|
|
|
|
|
QStringList combinedSummary() const;
|
|
|
|
|
|
|
|
QString versionString() const;
|
|
|
|
|
|
|
|
RecentAircraftModel* aircraftHistory();
|
|
|
|
|
|
|
|
RecentLocationsModel* locationHistory();
|
|
|
|
|
|
|
|
Q_INVOKABLE void launchUrl(QUrl url);
|
|
|
|
|
|
|
|
// list of QUrls containing the default splash images from FGData.
|
|
|
|
// used on the summary screen
|
|
|
|
Q_INVOKABLE QVariantList defaultSplashUrls() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LaunchConfig* config() const
|
|
|
|
{ return m_config; }
|
|
|
|
|
|
|
|
void doRun();
|
|
|
|
void doApply();
|
|
|
|
|
|
|
|
bool canFly() const;
|
|
|
|
|
|
|
|
AircraftItemModel* baseAircraftModel() const
|
|
|
|
{ return m_aircraftModel; }
|
|
|
|
|
2018-06-27 22:06:39 +00:00
|
|
|
void initialRestoreSettings();
|
2018-03-22 12:24:57 +00:00
|
|
|
void saveSettings();
|
2018-05-07 15:41:10 +00:00
|
|
|
|
|
|
|
LocationController* location() const
|
|
|
|
{ return m_location; }
|
|
|
|
|
|
|
|
enum AircraftType
|
|
|
|
{
|
2018-07-25 08:27:14 +00:00
|
|
|
Unknown = 0,
|
|
|
|
Airplane,
|
2018-05-07 15:41:10 +00:00
|
|
|
Seaplane,
|
|
|
|
Helicopter,
|
|
|
|
Airship
|
|
|
|
};
|
|
|
|
|
2018-06-15 09:33:00 +00:00
|
|
|
Q_ENUMS(AircraftType)
|
2018-05-07 15:41:10 +00:00
|
|
|
|
|
|
|
AircraftType aircraftType() const
|
|
|
|
{ return m_aircraftType; }
|
2018-06-23 16:55:39 +00:00
|
|
|
|
|
|
|
void setInAppMode();
|
|
|
|
bool keepRunningInAppMode() const;
|
|
|
|
bool inAppResult() const;
|
2018-07-02 10:49:34 +00:00
|
|
|
|
|
|
|
QSize minWindowSize() const
|
|
|
|
{
|
|
|
|
return m_minWindowSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMinWindowSize(QSize sz);
|
2018-03-22 12:24:57 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void selectedAircraftChanged(QUrl selectedAircraft);
|
2018-06-27 22:06:39 +00:00
|
|
|
void selectedAircraftStateChanged();
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
void searchChanged();
|
|
|
|
void summaryChanged();
|
2018-07-02 10:49:34 +00:00
|
|
|
void minWindowSizeChanged();
|
2018-03-22 12:24:57 +00:00
|
|
|
void canFlyChanged();
|
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
void viewCommandLine();
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
public slots:
|
|
|
|
void setSelectedAircraft(QUrl selectedAircraft);
|
|
|
|
|
|
|
|
void setSettingsSearchTerm(QString settingsSearchTerm);
|
|
|
|
|
|
|
|
void setSettingsSummary(QStringList settingsSummary);
|
|
|
|
|
|
|
|
void setEnvironmentSummary(QStringList environmentSummary);
|
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
void fly();
|
2018-06-26 16:13:28 +00:00
|
|
|
void quit();
|
2018-06-22 11:09:35 +00:00
|
|
|
|
2018-06-26 16:13:28 +00:00
|
|
|
void requestRestoreDefaults();
|
|
|
|
|
|
|
|
void requestChangeDataPath();
|
2018-06-27 22:06:39 +00:00
|
|
|
|
|
|
|
void openConfig();
|
|
|
|
void saveConfigAs();
|
2018-03-22 12:24:57 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
void onAircraftInstalledCompleted(QModelIndex index);
|
|
|
|
void onAircraftInstallFailed(QModelIndex index, QString errorMessage);
|
|
|
|
|
2018-06-27 22:06:39 +00:00
|
|
|
void saveAircraft();
|
|
|
|
void restoreAircraft();
|
2018-03-22 12:24:57 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Check if the passed index is the selected aircraft, and if so, refresh
|
|
|
|
* the associated UI data
|
|
|
|
*/
|
|
|
|
void maybeUpdateSelectedAircraft(QModelIndex index);
|
|
|
|
void updateSelectedAircraft();
|
|
|
|
|
|
|
|
|
|
|
|
simgear::pkg::PackageRef packageForAircraftURI(QUrl uri) const;
|
|
|
|
|
|
|
|
// need to wait after a model reset before restoring selection and
|
|
|
|
// scrolling, to give the view time it seems.
|
|
|
|
void delayedAircraftModelReset();
|
|
|
|
|
|
|
|
void collectAircraftArgs();
|
|
|
|
|
2018-06-27 22:06:39 +00:00
|
|
|
QString selectAircraftStateAutomatically();
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
private:
|
2018-06-22 11:09:35 +00:00
|
|
|
QWindow* m_window = nullptr;
|
|
|
|
|
2018-03-22 12:24:57 +00:00
|
|
|
AircraftProxyModel* m_installedAircraftModel;
|
|
|
|
AircraftItemModel* m_aircraftModel;
|
|
|
|
AircraftProxyModel* m_aircraftSearchModel;
|
|
|
|
AircraftProxyModel* m_browseAircraftModel;
|
2018-06-28 22:45:52 +00:00
|
|
|
AircraftProxyModel* m_aircraftWithUpdatesModel;
|
2018-03-22 12:24:57 +00:00
|
|
|
MPServersModel* m_serversModel = nullptr;
|
2018-05-07 15:41:10 +00:00
|
|
|
LocationController* m_location = nullptr;
|
2018-08-11 20:05:04 +00:00
|
|
|
FlightPlanController* m_flightPlan = nullptr;
|
2018-03-22 12:24:57 +00:00
|
|
|
|
|
|
|
QUrl m_selectedAircraft;
|
2018-06-27 22:06:39 +00:00
|
|
|
QString m_aircraftState;
|
2018-05-07 15:41:10 +00:00
|
|
|
AircraftType m_aircraftType = Airplane;
|
2018-03-22 12:24:57 +00:00
|
|
|
int m_ratingFilters[4] = {3, 3, 3, 3};
|
|
|
|
LaunchConfig* m_config = nullptr;
|
|
|
|
QmlAircraftInfo* m_selectedAircraftInfo = nullptr;
|
|
|
|
QString m_settingsSearchTerm;
|
|
|
|
QStringList m_settingsSummary, m_environmentSummary;
|
|
|
|
RecentAircraftModel* m_aircraftHistory = nullptr;
|
|
|
|
RecentLocationsModel* m_locationHistory = nullptr;
|
2018-07-02 10:49:34 +00:00
|
|
|
QSize m_minWindowSize;
|
2018-06-22 11:09:35 +00:00
|
|
|
QTimer* m_subsystemIdleTimer = nullptr;
|
2018-06-23 16:55:39 +00:00
|
|
|
|
|
|
|
bool m_inAppMode = false;
|
|
|
|
bool m_keepRunningInAppMode = false;
|
|
|
|
bool m_appModeResult = true;
|
2018-03-22 12:24:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LAUNCHERCONTROLLER_HXX
|