// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QList<QString> PluginManager::getPluginNames()
{
  QList<QString> pluginNames;
  for (QVector<ISIMPLibPlugin*>::iterator iter = plugins.begin(); iter != plugins.end(); ++iter)
  {
    ISIMPLibPlugin* plugin = *iter;
    if(NULL != plugin)
    {
      pluginNames.push_back(plugin->getPluginName());
    }
  }
  return pluginNames;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
ISIMPLibPlugin* PluginManager::findPlugin(QString pluginName)
{
  for (QVector<ISIMPLibPlugin*>::iterator iter = plugins.begin(); iter != plugins.end(); iter++)
  {
    ISIMPLibPlugin* plugin = *iter;
    if (plugin->getPluginName() == pluginName)
    {
      return plugin;
    }
  }

  // If the plugin isn't found in the vector...
  return NULL;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void WriteWebServerJSON(const QString& filePath)
{


  // Register all the filters including trying to load those from Plugins
  FilterManager* fm = FilterManager::Instance();
  SIMPLibPluginLoader::LoadPluginFilters(fm);
  PluginManager* pm = PluginManager::Instance();
  QVector<ISIMPLibPlugin*> plugins = pm->getPluginsVector();

  // Send progress messages from PipelineBuilder to this object for display
  QMetaObjectUtilities::RegisterMetaTypes();


  // Write our File Version and DREAM3D Version strings
  QJsonObject meta;

  meta["Release Date"] = QDate::currentDate().toString();
  meta["Release Type"] = DREAM3DProj_RELEASE_TYPE;
  meta["Major"] = SIMPLib::Version::Major();
  meta["Minor"] = SIMPLib::Version::Minor();
  meta["Patch"] = SIMPLib::Version::Patch();
  meta["Revision"] = SIMPLib::Version::Revision();
  meta["Download WebSite"] = "http://dream3d.bluequartz.net/?page_id=32";
  QJsonObject m_Root;
  m_Root["DREAM3D"] = meta;


  QJsonArray plugArray;

  for(int i = 0; i < plugins.size(); i++)
  {
    ISIMPLibPlugin* plug = plugins[i];
    QJsonObject jobj;
    jobj["Plugin Name"] = plug->getPluginName();
    jobj["Plugin Version"] = plug->getVersion();
    jobj["Plugin Vendor"] = plug->getVendor();
    plugArray.append(jobj);
  }
  m_Root["Plugins"] = plugArray;

  QJsonDocument doc(m_Root);
  QFile outputFile(filePath);
  if (outputFile.open(QIODevice::WriteOnly))
  {
    outputFile.write(doc.toJson());
    outputFile.close();
  }

}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QString PluginManager::getPluginName(QString filtName)
{
  QVector<ISIMPLibPlugin*> plugins = getPluginsVector();
  for (int i = 0; i < plugins.size(); i++)
  {
    ISIMPLibPlugin* plugin = plugins[i];

    if (plugin->getFilters().contains(filtName))
    {
      return plugin->getPluginName();
    }
  }

  return "";
}