1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Handbrake.Functions;
namespace Handbrake.Controls
{
public partial class Subtitles : UserControl
{
readonly IDictionary<string, string> LangMap = new Dictionary<string, string>();
public Subtitles()
{
InitializeComponent();
LangMap = Main.mapLanguages();
foreach (string key in LangMap.Keys)
srt_lang.Items.Add(key);
srt_charcode.SelectedIndex = 28;
srt_lang.SelectedIndex = 40;
}
private int FileContainer;
public void setSubtitleTrackAuto()
{
// 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.DubAudio) // We need to add a subtitle track if this is false.
{
int i = 0;
foreach (object item in drp_subtitleTracks.Items)
{
if (item.ToString().Contains(Properties.Settings.Default.NativeLanguage))
drp_subtitleTracks.SelectedIndex = i;
i++;
}
btn_addSubTrack_Click(this, new EventArgs());
}
}
}
public void setContainer(int value)
{
FileContainer = value;
Boolean 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;
}
}
}
// Controls
private void btn_addSubTrack_Click(object sender, EventArgs e)
{
string forcedVal = "No";
string burnedVal = "No";
string defaultSub = "No";
if (check_forced.Checked)
forcedVal = "Yes";
if (check_burned.Checked)
{
if (!drp_subtitleTracks.Text.Contains("Text"))
{
burnedVal = "Yes";
setNoBurned();
}
}
if (check_default.Checked)
{
defaultSub = "Yes";
setNoDefault();
}
Boolean addTrack = true;
if (FileContainer == 0)
{
burnedVal = "Yes"; // MP4 must have bitmap subs burned in.
// Make sure we only have 1 bitmap track.
if (drp_subtitleTracks.SelectedItem != null)
{
if (drp_subtitleTracks.SelectedItem.ToString().Contains("Bitmap"))
foreach (ListViewItem item in lv_subList.Items)
{
if (item.SubItems[1].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);
addTrack = false;
}
}
}
else
addTrack = false;
}
// Add the track if allowed.
if (addTrack)
{
ListViewItem newTrack = new ListViewItem(getNewID().ToString());
newTrack.SubItems.Add(drp_subtitleTracks.SelectedItem.ToString());
newTrack.SubItems.Add(forcedVal);
newTrack.SubItems.Add(burnedVal);
newTrack.SubItems.Add(defaultSub);
lv_subList.Items.Add(newTrack);
}
}
private void btn_srtAdd_Click(object sender, EventArgs e)
{
string defaultSub = "No";
if (check_default_srt.Checked)
{
defaultSub = "Yes";
setNoDefault();
}
ListViewItem newTrack = new ListViewItem(getNewID().ToString());
newTrack.SubItems.Add(srt_lang.SelectedItem + ", (" + srt_charcode.SelectedItem + ")");
newTrack.SubItems.Add("No");
newTrack.SubItems.Add("No");
newTrack.SubItems.Add(defaultSub);
if (openFileDialog.FileName != null)
newTrack.SubItems.Add(openFileDialog.FileName);
else
newTrack.SubItems.Add("None");
newTrack.SubItems.Add(srt_offset.Value.ToString());
lv_subList.Items.Add(newTrack);
}
private void btn_RemoveSubTrack_Click(object sender, EventArgs e)
{
removeTrack();
}
private void lb_subList_SelectedIndexChanged(object sender, EventArgs e)
{
// Set the dropdown controls based on the selected item in the List.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
if (lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems.Count != 5) // We have an SRT
{
string[] trackData = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text.Split(',');
string charCode = trackData[1].Replace("(", "").Replace(")", "");
srt_lang.SelectedItem = trackData[0];
srt_charcode.SelectedItem = charCode.Trim();
int offsetVal;
int.TryParse(lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[6].Text, out offsetVal);
srt_offset.Value = offsetVal;
check_default_srt.CheckState = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[4].Text == "Yes" ? CheckState.Checked : CheckState.Unchecked;
SRTGroup.Text = "Selected Track: " + lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[0].Text;
SubTitlesGroup.Text = "Selected Track: None";
}
else // We have Bitmap/CC
{
// Setup the controls
int c = 0;
foreach (var item in drp_subtitleTracks.Items)
{
if (item.ToString() == lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text)
drp_subtitleTracks.SelectedIndex = c;
c++;
}
drp_subtitleTracks.SelectedItem = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1];
check_forced.CheckState = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[2].Text == "Yes" ? CheckState.Checked : CheckState.Unchecked;
check_burned.CheckState = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[3].Text == "Yes" ? CheckState.Checked : CheckState.Unchecked;
check_default.CheckState = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[4].Text == "Yes" ? CheckState.Checked : CheckState.Unchecked;
SubTitlesGroup.Text = "Selected Track: " + lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[0].Text;
SRTGroup.Text = "Selected Track: None";
}
}
else
{
SubTitlesGroup.Text = "Selected Track: None (Click \"Add Track\" to add)";
SRTGroup.Text = "Selected Track: None (Click \"Add External SRT\" to add) ";
}
}
// Bitmap / CC Controls
private void drp_subtitleTracks_SelectedIndexChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text = drp_subtitleTracks.SelectedItem.ToString();
lv_subList.Select();
}
}
private void check_forced_CheckedChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[2].Text = check_forced.Checked ? "Yes" : "No";
lv_subList.Select();
}
}
private void check_burned_CheckedChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
if (check_burned.Checked) // Make sure we only have 1 burned track
setNoBurned();
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[3].Text = check_burned.Checked ? "Yes" : "No";
lv_subList.Select();
}
}
private void check_default_CheckedChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
if (check_default.Checked) // Make sure we only have 1 default track
setNoDefault();
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[4].Text = check_default.Checked ? "Yes" : "No";
lv_subList.Select();
}
}
private void check_default_srt_CheckedChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
if (check_default_srt.Checked) // Make sure we only have 1 default track
setNoDefault();
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[4].Text = check_default_srt.Checked ? "Yes" : "No";
lv_subList.Select();
}
}
// SRT Controls
private void srt_offset_ValueChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[6].Text = srt_offset.Value.ToString();
lv_subList.Select();
}
}
private void srt_charcode_SelectedIndexChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
string[] trackData = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text.Split(',');
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text = trackData[0].Trim() + ", (" + srt_charcode.SelectedItem + ")";
lv_subList.Select();
}
}
private void srt_lang_SelectedIndexChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
string[] trackData = lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text.Split(',');
string charCode = trackData[1].Replace("(", "").Replace(")", "").Trim();
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[1].Text = srt_lang.SelectedItem + ", (" + charCode + ")";
lv_subList.Select();
}
}
private void srt_browse_Click(object sender, EventArgs e)
{
openFileDialog.ShowDialog();
// Update an item in the list if required.
if (lv_subList.Items.Count != 0 && lv_subList.SelectedIndices.Count != 0)
{
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[5].Text = openFileDialog.FileName;
lv_subList.Select();
}
}
// Right Click Menu
private void mnu_moveup_Click(object sender, EventArgs e)
{
if (lv_subList.SelectedIndices.Count != 0)
{
ListViewItem item = lv_subList.SelectedItems[0];
int index = item.Index;
index--;
if (lv_subList.Items.Count > index && index >= 0)
{
lv_subList.Items.Remove(item);
lv_subList.Items.Insert(index, item);
item.Selected = true;
lv_subList.Focus();
}
}
}
private void mnu_movedown_Click(object sender, EventArgs e)
{
if (lv_subList.SelectedIndices.Count != 0)
{
ListViewItem item = lv_subList.SelectedItems[0];
int index = item.Index;
index++;
if (index < lv_subList.Items.Count)
{
lv_subList.Items.Remove(item);
lv_subList.Items.Insert(index, item);
item.Selected = true;
lv_subList.Focus();
}
}
}
private void mnu_remove_Click(object sender, EventArgs e)
{
removeTrack();
}
// Functions
private void setNoDefault()
{
foreach (ListViewItem item in lv_subList.Items)
{
if (item.SubItems[4].Text == "Yes")
item.SubItems[4].Text = "No";
}
}
private void setNoBurned()
{
foreach (ListViewItem item in lv_subList.Items)
{
if (item.SubItems[3].Text == "Yes")
item.SubItems[3].Text = "No";
}
}
private void removeTrack()
{
// Remove the Item and reselect the control if the following conditions are met.
if (lv_subList.SelectedItems.Count != 0)
{
// Record the current selected index.
int currentPosition = lv_subList.SelectedIndices[0];
lv_subList.Items.RemoveAt(lv_subList.SelectedIndices[0]);
// Now reslect the correct item and give focus to the list.
if (lv_subList.Items.Count != 0)
{
if (currentPosition <= (lv_subList.Items.Count - 1))
lv_subList.Items[currentPosition].Selected = true;
else if (currentPosition > (lv_subList.Items.Count - 1))
lv_subList.Items[lv_subList.Items.Count - 1].Selected = true;
lv_subList.Select();
}
// Regenerate the ID numers
reGenerateListIDs();
}
}
// Helper Functions
private int getNewID()
{
return lv_subList.Items.Count + 1;
}
private void reGenerateListIDs()
{
int i = 1;
foreach (ListViewItem item in lv_subList.Items)
{
item.SubItems[0].Text = i.ToString();
i++;
}
}
}
}
|