Chris@66
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@66
|
2 /*
|
Chris@66
|
3 Copyright (c) 2020 Queen Mary, University of London
|
Chris@66
|
4
|
Chris@66
|
5 Permission is hereby granted, free of charge, to any person
|
Chris@66
|
6 obtaining a copy of this software and associated documentation
|
Chris@66
|
7 files (the "Software"), to deal in the Software without
|
Chris@66
|
8 restriction, including without limitation the rights to use, copy,
|
Chris@66
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@66
|
10 of the Software, and to permit persons to whom the Software is
|
Chris@66
|
11 furnished to do so, subject to the following conditions:
|
Chris@66
|
12
|
Chris@66
|
13 The above copyright notice and this permission notice shall be
|
Chris@66
|
14 included in all copies or substantial portions of the Software.
|
Chris@66
|
15
|
Chris@66
|
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@66
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@66
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@66
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
Chris@66
|
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@66
|
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@66
|
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@66
|
23
|
Chris@66
|
24 Except as contained in this notice, the names of the Centre for
|
Chris@66
|
25 Digital Music and Queen Mary, University of London shall not be
|
Chris@66
|
26 used in advertising or otherwise to promote the sale, use or other
|
Chris@66
|
27 dealings in this Software without prior written authorization.
|
Chris@66
|
28 */
|
Chris@33
|
29
|
Chris@33
|
30 #include <QApplication>
|
Chris@33
|
31 #include <QString>
|
Chris@33
|
32 #include <QFile>
|
Chris@33
|
33 #include <QDir>
|
Chris@33
|
34
|
Chris@42
|
35 #include <QDialog>
|
Chris@42
|
36 #include <QFrame>
|
Chris@42
|
37 #include <QVBoxLayout>
|
Chris@42
|
38 #include <QCheckBox>
|
Chris@42
|
39 #include <QDialogButtonBox>
|
Chris@46
|
40 #include <QLabel>
|
Chris@51
|
41 #include <QFont>
|
Chris@51
|
42 #include <QFontInfo>
|
Chris@67
|
43 #include <QTemporaryFile>
|
Chris@67
|
44 #include <QMutex>
|
Chris@67
|
45 #include <QMutexLocker>
|
Chris@67
|
46 #include <QProcess>
|
Chris@72
|
47 #include <QToolButton>
|
Chris@79
|
48 #include <QPushButton>
|
Chris@72
|
49 #include <QMessageBox>
|
Chris@74
|
50 #include <QSvgRenderer>
|
Chris@74
|
51 #include <QPainter>
|
Chris@74
|
52 #include <QFontMetrics>
|
Chris@79
|
53 #include <QSpacerItem>
|
Chris@81
|
54 #include <QProgressDialog>
|
Chris@81
|
55 #include <QThread>
|
Chris@42
|
56
|
Chris@41
|
57 #include <vamp-hostsdk/PluginHostAdapter.h>
|
Chris@41
|
58
|
Chris@43
|
59 #include <dataquay/BasicStore.h>
|
Chris@43
|
60 #include <dataquay/RDFException.h>
|
Chris@43
|
61
|
Chris@33
|
62 #include <iostream>
|
Chris@58
|
63 #include <memory>
|
Chris@43
|
64 #include <set>
|
Chris@43
|
65
|
Chris@51
|
66 #include "base/Debug.h"
|
Chris@51
|
67
|
Chris@79
|
68 #include "version.h"
|
Chris@79
|
69
|
Chris@33
|
70 using namespace std;
|
Chris@43
|
71 using namespace Dataquay;
|
Chris@32
|
72
|
Chris@42
|
73 QString
|
Chris@42
|
74 getDefaultInstallDirectory()
|
Chris@32
|
75 {
|
Chris@41
|
76 auto pathList = Vamp::PluginHostAdapter::getPluginPath();
|
Chris@41
|
77 if (pathList.empty()) {
|
Chris@51
|
78 SVCERR << "Failed to look up Vamp plugin path" << endl;
|
Chris@42
|
79 return QString();
|
Chris@41
|
80 }
|
Chris@41
|
81
|
Chris@42
|
82 auto firstPath = *pathList.begin();
|
Chris@42
|
83 QString target = QString::fromUtf8(firstPath.c_str(), firstPath.size());
|
Chris@42
|
84 return target;
|
Chris@42
|
85 }
|
Chris@42
|
86
|
Chris@42
|
87 QStringList
|
Chris@42
|
88 getPluginLibraryList()
|
Chris@42
|
89 {
|
Chris@33
|
90 QDir dir(":out/");
|
Chris@33
|
91 auto entries = dir.entryList({ "*.so", "*.dll", "*.dylib" });
|
Chris@33
|
92
|
Chris@33
|
93 for (auto e: entries) {
|
Chris@51
|
94 SVCERR << e.toStdString() << endl;
|
Chris@33
|
95 }
|
Chris@33
|
96
|
Chris@42
|
97 return entries;
|
Chris@42
|
98 }
|
Chris@33
|
99
|
Chris@50
|
100 void
|
Chris@50
|
101 loadLibraryRdf(BasicStore &store, QString filename)
|
Chris@50
|
102 {
|
Chris@50
|
103 QFile f(filename);
|
Chris@50
|
104 if (!f.open(QFile::ReadOnly | QFile::Text)) {
|
Chris@51
|
105 SVCERR << "Failed to open RDF resource file "
|
Chris@51
|
106 << filename.toStdString() << endl;
|
Chris@50
|
107 return;
|
Chris@50
|
108 }
|
Chris@50
|
109
|
Chris@50
|
110 QByteArray content = f.readAll();
|
Chris@50
|
111 f.close();
|
Chris@50
|
112
|
Chris@50
|
113 try {
|
Chris@50
|
114 store.importString(QString::fromUtf8(content),
|
Chris@50
|
115 Uri("file:" + filename),
|
Chris@50
|
116 BasicStore::ImportIgnoreDuplicates);
|
Chris@50
|
117 } catch (const RDFException &ex) {
|
Chris@51
|
118 SVCERR << "Failed to import RDF resource file "
|
Chris@51
|
119 << filename.toStdString() << ": " << ex.what() << endl;
|
Chris@50
|
120 }
|
Chris@50
|
121 }
|
Chris@50
|
122
|
Chris@43
|
123 unique_ptr<BasicStore>
|
Chris@43
|
124 loadLibrariesRdf()
|
Chris@43
|
125 {
|
Chris@43
|
126 unique_ptr<BasicStore> store(new BasicStore);
|
Chris@43
|
127
|
Chris@50
|
128 vector<QString> dirs { ":rdf/plugins", ":out" };
|
Chris@43
|
129
|
Chris@50
|
130 for (auto d: dirs) {
|
Chris@50
|
131 for (auto e: QDir(d).entryList({ "*.ttl", "*.n3" })) {
|
Chris@50
|
132 loadLibraryRdf(*store, d + "/" + e);
|
Chris@43
|
133 }
|
Chris@43
|
134 }
|
Chris@43
|
135
|
Chris@43
|
136 return store;
|
Chris@43
|
137 }
|
Chris@43
|
138
|
Chris@43
|
139 struct LibraryInfo {
|
Chris@43
|
140 QString id;
|
Chris@43
|
141 QString fileName;
|
Chris@43
|
142 QString title;
|
Chris@43
|
143 QString maker;
|
Chris@43
|
144 QString description;
|
Chris@78
|
145 QString page;
|
Chris@47
|
146 QStringList pluginTitles;
|
Chris@67
|
147 map<QString, int> pluginVersions; // id -> version
|
Chris@74
|
148 QString licence;
|
Chris@43
|
149 };
|
Chris@43
|
150
|
Chris@74
|
151 QString
|
Chris@74
|
152 identifyLicence(QString libraryBasename)
|
Chris@74
|
153 {
|
Chris@74
|
154 QString licenceFile = QString(":out/%1_COPYING.txt").arg(libraryBasename);
|
Chris@74
|
155
|
Chris@74
|
156 QFile f(licenceFile);
|
Chris@74
|
157 if (!f.open(QFile::ReadOnly | QFile::Text)) {
|
Chris@74
|
158 SVCERR << "Failed to open licence file "
|
Chris@74
|
159 << licenceFile.toStdString() << endl;
|
Chris@74
|
160 return {};
|
Chris@74
|
161 }
|
Chris@74
|
162
|
Chris@74
|
163 QByteArray content = f.readAll();
|
Chris@74
|
164 f.close();
|
Chris@74
|
165
|
Chris@74
|
166 QString licenceText = QString::fromUtf8(content);
|
Chris@74
|
167
|
Chris@74
|
168 QString gpl = "GNU General Public License";
|
Chris@74
|
169 QString agpl = "GNU Affero General Public License";
|
Chris@74
|
170 QString apache = "Apache License";
|
Chris@74
|
171 QString mit = "MIT License";
|
Chris@74
|
172
|
Chris@82
|
173 // NB these are not expected to identify an arbitrary licence! We
|
Chris@74
|
174 // know we have only a limited set here. But we do want to
|
Chris@74
|
175 // determine this from the actual licence text included with the
|
Chris@74
|
176 // plugin distribution, not just from e.g. RDF metadata
|
Chris@74
|
177
|
Chris@74
|
178 if (licenceText.contains(gpl.toUpper(), Qt::CaseSensitive)) {
|
Chris@74
|
179 if (licenceText.contains("Version 3, 29 June 2007")) {
|
Chris@74
|
180 return QString("%1, version 3").arg(gpl);
|
Chris@74
|
181 } else if (licenceText.contains("Version 2, June 1991")) {
|
Chris@74
|
182 return QString("%1, version 2").arg(gpl);
|
Chris@74
|
183 } else {
|
Chris@74
|
184 return gpl;
|
Chris@74
|
185 }
|
Chris@74
|
186 }
|
Chris@74
|
187 if (licenceText.contains(agpl.toUpper(), Qt::CaseSensitive)) {
|
Chris@74
|
188 return agpl;
|
Chris@74
|
189 }
|
Chris@74
|
190 if (licenceText.contains(apache)) {
|
Chris@74
|
191 return apache;
|
Chris@74
|
192 }
|
Chris@74
|
193 if (licenceText.contains("Permission is hereby granted, free of charge, to any person")) {
|
Chris@74
|
194 return mit;
|
Chris@74
|
195 }
|
Chris@74
|
196
|
Chris@74
|
197 SVCERR << "Didn't recognise licence for " << libraryBasename << endl;
|
Chris@74
|
198
|
Chris@74
|
199 return {};
|
Chris@74
|
200 }
|
Chris@74
|
201
|
Chris@43
|
202 vector<LibraryInfo>
|
Chris@43
|
203 getLibraryInfo(const Store &store, QStringList libraries)
|
Chris@43
|
204 {
|
Chris@43
|
205 /* e.g.
|
Chris@43
|
206
|
Chris@43
|
207 plugbase:library a vamp:PluginLibrary ;
|
Chris@43
|
208 vamp:identifier "qm-vamp-plugins" ;
|
Chris@43
|
209 dc:title "Queen Mary plugin set"
|
Chris@43
|
210 */
|
Chris@43
|
211
|
Chris@43
|
212 Triples tt = store.match(Triple(Node(),
|
Chris@43
|
213 Uri("a"),
|
Chris@43
|
214 store.expand("vamp:PluginLibrary")));
|
Chris@43
|
215
|
Chris@67
|
216 map<QString, QString> wanted; // basename -> full lib name
|
Chris@43
|
217 for (auto lib: libraries) {
|
Chris@43
|
218 wanted[QFileInfo(lib).baseName()] = lib;
|
Chris@43
|
219 }
|
Chris@43
|
220
|
Chris@43
|
221 vector<LibraryInfo> results;
|
Chris@43
|
222
|
Chris@43
|
223 for (auto t: tt) {
|
Chris@43
|
224
|
Chris@43
|
225 Node libId = store.complete(Triple(t.subject(),
|
Chris@43
|
226 store.expand("vamp:identifier"),
|
Chris@43
|
227 Node()));
|
Chris@43
|
228 if (libId.type != Node::Literal) {
|
Chris@43
|
229 continue;
|
Chris@43
|
230 }
|
Chris@43
|
231 auto wi = wanted.find(libId.value);
|
Chris@43
|
232 if (wi == wanted.end()) {
|
Chris@43
|
233 continue;
|
Chris@43
|
234 }
|
Chris@74
|
235
|
Chris@50
|
236 Node title = store.complete(Triple(t.subject(),
|
Chris@50
|
237 store.expand("dc:title"),
|
Chris@50
|
238 Node()));
|
Chris@50
|
239 if (title.type != Node::Literal) {
|
Chris@50
|
240 continue;
|
Chris@50
|
241 }
|
Chris@50
|
242
|
Chris@43
|
243 LibraryInfo info;
|
Chris@43
|
244 info.id = wi->first;
|
Chris@43
|
245 info.fileName = wi->second;
|
Chris@50
|
246 info.title = title.value;
|
Chris@43
|
247
|
Chris@43
|
248 Node maker = store.complete(Triple(t.subject(),
|
Chris@43
|
249 store.expand("foaf:maker"),
|
Chris@43
|
250 Node()));
|
Chris@43
|
251 if (maker.type == Node::Literal) {
|
Chris@43
|
252 info.maker = maker.value;
|
Chris@46
|
253 } else if (maker != Node()) {
|
Chris@46
|
254 maker = store.complete(Triple(maker,
|
Chris@46
|
255 store.expand("foaf:name"),
|
Chris@46
|
256 Node()));
|
Chris@46
|
257 if (maker.type == Node::Literal) {
|
Chris@46
|
258 info.maker = maker.value;
|
Chris@46
|
259 }
|
Chris@43
|
260 }
|
Chris@46
|
261
|
Chris@43
|
262 Node desc = store.complete(Triple(t.subject(),
|
Chris@43
|
263 store.expand("dc:description"),
|
Chris@43
|
264 Node()));
|
Chris@43
|
265 if (desc.type == Node::Literal) {
|
Chris@43
|
266 info.description = desc.value;
|
Chris@43
|
267 }
|
Chris@78
|
268
|
Chris@78
|
269 Node page = store.complete(Triple(t.subject(),
|
Chris@78
|
270 store.expand("foaf:page"),
|
Chris@78
|
271 Node()));
|
Chris@79
|
272 if (page.type == Node::URI) {
|
Chris@79
|
273 info.page = page.value;
|
Chris@78
|
274 }
|
Chris@43
|
275
|
Chris@47
|
276 Triples pp = store.match(Triple(t.subject(),
|
Chris@47
|
277 store.expand("vamp:available_plugin"),
|
Chris@47
|
278 Node()));
|
Chris@47
|
279 for (auto p: pp) {
|
Chris@47
|
280 Node ptitle = store.complete(Triple(p.object(),
|
Chris@47
|
281 store.expand("dc:title"),
|
Chris@47
|
282 Node()));
|
Chris@47
|
283 if (ptitle.type == Node::Literal) {
|
Chris@47
|
284 info.pluginTitles.push_back(ptitle.value);
|
Chris@47
|
285 }
|
Chris@67
|
286
|
Chris@67
|
287 Node pident = store.complete(Triple(p.object(),
|
Chris@67
|
288 store.expand("vamp:identifier"),
|
Chris@67
|
289 Node()));
|
Chris@67
|
290 Node pversion = store.complete(Triple(p.object(),
|
Chris@67
|
291 store.expand("owl:versionInfo"),
|
Chris@67
|
292 Node()));
|
Chris@67
|
293 if (pident.type == Node::Literal &&
|
Chris@67
|
294 pversion.type == Node::Literal) {
|
Chris@67
|
295 bool ok = false;
|
Chris@67
|
296 int version = pversion.value.toInt(&ok);
|
Chris@67
|
297 if (ok) {
|
Chris@67
|
298 info.pluginVersions[pident.value] = version;
|
Chris@67
|
299 }
|
Chris@67
|
300 }
|
Chris@47
|
301 }
|
Chris@74
|
302
|
Chris@74
|
303 info.licence = identifyLicence(libId.value);
|
Chris@74
|
304 SVCERR << "licence = " << info.licence << endl;
|
Chris@47
|
305
|
Chris@43
|
306 results.push_back(info);
|
Chris@50
|
307 wanted.erase(libId.value);
|
Chris@43
|
308 }
|
Chris@43
|
309
|
Chris@50
|
310 for (auto wp: wanted) {
|
Chris@51
|
311 SVCERR << "Failed to find any RDF information about library "
|
Chris@51
|
312 << wp.second << endl;
|
Chris@50
|
313 }
|
Chris@50
|
314
|
Chris@43
|
315 return results;
|
Chris@43
|
316 }
|
Chris@43
|
317
|
Chris@67
|
318 struct TempFileDeleter {
|
Chris@67
|
319 ~TempFileDeleter() {
|
Chris@67
|
320 if (tempFile != "") {
|
Chris@67
|
321 QFile(tempFile).remove();
|
Chris@67
|
322 }
|
Chris@67
|
323 }
|
Chris@67
|
324 QString tempFile;
|
Chris@67
|
325 };
|
Chris@67
|
326
|
Chris@67
|
327 map<QString, int>
|
Chris@70
|
328 getLibraryPluginVersions(QString libraryFilePath)
|
Chris@67
|
329 {
|
Chris@67
|
330 static QMutex mutex;
|
Chris@67
|
331 static QString tempFileName;
|
Chris@67
|
332 static TempFileDeleter deleter;
|
Chris@67
|
333 static bool initHappened = false, initSucceeded = false;
|
Chris@67
|
334
|
Chris@67
|
335 QMutexLocker locker (&mutex);
|
Chris@67
|
336
|
Chris@67
|
337 if (!initHappened) {
|
Chris@67
|
338 initHappened = true;
|
Chris@67
|
339
|
Chris@67
|
340 QTemporaryFile tempFile;
|
Chris@67
|
341 tempFile.setAutoRemove(false);
|
Chris@67
|
342 if (!tempFile.open()) {
|
Chris@67
|
343 SVCERR << "ERROR: Failed to open a temporary file" << endl;
|
Chris@67
|
344 return {};
|
Chris@67
|
345 }
|
Chris@67
|
346
|
Chris@67
|
347 // We can't make the QTemporaryFile static, as it will hold
|
Chris@67
|
348 // the file open and that prevents us from executing it. Hence
|
Chris@67
|
349 // the separate deleter.
|
Chris@67
|
350
|
Chris@67
|
351 tempFileName = tempFile.fileName();
|
Chris@67
|
352 deleter.tempFile = tempFileName;
|
Chris@67
|
353
|
Chris@67
|
354 #ifdef Q_OS_WIN32
|
Chris@67
|
355 QString helperPath = ":out/get-version.exe";
|
Chris@67
|
356 #else
|
Chris@67
|
357 QString helperPath = ":out/get-version";
|
Chris@67
|
358 #endif
|
Chris@67
|
359 QFile helper(helperPath);
|
Chris@67
|
360 if (!helper.open(QFile::ReadOnly)) {
|
Chris@67
|
361 SVCERR << "ERROR: Failed to read helper code" << endl;
|
Chris@67
|
362 return {};
|
Chris@67
|
363 }
|
Chris@67
|
364 QByteArray content = helper.readAll();
|
Chris@67
|
365 helper.close();
|
Chris@67
|
366
|
Chris@67
|
367 if (tempFile.write(content) != content.size()) {
|
Chris@67
|
368 SVCERR << "ERROR: Incomplete write to temporary file" << endl;
|
Chris@67
|
369 return {};
|
Chris@67
|
370 }
|
Chris@67
|
371 tempFile.close();
|
Chris@67
|
372
|
Chris@67
|
373 if (!QFile::setPermissions
|
Chris@67
|
374 (tempFileName,
|
Chris@67
|
375 QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) {
|
Chris@67
|
376 SVCERR << "ERROR: Failed to set execute permission on helper "
|
Chris@67
|
377 << tempFileName << endl;
|
Chris@67
|
378 return {};
|
Chris@67
|
379 }
|
Chris@67
|
380
|
Chris@67
|
381 initSucceeded = true;
|
Chris@67
|
382 }
|
Chris@67
|
383
|
Chris@67
|
384 if (!initSucceeded) {
|
Chris@67
|
385 return {};
|
Chris@67
|
386 }
|
Chris@67
|
387
|
Chris@67
|
388 QProcess process;
|
Chris@67
|
389 process.start(tempFileName, { libraryFilePath });
|
Chris@67
|
390
|
Chris@67
|
391 if (!process.waitForStarted()) {
|
Chris@67
|
392 QProcess::ProcessError err = process.error();
|
Chris@67
|
393 if (err == QProcess::FailedToStart) {
|
Chris@67
|
394 SVCERR << "Unable to start helper process " << tempFileName << endl;
|
Chris@67
|
395 } else if (err == QProcess::Crashed) {
|
Chris@67
|
396 SVCERR << "Helper process " << tempFileName
|
Chris@67
|
397 << " crashed on startup" << endl;
|
Chris@67
|
398 } else {
|
Chris@67
|
399 SVCERR << "Helper process " << tempFileName
|
Chris@67
|
400 << " failed on startup with error code " << err << endl;
|
Chris@67
|
401 }
|
Chris@67
|
402 return {};
|
Chris@67
|
403 }
|
Chris@67
|
404 process.waitForFinished();
|
Chris@67
|
405
|
Chris@67
|
406 QByteArray stdOut = process.readAllStandardOutput();
|
Chris@67
|
407 QByteArray stdErr = process.readAllStandardError();
|
Chris@67
|
408
|
Chris@67
|
409 QString errStr = QString::fromUtf8(stdErr);
|
Chris@67
|
410 if (!errStr.isEmpty()) {
|
Chris@67
|
411 SVCERR << "Note: Helper process stderr follows:" << endl;
|
Chris@67
|
412 SVCERR << errStr << endl;
|
Chris@67
|
413 SVCERR << "Note: Helper process stderr ends" << endl;
|
Chris@67
|
414 }
|
Chris@67
|
415
|
Chris@67
|
416 QStringList lines = QString::fromUtf8(stdOut).split
|
Chris@67
|
417 (QRegExp("[\\r\\n]+"), QString::SkipEmptyParts);
|
Chris@67
|
418 map<QString, int> versions;
|
Chris@67
|
419 for (QString line: lines) {
|
Chris@67
|
420 QStringList parts = line.split(":");
|
Chris@67
|
421 if (parts.size() != 2) {
|
Chris@67
|
422 SVCERR << "Unparseable output line: " << line << endl;
|
Chris@67
|
423 continue;
|
Chris@67
|
424 }
|
Chris@67
|
425 bool ok = false;
|
Chris@67
|
426 int version = parts[1].toInt(&ok);
|
Chris@67
|
427 if (!ok) {
|
Chris@67
|
428 SVCERR << "Unparseable version number in line: " << line << endl;
|
Chris@67
|
429 continue;
|
Chris@67
|
430 }
|
Chris@67
|
431 versions[parts[0]] = version;
|
Chris@67
|
432 }
|
Chris@67
|
433
|
Chris@67
|
434 return versions;
|
Chris@67
|
435 }
|
Chris@67
|
436
|
Chris@67
|
437 bool isLibraryNewer(map<QString, int> a, map<QString, int> b)
|
Chris@67
|
438 {
|
Chris@67
|
439 // a and b are maps from plugin id to plugin version for libraries
|
Chris@67
|
440 // A and B. (There is no overarching library version number.) We
|
Chris@67
|
441 // deem library A to be newer than library B if:
|
Chris@67
|
442 //
|
Chris@67
|
443 // 1. A contains a plugin id that is also in B, whose version in
|
Chris@67
|
444 // A is newer than that in B, or
|
Chris@67
|
445 //
|
Chris@67
|
446 // 2. B is not newer than A according to rule 1, and neither A or
|
Chris@67
|
447 // B is empty, and A contains a plugin id that is not in B, and B
|
Chris@67
|
448 // does not contain any plugin id that is not in A
|
Chris@67
|
449 //
|
Chris@67
|
450 // (The not-empty part of rule 2 is just to avoid false positives
|
Chris@67
|
451 // when a library or its metadata could not be read at all.)
|
Chris@67
|
452
|
Chris@67
|
453 auto containsANewerPlugin = [](const map<QString, int> &m1,
|
Chris@67
|
454 const map<QString, int> &m2) {
|
Chris@67
|
455 for (auto p: m1) {
|
Chris@67
|
456 if (m2.find(p.first) != m2.end() &&
|
Chris@67
|
457 p.second > m2.at(p.first)) {
|
Chris@67
|
458 return true;
|
Chris@67
|
459 }
|
Chris@67
|
460 }
|
Chris@67
|
461 return false;
|
Chris@67
|
462 };
|
Chris@67
|
463
|
Chris@67
|
464 auto containsANovelPlugin = [](const map<QString, int> &m1,
|
Chris@67
|
465 const map<QString, int> &m2) {
|
Chris@67
|
466 for (auto p: m1) {
|
Chris@67
|
467 if (m2.find(p.first) == m2.end()) {
|
Chris@67
|
468 return true;
|
Chris@67
|
469 }
|
Chris@67
|
470 }
|
Chris@67
|
471 return false;
|
Chris@67
|
472 };
|
Chris@67
|
473
|
Chris@67
|
474 if (containsANewerPlugin(a, b)) {
|
Chris@67
|
475 return true;
|
Chris@67
|
476 }
|
Chris@67
|
477
|
Chris@67
|
478 if (!containsANewerPlugin(b, a) &&
|
Chris@67
|
479 !a.empty() &&
|
Chris@67
|
480 !b.empty() &&
|
Chris@67
|
481 containsANovelPlugin(a, b) &&
|
Chris@67
|
482 !containsANovelPlugin(b, a)) {
|
Chris@67
|
483 return true;
|
Chris@67
|
484 }
|
Chris@67
|
485
|
Chris@67
|
486 return false;
|
Chris@67
|
487 }
|
Chris@67
|
488
|
Chris@67
|
489 QString
|
Chris@67
|
490 versionsString(const map<QString, int> &vv)
|
Chris@67
|
491 {
|
Chris@67
|
492 QStringList pv;
|
Chris@67
|
493 for (auto v: vv) {
|
Chris@67
|
494 pv.push_back(QString("%1:%2").arg(v.first).arg(v.second));
|
Chris@67
|
495 }
|
Chris@67
|
496 return "{ " + pv.join(", ") + " }";
|
Chris@67
|
497 }
|
Chris@67
|
498
|
Chris@75
|
499 enum class RelativeStatus {
|
Chris@75
|
500 New,
|
Chris@75
|
501 Same,
|
Chris@75
|
502 Upgrade,
|
Chris@75
|
503 Downgrade,
|
Chris@75
|
504 TargetNotLoadable
|
Chris@75
|
505 };
|
Chris@75
|
506
|
Chris@75
|
507 QString
|
Chris@75
|
508 relativeStatusLabel(RelativeStatus status) {
|
Chris@75
|
509 switch (status) {
|
Chris@76
|
510 case RelativeStatus::New: return QObject::tr("Not yet installed");
|
Chris@76
|
511 case RelativeStatus::Same: return QObject::tr("Already installed");
|
Chris@76
|
512 case RelativeStatus::Upgrade: return QObject::tr("Update");
|
Chris@76
|
513 case RelativeStatus::Downgrade: return QObject::tr("Newer version installed");
|
Chris@76
|
514 case RelativeStatus::TargetNotLoadable: return QObject::tr("<unknown>");
|
Chris@79
|
515 default: return {};
|
Chris@75
|
516 }
|
Chris@75
|
517 }
|
Chris@75
|
518
|
Chris@75
|
519 RelativeStatus
|
Chris@75
|
520 getRelativeStatus(LibraryInfo info, QString targetDir)
|
Chris@75
|
521 {
|
Chris@75
|
522 QString destination = targetDir + "/" + info.fileName;
|
Chris@75
|
523
|
Chris@75
|
524 RelativeStatus status = RelativeStatus::New;
|
Chris@75
|
525
|
Chris@75
|
526 SVCERR << "\ngetRelativeStatus: " << info.fileName << ":\n";
|
Chris@75
|
527
|
Chris@75
|
528 if (QFileInfo(destination).exists()) {
|
Chris@75
|
529
|
Chris@75
|
530 auto installed = getLibraryPluginVersions(destination);
|
Chris@75
|
531
|
Chris@75
|
532 SVCERR << " * installed: " << versionsString(installed)
|
Chris@75
|
533 << "\n * packaged: " << versionsString(info.pluginVersions)
|
Chris@75
|
534 << endl;
|
Chris@75
|
535
|
Chris@75
|
536 status = RelativeStatus::Same;
|
Chris@75
|
537
|
Chris@75
|
538 if (installed.empty()) {
|
Chris@75
|
539 status = RelativeStatus::TargetNotLoadable;
|
Chris@75
|
540 }
|
Chris@75
|
541
|
Chris@75
|
542 if (isLibraryNewer(installed, info.pluginVersions)) {
|
Chris@75
|
543 status = RelativeStatus::Downgrade;
|
Chris@75
|
544 }
|
Chris@75
|
545
|
Chris@75
|
546 if (isLibraryNewer(info.pluginVersions, installed)) {
|
Chris@75
|
547 status = RelativeStatus::Upgrade;
|
Chris@75
|
548 }
|
Chris@75
|
549 }
|
Chris@75
|
550
|
Chris@75
|
551 SVCERR << " - relative status: " << relativeStatusLabel(status) << endl;
|
Chris@75
|
552
|
Chris@75
|
553 return status;
|
Chris@75
|
554 }
|
Chris@75
|
555
|
Chris@81
|
556 QString
|
Chris@75
|
557 installLibrary(LibraryInfo info, QString targetDir)
|
Chris@42
|
558 {
|
Chris@75
|
559 QString library = info.fileName;
|
Chris@52
|
560 QString source = ":out";
|
Chris@52
|
561 QFile f(source + "/" + library);
|
Chris@75
|
562 QString destination = targetDir + "/" + library;
|
Chris@67
|
563
|
Chris@67
|
564 if (QFileInfo(destination).exists()) {
|
Chris@70
|
565 auto installed = getLibraryPluginVersions(destination);
|
Chris@68
|
566 } else {
|
Chris@68
|
567 SVCERR << "Note: library " << library
|
Chris@68
|
568 << " is not yet installed, not comparing versions" << endl;
|
Chris@67
|
569 }
|
Chris@82
|
570
|
Chris@82
|
571 //!!! if destination exists, move it aside
|
Chris@52
|
572
|
Chris@51
|
573 SVCERR << "Copying " << library.toStdString() << " to "
|
Chris@51
|
574 << destination.toStdString() << "..." << endl;
|
Chris@42
|
575 if (!f.copy(destination)) {
|
Chris@51
|
576 SVCERR << "Failed to copy " << library.toStdString()
|
Chris@51
|
577 << " to target " << destination.toStdString() << endl;
|
Chris@81
|
578 return QObject::tr("Failed to copy library to destination directory");
|
Chris@42
|
579 }
|
Chris@42
|
580 if (!QFile::setPermissions
|
Chris@42
|
581 (destination,
|
Chris@42
|
582 QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner |
|
Chris@42
|
583 QFile::ReadGroup | QFile::ExeGroup |
|
Chris@42
|
584 QFile::ReadOther | QFile::ExeOther)) {
|
Chris@51
|
585 SVCERR << "Failed to set permissions on "
|
Chris@51
|
586 << library.toStdString() << endl;
|
Chris@81
|
587 return QObject::tr("Failed to set correct permissions on installed library");
|
Chris@42
|
588 }
|
Chris@52
|
589
|
Chris@52
|
590 QString base = QFileInfo(library).baseName();
|
Chris@52
|
591 QDir dir(source);
|
Chris@52
|
592 auto entries = dir.entryList({ base + "*" });
|
Chris@52
|
593 for (auto e: entries) {
|
Chris@52
|
594 if (e == library) continue;
|
Chris@75
|
595 QString destination = targetDir + "/" + e;
|
Chris@52
|
596 SVCERR << "Copying " << e.toStdString() << " to "
|
Chris@52
|
597 << destination.toStdString() << "..." << endl;
|
Chris@52
|
598 if (!QFile(source + "/" + e).copy(destination)) {
|
Chris@52
|
599 SVCERR << "Failed to copy " << e.toStdString()
|
Chris@52
|
600 << " to target " << destination.toStdString()
|
Chris@52
|
601 << " (ignoring)" << endl;
|
Chris@68
|
602 continue;
|
Chris@68
|
603 }
|
Chris@68
|
604 if (!QFile::setPermissions
|
Chris@68
|
605 (destination,
|
Chris@68
|
606 QFile::ReadOwner | QFile::WriteOwner |
|
Chris@68
|
607 QFile::ReadGroup |
|
Chris@68
|
608 QFile::ReadOther)) {
|
Chris@68
|
609 SVCERR << "Failed to set permissions on "
|
Chris@68
|
610 << destination.toStdString()
|
Chris@68
|
611 << " (ignoring)" << endl;
|
Chris@68
|
612 continue;
|
Chris@52
|
613 }
|
Chris@52
|
614 }
|
Chris@81
|
615
|
Chris@81
|
616 return {};
|
Chris@42
|
617 }
|
Chris@42
|
618
|
Chris@75
|
619 vector<LibraryInfo>
|
Chris@75
|
620 getUserApprovedPluginLibraries(vector<LibraryInfo> libraries,
|
Chris@75
|
621 QString targetDir)
|
Chris@42
|
622 {
|
Chris@42
|
623 QDialog dialog;
|
Chris@46
|
624
|
Chris@46
|
625 auto mainLayout = new QGridLayout;
|
Chris@47
|
626 mainLayout->setSpacing(0);
|
Chris@46
|
627 dialog.setLayout(mainLayout);
|
Chris@46
|
628
|
Chris@46
|
629 int mainRow = 0;
|
Chris@46
|
630
|
Chris@74
|
631 auto selectionFrame = new QWidget;
|
Chris@74
|
632 mainLayout->addWidget(selectionFrame, mainRow, 0);
|
Chris@47
|
633 ++mainRow;
|
Chris@46
|
634
|
Chris@46
|
635 auto selectionLayout = new QGridLayout;
|
Chris@46
|
636 selectionFrame->setLayout(selectionLayout);
|
Chris@46
|
637 int selectionRow = 0;
|
Chris@79
|
638
|
Chris@79
|
639 selectionLayout->addWidget
|
Chris@79
|
640 (new QLabel(QObject::tr("<b>Vamp Plugin Pack</b> v%1")
|
Chris@79
|
641 .arg(PACK_VERSION)),
|
Chris@79
|
642 selectionRow, 1);
|
Chris@79
|
643 ++selectionRow;
|
Chris@79
|
644
|
Chris@79
|
645 selectionLayout->addWidget
|
Chris@79
|
646 (new QLabel(QObject::tr("Select the plugin libraries to install:")),
|
Chris@79
|
647 selectionRow, 1, 1, 3);
|
Chris@79
|
648 ++selectionRow;
|
Chris@74
|
649
|
Chris@74
|
650 auto checkAll = new QCheckBox;
|
Chris@74
|
651 checkAll->setChecked(true);
|
Chris@74
|
652 selectionLayout->addWidget(checkAll, selectionRow, 0, Qt::AlignHCenter);
|
Chris@74
|
653 ++selectionRow;
|
Chris@74
|
654
|
Chris@74
|
655 auto checkArrow = new QLabel("▼");
|
Chris@74
|
656 checkArrow->setTextFormat(Qt::RichText);
|
Chris@74
|
657 selectionLayout->addWidget(checkArrow, selectionRow, 0, Qt::AlignHCenter);
|
Chris@74
|
658 ++selectionRow;
|
Chris@42
|
659
|
Chris@67
|
660 map<QString, QCheckBox *> checkBoxMap; // filename -> checkbox
|
Chris@67
|
661 map<QString, LibraryInfo> libFileInfo; // filename -> info
|
Chris@76
|
662 map<QString, RelativeStatus> statuses; // filename -> status
|
Chris@43
|
663
|
Chris@67
|
664 map<QString, LibraryInfo, function<bool (QString, QString)>>
|
Chris@49
|
665 orderedInfo
|
Chris@49
|
666 ([](QString k1, QString k2) {
|
Chris@49
|
667 return k1.localeAwareCompare(k2) < 0;
|
Chris@49
|
668 });
|
Chris@43
|
669 for (auto info: libraries) {
|
Chris@43
|
670 orderedInfo[info.title] = info;
|
Chris@43
|
671 }
|
Chris@53
|
672
|
Chris@74
|
673 int fontHeight = QFontMetrics(checkArrow->font()).height();
|
Chris@77
|
674 int dpratio = dialog.devicePixelRatio();
|
Chris@74
|
675
|
Chris@77
|
676 QPixmap infoMap(fontHeight * dpratio, fontHeight * dpratio);
|
Chris@77
|
677 QPixmap moreMap(fontHeight * dpratio * 2, fontHeight * dpratio * 2);
|
Chris@74
|
678 infoMap.fill(Qt::transparent);
|
Chris@74
|
679 moreMap.fill(Qt::transparent);
|
Chris@74
|
680 QSvgRenderer renderer(QString(":icons/scalable/info.svg"));
|
Chris@74
|
681 QPainter painter;
|
Chris@74
|
682 painter.begin(&infoMap);
|
Chris@74
|
683 renderer.render(&painter);
|
Chris@74
|
684 painter.end();
|
Chris@74
|
685 painter.begin(&moreMap);
|
Chris@74
|
686 renderer.render(&painter);
|
Chris@74
|
687 painter.end();
|
Chris@74
|
688
|
Chris@76
|
689 auto shouldCheck = [](RelativeStatus status) {
|
Chris@76
|
690 return (status == RelativeStatus::New ||
|
Chris@76
|
691 status == RelativeStatus::Upgrade ||
|
Chris@76
|
692 status == RelativeStatus::TargetNotLoadable);
|
Chris@76
|
693 };
|
Chris@76
|
694
|
Chris@43
|
695 for (auto ip: orderedInfo) {
|
Chris@46
|
696
|
Chris@46
|
697 auto cb = new QCheckBox;
|
Chris@74
|
698 selectionLayout->addWidget(cb, selectionRow, 0, Qt::AlignHCenter);
|
Chris@46
|
699
|
Chris@43
|
700 LibraryInfo info = ip.second;
|
Chris@72
|
701
|
Chris@76
|
702 auto shortLabel = new QLabel(info.title);
|
Chris@76
|
703 selectionLayout->addWidget(shortLabel, selectionRow, 1);
|
Chris@76
|
704
|
Chris@75
|
705 RelativeStatus relativeStatus = getRelativeStatus(info, targetDir);
|
Chris@76
|
706 auto statusLabel = new QLabel(relativeStatusLabel(relativeStatus));
|
Chris@76
|
707 selectionLayout->addWidget(statusLabel, selectionRow, 2);
|
Chris@76
|
708 cb->setChecked(shouldCheck(relativeStatus));
|
Chris@75
|
709
|
Chris@79
|
710 auto infoButton = new QToolButton;
|
Chris@79
|
711 infoButton->setAutoRaise(true);
|
Chris@79
|
712 infoButton->setIcon(infoMap);
|
Chris@79
|
713 infoButton->setIconSize(QSize(fontHeight, fontHeight));
|
Chris@77
|
714
|
Chris@77
|
715 #ifdef Q_OS_MAC
|
Chris@79
|
716 infoButton->setFixedSize(QSize(int(fontHeight * 1.2),
|
Chris@77
|
717 int(fontHeight * 1.2)));
|
Chris@79
|
718 infoButton->setStyleSheet("QToolButton { border: none; }");
|
Chris@77
|
719 #endif
|
Chris@77
|
720
|
Chris@79
|
721 selectionLayout->addWidget(infoButton, selectionRow, 3);
|
Chris@46
|
722
|
Chris@46
|
723 ++selectionRow;
|
Chris@46
|
724
|
Chris@77
|
725 QString moreTitleText = QObject::tr("<b>%1</b><br><i>%2</i>")
|
Chris@72
|
726 .arg(info.title)
|
Chris@77
|
727 .arg(info.maker);
|
Chris@77
|
728
|
Chris@79
|
729 QString moreInfoText = info.description;
|
Chris@79
|
730
|
Chris@79
|
731 if (info.page != "") {
|
Chris@79
|
732 moreInfoText += QObject::tr("<br><a href=\"%1\">%2</a>")
|
Chris@79
|
733 .arg(info.page)
|
Chris@79
|
734 .arg(info.page);
|
Chris@79
|
735 }
|
Chris@79
|
736
|
Chris@79
|
737 moreInfoText += QObject::tr("<br><br>Library contains:<ul>");
|
Chris@73
|
738
|
Chris@73
|
739 int n = 0;
|
Chris@73
|
740 bool closed = false;
|
Chris@73
|
741 for (auto title: info.pluginTitles) {
|
Chris@73
|
742 if (n == 10 && info.pluginTitles.size() > 15) {
|
Chris@77
|
743 moreInfoText += QObject::tr("</ul>");
|
Chris@77
|
744 moreInfoText += QObject::tr("... and %n other plugins.<br><br>",
|
Chris@77
|
745 "",
|
Chris@77
|
746 info.pluginTitles.size() - n);
|
Chris@73
|
747 closed = true;
|
Chris@73
|
748 break;
|
Chris@73
|
749 }
|
Chris@77
|
750 moreInfoText += QObject::tr("<li>%1</li>").arg(title);
|
Chris@73
|
751 ++n;
|
Chris@73
|
752 }
|
Chris@73
|
753
|
Chris@73
|
754 if (!closed) {
|
Chris@77
|
755 moreInfoText += QObject::tr("</ul>");
|
Chris@73
|
756 }
|
Chris@74
|
757
|
Chris@74
|
758 if (info.licence != "") {
|
Chris@77
|
759 moreInfoText += QObject::tr("Provided under the %1.<br>")
|
Chris@77
|
760 .arg(info.licence);
|
Chris@74
|
761 }
|
Chris@72
|
762
|
Chris@79
|
763 QObject::connect(infoButton, &QAbstractButton::clicked,
|
Chris@72
|
764 [=]() {
|
Chris@74
|
765 QMessageBox mbox;
|
Chris@74
|
766 mbox.setIconPixmap(moreMap);
|
Chris@74
|
767 mbox.setWindowTitle(QObject::tr("Library contents"));
|
Chris@77
|
768 mbox.setText(moreTitleText);
|
Chris@77
|
769 mbox.setInformativeText(moreInfoText);
|
Chris@74
|
770 mbox.exec();
|
Chris@72
|
771 });
|
Chris@72
|
772
|
Chris@43
|
773 checkBoxMap[info.fileName] = cb;
|
Chris@67
|
774 libFileInfo[info.fileName] = info;
|
Chris@76
|
775 statuses[info.fileName] = relativeStatus;
|
Chris@42
|
776 }
|
Chris@42
|
777
|
Chris@79
|
778 selectionLayout->addItem(new QSpacerItem(1, (fontHeight*2) / 3),
|
Chris@79
|
779 selectionRow, 0);
|
Chris@79
|
780 ++selectionRow;
|
Chris@79
|
781
|
Chris@79
|
782 selectionLayout->addWidget
|
Chris@79
|
783 (new QLabel(QObject::tr("Installation will be to: %1").arg(targetDir)),
|
Chris@79
|
784 selectionRow, 1, 1, 3);
|
Chris@79
|
785 ++selectionRow;
|
Chris@79
|
786
|
Chris@47
|
787 QObject::connect(checkAll, &QCheckBox::toggled,
|
Chris@72
|
788 [=](bool toCheck) {
|
Chris@47
|
789 for (auto p: checkBoxMap) {
|
Chris@47
|
790 p.second->setChecked(toCheck);
|
Chris@47
|
791 }
|
Chris@47
|
792 });
|
Chris@79
|
793
|
Chris@79
|
794 mainLayout->addItem(new QSpacerItem(1, fontHeight), mainRow, 0);
|
Chris@79
|
795 ++mainRow;
|
Chris@79
|
796
|
Chris@42
|
797 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok |
|
Chris@76
|
798 QDialogButtonBox::Cancel |
|
Chris@76
|
799 QDialogButtonBox::Reset);
|
Chris@79
|
800 bb->button(QDialogButtonBox::Ok)->setText(QObject::tr("Install"));
|
Chris@74
|
801 mainLayout->addWidget(bb, mainRow, 0);
|
Chris@46
|
802 ++mainRow;
|
Chris@47
|
803
|
Chris@74
|
804 mainLayout->setRowStretch(0, 10);
|
Chris@74
|
805 mainLayout->setColumnStretch(0, 10);
|
Chris@74
|
806 selectionLayout->setColumnMinimumWidth(0, 50);
|
Chris@74
|
807 selectionLayout->setColumnStretch(1, 10);
|
Chris@47
|
808
|
Chris@76
|
809 QObject::connect
|
Chris@76
|
810 (bb, &QDialogButtonBox::clicked,
|
Chris@76
|
811 [&](QAbstractButton *button) {
|
Chris@76
|
812
|
Chris@76
|
813 auto role = bb->buttonRole(button);
|
Chris@76
|
814
|
Chris@76
|
815 switch (role) {
|
Chris@76
|
816
|
Chris@76
|
817 case QDialogButtonBox::AcceptRole: {
|
Chris@76
|
818 bool downgrade = false;
|
Chris@76
|
819 for (const auto &p: checkBoxMap) {
|
Chris@76
|
820 if (p.second->isChecked() &&
|
Chris@76
|
821 statuses.at(p.first) == RelativeStatus::Downgrade) {
|
Chris@76
|
822 downgrade = true;
|
Chris@76
|
823 break;
|
Chris@76
|
824 }
|
Chris@76
|
825 }
|
Chris@76
|
826 if (downgrade) {
|
Chris@76
|
827 if (QMessageBox::warning
|
Chris@76
|
828 (bb, QObject::tr("Downgrade?"),
|
Chris@76
|
829 QObject::tr("You have asked to downgrade one or more plugin libraries that are already installed.<br><br>Are you sure?"),
|
Chris@76
|
830 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@76
|
831 QMessageBox::Cancel) == QMessageBox::Ok) {
|
Chris@76
|
832 dialog.accept();
|
Chris@76
|
833 }
|
Chris@76
|
834 } else {
|
Chris@76
|
835 dialog.accept();
|
Chris@76
|
836 }
|
Chris@76
|
837 break;
|
Chris@76
|
838 }
|
Chris@76
|
839
|
Chris@76
|
840 case QDialogButtonBox::RejectRole:
|
Chris@76
|
841 dialog.reject();
|
Chris@76
|
842 break;
|
Chris@76
|
843
|
Chris@76
|
844 case QDialogButtonBox::ResetRole:
|
Chris@76
|
845 for (const auto &p: checkBoxMap) {
|
Chris@76
|
846 p.second->setChecked(shouldCheck(statuses.at(p.first)));
|
Chris@76
|
847 }
|
Chris@76
|
848 break;
|
Chris@76
|
849
|
Chris@76
|
850 default:
|
Chris@76
|
851 SVCERR << "WARNING: Unexpected role " << role << endl;
|
Chris@76
|
852 }
|
Chris@76
|
853 });
|
Chris@53
|
854
|
Chris@70
|
855 if (dialog.exec() != QDialog::Accepted) {
|
Chris@51
|
856 SVCERR << "rejected" << endl;
|
Chris@70
|
857 return {};
|
Chris@42
|
858 }
|
Chris@42
|
859
|
Chris@75
|
860 vector<LibraryInfo> approved;
|
Chris@42
|
861 for (const auto &p: checkBoxMap) {
|
Chris@42
|
862 if (p.second->isChecked()) {
|
Chris@75
|
863 approved.push_back(libFileInfo[p.first]);
|
Chris@33
|
864 }
|
Chris@42
|
865 }
|
Chris@42
|
866
|
Chris@42
|
867 return approved;
|
Chris@42
|
868 }
|
Chris@42
|
869
|
Chris@42
|
870 int main(int argc, char **argv)
|
Chris@42
|
871 {
|
Chris@42
|
872 QApplication app(argc, argv);
|
Chris@42
|
873
|
Chris@51
|
874 QApplication::setOrganizationName("sonic-visualiser");
|
Chris@51
|
875 QApplication::setOrganizationDomain("sonicvisualiser.org");
|
Chris@51
|
876 QApplication::setApplicationName(QApplication::tr("Vamp Plugin Pack Installer"));
|
Chris@51
|
877
|
Chris@77
|
878 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
Chris@77
|
879
|
Chris@51
|
880 #ifdef Q_OS_WIN32
|
Chris@51
|
881 QFont font(QApplication::font());
|
Chris@51
|
882 QString preferredFamily = "Segoe UI";
|
Chris@51
|
883 font.setFamily(preferredFamily);
|
Chris@51
|
884 if (QFontInfo(font).family() == preferredFamily) {
|
Chris@51
|
885 font.setPointSize(10);
|
Chris@51
|
886 QApplication::setFont(font);
|
Chris@51
|
887 }
|
Chris@77
|
888 #else
|
Chris@77
|
889 #ifdef Q_OS_MAC
|
Chris@77
|
890 QFont font(QApplication::font());
|
Chris@77
|
891 QString preferredFamily = "Lucida Grande";
|
Chris@77
|
892 font.setFamily(preferredFamily);
|
Chris@77
|
893 if (QFontInfo(font).family() == preferredFamily) {
|
Chris@77
|
894 QApplication::setFont(font);
|
Chris@77
|
895 }
|
Chris@77
|
896 #endif
|
Chris@51
|
897 #endif
|
Chris@51
|
898
|
Chris@42
|
899 QString target = getDefaultInstallDirectory();
|
Chris@42
|
900 if (target == "") {
|
Chris@42
|
901 return 1;
|
Chris@42
|
902 }
|
Chris@42
|
903
|
Chris@42
|
904 QStringList libraries = getPluginLibraryList();
|
Chris@42
|
905
|
Chris@43
|
906 auto rdfStore = loadLibrariesRdf();
|
Chris@43
|
907
|
Chris@43
|
908 auto info = getLibraryInfo(*rdfStore, libraries);
|
Chris@43
|
909
|
Chris@75
|
910 vector<LibraryInfo> toInstall =
|
Chris@75
|
911 getUserApprovedPluginLibraries(info, target);
|
Chris@52
|
912
|
Chris@83
|
913 if (toInstall.empty()) { // Cancelled, or nothing selected
|
Chris@83
|
914 return 0;
|
Chris@83
|
915 }
|
Chris@83
|
916
|
Chris@83
|
917 if (!QDir(target).exists()) {
|
Chris@83
|
918 QDir().mkpath(target);
|
Chris@52
|
919 }
|
Chris@81
|
920
|
Chris@81
|
921 QProgressDialog progress(QObject::tr("Installing..."),
|
Chris@81
|
922 QObject::tr("Stop"), 0, toInstall.size() + 1);
|
Chris@81
|
923 progress.setMinimumDuration(0);
|
Chris@81
|
924
|
Chris@81
|
925 int pval = 0;
|
Chris@81
|
926 bool complete = true;
|
Chris@42
|
927
|
Chris@42
|
928 for (auto lib: toInstall) {
|
Chris@81
|
929 progress.setValue(++pval);
|
Chris@81
|
930 QThread::currentThread()->msleep(40);
|
Chris@81
|
931 app.processEvents();
|
Chris@81
|
932 if (progress.wasCanceled()) {
|
Chris@81
|
933 complete = false;
|
Chris@81
|
934 break;
|
Chris@81
|
935 }
|
Chris@81
|
936 QString error = installLibrary(lib, target);
|
Chris@81
|
937 if (error != "") {
|
Chris@81
|
938 complete = false;
|
Chris@81
|
939 if (QMessageBox::critical
|
Chris@81
|
940 (&progress,
|
Chris@81
|
941 QObject::tr("Install failed"),
|
Chris@81
|
942 QObject::tr("Failed to install library \"%1\": %2")
|
Chris@81
|
943 .arg(lib.title)
|
Chris@81
|
944 .arg(error),
|
Chris@81
|
945 QMessageBox::Abort | QMessageBox::Ignore,
|
Chris@81
|
946 QMessageBox::Ignore) ==
|
Chris@81
|
947 QMessageBox::Abort) {
|
Chris@81
|
948 break;
|
Chris@81
|
949 }
|
Chris@81
|
950 }
|
Chris@81
|
951 }
|
Chris@81
|
952
|
Chris@81
|
953 progress.hide();
|
Chris@81
|
954
|
Chris@81
|
955 if (complete) {
|
Chris@81
|
956 QMessageBox::information
|
Chris@81
|
957 (&progress,
|
Chris@81
|
958 QObject::tr("Complete"),
|
Chris@81
|
959 QObject::tr("Installation completed successfully"),
|
Chris@81
|
960 QMessageBox::Ok,
|
Chris@81
|
961 QMessageBox::Ok);
|
Chris@81
|
962 } else {
|
Chris@81
|
963 QMessageBox::information
|
Chris@81
|
964 (&progress,
|
Chris@81
|
965 QObject::tr("Incomplete"),
|
Chris@81
|
966 QObject::tr("Installation was not complete. Exiting"),
|
Chris@81
|
967 QMessageBox::Ok,
|
Chris@81
|
968 QMessageBox::Ok);
|
Chris@33
|
969 }
|
Chris@33
|
970
|
Chris@83
|
971 return (complete ? 0 : 2);
|
Chris@32
|
972 }
|