"Fossies" - the Fresh Open Source Software Archive

Member "flightgear-2020.3.8/src/GUI/LauncherController.hxx" (24 Mar 2021, 10372 Bytes) of package /linux/privat/flightgear-2020.3.8.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "LauncherController.hxx" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2020.3.7_vs_2020.3.8.

    1 // LauncherController.hxx - GUI launcher dialog using Qt5
    2 //
    3 // Written by James Turner, started March 2018.
    4 //
    5 // Copyright (C) 2018 James Turner <james@flightgear.org>
    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 #ifndef LAUNCHERCONTROLLER_HXX
   22 #define LAUNCHERCONTROLLER_HXX
   23 
   24 #include <QObject>
   25 #include <QUrl>
   26 #include <QModelIndex>
   27 #include <QSize>
   28 
   29 #include <simgear/package/Package.hxx>
   30 #include <simgear/package/Catalog.hxx>
   31 
   32 // forward decls
   33 class QTimer;
   34 class QWindow;
   35 class AircraftProxyModel;
   36 class QmlAircraftInfo;
   37 class RecentAircraftModel;
   38 class RecentLocationsModel;
   39 class MPServersModel;
   40 class AircraftItemModel;
   41 class QQuickItem;
   42 class LaunchConfig;
   43 class LocationController;
   44 class FlightPlanController;
   45 
   46 class LauncherController : public QObject
   47 {
   48     Q_OBJECT
   49 
   50     Q_PROPERTY(AircraftProxyModel* installedAircraftModel MEMBER m_installedAircraftModel CONSTANT)
   51     Q_PROPERTY(AircraftProxyModel* aircraftWithUpdatesModel MEMBER m_aircraftWithUpdatesModel CONSTANT)
   52     Q_PROPERTY(AircraftProxyModel* browseAircraftModel MEMBER m_browseAircraftModel CONSTANT)
   53     Q_PROPERTY(AircraftProxyModel* searchAircraftModel MEMBER m_aircraftSearchModel CONSTANT)
   54     Q_PROPERTY(AircraftProxyModel* favouriteAircraftModel MEMBER m_favouriteAircraftModel CONSTANT)
   55 
   56     Q_PROPERTY(AircraftItemModel* baseAircraftModel MEMBER m_aircraftModel CONSTANT)
   57 
   58     Q_PROPERTY(LocationController* location MEMBER m_location CONSTANT)
   59     Q_PROPERTY(FlightPlanController* flightPlan MEMBER m_flightPlan CONSTANT)
   60 
   61     Q_PROPERTY(MPServersModel* mpServersModel MEMBER m_serversModel CONSTANT)
   62 
   63     Q_PROPERTY(QUrl selectedAircraft READ selectedAircraft WRITE setSelectedAircraft NOTIFY selectedAircraftChanged)
   64 
   65     Q_PROPERTY(QmlAircraftInfo* selectedAircraftInfo READ selectedAircraftInfo NOTIFY selectedAircraftChanged)
   66 
   67     Q_PROPERTY(QString selectedAircraftState MEMBER m_aircraftState NOTIFY selectedAircraftStateChanged)
   68 
   69     Q_PROPERTY(bool isSearchActive READ isSearchActive NOTIFY searchChanged)
   70     Q_PROPERTY(QString settingsSearchTerm READ settingsSearchTerm WRITE setSettingsSearchTerm NOTIFY searchChanged)
   71 
   72     Q_PROPERTY(QStringList settingsSummary READ settingsSummary WRITE setSettingsSummary NOTIFY summaryChanged)
   73     Q_PROPERTY(QStringList environmentSummary READ environmentSummary WRITE setEnvironmentSummary NOTIFY summaryChanged)
   74 
   75     Q_PROPERTY(QStringList combinedSummary READ combinedSummary NOTIFY summaryChanged)
   76 
   77     Q_PROPERTY(QString versionString READ versionString CONSTANT)
   78 
   79     Q_PROPERTY(RecentAircraftModel* aircraftHistory READ aircraftHistory CONSTANT)
   80     Q_PROPERTY(RecentLocationsModel* locationHistory READ locationHistory CONSTANT)
   81 
   82     Q_PROPERTY(bool canFly READ canFly NOTIFY canFlyChanged)
   83 
   84     Q_PROPERTY(AircraftType aircraftType READ aircraftType NOTIFY selectedAircraftChanged)
   85 
   86     Q_PROPERTY(QSize minimumWindowSize READ minWindowSize WRITE setMinWindowSize NOTIFY minWindowSizeChanged)
   87 
   88     Q_PROPERTY(QUrl flyIconUrl READ flyIconUrl NOTIFY selectedAircraftChanged)
   89     Q_PROPERTY(QUrl flyButtonLabel READ flyButtonLabel NOTIFY selectedAircraftChanged)
   90 
   91     Q_PROPERTY(bool inAppMode READ inApp NOTIFY inAppChanged)
   92 
   93     Q_PROPERTY(bool aircraftGridMode READ aircraftGridMode WRITE setAircraftGridMode NOTIFY aircraftGridModeChanged)
   94 
   95     Q_PROPERTY(int launchCount READ launchCount CONSTANT);
   96     Q_PROPERTY(int versionLaunchCount READ versionLaunchCount CONSTANT);
   97 
   98     // property to indicate if we're disabling the aircraft selection because the user entered it manuall
   99     Q_PROPERTY(bool skipAircraftFromArgs MEMBER m_skipAircraftFromArgs NOTIFY skipAircraftFromArgsChanged)
  100 public:
  101     explicit LauncherController(QObject *parent, QWindow* win);
  102 
  103     void initQML();
  104 
  105     Q_INVOKABLE bool validateMetarString(QString metar);
  106 
  107     Q_INVOKABLE void requestInstallUpdate(QUrl aircraftUri);
  108 
  109     Q_INVOKABLE void requestUninstall(QUrl aircraftUri);
  110 
  111     Q_INVOKABLE void requestInstallCancel(QUrl aircraftUri);
  112 
  113     Q_INVOKABLE void downloadDirChanged(QString path);
  114 
  115     Q_INVOKABLE void requestUpdateAllAircraft();
  116 
  117     Q_INVOKABLE void queryMPServers();
  118 
  119     QUrl selectedAircraft() const;
  120 
  121     // work around the fact, that this is not available on QQuickItem until 5.7
  122     Q_INVOKABLE QPointF mapToGlobal(QQuickItem* item, const QPointF& pos) const;
  123 
  124     QmlAircraftInfo* selectedAircraftInfo() const;
  125 
  126     Q_INVOKABLE void restoreLocation(QVariant var);
  127 
  128     Q_INVOKABLE bool matchesSearch(QString term, QStringList keywords) const;
  129 
  130     bool isSearchActive() const;
  131 
  132     QString settingsSearchTerm() const
  133     {
  134         return m_settingsSearchTerm;
  135     }
  136 
  137     QStringList settingsSummary() const;
  138 
  139     QStringList environmentSummary() const;
  140 
  141     QStringList combinedSummary() const;
  142 
  143     QString versionString() const;
  144 
  145     RecentAircraftModel* aircraftHistory();
  146 
  147     RecentLocationsModel* locationHistory();
  148 
  149     Q_INVOKABLE void launchUrl(QUrl url);
  150 
  151     // list of QUrls containing the default splash images from FGData.
  152     // used on the summary screen
  153     Q_INVOKABLE QVariantList defaultSplashUrls() const;
  154 
  155     Q_INVOKABLE QVariant loadUISetting(QString name, QVariant defaultValue) const;
  156     Q_INVOKABLE void saveUISetting(QString name, QVariant value) const;
  157 
  158     /**
  159      * @brief urlToDataPath - convetr  a FGData path into a gloabl file:/// URL suitable for Qt.openExternally()
  160      * @param relPath - the path rlative to FG_ROOT
  161      * @return a file QUrl
  162      */
  163     Q_INVOKABLE QUrl urlToDataPath(QString relPath) const;
  164 
  165     LaunchConfig* config() const
  166     { return m_config; }
  167 
  168     void doRun();
  169     void doApply();
  170 
  171     bool canFly() const;
  172 
  173     AircraftItemModel* baseAircraftModel() const
  174     { return m_aircraftModel; }
  175 
  176     void initialRestoreSettings();
  177     void saveSettings();
  178 
  179     LocationController* location() const
  180     { return m_location; }
  181 
  182     enum AircraftType
  183     {
  184         Unknown = 0,
  185         Airplane,
  186         Seaplane,
  187         Helicopter,
  188         Airship
  189     };
  190 
  191     Q_ENUMS(AircraftType)
  192 
  193     AircraftType aircraftType() const
  194     { return m_aircraftType; }
  195 
  196     void setInAppMode();
  197     bool keepRunningInAppMode() const;
  198     bool inAppResult() const;
  199 
  200     QSize minWindowSize() const 
  201     {
  202         return m_minWindowSize; 
  203     }
  204 
  205     void setMinWindowSize(QSize sz);
  206 
  207     QUrl flyIconUrl() const;
  208 
  209     bool aircraftGridMode() const
  210     {
  211         return m_aircraftGridMode;
  212     }
  213 
  214     bool  inApp() const
  215     {
  216         return m_inAppMode;
  217     }
  218 
  219     int launchCount() const
  220     {
  221         return m_launchCount;
  222     }
  223 
  224     int versionLaunchCount() const
  225     {
  226         return m_versionLaunchCount;
  227     }
  228 
  229     QString flyButtonLabel() const;
  230 signals:
  231 
  232     void selectedAircraftChanged(QUrl selectedAircraft);
  233     void selectedAircraftStateChanged();
  234     
  235     void searchChanged();
  236     void summaryChanged();
  237     void minWindowSizeChanged();
  238     void canFlyChanged();
  239 
  240     void viewCommandLine();
  241 
  242     void aircraftGridModeChanged(bool aircraftGridMode);
  243 
  244     void inAppChanged();
  245     void installedAircraftCountChanged(int installedAircraftCount);
  246 
  247     void didResetGettingStartedTips();
  248     void skipAircraftFromArgsChanged();
  249 public slots:
  250     void setSelectedAircraft(QUrl selectedAircraft);
  251 
  252     void setSettingsSearchTerm(QString settingsSearchTerm);
  253 
  254     void setSettingsSummary(QStringList settingsSummary);
  255 
  256     void setEnvironmentSummary(QStringList environmentSummary);
  257 
  258     void fly();
  259     void quit();
  260 
  261     void requestRestoreDefaults();
  262 
  263     void requestChangeDataPath();
  264 
  265     void openConfig();
  266     void saveConfigAs();
  267     void setAircraftGridMode(bool aircraftGridMode);
  268 
  269     void resetGettingStartedTips();
  270 
  271 private slots:
  272 
  273     void onAircraftInstalledCompleted(QModelIndex index);
  274     void onAircraftInstallFailed(QModelIndex index, QString errorMessage);
  275 
  276     void saveAircraft();
  277     void restoreAircraft();
  278 
  279     void checkForOldDownloadDir();
  280 
  281 private:
  282     /**
  283      * Check if the passed index is the selected aircraft, and if so, refresh
  284      * the associated UI data
  285      */
  286     void maybeUpdateSelectedAircraft(QModelIndex index);
  287     void updateSelectedAircraft();
  288 
  289 
  290     simgear::pkg::PackageRef packageForAircraftURI(QUrl uri) const;
  291 
  292     // need to wait after a model reset before restoring selection and
  293     // scrolling, to give the view time it seems.
  294     void delayedAircraftModelReset();
  295 
  296     void collectAircraftArgs();
  297 
  298     QString selectAircraftStateAutomatically();
  299     bool haveOldWindowsDownloadDir() const;
  300 
  301 private:
  302     QWindow* m_window = nullptr;
  303 
  304     AircraftProxyModel* m_installedAircraftModel;
  305     AircraftItemModel* m_aircraftModel;
  306     AircraftProxyModel* m_aircraftSearchModel;
  307     AircraftProxyModel* m_browseAircraftModel;
  308     AircraftProxyModel* m_aircraftWithUpdatesModel;
  309     AircraftProxyModel* m_favouriteAircraftModel;
  310 
  311     MPServersModel* m_serversModel = nullptr;
  312     LocationController* m_location = nullptr;
  313     FlightPlanController* m_flightPlan = nullptr;
  314 
  315     QUrl m_selectedAircraft;
  316     QString m_aircraftState;
  317     AircraftType m_aircraftType = Airplane;
  318     int m_ratingFilters[4] = {3, 3, 3, 3};
  319     LaunchConfig* m_config = nullptr;
  320     QmlAircraftInfo* m_selectedAircraftInfo = nullptr;
  321     QString m_settingsSearchTerm;
  322     QStringList m_settingsSummary, m_environmentSummary;
  323     RecentAircraftModel* m_aircraftHistory = nullptr;
  324     RecentLocationsModel* m_locationHistory = nullptr;
  325     QSize m_minWindowSize;
  326     QTimer* m_subsystemIdleTimer = nullptr;
  327 
  328     bool m_inAppMode = false;
  329     bool m_keepRunningInAppMode = false;
  330     bool m_appModeResult = true;
  331     bool m_aircraftGridMode;
  332     int m_launchCount = 0;
  333     int m_versionLaunchCount = 0;
  334     bool m_flyRequested = false;
  335     bool m_skipAircraftFromArgs = false;
  336 };
  337 
  338 #endif // LAUNCHERCONTROLLER_HXX