/////////////////////////////////////////////////////////////////////////////
// Name:        ProgressDlg.h
// Purpose:     Progress of generation/burning dialog
// Author:      Alex Thuering
// Created:     14.08.2004
// RCS-ID:      $Id: ProgressDlg.h,v 1.25 2010/01/19 22:30:08 ntalex Exp $
// Copyright:   (c) Alex Thuering
// Licence:     GPL
/////////////////////////////////////////////////////////////////////////////

#ifndef PROGRESS_DLG_H
#define PROGRESS_DLG_H

#include "DVD.h"
#include "Cache.h"
#include "BurnDlg.h"

// begin wxGlade: dependencies
// end wxGlade

class ProgressDlg : public wxDialog {
public:
    // begin wxGlade: ProgressDlg::ids
    enum {
        HIDE_BT_ID = 1001,
        ICONIZE_BT_ID = 1002
    };
    // end wxGlade

public:
	/**
	 * Constructor
	 */
	ProgressDlg(wxWindow* parent, Cache* cache, bool autoStart);
	// starts the generating of DVD
	bool Start(BurnDlg* burnDlg, DVD* dvd);

	// add the given message to summary textbox
	void AddSummaryMsg(const wxString& message,
			const wxString& details = wxEmptyString,
			const wxColour& colour = wxNullColour);
	// add the given message to details textbox
	void AddDetailMsg(const wxString& message,
			const wxColour& colour = wxNullColour);
	// add the given text to details textbox
	void AddDetailText(const wxString& text);

	// sets the step count of generating process
	void SetSteps(int value) {
		m_gauge->SetRange(value*100);
		m_step = 0;
	}
	// increments the step
	void IncStep() {
		m_step ++;
		m_subStep = 0;
		UpdateGauge();
	}

	// sets the sub-step count of current step
	void SetSubSteps(int value) {
		m_subStepCount = value;
		m_subStep = 0;
	}
	// sets the sub-step
	void SetSubStep(int value) {
		m_subStep = value;
		UpdateGauge();
	}
	// increments the sub-step
	void IncSubStep(int value = 1) {
		SetSubStep(GetSubStep() + value);
	}
	// returns the sub-step
	int GetSubStep() {
		return m_subStep;
	}

	bool IsCanceled();

private:
    // begin wxGlade: ProgressDlg::methods
    void set_properties();
    void do_layout();
    // end wxGlade
    // begin wxGlade: ProgressDlg::attributes
    wxStaticText* m_summaryLabel;
    wxTextCtrl* m_summaryText;
    wxGauge* m_gauge;
    wxStaticText* m_detailsLabel;
    wxTextCtrl* m_detailsText;
    wxButton* m_detailsBt;
    wxButton* m_minimizeBt;
    wxButton* m_cancelBt;
    // end wxGlade
	wxSizer* m_panelSizer;
	wxWindowDisabler* m_winDisabler;
	wxString m_detailsBtLabel;
	
	bool m_autoStart;
	int m_step;
	int m_subStepCount;
	int m_subStep;
	bool m_cancel;
	
	Cache* m_cache;
	
	void UpdateGauge();

	void Failed(const wxString& message = wxEmptyString);
	void End();

	void OnCancel(wxCommandEvent& WXUNUSED(event));
	void OnHideDetails(wxCommandEvent& WXUNUSED(event));
	void OnMinimize(wxCommandEvent& WXUNUSED(event));

	void Run(BurnDlg* burnDlg, DVD* dvd);
	
	int GetMenuSubSteps(wxArrayPtrVoid& menuVobs, DVD* dvd, wxString dvdTmpDir);
	int GetTitleSubSteps(wxArrayPtrVoid& titleVobs, DVD* dvd, Cache* cache);
	int GetSlideshowSubSteps(wxArrayPtrVoid& slideshowVobs, DVD* dvd, wxString dvdTmpDir);
	int GetSubtitleSubSteps(wxArrayPtrVoid& subtitleVobs, DVD* dvd, wxString dvdTmpDir);
	bool CleanTemp(const wxString& tmpDir, const wxString& dvdTmpDir, const wxString& dvdOutDir);
	
	bool GenerateMenus(wxArrayPtrVoid& menuVobs, int menuSubSteps, DVD* dvd);
	bool Transcode(wxArrayPtrVoid& titleVobs, int titleSubSteps, DVD* dvd);
	bool Multiplex(const wxString& videoFile, const wxArrayString& audioFiles, const wxString& vobFile);
	bool GenerateSlideshow(wxArrayPtrVoid& slideshowVobs, int slideshowSubSteps, DVD* dvd);
	bool MultiplexSubtitles(wxArrayPtrVoid& subtitleVobs, int subtitleSubSteps, DVD* dvd);
	bool GenerateDvdFilesystem(DVD* dvd, const wxString& dvdTmpDir, const wxString& dvdOutDir, const wxString& tmpDir);
	bool Preview(BurnDlg* burnDlg, const wxString& dvdOutDir);
	bool CreateIsoImage(BurnDlg* burnDlg, DVD* dvd, const wxString& dvdDir, const wxString& tmpDir);
	bool AddEccData(BurnDlg* burnDlg, const wxString& tmpDir);
	bool FormatDvd(BurnDlg* burnDlg);
	bool BurnDvd(BurnDlg* burnDlg, DVD* dvd, const wxString& dvdOutDir, const wxString& tmpDir);
	
	bool GenerateMenu(Menu* menu, const wxString& menuFile, AudioFormat audioFormat, wxString audioFile,
			int videoBitrate);
    bool GenerateSlideshow(Slideshow* slideshow, const wxString& vobFile, AudioFormat audioFormat);
	bool Transcode(const StreamArray& streams, const wxString& mpegFile,
			const wxArrayString& audioFiles, const wxString& vobFile, int videoBitrate);
	bool MultiplexSubtitles(const wxString& vobFile, TextSub* textSub, unsigned int streamIdx,
			const wxString& resultFile);
	/** removes given file and print error message if it failed */
	bool DeleteFile(wxString fname);
	/** removes given directory and all files in it */
	bool DeleteDir(wxString dir, bool subdirs = false);
	/** removes given temporary directory and all temporary files in it */
	bool DeleteTempFiles(const wxString& tmpDir, const wxString& dvdTmpDir, const wxString& dvdOutDir);
	/** executes given command */
	bool Exec(wxString command, wxString inputFile = wxEmptyString, wxString outputFile = wxEmptyString);

private:
	DECLARE_EVENT_TABLE()
}; // wxGlade: end class

#endif // PROGRESS_DLG_H
