Change handling of default hangar / catalog.
- no longer re-add it on startup, add an explicit button in the UI (will add a more obvious item to the aircraft list in a follow-up commit)
This commit is contained in:
parent
4ea093ecc4
commit
be1291f689
7 changed files with 123 additions and 33 deletions
|
@ -52,6 +52,12 @@ CatalogRef AddCatalogDialog::addedCatalog()
|
|||
return m_result;
|
||||
}
|
||||
|
||||
void AddCatalogDialog::setUrlAndDownload(QUrl url)
|
||||
{
|
||||
m_catalogUrl = url;
|
||||
startDownload();
|
||||
}
|
||||
|
||||
void AddCatalogDialog::onUrlTextChanged()
|
||||
{
|
||||
m_catalogUrl = QUrl::fromUserInput(ui->urlEdit->text());
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
|
||||
simgear::pkg::CatalogRef addedCatalog();
|
||||
|
||||
void setUrlAndDownload(QUrl url);
|
||||
private slots:
|
||||
virtual void reject();
|
||||
virtual void accept();
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include "AddCatalogDialog.hxx"
|
||||
|
||||
#include <Main/options.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
#include <Network/HTTPClient.hxx>
|
||||
|
||||
PathsDialog::PathsDialog(QWidget *parent, simgear::pkg::RootRef root) :
|
||||
QDialog(parent),
|
||||
|
@ -22,6 +24,8 @@ PathsDialog::PathsDialog(QWidget *parent, simgear::pkg::RootRef root) :
|
|||
|
||||
connect(m_ui->addCatalog, &QToolButton::clicked,
|
||||
this, &PathsDialog::onAddCatalog);
|
||||
connect(m_ui->addDefaultCatalogButton, &QPushButton::clicked,
|
||||
this, &PathsDialog::onAddDefaultCatalog);
|
||||
connect(m_ui->removeCatalog, &QToolButton::clicked,
|
||||
this, &PathsDialog::onRemoveCatalog);
|
||||
|
||||
|
@ -120,26 +124,60 @@ void PathsDialog::onRemoveAircraftPath()
|
|||
|
||||
void PathsDialog::onAddCatalog()
|
||||
{
|
||||
AddCatalogDialog* dlg = new AddCatalogDialog(this, m_packageRoot);
|
||||
QScopedPointer<AddCatalogDialog> dlg(new AddCatalogDialog(this, m_packageRoot));
|
||||
dlg->exec();
|
||||
if (dlg->result() == QDialog::Accepted) {
|
||||
m_catalogsModel->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void PathsDialog::onAddDefaultCatalog()
|
||||
{
|
||||
// check it's not a duplicate somehow
|
||||
FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
|
||||
if (http->isDefaultCatalogInstalled())
|
||||
return;
|
||||
|
||||
QScopedPointer<AddCatalogDialog> dlg(new AddCatalogDialog(this, m_packageRoot));
|
||||
QUrl url(QString::fromStdString(http->getDefaultCatalogUrl()));
|
||||
dlg->setUrlAndDownload(url);
|
||||
dlg->exec();
|
||||
if (dlg->result() == QDialog::Accepted) {
|
||||
m_catalogsModel->refresh();
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
void PathsDialog::onRemoveCatalog()
|
||||
{
|
||||
QModelIndex mi = m_ui->catalogsList->currentIndex();
|
||||
FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
|
||||
|
||||
if (mi.isValid()) {
|
||||
QString s = QStringLiteral("Remove aircraft hangar '%1'? All installed aircraft from this "
|
||||
"hangar will be removed.");
|
||||
QString pkgId = mi.data(CatalogIdRole).toString();
|
||||
|
||||
if (pkgId.toStdString() == http->getDefaultCatalogId()) {
|
||||
s = QStringLiteral("Remove default aircraft hangar? "
|
||||
"This hangar contains all the default aircraft included with FlightGear. "
|
||||
"If you change your mind in the future, click the 'restore' button.");
|
||||
} else {
|
||||
s = s.arg(mi.data(Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
QMessageBox mb;
|
||||
mb.setText(QStringLiteral("Remove aircraft hangar '%1'?").arg(mi.data(Qt::DisplayRole).toString()));
|
||||
mb.setText(s);
|
||||
mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
mb.setDefaultButton(QMessageBox::No);
|
||||
mb.exec();
|
||||
|
||||
QString pkgId = mi.data(CatalogIdRole).toString();
|
||||
m_packageRoot->removeCatalogById(pkgId.toStdString());
|
||||
if (mb.result() == QMessageBox::Yes) {
|
||||
m_packageRoot->removeCatalogById(pkgId.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
updateUi();
|
||||
}
|
||||
|
||||
void PathsDialog::onChangeDownloadDir()
|
||||
|
@ -173,4 +211,7 @@ void PathsDialog::updateUi()
|
|||
|
||||
QString m = tr("Download location: %1").arg(s);
|
||||
m_ui->downloadLocation->setText(m);
|
||||
|
||||
FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
|
||||
m_ui->addDefaultCatalogButton->setEnabled(!http->isDefaultCatalogInstalled());
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ private slots:
|
|||
|
||||
void onAddCatalog();
|
||||
void onRemoveCatalog();
|
||||
|
||||
void onAddDefaultCatalog();
|
||||
|
||||
void onChangeDownloadDir();
|
||||
void onClearDownloadDir();
|
||||
private:
|
||||
|
|
|
@ -161,20 +161,7 @@
|
|||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>567</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<item row="1" column="3">
|
||||
<widget class="QToolButton" name="removeCatalog">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
|
@ -193,7 +180,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="1" column="2">
|
||||
<widget class="QToolButton" name="addCatalog">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
|
@ -212,7 +199,27 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<item row="1" column="1">
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>567</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="addDefaultCatalogButton">
|
||||
<property name="text">
|
||||
<string>Restore default aircraft hangar</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="4">
|
||||
<widget class="QListView" name="catalogsList"/>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -147,18 +147,6 @@ void FGHTTPClient::init()
|
|||
|
||||
_packageDelegate.reset(new FGDelegate);
|
||||
packageRoot->addDelegate(_packageDelegate.get());
|
||||
|
||||
const char * defaultCatalogId = fgGetString("/sim/package-system/default-catalog/id", "org.flightgear.official" );
|
||||
const char * defaultCatalogUrl = fgGetString("/sim/package-system/default-catalog/url",
|
||||
"http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");
|
||||
// setup default catalog if not present
|
||||
pkg::Catalog* defaultCatalog = packageRoot->getCatalogById( defaultCatalogId );
|
||||
if (!defaultCatalog) {
|
||||
// always show this message
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "default catalog not found, installing '"
|
||||
<< defaultCatalogId << "' from '" << defaultCatalogUrl << "'.");
|
||||
pkg::Catalog::createFromUrl(packageRoot,defaultCatalogUrl);
|
||||
}
|
||||
|
||||
// start a refresh now
|
||||
packageRoot->refresh();
|
||||
|
@ -167,6 +155,47 @@ void FGHTTPClient::init()
|
|||
_inited = true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
std::string _getDefaultCatalogId()
|
||||
{
|
||||
return fgGetString("/sim/package-system/default-catalog/id", "org.flightgear.official" );
|
||||
}
|
||||
|
||||
pkg::CatalogRef getDefaultCatalog()
|
||||
{
|
||||
if (!globals->packageRoot())
|
||||
return pkg::CatalogRef();
|
||||
|
||||
return globals->packageRoot()->getCatalogById(_getDefaultCatalogId());
|
||||
}
|
||||
|
||||
} // of anonymous namespace
|
||||
|
||||
bool FGHTTPClient::isDefaultCatalogInstalled() const
|
||||
{
|
||||
return getDefaultCatalog().valid();
|
||||
}
|
||||
|
||||
void FGHTTPClient::addDefaultCatalog()
|
||||
{
|
||||
pkg::CatalogRef defaultCatalog = getDefaultCatalog();
|
||||
if (!defaultCatalog.valid()) {
|
||||
pkg::Catalog::createFromUrl(globals->packageRoot(), getDefaultCatalogUrl());
|
||||
}
|
||||
}
|
||||
|
||||
std::string FGHTTPClient::getDefaultCatalogId() const
|
||||
{
|
||||
return _getDefaultCatalogId();
|
||||
}
|
||||
|
||||
std::string FGHTTPClient::getDefaultCatalogUrl() const
|
||||
{
|
||||
return fgGetString("/sim/package-system/default-catalog/url",
|
||||
"http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");;
|
||||
}
|
||||
|
||||
static naRef f_package_existingInstall( pkg::Package& pkg,
|
||||
const nasal::CallContext& ctx )
|
||||
{
|
||||
|
|
|
@ -41,6 +41,11 @@ public:
|
|||
virtual void shutdown();
|
||||
virtual void update(double);
|
||||
|
||||
bool isDefaultCatalogInstalled() const;
|
||||
void addDefaultCatalog();
|
||||
|
||||
std::string getDefaultCatalogId() const;
|
||||
std::string getDefaultCatalogUrl() const;
|
||||
private:
|
||||
class FGDelegate;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue