#include "testmanager.h"
#include "testmanager.moc"

#include "pluginmanager.h"
#include "plugin.h"

#include <kplugininfo.h>
#include <tdecmdlineargs.h>
#include <tdeapplication.h>
#include <kdebug.h>

using namespace Komposer;

TestManager::TestManager( TQObject *parent )
  : TQObject( parent )
{
  m_manager = new PluginManager( this );
  connect( m_manager, TQT_SIGNAL(pluginLoaded(Plugin*)),
           TQT_SLOT(slotPluginLoaded(Plugin*)) );
  connect( m_manager, TQT_SIGNAL(allPluginsLoaded()),
           TQT_SLOT(slotAllPluginsLoaded()) );
  m_manager->loadAllPlugins();

  TQValueList<KPluginInfo*> plugins = m_manager->availablePlugins();
  kdDebug()<<"Number of available plugins is "<< plugins.count() <<endl;
  for ( TQValueList<KPluginInfo*>::iterator it = plugins.begin(); it != plugins.end(); ++it ) {
    KPluginInfo *i = ( *it );
    kdDebug()<<"\tAvailable plugin "<< i->name()
             <<", comment = "<< i->comment() <<endl;
  }
}

void TestManager::slotAllPluginsLoaded()
{
  kdDebug()<<"Done"<<endl;
  m_manager->shutdown();
  tqApp->exit();
}

void TestManager::slotPluginLoaded( Plugin *plugin )
{
  kdDebug()<<"A plugin "<< m_manager->pluginName( plugin ) << " has been loaded"<<endl;
}

int main( int argc, char **argv )
{
  TDECmdLineArgs::init( argc, argv, "test", "test", "test", "0.1" );
  TDEApplication app;

  TestManager manager( &app );

  return app.exec();
}
