Files
Aaru/Aaru.Gui/ViewModels/Dialogs/SettingsViewModel.cs

290 lines
9.7 KiB
C#
Raw Normal View History

2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : SettingsViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model and code for the settings 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/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
2020-04-17 21:45:50 +01:00
// ****************************************************************************/
using System.Reactive;
2020-04-16 20:40:25 +01:00
using Aaru.Gui.Views.Dialogs;
using Aaru.Localization;
using Aaru.Settings;
2020-07-22 13:20:25 +01:00
using JetBrains.Annotations;
using ReactiveUI;
namespace Aaru.Gui.ViewModels.Dialogs;
2022-03-06 13:29:38 +00:00
public sealed class SettingsViewModel : ViewModelBase
{
2022-03-06 13:29:38 +00:00
readonly SettingsDialog _view;
bool _commandStatsChecked;
bool _deviceStatsChecked;
bool _filesystemStatsChecked;
bool _filterStatsChecked;
bool _gdprVisible;
bool _mediaImageStatsChecked;
bool _mediaScanStatsChecked;
bool _mediaStatsChecked;
bool _partitionStatsChecked;
bool _saveReportsGloballyChecked;
bool _saveStatsChecked;
bool _shareReportsChecked;
bool _shareStatsChecked;
int _tabControlSelectedIndex;
bool _verifyStatsChecked;
public SettingsViewModel(SettingsDialog view, bool gdprChange)
{
2022-03-06 13:29:38 +00:00
_view = view;
GdprVisible = gdprChange;
SaveReportsGloballyChecked = Settings.Settings.Current.SaveReportsGlobally;
ShareReportsChecked = Settings.Settings.Current.ShareReports;
if(Settings.Settings.Current.Stats != null)
2022-03-06 13:29:38 +00:00
{
SaveStatsChecked = true;
ShareStatsChecked = Settings.Settings.Current.Stats.ShareStats;
CommandStatsChecked = Settings.Settings.Current.Stats.CommandStats;
DeviceStatsChecked = Settings.Settings.Current.Stats.DeviceStats;
FilesystemStatsChecked = Settings.Settings.Current.Stats.FilesystemStats;
FilterStatsChecked = Settings.Settings.Current.Stats.FilterStats;
MediaImageStatsChecked = Settings.Settings.Current.Stats.MediaImageStats;
MediaScanStatsChecked = Settings.Settings.Current.Stats.MediaScanStats;
PartitionStatsChecked = Settings.Settings.Current.Stats.PartitionStats;
MediaStatsChecked = Settings.Settings.Current.Stats.MediaStats;
VerifyStatsChecked = Settings.Settings.Current.Stats.VerifyStats;
}
2022-03-06 13:29:38 +00:00
else
SaveStatsChecked = false;
CancelCommand = ReactiveCommand.Create(ExecuteCancelCommand);
SaveCommand = ReactiveCommand.Create(ExecuteSaveCommand);
2024-05-01 04:05:22 +01:00
if(!_gdprVisible) _tabControlSelectedIndex = 1;
2022-03-06 13:29:38 +00:00
}
// TODO: Show Preferences in macOS
[NotNull]
public string Title => UI.Title_Settings;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string GdprLabel => UI.Title_GDPR;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string ReportsLabel => UI.Title_Reports;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string StatisticsLabel => UI.Title_Statistics;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string SaveLabel => UI.ButtonLabel_Save;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string CancelLabel => UI.ButtonLabel_Cancel;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string GdprText1 => UI.GDPR_Compliance;
2022-03-06 13:29:38 +00:00
[NotNull]
public string GdprText2 => UI.GDPR_Open_Source_Disclaimer;
2022-03-06 13:29:38 +00:00
[NotNull]
public string GdprText3 => UI.GDPR_Information_sharing;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string ReportsGloballyText => UI.Configure_Device_Report_information_disclaimer;
2022-03-06 13:29:38 +00:00
[NotNull]
public string SaveReportsGloballyText => UI.Save_device_reports_in_shared_folder_of_your_computer_Q;
2022-03-06 13:29:38 +00:00
[NotNull]
public string ReportsText => UI.Configure_share_report_disclaimer;
2022-03-06 13:29:38 +00:00
[NotNull]
public string ShareReportsText => UI.Share_your_device_reports_with_us_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string StatisticsText => UI.Statistics_disclaimer;
2022-03-06 13:29:38 +00:00
[NotNull]
public string SaveStatsText => UI.Save_stats_about_your_Aaru_usage_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string ShareStatsText => UI.Share_your_stats_anonymously_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string CommandStatsText => UI.Gather_statistics_about_command_usage_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string DeviceStatsText => UI.Gather_statistics_about_found_devices_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string FilesystemStatsText => UI.Gather_statistics_about_found_filesystems_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string FilterStatsText => UI.Gather_statistics_about_found_file_filters_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string MediaImageStatsText => UI.Gather_statistics_about_found_media_image_formats_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string MediaScanStatsText => UI.Gather_statistics_about_scanned_media_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string PartitionStatsText => UI.Gather_statistics_about_found_partitioning_schemes_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string MediaStatsText => UI.Gather_statistics_about_media_types_Q;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string VerifyStatsText => UI.Gather_statistics_about_media_image_verifications_Q;
2022-03-06 13:29:38 +00:00
public ReactiveCommand<Unit, Unit> CancelCommand { get; }
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
public bool GdprVisible
{
get => _gdprVisible;
set => this.RaiseAndSetIfChanged(ref _gdprVisible, value);
}
2022-03-06 13:29:38 +00:00
public bool SaveReportsGloballyChecked
{
get => _saveReportsGloballyChecked;
set => this.RaiseAndSetIfChanged(ref _saveReportsGloballyChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool ShareReportsChecked
{
get => _shareReportsChecked;
set => this.RaiseAndSetIfChanged(ref _shareReportsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool SaveStatsChecked
{
get => _saveStatsChecked;
set => this.RaiseAndSetIfChanged(ref _saveStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool ShareStatsChecked
{
get => _shareStatsChecked;
set => this.RaiseAndSetIfChanged(ref _shareStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool CommandStatsChecked
{
get => _commandStatsChecked;
set => this.RaiseAndSetIfChanged(ref _commandStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool DeviceStatsChecked
{
get => _deviceStatsChecked;
set => this.RaiseAndSetIfChanged(ref _deviceStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool FilesystemStatsChecked
{
get => _filesystemStatsChecked;
set => this.RaiseAndSetIfChanged(ref _filesystemStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool FilterStatsChecked
{
get => _filterStatsChecked;
set => this.RaiseAndSetIfChanged(ref _filterStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool MediaImageStatsChecked
{
get => _mediaImageStatsChecked;
set => this.RaiseAndSetIfChanged(ref _mediaImageStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool MediaScanStatsChecked
{
get => _mediaScanStatsChecked;
set => this.RaiseAndSetIfChanged(ref _mediaScanStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool PartitionStatsChecked
{
get => _partitionStatsChecked;
set => this.RaiseAndSetIfChanged(ref _partitionStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool MediaStatsChecked
{
get => _mediaStatsChecked;
set => this.RaiseAndSetIfChanged(ref _mediaStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public bool VerifyStatsChecked
{
get => _verifyStatsChecked;
set => this.RaiseAndSetIfChanged(ref _verifyStatsChecked, value);
}
2022-03-06 13:29:38 +00:00
public int TabControlSelectedIndex
{
get => _tabControlSelectedIndex;
set => this.RaiseAndSetIfChanged(ref _tabControlSelectedIndex, value);
}
2022-03-06 13:29:38 +00:00
void ExecuteSaveCommand()
{
Settings.Settings.Current.SaveReportsGlobally = SaveReportsGloballyChecked;
Settings.Settings.Current.ShareReports = ShareReportsChecked;
2022-03-06 13:29:38 +00:00
if(SaveStatsChecked)
2023-10-03 23:27:57 +01:00
{
Settings.Settings.Current.Stats = new StatsSettings
2022-03-06 13:29:38 +00:00
{
ShareStats = ShareStatsChecked,
CommandStats = CommandStatsChecked,
DeviceStats = DeviceStatsChecked,
FilesystemStats = FilesystemStatsChecked,
FilterStats = FilterStatsChecked,
MediaImageStats = MediaImageStatsChecked,
MediaScanStats = MediaScanStatsChecked,
PartitionStats = PartitionStatsChecked,
MediaStats = MediaStatsChecked,
VerifyStats = VerifyStatsChecked
};
2023-10-03 23:27:57 +01:00
}
2022-03-06 13:29:38 +00:00
else
Settings.Settings.Current.Stats = null;
2022-03-06 13:29:38 +00:00
Settings.Settings.Current.GdprCompliance = DicSettings.GDPR_LEVEL;
Settings.Settings.SaveSettings();
2022-03-06 13:29:38 +00:00
_view.Close();
}
2022-03-06 13:29:38 +00:00
void ExecuteCancelCommand() => _view.Close();
}