2020-04-17 21:45:50 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : EncodingsViewModel.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : GUI view models.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// View model and code for the encodings list dialog.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2020-04-17 21:45:50 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2020-04-10 02:50:38 +01:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reactive;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Aaru.Gui.Models;
|
2020-04-16 20:40:25 +01:00
|
|
|
|
using Aaru.Gui.Views.Dialogs;
|
2022-11-19 21:10:41 +00:00
|
|
|
|
using Aaru.Localization;
|
2020-07-22 13:20:25 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2020-04-10 02:50:38 +01:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Gui.ViewModels.Dialogs;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
public sealed class EncodingsViewModel : ViewModelBase
|
2020-04-10 02:50:38 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
readonly Encodings _view;
|
|
|
|
|
|
|
|
|
|
|
|
public EncodingsViewModel(Encodings view)
|
2020-04-10 02:50:38 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_view = view;
|
|
|
|
|
|
Encodings = new ObservableCollection<EncodingModel>();
|
|
|
|
|
|
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
2020-04-10 02:50:38 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Task.Run(() =>
|
2020-04-10 02:50:38 +01:00
|
|
|
|
{
|
2023-10-04 17:34:40 +01:00
|
|
|
|
var encodings = Encoding.GetEncodings().
|
|
|
|
|
|
Select(info => new EncodingModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = info.Name,
|
|
|
|
|
|
DisplayName = info.GetEncoding().EncodingName
|
|
|
|
|
|
}).
|
|
|
|
|
|
ToList();
|
2020-04-10 02:50:38 +01:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
encodings.AddRange(Claunia.Encoding.Encoding.GetEncodings().
|
|
|
|
|
|
Select(info => new EncodingModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = info.Name,
|
|
|
|
|
|
DisplayName = info.DisplayName
|
|
|
|
|
|
}));
|
2020-04-10 02:50:38 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
foreach(EncodingModel encoding in encodings.OrderBy(t => t.DisplayName))
|
|
|
|
|
|
Encodings.Add(encoding);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2020-04-10 02:50:38 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string Title => UI.Encodings;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string CloseLabel => UI.ButtonLabel_Close;
|
2022-11-16 21:40:54 +00:00
|
|
|
|
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string CodeLabel => UI.Title_Code_for_encoding;
|
|
|
|
|
|
public string NameLabel => UI.Title_Name;
|
2022-11-16 21:40:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
|
|
|
|
|
public ObservableCollection<EncodingModel> Encodings { get; }
|
2020-04-10 02:50:38 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
void ExecuteCloseCommand() => _view.Close();
|
2020-04-10 02:50:38 +01:00
|
|
|
|
}
|