comparison plugin/PluginScan.cpp @ 1503:2057423c88fe

Merge from branch checker_errorcode
author Chris Cannam
date Fri, 31 Aug 2018 15:15:31 +0100
parents 2765b9db402b
children d7fdc77252c6
comparison
equal deleted inserted replaced
1499:68a0abfe7263 1503:2057423c88fe
16 16
17 #include "base/Debug.h" 17 #include "base/Debug.h"
18 #include "base/Preferences.h" 18 #include "base/Preferences.h"
19 #include "base/HelperExecPath.h" 19 #include "base/HelperExecPath.h"
20 20
21 #ifdef HAVE_PLUGIN_CHECKER_HELPER 21 #include <sstream>
22 #include "checker/knownplugincandidates.h"
23 #else
24 class KnownPluginCandidates {};
25 #endif
26 22
27 #include <QMutex> 23 #include <QMutex>
28 #include <QCoreApplication> 24 #include <QCoreApplication>
29 25
30 using std::string; 26 using std::string;
180 #else 176 #else
181 return {}; 177 return {};
182 #endif 178 #endif
183 } 179 }
184 180
181 #ifdef HAVE_PLUGIN_CHECKER_HELPER
182 QString
183 PluginScan::formatFailureReport(QString tag,
184 std::vector<PluginCandidates::FailureRec> failures) const
185 {
186 int n = int(failures.size());
187 int i = 0;
188
189 std::ostringstream os;
190
191 os << "<ul>";
192 for (auto f: failures) {
193 os << "<li>" + f.library;
194
195 SVDEBUG << "PluginScan::formatFailureReport: tag is \"" << tag
196 << "\", failure code is " << int(f.code) << ", message is \""
197 << f.message << "\"" << endl;
198
199 QString userMessage = QString::fromStdString(f.message);
200
201 switch (f.code) {
202
203 case PluginCheckCode::FAIL_LIBRARY_NOT_FOUND:
204 userMessage = QObject::tr("Library file could not be opened");
205 break;
206
207 case PluginCheckCode::FAIL_WRONG_ARCHITECTURE:
208 if (tag == "64" || (sizeof(void *) == 8 && tag == "")) {
209 userMessage = QObject::tr
210 ("Library has wrong architecture - possibly a 32-bit plugin installed in a folder for 64-bit plugins");
211 } else if (tag == "32" || (sizeof(void *) == 4 && tag == "")) {
212 userMessage = QObject::tr
213 ("Library has wrong architecture - possibly a 64-bit plugin installed in a folder for 32-bit plugins");
214 }
215 break;
216
217 case PluginCheckCode::FAIL_DEPENDENCY_MISSING:
218 userMessage = QObject::tr
219 ("Library depends on another library that cannot be found: %1")
220 .arg(userMessage);
221 break;
222
223 case PluginCheckCode::FAIL_NOT_LOADABLE:
224 userMessage = QObject::tr
225 ("Library cannot be loaded: %1").arg(userMessage);
226 break;
227
228 case PluginCheckCode::FAIL_DESCRIPTOR_MISSING:
229 userMessage = QObject::tr
230 ("Not a valid plugin library (no descriptor found)");
231 break;
232
233 case PluginCheckCode::FAIL_NO_PLUGINS:
234 userMessage = QObject::tr
235 ("Library contains no plugins");
236 break;
237
238 case PluginCheckCode::FAIL_OTHER:
239 if (userMessage == "") {
240 userMessage = QObject::tr
241 ("Unknown error");
242 }
243 break;
244
245 case PluginCheckCode::SUCCESS:
246 // success shouldn't happen here!
247 break;
248 }
249
250 os << "<br><i>" + userMessage.toStdString() + "</i>";
251 os << "</li>";
252
253 if (n > 10) {
254 if (++i == 5) {
255 os << "<li>";
256 os << QObject::tr("... and %n further failure(s)",
257 "", n - i)
258 .toStdString();
259 os << "</li>";
260 break;
261 }
262 }
263 }
264 os << "</ul>";
265
266 return QString::fromStdString(os.str());
267 }
268 #endif
269
185 QString 270 QString
186 PluginScan::getStartupFailureReport() const 271 PluginScan::getStartupFailureReport() const
187 { 272 {
188 #ifdef HAVE_PLUGIN_CHECKER_HELPER 273 #ifdef HAVE_PLUGIN_CHECKER_HELPER
189 274
202 "(internal error?)</p>"); 287 "(internal error?)</p>");
203 } 288 }
204 289
205 QString report; 290 QString report;
206 for (auto kp: m_kp) { 291 for (auto kp: m_kp) {
207 report += QString::fromStdString(kp.second->getFailureReport()); 292 auto failures = kp.second->getFailures();
293 if (!failures.empty()) {
294 report += formatFailureReport(kp.first, failures);
295 }
208 } 296 }
209 if (report == "") { 297 if (report == "") {
210 return report; 298 return report;
211 } 299 }
212 300