From 987a133a592c191ea0ec416da61faceb9b54f5ff Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 1 Oct 2010 16:31:13 +0000 Subject: WinGui: - Some refactoring of the Subtitle panel. Added support for subtitle type display to the subtitle dropdown and burn in support for SSA. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3560 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Controls/Subtitles.cs | 230 ++++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 113 deletions(-) (limited to 'win/C#/Controls') diff --git a/win/C#/Controls/Subtitles.cs b/win/C#/Controls/Subtitles.cs index dec3ec11a..2a22dee52 100644 --- a/win/C#/Controls/Subtitles.cs +++ b/win/C#/Controls/Subtitles.cs @@ -11,6 +11,9 @@ namespace Handbrake.Controls using System.Linq; using System.Windows.Forms; using Functions; + + using HandBrake.ApplicationServices.Model; + using Model; /// @@ -18,6 +21,8 @@ namespace Handbrake.Controls /// public partial class Subtitles : UserControl { + #region Priavate Variables and Collections + /// /// Map of languages to language codes /// @@ -33,6 +38,8 @@ namespace Handbrake.Controls /// private readonly List subList = new List(); + #endregion + /// /// Initializes a new instance of the class. /// @@ -48,6 +55,7 @@ namespace Handbrake.Controls srt_lang.SelectedIndex = 40; } + #region Public Methods /// /// Gets the CLI Query for this panel /// @@ -84,7 +92,7 @@ namespace Handbrake.Controls srtLang += srtLang == string.Empty ? langMap[item.SrtLang] : "," + langMap[item.SrtLang]; srtCodeset += srtCodeset == string.Empty ? item.SrtCharCode : "," + item.SrtCharCode; - if (item.Default == "Yes") + if (item.Default) srtDefault = srtCount.ToString(); itemToAdd = item.SrtPath; @@ -113,7 +121,7 @@ namespace Handbrake.Controls tempSub = item.Track.Split(' '); trackId = tempSub[0]; - if (item.Forced == "Yes") + if (item.Forced) itemToAdd = trackId; if (itemToAdd != string.Empty) @@ -125,10 +133,10 @@ namespace Handbrake.Controls if (trackId.Trim() == "Foreign") // foreign audio search trackId = "scan"; - if (item.Burned == "Yes") // burn + if (item.Burned) // burn subtitleBurn = trackId; - if (item.Default == "Yes") // default + if (item.Default) // default subtitleDefault = trackId; } } @@ -164,7 +172,76 @@ namespace Handbrake.Controls } } - /* Primary Controls */ + /// + /// Checks of the current settings will require the m4v file extension + /// + /// True if Yes + public bool RequiresM4V() + { + return this.subList.Any(track => track.SubtitleType != SubtitleType.VobSub); + } + + /// + /// Automatically setup the subtitle tracks. + /// This handles the automatic setup of subitles which the user can control from the program options + /// + /// List of Subtitles + public void SetSubtitleTrackAuto(object[] subs) + { + drp_subtitleTracks.Items.Clear(); + drp_subtitleTracks.Items.Add("Foreign Audio Search (Bitmap)"); + drp_subtitleTracks.Items.AddRange(subs); + drp_subtitleTracks.SelectedIndex = 0; + Clear(); + + this.AutomaticSubtitleSelection(); + } + + /// + /// Automatic Subtitle Selection based on user preferences. + /// + 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") + { + if (Properties.Settings.Default.DubMode != 1) // We need to add a subtitle track if this is false. + { + foreach (object item in drp_subtitleTracks.Items) + { + if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage)) + { + drp_subtitleTracks.SelectedItem = item; + BtnAddSubTrackClick(this, new EventArgs()); + } + } + + if (drp_subtitleTracks.SelectedIndex == 0 && Properties.Settings.Default.useClosedCaption) + { + foreach (object item in drp_subtitleTracks.Items) + { + if (item.ToString().Contains("Closed")) + { + drp_subtitleTracks.SelectedItem = item; + BtnAddSubTrackClick(this, new EventArgs()); + } + } + } + } + } + } + + /// + /// Clear the Subtitle List + /// + public void Clear() + { + lv_subList.Items.Clear(); + subList.Clear(); + } + #endregion + + #region Primary Controls /// /// Add a Subtitle track. @@ -181,7 +258,7 @@ namespace Handbrake.Controls string forcedVal = check_forced.CheckState == CheckState.Checked ? "Yes" : "No"; string defaultSub = check_default.CheckState == CheckState.Checked ? "Yes" : "No"; string burnedVal = check_burned.CheckState == CheckState.Checked && - (!drp_subtitleTracks.Text.Contains("Text")) + (drp_subtitleTracks.Text.Contains("(VOBSUB)") || drp_subtitleTracks.Text.Contains("(SSA)")) ? "Yes" : "No"; string srtCode = "-", srtLangVal = "-", srtPath = "-", srtFile = "-"; @@ -189,19 +266,17 @@ namespace Handbrake.Controls if (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt")) { - burnedVal = "No"; - forcedVal = "No"; srtFiles.TryGetValue(drp_subtitleTracks.SelectedItem.ToString(), out srtPath); srtFile = drp_subtitleTracks.SelectedItem.ToString(); srtLangVal = srt_lang.SelectedItem.ToString(); srtCode = srt_charcode.SelectedItem.ToString(); srtOffsetMs = (int)srt_offset.Value; - if (defaultSub == "Yes") SetNoSrtDefault(); + if (defaultSub == "Yes") this.SetDefaultToOffForAllSRTTracks(); } else { - if (defaultSub == "Yes") SetNoDefault(); - if (burnedVal == "Yes") SetNoBurned(); + if (defaultSub == "Yes") this.SetDefaultToOffForAllTracks(); + if (burnedVal == "Yes") this.SetBurnedToOffForAllTracks(); } string trackName = (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt")) @@ -211,9 +286,9 @@ namespace Handbrake.Controls SubtitleInfo track = new SubtitleInfo { Track = trackName, - Forced = forcedVal, - Burned = burnedVal, - Default = defaultSub, + Forced = check_forced.Checked, + Burned = check_burned.Checked, + Default = check_default.Checked, SrtLang = srtLangVal, SrtCharCode = srtCode, SrtOffset = srtOffsetMs, @@ -265,7 +340,7 @@ namespace Handbrake.Controls /// private void BtnRemoveSubTrackClick(object sender, EventArgs e) { - RemoveTrack(); + this.RemoveSelectedTrack(); } /// @@ -297,7 +372,7 @@ namespace Handbrake.Controls srt_lang.SelectedItem = track.SrtLang; srt_offset.Value = track.SrtOffset; srt_charcode.SelectedItem = track.SrtCharCode; - check_default.CheckState = track.Default == "Yes" ? CheckState.Checked : CheckState.Unchecked; + check_default.CheckState = track.Default ? CheckState.Checked : CheckState.Unchecked; SubGroupBox.Text = "Selected Track: " + track.Track; } else // We have Bitmap/CC @@ -308,9 +383,9 @@ namespace Handbrake.Controls drp_subtitleTracks.SelectedIndex = c; c++; } - check_forced.CheckState = track.Forced == "Yes" ? CheckState.Checked : CheckState.Unchecked; - check_burned.CheckState = track.Burned == "Yes" ? CheckState.Checked : CheckState.Unchecked; - check_default.CheckState = track.Default == "Yes" ? CheckState.Checked : CheckState.Unchecked; + check_forced.CheckState = track.Forced ? CheckState.Checked : CheckState.Unchecked; + check_burned.CheckState = track.Burned ? CheckState.Checked : CheckState.Unchecked; + check_default.CheckState = track.Default ? CheckState.Checked : CheckState.Unchecked; SubGroupBox.Text = "Selected Track: " + lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[0].Text; } @@ -319,7 +394,9 @@ namespace Handbrake.Controls SubGroupBox.Text = "Selected Track: None (Click \"Add\" to add another track to the list)"; } - /* Bitmap / CC / SRT Controls */ + #endregion + + #region Subtitle Controls /// /// Handle the Subtitle track dropdown changed event @@ -387,7 +464,7 @@ namespace Handbrake.Controls lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text = check_forced.Checked ? "Yes" : "No"; lv_subList.Select(); - subList[lv_subList.SelectedIndices[0]].Forced = check_forced.Checked ? "Yes" : "No"; + subList[lv_subList.SelectedIndices[0]].Forced = check_forced.Checked; // Update SubList List } @@ -405,12 +482,12 @@ namespace Handbrake.Controls if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0) return; if (check_burned.Checked) // Make sure we only have 1 burned track - SetNoBurned(); + this.SetBurnedToOffForAllTracks(); lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[2].Text = check_burned.Checked ? "Yes" : "No"; lv_subList.Select(); - subList[lv_subList.SelectedIndices[0]].Burned = check_burned.Checked ? "Yes" : "No"; + subList[lv_subList.SelectedIndices[0]].Burned = check_burned.Checked; // Update SubList List } @@ -429,14 +506,14 @@ namespace Handbrake.Controls if (check_default.Checked) // Make sure we only have 1 default track if (lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[0].Text.Contains(".srt")) - SetNoSrtDefault(); + this.SetDefaultToOffForAllSRTTracks(); else - SetNoDefault(); + this.SetDefaultToOffForAllTracks(); lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[3].Text = check_default.Checked ? "Yes" : "No"; lv_subList.Select(); - subList[lv_subList.SelectedIndices[0]].Default = check_default.Checked ? "Yes" : "No"; + subList[lv_subList.SelectedIndices[0]].Default = check_default.Checked; // Update SubList List } @@ -502,7 +579,9 @@ namespace Handbrake.Controls // Update SubList List } - /* Right Click Menu */ + #endregion + + #region Right Click Menu /// /// Move an item in the subtitle list up @@ -569,15 +648,16 @@ namespace Handbrake.Controls /// private void MnuRemoveClick(object sender, EventArgs e) { - RemoveTrack(); + this.RemoveSelectedTrack(); } - /* Functions */ + #endregion + #region Helpers /// /// Set all Non SRT tracks to Default = NO /// - private void SetNoDefault() + private void SetDefaultToOffForAllTracks() { int c = 0; foreach (ListViewItem item in lv_subList.Items) @@ -587,7 +667,7 @@ namespace Handbrake.Controls if (item.SubItems[3].Text == "Yes") { item.SubItems[3].Text = "No"; - subList[c].Default = "No"; + subList[c].Default = false; } } c++; @@ -597,7 +677,7 @@ namespace Handbrake.Controls /// /// Set all subtitle tracks so that they have no default. /// - private void SetNoSrtDefault() + private void SetDefaultToOffForAllSRTTracks() { int c = 0; foreach (ListViewItem item in lv_subList.Items) @@ -607,7 +687,7 @@ namespace Handbrake.Controls if (item.SubItems[3].Text == "Yes") { item.SubItems[3].Text = "No"; - subList[c].Default = "No"; + subList[c].Default = false; } } c++; @@ -617,7 +697,7 @@ namespace Handbrake.Controls /// /// Set all tracks to Burned = No /// - private void SetNoBurned() + private void SetBurnedToOffForAllTracks() { int c = 0; foreach (ListViewItem item in lv_subList.Items) @@ -625,7 +705,7 @@ namespace Handbrake.Controls if (item.SubItems[2].Text == "Yes") { item.SubItems[2].Text = "No"; - subList[c].Burned = "No"; + subList[c].Burned = false; } c++; } @@ -634,7 +714,7 @@ namespace Handbrake.Controls /// /// Remove a selected track /// - private void RemoveTrack() + private void RemoveSelectedTrack() { // Remove the Item and reselect the control if the following conditions are met. if (lv_subList.SelectedItems.Count != 0) @@ -658,82 +738,6 @@ namespace Handbrake.Controls } } } - - /// - /// Clear the Subtitle List - /// - public void Clear() - { - lv_subList.Items.Clear(); - subList.Clear(); - } - - /// - /// Checks of the current settings will require the m4v file extension - /// - /// True if Yes - public bool RequiresM4V() - { - return this.lv_subList.Items.Cast().Any(item => item.SubItems.Count != 5 || item.SubItems[1].Text.Contains("(Text)")); - } - - /// - /// Automatically setup the subtitle tracks. - /// This handles the automatic setup of subitles which the user can control from the program options - /// - /// List of Subtitles - public void SetSubtitleTrackAuto(object[] subs) - { - drp_subtitleTracks.Items.Clear(); - drp_subtitleTracks.Items.Add("Foreign Audio Search (Bitmap)"); - drp_subtitleTracks.Items.AddRange(subs); - drp_subtitleTracks.SelectedIndex = 0; - Clear(); - - this.AutomaticSubtitleSelection(); - } - - /// - /// Automatic Subtitle Selection based on user preferences. - /// - 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") - { - if (Properties.Settings.Default.DubMode != 1) // We need to add a subtitle track if this is false. - { - foreach (object item in drp_subtitleTracks.Items) - { - if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage)) - { - drp_subtitleTracks.SelectedItem = item; - BtnAddSubTrackClick(this, new EventArgs()); - } - } - - if (drp_subtitleTracks.SelectedIndex == 0 && Properties.Settings.Default.useClosedCaption) - { - foreach (object item in drp_subtitleTracks.Items) - { - if (item.ToString().Contains("Closed")) - { - drp_subtitleTracks.SelectedItem = item; - BtnAddSubTrackClick(this, new EventArgs()); - } - } - } - } - } - } - - /// - /// Get the list of subtitles. - /// - /// A List of SubtitleInfo Object - public List GetSubtitleInfoList() - { - return subList; - } + #endregion } } \ No newline at end of file -- cgit v1.2.3