Mercurial > hg > vamp-plugin-pack
comparison installer.cpp @ 81:ebd0980e33ff
Progress dialog; show errors
author | Chris Cannam |
---|---|
date | Wed, 19 Feb 2020 14:18:54 +0000 |
parents | 4423e96a5243 |
children | 11661e61fed0 |
comparison
equal
deleted
inserted
replaced
80:12bf881f9f9f | 81:ebd0980e33ff |
---|---|
49 #include <QMessageBox> | 49 #include <QMessageBox> |
50 #include <QSvgRenderer> | 50 #include <QSvgRenderer> |
51 #include <QPainter> | 51 #include <QPainter> |
52 #include <QFontMetrics> | 52 #include <QFontMetrics> |
53 #include <QSpacerItem> | 53 #include <QSpacerItem> |
54 #include <QProgressDialog> | |
55 #include <QThread> | |
54 | 56 |
55 #include <vamp-hostsdk/PluginHostAdapter.h> | 57 #include <vamp-hostsdk/PluginHostAdapter.h> |
56 | 58 |
57 #include <dataquay/BasicStore.h> | 59 #include <dataquay/BasicStore.h> |
58 #include <dataquay/RDFException.h> | 60 #include <dataquay/RDFException.h> |
549 SVCERR << " - relative status: " << relativeStatusLabel(status) << endl; | 551 SVCERR << " - relative status: " << relativeStatusLabel(status) << endl; |
550 | 552 |
551 return status; | 553 return status; |
552 } | 554 } |
553 | 555 |
554 void | 556 QString |
555 installLibrary(LibraryInfo info, QString targetDir) | 557 installLibrary(LibraryInfo info, QString targetDir) |
556 { | 558 { |
557 QString library = info.fileName; | 559 QString library = info.fileName; |
558 QString source = ":out"; | 560 QString source = ":out"; |
559 QFile f(source + "/" + library); | 561 QFile f(source + "/" + library); |
569 SVCERR << "Copying " << library.toStdString() << " to " | 571 SVCERR << "Copying " << library.toStdString() << " to " |
570 << destination.toStdString() << "..." << endl; | 572 << destination.toStdString() << "..." << endl; |
571 if (!f.copy(destination)) { | 573 if (!f.copy(destination)) { |
572 SVCERR << "Failed to copy " << library.toStdString() | 574 SVCERR << "Failed to copy " << library.toStdString() |
573 << " to target " << destination.toStdString() << endl; | 575 << " to target " << destination.toStdString() << endl; |
574 return; | 576 return QObject::tr("Failed to copy library to destination directory"); |
575 } | 577 } |
576 if (!QFile::setPermissions | 578 if (!QFile::setPermissions |
577 (destination, | 579 (destination, |
578 QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | | 580 QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | |
579 QFile::ReadGroup | QFile::ExeGroup | | 581 QFile::ReadGroup | QFile::ExeGroup | |
580 QFile::ReadOther | QFile::ExeOther)) { | 582 QFile::ReadOther | QFile::ExeOther)) { |
581 SVCERR << "Failed to set permissions on " | 583 SVCERR << "Failed to set permissions on " |
582 << library.toStdString() << endl; | 584 << library.toStdString() << endl; |
583 return; | 585 return QObject::tr("Failed to set correct permissions on installed library"); |
584 } | 586 } |
585 | 587 |
586 QString base = QFileInfo(library).baseName(); | 588 QString base = QFileInfo(library).baseName(); |
587 QDir dir(source); | 589 QDir dir(source); |
588 auto entries = dir.entryList({ base + "*" }); | 590 auto entries = dir.entryList({ base + "*" }); |
606 << destination.toStdString() | 608 << destination.toStdString() |
607 << " (ignoring)" << endl; | 609 << " (ignoring)" << endl; |
608 continue; | 610 continue; |
609 } | 611 } |
610 } | 612 } |
613 | |
614 return {}; | |
611 } | 615 } |
612 | 616 |
613 vector<LibraryInfo> | 617 vector<LibraryInfo> |
614 getUserApprovedPluginLibraries(vector<LibraryInfo> libraries, | 618 getUserApprovedPluginLibraries(vector<LibraryInfo> libraries, |
615 QString targetDir) | 619 QString targetDir) |
907 if (!toInstall.empty()) { | 911 if (!toInstall.empty()) { |
908 if (!QDir(target).exists()) { | 912 if (!QDir(target).exists()) { |
909 QDir().mkpath(target); | 913 QDir().mkpath(target); |
910 } | 914 } |
911 } | 915 } |
916 | |
917 QProgressDialog progress(QObject::tr("Installing..."), | |
918 QObject::tr("Stop"), 0, toInstall.size() + 1); | |
919 progress.setMinimumDuration(0); | |
920 | |
921 int pval = 0; | |
922 bool complete = true; | |
912 | 923 |
913 for (auto lib: toInstall) { | 924 for (auto lib: toInstall) { |
914 installLibrary(lib, target); | 925 progress.setValue(++pval); |
926 QThread::currentThread()->msleep(40); | |
927 app.processEvents(); | |
928 if (progress.wasCanceled()) { | |
929 complete = false; | |
930 break; | |
931 } | |
932 QString error = installLibrary(lib, target); | |
933 if (error != "") { | |
934 complete = false; | |
935 if (QMessageBox::critical | |
936 (&progress, | |
937 QObject::tr("Install failed"), | |
938 QObject::tr("Failed to install library \"%1\": %2") | |
939 .arg(lib.title) | |
940 .arg(error), | |
941 QMessageBox::Abort | QMessageBox::Ignore, | |
942 QMessageBox::Ignore) == | |
943 QMessageBox::Abort) { | |
944 break; | |
945 } | |
946 } | |
947 } | |
948 | |
949 progress.hide(); | |
950 | |
951 if (complete) { | |
952 QMessageBox::information | |
953 (&progress, | |
954 QObject::tr("Complete"), | |
955 QObject::tr("Installation completed successfully"), | |
956 QMessageBox::Ok, | |
957 QMessageBox::Ok); | |
958 } else { | |
959 QMessageBox::information | |
960 (&progress, | |
961 QObject::tr("Incomplete"), | |
962 QObject::tr("Installation was not complete. Exiting"), | |
963 QMessageBox::Ok, | |
964 QMessageBox::Ok); | |
915 } | 965 } |
916 | 966 |
917 return 0; | 967 return 0; |
918 } | 968 } |