/**
 * settings.c: Stores global parameters
 * 
 * Copyright: See COPYING file that comes with this distribution
 *
 * Author: Matthias Feistel <hitman_47@users.sourceforge.net>, (C) 2006, 2007
 */

#include <stdlib.h>
#include <string>
#include <vdr/interface.h>  //SETUP
#include "settings.h"
#include "config.h"

// --- NewStrDup ---------------------------------------------------------------

char *NewStrDup( const char *string )
{
	if( NULL == string )
		return NULL;

	int n = strlen( string );
	char *p = new char[n + 1];
	strncpy( p, string, n );
	p[n] = 0x00;

	return p;
}

// --- NewStrNDup --------------------------------------------------------------

char *NewStrNDup( const char *string, int i )
{
	if( NULL == string )
		return NULL;

	int n = strnlen( string, i );
	char *p = new char[n + 1];
	strncpy( p, string, n );
	p[n] = 0x00;

	return p;
}

// --- cConfiguration ---------------------------------------------------------
cSettings::cSettings( )
{
	strncpy( m_Osd_Path, "home", 511 );
	//Xmlconfig:
	strncpy( m_Xmlconfig_Fileurl, "", 511 ); // m_Xmlconfig_Fileurl: initialized in cPluginLastfm::Initialize() already

	ResetParameterMap();
	
	// Standardparameter init. für HandshakedataMap:
	HandshakedataMap[ "Session ID" ] = "";
	HandshakedataMap[ "Now-Playing URL" ] = "";
	HandshakedataMap[ "Submission URL" ] = "";

	HandshakedataMap[ "session" ] = "";
	HandshakedataMap[ "stream_url" ] = "";
	HandshakedataMap[ "subscriber" ] = "";
	HandshakedataMap[ "framehack" ] = "";
	HandshakedataMap[ "base_url" ] = "";
	HandshakedataMap[ "base_path" ] = "";
	HandshakedataMap[ "info_message" ] = "";
	HandshakedataMap[ "fingerprint_upload_url" ] = "";
	
	// Osd_Tools:
	Osd_ParameterMap[ "Osd_Width" ] = 480; ///480 defined in <vdr/config.> as #define MINOSDWIDTH  480           ///452 funktioniert"
	Osd_ParameterMap[ "Osd_Height" ] = 360;/// defined in <vdr/config.> as #define #define MINOSDHEIGHT 324
	Osd_ParameterMap[ "Osd_AreaDepth" ] = 4; ///bpp ACHTUNG: Es werden verschiedene Werte in osd_userinterface.c SetAreas benutzt
	Osd_ParameterMap[ "Osd_ColourDepth" ] = 16; ///Farbanzahl f�r �bergabe an bitmap.c
	Osd_ParameterMap[ "Osd_Centre_x" ] = Osd_ParameterMap[ "Osd_Width" ] / 2;
	Osd_ParameterMap[ "Osd_Centre_y" ] = Osd_ParameterMap[ "Osd_Height" ] / 2;
	Osd_ParameterMap[ "Osd_BitmapSize_x" ] = 180;///Darf nicht groe�er als  m_Osd_Centre_x  sein
	Osd_ParameterMap[ "Osd_BitmapSize_y" ] = 180;///Darf nicht groe�er als  m_Osd_Centre_y  sein
	Osd_ParameterMap[ "Osd_ImgAlpha" ] = 255;
	Osd_ParameterMap[ "Osd_BtnWidth" ] = Osd_ParameterMap[ "Osd_Width" ] / 4;
	Osd_ParameterMap[ "Osd_FontHeight" ] = 20;
	
	Mp3decoderstate = 0;
}

cSettings::~cSettings( )
{
}

cSettings *cSettings::gpo_config = NULL;

cSettings& cSettings::GetInstance( void )
{
	if( NULL == gpo_config )
		gpo_config = new cSettings();

	return *gpo_config;
}

const char *cSettings::SetOsd_Path( const char *osdpath )
{
	return strncpy( m_Osd_Path, osdpath, 512 );
}

//------------------------------------------------------------------------------

bool cSettings::SetShow_SearchActions_Menu( bool on )
{
	return m_Show_SearchActions_Menu = on;
}

// Xmlconfig m_Xmlconfig_Fileurl:
const char *cSettings::SetXmlconfig_Fileurl( const char *fileurl )
{
	return strncpy( m_Xmlconfig_Fileurl, fileurl, 512 );
}

void cSettings::ResetParameterMap( void )
{
	// Standardparameter init.:
	// Userdetails:
	ParameterMap[ "Username" ] = "";
	ParameterMap[ "Password_md5" ]= "";
	// Other settings:
	ParameterMap[ "Receivermode" ] = itoa( 0 );
	ParameterMap[ "Scrobblemode" ] = itoa( 0 );

	// OSD settings:
	ParameterMap[ "Albumcovermode" ] = itoa( 0 );
	ParameterMap[ "Osd_Mode" ] = itoa( 0 );
	ParameterMap[ "Osd_Autostartmode" ] = itoa( 1 );
	ParameterMap[ "Osd_Refreshinterval" ] = itoa( 13 );

}
