//#define DJ_DBG
#include <djWindow.h>
#include <djTabWidget.h>
#include <djApp.h>

using namespace dj;

class myApp : public App {
public:

  myApp(int & argc, char ** argv);
  ~myApp();

private:

  DJ_CALLBACK(myApp, exitCallback, bool)

  Window * _window;
};

myApp::myApp(int & argc, char ** argv) :
  App("imageWidgetPlugins", argc, argv),
  _window(0)
{
  _window = new Window(name());
  TabWidget * tabWidget = new TabWidget;
  
  // Image operation widgets.
  //
  TabWidget * tabOpWidget = new TabWidget;
  tabWidget->tabAdd("Operations", tabOpWidget);
  const List<ImageOpWidget *> opWidget = imageOpWidget().pluginList();
  for (ConstListIt<ImageOpWidget *> it = opWidget; it.isValid(); ++it) {
    ImageOpWidget * widget = static_cast<ImageOpWidget *>(it()->copy());
    tabOpWidget->tabAdd(widget->name(), widget);
  }
  
  // Image load widgets.
  //
  TabWidget * tabLoadWidget = new TabWidget;
  tabWidget->tabAdd("Load", tabLoadWidget);
  const List<ImageLoadWidget *> loadWidget = imageLoadWidget().pluginList();
  for (ConstListIt<ImageLoadWidget *> it = loadWidget; it.isValid(); ++it) {
    ImageLoadWidget * widget = static_cast<ImageLoadWidget *>(it()->copy());
    tabLoadWidget->tabAdd(widget->name(), widget);
  }
  
  // Image save widgets.
  //
  TabWidget * tabSaveWidget = new TabWidget;
  tabWidget->tabAdd("Save", tabSaveWidget);
  const List<ImageSaveWidget *> saveWidget = imageSaveWidget().pluginList();
  for (ConstListIt<ImageSaveWidget *> it = saveWidget; it.isValid(); ++it) {
    ImageSaveWidget * widget = static_cast<ImageSaveWidget *>(it()->copy());
    tabSaveWidget->tabAdd(widget->name(), widget);
  }
  
  VLayout * layout = new VLayout(_window);
  layout->margin(0);
  layout->add(tabWidget);
  
  _window->closeSig().set(this, exitCallback);
  
  _window->show();
  
  valid(true);
}

myApp::~myApp()
{
  if (_window) delete _window;
}

void myApp::exitCallback(bool) { exit(); }

int main(int argc, char ** argv)
{
  DJ_DBG_LOG();
  return myApp(argc, argv).exec();
}
