230{
231
233
234 QString
bn = QFileInfo(filename).fileName();
235
236 if (
m_d->pluginfile_2_basenamesAndFactory.find(filename)!=
m_d->pluginfile_2_basenamesAndFactory.end()) {
237 return "Error: Plugin already loaded.";
238 } else {
239
240
241 QFileInfo fi(filename);
242 if (!fi.exists())
243 return "File does not exist";
244 if (!fi.isReadable())
245 return "File is not readable";
246
250
251 QString pluginAbsPath = fi.absoluteFilePath();
252
253 QPluginLoader * loader = new QPluginLoader(pluginAbsPath);
255
256 bool loadOk = loader->load();
257
258 if (!loadOk) {
259 VP1Msg::message(
"ERROR! Failed to load plugin. Error message: "+loader->errorString());
260
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280 pluginAbsPath.replace("opt", "dbg");
281
282 loader = new QPluginLoader(pluginAbsPath);
283 loadOk = loader->load();
284
285 if (loadOk)
VP1Msg::message(
"Ok! 'dbg' build of the plugin successfully loaded!");
287
288 }
289
290
291 QObject *
plugin = loader->instance();
292
293
294 if (!plugin) {
295
296 bool error = loader->errorString().isNull();
297
298
299 QString errStr = "ERROR!!";
300 if (error)
301 errStr = QString("Did not find any compatible plugins in file");
302 else
303 errStr = loader->errorString();
304
305
306 return errStr;
307 }
308
309
310 IVP1ChannelWidgetFactory * fact = qobject_cast<IVP1ChannelWidgetFactory *>(plugin);
312
313
314 if (!fact)
315 return "Did not find any channel factory in plugin file";
316
317
319
320
321 if (providedbasenames.count()==0)
322 return "Found channel factory in plugin file, but no advertised channels!";
323
324
325 m_d->pluginfile_2_basenamesAndFactory[
filename] = std::pair<QStringList,IVP1ChannelWidgetFactory *>(providedbasenames,fact);
326
327
328 for (const QString& bn : providedbasenames) {
329 if (
m_d->basename_2_pluginfile.find(bn)!=
m_d->basename_2_pluginfile.end())
330 return "Channels navp1 '"+
bn+
"' are already provided by plugin file "
331 +
m_d->basename_2_pluginfile[
bn]+
" (ignoring other plugins in file '"+
filename+
"')";
332 }
333
334
335 for (const QString& bn : providedbasenames) {
337 m_d->basename_2_channels[
bn] = std::set<IVP1ChannelWidget*>();
338 }
339
340
341 m_d->emit_basename_availableChannelListChanged();
342 m_d->emit_basename_availableUnusedChannelListChanged();
343
344
345
346 }
347
348
349 m_d->mainwindow->addToMessageBox(
"Successfully loaded "+bn,
"color:#008b00" );
351 m_d->mainwindow->addToMessageBox( out,
"color:#008b00" );
352
353
354 return "";
355}
QStringList channelsInPluginFile(const QString &filename) const
static void messageVerbose(const QString &)
static void message(const QString &, IVP1System *sys=0)