Vuo  2.0.0
VuoInputEditorManager.cc
Go to the documentation of this file.
1 
10 #include "VuoInputEditorManager.hh"
13 #include "VuoFileUtilities.hh"
14 #include "VuoType.hh"
15 
16 #include <dlfcn.h>
17 
21 VuoInputEditorManager::VuoInputEditorManager(QList<QDir> extraPluginDirectories)
22 {
23  QList<QDir> pluginDirectories;
24  pluginDirectories += QCoreApplication::applicationDirPath() + "/../Resources/InputEditors";
25  pluginDirectories += QString::fromUtf8(VuoFileUtilities::getSystemModulesPath().c_str());
26  pluginDirectories += QString::fromUtf8(VuoFileUtilities::getUserModulesPath().c_str());
27  pluginDirectories += extraPluginDirectories;
28 
29  foreach (QDir pluginDirectory, pluginDirectories)
30  {
31  foreach (QString pluginFileName, pluginDirectory.entryList(QDir::Files))
32  {
33  QPluginLoader loader(pluginDirectory.absoluteFilePath(pluginFileName));
34  QObject *plugin = loader.instance();
35  if (plugin)
36  {
37  VuoInputEditorFactory *inputEditorFactory = qobject_cast<VuoInputEditorFactory *>(plugin);
38  plugins[loader.metaData().value("MetaData").toObject().value("type").toString()] = inputEditorFactory;
39  }
40  }
41  }
42 }
43 
50 {
51  if (!type)
52  return NULL;
53 
54  json_object *menuItemsValue = NULL;
55  if (type->getModuleKey() == "VuoInteger" && details && json_object_object_get_ex(details, "menuItems", &menuItemsValue))
56  return new VuoInputEditorNamedEnum();
57 
58  VuoInputEditorFactory *inputEditorFactory = plugins[type->getModuleKey().c_str()];
59 
60  if (!inputEditorFactory)
61  {
62  // There's no explicitly-defined input editor for this type — but if it's an enum type, we can provide the standard enum input editor.
63  string allowedValuesFunctionName = type->getModuleKey() + "_getAllowedValues";
64  if (dlsym(RTLD_SELF, allowedValuesFunctionName.c_str()))
65  return new VuoInputEditorWithEnumMenu(type->getModuleKey().c_str());
66 
67  return NULL;
68  }
69 
70  return inputEditorFactory->newInputEditor();
71 }
72 
82 {
83  if (!type)
84  return false;
85 
86  VuoInputEditor *inputEditorLoadedForPortDataType = newInputEditor(type);
87  if (inputEditorLoadedForPortDataType)
88  {
89  inputEditorLoadedForPortDataType->deleteLater();
90  return true;
91  }
92 
93  return false;
94 }