comparison plugin/FeatureExtractionPluginFactory.cpp @ 165:5ae5885d6ce3

* Add support for plugin classification using category files. Add separate menus listing plugins by category, maker, and plugin name.
author Chris Cannam
date Thu, 21 Sep 2006 16:43:50 +0000
parents 4b2ea82fd0ed
children 06ad01f3e553
comparison
equal deleted inserted replaced
164:da3701a3953e 165:5ae5885d6ce3
22 #include "system/System.h" 22 #include "system/System.h"
23 23
24 #include <QDir> 24 #include <QDir>
25 #include <QFile> 25 #include <QFile>
26 #include <QFileInfo> 26 #include <QFileInfo>
27 #include <QTextStream>
27 28
28 #include <iostream> 29 #include <iostream>
29 30
30 static FeatureExtractionPluginFactory *_nativeInstance = 0; 31 static FeatureExtractionPluginFactory *_nativeInstance = 0;
31 32
169 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl; 170 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl;
170 } 171 }
171 } 172 }
172 } 173 }
173 174
175 generateTaxonomy();
176
174 return rv; 177 return rv;
175 } 178 }
176 179
177 QString 180 QString
178 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir) 181 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir)
292 // std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Instantiated plugin " << label.toStdString() << " from library " << soname.toStdString() << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << std::endl; 295 // std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Instantiated plugin " << label.toStdString() << " from library " << soname.toStdString() << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << std::endl;
293 296
294 return rv; 297 return rv;
295 } 298 }
296 299
300 QString
301 FeatureExtractionPluginFactory::getPluginCategory(QString identifier)
302 {
303 return m_taxonomy[identifier];
304 }
305
306 void
307 FeatureExtractionPluginFactory::generateTaxonomy()
308 {
309 std::vector<QString> pluginPath = getPluginPath();
310 std::vector<QString> path;
311
312 for (size_t i = 0; i < pluginPath.size(); ++i) {
313 if (pluginPath[i].contains("/lib/")) {
314 QString p(pluginPath[i]);
315 path.push_back(p);
316 p.replace("/lib/", "/share/");
317 path.push_back(p);
318 }
319 path.push_back(pluginPath[i]);
320 }
321
322 for (size_t i = 0; i < path.size(); ++i) {
323
324 QDir dir(path[i], "*.cat");
325
326 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i].toStdString() << " has " << dir.count() << " .cat files" << std::endl;
327 for (unsigned int j = 0; j < dir.count(); ++j) {
328
329 QFile file(path[i] + "/" + dir[j]);
330
331 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i].toStdString() + "/" + dir[j].toStdString()) << std::endl;
332
333 if (file.open(QIODevice::ReadOnly)) {
334 // std::cerr << "...opened" << std::endl;
335 QTextStream stream(&file);
336 QString line;
337
338 while (!stream.atEnd()) {
339 line = stream.readLine();
340 // std::cerr << "line is: \"" << line.toStdString() << "\"" << std::endl;
341 QString id = PluginIdentifier::canonicalise
342 (line.section("::", 0, 0));
343 QString cat = line.section("::", 1, 1);
344 m_taxonomy[id] = cat;
345 // std::cerr << "FeatureExtractionPluginFactory: set id \"" << id.toStdString() << "\" to cat \"" << cat.toStdString() << "\"" << std::endl;
346 }
347 }
348 }
349 }
350 }