mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Updated Settings page
Added new settings (history and clipboard) Renamed and moved Settings Vms
This commit is contained in:
37
WinAppCommon/ViewModels/Settings/CredentialsVm.cs
Normal file
37
WinAppCommon/ViewModels/Settings/CredentialsVm.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class CredentialsVm: ViewModelBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly INotificationService _notification;
|
||||
|
||||
public CredentialsVm(IMediator mediator, IResourceProxy resource, INotificationService notification)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_resource = resource;
|
||||
_notification = notification;
|
||||
|
||||
MessengerInstance.Register<CredentialsSetMessage>(this, async message => await UpdateDatabaseCredentials(message));
|
||||
}
|
||||
|
||||
public async Task UpdateDatabaseCredentials(CredentialsSetMessage message)
|
||||
{
|
||||
await _mediator.Send(new UpdateCredentialsCommand
|
||||
{
|
||||
KeyFilePath = message.KeyFilePath,
|
||||
Password = message.Password
|
||||
});
|
||||
var database = await _mediator.Send(new GetDatabaseQuery());
|
||||
_notification.Show(database.Name, _resource.GetResourceValue("CompositeKeyUpdated"));
|
||||
}
|
||||
}
|
||||
}
|
28
WinAppCommon/ViewModels/Settings/GeneralVm.cs
Normal file
28
WinAppCommon/ViewModels/Settings/GeneralVm.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class GeneralVm
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public bool IsSaveSuspend
|
||||
{
|
||||
get { return _settings.GetSetting(Constants.Settings.SaveSuspend, true); }
|
||||
set { _settings.PutSetting(Constants.Settings.SaveSuspend, value); }
|
||||
}
|
||||
|
||||
public int CopyExpiration
|
||||
{
|
||||
get { return _settings.GetSetting(Constants.Settings.ClipboardTimeout, 10); }
|
||||
set { _settings.PutSetting(Constants.Settings.ClipboardTimeout, value); }
|
||||
}
|
||||
|
||||
public GeneralVm(ISettingsProxy settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
32
WinAppCommon/ViewModels/Settings/HistoryVm.cs
Normal file
32
WinAppCommon/ViewModels/Settings/HistoryVm.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetMaxHistoryCount;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetMaxHistorySize;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class HistoryVm
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
|
||||
public int MaxCount
|
||||
{
|
||||
get { return _database.MaxHistoryCount; }
|
||||
set { _mediator.Send(new SetMaxHistoryCountCommand { MaxHistoryCount = value }).Wait(); }
|
||||
}
|
||||
|
||||
public long MaxSize
|
||||
{
|
||||
get { return _database.MaxHistorySize / 1024 / 1024; }
|
||||
set { _mediator.Send(new SetMaxHistorySizeCommand { MaxHistorySize = value * 1024 * 1024 }).Wait(); }
|
||||
}
|
||||
|
||||
public HistoryVm(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
57
WinAppCommon/ViewModels/Settings/RecycleBinVm.cs
Normal file
57
WinAppCommon/ViewModels/Settings/RecycleBinVm.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetHasRecycleBin;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetRecycleBin;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class RecycleBinVm: ObservableObject
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
|
||||
public bool HasRecycleBin
|
||||
{
|
||||
get { return _database.IsRecycleBinEnabled; }
|
||||
set
|
||||
{
|
||||
_mediator.Send(new SetHasRecycleBinCommand { HasRecycleBin = value }).Wait();
|
||||
RaisePropertyChanged(nameof(HasRecycleBin));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNewRecycleBin
|
||||
{
|
||||
get { return string.IsNullOrEmpty(_database.RecycleBinId); }
|
||||
set
|
||||
{
|
||||
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = null }).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<IEntityVm> Groups { get; }
|
||||
|
||||
public IEntityVm SelectedRecycleBin
|
||||
{
|
||||
get { return Groups.FirstOrDefault(g => g.Id == _database.RecycleBinId); }
|
||||
set
|
||||
{
|
||||
if (!IsNewRecycleBin) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = value.Id }).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public RecycleBinVm(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
|
||||
Groups = new ObservableCollection<IEntityVm>(rootGroup.SubGroups);
|
||||
}
|
||||
}
|
||||
}
|
56
WinAppCommon/ViewModels/Settings/SecurityVm.cs
Normal file
56
WinAppCommon/ViewModels/Settings/SecurityVm.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetCipher;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetCompression;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetKeyDerivation;
|
||||
using ModernKeePass.Application.Parameters.Models;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetCiphers;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetCompressions;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
// TODO: implement Kdf settings
|
||||
public class SecurityVm: ObservableObject
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
|
||||
public ObservableCollection<CipherVm> Ciphers { get; }
|
||||
public IEnumerable<string> Compressions => _mediator.Send(new GetCompressionsQuery()).GetAwaiter().GetResult();
|
||||
public ObservableCollection<KeyDerivationVm> KeyDerivations { get; }
|
||||
|
||||
public CipherVm SelectedCipher
|
||||
{
|
||||
get { return Ciphers.FirstOrDefault(c => c.Id == _database.CipherId); }
|
||||
set { _mediator.Send(new SetCipherCommand {CipherId = value.Id}).Wait(); }
|
||||
}
|
||||
|
||||
public string SelectedCompression
|
||||
{
|
||||
get { return Compressions.FirstOrDefault(c => c == _database.Compression); }
|
||||
set { _mediator.Send(new SetCompressionCommand {Compression = value}).Wait(); }
|
||||
}
|
||||
|
||||
public KeyDerivationVm SelectedKeyDerivation
|
||||
{
|
||||
get { return KeyDerivations.FirstOrDefault(c => c.Id == _database.KeyDerivationId); }
|
||||
set { _mediator.Send(new SetKeyDerivationCommand {KeyDerivationId = value.Id}).Wait(); }
|
||||
}
|
||||
|
||||
public SecurityVm(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
var ciphers = _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult();
|
||||
Ciphers = new ObservableCollection<CipherVm>(ciphers);
|
||||
var keyDerivations = _mediator.Send(new GetKeyDerivationsQuery()).GetAwaiter().GetResult();
|
||||
KeyDerivations = new ObservableCollection<KeyDerivationVm>(keyDerivations);
|
||||
}
|
||||
}
|
||||
}
|
37
WinAppCommon/ViewModels/Settings/SettingsCredentialsVm.cs
Normal file
37
WinAppCommon/ViewModels/Settings/SettingsCredentialsVm.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class SettingsCredentialsVm: ViewModelBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly INotificationService _notification;
|
||||
|
||||
public SettingsCredentialsVm(IMediator mediator, IResourceProxy resource, INotificationService notification)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_resource = resource;
|
||||
_notification = notification;
|
||||
|
||||
MessengerInstance.Register<CredentialsSetMessage>(this, async message => await UpdateDatabaseCredentials(message));
|
||||
}
|
||||
|
||||
public async Task UpdateDatabaseCredentials(CredentialsSetMessage message)
|
||||
{
|
||||
await _mediator.Send(new UpdateCredentialsCommand
|
||||
{
|
||||
KeyFilePath = message.KeyFilePath,
|
||||
Password = message.Password
|
||||
});
|
||||
var database = await _mediator.Send(new GetDatabaseQuery());
|
||||
_notification.Show(database.Name, _resource.GetResourceValue("CompositeKeyUpdated"));
|
||||
}
|
||||
}
|
||||
}
|
7
WinAppCommon/ViewModels/Settings/SettingsHistoryVm.cs
Normal file
7
WinAppCommon/ViewModels/Settings/SettingsHistoryVm.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class SettingsHistoryVm
|
||||
{
|
||||
|
||||
}
|
||||
}
|
53
WinAppCommon/ViewModels/Settings/SettingsNewVm.cs
Normal file
53
WinAppCommon/ViewModels/Settings/SettingsNewVm.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class SettingsNewVm
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsNewVm(ISettingsProxy settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public bool IsCreateSample
|
||||
{
|
||||
get { return _settings.GetSetting(Constants.Settings.Sample, true); }
|
||||
set { _settings.PutSetting(Constants.Settings.Sample, value); }
|
||||
}
|
||||
|
||||
public IEnumerable<DatabaseFormat> FileFormats => new []
|
||||
{
|
||||
new DatabaseFormat
|
||||
{
|
||||
Version = "4",
|
||||
DisplayText = "4 (Argon2, ChaCha20)"
|
||||
},
|
||||
new DatabaseFormat
|
||||
{
|
||||
Version = "3",
|
||||
DisplayText = "3 (AES-KDF, AES/Rijndael)"
|
||||
}
|
||||
};
|
||||
|
||||
public DatabaseFormat DatabaseFormatVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
var version = _settings.GetSetting(Constants.Settings.DefaultFileFormat, "4");
|
||||
return FileFormats.FirstOrDefault(f => f.Version == version);
|
||||
}
|
||||
set { _settings.PutSetting(Constants.Settings.DefaultFileFormat, value.Version); }
|
||||
}
|
||||
}
|
||||
|
||||
public class DatabaseFormat
|
||||
{
|
||||
public string Version { get; set; }
|
||||
public string DisplayText { get; set; }
|
||||
}
|
||||
}
|
57
WinAppCommon/ViewModels/Settings/SettingsRecycleBinVm.cs
Normal file
57
WinAppCommon/ViewModels/Settings/SettingsRecycleBinVm.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetHasRecycleBin;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetRecycleBin;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class SettingsRecycleBinVm: ObservableObject
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
|
||||
public bool HasRecycleBin
|
||||
{
|
||||
get { return _database.IsRecycleBinEnabled; }
|
||||
set
|
||||
{
|
||||
_mediator.Send(new SetHasRecycleBinCommand { HasRecycleBin = value }).Wait();
|
||||
RaisePropertyChanged(nameof(HasRecycleBin));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNewRecycleBin
|
||||
{
|
||||
get { return string.IsNullOrEmpty(_database.RecycleBinId); }
|
||||
set
|
||||
{
|
||||
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = null }).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<IEntityVm> Groups { get; }
|
||||
|
||||
public IEntityVm SelectedRecycleBin
|
||||
{
|
||||
get { return Groups.FirstOrDefault(g => g.Id == _database.RecycleBinId); }
|
||||
set
|
||||
{
|
||||
if (!IsNewRecycleBin) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = value.Id }).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsRecycleBinVm(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
|
||||
Groups = new ObservableCollection<IEntityVm>(rootGroup.SubGroups);
|
||||
}
|
||||
}
|
||||
}
|
21
WinAppCommon/ViewModels/Settings/SettingsSaveVm.cs
Normal file
21
WinAppCommon/ViewModels/Settings/SettingsSaveVm.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels.Settings
|
||||
{
|
||||
public class SettingsSaveVm
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsSaveVm(ISettingsProxy settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public bool IsSaveSuspend
|
||||
{
|
||||
get { return _settings.GetSetting(Constants.Settings.SaveSuspend, true); }
|
||||
set { _settings.PutSetting(Constants.Settings.SaveSuspend, value); }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user