comparison installer.cpp @ 99:de8552bfeadf

Help page, licence URLs
author Chris Cannam
date Fri, 28 Feb 2020 13:15:35 +0000
parents fb4ca43863b5
children 6dc2c2adae08
comparison
equal deleted inserted replaced
98:fb4ca43863b5 99:de8552bfeadf
147 QString page; 147 QString page;
148 QStringList pluginTitles; 148 QStringList pluginTitles;
149 QString licence; 149 QString licence;
150 }; 150 };
151 151
152 struct Licence
153 {
154 static QString gpl;
155 static QString gpl2;
156 static QString gpl3;
157 static QString agpl;
158 static QString apache;
159 static QString mit;
160 };
161
162 QString Licence::gpl = "GNU General Public License";
163 QString Licence::gpl2 = "GNU General Public License, version 2";
164 QString Licence::gpl3 = "GNU General Public License, version 3";
165 QString Licence::agpl = "GNU Affero General Public License";
166 QString Licence::apache = "Apache License";
167 QString Licence::mit = "MIT License";
168
152 QString 169 QString
153 identifyLicence(QString libraryBasename) 170 identifyLicence(QString libraryBasename)
154 { 171 {
155 QString licenceFile = QString(":out/%1_COPYING.txt").arg(libraryBasename); 172 QString licenceFile = QString(":out/%1_COPYING.txt").arg(libraryBasename);
156 173
164 QByteArray content = f.readAll(); 181 QByteArray content = f.readAll();
165 f.close(); 182 f.close();
166 183
167 QString licenceText = QString::fromUtf8(content); 184 QString licenceText = QString::fromUtf8(content);
168 185
169 QString gpl = "GNU General Public License";
170 QString agpl = "GNU Affero General Public License";
171 QString apache = "Apache License";
172 QString mit = "MIT License";
173
174 // NB these are not expected to identify an arbitrary licence! We 186 // NB these are not expected to identify an arbitrary licence! We
175 // know we have only a limited set here. But we do want to 187 // know we have only a limited set here. But we do want to
176 // determine this from the actual licence text included with the 188 // determine this from the actual licence text included with the
177 // plugin distribution, not just from e.g. RDF metadata 189 // plugin distribution, not just from e.g. RDF metadata
178 190
179 if (licenceText.contains(gpl.toUpper(), Qt::CaseSensitive)) { 191 if (licenceText.contains(Licence::gpl.toUpper(), Qt::CaseSensitive)) {
180 if (licenceText.contains("Version 3, 29 June 2007")) { 192 if (licenceText.contains("Version 3, 29 June 2007")) {
181 return QString("%1, version 3").arg(gpl); 193 return Licence::gpl3;
182 } else if (licenceText.contains("Version 2, June 1991")) { 194 } else if (licenceText.contains("Version 2, June 1991")) {
183 return QString("%1, version 2").arg(gpl); 195 return Licence::gpl2;
184 } else { 196 } else {
185 return gpl; 197 return Licence::gpl;
186 } 198 }
187 } 199 }
188 if (licenceText.contains(agpl.toUpper(), Qt::CaseSensitive)) { 200 if (licenceText.contains(Licence::agpl.toUpper(), Qt::CaseSensitive)) {
189 return agpl; 201 return Licence::agpl;
190 } 202 }
191 if (licenceText.contains(apache)) { 203 if (licenceText.contains(Licence::apache)) {
192 return apache; 204 return Licence::apache;
193 } 205 }
194 if (licenceText.contains("Permission is hereby granted, free of charge, to any person")) { 206 if (licenceText.contains("Permission is hereby granted, free of charge, to any person")) {
195 return mit; 207 return Licence::mit;
196 } 208 }
197 209
198 SVCERR << "Didn't recognise licence for " << libraryBasename << endl; 210 SVCERR << "Didn't recognise licence for " << libraryBasename << endl;
199 211
212 return {};
213 }
214
215 QString
216 getLicenceURL(QString licence)
217 {
218 if (licence == Licence::gpl ||
219 licence == Licence::gpl3) {
220 return "https://www.gnu.org/licenses/gpl-3.0.en.html";
221 } else if (licence == Licence::gpl2) {
222 return "https://www.gnu.org/licenses/old-licenses/gpl-2.0.html";
223 } else if (licence == Licence::agpl) {
224 return "https://www.gnu.org/licenses/agpl-3.0.html";
225 } else if (licence == Licence::apache) {
226 return "https://www.apache.org/licenses/LICENSE-2.0";
227 } else if (licence == Licence::mit) {
228 return "https://opensource.org/licenses/MIT";
229 }
230
200 return {}; 231 return {};
201 } 232 }
202 233
203 vector<LibraryInfo> 234 vector<LibraryInfo>
204 getLibraryInfo(const Store &store, QStringList libraries) 235 getLibraryInfo(const Store &store, QStringList libraries)
676 } 707 }
677 708
678 return {}; 709 return {};
679 } 710 }
680 711
712 QString
713 getHelpText(vector<LibraryInfo> libraries)
714 {
715 set<QString, function<bool (QString, QString)>>
716 makers
717 ([](QString k1, QString k2) {
718 return k1.localeAwareCompare(k2) < 0;
719 });
720
721 for (auto info: libraries) {
722 makers.insert(info.maker);
723 }
724
725 QString makerList;
726 for (QString maker: makers) {
727 makerList += QObject::tr("<li>%1</li>").arg(maker);
728 }
729
730 return QObject::tr
731 ("<p>Vamp Plugin Pack collects together a number of <a href=\"https://vamp-plugins.org\">Vamp audio analysis plugins</a> into a single installer.</p>"
732 "<p>The libraries you select will be installed into the standard Vamp plugin directory, where hosts such as <a href=\"https://sonicvisualiser.org/\">Sonic Visualiser</a> can find them.</p>"
733 "<p>The plugin libraries included here were developed and published by various different authors and institutions:</p><ul>%1</ul>"
734 "<p>All of the libraries are open source and are redistributable under open-source licences. Click the information icon to the right of each library in the main window for more details.</p>"
735 "<p>The entire pack may be redistributed under the <a href=\"%2\">GNU Affero General Public License v3</a>.</p>"
736 "<p>The plugins were collected together, and the installer was written and published, at the <a href=\"https://c4dm.eecs.qmul.ac.uk\">Centre for Digital Music</a>, Queen Mary University of London.</p>")
737 .arg(makerList)
738 .arg(getLicenceURL(Licence::agpl));
739 }
740
681 vector<LibraryInfo> 741 vector<LibraryInfo>
682 getUserApprovedPluginLibraries(vector<LibraryInfo> libraries, 742 getUserApprovedPluginLibraries(vector<LibraryInfo> libraries,
683 QString targetDir) 743 QString targetDir)
684 { 744 {
685 QDialog dialog; 745 QDialog dialog;
832 if (!closed) { 892 if (!closed) {
833 moreInfoText += QObject::tr("</ul>"); 893 moreInfoText += QObject::tr("</ul>");
834 } 894 }
835 895
836 if (info.licence != "") { 896 if (info.licence != "") {
837 moreInfoText += QObject::tr("Provided under the %1.<br>") 897 moreInfoText += QObject::tr("Provided under the <a href=\"%1\">%2</a>.<br>")
898 .arg(getLicenceURL(info.licence))
838 .arg(info.licence); 899 .arg(info.licence);
839 } 900 }
840 901
841 QObject::connect(infoButton, &QAbstractButton::clicked, 902 QObject::connect(infoButton, &QAbstractButton::clicked,
842 [=]() { 903 [=]() {
872 mainLayout->addItem(new QSpacerItem(1, fontHeight), mainRow, 0); 933 mainLayout->addItem(new QSpacerItem(1, fontHeight), mainRow, 0);
873 ++mainRow; 934 ++mainRow;
874 935
875 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok | 936 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok |
876 QDialogButtonBox::Cancel | 937 QDialogButtonBox::Cancel |
877 QDialogButtonBox::Reset); 938 QDialogButtonBox::Reset |
939 QDialogButtonBox::Help);
878 bb->button(QDialogButtonBox::Ok)->setText(QObject::tr("Install")); 940 bb->button(QDialogButtonBox::Ok)->setText(QObject::tr("Install"));
879 mainLayout->addWidget(bb, mainRow, 0); 941 mainLayout->addWidget(bb, mainRow, 0);
880 ++mainRow; 942 ++mainRow;
881 943
882 mainLayout->setRowStretch(0, 10); 944 mainLayout->setRowStretch(0, 10);
927 for (const auto &p: checkBoxMap) { 989 for (const auto &p: checkBoxMap) {
928 p.second->setChecked(shouldCheck(statuses.at(p.first))); 990 p.second->setChecked(shouldCheck(statuses.at(p.first)));
929 } 991 }
930 break; 992 break;
931 993
994 case QDialogButtonBox::HelpRole: {
995 QMessageBox mbox;
996 mbox.setWindowTitle(QApplication::applicationName());
997 mbox.setText(QObject::tr("<b>Vamp Plugin Pack</b>"));
998 mbox.setInformativeText(getHelpText(libraries));
999 mbox.exec();
1000 break;
1001 }
1002
932 default: 1003 default:
933 SVCERR << "WARNING: Unexpected role " << role << endl; 1004 SVCERR << "WARNING: Unexpected role " << role << endl;
1005 break;
934 } 1006 }
935 }); 1007 });
936 1008
937 if (QString(PACK_VERSION).contains("-pre") || 1009 if (QString(PACK_VERSION).contains("-pre") ||
938 QString(PACK_VERSION).contains("-alpha") || 1010 QString(PACK_VERSION).contains("-alpha") ||
1008 1080
1009 auto info = getLibraryInfo(*rdfStore, libraries); 1081 auto info = getLibraryInfo(*rdfStore, libraries);
1010 1082
1011 vector<LibraryInfo> toInstall = 1083 vector<LibraryInfo> toInstall =
1012 getUserApprovedPluginLibraries(info, target); 1084 getUserApprovedPluginLibraries(info, target);
1013
1014 if (toInstall.empty()) { // Cancelled, or nothing selected
1015 SVCERR << "No libraries selected for installation, nothing to do"
1016 << endl;
1017 return 0;
1018 }
1019 1085
1020 QProgressDialog progress(QObject::tr("Installing..."), 1086 QProgressDialog progress(QObject::tr("Installing..."),
1021 QObject::tr("Stop"), 0, 1087 QObject::tr("Stop"), 0,
1022 int(toInstall.size()) + 1); 1088 int(toInstall.size()) + 1);
1023 progress.setMinimumDuration(0); 1089 progress.setMinimumDuration(0);
1090
1091 if (toInstall.empty()) { // Cancelled, or nothing selected
1092 SVCERR << "No libraries selected for installation, nothing to do"
1093 << endl;
1094 progress.hide();
1095 QMessageBox::information
1096 (&progress,
1097 QObject::tr("Nothing to do"),
1098 QObject::tr("No libraries selected for installation"),
1099 QMessageBox::Ok,
1100 QMessageBox::Ok);
1101 return 0;
1102 }
1024 1103
1025 int pval = 0; 1104 int pval = 0;
1026 bool complete = true; 1105 bool complete = true;
1027 1106
1028 for (auto lib: toInstall) { 1107 for (auto lib: toInstall) {