From 43bcc859193e4363f23b8c52053975925109a81e Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 27 Sep 2015 19:44:29 -0500 Subject: [PATCH] Correct handling of updating packages --- src/GUI/AircraftModel.cxx | 12 ++++++------ src/GUI/AircraftModel.hxx | 7 ++++--- src/GUI/QtLauncher.cxx | 31 +++++++++++++++++++++---------- src/GUI/QtLauncher.hxx | 6 ++++++ 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index f8dc22a32..386f0e282 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -407,7 +407,7 @@ AircraftItemModel::AircraftItemModel(QObject* pr, simgear::pkg::RootRef& rootRef m_scanThread(NULL), m_packageRoot(rootRef) { - new PackageDelegate(this); + m_delegate = new PackageDelegate(this); // packages may already be refreshed, so pull now refreshPackages(); } @@ -415,6 +415,7 @@ AircraftItemModel::AircraftItemModel(QObject* pr, simgear::pkg::RootRef& rootRef AircraftItemModel::~AircraftItemModel() { abandonCurrentScan(); + delete m_delegate; } void AircraftItemModel::setPaths(QStringList paths) @@ -738,15 +739,14 @@ void AircraftItemModel::installFailed(QModelIndex index, simgear::pkg::Delegate: msg = tr("Package could not be extracted"); break; case Delegate::FAIL_FILESYSTEM: msg = tr("A local file-system error occurred"); break; + case Delegate::FAIL_NOT_FOUND: + msg = tr("Package file missing from download server"); break; case Delegate::FAIL_UNKNOWN: default: msg = tr("Unknown reason"); } - - quint32 packageIndex = index.row() - m_items.size(); - const PackageRef& pkg(m_packages[packageIndex]); - QString packageName = QString::fromStdString(pkg->description()); - emit aircraftInstallFailed(index, tr("Failed installation of package '%1': %2").arg(packageName).arg(msg)); + + emit aircraftInstallFailed(index, msg); } void AircraftItemModel::installSucceeded(QModelIndex index) diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index bb85158c8..e717ea115 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -52,7 +52,7 @@ const int AircraftThumbnailRole = Qt::UserRole + 300; class AircraftScanThread; class QDataStream; - +class PackageDelegate; struct AircraftItem; typedef QSharedPointer AircraftItemPtr; @@ -86,7 +86,7 @@ private: enum AircraftItemStatus { - PackageNotInstalled, + PackageNotInstalled = 0, PackageInstalled, PackageUpdateAvailable, PackageQueued, @@ -137,7 +137,7 @@ private slots: private: friend class PackageDelegate; - + QVariant dataFromItem(AircraftItemPtr item, quint32 variantIndex, int role) const; QVariant dataFromPackage(const simgear::pkg::PackageRef& item, @@ -154,6 +154,7 @@ private: QStringList m_paths; AircraftScanThread* m_scanThread; QVector m_items; + PackageDelegate* m_delegate; QVector m_activeVariant; QVector m_packageVariant; diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index adcac2637..8141518f1 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -927,13 +927,7 @@ void QtLauncher::onToggleTerrasync(bool enabled) void QtLauncher::onAircraftInstalledCompleted(QModelIndex index) { - qDebug() << Q_FUNC_INFO; - QUrl u = index.data(AircraftURIRole).toUrl(); - if (u == m_selectedAircraft) { - // potentially enable the run button now! - updateSelectedAircraft(); - qDebug() << "updating selected aircraft" << index.data(); - } + maybeUpdateSelectedAircraft(index); } void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage) @@ -941,11 +935,13 @@ void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage qWarning() << Q_FUNC_INFO << index.data(AircraftURIRole) << errorMessage; QMessageBox msg; - msg.setWindowTitle(tr("Aircraft insallation failed")); + msg.setWindowTitle(tr("Aircraft installation failed")); msg.setText(tr("An error occurred installing the aircraft %1: %2"). arg(index.data(Qt::DisplayRole).toString()).arg(errorMessage)); msg.addButton(QMessageBox::Ok); msg.exec(); + + maybeUpdateSelectedAircraft(index); } void QtLauncher::updateAirportDescription() @@ -997,9 +993,15 @@ void QtLauncher::onAircraftSelected(const QModelIndex& index) void QtLauncher::onRequestPackageInstall(const QModelIndex& index) { QString pkg = index.data(AircraftPackageIdRole).toString(); - qDebug() << "request install of" << pkg; simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString()); - pref->install(); + if (pref->isInstalled()) { + InstallRef install = pref->existingInstall(); + if (install && install->hasUpdate()) { + globals->packageRoot()->scheduleToUpdate(install); + } + } else { + pref->install(); + } } void QtLauncher::onCancelDownload(const QModelIndex& index) @@ -1011,6 +1013,15 @@ void QtLauncher::onCancelDownload(const QModelIndex& index) i->cancelDownload(); } +void QtLauncher::maybeUpdateSelectedAircraft(QModelIndex index) +{ + QUrl u = index.data(AircraftURIRole).toUrl(); + if (u == m_selectedAircraft) { + // potentially enable the run button now! + updateSelectedAircraft(); + } +} + void QtLauncher::updateSelectedAircraft() { QModelIndex index = m_aircraftModel->indexOfAircraftURI(m_selectedAircraft); diff --git a/src/GUI/QtLauncher.hxx b/src/GUI/QtLauncher.hxx index 3dad6b4bb..c0412bf40 100644 --- a/src/GUI/QtLauncher.hxx +++ b/src/GUI/QtLauncher.hxx @@ -92,6 +92,12 @@ private slots: void onAircraftInstallFailed(QModelIndex index, QString errorMessage); private: void setAirport(FGAirportRef ref); + + /** + * Check if the passed index is the selected aircraft, and if so, refresh + * the associated UI data + */ + void maybeUpdateSelectedAircraft(QModelIndex index); void updateSelectedAircraft(); void restoreSettings(); -- 2.39.5