summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/ViewModels
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-03-04 14:59:30 +0000
committersr55 <[email protected]>2012-03-04 14:59:30 +0000
commit24bbf1b361a7b9cb78208b43cfec59173757ae24 (patch)
treef321083db8c12f3f51325a94063617b9612f7e9e /win/CS/HandBrakeWPF/ViewModels
parent16f44055c88ecbedd9f9d216b240b3f2f9545e9e (diff)
WinGui: (WPF) Wiring up the Subtitles Auto-selection and Point-to-Point on the main window.
Also fixed the subtitles key defaults. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4494 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels')
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs35
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs48
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs167
3 files changed, 178 insertions, 72 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index 7d64cfb5e..e8e584f60 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -23,7 +23,6 @@ namespace HandBrakeWPF.ViewModels
using HandBrake.ApplicationServices;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Model.Encoding;
- using HandBrake.ApplicationServices.Model.General;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services;
using HandBrake.ApplicationServices.Services.Interfaces;
@@ -231,7 +230,7 @@ namespace HandBrakeWPF.ViewModels
set
{
- if (!object.Equals(this.windowName, value))
+ if (!Equals(this.windowName, value))
{
this.windowName = value;
}
@@ -251,7 +250,7 @@ namespace HandBrakeWPF.ViewModels
set
{
- if (!object.Equals(this.programStatusLabel, value))
+ if (!Equals(this.programStatusLabel, value))
{
this.programStatusLabel = value;
this.NotifyOfPropertyChange("ProgramStatusLabel");
@@ -334,7 +333,7 @@ namespace HandBrakeWPF.ViewModels
set
{
- if (!object.Equals(this.sourceLabel, value))
+ if (!Equals(this.sourceLabel, value))
{
this.sourceLabel = value;
this.NotifyOfPropertyChange("SourceLabel");
@@ -395,6 +394,17 @@ namespace HandBrakeWPF.ViewModels
}
/// <summary>
+ /// Gets a value indicating whether ShowTextEntryForPointToPointMode.
+ /// </summary>
+ public bool ShowTextEntryForPointToPointMode
+ {
+ get
+ {
+ return this.SelectedPointToPoint != PointToPointMode.Chapters;
+ }
+ }
+
+ /// <summary>
/// Gets StartEndRangeItems.
/// </summary>
public IEnumerable<int> StartEndRangeItems
@@ -406,7 +416,7 @@ namespace HandBrakeWPF.ViewModels
return null;
}
- return this.SelectedTitle.Chapters.Select(item => item.ChapterNumber).Select(dummy => (int)dummy).ToList();
+ return this.SelectedTitle.Chapters.Select(item => item.ChapterNumber).Select(dummy => dummy).ToList();
}
}
@@ -509,7 +519,7 @@ namespace HandBrakeWPF.ViewModels
}
set
{
- if (!object.Equals(this.selectedTitle, value))
+ if (!Equals(this.selectedTitle, value))
{
this.selectedTitle = value;
@@ -604,7 +614,8 @@ namespace HandBrakeWPF.ViewModels
set
{
this.CurrentTask.PointToPointMode = value;
- this.NotifyOfPropertyChange("SelectedPointToPoint");
+ this.NotifyOfPropertyChange(() => SelectedPointToPoint);
+ this.NotifyOfPropertyChange(() => ShowTextEntryForPointToPointMode);
}
}
@@ -620,8 +631,8 @@ namespace HandBrakeWPF.ViewModels
set
{
this.selectedOutputFormat = value;
- this.NotifyOfPropertyChange("SelectedOutputFormat");
- this.NotifyOfPropertyChange("IsMkv");
+ this.NotifyOfPropertyChange(() => SelectedOutputFormat);
+ this.NotifyOfPropertyChange(() => IsMkv);
this.SetExtension(string.Format(".{0}", this.selectedOutputFormat.ToString().ToLower())); // TODO, tidy up
}
}
@@ -1110,12 +1121,16 @@ namespace HandBrakeWPF.ViewModels
/// </returns>
private string DurationCalculation()
{
+ if (this.selectedTitle == null)
+ {
+ return "--:--:--";
+ }
+
double startEndDuration = this.SelectedEndPoint - this.SelectedStartPoint;
switch (this.SelectedPointToPoint)
{
case PointToPointMode.Chapters:
return this.SelectedTitle.CalculateDuration(this.SelectedStartPoint, this.SelectedEndPoint).ToString();
- break;
case PointToPointMode.Seconds:
return TimeSpan.FromSeconds(startEndDuration).ToString();
case PointToPointMode.Frames:
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
index 4a9dd8aa4..673579915 100644
--- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
@@ -149,11 +149,6 @@ namespace HandBrakeWPF.ViewModels
private bool enableGuiTooltips;
/// <summary>
- /// The enable query editor.
- /// </summary>
- private bool enableQueryEditor;
-
- /// <summary>
/// The growl after encode.
/// </summary>
private bool growlAfterEncode;
@@ -204,11 +199,6 @@ namespace HandBrakeWPF.ViewModels
private BindingList<string> priorityLevelOptions = new BindingList<string>();
/// <summary>
- /// The prompt on different query.
- /// </summary>
- private bool promptOnDifferentQuery;
-
- /// <summary>
/// The remove underscores.
/// </summary>
private bool removeUnderscores;
@@ -1040,40 +1030,6 @@ namespace HandBrakeWPF.ViewModels
#region Advanced
/// <summary>
- /// Gets or sets a value indicating whether EnableQueryEditor.
- /// </summary>
- public bool EnableQueryEditor
- {
- get
- {
- return this.enableQueryEditor;
- }
-
- set
- {
- this.enableQueryEditor = value;
- this.NotifyOfPropertyChange("EnableQueryEditor");
- }
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether PromptOnDifferentQuery.
- /// </summary>
- public bool PromptOnDifferentQuery
- {
- get
- {
- return this.promptOnDifferentQuery;
- }
-
- set
- {
- this.promptOnDifferentQuery = value;
- this.NotifyOfPropertyChange("PromptOnDifferentQuery");
- }
- }
-
- /// <summary>
/// Gets or sets ConstantQualityGranularity.
/// </summary>
public BindingList<string> ConstantQualityGranularity
@@ -1435,8 +1391,6 @@ namespace HandBrakeWPF.ViewModels
// Minimise to Tray
this.displayStatusMessagesTrayIcon = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.TrayIconAlerts);
this.minimiseToTray = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.MainWindowMinimize);
- this.enableQueryEditor = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.QueryEditorTab);
- this.promptOnDifferentQuery = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PromptOnUnmatchingQueries);
this.disablePresetUpdateCheckNotification = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PresetNotification);
this.showCliWindow = userSettingService.GetUserSetting<bool>(ASUserSettingConstants.ShowCLI);
@@ -1676,8 +1630,6 @@ namespace HandBrakeWPF.ViewModels
/* Advanced */
userSettingService.SetUserSetting(UserSettingConstants.MainWindowMinimize, this.MinimiseToTray);
userSettingService.SetUserSetting(UserSettingConstants.TrayIconAlerts, this.DisplayStatusMessagesTrayIcon);
- userSettingService.SetUserSetting(UserSettingConstants.QueryEditorTab, this.EnableQueryEditor);
- userSettingService.SetUserSetting(UserSettingConstants.PromptOnUnmatchingQueries, this.PromptOnDifferentQuery);
userSettingService.SetUserSetting(UserSettingConstants.PresetNotification, this.DisablePresetUpdateCheckNotification);
userSettingService.SetUserSetting(ASUserSettingConstants.ShowCLI, this.ShowCliWindow);
userSettingService.SetUserSetting(ASUserSettingConstants.PreviewScanCount, this.SelectedPreviewCount);
diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
index 13aabe5e8..cc882b160 100644
--- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
@@ -11,6 +11,7 @@ namespace HandBrakeWPF.ViewModels
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
using System.ComponentModel.Composition;
using System.Linq;
@@ -96,7 +97,6 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public IEnumerable<string> CharacterCodes { get; set; }
-
/// <summary>
/// Gets or sets SourceTracks.
/// </summary>
@@ -122,19 +122,7 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void Add()
{
- if (this.SourceTracks != null)
- {
- Subtitle source = this.SourceTracks.FirstOrDefault();
- if (source != null)
- {
- SubtitleTrack track = new SubtitleTrack
- {
- SubtitleType = SubtitleType.VobSub
- };
-
- this.SubtitleTracks.Add(track);
- }
- }
+ this.Add(null);
}
/// <summary>
@@ -187,6 +175,8 @@ namespace HandBrakeWPF.ViewModels
{
this.SourceTracks = title.Subtitles;
this.SubtitleTracks = task.SubtitleTracks;
+
+ this.AutomaticSubtitleSelection();
}
/// <summary>
@@ -199,6 +189,155 @@ namespace HandBrakeWPF.ViewModels
{
// We don't currently support subtitles within presets.
}
+
+ /// <summary>
+ /// Automatic Subtitle Selection based on user preferences.
+ /// </summary>
+ public void AutomaticSubtitleSelection()
+ {
+ this.SubtitleTracks.Clear();
+
+ // New DUB Settings
+ int mode = UserSettingService.GetUserSetting<int>(UserSettingConstants.DubModeSubtitle);
+ switch (mode)
+ {
+ case 1: // Adding all remaining subtitle tracks
+ this.AddAllRemaining();
+ break;
+ case 2: // Adding only the first or preferred first subtitle track.
+ this.Add();
+ break;
+ case 3: // Selected Languages Only
+ this.AddAllRemainingForSelectedLanguages();
+ break;
+ case 4: // Prefered Only
+ this.AddForPreferredLanaguages(true);
+ break;
+ case 5: // Prefered Only All
+ this.AddForPreferredLanaguages(false);
+ break;
+ }
+
+ // Add all closed captions if enabled.
+ this.AddAllClosedCaptions();
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ /// <summary>
+ /// Add a subtitle track.
+ /// The Source track is set based on the following order. If null, it will skip to the next option.
+ /// 1. Passed in Subitle param
+ /// 2. First preferred Subtitle from source
+ /// 3. First subtitle from source.
+ /// Will not add a subtitle if the source has none.
+ /// </summary>
+ /// <param name="subtitle">
+ /// The subtitle. Use null to add preferred, or first from source (based on user preference)
+ /// </param>
+ private void Add(Subtitle subtitle)
+ {
+ if (this.SourceTracks != null)
+ {
+ string preferred = UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles);
+
+ Subtitle source = subtitle ?? (this.SourceTracks.FirstOrDefault(l => l.Language == preferred) ??
+ this.SourceTracks.FirstOrDefault());
+
+ if (source != null)
+ {
+ SubtitleTrack track = new SubtitleTrack
+ {
+ SubtitleType = SubtitleType.VobSub,
+ SourceTrack = source,
+ };
+
+ this.SubtitleTracks.Add(track);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Add all the remaining subtitle tracks.
+ /// </summary>
+ private void AddAllRemaining()
+ {
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(null))
+ {
+ this.Add(subtitle);
+ }
+ }
+
+ /// <summary>
+ /// Add all remaining tracks for the users preferred and selected languages
+ /// </summary>
+ private void AddAllRemainingForSelectedLanguages()
+ {
+ // Get a list of subtitle tracks that match the users lanaguages
+ StringCollection userSelectedLanguages = UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages);
+ userSelectedLanguages.Add(UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles));
+ List<Subtitle> availableTracks = this.SourceTracks.Where(subtitle => userSelectedLanguages.Contains(subtitle.Language)).ToList();
+
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(availableTracks))
+ {
+ this.Add(subtitle);
+ }
+ }
+
+ /// <summary>
+ /// Add all tracks for the preferred languages settings.
+ /// </summary>
+ /// <param name="firstOnly">
+ /// The first only.
+ /// </param>
+ private void AddForPreferredLanaguages(bool firstOnly)
+ {
+ string preferred = UserSettingService.GetUserSetting<string>(
+ UserSettingConstants.NativeLanguageForSubtitles);
+
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(null))
+ {
+ if (subtitle.Language == preferred)
+ {
+ this.Add(subtitle);
+ if (firstOnly)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Add all closed captions not already on the list.
+ /// </summary>
+ private void AddAllClosedCaptions()
+ {
+ if (UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseClosedCaption))
+ {
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(null).Where(s => s.SubtitleType == SubtitleType.CC))
+ {
+ this.Add(subtitle);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets a list of Source subtitle tracks that are not currently used.
+ /// </summary>
+ /// <param name="subtitles">
+ /// The subtitles. (Optional). If null, works on the full source subtitle collection
+ /// </param>
+ /// <returns>
+ /// An IEnumerable collection of subtitles
+ /// </returns>
+ private IEnumerable<Subtitle> SourceTitlesSubset(IEnumerable<Subtitle> subtitles)
+ {
+ return subtitles != null ? subtitles.Where(subtitle => !this.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList()
+ : this.SourceTracks.Where(subtitle => !this.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList();
+ }
#endregion
}