// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// Video Encoder Converter
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Converters.Video
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Model.Encoding;
using HandBrake.Interop.Model.Encoding;
///
/// Video Encoder Converter
///
public class VideoEncoderConverter : IMultiValueConverter
{
///
/// Gets a list of Video encoders OR returns the string name of an encoder depending on the input.
///
///
/// The values.
///
///
/// The target type.
///
///
/// The parameter.
///
///
/// The culture.
///
///
/// IEnumberable VideoEncoder or String encoder name.
///
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Count() == 2)
{
List encoders = EnumHelper.GetEnumList().ToList();
EncodeTask task = values[1] as EncodeTask;
if (task != null && task.OutputFormat != OutputFormat.Mkv)
{
encoders.Remove(VideoEncoder.Theora);
}
return EnumHelper.GetEnumDisplayValuesSubset(encoders);
}
if (values[0].GetType() == typeof(VideoEncoder))
{
return EnumHelper.GetDisplay((VideoEncoder)values[0]);
}
return null;
}
///
/// Convert from a string name, to enum value.
///
///
/// The value.
///
///
/// The target types.
///
///
/// The parameter.
///
///
/// The culture.
///
///
/// Returns the video encoder enum item.
///
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
string name = value as string;
if (!string.IsNullOrEmpty(name))
{
return new object[] { EnumHelper.GetValue(name)};
}
return null;
}
}
}