]> git.mxchange.org Git - flightgear.git/commitdiff
Correct handling of updating packages
authorJames Turner <zakalawe@mac.com>
Mon, 28 Sep 2015 00:44:29 +0000 (19:44 -0500)
committerJames Turner <zakalawe@mac.com>
Mon, 28 Sep 2015 00:44:29 +0000 (19:44 -0500)
src/GUI/AircraftModel.cxx
src/GUI/AircraftModel.hxx
src/GUI/QtLauncher.cxx
src/GUI/QtLauncher.hxx

index f8dc22a32f1e5aa49cab2a8e4d066dc7c5705bf1..386f0e2826444b7a7fdfd9fc35dd7b24751b8503 100644 (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)
index bb85158c80b55148d271889343b94277fd762b64..e717ea1150ee4724f2b09de57160eef764a90115 100644 (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;
index adcac26373097590e6dfdaa77b5c76f56cb457b3..8141518f121221335f1cea8c9c2af96b14a6c103 100644 (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);
index 3dad6b4bb19aa3265dc33795cb71fa6dc81d90f7..c0412bf40a26c949d83e7c6e5b5ecd9ba3502f73 100644 (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();