2017-10-02 18:40:54 +02:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
using ModernKeePass.Mappings;
|
2017-09-26 15:38:58 +02:00
|
|
|
|
using ModernKeePassLib;
|
|
|
|
|
using ModernKeePassLib.Security;
|
2017-09-29 17:23:35 -04:00
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
using Windows.UI;
|
2017-10-02 18:40:54 +02:00
|
|
|
|
using Windows.UI.Text;
|
|
|
|
|
using Windows.UI.Xaml;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-09-29 17:23:35 -04:00
|
|
|
|
public class EntryVm
|
2017-09-12 18:20:32 +02:00
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public GroupVm ParentGroup { get; }
|
|
|
|
|
public PwEntry Entry => _pwEntry;
|
2017-09-26 14:32:15 +02:00
|
|
|
|
public string Title
|
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var title = GetEntryValue(PwDefs.TitleField);
|
|
|
|
|
return title == null ? "New entry" : title;
|
|
|
|
|
}
|
2017-09-26 14:32:15 +02:00
|
|
|
|
set { SetEntryValue(PwDefs.TitleField, value); }
|
|
|
|
|
}
|
|
|
|
|
public string UserName
|
|
|
|
|
{
|
|
|
|
|
get { return GetEntryValue(PwDefs.UserNameField); }
|
|
|
|
|
set { SetEntryValue(PwDefs.UserNameField, value); }
|
|
|
|
|
}
|
|
|
|
|
public string Password
|
|
|
|
|
{
|
|
|
|
|
get { return GetEntryValue(PwDefs.PasswordField); }
|
|
|
|
|
set { SetEntryValue(PwDefs.PasswordField, value); }
|
|
|
|
|
}
|
|
|
|
|
public string Url
|
|
|
|
|
{
|
|
|
|
|
get { return GetEntryValue(PwDefs.UrlField); }
|
|
|
|
|
set { SetEntryValue(PwDefs.UrlField, value); }
|
|
|
|
|
}
|
|
|
|
|
public string Notes
|
|
|
|
|
{
|
|
|
|
|
get { return GetEntryValue(PwDefs.NotesField); }
|
|
|
|
|
set { SetEntryValue(PwDefs.NotesField, value); }
|
|
|
|
|
}
|
2017-10-03 16:06:49 +02:00
|
|
|
|
public System.Drawing.Color? BackgroundColor => _pwEntry?.BackgroundColor;
|
2017-09-26 14:32:15 +02:00
|
|
|
|
|
2017-10-03 16:06:49 +02:00
|
|
|
|
public System.Drawing.Color? ForegroundColor => _pwEntry?.ForegroundColor;
|
|
|
|
|
|
2017-09-29 18:08:20 +02:00
|
|
|
|
public Symbol IconSymbol
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
if (_pwEntry == null) return Symbol.Add;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwEntry.IconId);
|
|
|
|
|
return result == Symbol.More ? Symbol.Permissions : result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 17:23:35 -04:00
|
|
|
|
|
2017-09-26 14:32:15 +02:00
|
|
|
|
private readonly PwEntry _pwEntry;
|
2017-09-13 18:37:44 +02:00
|
|
|
|
|
2017-09-14 18:33:29 +02:00
|
|
|
|
public EntryVm() { }
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public EntryVm(PwEntry entry, GroupVm parent)
|
2017-09-13 18:37:44 +02:00
|
|
|
|
{
|
2017-09-26 14:32:15 +02:00
|
|
|
|
_pwEntry = entry;
|
2017-10-02 18:40:54 +02:00
|
|
|
|
ParentGroup = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveEntry()
|
|
|
|
|
{
|
|
|
|
|
ParentGroup.RemoveEntry(this);
|
2017-09-13 18:37:44 +02:00
|
|
|
|
}
|
2017-09-15 11:24:14 +02:00
|
|
|
|
|
2017-09-26 14:32:15 +02:00
|
|
|
|
private string GetEntryValue(string key)
|
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
return _pwEntry?.Strings.GetSafe(key).ReadString();
|
2017-09-26 14:32:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetEntryValue(string key, string newValue)
|
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
_pwEntry?.Strings.Set(key, new ProtectedString(true, newValue));
|
2017-09-26 14:32:15 +02:00
|
|
|
|
}
|
2017-09-12 18:20:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|