/*
 * See the files COPYING and README for copyright information and how to reach 
 * the author.
 *
 *  $Id: jobs.h,v 1.2 2004/12/02 15:02:52 lordjaxom Exp $
 */

#ifndef VDR_BURN_JOBS_H
#define VDR_BURN_JOBS_H

#include "common.h"
#include "process.h"
#include <vdr/tools.h>
#include <vdr/thread.h>
#include <stdlib.h>

class cRecording;

// --- cBurnRecording ---------------------------------------------------------

class cBurnRecording: public cListObject {
	friend class cBurnMenuEditRecordingItem;
#ifdef TEST_PROG
	friend int main(void);
#endif

private:
	char *mFileName;
	char mName[JOBNAMELEN + 1];
	char *mSummary;
	char *mTitle;
	char *mTempDir;
	time_t mTimestamp;
	int mNumber;
	double mSizeMB;
	eDiskType mDt;	
	tTrackInfoArray mTracks;

protected:
	cBurnRecording(void) {} // for test program

public:
	cBurnRecording(cRecording *Recording, time_t Timestamp);
	cBurnRecording(const cBurnRecording &Recording);
	virtual ~cBurnRecording();

	void SetTempDir(const char *TempDir);
	void SetNumber(int Number) { mNumber = Number; }
	void SetTitle(const char *Title);

	const char *FileName(void) const { return mFileName; }
	const char *Name(void) const { return mName; }
	const char *Summary(void) const { return mSummary; }
	const char *Title(void) const { return mTitle; }
	const char *TempDir(void) const { return mTempDir; }
	time_t Timestamp(void) const { return mTimestamp; }
	int Number(void) const { return mNumber; }
	const tTrackInfoArray& GetTracks(void);
	double SizeMB(eDiskType dt);
};

// --- cBurnJob ---------------------------------------------------------------

class cBurnJob: public cList<cBurnRecording>, public cListObject {
	friend class cBurnMenuBurn;

private:
	char mTitle[JOBNAMELEN + 1];
	char *mTempDir;

	eDiskType mDiskType;
	eStoreMode mStoreMode;
	eBurnMode mBurnMode;

	cBurnProcess *mProcess;

	bool marksSet;
	int mArchiveMark;

public:
	cBurnJob(void);
	virtual ~cBurnJob();

	void Start(void);
	void Stop(void);

	int Progress(void) const { return mProcess ? mProcess->Progress() : 0; }
	int Status(void) const { return mProcess ? mProcess->Status() : rsNone; }
	bool Burning(int &Progress) const;
	bool Verifying(int &Progress) const;
	
	void Add(cBurnRecording *Object);
	void SetTempDir(const char *TempDir);
	void SetTitle(const char *Title) { strncpy(mTitle, Title, JOBNAMELEN); }

	cBurnRecording *GetByFileName(const char *FileName);
	cBurnRecording *First(void) const { return cList<cBurnRecording>::First(); }
	cBurnRecording *Next(cBurnRecording *Recording) const;

	const char *TempDir(void) const { return mTempDir; }
	const char *Title(void) const { return mTitle; }
	eDiskType DiskType(void) const { return mDiskType; }
	eStoreMode StoreMode(void) const { return mStoreMode; }
	eBurnMode BurnMode(void) const { return mBurnMode; }

	double SizeMB();

	/* Don not call getArchiveMark before previous archive jobs are finished
	 * or you will get duplicate archive numbers
	 */
	virtual int GetArchiveMark();
	virtual int GetNextArchiveMark();
	virtual bool CreateNextArchiveMark();
	virtual bool CreateArchiveMarks();
	virtual bool ClearArchiveMarks();
	virtual bool hasArchiveMark() { return mArchiveMark!=0; }
};

inline bool cBurnJob::Burning(int &Progress) const {
	return mProcess ? mProcess->Burning(Progress) : false;
}
	
inline bool cBurnJob::Verifying(int &Progress) const {
	return mProcess ? mProcess->Verifying(Progress) : false;
}
	
inline cBurnRecording *cBurnJob::Next(cBurnRecording *Recording) const {
	return cList<cBurnRecording>::Next(Recording);
}

// --- cBurnJobQueue ----------------------------------------------------------

class cBurnJobQueue: public cList<cBurnJob> {
	// By definition, the first job is the active one
};

#endif // VDR_BURN_JOBS_H
