require 'net/telnet.rb'

class MythFrontend
  JUMP_POINTS = {"channelpriorities"  =>  "Channel Recording Priorities",
			"channelrecpriority" => "Channel Recording Priorities",
			"deletebox"          => "TV Recording Deletion",
			"deleterecordings"   => "TV Recording Deletion",
			"flixbrowse"         => "Netflix Browser",
			"flixhistory"        => "Netflix History",
			"flixqueue"          => "Netflix Queue",
			"guidegrid"          => "Program Guide",
			"livetv"             => "Live TV",
			"livetvinguide"      => "Live TV In Guide",
			"mainmenu"           => "Main Menu",
			"managerecordings"   => "Manage Recordings / Fix Conflicts",
			"manualbox"          => "Manual Record Scheduling",
			"manualrecording"    => "Manual Record Scheduling",
			"musicplaylists"     => "Select music playlists",
			"mythgallery"        => "MythGallery",
			"mythgame"           => "MythGame",
			"mythmovietime"      => "MythMovieTime",
			"mythnews"           => "MythNews",
			"mythvideo"          => "MythVideo",
			"mythweather"        => "MythWeather",
			"playbackbox"        => "TV Recording Playback",
			"playbackrecordings" => "TV Recording Playback",
			"playdvd"            => "Play DVD",
			"playmusic"          => "Play music",
			"previousbox"        => "Previously Recorded",
			"progfinder"         => "Program Finder",
			"programfinder"      => "Program Finder",
			"programguide"       => "Program Guide",
			"programrecpriority" => "Program Recording Priorities",
			"recordingpriorities"=> "Program Recording Priorities",
			"ripcd"              => "Rip CD",
			"ripdvd"             => "Rip DVD",
			"statusbox"          => "Status Screen",
			"videobrowser"       => "Video Browser",
			"videogallery"       => "Video Gallery",
			"videolistings"      =>  "Video Listings",
			"videomanager"       =>  "Video Manager",
			"viewscheduled"      =>  "Manage Recordings / Fix Conflicts"}

  def initialize( host ) 
    @connection= Net::Telnet::new("Host" => host,
							"Port"=> 6546,
                            "Timeout" => 10)
  end
  
  def cmd(command, &blk) 
	@connection.cmd( command ) do |c|
	    if blk 
			blk.call( c )
		end
	end
  end
  
  def exit() 
	cmd( "exit" )
  end

  def jump( jump_command ) 
	cmd( "jump #{jump_command}" )
  end
  
  def key( key_command ) 
	cmd( "key #{key_command}" )
  end

  def play( play_command ) 
	cmd( "play #{play_command}" )
  end

  def query( query_command, &blk ) 
	cmd( "query #{query_command}", &blk )  
  end
end

