Skip to content

Commit

Permalink
little style refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallimathias committed Feb 28, 2018
1 parent 736b92f commit 3c57b20
Show file tree
Hide file tree
Showing 11 changed files with 742 additions and 809 deletions.
4 changes: 2 additions & 2 deletions KeePassHttp/AccessControlForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 59 additions & 48 deletions KeePassHttp/AccessControlForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,78 +13,89 @@ namespace KeePassHttp
{
public partial class AccessControlForm : Form
{
public string Host
{
set
{
host = value;
SetLabel();
}
}
public List<PwEntry> Entries { set => SetEntries(value); }
public bool Remember => RememberCheck.Checked;
public bool Allowed { get; private set; }
public bool Denied { get; private set; }

internal KeePassHttpExt Plugin;

private readonly string message;
private int count;
private string host;


public AccessControlForm()
{
count = 0;
host = null;
Allowed = false;
Denied = false;
Plugin = null;
message = "{0} has requested access to passwords for the above {1}.{2} " +
"Please select whether you want to allow access{3}.";

InitializeComponent();
}

private void AllowButton_Click(object sender, EventArgs e)
private void AllowButtonClick(object sender, EventArgs e)
{
Allowed = true;
Close();
}

private void DenyButton_Click(object sender, EventArgs e)
private void DenyButtonClick(object sender, EventArgs e)
{
Denied = true;
Close();
}

public bool Allowed = false;
public bool Denied = false;

public bool Remember
private void SetLabel()
{
get { return RememberCheck.Checked; }
if (host == null)
return;

ConfirmTextLabel.Text = string.Format(
message,
host,
count == 1 ? "item" : "items",
count == 1 ? "" : "\nYou can only grant access to all items.",
count == 1 ? "" : " to all of them"
);
}

public List<PwEntry> Entries
private void SetEntries(List<PwEntry> value)
{
set
EntriesBox.SelectionMode = SelectionMode.None;
count = value.Count;
SetLabel();

foreach (var e in value)
{
EntriesBox.SelectionMode = SelectionMode.None;
Count = value.Count;
SetLabel();
foreach (var e in value)
if (e == null ||
e.Strings == null ||
e.Strings.Get(PwDefs.TitleField) == null)
{
if (e == null || e.Strings == null ||
e.Strings.Get(PwDefs.TitleField) == null) continue;
var title = e.Strings.Get(PwDefs.TitleField).ReadString();
if (Plugin == null || Plugin.GetUserPass(e) == null)
continue;
var username = Plugin.GetUserPass(e)[0];

EntriesBox.Items.Add(title + " - " + username);
continue;
}
}
}

public string Host
{
set
{
_Host = value;
SetLabel();
}
}
var title = e.Strings.Get(PwDefs.TitleField).ReadString();

private void SetLabel()
{
if (_Host == null)
return;
ConfirmTextLabel.Text = String.Format(
Message,
_Host,
Count == 1 ? "item" : "items",
Count == 1 ? "" : "\nYou can only grant access to all items.",
Count == 1 ? "" : " to all of them"
);
}
if (Plugin == null || Plugin.GetUserPass(e) == null)
continue;

private int Count = 0;
private const string Message = "{0} has requested access to passwords for the above {1}.{2} " +
"Please select whether you want to allow access{3}.";
private string _Host = null;
internal KeePassHttpExt Plugin = null;
var username = Plugin.GetUserPass(e)[0];

EntriesBox.Items.Add(title + " - " + username);
}
}
}
}
90 changes: 45 additions & 45 deletions KeePassHttp/ConfigOpt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,101 @@ namespace KeePassHttp
{
public class ConfigOpt
{
readonly AceCustomConfig _config;
const string ReceiveCredentialNotificationKey = "KeePassHttp_ReceiveCredentialNotification";
const string SpecificMatchingOnlyKey = "KeePassHttp_SpecificMatchingOnly";
const string UnlockDatabaseRequestKey = "KeePassHttp_UnlockDatabaseRequest";
const string AlwaysAllowAccessKey = "KeePassHttp_AlwaysAllowAccess";
const string AlwaysAllowUpdatesKey = "KeePassHttp_AlwaysAllowUpdates";
const string SearchInAllOpenedDatabasesKey = "KeePassHttp_SearchInAllOpenedDatabases";
const string HideExpiredKey = "KeePassHttp_HideExpired";
const string MatchSchemesKey = "KeePassHttp_MatchSchemes";
const string ReturnStringFieldsKey = "KeePassHttp_ReturnStringFields";
const string ReturnStringFieldsWithKphOnlyKey = "KeePassHttp_ReturnStringFieldsWithKphOnly";
const string SortResultByUsernameKey = "KeePassHttp_SortResultByUsername";
const string ListenerPortKey = "KeePassHttp_ListenerPort";
const string ListenerHostKey = "KeePassHttp_ListenerHost";

public ConfigOpt(AceCustomConfig config)
{
_config = config;
}
public const string RECEIVE_CREDENTIAL_NOTIFICATIONKEY = "KeePassHttp_ReceiveCredentialNotification";
public const string SPECIFIC_MATCHING_ONLYKEY = "KeePassHttp_SpecificMatchingOnly";
public const string UNLOCK_DATABASE_REQUESTKEY = "KeePassHttp_UnlockDatabaseRequest";
public const string ALWAYS_ALLOW_ACCESSKEY = "KeePassHttp_AlwaysAllowAccess";
public const string ALWAYS_ALLOW_UPDATESKEY = "KeePassHttp_AlwaysAllowUpdates";
public const string SEARCH_IN_ALL_OPENED_DATABASESKEY = "KeePassHttp_SearchInAllOpenedDatabases";
public const string HIDE_EXPIRED_KEY = "KeePassHttp_HideExpired";
public const string MATCH_SCHEMES_KEY = "KeePassHttp_MatchSchemes";
public const string RETURN_STRING_FIELDSKEY = "KeePassHttp_ReturnStringFields";
public const string RETURN_STRING_FIELDS_WITH_KPH_ONLYKEY = "KeePassHttp_ReturnStringFieldsWithKphOnly";
public const string SORT_RESULT_BY_USERNAMEKEY = "KeePassHttp_SortResultByUsername";
public const string LISTENER_PORTKEY = "KeePassHttp_ListenerPort";
public const string LISTENER_HOSTKEY = "KeePassHttp_ListenerHost";


public bool ReceiveCredentialNotification
{
get { return _config.GetBool(ReceiveCredentialNotificationKey, true); }
set { _config.SetBool(ReceiveCredentialNotificationKey, value); }
get => config.GetBool(RECEIVE_CREDENTIAL_NOTIFICATIONKEY, true);
set => config.SetBool(RECEIVE_CREDENTIAL_NOTIFICATIONKEY, value);
}

public bool UnlockDatabaseRequest
{
get { return _config.GetBool(UnlockDatabaseRequestKey, false); }
set { _config.SetBool(UnlockDatabaseRequestKey, value); }
get => config.GetBool(UNLOCK_DATABASE_REQUESTKEY, false);
set => config.SetBool(UNLOCK_DATABASE_REQUESTKEY, value);
}

public bool SpecificMatchingOnly
{
get { return _config.GetBool(SpecificMatchingOnlyKey, false); }
set { _config.SetBool(SpecificMatchingOnlyKey, value); }
get => config.GetBool(SPECIFIC_MATCHING_ONLYKEY, false);
set => config.SetBool(SPECIFIC_MATCHING_ONLYKEY, value);
}

public bool AlwaysAllowAccess
{
get { return _config.GetBool(AlwaysAllowAccessKey, false); }
set { _config.SetBool(AlwaysAllowAccessKey, value); }
get => config.GetBool(ALWAYS_ALLOW_ACCESSKEY, false);
set => config.SetBool(ALWAYS_ALLOW_ACCESSKEY, value);
}

public bool AlwaysAllowUpdates
{
get { return _config.GetBool(AlwaysAllowUpdatesKey, false); }
set { _config.SetBool(AlwaysAllowUpdatesKey, value); }
get => config.GetBool(ALWAYS_ALLOW_UPDATESKEY, false);
set => config.SetBool(ALWAYS_ALLOW_UPDATESKEY, value);
}

public bool SearchInAllOpenedDatabases
{
get { return _config.GetBool(SearchInAllOpenedDatabasesKey, false); }
set { _config.SetBool(SearchInAllOpenedDatabasesKey, value); }
get => config.GetBool(SEARCH_IN_ALL_OPENED_DATABASESKEY, false);
set => config.SetBool(SEARCH_IN_ALL_OPENED_DATABASESKEY, value);
}

public bool HideExpired
{
get { return _config.GetBool(HideExpiredKey, false); }
set { _config.SetBool(HideExpiredKey, value); }
get => config.GetBool(HIDE_EXPIRED_KEY, false);
set => config.SetBool(HIDE_EXPIRED_KEY, value);
}
public bool MatchSchemes
{
get { return _config.GetBool(MatchSchemesKey, false); }
set { _config.SetBool(MatchSchemesKey, value); }
get => config.GetBool(MATCH_SCHEMES_KEY, false);
set => config.SetBool(MATCH_SCHEMES_KEY, value);
}

public bool ReturnStringFields
{
get { return _config.GetBool(ReturnStringFieldsKey, false); }
set { _config.SetBool(ReturnStringFieldsKey, value); }
get => config.GetBool(RETURN_STRING_FIELDSKEY, false);
set => config.SetBool(RETURN_STRING_FIELDSKEY, value);
}

public bool ReturnStringFieldsWithKphOnly
{
get { return _config.GetBool(ReturnStringFieldsWithKphOnlyKey, true); }
set { _config.SetBool(ReturnStringFieldsWithKphOnlyKey, value); }
get => config.GetBool(RETURN_STRING_FIELDS_WITH_KPH_ONLYKEY, true);
set => config.SetBool(RETURN_STRING_FIELDS_WITH_KPH_ONLYKEY, value);
}

public bool SortResultByUsername
{
get { return _config.GetBool(SortResultByUsernameKey, true); }
set { _config.SetBool(SortResultByUsernameKey, value); }
get => config.GetBool(SORT_RESULT_BY_USERNAMEKEY, true);
set => config.SetBool(SORT_RESULT_BY_USERNAMEKEY, value);
}

public long ListenerPort
{
get { return _config.GetLong(ListenerPortKey, KeePassHttpExt.DEFAULT_PORT); }
set { _config.SetLong(ListenerPortKey, value); }
get => config.GetLong(LISTENER_PORTKEY, KeePassHttpExt.DEFAULT_PORT);
set => config.SetLong(LISTENER_PORTKEY, value);
}

public string ListenerHost
{
get { return _config.GetString(ListenerHostKey, KeePassHttpExt.DEFAULT_HOST); }
set { _config.SetString(ListenerHostKey, value); }
get => config.GetString(LISTENER_HOSTKEY, KeePassHttpExt.DEFAULT_HOST);
set => config.SetString(LISTENER_HOSTKEY, value);
}

private readonly AceCustomConfig config;

public ConfigOpt(AceCustomConfig config) => this.config = config;

}
}
4 changes: 2 additions & 2 deletions KeePassHttp/ConfirmAssociationForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 11 additions & 25 deletions KeePassHttp/ConfirmAssociationForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,32 @@ namespace KeePassHttp
{
public partial class ConfirmAssociationForm : Form
{
public string KeyId => Saved ? KeyName.Text : null;
public bool Saved { get; private set; }
public string Key
{
get => KeyLabel.Text;
set => KeyLabel.Text = value;
}

public ConfirmAssociationForm()
{
InitializeComponent();
Saved = false;
}

private void Save_Click(object sender, EventArgs e)
private void SaveClick(object sender, EventArgs e)
{
var value = KeyName.Text;

if (value != null && value.Trim() != "")
{
Saved = true;
Close();
}
}

private void Cancel_Click(object sender, EventArgs e)
{
Close();
}

public string KeyId
{
get
{
return Saved ? KeyName.Text : null;
}
}
private void CancelClick(object sender, EventArgs e) => Close();

public bool Saved { get; private set; }
public string Key
{
get
{
return KeyLabel.Text;
}
set
{
KeyLabel.Text = value;
}
}
}
}
Loading

0 comments on commit 3c57b20

Please sign in to comment.