Launcher: fixes for invalid catalog handling
This commit is contained in:
parent
f2c050d476
commit
f760b8cd8f
12 changed files with 122 additions and 18 deletions
|
@ -84,7 +84,12 @@ CatalogRef AddCatalogDialog::addedCatalog()
|
|||
void AddCatalogDialog::setNonInteractiveMode()
|
||||
{
|
||||
m_nonInteractiveMode = true;
|
||||
ui->buttonBox->hide();
|
||||
ui->buttonBox->hide();
|
||||
}
|
||||
|
||||
void AddCatalogDialog::setUpdatingExistingCatalog()
|
||||
{
|
||||
m_updatingExistingCatalog = true;
|
||||
}
|
||||
|
||||
void AddCatalogDialog::setUrlAndDownload(QUrl url)
|
||||
|
@ -187,10 +192,23 @@ void AddCatalogDialog::accept()
|
|||
|
||||
void AddCatalogDialog::reject()
|
||||
{
|
||||
if (m_result && !m_result->id().empty()) {
|
||||
// user may have successfully download the catalog, but choosen
|
||||
// not to add it. so remove it here
|
||||
m_packageRoot->removeCatalogById(m_result->id());
|
||||
// user may have successfully download the catalog, but choosen
|
||||
// not to add it. so remove it here
|
||||
|
||||
// however, if we got in here as part of re-validating an existing
|
||||
// disabled catalog, *but* the re-validation also failed, we do not
|
||||
// want to remove it here.
|
||||
|
||||
if (m_result && !m_result->id().empty())
|
||||
{
|
||||
if (m_updatingExistingCatalog) {
|
||||
qWarning() << "cancelled add, but existing catalog so not removing:"
|
||||
<< QString::fromStdString(m_result->id());
|
||||
} else {
|
||||
qWarning() << "removed cancelled catalog:"
|
||||
<< QString::fromStdString(m_result->id());
|
||||
m_packageRoot->removeCatalogById(m_result->id());
|
||||
}
|
||||
}
|
||||
|
||||
QDialog::reject();
|
||||
|
|
|
@ -52,6 +52,13 @@ public:
|
|||
*/
|
||||
void setNonInteractiveMode();
|
||||
|
||||
/**
|
||||
* @brief setUpdatingExistingCatalog - indicate that this is an update or
|
||||
* fix of an existing catalog, in which case we will treat failures /
|
||||
* cancellation differently.
|
||||
*/
|
||||
void setUpdatingExistingCatalog();
|
||||
|
||||
void setUrlAndDownload(QUrl url);
|
||||
private slots:
|
||||
virtual void reject();
|
||||
|
@ -82,7 +89,7 @@ private:
|
|||
QUrl m_catalogUrl;
|
||||
simgear::pkg::CatalogRef m_result;
|
||||
bool m_nonInteractiveMode = false;
|
||||
|
||||
bool m_updatingExistingCatalog = false;
|
||||
std::unique_ptr<AddCatalogDelegate> m_delegate;
|
||||
};
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ protected:
|
|||
qWarning() << "failed refresh of "
|
||||
<< QString::fromStdString(aCatalog->url()) << ":" << aReason << endl;
|
||||
}
|
||||
|
||||
m_model->catalogsRefreshed();
|
||||
}
|
||||
|
||||
void startInstall(InstallRef aInstall) override
|
||||
|
|
|
@ -121,6 +121,7 @@ signals:
|
|||
|
||||
void aircraftNeedingUpdatedChanged();
|
||||
|
||||
void catalogsRefreshed();
|
||||
public slots:
|
||||
void setShowUpdateAll(bool showUpdateAll);
|
||||
|
||||
|
|
|
@ -33,10 +33,13 @@
|
|||
// FlightGear
|
||||
#include <Main/globals.hxx>
|
||||
|
||||
using namespace simgear::pkg;
|
||||
|
||||
CatalogListModel::CatalogListModel(QObject* pr, simgear::pkg::RootRef& rootRef) :
|
||||
QAbstractListModel(pr),
|
||||
m_packageRoot(rootRef)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
CatalogListModel::~CatalogListModel()
|
||||
|
@ -46,21 +49,39 @@ CatalogListModel::~CatalogListModel()
|
|||
void CatalogListModel::refresh()
|
||||
{
|
||||
beginResetModel();
|
||||
m_catalogs = m_packageRoot->allCatalogs();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int CatalogListModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return m_packageRoot->catalogs().size();
|
||||
return m_catalogs.size();
|
||||
}
|
||||
|
||||
QVariant CatalogListModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
simgear::pkg::CatalogRef cat = m_packageRoot->catalogs().at(index.row());
|
||||
simgear::pkg::CatalogRef cat = m_catalogs.at(index.row());
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
QString name = QString::fromStdString(cat->name());
|
||||
QString desc = QString::fromStdString(cat->description()).simplified();
|
||||
QString desc;
|
||||
if (cat->isEnabled()) {
|
||||
desc = QString::fromStdString(cat->description()).simplified();
|
||||
} else {
|
||||
switch (cat->status()) {
|
||||
case Delegate::FAIL_NOT_FOUND:
|
||||
desc = tr("The catalog data was not found on the server at the expected location (URL)");
|
||||
break;
|
||||
case Delegate::FAIL_VERSION:
|
||||
desc = tr("The catalog is not comaptible with the version of FlightGear");
|
||||
break;
|
||||
case Delegate::FAIL_HTTP_FORBIDDEN:
|
||||
desc = tr("The catalog server is blocking access from some reason (forbidden)");
|
||||
break;
|
||||
default:
|
||||
desc = tr("disabled due to an internal error");
|
||||
}
|
||||
}
|
||||
return tr("%1 - %2").arg(name).arg(desc);
|
||||
} else if (role == Qt::ToolTipRole) {
|
||||
return QString::fromStdString(cat->url());
|
||||
|
@ -81,3 +102,11 @@ bool CatalogListModel::setData(const QModelIndex &index, const QVariant &value,
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags CatalogListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
auto r = QAbstractListModel::flags(index);
|
||||
const auto cat = m_catalogs.at(index.row());
|
||||
r.setFlag(Qt::ItemIsEnabled, cat->isEnabled());
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -45,17 +45,20 @@ public:
|
|||
|
||||
void refresh();
|
||||
|
||||
virtual int rowCount(const QModelIndex& parent) const;
|
||||
int rowCount(const QModelIndex& parent) const override;
|
||||
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
private:
|
||||
simgear::pkg::RootRef m_packageRoot;
|
||||
simgear::pkg::CatalogList m_catalogs;
|
||||
};
|
||||
|
||||
#endif // of FG_GUI_CATALOG_LIST_MODEL
|
||||
|
|
|
@ -104,7 +104,6 @@ LauncherMainWindow::LauncherMainWindow() :
|
|||
this, &LauncherMainWindow::onViewCommandLine);
|
||||
|
||||
m_serversModel = new MPServersModel(this);
|
||||
m_serversModel->refresh();
|
||||
|
||||
// keep the description QLabel in sync as the current item changes
|
||||
connect(m_ui->stateCombo,
|
||||
|
@ -151,7 +150,6 @@ LauncherMainWindow::LauncherMainWindow() :
|
|||
m_ui->locationHistory->setIcon(historyIcon);
|
||||
|
||||
m_aircraftModel = new AircraftItemModel(this);
|
||||
|
||||
m_installedAircraftModel = new AircraftProxyModel(this, m_aircraftModel);
|
||||
m_installedAircraftModel->setInstalledFilterEnabled(true);
|
||||
|
||||
|
@ -185,6 +183,9 @@ LauncherMainWindow::LauncherMainWindow() :
|
|||
this, &LauncherMainWindow::onAircraftPathsChanged);
|
||||
m_ui->stack->addWidget(addOnsPage);
|
||||
|
||||
connect (m_aircraftModel, &AircraftItemModel::catalogsRefreshed,
|
||||
addOnsPage, &AddOnsPage::onCatalogsRefreshed);
|
||||
|
||||
QSettings settings;
|
||||
LocalAircraftCache::instance()->setPaths(settings.value("aircraft-paths").toStringList());
|
||||
LocalAircraftCache::instance()->scanDirs();
|
||||
|
@ -1015,6 +1016,11 @@ void LauncherMainWindow::requestUpdateAllAircraft()
|
|||
});
|
||||
}
|
||||
|
||||
void LauncherMainWindow::queryMPServers()
|
||||
{
|
||||
m_serversModel->refresh();
|
||||
}
|
||||
|
||||
bool LauncherMainWindow::showNoOfficialHanger() const
|
||||
{
|
||||
return shouldShowOfficialCatalogMessage();
|
||||
|
|
|
@ -84,6 +84,8 @@ public:
|
|||
|
||||
Q_INVOKABLE void requestUpdateAllAircraft();
|
||||
|
||||
Q_INVOKABLE void queryMPServers();
|
||||
|
||||
bool showNoOfficialHanger() const;
|
||||
|
||||
Q_INVOKABLE void officialCatalogAction(QString s);
|
||||
|
|
|
@ -13,6 +13,13 @@ Section {
|
|||
+ "flight. This requires a moderately fast Internet connection to be usable. Your aircraft "
|
||||
+ "will be visible to other users online, and you will see their aircraft.")
|
||||
keywords: ["network", "mp", "multiplay","online"]
|
||||
|
||||
onCheckedChanged: {
|
||||
if (checked) {
|
||||
// kick off a server query now
|
||||
_launcher.queryMPServers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LineEdit {
|
||||
|
@ -100,7 +107,12 @@ Section {
|
|||
}
|
||||
|
||||
onRestore: {
|
||||
// nothing to do, restoration is done by the C++ code
|
||||
if (enableMP.checked) {
|
||||
// only query servers if MP is enabled
|
||||
_launcher.queryMPServers();
|
||||
}
|
||||
|
||||
// restoration is done by the C++ code
|
||||
// in MPServersModel::restoreMPServerSelection
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@ AddOnsPage::AddOnsPage(QWidget *parent, simgear::pkg::RootRef root) :
|
|||
|
||||
m_catalogsModel = new CatalogListModel(this, m_packageRoot);
|
||||
m_ui->catalogsList->setModel(m_catalogsModel);
|
||||
|
||||
connect(m_ui->catalogsList, &QListView::doubleClicked,
|
||||
this, &AddOnsPage::onCatalogDoubleClicked);
|
||||
// enable drag-drop to re-order the paths
|
||||
m_ui->sceneryPathsList->setDragEnabled(true);
|
||||
m_ui->sceneryPathsList->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
@ -245,7 +246,12 @@ void AddOnsPage::addDefaultCatalog(QWidget* pr, bool silent)
|
|||
}
|
||||
dlg->setUrlAndDownload(url);
|
||||
dlg->exec();
|
||||
}
|
||||
|
||||
void AddOnsPage::onCatalogsRefreshed()
|
||||
{
|
||||
m_catalogsModel->refresh();
|
||||
updateUi();
|
||||
}
|
||||
|
||||
void AddOnsPage::onRemoveCatalog()
|
||||
|
@ -280,6 +286,18 @@ void AddOnsPage::onRemoveCatalog()
|
|||
updateUi();
|
||||
}
|
||||
|
||||
void AddOnsPage::onCatalogDoubleClicked(const QModelIndex& index)
|
||||
{
|
||||
if ((index.flags() & Qt::ItemIsEnabled) == false) {
|
||||
// re-validate existing catalog
|
||||
QScopedPointer<AddCatalogDialog> dlg(new AddCatalogDialog(this, m_packageRoot));
|
||||
dlg->setUpdatingExistingCatalog();
|
||||
dlg->setUrlAndDownload(index.data(CatalogUrlRole).toUrl());
|
||||
dlg->exec();
|
||||
m_catalogsModel->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void AddOnsPage::onInstallScenery()
|
||||
{
|
||||
QSettings settings;
|
||||
|
|
|
@ -22,6 +22,9 @@ public:
|
|||
|
||||
static void addDefaultCatalog(QWidget* pr, bool silent);
|
||||
|
||||
public slots:
|
||||
void onCatalogsRefreshed();
|
||||
|
||||
signals:
|
||||
void sceneryPathsChanged();
|
||||
void aircraftPathsChanged();
|
||||
|
@ -43,6 +46,8 @@ private slots:
|
|||
|
||||
void saveAircraftPaths();
|
||||
void saveSceneryPaths();
|
||||
|
||||
void onCatalogDoubleClicked(const QModelIndex& index);
|
||||
private:
|
||||
void updateUi();
|
||||
|
||||
|
|
|
@ -238,8 +238,9 @@ void FGHTTPClient::postinit()
|
|||
.method("refresh", &pkg::Catalog::refresh)
|
||||
.method("needingUpdate", &pkg::Catalog::packagesNeedingUpdate)
|
||||
.member("installed", &pkg::Catalog::installedPackages)
|
||||
.method("search", &f_catalog_search);
|
||||
|
||||
.method("search", &f_catalog_search)
|
||||
.member("enabled", &pkg::Catalog::isEnabled);
|
||||
|
||||
NasalPackage::init("Package")
|
||||
.member("id", &pkg::Package::id)
|
||||
.member("name", &pkg::Package::name)
|
||||
|
|
Loading…
Add table
Reference in a new issue