/***************************************************************************
 *   Copyright (C) 2005 by James Thorniley                                 *
 *   james@uncommonlygood.co.uk                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "burndevicescanner.h"
#include <k3bcore.h>
#include <k3bdevicemanager.h>
#include <qptrlist.h>
#include <k3bdevice.h>
#include "burnsidebarplugin.h"
#include <qapplication.h>
#include <qptrlist.h>
#include <kdebug.h>

BurnDeviceScanner::BurnDeviceScanner( BurnSidebarPlugin *parent )
 : QThread(),
   m_parent( parent )
{
}

void BurnDeviceScanner::run()
{
//  kdDebug() << "BurnDeviceScanner::run()" << endl;

  K3bDevice::DeviceManager *manager = K3bCore::k3bCore()->deviceManager(); 

  manager->scanBus();

  //will be deleted by BurnSidebarPlugin::customEvent - could cause trouble if
  //its deleted elsewhere 
  QPtrList<K3bDevice::Device> *devices = new QPtrList<K3bDevice::Device>(manager->burningDevices());
  QCustomEvent *e = new QCustomEvent( QEvent::User, devices );

  QApplication::postEvent( m_parent, e );
}


BurnDeviceScanner::~BurnDeviceScanner()
{
  //we'll quit when the device scan finishes
  if( running() )
    wait();
}


