diff --git a/InternalUtilities/Accounts.cs b/InternalUtilities/Accounts.cs index b15b3aa2..60898f97 100644 --- a/InternalUtilities/Accounts.cs +++ b/InternalUtilities/Accounts.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using AudibleApi; @@ -25,7 +26,11 @@ namespace InternalUtilities protected override JsonSerializerSettings GetSerializerSettings() => Identity.GetJsonSerializerSettings(); } - public class Accounts : Updatable + // 'Accounts' is intentionally not IEnumerable<> so that properties can be added/extended + // from newtonsoft (https://www.newtonsoft.com/json/help/html/SerializationGuide.htm): + // .NET : IList, IEnumerable, IList, Array + // JSON : Array (properties on the collection will not be serialized) + public class Accounts : IUpdatable { public event EventHandler Updated; private void update(object sender = null, EventArgs e = null) @@ -143,7 +148,7 @@ namespace InternalUtilities throw new InvalidOperationException("Cannot add an account with the same account Id and Locale"); } } - public class Account : Updatable + public class Account : IUpdatable { public event EventHandler Updated; private void update(object sender = null, EventArgs e = null) @@ -169,6 +174,10 @@ namespace InternalUtilities } } + // whether to include this account when scanning libraries. + // technically this is an app setting; not an attribute of account. but since it's managed with accounts, it makes sense to put this exception-to-the-rule here + public bool LibraryScan { get; set; } + private string _decryptKey = ""; public string DecryptKey { diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 139b84a5..6079cc20 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.229 + 3.1.12.249 diff --git a/LibationLauncher/UNTESTED/Program.cs b/LibationLauncher/UNTESTED/Program.cs index e9e08e45..a514a0d9 100644 --- a/LibationLauncher/UNTESTED/Program.cs +++ b/LibationLauncher/UNTESTED/Program.cs @@ -157,6 +157,7 @@ namespace LibationLauncher var account = new Account(email) { AccountName = $"{email} - {locale.Name}", + LibraryScan = true, IdentityTokens = identity }; diff --git a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs index 7a5efd71..f24e821b 100644 --- a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs +++ b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs @@ -35,8 +35,8 @@ this.DeleteAccount = new System.Windows.Forms.DataGridViewButtonColumn(); this.LibraryScan = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.AccountId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Locale = new System.Windows.Forms.DataGridViewComboBoxColumn(); + this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // @@ -75,8 +75,8 @@ this.DeleteAccount, this.LibraryScan, this.AccountId, - this.AccountName, - this.Locale}); + this.Locale, + this.AccountName}); this.dataGridView1.Location = new System.Drawing.Point(12, 12); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; @@ -118,18 +118,18 @@ this.AccountId.Name = "AccountId"; this.AccountId.Width = 111; // - // AccountName - // - this.AccountName.HeaderText = "Account nickname (optional)"; - this.AccountName.Name = "AccountName"; - this.AccountName.Width = 152; - // // Locale // this.Locale.HeaderText = "Locale"; this.Locale.Name = "Locale"; this.Locale.Width = 45; // + // AccountName + // + this.AccountName.HeaderText = "Account nickname (optional)"; + this.AccountName.Name = "AccountName"; + this.AccountName.Width = 152; + // // AccountsDialog // this.AcceptButton = this.saveBtn; @@ -156,7 +156,7 @@ private System.Windows.Forms.DataGridViewButtonColumn DeleteAccount; private System.Windows.Forms.DataGridViewCheckBoxColumn LibraryScan; private System.Windows.Forms.DataGridViewTextBoxColumn AccountId; - private System.Windows.Forms.DataGridViewTextBoxColumn AccountName; private System.Windows.Forms.DataGridViewComboBoxColumn Locale; + private System.Windows.Forms.DataGridViewTextBoxColumn AccountName; } } \ No newline at end of file diff --git a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs index 4851ce95..64b91448 100644 --- a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs +++ b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs @@ -1,36 +1,99 @@ using System; using System.Linq; using System.Windows.Forms; +using AudibleApi; using FileManager; +using InternalUtilities; namespace LibationWinForms.Dialogs { public partial class AccountsDialog : Form { - const string COL_Original = "Original"; - const string COL_Delete = "Delete"; - const string COL_Filter = "Filter"; - const string COL_MoveUp = "MoveUp"; - const string COL_MoveDown = "MoveDown"; + const string NON_BREAKING_SPACE = "\u00a0"; + + const string COL_Original = nameof(Original); + const string COL_Delete = nameof(DeleteAccount); + const string COL_LibraryScan = nameof(LibraryScan); + const string COL_AccountId = nameof(AccountId); + const string COL_AccountName = nameof(AccountName); + const string COL_Locale = nameof(Locale); public AccountsDialog() { InitializeComponent(); + + dataGridView1.Columns[COL_AccountName].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + populateDropDown(); + + populateGridValues(); + } + + private void populateDropDown() + => (dataGridView1.Columns[COL_Locale] as DataGridViewComboBoxColumn).DataSource + = Localization.Locales + .Select(l => l.Name) + .OrderBy(a => a).ToList(); + + private void populateGridValues() + { + var accounts = AudibleApiStorage.GetAccounts().AccountsSettings; + if (!accounts.Any()) + return; + + foreach (var account in accounts) + dataGridView1.Rows.Add( + new { account.AccountId, account.Locale.Name }, + "X", + account.LibraryScan, + account.AccountId, + account.Locale.Name, + account.AccountName); + } + + private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e) + { + e.Row.Cells[COL_Delete].Value = "X"; + e.Row.Cells[COL_LibraryScan].Value = true; + } + + private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + var dgv = (DataGridView)sender; + + var col = dgv.Columns[e.ColumnIndex]; + if (col is DataGridViewButtonColumn && e.RowIndex >= 0) + { + var row = dgv.Rows[e.RowIndex]; + switch (col.Name) + { + case COL_Delete: + // if final/edit row: do nothing + if (e.RowIndex < dgv.RowCount - 1) + dgv.Rows.Remove(row); + break; + //case COL_MoveUp: + // // if top: do nothing + // if (e.RowIndex < 1) + // break; + // dgv.Rows.Remove(row); + // dgv.Rows.Insert(e.RowIndex - 1, row); + // break; + //case COL_MoveDown: + // // if final/edit row or bottom filter row: do nothing + // if (e.RowIndex >= dgv.RowCount - 2) + // break; + // dgv.Rows.Remove(row); + // dgv.Rows.Insert(e.RowIndex + 1, row); + // break; + } + } } private void cancelBtn_Click(object sender, EventArgs e) => this.Close(); #region TEMP - private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e) - { - - - - //e.Row.Cells["Region"].Value = "WA"; - //e.Row.Cells["CustomerID"].Value = NewCustomerId(); - } - private void saveBtn_Click(object sender, EventArgs e) { @@ -65,39 +128,6 @@ namespace LibationWinForms.Dialogs { } - - private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) - { - //var dgv = (DataGridView)sender; - - //var col = dgv.Columns[e.ColumnIndex]; - //if (col is DataGridViewButtonColumn && e.RowIndex >= 0) - //{ - // var row = dgv.Rows[e.RowIndex]; - // switch (col.Name) - // { - // case COL_Delete: - // // if final/edit row: do nothing - // if (e.RowIndex < dgv.RowCount - 1) - // dgv.Rows.Remove(row); - // break; - // case COL_MoveUp: - // // if top: do nothing - // if (e.RowIndex < 1) - // break; - // dgv.Rows.Remove(row); - // dgv.Rows.Insert(e.RowIndex - 1, row); - // break; - // case COL_MoveDown: - // // if final/edit row or bottom filter row: do nothing - // if (e.RowIndex >= dgv.RowCount - 2) - // break; - // dgv.Rows.Remove(row); - // dgv.Rows.Insert(e.RowIndex + 1, row); - // break; - // } - //} - } #endregion } } diff --git a/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.Designer.cs b/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.Designer.cs index 66130355..ced0d386 100644 --- a/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.Designer.cs +++ b/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.Designer.cs @@ -81,6 +81,7 @@ this.dataGridView1.Size = new System.Drawing.Size(776, 397); this.dataGridView1.TabIndex = 0; this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1_CellContentClick); + this.dataGridView1.DefaultValuesNeeded += new System.Windows.Forms.DataGridViewRowEventHandler(this.dataGridView1_DefaultValuesNeeded); // // Original // diff --git a/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs b/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs index 1a81e70d..f495db02 100644 --- a/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs +++ b/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs @@ -10,11 +10,11 @@ namespace LibationWinForms.Dialogs const string BLACK_UP_POINTING_TRIANGLE = "\u25B2"; const string BLACK_DOWN_POINTING_TRIANGLE = "\u25BC"; - const string COL_Original = "Original"; - const string COL_Delete = "Delete"; - const string COL_Filter = "Filter"; - const string COL_MoveUp = "MoveUp"; - const string COL_MoveDown = "MoveDown"; + const string COL_Original = nameof(Original); + const string COL_Delete = nameof(Delete); + const string COL_Filter = nameof(Filter); + const string COL_MoveUp = nameof(MoveUp); + const string COL_MoveDown = nameof(MoveDown); Form1 _parent { get; } @@ -26,10 +26,10 @@ namespace LibationWinForms.Dialogs dataGridView1.Columns[COL_Filter].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - populateFilters(); + populateGridValues(); } - private void populateFilters() + private void populateGridValues() { var filters = QuickFilters.Filters; if (!filters.Any()) @@ -39,6 +39,13 @@ namespace LibationWinForms.Dialogs dataGridView1.Rows.Add(filter, "X", filter, BLACK_UP_POINTING_TRIANGLE, BLACK_DOWN_POINTING_TRIANGLE); } + private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e) + { + e.Row.Cells[COL_Delete].Value = "X"; + e.Row.Cells[COL_MoveUp].Value = BLACK_UP_POINTING_TRIANGLE; + e.Row.Cells[COL_MoveDown].Value = BLACK_DOWN_POINTING_TRIANGLE; + } + private void saveBtn_Click(object sender, EventArgs e) { var list = dataGridView1.Rows diff --git a/WinFormsDesigner/Dialogs/AccountsDialog.Designer.cs b/WinFormsDesigner/Dialogs/AccountsDialog.Designer.cs index a677c76b..bf3c6d57 100644 --- a/WinFormsDesigner/Dialogs/AccountsDialog.Designer.cs +++ b/WinFormsDesigner/Dialogs/AccountsDialog.Designer.cs @@ -35,8 +35,8 @@ this.DeleteAccount = new System.Windows.Forms.DataGridViewButtonColumn(); this.LibraryScan = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.AccountId = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Locale = new System.Windows.Forms.DataGridViewComboBoxColumn(); + this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // @@ -63,18 +63,18 @@ // // dataGridView1 // - this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Original, - this.DeleteAccount, - this.LibraryScan, - this.AccountId, - this.AccountName, - this.Locale}); + this.Original, + this.DeleteAccount, + this.LibraryScan, + this.AccountId, + this.Locale, + this.AccountName}); this.dataGridView1.Location = new System.Drawing.Point(12, 12); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; @@ -110,18 +110,18 @@ this.AccountId.Name = "AccountId"; this.AccountId.Width = 111; // - // AccountName - // - this.AccountName.HeaderText = "Account nickname (optional)"; - this.AccountName.Name = "AccountName"; - this.AccountName.Width = 152; - // // Locale // this.Locale.HeaderText = "Locale"; this.Locale.Name = "Locale"; this.Locale.Width = 45; // + // AccountName + // + this.AccountName.HeaderText = "Account nickname (optional)"; + this.AccountName.Name = "AccountName"; + this.AccountName.Width = 152; + // // AccountsDialog // this.AcceptButton = this.saveBtn; @@ -148,7 +148,7 @@ private System.Windows.Forms.DataGridViewButtonColumn DeleteAccount; private System.Windows.Forms.DataGridViewCheckBoxColumn LibraryScan; private System.Windows.Forms.DataGridViewTextBoxColumn AccountId; - private System.Windows.Forms.DataGridViewTextBoxColumn AccountName; private System.Windows.Forms.DataGridViewComboBoxColumn Locale; + private System.Windows.Forms.DataGridViewTextBoxColumn AccountName; } } \ No newline at end of file