2020-04-06 20:20:45 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Windows.UI;
|
2020-04-30 11:10:10 +02:00
|
|
|
|
using GalaSoft.MvvmLight;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using ModernKeePass.Domain.Entities;
|
|
|
|
|
using ModernKeePass.Domain.Enums;
|
|
|
|
|
using ModernKeePass.Domain.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels.ListItems
|
|
|
|
|
{
|
2020-04-30 11:10:10 +02:00
|
|
|
|
public class EntryItemVm : ObservableObject
|
2020-04-06 20:20:45 +02:00
|
|
|
|
{
|
|
|
|
|
public EntryEntity EntryEntity { get; }
|
2020-04-29 16:39:20 +02:00
|
|
|
|
public GroupItemVm Parent { get; }
|
2020-04-06 20:20:45 +02:00
|
|
|
|
|
|
|
|
|
public bool HasExpired => HasExpirationDate && EntryEntity.ExpirationDate < DateTime.Now;
|
|
|
|
|
|
|
|
|
|
public bool HasUrl => !string.IsNullOrEmpty(Url);
|
|
|
|
|
|
|
|
|
|
public double PasswordComplexityIndicator => _securityService.EstimatePasswordComplexity(Password);
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.Name;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
EntryEntity.Name = value;
|
|
|
|
|
OnPropertyChanged(nameof(Name));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string UserName
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.UserName;
|
|
|
|
|
set => EntryEntity.UserName = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Password
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.Password;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
EntryEntity.Password = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Url
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.Url?.ToString();
|
|
|
|
|
set => EntryEntity.Url = new Uri(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Notes
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.Notes;
|
|
|
|
|
set => EntryEntity.Notes = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Icon Icon
|
|
|
|
|
{
|
|
|
|
|
get => HasExpired ? Icon.Important : EntryEntity.Icon;
|
|
|
|
|
set => EntryEntity.Icon = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTimeOffset ExpiryDate
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.ExpirationDate;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!HasExpirationDate) return;
|
|
|
|
|
EntryEntity.ExpirationDate = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TimeSpan ExpiryTime
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.ExpirationDate.TimeOfDay;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!HasExpirationDate) return;
|
|
|
|
|
EntryEntity.ExpirationDate = EntryEntity.ExpirationDate.Date.Add(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasExpirationDate
|
|
|
|
|
{
|
|
|
|
|
get => EntryEntity.HasExpirationDate;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
EntryEntity.HasExpirationDate = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color BackgroundColor
|
|
|
|
|
{
|
|
|
|
|
get => Color.FromArgb(EntryEntity.BackgroundColor.A, EntryEntity.BackgroundColor.R, EntryEntity.BackgroundColor.G, EntryEntity.BackgroundColor.B);
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
EntryEntity.BackgroundColor = System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color ForegroundColor
|
|
|
|
|
{
|
|
|
|
|
get => Color.FromArgb(EntryEntity.ForegroundColor.A, EntryEntity.ForegroundColor.R, EntryEntity.ForegroundColor.G, EntryEntity.ForegroundColor.B);
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
EntryEntity.ForegroundColor = System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 16:39:20 +02:00
|
|
|
|
public IEnumerable<EntryItemVm> History
|
2020-04-06 20:20:45 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-04-29 16:39:20 +02:00
|
|
|
|
var history = new Stack<EntryItemVm>();
|
2020-04-06 20:20:45 +02:00
|
|
|
|
foreach (var historyEntry in EntryEntity.History)
|
|
|
|
|
{
|
2020-04-29 16:39:20 +02:00
|
|
|
|
history.Push(new EntryItemVm(_securityService, historyEntry, Parent));
|
2020-04-06 20:20:45 +02:00
|
|
|
|
}
|
|
|
|
|
history.Push(this);
|
|
|
|
|
|
|
|
|
|
return history;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public Dictionary<string, string> AdditionalFields => EntryEntity.AdditionalFields;
|
|
|
|
|
|
2020-04-29 16:39:20 +02:00
|
|
|
|
public EntryItemVm(EntryEntity entryEntity, GroupItemVm parentGroup): this(App.Container.Resolve<ISecurityService>(), entryEntity, parentGroup)
|
2020-04-06 20:20:45 +02:00
|
|
|
|
{ }
|
|
|
|
|
|
2020-04-29 16:39:20 +02:00
|
|
|
|
public EntryItemVm(ISecurityService securityService, EntryEntity entryEntity, GroupItemVm parentGroup)
|
2020-04-06 20:20:45 +02:00
|
|
|
|
{
|
|
|
|
|
_securityService = securityService;
|
|
|
|
|
EntryEntity = entryEntity;
|
|
|
|
|
Parent = parentGroup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() => EntryEntity.LastModificationDate.ToString("g");
|
|
|
|
|
}
|
|
|
|
|
}
|