void ctkPluginFrameworkContext::init()
{
  log() << "initializing";

  if (firstInit && ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT
      == props[ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN])
  {
    deleteFWDir();
    firstInit = false;
  }

  ctkPluginFrameworkPrivate* const systemPluginPrivate = systemPlugin->d_func();
  systemPluginPrivate->initSystemPlugin();

  storage = new ctkPluginStorage(this);
  dataStorage = ctkPluginFrameworkUtil::getFileStorage(this, "data");
  services = new ctkServices(this);
  plugins = new ctkPlugins(this);

  plugins->load();

  log() << "inited";
  initialized = true;

  log() << "Installed plugins:";
  // Use the ordering in the plugin storage to get a sorted list of plugins.
  QList<ctkPluginArchive*> allPAs = storage->getAllPluginArchives();
  for (int i = 0; i < allPAs.size(); ++i)
  {
    ctkPluginArchive* pa = allPAs[i];
    QSharedPointer<ctkPlugin> plugin = plugins->getPlugin(pa->getPluginLocation().toString());
    log() << " #" << plugin->getPluginId() << " " << plugin->getSymbolicName() << ":"
        << plugin->getVersion() << " location:" << plugin->getLocation();
  }
}
//----------------------------------------------------------------------------
void ctkPluginFrameworkContext::init()
{
  log() << "initializing";

  if (firstInit && ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT
      == props[ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN])
  {
    deleteFWDir();
    firstInit = false;
  }

  // Pre-load libraries
  // This may speed up installing new plug-ins if they have dependencies on
  // one of these libraries. It prevents repeated loading and unloading of the
  // pre-loaded libraries during caching of the plug-in meta-data.
  if (props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].isValid())
  {
    QStringList preloadLibs = props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].toStringList();
    QLibrary::LoadHints loadHints;
    QVariant loadHintsVariant = props[ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS];
    if (loadHintsVariant.isValid())
    {
      loadHints = loadHintsVariant.value<QLibrary::LoadHints>();
    }

    foreach(QString preloadLib, preloadLibs)
    {
      QLibrary lib;
      QStringList nameAndVersion = preloadLib.split(":");

      QString libraryName;
      if (nameAndVersion.count() == 1)
      {
        libraryName = nameAndVersion.front();
        lib.setFileName(nameAndVersion.front());
      }
      else if (nameAndVersion.count() == 2)
      {
        libraryName = nameAndVersion.front() + "." + nameAndVersion.back();
        lib.setFileNameAndVersion(nameAndVersion.front(), nameAndVersion.back());
      }
      else
      {
        qWarning() << "Wrong syntax in" << preloadLib << ". Use <lib-name>[:version]. Skipping.";
        continue;
      }

      lib.setLoadHints(loadHints);
      log() << "Pre-loading library" << lib.fileName() << "with hints [" << static_cast<int>(loadHints) << "]";
      if (!lib.load())
      {
        qWarning() << "Pre-loading library" << lib.fileName() << "failed:" << lib.errorString() << "\nCheck your library search paths.";
      }
    }