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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
|
/* Subtitles.cs $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr>.
It may be used under the terms of the GNU General Public License. */
namespace Handbrake.Controls
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using HandBrake.ApplicationServices;
using HandBrake.ApplicationServices.Model.Encoding;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.ApplicationServices.Utilities;
/// <summary>
/// The Subtitles Tab
/// </summary>
public partial class Subtitles : UserControl
{
#region Priavate Variables and Collections
/// <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<SubtitleTrack> subList = new List<SubtitleTrack>();
/// <summary>
/// The User Setting Service.
/// </summary>
private static readonly IUserSettingService UserSettingService = ServiceManager.UserSettingService;
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="Subtitles"/> class.
/// </summary>
public Subtitles()
{
InitializeComponent();
langMap = LanguageUtilities.MapLanguages();
foreach (string key in langMap.Keys)
srt_lang.Items.Add(key);
srt_charcode.SelectedIndex = 28;
srt_lang.SelectedIndex = 40;
}
/// <summary>
/// Gets SubtitlesList.
/// </summary>
public List<SubtitleTrack> SubtitlesList
{
get
{
return subList;
}
}
#region Public Methods
/// <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;
int subCount = 0;
foreach (SubtitleTrack item in subList)
{
string itemToAdd;
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)
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
{
subCount++;
// Find --subtitle <string>
if (item.Track.Contains("Foreign Audio Search"))
itemToAdd = "scan";
else
{
string[] tempSub = item.Track.Split(' ');
itemToAdd = tempSub[0];
}
subtitleTracks += subtitleTracks == string.Empty ? itemToAdd : "," + itemToAdd;
// Find --subtitle-forced
if (item.Forced)
subtitleForced += subtitleForced == string.Empty ? subCount.ToString() : "," + subCount;
// Find --subtitle-burn
if (item.Burned)
subtitleBurn = subCount.ToString();
// Find --subtitle-default
if (item.Default)
subtitleDefault = subCount.ToString();
}
}
// 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;
}
}
/// <summary>
/// Checks of the current settings will require the m4v file extension
/// </summary>
/// <returns>True if Yes</returns>
public bool RequiresM4V()
{
return this.subList.Any(track => track.SubtitleType != SubtitleType.VobSub);
}
/// <summary>
/// Automatically setup the subtitle tracks.
/// This handles the automatic setup of subitles which the user can control from the program options
/// </summary>
/// <param name="subs">List of Subtitles</param>
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();
}
/// <summary>
/// Automatic Subtitle Selection based on user preferences.
/// </summary>
public void AutomaticSubtitleSelection()
{
// Avoid trying to add elements when no subtitles are there.
if (drp_subtitleTracks.Items.Count < 2)
{
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 = UserSettingService.GetUserSetting<int>(UserSettingConstants.DubModeSubtitle);
if (UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage) == "Any")
mode = 0;
// Native Language is not 'Any', so initialising the Language Dictionary
if (mode >= 3)
{
languageIndex.Add(UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage), new ArrayList());
languageOrder.Add(UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage));
foreach (string item in UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages))
{
if (!languageIndex.ContainsKey(item))
{
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))
{
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.btn_addSubtitleTrack_Click(this, new EventArgs());
}
break;
case 2: // Adding only the first Audio Track
drp_subtitleTracks.SelectedIndex = 1;
if (drp_subtitleTracks.SelectedItem != null)
this.btn_addSubtitleTrack_Click(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.btn_addSubtitleTrack_Click(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.btn_addSubtitleTrack_Click(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 (UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseClosedCaption))
{
foreach (object item in drp_subtitleTracks.Items)
{
if (item.ToString().Contains("Closed"))
{
drp_subtitleTracks.SelectedItem = item;
btn_addSubtitleTrack_Click(this, EventArgs.Empty);
}
}
}
}
/// <summary>
/// Clear the Subtitle List
/// </summary>
public void Clear()
{
lv_subList.Items.Clear();
subList.Clear();
srtFiles.Clear();
}
#endregion
#region Primary Controls
/// <summary>
/// Add a subtitle Track
/// </summary>
/// <param name="sender">
/// The Sender
/// </param>
/// <param name="e">
/// The Event Args
/// </param>
private void btn_addSubtitleTrack_Click(object sender, EventArgs e)
{
if (drp_subtitleTracks.SelectedItem == null)
{
MessageBox.Show("No Subtitle Track Selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Logic
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("(VOBSUB)") || drp_subtitleTracks.Text.Contains("(SSA)"))
? "Yes"
: "No";
string srtCode = "-", srtLangVal = "-", srtPath = "-", srtFile = "-";
int srtOffsetMs = 0;
if (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt"))
{
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") this.SetDefaultToOffForAllSRTTracks();
}
else
{
if (defaultSub == "Yes") this.SetDefaultToOffForAllTracks();
if (burnedVal == "Yes") this.SetBurnedToOffForAllTracks();
}
string trackName = (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt"))
? srtLangVal + " (" + srtFile + ")"
: drp_subtitleTracks.SelectedItem.ToString();
SubtitleTrack track = new SubtitleTrack
{
Track = trackName,
Forced = check_forced.Checked,
Burned = check_burned.Checked,
Default = check_default.Checked,
SrtLang = srtLangVal,
SrtCharCode = srtCode,
SrtOffset = srtOffsetMs,
SrtPath = srtPath,
SrtFileName = srtFile
};
lv_subList.Items.Add(track.ListView);
subList.Add(track);
}
/// <summary>
/// Add all audio tracks.
/// </summary>
/// <param name="sender">
/// The Sender
/// </param>
/// <param name="e">
/// The Event Args
/// </param>
private void mnu_AddAll_Click(object sender, EventArgs e)
{
// TODO - Might need to be a bit more clever with this. Will wait and see if this causes any problems.
foreach (object item in drp_subtitleTracks.Items)
{
if (!item.ToString().Contains("Foreign Audio Search"))
{
drp_subtitleTracks.SelectedItem = item;
btn_addSubtitleTrack_Click(this, EventArgs.Empty);
}
}
}
/// <summary>
/// Add all closed caption tracks
/// </summary>
/// <param name="sender">
/// The Sender
/// </param>
/// <param name="e">
/// The Event Args
/// </param>
private void mnu_AddAllCC_Click(object sender, EventArgs e)
{
foreach (object item in drp_subtitleTracks.Items)
{
if (item.ToString().Contains("Closed"))
{
drp_subtitleTracks.SelectedItem = item;
btn_addSubtitleTrack_Click(this, EventArgs.Empty);
}
}
}
/// <summary>
/// Clear all tracks.
/// </summary>
/// <param name="sender">
/// The Sender
/// </param>
/// <param name="e">
/// The Event Args
/// </param>
private void mnu_ClearAll_Click(object sender, EventArgs e)
{
lv_subList.Items.Clear();
subList.Clear();
}
/// <summary>
/// Remvoe a track
/// </summary>
/// <param name="sender">
/// The Sender
/// </param>
/// <param name="e">
/// The Event Args
/// </param>
private void btn_RemoveTrack_Click(object sender, EventArgs e)
{
this.RemoveSelectedTrack();
}
/// <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);
}
/// <summary>
/// The Subtitle List selected index has changed
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void LbSubListSelectedIndexChanged(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)
{
SubtitleTrack track = subList[lv_subList.SelectedIndices[0]];
int c = 0;
if (lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[0].Text.ToLower().Contains(".srt"))
// We have an SRT
{
foreach (var item in drp_subtitleTracks.Items)
{
if (item.ToString() == track.SrtFileName)
drp_subtitleTracks.SelectedIndex = c;
c++;
}
srt_lang.SelectedItem = track.SrtLang;
srt_offset.Value = track.SrtOffset;
srt_charcode.SelectedItem = track.SrtCharCode;
check_default.CheckState = track.Default ? CheckState.Checked : CheckState.Unchecked;
}
else // We have Bitmap/CC
{
foreach (var item in drp_subtitleTracks.Items)
{
if (item.ToString() == track.Track)
drp_subtitleTracks.SelectedIndex = c;
c++;
}
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;
}
}
}
#endregion
#region Subtitle Controls
/// <summary>
/// Handle the Subtitle track dropdown changed event
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void DrpSubtitleTracksSelectedIndexChanged(object sender, EventArgs e)
{
if (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt"))
{
check_forced.Enabled = false;
check_burned.Enabled = false;
srt_lang.Enabled = true;
srt_charcode.Enabled = true;
srt_offset.Enabled = true;
}
else
{
check_forced.Enabled = true;
check_burned.Enabled = true;
srt_lang.Enabled = false;
srt_charcode.Enabled = false;
srt_offset.Enabled = false;
}
// Update an item in the list if required.
if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0) return;
if (drp_subtitleTracks.SelectedItem.ToString().Contains(".srt"))
{
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
{
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[0].Text =
drp_subtitleTracks.SelectedItem.ToString();
lv_subList.Select();
}
subList[lv_subList.SelectedIndices[0]].Track = drp_subtitleTracks.SelectedItem.ToString();
}
/// <summary>
/// Foreced Subtitles checkbox changed
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void CheckForcedCheckedChanged(object sender, EventArgs e)
{
if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0) return;
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;
// Update SubList List<SubtitleInfo>
}
/// <summary>
/// Burned in subtitles checkbox changed
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void CheckBurnedCheckedChanged(object sender, EventArgs e)
{
if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0) return;
if (check_burned.Checked) // Make sure we only have 1 burned track
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;
// Update SubList List<SubtitleInfo>
}
/// <summary>
/// Default Subitle track check changed
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void CheckDefaultCheckedChanged(object sender, EventArgs e)
{
if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0) return;
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"))
this.SetDefaultToOffForAllSRTTracks();
else
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;
// Update SubList List<SubtitleInfo>
}
/// <summary>
/// Srt Offset Numeric Control Changed
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void SrtOffsetValueChanged(object sender, EventArgs e)
{
// Update an item in the list if required.
if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0)
return;
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[6].Text = srt_offset.Value.ToString();
lv_subList.Select();
subList[lv_subList.SelectedIndices[0]].SrtOffset = (int)srt_offset.Value;
// Update SubList List<SubtitleInfo>
}
/// <summary>
/// The SRT Charcode changed
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void SrtCharcodeSelectedIndexChanged(object sender, EventArgs e)
{
if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0) return;
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[5].Text = srt_charcode.SelectedItem.ToString();
lv_subList.Select();
subList[lv_subList.SelectedIndices[0]].SrtCharCode = srt_charcode.SelectedItem.ToString();
// Update SubList List<SubtitleInfo>
}
/// <summary>
/// The Srt Language code changed
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void SrtLangSelectedIndexChanged(object sender, EventArgs e)
{
if (lv_subList.Items.Count == 0 || lv_subList.SelectedIndices.Count == 0) return;
lv_subList.Items[lv_subList.SelectedIndices[0]].SubItems[4].Text = srt_lang.SelectedItem.ToString();
lv_subList.Select();
subList[lv_subList.SelectedIndices[0]].SrtLang = srt_lang.SelectedItem.ToString();
// Update SubList List<SubtitleInfo>
}
#endregion
#region Right Click Menu
/// <summary>
/// Move an item in the subtitle list up
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void MnuMoveupClick(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();
}
}
}
/// <summary>
/// Move an item in the subtitle list down
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void MnuMovedownClick(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();
}
}
}
/// <summary>
/// Remove a selected subtitle track.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void MnuRemoveClick(object sender, EventArgs e)
{
this.RemoveSelectedTrack();
}
#endregion
#region Helpers
/// <summary>
/// Set all Non SRT tracks to Default = NO
/// </summary>
private void SetDefaultToOffForAllTracks()
{
int c = 0;
foreach (ListViewItem item in lv_subList.Items)
{
if (subList[c].SrtPath == "-")
{
if (item.SubItems[3].Text == "Yes")
{
item.SubItems[3].Text = "No";
subList[c].Default = false;
}
}
c++;
}
}
/// <summary>
/// Set all subtitle tracks so that they have no default.
/// </summary>
private void SetDefaultToOffForAllSRTTracks()
{
int c = 0;
foreach (ListViewItem item in lv_subList.Items)
{
if (!subList[c].IsSrtSubtitle)
{
if (item.SubItems[3].Text == "Yes")
{
item.SubItems[3].Text = "No";
subList[c].Default = false;
}
}
c++;
}
}
/// <summary>
/// Set all tracks to Burned = No
/// </summary>
private void SetBurnedToOffForAllTracks()
{
int c = 0;
foreach (ListViewItem item in lv_subList.Items)
{
if (item.SubItems[2].Text == "Yes")
{
item.SubItems[2].Text = "No";
subList[c].Burned = false;
}
c++;
}
}
/// <summary>
/// Remove a selected track
/// </summary>
private void RemoveSelectedTrack()
{
// 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];
int selectedInd = lv_subList.SelectedIndices[0];
lv_subList.Items.RemoveAt(selectedInd);
subList.RemoveAt(selectedInd);
// 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();
}
}
}
#endregion
}
}
|