return m_result;
}
+void AddCatalogDialog::setUrlAndDownload(QUrl url)
+{
+ m_catalogUrl = url;
+ startDownload();
+}
+
void AddCatalogDialog::onUrlTextChanged()
{
m_catalogUrl = QUrl::fromUserInput(ui->urlEdit->text());
simgear::pkg::CatalogRef addedCatalog();
+ void setUrlAndDownload(QUrl url);
private slots:
virtual void reject();
virtual void accept();
#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),
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);
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()
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());
}
void onAddCatalog();
void onRemoveCatalog();
-
+ void onAddDefaultCatalog();
+
void onChangeDownloadDir();
void onClearDownloadDir();
private:
<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">
</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">
</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>
_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();
_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 )
{
virtual void shutdown();
virtual void update(double);
+ bool isDefaultCatalogInstalled() const;
+ void addDefaultCatalog();
+
+ std::string getDefaultCatalogId() const;
+ std::string getDefaultCatalogUrl() const;
private:
class FGDelegate;