Finalized ProcessBookControl
This commit is contained in:
parent
77c6a2890b
commit
676af0210b
@ -98,7 +98,6 @@
|
|||||||
this.cancelBtn.Size = new System.Drawing.Size(20, 20);
|
this.cancelBtn.Size = new System.Drawing.Size(20, 20);
|
||||||
this.cancelBtn.TabIndex = 4;
|
this.cancelBtn.TabIndex = 4;
|
||||||
this.cancelBtn.UseVisualStyleBackColor = false;
|
this.cancelBtn.UseVisualStyleBackColor = false;
|
||||||
this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click);
|
|
||||||
//
|
//
|
||||||
// statusLbl
|
// statusLbl
|
||||||
//
|
//
|
||||||
@ -128,53 +127,61 @@
|
|||||||
//
|
//
|
||||||
this.moveUpBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.moveUpBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.moveUpBtn.BackColor = System.Drawing.Color.Transparent;
|
||||||
this.moveUpBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveUpBtn.BackgroundImage")));
|
this.moveUpBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveUpBtn.BackgroundImage")));
|
||||||
this.moveUpBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.moveUpBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
|
this.moveUpBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
this.moveUpBtn.ForeColor = System.Drawing.SystemColors.Control;
|
||||||
this.moveUpBtn.Location = new System.Drawing.Point(314, 24);
|
this.moveUpBtn.Location = new System.Drawing.Point(314, 24);
|
||||||
this.moveUpBtn.Name = "moveUpBtn";
|
this.moveUpBtn.Name = "moveUpBtn";
|
||||||
this.moveUpBtn.Size = new System.Drawing.Size(30, 17);
|
this.moveUpBtn.Size = new System.Drawing.Size(30, 17);
|
||||||
this.moveUpBtn.TabIndex = 5;
|
this.moveUpBtn.TabIndex = 5;
|
||||||
this.moveUpBtn.UseVisualStyleBackColor = true;
|
this.moveUpBtn.UseVisualStyleBackColor = false;
|
||||||
this.moveUpBtn.Click += new System.EventHandler(this.moveUpBtn_Click_1);
|
|
||||||
//
|
//
|
||||||
// moveDownBtn
|
// moveDownBtn
|
||||||
//
|
//
|
||||||
this.moveDownBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.moveDownBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.moveDownBtn.BackColor = System.Drawing.Color.Transparent;
|
||||||
this.moveDownBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveDownBtn.BackgroundImage")));
|
this.moveDownBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveDownBtn.BackgroundImage")));
|
||||||
this.moveDownBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.moveDownBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
|
this.moveDownBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
this.moveDownBtn.ForeColor = System.Drawing.SystemColors.Control;
|
||||||
this.moveDownBtn.Location = new System.Drawing.Point(314, 40);
|
this.moveDownBtn.Location = new System.Drawing.Point(314, 40);
|
||||||
this.moveDownBtn.Name = "moveDownBtn";
|
this.moveDownBtn.Name = "moveDownBtn";
|
||||||
this.moveDownBtn.Size = new System.Drawing.Size(30, 17);
|
this.moveDownBtn.Size = new System.Drawing.Size(30, 17);
|
||||||
this.moveDownBtn.TabIndex = 5;
|
this.moveDownBtn.TabIndex = 5;
|
||||||
this.moveDownBtn.UseVisualStyleBackColor = true;
|
this.moveDownBtn.UseVisualStyleBackColor = false;
|
||||||
this.moveDownBtn.Click += new System.EventHandler(this.moveDownBtn_Click);
|
|
||||||
//
|
//
|
||||||
// moveFirstBtn
|
// moveFirstBtn
|
||||||
//
|
//
|
||||||
this.moveFirstBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.moveFirstBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.moveFirstBtn.BackColor = System.Drawing.Color.Transparent;
|
||||||
this.moveFirstBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveFirstBtn.BackgroundImage")));
|
this.moveFirstBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveFirstBtn.BackgroundImage")));
|
||||||
this.moveFirstBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.moveFirstBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
|
this.moveFirstBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
this.moveFirstBtn.ForeColor = System.Drawing.SystemColors.Control;
|
||||||
this.moveFirstBtn.Location = new System.Drawing.Point(314, 3);
|
this.moveFirstBtn.Location = new System.Drawing.Point(314, 3);
|
||||||
this.moveFirstBtn.Name = "moveFirstBtn";
|
this.moveFirstBtn.Name = "moveFirstBtn";
|
||||||
this.moveFirstBtn.Size = new System.Drawing.Size(30, 17);
|
this.moveFirstBtn.Size = new System.Drawing.Size(30, 17);
|
||||||
this.moveFirstBtn.TabIndex = 5;
|
this.moveFirstBtn.TabIndex = 5;
|
||||||
this.moveFirstBtn.UseVisualStyleBackColor = true;
|
this.moveFirstBtn.UseVisualStyleBackColor = false;
|
||||||
this.moveFirstBtn.Click += new System.EventHandler(this.moveFirstBtn_Click);
|
|
||||||
//
|
//
|
||||||
// moveLastBtn
|
// moveLastBtn
|
||||||
//
|
//
|
||||||
this.moveLastBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.moveLastBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.moveLastBtn.BackColor = System.Drawing.Color.Transparent;
|
||||||
this.moveLastBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveLastBtn.BackgroundImage")));
|
this.moveLastBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("moveLastBtn.BackgroundImage")));
|
||||||
this.moveLastBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
this.moveLastBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||||
|
this.moveLastBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
this.moveLastBtn.ForeColor = System.Drawing.SystemColors.Control;
|
||||||
this.moveLastBtn.Location = new System.Drawing.Point(314, 63);
|
this.moveLastBtn.Location = new System.Drawing.Point(314, 63);
|
||||||
this.moveLastBtn.Name = "moveLastBtn";
|
this.moveLastBtn.Name = "moveLastBtn";
|
||||||
this.moveLastBtn.Size = new System.Drawing.Size(30, 17);
|
this.moveLastBtn.Size = new System.Drawing.Size(30, 17);
|
||||||
this.moveLastBtn.TabIndex = 5;
|
this.moveLastBtn.TabIndex = 5;
|
||||||
this.moveLastBtn.UseVisualStyleBackColor = true;
|
this.moveLastBtn.UseVisualStyleBackColor = false;
|
||||||
this.moveLastBtn.Click += new System.EventHandler(this.moveLastBtn_Click);
|
|
||||||
//
|
//
|
||||||
// ProcessBookControl
|
// ProcessBookControl
|
||||||
//
|
//
|
||||||
@ -193,7 +200,7 @@
|
|||||||
this.Controls.Add(this.progressBar1);
|
this.Controls.Add(this.progressBar1);
|
||||||
this.Controls.Add(this.bookInfoLbl);
|
this.Controls.Add(this.bookInfoLbl);
|
||||||
this.Controls.Add(this.pictureBox1);
|
this.Controls.Add(this.pictureBox1);
|
||||||
this.Margin = new System.Windows.Forms.Padding(2);
|
this.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
|
||||||
this.Name = "ProcessBookControl";
|
this.Name = "ProcessBookControl";
|
||||||
this.Size = new System.Drawing.Size(375, 86);
|
this.Size = new System.Drawing.Size(375, 86);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||||
@ -208,12 +215,12 @@
|
|||||||
private System.Windows.Forms.ProgressBar progressBar1;
|
private System.Windows.Forms.ProgressBar progressBar1;
|
||||||
private System.Windows.Forms.Label remainingTimeLbl;
|
private System.Windows.Forms.Label remainingTimeLbl;
|
||||||
private System.Windows.Forms.Label etaLbl;
|
private System.Windows.Forms.Label etaLbl;
|
||||||
private System.Windows.Forms.Button cancelBtn;
|
|
||||||
private System.Windows.Forms.Label statusLbl;
|
private System.Windows.Forms.Label statusLbl;
|
||||||
private System.Windows.Forms.Label bookInfoLbl;
|
private System.Windows.Forms.Label bookInfoLbl;
|
||||||
private System.Windows.Forms.Button moveUpBtn;
|
public System.Windows.Forms.Button cancelBtn;
|
||||||
private System.Windows.Forms.Button moveDownBtn;
|
public System.Windows.Forms.Button moveUpBtn;
|
||||||
private System.Windows.Forms.Button moveFirstBtn;
|
public System.Windows.Forms.Button moveDownBtn;
|
||||||
private System.Windows.Forms.Button moveLastBtn;
|
public System.Windows.Forms.Button moveFirstBtn;
|
||||||
|
public System.Windows.Forms.Button moveLastBtn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,40 +1,19 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Forms.Layout;
|
|
||||||
using DataLayer;
|
|
||||||
using Dinah.Core.Net.Http;
|
|
||||||
using Dinah.Core.Threading;
|
|
||||||
using FileLiberator;
|
|
||||||
using LibationFileManager;
|
|
||||||
using LibationWinForms.BookLiberation;
|
|
||||||
using LibationWinForms.ProcessQueue;
|
|
||||||
|
|
||||||
namespace LibationWinForms.ProcessQueue
|
namespace LibationWinForms.ProcessQueue
|
||||||
{
|
{
|
||||||
internal interface ILiberatiofffnBaseForm
|
|
||||||
{
|
|
||||||
Action CancelAction { get; set; }
|
|
||||||
Func<QueuePosition?> MoveUpAction { get; set; }
|
|
||||||
Func<QueuePosition?> MoveDownAction { get; set; }
|
|
||||||
void SetResult(ProcessBookResult status);
|
|
||||||
void SetQueuePosition(QueuePosition status);
|
|
||||||
void RegisterFileLiberator(Processable streamable, LogMe logMe);
|
|
||||||
void Processable_Begin(object sender, LibraryBook libraryBook);
|
|
||||||
int Width { get; set; }
|
|
||||||
int Height { get; set; }
|
|
||||||
Padding Margin { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal partial class ProcessBookControl : UserControl
|
internal partial class ProcessBookControl : UserControl
|
||||||
{
|
{
|
||||||
public ProcessBookStatus Status { get; private set; } = ProcessBookStatus.Queued;
|
private static int ControlNumberCounter = 0;
|
||||||
public Action CancelAction { get; set; }
|
|
||||||
public Func<QueuePositionRequest, QueuePosition?> RequestMoveAction { get; set; }
|
/// <summary>
|
||||||
public string DecodeActionName { get; } = "Decoding";
|
/// The contol's position within <see cref="VirtualFlowControl"/>
|
||||||
private Func<byte[]> GetCoverArtDelegate;
|
/// </summary>
|
||||||
protected Processable Processable { get; private set; }
|
public int ControlNumber { get; }
|
||||||
protected LogMe LogMe { get; private set; }
|
private ProcessBookStatus Status { get; set; } = ProcessBookStatus.Queued;
|
||||||
|
private readonly int CancelBtnDistanceFromEdge;
|
||||||
public ProcessBookControl()
|
public ProcessBookControl()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -42,17 +21,27 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
remainingTimeLbl.Visible = false;
|
remainingTimeLbl.Visible = false;
|
||||||
progressBar1.Visible = false;
|
progressBar1.Visible = false;
|
||||||
etaLbl.Visible = false;
|
etaLbl.Visible = false;
|
||||||
|
|
||||||
|
CancelBtnDistanceFromEdge = Width - cancelBtn.Location.X;
|
||||||
|
ControlNumber = ControlNumberCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCover(Image cover)
|
public void SetCover(Image cover)
|
||||||
{
|
{
|
||||||
pictureBox1.Image = cover;
|
pictureBox1.Image = cover;
|
||||||
}
|
}
|
||||||
public void SetTitle(string title)
|
public void SetBookInfo(string title)
|
||||||
{
|
{
|
||||||
bookInfoLbl.Text = title;
|
bookInfoLbl.Text = title;
|
||||||
}
|
}
|
||||||
|
public void SetProgrss(int progress)
|
||||||
|
{
|
||||||
|
progressBar1.Value = progress;
|
||||||
|
}
|
||||||
|
public void SetRemainingTime(TimeSpan remaining)
|
||||||
|
{
|
||||||
|
remainingTimeLbl.Text = $"{remaining:mm\\:ss}";
|
||||||
|
}
|
||||||
public void SetResult(ProcessBookResult result)
|
public void SetResult(ProcessBookResult result)
|
||||||
{
|
{
|
||||||
string statusText = default;
|
string statusText = default;
|
||||||
@ -90,8 +79,7 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
|
|
||||||
SetStatus(Status, statusText);
|
SetStatus(Status, statusText);
|
||||||
}
|
}
|
||||||
|
public void SetStatus(ProcessBookStatus status, string statusText = null)
|
||||||
public void SetStatus(ProcessBookStatus status, string statusText)
|
|
||||||
{
|
{
|
||||||
Color backColor = default;
|
Color backColor = default;
|
||||||
switch (status)
|
switch (status)
|
||||||
@ -118,245 +106,49 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.UIThreadAsync(() =>
|
SuspendLayout();
|
||||||
|
|
||||||
|
cancelBtn.Visible = Status is ProcessBookStatus.Queued or ProcessBookStatus.Working;
|
||||||
|
moveLastBtn.Visible = Status == ProcessBookStatus.Queued;
|
||||||
|
moveDownBtn.Visible = Status == ProcessBookStatus.Queued;
|
||||||
|
moveUpBtn.Visible = Status == ProcessBookStatus.Queued;
|
||||||
|
moveFirstBtn.Visible = Status == ProcessBookStatus.Queued;
|
||||||
|
remainingTimeLbl.Visible = Status == ProcessBookStatus.Working;
|
||||||
|
progressBar1.Visible = Status == ProcessBookStatus.Working;
|
||||||
|
etaLbl.Visible = Status == ProcessBookStatus.Working;
|
||||||
|
statusLbl.Visible = Status != ProcessBookStatus.Working;
|
||||||
|
statusLbl.Text = statusText ?? Status.ToString();
|
||||||
|
BackColor = backColor;
|
||||||
|
|
||||||
|
int deltaX = Width - cancelBtn.Location.X - CancelBtnDistanceFromEdge;
|
||||||
|
|
||||||
|
if (Status is ProcessBookStatus.Queued or ProcessBookStatus.Working && deltaX != 0)
|
||||||
{
|
{
|
||||||
SuspendLayout();
|
//If the last book to occupy this control before resizing was not queued,
|
||||||
|
//the buttons were not Visible so the Anchor property was ignored.
|
||||||
|
|
||||||
cancelBtn.Visible = Status is ProcessBookStatus.Queued or ProcessBookStatus.Working;
|
cancelBtn.Location = new Point(cancelBtn.Location.X + deltaX, cancelBtn.Location.Y);
|
||||||
moveLastBtn.Visible = Status == ProcessBookStatus.Queued;
|
moveFirstBtn.Location = new Point(moveFirstBtn.Location.X + deltaX, moveFirstBtn.Location.Y);
|
||||||
moveDownBtn.Visible = Status == ProcessBookStatus.Queued;
|
moveUpBtn.Location = new Point(moveUpBtn.Location.X + deltaX, moveUpBtn.Location.Y);
|
||||||
moveUpBtn.Visible = Status == ProcessBookStatus.Queued;
|
moveDownBtn.Location = new Point(moveDownBtn.Location.X + deltaX, moveDownBtn.Location.Y);
|
||||||
moveFirstBtn.Visible = Status == ProcessBookStatus.Queued;
|
moveLastBtn.Location = new Point(moveLastBtn.Location.X + deltaX, moveLastBtn.Location.Y);
|
||||||
remainingTimeLbl.Visible = Status == ProcessBookStatus.Working;
|
}
|
||||||
progressBar1.Visible = Status == ProcessBookStatus.Working;
|
|
||||||
etaLbl.Visible = Status == ProcessBookStatus.Working;
|
|
||||||
statusLbl.Visible = Status != ProcessBookStatus.Working;
|
|
||||||
statusLbl.Text = statusText;
|
|
||||||
BackColor = backColor;
|
|
||||||
|
|
||||||
if (status == ProcessBookStatus.Working)
|
if (status == ProcessBookStatus.Working)
|
||||||
{
|
{
|
||||||
bookInfoLbl.Width += moveLastBtn.Width + moveLastBtn.Padding.Left + moveLastBtn.Padding.Right;
|
bookInfoLbl.Width = cancelBtn.Location.X - bookInfoLbl.Location.X - bookInfoLbl.Padding.Left + cancelBtn.Padding.Right;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
bookInfoLbl.Width -= moveLastBtn.Width + moveLastBtn.Padding.Left + moveLastBtn.Padding.Right;
|
|
||||||
|
|
||||||
}
|
|
||||||
ResumeLayout();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProcessBookControl(string title, Image cover) : this()
|
|
||||||
{
|
|
||||||
this.title = title;
|
|
||||||
pictureBox1.Image = cover;
|
|
||||||
bookInfoLbl.Text = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterFileLiberator(Processable processable, LogMe logMe = null)
|
|
||||||
{
|
|
||||||
if (processable is null) return;
|
|
||||||
|
|
||||||
Processable = processable;
|
|
||||||
LogMe = logMe;
|
|
||||||
|
|
||||||
Subscribe((Streamable)processable);
|
|
||||||
Subscribe(processable);
|
|
||||||
if (processable is AudioDecodable audioDecodable)
|
|
||||||
Subscribe(audioDecodable);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#region Event Subscribers and Unsubscribers
|
|
||||||
private void Subscribe(Streamable streamable)
|
|
||||||
{
|
|
||||||
UnsubscribeStreamable(this, EventArgs.Empty);
|
|
||||||
|
|
||||||
streamable.StreamingProgressChanged += Streamable_StreamingProgressChanged;
|
|
||||||
streamable.StreamingTimeRemaining += Streamable_StreamingTimeRemaining;
|
|
||||||
|
|
||||||
Disposed += UnsubscribeStreamable;
|
|
||||||
}
|
|
||||||
private void Subscribe(Processable processable)
|
|
||||||
{
|
|
||||||
UnsubscribeProcessable(this, null);
|
|
||||||
|
|
||||||
processable.Begin += Processable_Begin;
|
|
||||||
processable.Completed += Processable_Completed;
|
|
||||||
|
|
||||||
//Don't unsubscribe from Dispose because it fires when
|
|
||||||
//Streamable.StreamingCompleted closes the form, and
|
|
||||||
//the Processable events need to live past that event.
|
|
||||||
processable.Completed += UnsubscribeProcessable;
|
|
||||||
}
|
|
||||||
private void Subscribe(AudioDecodable audioDecodable)
|
|
||||||
{
|
|
||||||
UnsubscribeAudioDecodable(this, EventArgs.Empty);
|
|
||||||
|
|
||||||
audioDecodable.RequestCoverArt += AudioDecodable_RequestCoverArt;
|
|
||||||
audioDecodable.TitleDiscovered += AudioDecodable_TitleDiscovered;
|
|
||||||
audioDecodable.AuthorsDiscovered += AudioDecodable_AuthorsDiscovered;
|
|
||||||
audioDecodable.NarratorsDiscovered += AudioDecodable_NarratorsDiscovered;
|
|
||||||
audioDecodable.CoverImageDiscovered += AudioDecodable_CoverImageDiscovered;
|
|
||||||
|
|
||||||
Disposed += UnsubscribeAudioDecodable;
|
|
||||||
}
|
|
||||||
private void UnsubscribeStreamable(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Disposed -= UnsubscribeStreamable;
|
|
||||||
|
|
||||||
Processable.StreamingProgressChanged -= Streamable_StreamingProgressChanged;
|
|
||||||
Processable.StreamingTimeRemaining -= Streamable_StreamingTimeRemaining;
|
|
||||||
}
|
|
||||||
private void UnsubscribeProcessable(object sender, LibraryBook e)
|
|
||||||
{
|
|
||||||
Processable.Completed -= UnsubscribeProcessable;
|
|
||||||
Processable.Begin -= Processable_Begin;
|
|
||||||
Processable.Completed -= Processable_Completed;
|
|
||||||
}
|
|
||||||
private void UnsubscribeAudioDecodable(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (Processable is not AudioDecodable audioDecodable)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Disposed -= UnsubscribeAudioDecodable;
|
|
||||||
audioDecodable.RequestCoverArt -= AudioDecodable_RequestCoverArt;
|
|
||||||
audioDecodable.TitleDiscovered -= AudioDecodable_TitleDiscovered;
|
|
||||||
audioDecodable.AuthorsDiscovered -= AudioDecodable_AuthorsDiscovered;
|
|
||||||
audioDecodable.NarratorsDiscovered -= AudioDecodable_NarratorsDiscovered;
|
|
||||||
audioDecodable.CoverImageDiscovered -= AudioDecodable_CoverImageDiscovered;
|
|
||||||
|
|
||||||
audioDecodable.Cancel();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Streamable event handlers
|
|
||||||
public void Streamable_StreamingProgressChanged(object sender, DownloadProgress downloadProgress)
|
|
||||||
{
|
|
||||||
if (!downloadProgress.ProgressPercentage.HasValue)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (downloadProgress.ProgressPercentage == 0)
|
|
||||||
updateRemainingTime(0);
|
|
||||||
else
|
else
|
||||||
progressBar1.UIThreadAsync(() => progressBar1.Value = (int)downloadProgress.ProgressPercentage);
|
{
|
||||||
}
|
bookInfoLbl.Width = moveLastBtn.Location.X - bookInfoLbl.Location.X - bookInfoLbl.Padding.Left + moveLastBtn.Padding.Right;
|
||||||
|
}
|
||||||
|
|
||||||
public void Streamable_StreamingTimeRemaining(object sender, TimeSpan timeRemaining)
|
ResumeLayout();
|
||||||
{
|
|
||||||
updateRemainingTime((int)timeRemaining.TotalSeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateRemainingTime(int remaining)
|
|
||||||
=> remainingTimeLbl.UIThreadAsync(() => remainingTimeLbl.Text = formatTime(remaining));
|
|
||||||
|
|
||||||
private string formatTime(int seconds)
|
|
||||||
{
|
|
||||||
var timeSpan = TimeSpan.FromSeconds(seconds);
|
|
||||||
return $"{timeSpan:mm\\:ss}";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Processable event handlers
|
|
||||||
public void Processable_Begin(object sender, LibraryBook libraryBook)
|
|
||||||
{
|
|
||||||
Status = ProcessBookStatus.Working;
|
|
||||||
|
|
||||||
LogMe.Info($"{Environment.NewLine}{Processable.Name} Step, Begin: {libraryBook.Book}");
|
|
||||||
|
|
||||||
SetStatus(ProcessBookStatus.Working, "");
|
|
||||||
|
|
||||||
GetCoverArtDelegate = () => PictureStorage.GetPictureSynchronously(
|
|
||||||
new PictureDefinition(
|
|
||||||
libraryBook.Book.PictureId,
|
|
||||||
PictureSize._500x500));
|
|
||||||
|
|
||||||
//Set default values from library
|
|
||||||
AudioDecodable_TitleDiscovered(sender, libraryBook.Book.Title);
|
|
||||||
AudioDecodable_AuthorsDiscovered(sender, libraryBook.Book.AuthorNames());
|
|
||||||
AudioDecodable_NarratorsDiscovered(sender, libraryBook.Book.NarratorNames());
|
|
||||||
AudioDecodable_CoverImageDiscovered(sender,
|
|
||||||
PictureStorage.GetPicture(
|
|
||||||
new PictureDefinition(
|
|
||||||
libraryBook.Book.PictureId,
|
|
||||||
PictureSize._80x80)).bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Processable_Completed(object sender, LibraryBook libraryBook)
|
|
||||||
{
|
|
||||||
LogMe.Info($"{Processable.Name} Step, Completed: {libraryBook.Book}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region AudioDecodable event handlers
|
|
||||||
|
|
||||||
private string title;
|
|
||||||
private string authorNames;
|
|
||||||
private string narratorNames;
|
|
||||||
public void AudioDecodable_TitleDiscovered(object sender, string title)
|
|
||||||
{
|
|
||||||
this.UIThreadAsync(() => this.Text = DecodeActionName + " " + title);
|
|
||||||
this.title = title;
|
|
||||||
updateBookInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AudioDecodable_AuthorsDiscovered(object sender, string authors)
|
|
||||||
{
|
|
||||||
authorNames = authors;
|
|
||||||
updateBookInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AudioDecodable_NarratorsDiscovered(object sender, string narrators)
|
|
||||||
{
|
|
||||||
narratorNames = narrators;
|
|
||||||
updateBookInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBookInfo()
|
|
||||||
=> bookInfoLbl.UIThreadAsync(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}");
|
|
||||||
|
|
||||||
public void AudioDecodable_RequestCoverArt(object sender, Action<byte[]> setCoverArtDelegate)
|
|
||||||
{
|
|
||||||
setCoverArtDelegate(GetCoverArtDelegate?.Invoke());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AudioDecodable_CoverImageDiscovered(object sender, byte[] coverArt)
|
|
||||||
{
|
|
||||||
pictureBox1.UIThreadAsync(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt));
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private void cancelBtn_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CancelAction?.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveLastBtn_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
RequestMoveAction?.Invoke(QueuePositionRequest.Last);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveFirstBtn_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
RequestMoveAction?.Invoke(QueuePositionRequest.Fisrt);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveUpBtn_Click_1(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
RequestMoveAction?.Invoke(QueuePositionRequest.OneUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveDownBtn_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
RequestMoveAction?.Invoke(QueuePositionRequest.OneDown);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return title ?? "NO TITLE";
|
return bookInfoLbl.Text ?? "[NO TITLE]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,21 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="pictureBox1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="progressBar1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="remainingTimeLbl.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="etaLbl.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="cancelBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||||
<data name="cancelBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="cancelBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
@ -719,6 +734,15 @@
|
|||||||
/x9W31o+WFcHNAAAAABJRU5ErkJggg==
|
/x9W31o+WFcHNAAAAABJRU5ErkJggg==
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
|
<metadata name="statusLbl.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="bookInfoLbl.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="moveUpBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
<data name="moveUpBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="moveUpBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAMgAAABNCAYAAADjJSv1AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
iVBORw0KGgoAAAANSUhEUgAAAMgAAABNCAYAAADjJSv1AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
||||||
@ -746,6 +770,9 @@
|
|||||||
t7PIdXRT9kCF1lo8u3IPfFOKqVljg2IAAAAASUVORK5CYII=
|
t7PIdXRT9kCF1lo8u3IPfFOKqVljg2IAAAAASUVORK5CYII=
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
|
<metadata name="moveDownBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
<data name="moveDownBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="moveDownBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAMgAAABNCAYAAADjJSv1AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
iVBORw0KGgoAAAANSUhEUgAAAMgAAABNCAYAAADjJSv1AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
||||||
@ -773,6 +800,9 @@
|
|||||||
wxjjQQ1jjAc1jDEe1DDGiJcX/wKcO4zm90rrbQAAAABJRU5ErkJggg==
|
wxjjQQ1jjAc1jDEe1DDGiJcX/wKcO4zm90rrbQAAAABJRU5ErkJggg==
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
|
<metadata name="moveFirstBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
<data name="moveFirstBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="moveFirstBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAMgAAABZCAYAAAB7Ymt4AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
iVBORw0KGgoAAAANSUhEUgAAAMgAAABZCAYAAAB7Ymt4AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
||||||
@ -801,6 +831,9 @@
|
|||||||
jfkqyMbMAAAAAElFTkSuQmCC
|
jfkqyMbMAAAAAElFTkSuQmCC
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
|
<metadata name="moveLastBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
<data name="moveLastBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="moveLastBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAMgAAABZCAYAAAB7Ymt4AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
iVBORw0KGgoAAAANSUhEUgAAAMgAAABZCAYAAAB7Ymt4AAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
|
||||||
@ -829,4 +862,7 @@
|
|||||||
6l8KOJAbKVKmPQAAAABJRU5ErkJggg==
|
6l8KOJAbKVKmPQAAAABJRU5ErkJggg==
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
|
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
||||||
Loading…
x
Reference in New Issue
Block a user