From: brianmario Date: Wed, 18 Jul 2007 19:24:04 +0000 (+0000) Subject: WinGui: X-Git-Tag: 0.9.0~130 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a86e63089a22839b51890db36481c88e25a0a0c6;p=handbrake WinGui: added OnScanProgress event to Parser class which is raised upon noticing "Scanning title # of #..." in the output added progress bar to frmReadDVD to give better visual notification of scan progress git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@711 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs index 8c3c24b3e..ef6476f78 100644 --- a/win/C#/Parsing/Parser.cs +++ b/win/C#/Parsing/Parser.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; using System.IO; +using System.Text.RegularExpressions; namespace Handbrake.Parsing { @@ -12,6 +13,8 @@ namespace Handbrake.Parsing /// The data parsed from the stream public delegate void DataReadEventHandler(object Sender, string Data); + public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount); + /// /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process /// @@ -39,6 +42,8 @@ namespace Handbrake.Parsing /// public static event DataReadEventHandler OnReadToEnd; + public static event ScanProgressEventHandler OnScanProgress; + /// /// Default constructor for this object /// @@ -52,10 +57,15 @@ namespace Handbrake.Parsing { string tmp = base.ReadLine(); this.m_buffer += tmp; + Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)"); if (OnReadLine != null) { OnReadLine(this, tmp); } + if (m.Success && OnScanProgress != null) + { + OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value)); + } return tmp; } diff --git a/win/C#/frmReadDVD.Designer.cs b/win/C#/frmReadDVD.Designer.cs index 18bbd36a1..40ab0fc33 100644 --- a/win/C#/frmReadDVD.Designer.cs +++ b/win/C#/frmReadDVD.Designer.cs @@ -33,14 +33,14 @@ namespace Handbrake this.btn_ok = new System.Windows.Forms.Button(); this.Label3 = new System.Windows.Forms.Label(); this.Label2 = new System.Windows.Forms.Label(); - this.lbl_status = new System.Windows.Forms.Label(); + this.scanProgress = new System.Windows.Forms.ProgressBar(); this.SuspendLayout(); // // lbl_pressOk // this.lbl_pressOk.AutoSize = true; this.lbl_pressOk.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbl_pressOk.Location = new System.Drawing.Point(66, 60); + this.lbl_pressOk.Location = new System.Drawing.Point(216, 56); this.lbl_pressOk.Name = "lbl_pressOk"; this.lbl_pressOk.Size = new System.Drawing.Size(178, 13); this.lbl_pressOk.TabIndex = 29; @@ -82,23 +82,20 @@ namespace Handbrake this.Label2.TabIndex = 26; this.Label2.Text = "Status:"; // - // lbl_status + // scanProgress // - this.lbl_status.AutoSize = true; - this.lbl_status.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbl_status.Location = new System.Drawing.Point(66, 41); - this.lbl_status.Name = "lbl_status"; - this.lbl_status.Size = new System.Drawing.Size(178, 13); - this.lbl_status.TabIndex = 30; - this.lbl_status.Text = "Processing.... Please Wait!"; - this.lbl_status.Visible = false; + this.scanProgress.Location = new System.Drawing.Point(22, 51); + this.scanProgress.Name = "scanProgress"; + this.scanProgress.Size = new System.Drawing.Size(361, 23); + this.scanProgress.TabIndex = 30; + this.scanProgress.Visible = false; // // frmReadDVD // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(473, 86); - this.Controls.Add(this.lbl_status); + this.Controls.Add(this.scanProgress); this.Controls.Add(this.lbl_pressOk); this.Controls.Add(this.btn_ok); this.Controls.Add(this.Label3); @@ -119,6 +116,6 @@ namespace Handbrake internal System.Windows.Forms.Button btn_ok; internal System.Windows.Forms.Label Label3; internal System.Windows.Forms.Label Label2; - internal System.Windows.Forms.Label lbl_status; + private System.Windows.Forms.ProgressBar scanProgress; } } \ No newline at end of file diff --git a/win/C#/frmReadDVD.cs b/win/C#/frmReadDVD.cs index 2958bdf65..eaecf823f 100644 --- a/win/C#/frmReadDVD.cs +++ b/win/C#/frmReadDVD.cs @@ -27,13 +27,15 @@ namespace Handbrake this.inputFile = inputFile; this.mainWindow = parent; this.dvdInfo = dvdInfoWindow; + Parsing.Parser.OnScanProgress += Parser_OnScanProgress; } private void btn_ok_Click(object sender, EventArgs e) { - lbl_status.Visible = true; btn_ok.Enabled = false; lbl_pressOk.Visible = false; + scanProgress.Value = 0; + scanProgress.Visible = true; // throw cli call and parsing on it's own thread ThreadPool.QueueUserWorkItem(startProc); } @@ -71,5 +73,15 @@ namespace Handbrake updateUIElements(); } + private void Parser_OnScanProgress(object Sender, int CurrentTitle, int TitleCount) + { + if (this.InvokeRequired) + { + this.BeginInvoke(new Parsing.ScanProgressEventHandler(Parser_OnScanProgress), new object[] { Sender, CurrentTitle, TitleCount }); + return; + } + this.scanProgress.Value = Convert.ToInt32(Convert.ToDouble(CurrentTitle) / Convert.ToDouble(TitleCount) * 100) + 1; + } + } } \ No newline at end of file