summaryrefslogtreecommitdiffstats
path: root/win/CS/Controls
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-07-23 19:13:05 +0000
committersr55 <[email protected]>2011-07-23 19:13:05 +0000
commit0acf6155a9410cd1faf207b2cf77fc31f392e396 (patch)
tree9178cd036b455c39004448ee4fa3f9601fc1249d /win/CS/Controls
parent80dc05bf339c0bbe492a6d20ccc013812c4582c2 (diff)
WinGui: Auto Selection of Audio and Subtitles - Patch by vendolis (Thanks!)
Adds finer grained control of the Automatic Audio and Subtitle selection feature. Adds the ability to select multiple languages. https://reviews.handbrake.fr/r/158/ git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4127 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/Controls')
-rw-r--r--win/CS/Controls/AudioPanel.cs129
-rw-r--r--win/CS/Controls/Subtitles.cs108
2 files changed, 188 insertions, 49 deletions
diff --git a/win/CS/Controls/AudioPanel.cs b/win/CS/Controls/AudioPanel.cs
index fefd694ac..fe56bfbdd 100644
--- a/win/CS/Controls/AudioPanel.cs
+++ b/win/CS/Controls/AudioPanel.cs
@@ -6,6 +6,7 @@
namespace Handbrake.Controls
{
using System;
+ using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -213,7 +214,7 @@ namespace Handbrake.Controls
}
}
- if (this.AudioTracks.Count > 0)
+ if (selectedTitle.AudioTracks.Count > 0)
{
this.AutomaticTrackSelection();
}
@@ -553,69 +554,115 @@ namespace Handbrake.Controls
/// </summary>
private void AutomaticTrackSelection()
{
+ // Sanity check that we have Audio Tracks and if not, clear the track list.
if (drp_audioTrack.SelectedItem != null && drp_audioTrack.SelectedItem.ToString() == AudioHelper.NoneFound.Description)
{
this.AudioTracks.Clear();
return;
}
- // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
+ // Remove all old Audiotracks before adding new ones.
+ this.AudioTracks.Clear();
+
+ // Array with the Index numbers of the prefered and additional languages.
+ // This allows to have for each language the order in which they appear in the DVD list.
+ Dictionary<String, ArrayList> languageIndex = new Dictionary<String, ArrayList>();
+
+ // This is used to keep the Prefered Language in the front and the other languages in order.
+ ArrayList languageOrder = new ArrayList();
+
+ // New DUB Settings
+ int mode = Properties.Settings.Default.DubModeAudio;
+
if (Properties.Settings.Default.NativeLanguage == "Any")
+ mode = 2;
+
+ // Native Language is not 'Any', so initialising the Language Dictionary
+ if (mode >= 3)
{
- drp_audioTrack.SelectedIndex = 0;
- foreach (AudioTrack track in this.audioTracks)
+ languageIndex.Add(Properties.Settings.Default.NativeLanguage, new ArrayList());
+ languageOrder.Add(Properties.Settings.Default.NativeLanguage);
+
+ foreach (string item in Properties.Settings.Default.SelectedLanguages)
{
- if (this.drp_audioTrack.SelectedItem != null)
+ if (!languageIndex.ContainsKey(item))
{
- track.ScannedTrack = this.drp_audioTrack.SelectedItem as Audio;
+ languageIndex.Add(item, new ArrayList());
+ languageOrder.Add(item);
}
}
- }
- else
- {
- int mode = Properties.Settings.Default.DubMode;
- switch (mode)
+
+ bool elementFound = false;
+ int i = 0;
+ foreach (object item in drp_audioTrack.Items)
{
- case 1:
- case 3:
- // Dub Foreign Language Audio
- // Select the prefered language audio, or the first track if it doesn't exist.
- int i = 0;
- foreach (object item in drp_audioTrack.Items)
+ foreach (KeyValuePair<String, ArrayList> kvp in languageIndex)
+ {
+ if (item.ToString().Contains(kvp.Key))
{
- if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
+ // Only the first Element if the "Only One Audio"-option is chosen.
+ if (!Properties.Settings.Default.addOnlyOneAudioPerLanguage || kvp.Value.Count == 0)
{
- drp_audioTrack.SelectedIndex = i;
- break;
+ kvp.Value.Add(i);
}
- i++;
+ elementFound = true;
}
+ }
- if (drp_audioTrack.SelectedItem != null)
- foreach (AudioTrack track in this.audioTracks)
- track.ScannedTrack =
- drp_audioTrack.SelectedItem as Audio;
- else
+ i++;
+ }
+
+ // If there are no selected languages found, the first available will be taken.
+ if (!elementFound)
+ mode = 2;
+ }
+
+ switch (mode)
+ {
+ case 1: // Adding all audio tracks
+ this.mnu_AddAll_Click(this, EventArgs.Empty);
+ break;
+ case 2: // Adding only the first Audio Track
+ drp_audioTrack.SelectedIndex = 0;
+ if (drp_audioTrack.SelectedItem != null)
+ this.AddAudioTrack_Click(this, EventArgs.Empty);
+ break;
+ case 3:
+ foreach (string item in languageOrder)
+ {
+ if (languageIndex[item].Count > 0)
{
- drp_audioTrack.SelectedIndex = 0;
+ foreach (int i in languageIndex[item])
+ {
+ drp_audioTrack.SelectedIndex = i;
+ if (drp_audioTrack.SelectedItem != null)
+ {
+ this.AddAudioTrack_Click(this, EventArgs.Empty);
+ audioList.ClearSelection();
+ }
+ }
+ }
+ }
+ break;
+ case 4:
+ if (languageIndex[(string)languageOrder[0]].Count > 0)
+ {
+ foreach (int i in languageIndex[(string)languageOrder[0]])
+ {
+ drp_audioTrack.SelectedIndex = i;
if (drp_audioTrack.SelectedItem != null)
- foreach (AudioTrack track in this.audioTracks)
- track.ScannedTrack = drp_audioTrack.SelectedItem as Audio;
+ {
+ this.AddAudioTrack_Click(this, EventArgs.Empty);
+ audioList.ClearSelection();
+ }
}
-
- break;
- case 2:
- default:
- // Select the first track which is hopefully the default and foreign track.
- drp_audioTrack.SelectedIndex = 0;
-
- if (drp_audioTrack.SelectedItem != null)
- foreach (AudioTrack track in this.audioTracks)
- track.ScannedTrack = drp_audioTrack.SelectedItem as Audio;
- break;
- }
+ }
+ break;
}
+
+ // Revert the selection back tio the first item.
+ drp_audioTrack.SelectedIndex = 0;
}
/// <summary>
diff --git a/win/CS/Controls/Subtitles.cs b/win/CS/Controls/Subtitles.cs
index e277a8c1a..1c8bef8cc 100644
--- a/win/CS/Controls/Subtitles.cs
+++ b/win/CS/Controls/Subtitles.cs
@@ -6,6 +6,7 @@
namespace Handbrake.Controls
{
using System;
+ using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -190,23 +191,114 @@ namespace Handbrake.Controls
/// </summary>
public void AutomaticSubtitleSelection()
{
- // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options
- if (Properties.Settings.Default.NativeLanguage != "Any")
+ // Avoid trying to add elements when no subtitles are there.
+ if (drp_subtitleTracks.Items.Count < 2)
{
- if (Properties.Settings.Default.DubMode != 1) // We need to add a subtitle track if this is false.
+ return;
+ }
+
+ this.Clear();
+
+ // Array with the Index numbers of the prefered and additional languages.
+ // This allows to have for each language the order in which they appear in the DVD list.
+ Dictionary<String, ArrayList> languageIndex = new Dictionary<String, ArrayList>();
+
+ // This is used to keep the Prefered Language in the front and the other languages in order.
+ ArrayList languageOrder = new ArrayList();
+
+ // New DUB Settings
+ int mode = Properties.Settings.Default.DubModeSubtitle;
+
+ if (Properties.Settings.Default.NativeLanguage == "Any")
+ mode = 0;
+
+ // Native Language is not 'Any', so initialising the Language Dictionary
+ if (mode >= 3)
+ {
+ languageIndex.Add(Properties.Settings.Default.NativeLanguage, new ArrayList());
+ languageOrder.Add(Properties.Settings.Default.NativeLanguage);
+
+ foreach (string item in Properties.Settings.Default.SelectedLanguages)
{
- foreach (object item in drp_subtitleTracks.Items)
+ if (!languageIndex.ContainsKey(item))
{
- if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
+ languageIndex.Add(item, new ArrayList());
+ languageOrder.Add(item);
+ }
+ }
+
+ bool elementFound = false;
+ int i = 0;
+ foreach (object item in drp_subtitleTracks.Items)
+ {
+ foreach (KeyValuePair<String, ArrayList> kvp in languageIndex)
+ {
+ if (item.ToString().Contains(kvp.Key))
{
- drp_subtitleTracks.SelectedItem = item;
- BtnAddSubTrackClick(this, new EventArgs());
+ kvp.Value.Add(i);
+ elementFound = true;
}
}
+
+ i++;
}
+
+ // If there are no selected languages found, the first available will be taken.
+ if (!elementFound)
+ mode = 2;
}
+ switch (mode)
+ {
+ case 1: // Adding all audio tracks
+ for (int i = 1; i < drp_subtitleTracks.Items.Count; i++)
+ {
+ drp_subtitleTracks.SelectedIndex = i;
+ this.BtnAddSubTrackClick(this, new EventArgs());
+ }
+ break;
+ case 2: // Adding only the first Audio Track
+ drp_subtitleTracks.SelectedIndex = 1;
+ if (drp_subtitleTracks.SelectedItem != null)
+ this.BtnAddSubTrackClick(this, new EventArgs());
+ break;
+ case 3:
+ foreach (string item in languageOrder)
+ {
+ if (languageIndex[item].Count > 0)
+ {
+ foreach (int i in languageIndex[item])
+ {
+ drp_subtitleTracks.SelectedIndex = i;
+ if (drp_subtitleTracks.SelectedItem != null)
+ {
+ this.BtnAddSubTrackClick(this, new EventArgs());
+ //subList.ClearSelection();
+ }
+ }
+ }
+ }
+ break;
+ case 4:
+ if (languageIndex[(string)languageOrder[0]].Count > 0)
+ {
+ foreach (int i in languageIndex[(string)languageOrder[0]])
+ {
+ drp_subtitleTracks.SelectedIndex = i;
+ if (drp_subtitleTracks.SelectedItem != null)
+ {
+ this.BtnAddSubTrackClick(this, new EventArgs());
+ //subList.ClearSelection();
+ }
+ }
+ }
+ break;
+ }
+
+ // Revert the selection back tio the first item.
+ drp_subtitleTracks.SelectedIndex = 0;
+ // Add Closed Captions if the user has the option enabled.
if (Properties.Settings.Default.useClosedCaption)
{
foreach (object item in drp_subtitleTracks.Items)
@@ -214,7 +306,7 @@ namespace Handbrake.Controls
if (item.ToString().Contains("Closed"))
{
drp_subtitleTracks.SelectedItem = item;
- BtnAddSubTrackClick(this, new EventArgs());
+ BtnAddSubTrackClick(this, EventArgs.Empty);
}
}
}