m_scanThread(NULL),
m_packageRoot(rootRef)
{
- new PackageDelegate(this);
+ m_delegate = new PackageDelegate(this);
// packages may already be refreshed, so pull now
refreshPackages();
}
AircraftItemModel::~AircraftItemModel()
{
abandonCurrentScan();
+ delete m_delegate;
}
void AircraftItemModel::setPaths(QStringList paths)
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)
class AircraftScanThread;
class QDataStream;
-
+class PackageDelegate;
struct AircraftItem;
typedef QSharedPointer<AircraftItem> AircraftItemPtr;
enum AircraftItemStatus {
- PackageNotInstalled,
+ PackageNotInstalled = 0,
PackageInstalled,
PackageUpdateAvailable,
PackageQueued,
private:
friend class PackageDelegate;
-
+
QVariant dataFromItem(AircraftItemPtr item, quint32 variantIndex, int role) const;
QVariant dataFromPackage(const simgear::pkg::PackageRef& item,
QStringList m_paths;
AircraftScanThread* m_scanThread;
QVector<AircraftItemPtr> m_items;
+ PackageDelegate* m_delegate;
QVector<quint32> m_activeVariant;
QVector<quint32> m_packageVariant;
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)
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()
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)
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);
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();