{\r
get\r
{\r
- return this.SrtFileName != "-";\r
+ return this.SrtFileName != "-" && this.SrtFileName != null;\r
}\r
}\r
\r
/// </param>\r
public static void Export(string path, Preset preset)\r
{\r
+ if (string.IsNullOrEmpty(path))\r
+ {\r
+ return;\r
+ }\r
+\r
EncodeTask parsed = QueryParserUtility.Parse(preset.Query);\r
XmlTextWriter xmlWriter = new XmlTextWriter(path, Encoding.UTF8) { Formatting = Formatting.Indented };\r
\r
public const string AutoNameFormat = "autoNameFormat";\r
public const string VLC_Path = "VLC_Path";\r
public const string MainWindowMinimize = "MainWindowMinimize";\r
- public const string QueryEditorTab = "QueryEditorTab";\r
public const string PresetNotification = "presetNotification";\r
public const string TrayIconAlerts = "trayIconAlerts";\r
public const string LastUpdateCheckDate = "lastUpdateCheckDate";\r
public const string DaysBetweenUpdateCheck = "daysBetweenUpdateCheck";\r
public const string UseM4v = "useM4v";\r
- public const string PromptOnUnmatchingQueries = "PromptOnUnmatchingQueries";\r
public const string NativeLanguage = "NativeLanguage";\r
public const string NativeLanguageForSubtitles = "NativeLanguageSubtitles";\r
public const string DubMode = "DubMode";\r
using HandBrake.ApplicationServices;\r
using HandBrake.ApplicationServices.Model;\r
using HandBrake.ApplicationServices.Model.Encoding;\r
- using HandBrake.ApplicationServices.Model.General;\r
using HandBrake.ApplicationServices.Parsing;\r
using HandBrake.ApplicationServices.Services;\r
using HandBrake.ApplicationServices.Services.Interfaces;\r
\r
set\r
{\r
- if (!object.Equals(this.windowName, value))\r
+ if (!Equals(this.windowName, value))\r
{\r
this.windowName = value;\r
}\r
\r
set\r
{\r
- if (!object.Equals(this.programStatusLabel, value))\r
+ if (!Equals(this.programStatusLabel, value))\r
{\r
this.programStatusLabel = value;\r
this.NotifyOfPropertyChange("ProgramStatusLabel");\r
\r
set\r
{\r
- if (!object.Equals(this.sourceLabel, value))\r
+ if (!Equals(this.sourceLabel, value))\r
{\r
this.sourceLabel = value;\r
this.NotifyOfPropertyChange("SourceLabel");\r
}\r
}\r
\r
+ /// <summary>\r
+ /// Gets a value indicating whether ShowTextEntryForPointToPointMode.\r
+ /// </summary>\r
+ public bool ShowTextEntryForPointToPointMode\r
+ {\r
+ get\r
+ {\r
+ return this.SelectedPointToPoint != PointToPointMode.Chapters;\r
+ }\r
+ }\r
+\r
/// <summary>\r
/// Gets StartEndRangeItems.\r
/// </summary>\r
return null;\r
}\r
\r
- return this.SelectedTitle.Chapters.Select(item => item.ChapterNumber).Select(dummy => (int)dummy).ToList();\r
+ return this.SelectedTitle.Chapters.Select(item => item.ChapterNumber).Select(dummy => dummy).ToList();\r
}\r
}\r
\r
}\r
set\r
{\r
- if (!object.Equals(this.selectedTitle, value))\r
+ if (!Equals(this.selectedTitle, value))\r
{\r
this.selectedTitle = value;\r
\r
set\r
{\r
this.CurrentTask.PointToPointMode = value;\r
- this.NotifyOfPropertyChange("SelectedPointToPoint");\r
+ this.NotifyOfPropertyChange(() => SelectedPointToPoint);\r
+ this.NotifyOfPropertyChange(() => ShowTextEntryForPointToPointMode);\r
}\r
}\r
\r
set\r
{\r
this.selectedOutputFormat = value;\r
- this.NotifyOfPropertyChange("SelectedOutputFormat");\r
- this.NotifyOfPropertyChange("IsMkv");\r
+ this.NotifyOfPropertyChange(() => SelectedOutputFormat);\r
+ this.NotifyOfPropertyChange(() => IsMkv);\r
this.SetExtension(string.Format(".{0}", this.selectedOutputFormat.ToString().ToLower())); // TODO, tidy up\r
}\r
}\r
/// </returns>\r
private string DurationCalculation()\r
{\r
+ if (this.selectedTitle == null)\r
+ {\r
+ return "--:--:--";\r
+ }\r
+\r
double startEndDuration = this.SelectedEndPoint - this.SelectedStartPoint;\r
switch (this.SelectedPointToPoint)\r
{\r
case PointToPointMode.Chapters:\r
return this.SelectedTitle.CalculateDuration(this.SelectedStartPoint, this.SelectedEndPoint).ToString();\r
- break;\r
case PointToPointMode.Seconds:\r
return TimeSpan.FromSeconds(startEndDuration).ToString();\r
case PointToPointMode.Frames:\r
/// </summary>\r
private bool enableGuiTooltips;\r
\r
- /// <summary>\r
- /// The enable query editor.\r
- /// </summary>\r
- private bool enableQueryEditor;\r
-\r
/// <summary>\r
/// The growl after encode.\r
/// </summary>\r
/// </summary>\r
private BindingList<string> priorityLevelOptions = new BindingList<string>();\r
\r
- /// <summary>\r
- /// The prompt on different query.\r
- /// </summary>\r
- private bool promptOnDifferentQuery;\r
-\r
/// <summary>\r
/// The remove underscores.\r
/// </summary>\r
\r
#region Advanced\r
\r
- /// <summary>\r
- /// Gets or sets a value indicating whether EnableQueryEditor.\r
- /// </summary>\r
- public bool EnableQueryEditor\r
- {\r
- get\r
- {\r
- return this.enableQueryEditor;\r
- }\r
-\r
- set\r
- {\r
- this.enableQueryEditor = value;\r
- this.NotifyOfPropertyChange("EnableQueryEditor");\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets a value indicating whether PromptOnDifferentQuery.\r
- /// </summary>\r
- public bool PromptOnDifferentQuery\r
- {\r
- get\r
- {\r
- return this.promptOnDifferentQuery;\r
- }\r
-\r
- set\r
- {\r
- this.promptOnDifferentQuery = value;\r
- this.NotifyOfPropertyChange("PromptOnDifferentQuery");\r
- }\r
- }\r
-\r
/// <summary>\r
/// Gets or sets ConstantQualityGranularity.\r
/// </summary>\r
// Minimise to Tray\r
this.displayStatusMessagesTrayIcon = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.TrayIconAlerts);\r
this.minimiseToTray = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.MainWindowMinimize);\r
- this.enableQueryEditor = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.QueryEditorTab);\r
- this.promptOnDifferentQuery = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PromptOnUnmatchingQueries);\r
this.disablePresetUpdateCheckNotification = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PresetNotification);\r
this.showCliWindow = userSettingService.GetUserSetting<bool>(ASUserSettingConstants.ShowCLI);\r
\r
/* Advanced */\r
userSettingService.SetUserSetting(UserSettingConstants.MainWindowMinimize, this.MinimiseToTray);\r
userSettingService.SetUserSetting(UserSettingConstants.TrayIconAlerts, this.DisplayStatusMessagesTrayIcon);\r
- userSettingService.SetUserSetting(UserSettingConstants.QueryEditorTab, this.EnableQueryEditor);\r
- userSettingService.SetUserSetting(UserSettingConstants.PromptOnUnmatchingQueries, this.PromptOnDifferentQuery);\r
userSettingService.SetUserSetting(UserSettingConstants.PresetNotification, this.DisablePresetUpdateCheckNotification);\r
userSettingService.SetUserSetting(ASUserSettingConstants.ShowCLI, this.ShowCliWindow);\r
userSettingService.SetUserSetting(ASUserSettingConstants.PreviewScanCount, this.SelectedPreviewCount);\r
{\r
using System.Collections.Generic;\r
using System.Collections.ObjectModel;\r
+ using System.Collections.Specialized;\r
using System.ComponentModel.Composition;\r
using System.Linq;\r
\r
/// </summary>\r
public IEnumerable<string> CharacterCodes { get; set; }\r
\r
-\r
/// <summary>\r
/// Gets or sets SourceTracks.\r
/// </summary>\r
/// </summary>\r
public void Add()\r
{\r
- if (this.SourceTracks != null)\r
- {\r
- Subtitle source = this.SourceTracks.FirstOrDefault();\r
- if (source != null)\r
- {\r
- SubtitleTrack track = new SubtitleTrack\r
- {\r
- SubtitleType = SubtitleType.VobSub\r
- };\r
-\r
- this.SubtitleTracks.Add(track);\r
- }\r
- }\r
+ this.Add(null);\r
}\r
\r
/// <summary>\r
{\r
this.SourceTracks = title.Subtitles;\r
this.SubtitleTracks = task.SubtitleTracks;\r
+\r
+ this.AutomaticSubtitleSelection();\r
}\r
\r
/// <summary>\r
{\r
// We don't currently support subtitles within presets.\r
}\r
+ \r
+ /// <summary>\r
+ /// Automatic Subtitle Selection based on user preferences.\r
+ /// </summary>\r
+ public void AutomaticSubtitleSelection()\r
+ {\r
+ this.SubtitleTracks.Clear();\r
+\r
+ // New DUB Settings\r
+ int mode = UserSettingService.GetUserSetting<int>(UserSettingConstants.DubModeSubtitle);\r
+ switch (mode)\r
+ {\r
+ case 1: // Adding all remaining subtitle tracks\r
+ this.AddAllRemaining();\r
+ break;\r
+ case 2: // Adding only the first or preferred first subtitle track.\r
+ this.Add();\r
+ break;\r
+ case 3: // Selected Languages Only\r
+ this.AddAllRemainingForSelectedLanguages();\r
+ break;\r
+ case 4: // Prefered Only\r
+ this.AddForPreferredLanaguages(true);\r
+ break;\r
+ case 5: // Prefered Only All\r
+ this.AddForPreferredLanaguages(false);\r
+ break;\r
+ }\r
+\r
+ // Add all closed captions if enabled.\r
+ this.AddAllClosedCaptions();\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region Private Methods\r
+\r
+ /// <summary>\r
+ /// Add a subtitle track.\r
+ /// The Source track is set based on the following order. If null, it will skip to the next option.\r
+ /// 1. Passed in Subitle param\r
+ /// 2. First preferred Subtitle from source\r
+ /// 3. First subtitle from source.\r
+ /// Will not add a subtitle if the source has none.\r
+ /// </summary>\r
+ /// <param name="subtitle">\r
+ /// The subtitle. Use null to add preferred, or first from source (based on user preference)\r
+ /// </param>\r
+ private void Add(Subtitle subtitle)\r
+ {\r
+ if (this.SourceTracks != null)\r
+ {\r
+ string preferred = UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles);\r
+\r
+ Subtitle source = subtitle ?? (this.SourceTracks.FirstOrDefault(l => l.Language == preferred) ??\r
+ this.SourceTracks.FirstOrDefault());\r
+\r
+ if (source != null)\r
+ {\r
+ SubtitleTrack track = new SubtitleTrack\r
+ {\r
+ SubtitleType = SubtitleType.VobSub,\r
+ SourceTrack = source,\r
+ };\r
+\r
+ this.SubtitleTracks.Add(track);\r
+ }\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Add all the remaining subtitle tracks.\r
+ /// </summary>\r
+ private void AddAllRemaining()\r
+ {\r
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(null))\r
+ {\r
+ this.Add(subtitle);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Add all remaining tracks for the users preferred and selected languages\r
+ /// </summary>\r
+ private void AddAllRemainingForSelectedLanguages()\r
+ {\r
+ // Get a list of subtitle tracks that match the users lanaguages\r
+ StringCollection userSelectedLanguages = UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages);\r
+ userSelectedLanguages.Add(UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles));\r
+ List<Subtitle> availableTracks = this.SourceTracks.Where(subtitle => userSelectedLanguages.Contains(subtitle.Language)).ToList();\r
+\r
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(availableTracks))\r
+ {\r
+ this.Add(subtitle);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Add all tracks for the preferred languages settings.\r
+ /// </summary>\r
+ /// <param name="firstOnly">\r
+ /// The first only.\r
+ /// </param>\r
+ private void AddForPreferredLanaguages(bool firstOnly)\r
+ {\r
+ string preferred = UserSettingService.GetUserSetting<string>(\r
+ UserSettingConstants.NativeLanguageForSubtitles);\r
+\r
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(null))\r
+ {\r
+ if (subtitle.Language == preferred)\r
+ {\r
+ this.Add(subtitle);\r
+ if (firstOnly)\r
+ {\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Add all closed captions not already on the list.\r
+ /// </summary>\r
+ private void AddAllClosedCaptions()\r
+ {\r
+ if (UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseClosedCaption))\r
+ {\r
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(null).Where(s => s.SubtitleType == SubtitleType.CC))\r
+ {\r
+ this.Add(subtitle);\r
+ }\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Gets a list of Source subtitle tracks that are not currently used.\r
+ /// </summary>\r
+ /// <param name="subtitles">\r
+ /// The subtitles. (Optional). If null, works on the full source subtitle collection\r
+ /// </param>\r
+ /// <returns>\r
+ /// An IEnumerable collection of subtitles\r
+ /// </returns>\r
+ private IEnumerable<Subtitle> SourceTitlesSubset(IEnumerable<Subtitle> subtitles)\r
+ {\r
+ return subtitles != null ? subtitles.Where(subtitle => !this.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList() \r
+ : this.SourceTracks.Where(subtitle => !this.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList();\r
+ }\r
\r
#endregion\r
}\r
<ComboBox Name="Angles" Margin="8,0,0,0" MinWidth="60" ItemsSource="{Binding Angles}" SelectedItem="{Binding SelectedAngle}"/>\r
\r
<ComboBox Name="PointToPointMode" Margin="8,0,0,0" MinWidth="80" ItemsSource="{Binding RangeMode}" SelectedItem="{Binding SelectedPointToPoint}" />\r
- <ComboBox Name="StartPoint" Margin="8,0,0,0" MinWidth="60" ItemsSource="{Binding StartEndRangeItems}" SelectedItem="{Binding SelectedStartPoint}" />\r
+ \r
+ <ComboBox Name="StartPoint" Margin="8,0,0,0" MinWidth="60" ItemsSource="{Binding StartEndRangeItems}" SelectedItem="{Binding SelectedStartPoint}"\r
+ Visibility="{Binding ShowTextEntryForPointToPointMode,Converter={StaticResource boolToVisConverter}, ConverterParameter=true}"/>\r
+ <TextBox Name="StartPointText" Margin="8,0,0,0" MinWidth="60" Text="{Binding SelectedStartPoint}"\r
+ Visibility="{Binding ShowTextEntryForPointToPointMode, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}"/>\r
+ \r
<Label Content="through" Margin="8,0,0,0" />\r
- <ComboBox Name="EndPoint" Margin="8,0,0,0" MinWidth="60" ItemsSource="{Binding StartEndRangeItems}" SelectedItem="{Binding SelectedEndPoint}" />\r
+ <ComboBox Name="EndPoint" Margin="8,0,0,0" MinWidth="60" ItemsSource="{Binding StartEndRangeItems}" SelectedItem="{Binding SelectedEndPoint}"\r
+ Visibility="{Binding ShowTextEntryForPointToPointMode, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}"/>\r
+ <TextBox Name="EndPointText" Margin="8,0,0,0" MinWidth="60" Text="{Binding SelectedEndPoint}" \r
+ Visibility="{Binding ShowTextEntryForPointToPointMode, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />\r
+ \r
<Label Content="Duration" Margin="8,0,0,0" />\r
<Label Content="{Binding Duration}" Margin="8,0,0,0" />\r
</StackPanel>\r
<StackPanel Orientation="Horizontal">\r
<Label Content="File" Margin="8,0,0,0" />\r
<TextBox Name="Destination" Margin="8,0,0,0" Width="600" Text="{Binding CurrentTask.Destination}" />\r
- <Button Name="DestinationBrowser" Margin="8,0,0,0" Padding="8,0,8,0" Content="Browse" Micro:Message.Attach="[Event Click] = [Action BrowseDestination]" />\r
+ <Button Name="DestinationBrowser" Margin="8,0,0,0" Content="Browse" Micro:Message.Attach="[Event Click] = [Action BrowseDestination]" />\r
</StackPanel>\r
</StackPanel>\r
\r
<StackPanel Orientation="Vertical" Grid.Column="1">\r
<CheckBox Content="Minimize to system tray (Requires Restart)" IsChecked="{Binding MinimiseToTray}" />\r
<CheckBox Content="Display status messages from tray icon (balloon popups)" IsChecked="{Binding DisplayStatusMessagesTrayIcon}" />\r
- <CheckBox Content="Enable 'Query Editor' tab (Requires Restart)" IsChecked="{Binding EnableQueryEditor}" />\r
- <CheckBox Content="Prompt when a manual query does not match GUI settings" Margin="10,0,0,5" IsChecked="{Binding PromptOnDifferentQuery}" />\r
<CheckBox Content="Disable built-in preset update notification" IsChecked="{Binding DisablePresetUpdateCheckNotification}" />\r
<CheckBox Content="Show CLI window (Allows you to cleanly exit encode with ctrl-c)" IsChecked="{Binding ShowCliWindow}" />\r
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">\r
<!-- Row 1-->\r
\r
<TextBlock Text="Source" FontWeight="Bold" Grid.Column="0" VerticalAlignment="Center" />\r
- <ComboBox Width="100" ItemsSource="{Binding DataContext.SourceTracks, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" \r
+ <ComboBox Width="120" ItemsSource="{Binding DataContext.SourceTracks, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" \r
SelectedItem="{Binding SourceTrack}" Grid.Column="1" Margin="5,0,5,0" Height="22" />\r
<TextBlock Text="Forced Only" FontWeight="Bold" Grid.Column="2" VerticalAlignment="Center" />\r
<CheckBox Grid.Column="3" IsChecked="{Binding Forced}" VerticalAlignment="Center" Margin="5,0,5,0"/>\r
\r
<!-- Row 2-->\r
<TextBlock Text="Language" FontWeight="Bold" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center"/>\r
- <ComboBox Width="100" Grid.Column="1" ItemsSource="{Binding DataContext.Langauges, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" SelectedItem="{Binding SrtLang}" Margin="5,0,5,0" Grid.Row="1" Height="22" />\r
+ <ComboBox Width="120" Grid.Column="1" \r
+ ItemsSource="{Binding DataContext.Langauges, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" \r
+ SelectedItem="{Binding SrtLang}" Margin="5,0,5,0" Grid.Row="1" Height="22"\r
+ IsEnabled="{Binding IsSrtSubtitle}"/>\r
<TextBlock Text="Char Code" FontWeight="Bold" Grid.Column="2" Grid.Row="1" VerticalAlignment="Center"/>\r
- <ComboBox Width="100" Grid.Column="3" ItemsSource="{Binding DataContext.CharacterCodes, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" SelectedItem="{Binding SrtCharCode}" Grid.Row="1" Margin="5,0,5,0" Height="22" />\r
+ <ComboBox Width="100" Grid.Column="3" \r
+ ItemsSource="{Binding DataContext.CharacterCodes, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" \r
+ SelectedItem="{Binding SrtCharCode}" Grid.Row="1" Margin="5,0,5,0" Height="22" \r
+ IsEnabled="{Binding IsSrtSubtitle}" />\r
<TextBlock Text="Offset (ms)" FontWeight="Bold" Grid.Column="4" Grid.Row="1" VerticalAlignment="Center"/>\r
- <NumericUpDown:NumericUpDown Width="45" Value="{Binding SrtOffset}" Grid.Row="1" Grid.Column="5" HorizontalAlignment="Left" Margin="5,0,5,0" />\r
+ <NumericUpDown:NumericUpDown Width="65" Value="{Binding SrtOffset}" Grid.Row="1" Grid.Column="5" HorizontalAlignment="Left" \r
+ IsEnabled="{Binding IsSrtSubtitle}" Margin="5,0,5,0" />\r
\r
</Grid>\r
\r
</item>\r
<item>\r
<key>\r
- <string>NativeLanguageForSubtitles</string>\r
+ <string>NativeLanguageSubtitles</string>\r
</key>\r
<value>\r
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">Any</anyType>\r
</item>\r
<item>\r
<key>\r
- <string>NativeLanguageForSubtitles</string>\r
+ <string>NativeLanguageSubtitles</string>\r
</key>\r
<value>\r
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">Any</anyType>\r