1
0
Fork 0

Modifications to the Launcher to enable the management of Add-on modules

This commit is contained in:
danw 2019-02-02 15:46:09 -05:00
parent f05c0297c0
commit 1c4e146a43
5 changed files with 135 additions and 1 deletions

View file

@ -34,6 +34,7 @@ AddOnsController::AddOnsController(LauncherMainWindow *parent) :
QSettings settings;
m_sceneryPaths = settings.value("scenery-paths").toStringList();
m_aircraftPaths = settings.value("aircraft-paths").toStringList();
m_addonModulePaths = settings.value("addon-module-paths").toStringList();
qmlRegisterUncreatableType<AddOnsController>("FlightGear.Launcher", 1, 0, "AddOnsControllers", "no");
qmlRegisterUncreatableType<CatalogListModel>("FlightGear.Launcher", 1, 0, "CatalogListModel", "no");
@ -49,6 +50,11 @@ QStringList AddOnsController::sceneryPaths() const
return m_sceneryPaths;
}
QStringList AddOnsController::modulePaths() const
{
return m_addonModulePaths;
}
QString AddOnsController::addAircraftPath() const
{
QString path = QFileDialog::getExistingDirectory(nullptr, tr("Choose aircraft folder"));
@ -88,6 +94,43 @@ QString AddOnsController::addAircraftPath() const
return path;
}
QString AddOnsController::addAddOnModulePath() const
{
QString path = QFileDialog::getExistingDirectory(nullptr, tr("Choose addon module folder"));
if (path.isEmpty()) {
return {};
}
// validation
SGPath p(path.toStdString());
bool isValid = false;
for (const auto& file: {"addon-config.xml", "addon-main.nas"}) {
if ((p / file).exists()) {
isValid = true;
break;
}
}
if (!isValid) {
QMessageBox mb;
mb.setText(tr("The folder '%1' doesn't appear to contain an addon module - add anyway?").arg(path));
mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
mb.setDefaultButton(QMessageBox::No);
mb.setInformativeText(tr("Added modules should contain at least both of the following "
"files: addon-config.xml, addon-main.nas."));
mb.exec();
if (mb.result() == QMessageBox::No) {
return {};
}
}
return path;
}
QString AddOnsController::addSceneryPath() const
{
QString path = QFileDialog::getExistingDirectory(nullptr, tr("Choose scenery folder"));
@ -173,6 +216,19 @@ void AddOnsController::setSceneryPaths(QStringList sceneryPaths)
emit sceneryPathsChanged(m_sceneryPaths);
}
void AddOnsController::setModulePaths(QStringList modulePaths)
{
if (m_addonModulePaths == modulePaths)
return;
m_addonModulePaths = modulePaths;
QSettings settings;
settings.setValue("addon-module-paths", m_addonModulePaths);
emit modulePathsChanged(m_addonModulePaths);
}
void AddOnsController::officialCatalogAction(QString s)
{
if (s == "hide") {

View file

@ -13,6 +13,7 @@ class AddOnsController : public QObject
Q_PROPERTY(QStringList aircraftPaths READ aircraftPaths WRITE setAircraftPaths NOTIFY aircraftPathsChanged)
Q_PROPERTY(QStringList sceneryPaths READ sceneryPaths WRITE setSceneryPaths NOTIFY sceneryPathsChanged)
Q_PROPERTY(QStringList modulePaths READ modulePaths WRITE setModulePaths NOTIFY modulePathsChanged)
Q_PROPERTY(CatalogListModel* catalogs READ catalogs CONSTANT)
@ -24,12 +25,14 @@ public:
QStringList aircraftPaths() const;
QStringList sceneryPaths() const;
QStringList modulePaths() const;
CatalogListModel* catalogs() const
{ return m_catalogs; }
Q_INVOKABLE QString addAircraftPath() const;
Q_INVOKABLE QString addSceneryPath() const;
Q_INVOKABLE QString addAddOnModulePath() const;
// we would ideally do this in-page, but needs some extra work
Q_INVOKABLE QString installCustomScenery();
@ -44,6 +47,7 @@ public:
signals:
void aircraftPathsChanged(QStringList aircraftPaths);
void sceneryPathsChanged(QStringList sceneryPaths);
void modulePathsChanged(QStringList modulePaths);
void isOfficialHangarRegisteredChanged();
void showNoOfficialHangarChanged();
@ -51,6 +55,7 @@ signals:
public slots:
void setAircraftPaths(QStringList aircraftPaths);
void setSceneryPaths(QStringList sceneryPaths);
void setModulePaths(QStringList modulePaths);
private:
bool shouldShowOfficialCatalogMessage() const;
@ -60,6 +65,7 @@ private:
CatalogListModel* m_catalogs = nullptr;
QStringList m_aircraftPaths;
QStringList m_sceneryPaths;
QStringList m_addonModulePaths;
};
#endif // ADDONSCONTROLLER_HXX

View file

@ -291,6 +291,10 @@ void LauncherController::collectAircraftArgs()
Q_FOREACH(QString path, settings.value("aircraft-paths").toStringList()) {
m_config->setArg("fg-aircraft", path);
}
Q_FOREACH(QString path, settings.value("addon-module-paths").toStringList()) {
m_config->setArg("addon", path);
}
}
void LauncherController::saveAircraft()

View file

@ -63,6 +63,8 @@
#include <Navaids/navrecord.hxx>
#include <Navaids/SHPParser.hxx>
#include <Airports/airport.hxx>
#include <Add-ons/AddonManager.hxx>
#include <Main/options.hxx>
#include <Main/fg_init.hxx>
@ -391,7 +393,6 @@ void restartTheApp()
qApp->exit(-1);
}
void launcherSetSceneryPaths()
{
globals->clear_fg_scenery();

View file

@ -129,6 +129,73 @@ Item {
}
//////////////////////////////////////////////////////////////////
Item {
// spacing item
width: parent.width
height: Style.margin * 2
}
AddOnsHeader {
id: addonModuleHeader
title: qsTr("Add-on Module folders")
description: qsTr("To use Add-on Modules that you download yourself, FlightGear needs to " +
"know the folder(s) containing the Add-on Modules.")
showAddButton: true
onAdd: {
var newPath =_addOns.addAddOnModulePath();
if (newPath !== "") {
_addOns.modulePaths.push(newPath)
}
}
}
Rectangle {
width: parent.width
height: addonModulePathsColumn.childrenRect.height + 1
border.width: 1
border.color: Style.frameColor
clip: true
Column {
id: addonModulePathsColumn
width: parent.width - Style.margin * 2
x: Style.margin
Repeater {
id: addonModulesPathsRepeater
model: _addOns.modulePaths
delegate: PathListDelegate {
width: addonModulePathsColumn.width
deletePromptText: qsTr("Remove the add-on module folder: '%1' from the list? (The folder contents will not be changed)").arg(modelData);
modelCount: _addOns.modulePaths.length
onPerformDelete: {
var modifiedPaths = _addOns.modulePaths.slice()
modifiedPaths.splice(model.index, 1);
_addOns.modulePaths = modifiedPaths;
}
onPerformMove: {
var modifiedPaths = _addOns.modulePaths.slice()
modifiedPaths.splice(model.index, 1);
modifiedPaths.splice(newIndex, 0, modelData)
_addOns.modulePaths = modifiedPaths;
}
}
}
StyledText {
visible: (addonModulesPathsRepeater.count == 0)
width: parent.width
text : qsTr("No custom add-on module paths are configured.");
}
}
}
//////////////////////////////////////////////////////////////////
Item {