1
0
Fork 0

Correct handling of updating packages

This commit is contained in:
James Turner 2015-09-27 19:44:29 -05:00
parent 1e2460d9bf
commit 43bcc85919
4 changed files with 37 additions and 19 deletions

View file

@ -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)

View file

@ -52,7 +52,7 @@ const int AircraftThumbnailRole = Qt::UserRole + 300;
class AircraftScanThread;
class QDataStream;
class PackageDelegate;
struct AircraftItem;
typedef QSharedPointer<AircraftItem> 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<AircraftItemPtr> m_items;
PackageDelegate* m_delegate;
QVector<quint32> m_activeVariant;
QVector<quint32> m_packageVariant;

View file

@ -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);

View file

@ -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();