/*
 * See the files COPYING and README for copyright information and how to reach
 * the author.
 *
 *  $Id: common.h,v 1.10 2006/04/24 19:43:37 lordjaxom Exp $
 */

#ifndef VDR_BURN_COMMON_H
#define VDR_BURN_COMMON_H

#include <vector>
#include <string>
#include <utility>
#include "proctools/functions.h"
#include <vdr/tools.h>
#include "vdr_compat.h"

#define JOBNAMELEN 255
#define MAXATRACKS (MAXAPIDS + MAXDPIDS)
#define MAXTRACKS 9 // the maximum tcmplex-panteltje can handle
#define MAXPAGETITLES 8

namespace vdr_burn 
{

	// --- path_pair ----------------------------------------------------------
	
	struct path_pair
	{
		std::string temp;
		std::string data;
		path_pair(void) {}
		path_pair(const std::string& temp_, const std::string& data_):
			temp(temp_), data(data_) {}
	};

	// --- disk_type ----------------------------------------------------------

	namespace disk_type
	{

		enum type
		{
			dvd_menu,
			dvd_no_menu,
			archive
		};

		const int count_requant = dvd_no_menu + 1;
		const int count         = archive + 1;

		extern const char* strings[count];
	}

// --- eStoreMode -------------------------------------------------------------

enum eStoreMode
{
	smCreateISO,
	smBurnISO,
	smCreateBurn,
#define sm_Count (smCreateBurn + 1)
};

// --- eChaptersMode ----------------------------------------------------------

enum eChaptersMode
{
	cmNoChapters,
	cmEditingMarks,
	cm5Mins,
	cm10Mins,
	cm15Mins,
	cm30Mins,
	cm60Mins,
#define cm_Count (cm60Mins + 1)
};

	// --- disk_size ----------------------------------------------------------

	namespace disk_size
	{
		enum type
		{
			single_layer,
			double_layer,
			mini_dvd,
			custom_dvd
		};
		
		const int count = custom_dvd + 1;
		const int sizes[count - 1] = { 4472, 7944, 690 };
		
		extern const char* strings[count];
	}

// --- eReturnStatus ----------------------------------------------------------

enum eReturnStatus
{
	rsNone,
	rsOk,
	rsError
};

// --- eNextStep --------------------------------------------------------------

enum eNextStep
{
	nsContinue,
	nsNext,
	nsRetry
};
	
	// --- track_type ---------------------------------------------------------

	enum track_type
	{
		unknown,
		video,
		mpeg_audio,
		ac3_audio,
	};

	// --- track_info ---------------------------------------------------------

	struct track_info
	{
		std::string filename;
		track_type type;
		int cid;
		int language;
		int64_t size;
		bool used;

		track_info(track_type type_, int cid_, const std::string& filename_): 
				filename(filename_), type(type_), cid(cid_), language(-1),
				size(0), used(true) {}

		std::string get_type_description(void) const;
	};

	typedef std::vector<track_info> track_info_list;

	// --- demux_type ---------------------------------------------------------
	
	namespace demux_type
	{
		enum type
		{
			vdrsync,
			projectx
		};

		const int count = projectx + 1;

		extern const char* strings[count];
	}

// --- various declarations ---------------------------------------------------

extern const char *StoreModes[sm_Count];
extern const char *ChaptersModes[cm_Count];

extern const char *TitleChars;

int ScanPageCount(const std::string& Path);
std::string progress_bar(double current, double total, int length = 20);
std::string escape_iso_to_utf8(const std::string& Text);
void trim_left(char *Text, const char *Chars);
std::string get_recording_datetime(const cRecording* recording_, 
								   char delimiter = '\t');
std::string get_recording_title(const cRecording* recording_, int level);
//std::string strip_recording_title(const cRecording* recording_, char separator,
								  //bool newIndicator = false, int level = -1);
std::string escape_shellcmd(const std::string& command);
bool elapsed_since(time_t& timestamp, time_t difference);
std::string int_to_string(int value, int base, bool prefix = false);

template<typename InIt, typename Fn>
std::string join_strings(InIt first, InIt last, Fn func, std::string delimiter)
{
	return proctools::sum(first, last, std::string( "" ), func, delimiter);
}

}

#endif // VDR_BURN_COMMON_H
