101 lines
3.0 KiB
C#
101 lines
3.0 KiB
C#
using System.ComponentModel;
|
|
using System.Collections.ObjectModel;
|
|
using System.Runtime.CompilerServices;
|
|
using EmbyToolbox.Models;
|
|
|
|
namespace EmbyToolbox.ViewModels;
|
|
|
|
public sealed class AddFilesOptionsViewModel : INotifyPropertyChanged
|
|
{
|
|
private readonly Action<AddFilesOptions> _onAdd;
|
|
private readonly Action _onCancel;
|
|
|
|
private bool _disableSubtitleDefault;
|
|
private bool _removeForeignAudioAndSubtitles;
|
|
private ConversionProfilePresetRow? _selectedProfile;
|
|
|
|
public AddFilesOptionsViewModel(
|
|
IReadOnlyList<ConversionProfilePresetRow> profiles,
|
|
string selectedProfileName,
|
|
bool disableSubtitleDefault,
|
|
Action<AddFilesOptions> onAdd,
|
|
Action onCancel)
|
|
{
|
|
_onAdd = onAdd;
|
|
_onCancel = onCancel;
|
|
_disableSubtitleDefault = disableSubtitleDefault;
|
|
Profiles = new ObservableCollection<ConversionProfilePresetRow>(profiles);
|
|
_selectedProfile = Profiles.FirstOrDefault(p => p.Profile.Equals(selectedProfileName, StringComparison.OrdinalIgnoreCase))
|
|
?? Profiles.FirstOrDefault(p => p.Profile.Equals("Emby", StringComparison.OrdinalIgnoreCase))
|
|
?? Profiles.FirstOrDefault();
|
|
AddCommand = new RelayCommand(ExecuteAdd);
|
|
CancelCommand = new RelayCommand(() => _onCancel());
|
|
}
|
|
|
|
public bool DisableSubtitleDefault
|
|
{
|
|
get => _disableSubtitleDefault;
|
|
set
|
|
{
|
|
if (_disableSubtitleDefault == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_disableSubtitleDefault = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public bool RemoveForeignAudioAndSubtitles
|
|
{
|
|
get => _removeForeignAudioAndSubtitles;
|
|
set
|
|
{
|
|
if (_removeForeignAudioAndSubtitles == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_removeForeignAudioAndSubtitles = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public ObservableCollection<ConversionProfilePresetRow> Profiles { get; }
|
|
|
|
public ConversionProfilePresetRow? SelectedProfile
|
|
{
|
|
get => _selectedProfile;
|
|
set
|
|
{
|
|
if (ReferenceEquals(_selectedProfile, value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_selectedProfile = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public RelayCommand AddCommand { get; }
|
|
public RelayCommand CancelCommand { get; }
|
|
|
|
private void ExecuteAdd()
|
|
{
|
|
_onAdd(
|
|
new AddFilesOptions
|
|
{
|
|
Profile = string.IsNullOrWhiteSpace(_selectedProfile?.Profile) ? "Emby" : _selectedProfile.Profile,
|
|
DisableSubtitleDefault = _disableSubtitleDefault,
|
|
RemoveForeignAudioAndSubtitles = _removeForeignAudioAndSubtitles
|
|
});
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string? name = null) =>
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|