void InputMap::loadPlugins() { QString path; #ifdef __APPLE__ path = QString("%1/../%2").arg(QApplication::applicationDirPath()) .arg(INPUTPLUGINDIR); #else path = QString(INPUTPLUGINDIR); #endif /* Find plugins from input plugin dir, sort by name, get regular files */ QDir dir(path, QString("*%1").arg(PLUGINEXT), QDir::Name, QDir::Files); /* Check that we can access the directory */ if (dir.exists() == false || dir.isReadable() == false) { qWarning() << "Unable to load input plugins from" << dir.absolutePath(); return; } /* Loop thru all files in the directory */ QStringListIterator it(dir.entryList()); while (it.hasNext() == true) { QLCInPlugin* p; QString path; /* Attempt to load a plugin from the path */ path = dir.absoluteFilePath(it.next()); QPluginLoader loader(path, this); p = qobject_cast<QLCInPlugin*> (loader.instance()); if (p != NULL) { /* Check for duplicates */ if (plugin(p->name()) == NULL) { /* New plugin. Append and init. */ p->init(); appendPlugin(p); p->connectInputData(this); } else { /* Duplicate plugin. Unload it. */ qWarning() << "Discarded duplicate plugin" << path; loader.unload(); } } else { qWarning() << "Unable to load an input plugin from" << path << "because:" << loader.errorString(); } } }
void InputMap::loadPlugins(const QDir& dir) { /* Check that we can access the directory */ if (dir.exists() == false || dir.isReadable() == false) return; /* Loop thru all files in the directory */ QStringListIterator it(dir.entryList()); while (it.hasNext() == true) { /* Attempt to load a plugin from the path */ QString fileName(it.next()); QString path = dir.absoluteFilePath(fileName); QPluginLoader loader(path, this); QLCInPlugin* p = qobject_cast<QLCInPlugin*> (loader.instance()); if (p != NULL) { /* Check for duplicates */ if (plugin(p->name()) == NULL) { /* New plugin. Append and init. */ qDebug() << "Input plugin" << p->name() << "from" << fileName; p->init(); appendPlugin(p); QLCi18n::loadTranslation(p->name().replace(" ", "_")); } else { /* Duplicate plugin. Unload it. */ qWarning() << Q_FUNC_INFO << "Discarded duplicate input plugin" << fileName; loader.unload(); } } else { qWarning() << Q_FUNC_INFO << fileName << "doesn't contain a QLC input plugin:" << loader.errorString(); loader.unload(); } } }