/*------------------------------------------------------------------------------
 src/lib/djWidget/imageOpWidget.cxx
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djImageOpWidget.h"
#include <dlfcn.h>

namespace dj {

ImageOpWidget::ImageOpWidget() :
  _op(0)
{}

ImageOpWidget::~ImageOpWidget() {}

void ImageOpWidget::set(ImageOp * in)
{
  _op = in;
}

ImageOpWidgetFactory::~ImageOpWidgetFactory()
{
  del();
}

ImageOpWidget * ImageOpWidgetFactory::pluginCopy(const Str & in)
{
  for (ListIt<ImageOpWidget *> it = _pluginList; it.isValid(); ++it)
    if (lowercase(in) == lowercase(it()->name()))
      return static_cast<ImageOpWidget *>(it()->copy());
  return 0;
}

void ImageOpWidgetFactory::pluginAdd(const List<ImageOpWidget *> & in)
{
  _pluginList += in;
}

bool ImageOpWidgetFactory::init(void * in)
{
  ImageOpWidgetFnc * fnc = (ImageOpWidgetFnc *)dlsym(in, "djImageOpWidget");
  if (! fnc) return false;
  _pluginList += fnc();
  return true;
}

void ImageOpWidgetFactory::del()
{
  for (ListIt<ImageOpWidget *> it = _pluginList; it.isValid(); ++it)
    delete it();
  _pluginList.del();
  PluginFactory::del();
}

}
