
#include <qcstring.h>
#include <qsocket.h>
#include <qdatetime.h>
#include <qbitarray.h>

#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <kapplication.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kinstance.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <dcopclient.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#include <kurl.h>
#include <ksock.h>
#include <qdir.h>

#include "burn.h"

using namespace KIO;


kio_burnProtocol::kio_burnProtocol(const QCString &protocol, const QCString &pool_socket, const QCString &app_socket)
    : ForwardingSlaveBase(protocol, pool_socket, app_socket)
{
  KGlobal::locale()->insertCatalogue("konqsidebar_burn");
	
  m_dataDir = new QDir( locateLocal( "data", "kio_burn/data" ) );
  if( !m_dataDir->exists() )
    m_dataDir->mkdir( m_dataDir->absPath() );
}


kio_burnProtocol::~kio_burnProtocol()
{
  delete m_dataDir;
}


bool kio_burnProtocol::rewriteURL( const KURL& url, KURL &newURL )
{
  newURL.setPath( m_dataDir->path() + url.path() );
  return true;
}

static const KCmdLineOptions options[] =
{
	{ "+protocol", I18N_NOOP( "Protocol name" ), 0 },
	{ "+pool", I18N_NOOP( "Socket name" ), 0 },
	{ "+app", I18N_NOOP( "Socket name" ), 0 },
	KCmdLineLastOption
};
extern "C"
{
    int KDE_EXPORT kdemain(int argc, char **argv)
    {
        KCmdLineArgs::init(argc, argv, "kio_burn", 0, 0, 0, 0);
        KCmdLineArgs::addCmdLineOptions( options );

        KApplication instance( false, false );
        // We want to be anonymous even if we use DCOP
        instance.dcopClient()->attach();

        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
        kio_burnProtocol slave(args->arg(0),args->arg(1),args->arg(2));
        slave.dispatchLoop();
        
        return 0;
    }
} 
