// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // The Subtitles View Model // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.ViewModels { using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel.Composition; using System.Linq; using Caliburn.Micro; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services.Interfaces; using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.ViewModels.Interfaces; using Ookii.Dialogs.Wpf; /// /// The Subtitles View Model /// [Export(typeof(ISubtitlesViewModel))] public class SubtitlesViewModel : ViewModelBase, ISubtitlesViewModel { #region Constants and Fields /// /// The subtitle tracks. /// private ObservableCollection subtitleTracks; /// /// Backing field for the source subtitle tracks. /// private IEnumerable sourceTracks; #endregion #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// The window manager. /// /// /// The user Setting Service. /// public SubtitlesViewModel(IWindowManager windowManager, IUserSettingService userSettingService) { this.SubtitleTracks = new ObservableCollection(); Langauges = LanguageUtilities.MapLanguages().Keys; CharacterCodes = CharCodesUtilities.GetCharacterCodes(); } #endregion #region Public Properties /// /// Gets or sets State. /// public ObservableCollection SubtitleTracks { get { return this.subtitleTracks; } set { this.subtitleTracks = value; this.NotifyOfPropertyChange(() => this.SubtitleTracks); } } /// /// Gets or sets Langauges. /// public IEnumerable Langauges { get; set; } /// /// Gets or sets CharacterCodes. /// public IEnumerable CharacterCodes { get; set; } /// /// Gets or sets SourceTracks. /// public IEnumerable SourceTracks { get { return this.sourceTracks; } set { this.sourceTracks = value; this.NotifyOfPropertyChange(() => SourceTracks); } } #endregion #region Public Methods /// /// Add a new Track /// public void Add() { if (this.SourceTracks != null) { Subtitle source = this.SourceTracks.FirstOrDefault(); if (source != null) { SubtitleTrack track = new SubtitleTrack { SubtitleType = SubtitleType.VobSub }; this.SubtitleTracks.Add(track); } } } /// /// Import an SRT File. /// public void Import() { VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "SRT files (*.srt)|*.srt", CheckFileExists = true, Multiselect = true }; dialog.ShowDialog(); foreach (var srtFile in dialog.FileNames) { SubtitleTrack track = new SubtitleTrack { SrtFileName = srtFile, SrtOffset = 0, SrtCharCode = "UTF-8", SrtLang = "English", SubtitleType = SubtitleType.SRT }; this.SubtitleTracks.Add(track); } } /// /// Remove a Track /// /// /// The track. /// public void Remove(SubtitleTrack track) { this.SubtitleTracks.Remove(track); } /// /// Setup this window for a new source /// /// /// The title. /// /// /// The preset. /// /// /// The task. /// public void SetSource(Title title, Preset preset, EncodeTask task) { this.SourceTracks = title.Subtitles; this.SubtitleTracks = task.SubtitleTracks; } #endregion } }