/**
 * osd_userinterface_search_favourites.c: Search submenu for selecting favourites
 * 
 * Copyright: See COPYING file that comes with this distribution
 *
 * Author: Matthias Feistel <hitman_47@users.sourceforge.net>, (C) 2006, 2007
 */

#include <vector>
#include <vdr/interface.h>
#include <vdr/menu.h>
#include <vdr/plugin.h>
#include <sstream>
#include "osd_userinterface_search_favourites.h"
#include "settings.h"

cUserInterface_Search_Favourites::cUserInterface_Search_Favourites( char *searchword_ptr )
:cOsdMenu( tr( "SearchFavourites" ), 20 )
{
	m_searchword_ptr = searchword_ptr;
	cSettings::GetInstance().SetOsd_Path( "search_favourites" );

	// OSD-Elemente aufbauen
	BuildItems( );
}

cUserInterface_Search_Favourites::~cUserInterface_Search_Favourites( void )
{
	cSettings::GetInstance().SetOsd_Path( "search" );
}

void cUserInterface_Search_Favourites::BuildItems( void )
{
	SetHelp( tr( "Select" ) );

	for( std::list<std::string>::iterator it = cSettings::GetInstance().FavouriteList.begin( );
		it != cSettings::GetInstance().FavouriteList.end( );
		it++ )
	{
		std::string it_string = *it;

		Add( new cOsdItem(it_string.c_str() ) );

	}
	
	Display( );
}

eOSState cUserInterface_Search_Favourites::ProcessKey( eKeys Key )
{
	eOSState state = cOsdMenu::ProcessKey( Key );

	if( !strcmp( cSettings::GetInstance().GetOsd_Path( ), "search_favourites" ) )
	{
		switch( Key )
		{
		// cases fuer bereits belegte Tasten werden erwaehnt, damit die vom darueberliegenden Menue gleichermassen belegten Tasten ignoriert werden.
		case kRed: // select favourite

			// execute only, if an item is available
			if( !Get( Current( ) ) )
			{
				Skins.Message( mtError, tr( "no favourites entered in setup" ) );
			}
			else
			{
				snprintf( m_searchword_ptr, 511, Get( Current() )->Text( ) ); ///TODO: size aus Get(Current())->Text() ermitteln
				return osBack;
			}
			break;

		case kBack:
			return osBack;

		default:
			state = osContinue;
			break;
		}

	}

	return state;
}
