/***************************************************************************
                          CdboAudioActionFactory.h  -  description
                             -------------------
    begin                : Sun Feb 3 2002
    copyright            : (C) 2002 by Alex Podolsky
    email                : alexpod@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef CDBOAUDIOACTIONFACTORY_H
#define CDBOAUDIOACTIONFACTORY_H

#include <qobject.h>

#include <kio/job.h>
//#include <kio/netaccess.h>

class QListView;

class KProcess;
class KShellProcess;
class KConfig;

class CdboDialogBase;

class CdboAudioActionFactory : public QObject{
	Q_OBJECT
public:
	CdboAudioActionFactory(QObject *, const char *);
	~CdboAudioActionFactory();

	void scanAudioDisk(QString device, QListView *list, CdboDialogBase *user = 0, bool uncheck = false);
	bool ripp(QString device, QStringList* tracks, QString outputDir, QString ext, CdboDialogBase *user = 0);
	/** tracks could be alone as 10 or from+to as in 10+11 */
	void play(QString device, QString tracks, int sector, CdboDialogBase *user = 0);

	void killCurrentTask();

signals:
	void processDone(bool);
	void failedToLunchProcess();
	//void processCancelled();
	
	void countedTracks(int totTracks);
	void songDone();
	void playDone();
	
protected slots:
	virtual void timerEvent(QTimerEvent *event);

protected:
	
	
private slots:
    	/*void receivedMessageSlot(KProcess *proc, char *buffer, int buflen);
    	void receivedErrMessageSlot(KProcess *proc, char *buffer, int buflen);
	void processDoneSlot(KProcess *);
*/
    	void receivedScanAudioDiskMessageSlot(KProcess *, char *, int);
    	void scanAudioDiskProcessDoneSlot(KProcess *);
    	
    	void rippResult( KIO::Job *);
    	void rippPercent( KIO::Job *,unsigned long);
    	void rippProcessedFiles( KIO::Job *,unsigned long);
    	void rippCanceled( KIO::Job *);
    	void rippMessage( KIO::Job *,const QString &);
	void rippedFile ( KIO::Job *, const KURL &from, const KURL &to, bool, bool renamed );
	
	void receivedPlayMessageSlot(KProcess *, char *, int);
	void playProcessDoneSlot(KProcess *);
	
private:
	bool loadTracks();
	
	//members
	KProcess *cdboProc;
	KProcess *currentProc;
	KShellProcess *cdboShellProc;

	CdboDialogBase *user;
	QListView *list;
	QString outStr;
	QString device;
	KConfig *config;
	KIO::Job *curJob;

	bool uncheck;
	bool DEBUG_COMMANDS;
	bool watchTime;
	int timeOutId;
};
#endif
