
/*
 * 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 *mRecordingTitle;
    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 *RecordingTitle(void) const { return mRecordingTitle; }
    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 void RefreshTracks(void);
    const tTrackInfoArray &GetTracks(void);
    double SizeMB(eDiskType dt);
    const char *GetChapters(eChaptersMode);
};

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

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

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

    eDiskType mDiskType;
    eStoreMode mStoreMode;
    eBurnMode mBurnMode;
    eChaptersMode mChaptersMode;

    cBurnProcess *mProcess;

    bool mIsProcessed;
    bool mMarksSet;
    int mArchiveMark;

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

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

    int Progress(void) { return mProcess ? mProcess->Progress() : 0; }
    int Status(void) { 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) { return cList <cBurnRecording>::First(); }
    cBurnRecording *Next(cBurnRecording * Recording) const;

    const char *TempDir() { return mTempDir; }
    const char *Title() { return mTitle; }
    eDiskType DiskType() { return mDiskType; }
    eStoreMode StoreMode() { return mStoreMode; }
    eBurnMode BurnMode() { return mBurnMode; }
    eChaptersMode ChaptersMode() { return mChaptersMode; }
    bool IsProcessed() { return mIsProcessed; }

    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; }
};

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

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

#endif // VDR_BURN_JOBS_H
