changeset 81:ebd0980e33ff

Progress dialog; show errors
author Chris Cannam
date Wed, 19 Feb 2020 14:18:54 +0000
parents 12bf881f9f9f
children 11661e61fed0
files installer.cpp
diffstat 1 files changed, 54 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/installer.cpp	Wed Feb 19 11:55:46 2020 +0000
+++ b/installer.cpp	Wed Feb 19 14:18:54 2020 +0000
@@ -51,6 +51,8 @@
 #include <QPainter>
 #include <QFontMetrics>
 #include <QSpacerItem>
+#include <QProgressDialog>
+#include <QThread>
 
 #include <vamp-hostsdk/PluginHostAdapter.h>
 
@@ -551,7 +553,7 @@
     return status;
 }
 
-void
+QString
 installLibrary(LibraryInfo info, QString targetDir)
 {
     QString library = info.fileName;
@@ -571,7 +573,7 @@
     if (!f.copy(destination)) {
         SVCERR << "Failed to copy " << library.toStdString()
                << " to target " << destination.toStdString() << endl;
-        return;
+        return QObject::tr("Failed to copy library to destination directory");
     }
     if (!QFile::setPermissions
         (destination,
@@ -580,7 +582,7 @@
          QFile::ReadOther | QFile::ExeOther)) {
         SVCERR << "Failed to set permissions on "
                << library.toStdString() << endl;
-        return;
+        return QObject::tr("Failed to set correct permissions on installed library");
     }
 
     QString base = QFileInfo(library).baseName();
@@ -608,6 +610,8 @@
             continue;
         }
     }
+
+    return {};
 }
 
 vector<LibraryInfo>
@@ -909,9 +913,55 @@
             QDir().mkpath(target);
         }
     }
+
+    QProgressDialog progress(QObject::tr("Installing..."),
+                             QObject::tr("Stop"), 0, toInstall.size() + 1);
+    progress.setMinimumDuration(0);
+    
+    int pval = 0;
+    bool complete = true;
     
     for (auto lib: toInstall) {
-        installLibrary(lib, target);
+        progress.setValue(++pval);
+        QThread::currentThread()->msleep(40);
+        app.processEvents();
+        if (progress.wasCanceled()) {
+            complete = false;
+            break;
+        }
+        QString error = installLibrary(lib, target);
+        if (error != "") {
+            complete = false;
+            if (QMessageBox::critical
+                (&progress,
+                 QObject::tr("Install failed"),
+                 QObject::tr("Failed to install library \"%1\": %2")
+                 .arg(lib.title)
+                 .arg(error),
+                 QMessageBox::Abort | QMessageBox::Ignore,
+                 QMessageBox::Ignore) ==
+                QMessageBox::Abort) {
+                break;
+            }
+        }
+    }
+
+    progress.hide();
+
+    if (complete) {
+        QMessageBox::information
+            (&progress,
+             QObject::tr("Complete"),
+             QObject::tr("Installation completed successfully"),
+             QMessageBox::Ok,
+             QMessageBox::Ok);
+    } else {
+        QMessageBox::information
+            (&progress,
+             QObject::tr("Incomplete"),
+             QObject::tr("Installation was not complete. Exiting"),
+             QMessageBox::Ok,
+             QMessageBox::Ok);
     }
     
     return 0;