diff options
author | sr55 <[email protected]> | 2010-05-30 13:02:23 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-05-30 13:02:23 +0000 |
commit | 96b87650cda57ba96a11cde80d1d8a1beeb1ee97 (patch) | |
tree | aea2355fc840cc274e47d8e04283df8c87b581c1 /win/C#/Controls | |
parent | 56186b06ee94845ac6a99fa35f62c4d8ad737c97 (diff) |
WinGui:
- Added resharper 5 file for the 2008 project.
- Unlocked VobSub in Mp4 to allow multiple tracks via passthru. Also fixed a bug with srt import handling.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3333 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Controls')
-rw-r--r-- | win/C#/Controls/Subtitles.cs | 355 |
1 files changed, 191 insertions, 164 deletions
diff --git a/win/C#/Controls/Subtitles.cs b/win/C#/Controls/Subtitles.cs index fc9315757..d3f879590 100644 --- a/win/C#/Controls/Subtitles.cs +++ b/win/C#/Controls/Subtitles.cs @@ -13,12 +13,34 @@ namespace Handbrake.Controls using Functions;
using Model;
+ /// <summary>
+ /// The Subtitles Tab
+ /// </summary>
public partial class Subtitles : UserControl
{
+ /// <summary>
+ /// Map of languages to language codes
+ /// </summary>
private readonly IDictionary<string, string> langMap = new Dictionary<string, string>();
+
+ /// <summary>
+ /// A List of SRT Files
+ /// </summary>
+ private readonly IDictionary<string, string> srtFiles = new Dictionary<string, string>();
+
+ /// <summary>
+ /// The Subtitle List
+ /// </summary>
private readonly List<SubtitleInfo> subList = new List<SubtitleInfo>();
+
+ /// <summary>
+ /// The File Container
+ /// </summary>
private int fileContainer;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Subtitles"/> class.
+ /// </summary>
public Subtitles()
{
InitializeComponent();
@@ -31,7 +53,133 @@ namespace Handbrake.Controls srt_lang.SelectedIndex = 40;
}
- // Primary Controls
+ /// <summary>
+ /// Gets the CLI Query for this panel
+ /// </summary>
+ /// <returns>A CliQuery string</returns>
+ public string GetCliQuery
+ {
+ get
+ {
+ string query = string.Empty;
+ if (lv_subList.Items.Count != 0) // If we have subtitle tracks
+ {
+ // BitMap and CC's
+ string subtitleTracks = String.Empty;
+ string subtitleForced = String.Empty;
+ string subtitleBurn = String.Empty;
+ string subtitleDefault = String.Empty;
+
+ // SRT
+ string srtFile = String.Empty;
+ string srtCodeset = String.Empty;
+ string srtOffset = String.Empty;
+ string srtLang = String.Empty;
+ string srtDefault = String.Empty;
+ int srtCount = 0;
+
+ foreach (SubtitleInfo item in subList)
+ {
+ string itemToAdd, trackId;
+
+ if (item.IsSrtSubtitle) // We have an SRT file
+ {
+ srtCount++; // SRT track id.
+
+ srtLang += srtLang == string.Empty ? langMap[item.SrtLang] : "," + langMap[item.SrtLang];
+ srtCodeset += srtCodeset == string.Empty ? item.SrtCharCode : "," + item.SrtCharCode;
+
+ if (item.Default == "Yes")
+ srtDefault = srtCount.ToString();
+
+ itemToAdd = item.SrtPath;
+ srtFile += srtFile == string.Empty ? itemToAdd : "," + itemToAdd;
+
+ itemToAdd = item.SrtOffset.ToString();
+ srtOffset += srtOffset == string.Empty ? itemToAdd : "," + itemToAdd;
+ }
+ else // We have Bitmap or CC
+ {
+ string[] tempSub;
+
+ // Find --subtitle <string>
+ if (item.Track.Contains("Foreign Audio Search"))
+ itemToAdd = "scan";
+ else
+ {
+ tempSub = item.Track.Split(' ');
+ itemToAdd = tempSub[0];
+ }
+
+ subtitleTracks += subtitleTracks == string.Empty ? itemToAdd : "," + itemToAdd;
+
+ // Find --subtitle-forced
+ itemToAdd = string.Empty;
+ tempSub = item.Track.Split(' ');
+ trackId = tempSub[0];
+
+ if (item.Forced == "Yes")
+ itemToAdd = "scan";
+
+ if (itemToAdd != string.Empty)
+ subtitleForced += subtitleForced == string.Empty ? itemToAdd : "," + itemToAdd;
+
+ // Find --subtitle-burn and --subtitle-default
+ trackId = tempSub[0];
+
+ if (trackId.Trim() == "Foreign") // foreign audio search
+ trackId = "scan";
+
+ if (item.Burned == "Yes") // burn
+ subtitleBurn = trackId;
+
+ if (item.Default == "Yes") // default
+ subtitleDefault = trackId;
+ }
+ }
+
+ // Build The CLI Subtitles Query
+ if (subtitleTracks != string.Empty)
+ {
+ query += " --subtitle " + subtitleTracks;
+
+ if (subtitleForced != string.Empty)
+ query += " --subtitle-forced=" + subtitleForced;
+ if (subtitleBurn != string.Empty)
+ query += " --subtitle-burn=" + subtitleBurn;
+ if (subtitleDefault != string.Empty)
+ query += " --subtitle-default=" + subtitleDefault;
+ }
+
+ if (srtFile != string.Empty) // SRTs
+ {
+ query += " --srt-file " + "\"" + srtFile + "\"";
+
+ if (srtCodeset != string.Empty)
+ query += " --srt-codeset " + srtCodeset;
+ if (srtOffset != string.Empty)
+ query += " --srt-offset " + srtOffset;
+ if (srtLang != string.Empty)
+ query += " --srt-lang " + srtLang;
+ if (srtDefault != string.Empty)
+ query += " --srt-default=" + srtDefault;
+ }
+ }
+ return query;
+ }
+ }
+
+ /* Primary Controls */
+
+ /// <summary>
+ /// Add a Subtitle track.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
private void BtnAddSubTrackClick(object sender, EventArgs e)
{
// Logic
@@ -48,8 +196,8 @@ namespace Handbrake.Controls {
burnedVal = "No";
forcedVal = "No";
- srtPath = openFileDialog.FileName;
- srtFile = Path.GetFileName(openFileDialog.FileName);
+ 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;
@@ -59,25 +207,6 @@ namespace Handbrake.Controls {
if (defaultSub == "Yes") SetNoDefault();
if (burnedVal == "Yes") SetNoBurned();
-
- if (fileContainer == 0)
- burnedVal = "Yes"; // MP4 must have bitmap subs burned in.
- }
-
- if (fileContainer == 0) // MP4 and M4V file extension
- {
- // Make sure we only have 1 bitmap track.
- if (drp_subtitleTracks.SelectedItem != null &&
- drp_subtitleTracks.SelectedItem.ToString().Contains("Bitmap"))
- {
- if (lv_subList.Items.Cast<ListViewItem>().Any(item => item.SubItems[0].Text.Contains("Bitmap")))
- {
- MessageBox.Show(this,
- "More than one vobsub is not supported in mp4... Your first vobsub track will now be used.",
- "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
}
string trackName = (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt"))
@@ -101,12 +230,33 @@ namespace Handbrake.Controls subList.Add(track);
}
+ /// <summary>
+ /// Import an SRT Subtitle Track
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
private void BtnSrtAddClick(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() != DialogResult.OK)
return;
+
+ if (srtFiles.ContainsKey(Path.GetFileName(openFileDialog.FileName)))
+ {
+ MessageBox.Show(
+ "A Subtitle track with the same name has already been imported.",
+ "Warning",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Warning);
+ return;
+ }
+
drp_subtitleTracks.Items.Add(Path.GetFileName(openFileDialog.FileName));
drp_subtitleTracks.SelectedItem = Path.GetFileName(openFileDialog.FileName);
+ srtFiles.Add(Path.GetFileName(openFileDialog.FileName), openFileDialog.FileName);
}
private void BtnRemoveSubTrackClick(object sender, EventArgs e)
@@ -114,7 +264,6 @@ namespace Handbrake.Controls RemoveTrack();
}
- // Secondary Controls
private void LbSubListSelectedIndexChanged(object sender, EventArgs e)
{
// Set the dropdown controls based on the selected item in the List.
@@ -157,7 +306,8 @@ namespace Handbrake.Controls SubGroupBox.Text = "Selected Track: None (Click \"Add\" to add another track to the list)";
}
- // Bitmap / CC / SRT Controls
+ /* Bitmap / CC / SRT Controls */
+
private void DrpSubtitleTracksSelectedIndexChanged(object sender, EventArgs e)
{
if (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt"))
@@ -184,6 +334,10 @@ namespace Handbrake.Controls lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[0].Text = srt_lang.SelectedItem + "(" +
drp_subtitleTracks.SelectedItem + ")";
lv_subList.Select();
+
+ string srtPath;
+ srtFiles.TryGetValue(drp_subtitleTracks.SelectedItem.ToString(), out srtPath);
+ subList[lv_subList.SelectedIndices[0]].SrtPath = srtPath;
}
else
{
@@ -193,7 +347,6 @@ namespace Handbrake.Controls }
subList[lv_subList.SelectedIndices[0]].Track = drp_subtitleTracks.SelectedItem.ToString();
- // Update SubList List<SubtitleInfo>
}
private void CheckForcedCheckedChanged(object sender, EventArgs e)
@@ -273,7 +426,8 @@ namespace Handbrake.Controls // Update SubList List<SubtitleInfo>
}
- // Right Click Menu
+ /* Right Click Menu */
+
private void MnuMoveupClick(object sender, EventArgs e)
{
if (lv_subList.SelectedIndices.Count != 0)
@@ -315,7 +469,11 @@ namespace Handbrake.Controls RemoveTrack();
}
- // Functions
+ /* Functions */
+
+ /// <summary>
+ /// Set all Non SRT tracks to Default = NO
+ /// </summary>
private void SetNoDefault()
{
int c = 0;
@@ -353,6 +511,9 @@ namespace Handbrake.Controls }
}
+ /// <summary>
+ /// Set all tracks to Burned = No
+ /// </summary>
private void SetNoBurned()
{
int c = 0;
@@ -367,6 +528,9 @@ namespace Handbrake.Controls }
}
+ /// <summary>
+ /// Remove a selected track
+ /// </summary>
private void RemoveTrack()
{
// Remove the Item and reselect the control if the following conditions are met.
@@ -402,16 +566,6 @@ namespace Handbrake.Controls }
/// <summary>
- /// Cleverly Clear the subtitle list. Only remove tracks that are not available for the current source.
- /// </summary>
- public void SmartClear()
- {
- /* Smart clear will only remove subtitle tracks that do not have an equivlent
- for the new source / title which the user has selected. */
- throw new NotImplementedException();
- }
-
- /// <summary>
/// Checks of the current settings will require the m4v file extension
/// </summary>
/// <returns>True if Yes</returns>
@@ -467,17 +621,6 @@ namespace Handbrake.Controls public void SetContainer(int value)
{
fileContainer = value;
- bool trigger = false;
- if (fileContainer != 1)
- foreach (ListViewItem item in lv_subList.Items)
- {
- if (item.SubItems[1].Text.Contains("Bitmap"))
- {
- if (trigger)
- lv_subList.Items.Remove(item);
- trigger = true;
- }
- }
}
/// <summary>
@@ -488,121 +631,5 @@ namespace Handbrake.Controls {
return subList;
}
-
- /// <summary>
- /// Gets the CLI Query for this panel
- /// </summary>
- /// <returns>A CliQuery string</returns>
- public string GetCliQuery
- {
- get
- {
- string query = string.Empty;
- if (lv_subList.Items.Count != 0) // If we have subtitle tracks
- {
- // BitMap and CC's
- string subtitleTracks = String.Empty;
- string subtitleForced = String.Empty;
- string subtitleBurn = String.Empty;
- string subtitleDefault = String.Empty;
-
- // SRT
- string srtFile = String.Empty;
- string srtCodeset = String.Empty;
- string srtOffset = String.Empty;
- string srtLang = String.Empty;
- string srtDefault = String.Empty;
- int srtCount = 0;
-
- foreach (SubtitleInfo item in subList)
- {
- string itemToAdd, trackId;
-
- if (item.IsSrtSubtitle) // We have an SRT file
- {
- srtCount++; // SRT track id.
-
- srtLang += srtLang == string.Empty ? langMap[item.SrtLang] : "," + langMap[item.SrtLang];
- srtCodeset += srtCodeset == string.Empty ? item.SrtCharCode : "," + item.SrtCharCode;
-
- if (item.Default == "Yes")
- srtDefault = srtCount.ToString();
-
- itemToAdd = item.SrtPath;
- srtFile += srtFile == string.Empty ? itemToAdd : "," + itemToAdd;
-
- itemToAdd = item.SrtOffset.ToString();
- srtOffset += srtOffset == string.Empty ? itemToAdd : "," + itemToAdd;
- }
- else // We have Bitmap or CC
- {
- string[] tempSub;
-
- // Find --subtitle <string>
- if (item.Track.Contains("Foreign Audio Search"))
- itemToAdd = "scan";
- else
- {
- tempSub = item.Track.Split(' ');
- itemToAdd = tempSub[0];
- }
-
- subtitleTracks += subtitleTracks == string.Empty ? itemToAdd : "," + itemToAdd;
-
- // Find --subtitle-forced
- itemToAdd = string.Empty;
- tempSub = item.Track.Split(' ');
- trackId = tempSub[0];
-
- if (item.Forced == "Yes")
- itemToAdd = "scan";
-
- if (itemToAdd != string.Empty)
- subtitleForced += subtitleForced == string.Empty ? itemToAdd : "," + itemToAdd;
-
- // Find --subtitle-burn and --subtitle-default
- trackId = tempSub[0];
-
- if (trackId.Trim() == "Foreign") // foreign audio search
- trackId = "scan";
-
- if (item.Burned == "Yes") // burn
- subtitleBurn = trackId;
-
- if (item.Default == "Yes") // default
- subtitleDefault = trackId;
- }
- }
-
- // Build The CLI Subtitles Query
- if (subtitleTracks != string.Empty)
- {
- query += " --subtitle " + subtitleTracks;
-
- if (subtitleForced != string.Empty)
- query += " --subtitle-forced=" + subtitleForced;
- if (subtitleBurn != string.Empty)
- query += " --subtitle-burn=" + subtitleBurn;
- if (subtitleDefault != string.Empty)
- query += " --subtitle-default=" + subtitleDefault;
- }
-
- if (srtFile != string.Empty) // SRTs
- {
- query += " --srt-file " + "\"" + srtFile + "\"";
-
- if (srtCodeset != string.Empty)
- query += " --srt-codeset " + srtCodeset;
- if (srtOffset != string.Empty)
- query += " --srt-offset " + srtOffset;
- if (srtLang != string.Empty)
- query += " --srt-lang " + srtLang;
- if (srtDefault != string.Empty)
- query += " --srt-default=" + srtDefault;
- }
- }
- return query;
- }
- }
}
}
\ No newline at end of file |