blob: 3e842da1944b576d9278541c6e06b6126da17e06 (
plain)
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
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SubtitlesDefaultsViewModel.cs" company="HandBrake Project (http://handbrake.fr)">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// The Subtitles Defaults View Model
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using HandBrake.Interop.Utilities;
using HandBrakeWPF.Model.Subtitles;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Presets.Model;
using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
/// <summary>
/// The Subtitles View Model
/// </summary>
public class SubtitlesDefaultsViewModel : ViewModelBase, ISubtitlesDefaultsViewModel
{
#region Constants and Fields
private SubtitleBehaviours subtitleBehaviours;
private BindingList<string> availableLanguages;
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="SubtitlesDefaultsViewModel"/> class.
/// </summary>
public SubtitlesDefaultsViewModel()
{
this.Langauges = LanguageUtilities.MapLanguages().Keys;
this.CharacterCodes = CharCodesUtilities.GetCharacterCodes();
this.SubtitleBehaviours = new SubtitleBehaviours();
this.SelectedAvailableToMove = new BindingList<string>();
this.SelectedLangaugesToMove = new BindingList<string>();
this.availableLanguages = new BindingList<string>();
this.SetupLanguages((Preset)null);
this.Title = Resources.SubtitlesViewModel_SubDefaults;
}
#endregion
#region Properties
public bool IsApplied { get; set; }
/// <summary>
/// Gets CharacterCodes.
/// </summary>
public IEnumerable<string> CharacterCodes { get; private set; }
/// <summary>
/// Gets Langauges.
/// </summary>
public IEnumerable<string> Langauges { get; private set; }
/// <summary>
/// Gets or sets the subtitle behaviours.
/// </summary>
public SubtitleBehaviours SubtitleBehaviours
{
get
{
return this.subtitleBehaviours;
}
set
{
if (Equals(value, this.subtitleBehaviours))
{
return;
}
this.subtitleBehaviours = value;
this.NotifyOfPropertyChange(() => this.SubtitleBehaviours);
}
}
/// <summary>
/// Gets the sbutitle behaviour modes.
/// </summary>
public BindingList<SubtitleBehaviourModes> SubtitleBehaviourModeList
{
get
{
return new BindingList<SubtitleBehaviourModes>(EnumHelper<SubtitleBehaviourModes>.GetEnumList().ToList());
}
}
/// <summary>
/// Gets the subtitle burn in behaviour mode list.
/// </summary>
public BindingList<SubtitleBurnInBehaviourModes> SubtitleBurnInBehaviourModeList
{
get
{
return new BindingList<SubtitleBurnInBehaviourModes>(EnumHelper<SubtitleBurnInBehaviourModes>.GetEnumList().ToList());
}
}
/// <summary>
/// Gets AvailableLanguages.
/// </summary>
public BindingList<string> AvailableLanguages
{
get
{
return this.availableLanguages;
}
private set
{
this.availableLanguages = value;
this.NotifyOfPropertyChange("AvailableLanguages");
}
}
/// <summary>
/// Gets SelectedLangauges.
/// </summary>
public BindingList<string> SelectedAvailableToMove { get; private set; }
/// <summary>
/// Gets SelectedLangauges.
/// </summary>
public BindingList<string> SelectedLangaugesToMove { get; private set; }
#endregion
#region Public Methods
/// <summary>
/// Audio List Move Left
/// </summary>
public void LanguageMoveRight()
{
if (this.SelectedAvailableToMove.Count > 0)
{
List<string> copiedList = SelectedAvailableToMove.ToList();
foreach (string item in copiedList)
{
this.AvailableLanguages.Remove(item);
this.SubtitleBehaviours.SelectedLangauges.Add(item);
}
this.AvailableLanguages = new BindingList<string>(this.AvailableLanguages.OrderBy(o => o).ToList());
}
}
/// <summary>
/// Audio List Move Right
/// </summary>
public void LanguageMoveLeft()
{
if (this.SelectedLangaugesToMove.Count > 0)
{
List<string> copiedList = SelectedLangaugesToMove.ToList();
foreach (string item in copiedList)
{
this.SubtitleBehaviours.SelectedLangauges.Remove(item);
this.AvailableLanguages.Add(item);
}
}
this.AvailableLanguages = new BindingList<string>(this.AvailableLanguages.OrderBy(o => o).ToList());
}
/// <summary>
/// Language List Clear all selected languages
/// </summary>
public void LanguageClearAll()
{
foreach (string item in this.SubtitleBehaviours.SelectedLangauges)
{
this.AvailableLanguages.Add(item);
}
this.AvailableLanguages = new BindingList<string>(this.AvailableLanguages.OrderBy(o => o).ToList());
this.SubtitleBehaviours.SelectedLangauges.Clear();
}
public void LaunchHelp()
{
Process.Start("https://handbrake.fr/docs/en/latest/advanced/audio-subtitle-defaults.html");
}
#endregion
#region Methods
/// <summary>
/// The setup languages.
/// </summary>
/// <param name="preset">
/// The preset.
/// </param>
public void SetupLanguages(Preset preset)
{
if (preset != null)
{
this.SetupLanguages(preset.SubtitleTrackBehaviours);
}
}
public void ResetApplied()
{
this.IsApplied = false;
}
/// <summary>
/// The setup languages.
/// </summary>
/// <param name="behaviours">
/// The behaviours.
/// </param>
public void SetupLanguages(SubtitleBehaviours behaviours)
{
// Reset
this.IsApplied = false;
// Step 1, Set the behaviour mode
this.SubtitleBehaviours.SelectedBehaviour = SubtitleBehaviourModes.None;
this.SubtitleBehaviours.SelectedBurnInBehaviour = SubtitleBurnInBehaviourModes.None;
this.SubtitleBehaviours.AddClosedCaptions = false;
this.SubtitleBehaviours.AddForeignAudioScanTrack = false;
this.SubtitleBehaviours.SelectedLangauges.Clear();
// Step 2, Get all the languages
IDictionary<string, string> langList = LanguageUtilities.MapLanguages();
langList = (from entry in langList orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
// Step 3, Setup Available Languages
this.AvailableLanguages.Clear();
foreach (string item in langList.Keys)
{
this.AvailableLanguages.Add(item);
}
// Step 4, Set the Selected Languages
if (behaviours != null)
{
this.SubtitleBehaviours.SelectedBehaviour = behaviours.SelectedBehaviour;
this.SubtitleBehaviours.SelectedBurnInBehaviour = behaviours.SelectedBurnInBehaviour;
this.SubtitleBehaviours.AddClosedCaptions = behaviours.AddClosedCaptions;
this.SubtitleBehaviours.AddForeignAudioScanTrack = behaviours.AddForeignAudioScanTrack;
foreach (string selectedItem in behaviours.SelectedLangauges)
{
this.AvailableLanguages.Remove(selectedItem);
this.SubtitleBehaviours.SelectedLangauges.Add(selectedItem);
}
}
}
#endregion
}
}
|