Mercurial > hg > vamp-plugin-pack
changeset 42:37d79024d966
Begin on installer dialog
author | Chris Cannam |
---|---|
date | Mon, 20 Jan 2020 14:22:24 +0000 |
parents | f1326adbb33b |
children | 4aea515b404f |
files | installer.cpp |
diffstat | 1 files changed, 94 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/installer.cpp Thu Dec 19 13:44:39 2019 +0000 +++ b/installer.cpp Mon Jan 20 14:22:24 2020 +0000 @@ -4,20 +4,34 @@ #include <QFile> #include <QDir> +#include <QDialog> +#include <QFrame> +#include <QVBoxLayout> +#include <QCheckBox> +#include <QDialogButtonBox> + #include <vamp-hostsdk/PluginHostAdapter.h> #include <iostream> using namespace std; -int main(int argc, char **argv) +QString +getDefaultInstallDirectory() { auto pathList = Vamp::PluginHostAdapter::getPluginPath(); if (pathList.empty()) { cerr << "Failed to look up Vamp plugin path" << endl; - return 1; + return QString(); } - QApplication app(argc, argv); + auto firstPath = *pathList.begin(); + QString target = QString::fromUtf8(firstPath.c_str(), firstPath.size()); + return target; +} + +QStringList +getPluginLibraryList() +{ QDir dir(":out/"); auto entries = dir.entryList({ "*.so", "*.dll", "*.dylib" }); @@ -25,27 +39,85 @@ cerr << e.toStdString() << endl; } - auto firstPath = *pathList.begin(); - QString target = QString::fromUtf8(firstPath.c_str(), firstPath.size()); + return entries; +} - for (auto e: entries) { - QFile f(":out/" + e); - QString destination = target + "/" + e; - cerr << "Copying " << e.toStdString() << " to " - << destination.toStdString() << "..." << endl; - if (!f.copy(destination)) { - cerr << "Failed to copy " << e.toStdString() - << " to target " << destination.toStdString() << endl; - continue; +void +installLibrary(QString library, QString target) +{ + QFile f(":out/" + library); + QString destination = target + "/" + library; + cerr << "Copying " << library.toStdString() << " to " + << destination.toStdString() << "..." << endl; + if (!f.copy(destination)) { + cerr << "Failed to copy " << library.toStdString() + << " to target " << destination.toStdString() << endl; + return; + } + if (!QFile::setPermissions + (destination, + QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | + QFile::ReadGroup | QFile::ExeGroup | + QFile::ReadOther | QFile::ExeOther)) { + cerr << "Failed to set permissions on " + << library.toStdString() << endl; + return; + } +} + +QStringList +getUserApprovedPluginLibraries(QStringList libraries) +{ + QDialog dialog; + auto layout = new QVBoxLayout; + + std::map<QString, QCheckBox *> checkBoxMap; + + for (auto lib: libraries) { + auto cb = new QCheckBox(lib); + layout->addWidget(cb); + checkBoxMap[lib] = cb; + } + + auto bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + layout->addWidget(bb); + QObject::connect(bb, SIGNAL(accepted()), &dialog, SLOT(accept())); + QObject::connect(bb, SIGNAL(rejected()), &dialog, SLOT(reject())); + + dialog.setLayout(layout); + + if (dialog.exec() == QDialog::Accepted) { + cerr << "accepted" << endl; + } else { + cerr << "rejected" << endl; + } + + QStringList approved; + for (const auto &p: checkBoxMap) { + if (p.second->isChecked()) { + approved.push_back(p.first); } - if (!QFile::setPermissions - (destination, - QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | - QFile::ReadGroup | QFile::ExeGroup | - QFile::ReadOther | QFile::ExeOther)) { - cerr << "Failed to set permissions on " << e.toStdString() << endl; - continue; - } + } + + return approved; +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QString target = getDefaultInstallDirectory(); + if (target == "") { + return 1; + } + + QStringList libraries = getPluginLibraryList(); + + QStringList toInstall = getUserApprovedPluginLibraries(libraries); + + for (auto lib: toInstall) { + installLibrary(lib, target); } return 0;