Chris@1178
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1178
|
2
|
Chris@1178
|
3 /*
|
Chris@1178
|
4 Sonic Visualiser
|
Chris@1178
|
5 An audio file viewer and annotation editor.
|
Chris@1178
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1178
|
7
|
Chris@1178
|
8 This program is free software; you can redistribute it and/or
|
Chris@1178
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1178
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1178
|
11 License, or (at your option) any later version. See the file
|
Chris@1178
|
12 COPYING included with this distribution for more information.
|
Chris@1178
|
13 */
|
Chris@1178
|
14
|
Chris@1178
|
15 #include "PluginScan.h"
|
Chris@1178
|
16
|
Chris@1178
|
17 #include "base/Debug.h"
|
Chris@1178
|
18
|
Chris@1180
|
19 #include "checker/knownplugins.h"
|
Chris@1180
|
20
|
Chris@1178
|
21 #include <QMutex>
|
Chris@1178
|
22
|
Chris@1178
|
23 using std::string;
|
Chris@1178
|
24
|
Chris@1180
|
25 class PluginScan::Logger : public PluginCandidates::LogCallback
|
Chris@1180
|
26 {
|
Chris@1180
|
27 protected:
|
Chris@1180
|
28 void log(std::string message) {
|
Chris@1180
|
29 SVDEBUG << "PluginScan: " << message;
|
Chris@1180
|
30 }
|
Chris@1180
|
31 };
|
Chris@1180
|
32
|
Chris@1180
|
33 PluginScan *PluginScan::getInstance()
|
Chris@1180
|
34 {
|
Chris@1178
|
35 static QMutex mutex;
|
Chris@1178
|
36 static PluginScan *m_instance = 0;
|
Chris@1178
|
37 mutex.lock();
|
Chris@1178
|
38 if (!m_instance) m_instance = new PluginScan();
|
Chris@1178
|
39 mutex.unlock();
|
Chris@1178
|
40 return m_instance;
|
Chris@1178
|
41 }
|
Chris@1178
|
42
|
Chris@1180
|
43 PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) {
|
Chris@1178
|
44 }
|
Chris@1178
|
45
|
Chris@1178
|
46 PluginScan::~PluginScan() {
|
Chris@1178
|
47 delete m_kp;
|
Chris@1180
|
48 delete m_logger;
|
Chris@1178
|
49 }
|
Chris@1178
|
50
|
Chris@1178
|
51 void
|
Chris@1178
|
52 PluginScan::scan()
|
Chris@1178
|
53 {
|
Chris@1178
|
54 delete m_kp;
|
Chris@1179
|
55 m_succeeded = false;
|
Chris@1179
|
56 try {
|
Chris@1180
|
57 m_kp = new KnownPlugins("./helper", m_logger); //!!!
|
Chris@1179
|
58 m_succeeded = true;
|
Chris@1179
|
59 } catch (const std::exception &e) {
|
Chris@1179
|
60 cerr << "ERROR: PluginScan::scan: " << e.what() << endl;
|
Chris@1179
|
61 m_kp = 0;
|
Chris@1179
|
62 }
|
Chris@1179
|
63 }
|
Chris@1179
|
64
|
Chris@1179
|
65 QStringList
|
Chris@1180
|
66 PluginScan::getCandidateLibrariesFor(PluginType type) const
|
Chris@1179
|
67 {
|
Chris@1180
|
68 KnownPlugins::PluginType kpt;
|
Chris@1180
|
69 switch (type) {
|
Chris@1180
|
70 case VampPlugin: kpt = KnownPlugins::VampPlugin; break;
|
Chris@1180
|
71 case LADSPAPlugin: kpt = KnownPlugins::LADSPAPlugin; break;
|
Chris@1180
|
72 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break;
|
Chris@1180
|
73 default: throw std::logic_error("Inconsistency in plugin type enums");
|
Chris@1180
|
74 }
|
Chris@1180
|
75
|
Chris@1179
|
76 QStringList candidates;
|
Chris@1179
|
77 if (!m_kp) return candidates;
|
Chris@1180
|
78 auto c = m_kp->getCandidateLibrariesFor(kpt);
|
Chris@1179
|
79 for (auto s: c) candidates.push_back(s.c_str());
|
Chris@1179
|
80 return candidates;
|
Chris@1178
|
81 }
|
Chris@1178
|
82
|
Chris@1178
|
83 QString
|
Chris@1178
|
84 PluginScan::getStartupFailureReport() const
|
Chris@1178
|
85 {
|
Chris@1179
|
86 if (!m_succeeded) {
|
Chris@1179
|
87 return QObject::tr("<b>Failed to scan for plugins</b>"
|
Chris@1179
|
88 "<p>Failed to scan for plugins at startup "
|
Chris@1179
|
89 "(application installation problem?)</p>");
|
Chris@1179
|
90 }
|
Chris@1179
|
91 if (!m_kp) {
|
Chris@1179
|
92 return QObject::tr("<b>Did not scan for plugins</b>"
|
Chris@1179
|
93 "<p>Apparently no scan for plugins was attempted "
|
Chris@1179
|
94 "(internal error?)</p>");
|
Chris@1179
|
95 }
|
Chris@1179
|
96
|
Chris@1178
|
97 string report = m_kp->getFailureReport();
|
Chris@1179
|
98 if (report == "") {
|
Chris@1179
|
99 return QString(report.c_str());
|
Chris@1179
|
100 }
|
Chris@1179
|
101
|
Chris@1179
|
102 return QObject::tr("<b>Failed to load plugins</b>"
|
Chris@1179
|
103 "<p>Failed to load one or more plugin libraries:</p>")
|
Chris@1179
|
104 + QString(report.c_str());
|
Chris@1178
|
105 }
|
Chris@1178
|
106
|