From ac1f7bafb2f980eda44bd93e507914ae8aa284dc Mon Sep 17 00:00:00 2001
From: sr55 <sr55.hb@outlook.com>
Date: Fri, 19 Dec 2008 13:57:08 +0000
Subject: [PATCH] WinGui: - Fixes for a few rather stupid issues with the new
 queue/mainwindow encode link. - Got rid of the queue encode progress bar.
 It's just a pain to keep it working and doesn't really offer much.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2040 b64f7644-9d1e-0410-96f1-a4d463321fa5
---
 win/C#/Properties/Settings.Designer.cs |   2 +-
 win/C#/Properties/Settings.settings    |   2 +-
 win/C#/app.config                      |   2 +-
 win/C#/frmMain.cs                      | 183 ++++++++++++++-----------
 win/C#/frmQueue.Designer.cs            |  46 ++-----
 win/C#/frmQueue.cs                     |  51 ++-----
 6 files changed, 127 insertions(+), 159 deletions(-)

diff --git a/win/C#/Properties/Settings.Designer.cs b/win/C#/Properties/Settings.Designer.cs
index 429e3503c..17391563f 100644
--- a/win/C#/Properties/Settings.Designer.cs
+++ b/win/C#/Properties/Settings.Designer.cs
@@ -301,7 +301,7 @@ namespace Handbrake.Properties {
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("T:\\\\Program Files\\\\VideoLAN\\\\vlc\\\\vlc.exe")]
+        [global::System.Configuration.DefaultSettingValueAttribute("T:\\Program Files\\VideoLAN\\vlc\\vlc.exe")]
         public string VLC_Path {
             get {
                 return ((string)(this["VLC_Path"]));
diff --git a/win/C#/Properties/Settings.settings b/win/C#/Properties/Settings.settings
index a65215306..42af2949d 100644
--- a/win/C#/Properties/Settings.settings
+++ b/win/C#/Properties/Settings.settings
@@ -72,7 +72,7 @@
       <Value Profile="(Default)" />
     </Setting>
     <Setting Name="VLC_Path" Type="System.String" Scope="User">
-      <Value Profile="(Default)">T:\\Program Files\\VideoLAN\\vlc\\vlc.exe</Value>
+      <Value Profile="(Default)">T:\Program Files\VideoLAN\vlc\vlc.exe</Value>
     </Setting>
     <Setting Name="MainWindowMinimize" Type="System.String" Scope="User">
       <Value Profile="(Default)">Checked</Value>
diff --git a/win/C#/app.config b/win/C#/app.config
index f6a004ded..dcaf46f71 100644
--- a/win/C#/app.config
+++ b/win/C#/app.config
@@ -77,7 +77,7 @@
                 <value />
             </setting>
             <setting name="VLC_Path" serializeAs="String">
-                <value>T:\\Program Files\\VideoLAN\\vlc\\vlc.exe</value>
+                <value>T:\Program Files\VideoLAN\vlc\vlc.exe</value>
             </setting>
             <setting name="MainWindowMinimize" serializeAs="String">
                 <value>Checked</value>
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs
index d5b70e363..6f971eb99 100644
--- a/win/C#/frmMain.cs
+++ b/win/C#/frmMain.cs
@@ -47,73 +47,80 @@ namespace Handbrake
 
         public frmMain()
         {
-            // Load the splash screen in this thread
-            Form splash = new frmSplashScreen();
-            splash.Show();
-
-            //Create a label that can be updated from the parent thread.
-            Label lblStatus = new Label();
-            lblStatus.Size = new Size(250, 20);
-            lblStatus.Location = new Point(10, 280);
-            splash.Controls.Add(lblStatus);
-            InitializeComponent();
-
-            // Update the users config file with the CLI version data.
-            lblStatus.Text = "Setting Version Data ...";
-            Application.DoEvents();
-            ArrayList x = hb_common_func.getCliVersionData();
-            Properties.Settings.Default.hb_build = int.Parse(x[1].ToString());
-            Properties.Settings.Default.hb_version = x[0].ToString();
-
-            // show the form, but leave disabled until preloading is complete then show the main form
-            this.Enabled = false;
-            this.Show();
-            Application.DoEvents(); // Forces frmMain to draw
-
-            // update the status
-            if (Properties.Settings.Default.updateStatus == "Checked")
-            {
-                lblStatus.Text = "Checking for updates ...";
+            try
+            {
+                // Load the splash screen in this thread
+                Form splash = new frmSplashScreen();
+                splash.Show();
+
+                //Create a label that can be updated from the parent thread.
+                Label lblStatus = new Label();
+                lblStatus.Size = new Size(250, 20);
+                lblStatus.Location = new Point(10, 280);
+                splash.Controls.Add(lblStatus);
+                InitializeComponent();
+
+                // Update the users config file with the CLI version data.
+                lblStatus.Text = "Setting Version Data ...";
                 Application.DoEvents();
-                Thread updateCheckThread = new Thread(startupUpdateCheck);
-                updateCheckThread.Start();
-            }
+                ArrayList x = hb_common_func.getCliVersionData();
+                Properties.Settings.Default.hb_build = int.Parse(x[1].ToString());
+                Properties.Settings.Default.hb_version = x[0].ToString();
 
-            // Setup the GUI components
-            lblStatus.Text = "Setting up the GUI ...";
-            Application.DoEvents();
-            x264PanelFunctions.reset2Defaults(this); // Initialize all the x264 widgets to their default values
-            loadPresetPanel();                       // Load the Preset Panel
-            treeView_presets.ExpandAll();
-            lbl_encode.Text = "";
-            queueWindow = new frmQueue(this);        // Prepare the Queue
+                // show the form, but leave disabled until preloading is complete then show the main form
+                this.Enabled = false;
+                this.Show();
+                Application.DoEvents(); // Forces frmMain to draw
 
-            // Load the user's default settings or Normal Preset
-            if (Properties.Settings.Default.defaultSettings == "Checked" && Properties.Settings.Default.defaultUserSettings != "")
-            {
-                Functions.QueryParser presetQuery = Functions.QueryParser.Parse(Properties.Settings.Default.defaultUserSettings);
-                presetLoader.presetLoader(this, presetQuery, "User Defaults ");
-            }
-            else
-                loadNormalPreset();
+                // update the status
+                if (Properties.Settings.Default.updateStatus == "Checked")
+                {
+                    lblStatus.Text = "Checking for updates ...";
+                    Application.DoEvents();
+                    Thread updateCheckThread = new Thread(startupUpdateCheck);
+                    updateCheckThread.Start();
+                }
 
-            // Enabled GUI tooltip's if Required
-            if (Properties.Settings.Default.tooltipEnable == "Checked")
-                ToolTip.Active = true;
+                // Setup the GUI components
+                lblStatus.Text = "Setting up the GUI ...";
+                Application.DoEvents();
+                x264PanelFunctions.reset2Defaults(this); // Initialize all the x264 widgets to their default values
+                loadPresetPanel();                       // Load the Preset Panel
+                treeView_presets.ExpandAll();
+                lbl_encode.Text = "";
+                queueWindow = new frmQueue(this);        // Prepare the Queue
 
-            //Finished Loading
-            lblStatus.Text = "Loading Complete!";
-            Application.DoEvents();
-            splash.Close();
-            splash.Dispose();
-            this.Enabled = true;
+                // Load the user's default settings or Normal Preset
+                if (Properties.Settings.Default.defaultSettings == "Checked" && Properties.Settings.Default.defaultUserSettings != "")
+                {
+                    Functions.QueryParser presetQuery = Functions.QueryParser.Parse(Properties.Settings.Default.defaultUserSettings);
+                    presetLoader.presetLoader(this, presetQuery, "User Defaults ");
+                }
+                else
+                    loadNormalPreset();
 
-            // Event Handlers
-            if (Properties.Settings.Default.MainWindowMinimize == "Checked")
-                this.Resize += new EventHandler(frmMain_Resize);
+                // Enabled GUI tooltip's if Required
+                if (Properties.Settings.Default.tooltipEnable == "Checked")
+                    ToolTip.Active = true;
 
-            // Queue Recovery
-            queueRecovery();
+                //Finished Loading
+                lblStatus.Text = "Loading Complete!";
+                Application.DoEvents();
+                splash.Close();
+                splash.Dispose();
+                this.Enabled = true;
+
+                // Event Handlers
+                if (Properties.Settings.Default.MainWindowMinimize == "Checked")
+                    this.Resize += new EventHandler(frmMain_Resize);
+
+                // Queue Recovery
+                queueRecovery();
+            }
+            catch (Exception e)
+            {
+                MessageBox.Show("Error at startup: \n\n" + e);
+            }
         }
 
         // Startup Functions
@@ -457,30 +464,47 @@ namespace Handbrake
         }
         private void btn_start_Click(object sender, EventArgs e)
         {
-            if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)
-                MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+            if (btn_start.Text == "Stop")
+            {
+                DialogResult result = MessageBox.Show("Are you sure you wish to cancel the encode? Please note that this may break the encoded file. \nTo safely cancel your encode, press ctrl-c on your keyboard in the CLI window. This *may* allow you to preview your encoded content.", "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+
+                if (result == DialogResult.Yes)
+                {
+                    queueWindow.frmMain_cancelEncode();
+                    if (!queueWindow.isEncoding())
+                        setEncodeStatus(0);
+                }
+            }
             else
             {
-                // Set the last action to encode. 
-                // This is used for tracking which file to load in the activity window
-                lastAction = "encode";
+                if (encodeQueue.count() != 0 || (text_source.Text != string.Empty && text_source.Text != "Click 'Source' to continue" && text_destination.Text != string.Empty))
+                {
+                    // Set the last action to encode. 
+                    // This is used for tracking which file to load in the activity window
+                    lastAction = "encode";
 
-                String query;
-                if (rtf_query.Text != "")
-                    query = rtf_query.Text;
-                else
-                    query = queryGen.GenerateTheQuery(this);
+                    String query;
+                    if (rtf_query.Text != "")
+                        query = rtf_query.Text;
+                    else
+                        query = queryGen.GenerateTheQuery(this);
 
-                if (encodeQueue.count() == 0)
-                {
-                    encodeQueue.add(query, text_source.Text, text_destination.Text);
-                    encodeQueue.write2disk("hb_queue_recovery.xml");
+                    if (encodeQueue.count() == 0)
+                    {
+                        encodeQueue.add(query, text_source.Text, text_destination.Text);
+                        encodeQueue.write2disk("hb_queue_recovery.xml");
+                    }
+                    queueWindow.setQueue(encodeQueue);
+                    if (encodeQueue.count() > 1)
+                        queueWindow.Show();
+
+                    queueWindow.frmMain_encode();
+
+                    setEncodeStatus(1); // Encode is running, so setup the GUI appropriately
                 }
-                queueWindow.setQueue(encodeQueue);
-                queueWindow.Show();
-                queueWindow.frmMain_encode();
+                else if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)
+                    MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
 
-                setEncodeStatus(1); // Encode is running, so setup the GUI appropriately
             }
         }
         private void btn_add2Queue_Click(object sender, EventArgs e)
@@ -1962,9 +1986,6 @@ namespace Handbrake
 
         #endregion
 
-
-
-
         // This is the END of the road ------------------------------------------------------------------------------
     }
 }
\ No newline at end of file
diff --git a/win/C#/frmQueue.Designer.cs b/win/C#/frmQueue.Designer.cs
index bb0635c7a..0682c3c85 100644
--- a/win/C#/frmQueue.Designer.cs
+++ b/win/C#/frmQueue.Designer.cs
@@ -67,9 +67,6 @@ namespace Handbrake
             this.Audio = new System.Windows.Forms.ColumnHeader();
             this.statusStrip1 = new System.Windows.Forms.StatusStrip();
             this.lbl_encodesPending = new System.Windows.Forms.ToolStripStatusLabel();
-            this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
-            this.progressBar = new System.Windows.Forms.ToolStripProgressBar();
-            this.lbl_progressValue = new System.Windows.Forms.ToolStripStatusLabel();
             this.OpenFile = new System.Windows.Forms.OpenFileDialog();
             this.splitContainer1 = new System.Windows.Forms.SplitContainer();
             this.panel3 = new System.Windows.Forms.Panel();
@@ -316,7 +313,7 @@ namespace Handbrake
             this.list_queue.Location = new System.Drawing.Point(15, 0);
             this.list_queue.MultiSelect = false;
             this.list_queue.Name = "list_queue";
-            this.list_queue.Size = new System.Drawing.Size(749, 210);
+            this.list_queue.Size = new System.Drawing.Size(749, 219);
             this.list_queue.TabIndex = 72;
             this.list_queue.UseCompatibleStateImageBehavior = false;
             this.list_queue.View = System.Windows.Forms.View.Details;
@@ -355,13 +352,10 @@ namespace Handbrake
             // statusStrip1
             // 
             this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
-            this.lbl_encodesPending,
-            this.toolStripStatusLabel1,
-            this.progressBar,
-            this.lbl_progressValue});
-            this.statusStrip1.Location = new System.Drawing.Point(0, 359);
+            this.lbl_encodesPending});
+            this.statusStrip1.Location = new System.Drawing.Point(0, 368);
             this.statusStrip1.Name = "statusStrip1";
-            this.statusStrip1.Size = new System.Drawing.Size(779, 31);
+            this.statusStrip1.Size = new System.Drawing.Size(779, 22);
             this.statusStrip1.TabIndex = 73;
             this.statusStrip1.Text = "statusStrip1";
             // 
@@ -370,28 +364,9 @@ namespace Handbrake
             this.lbl_encodesPending.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
             this.lbl_encodesPending.Margin = new System.Windows.Forms.Padding(0, 3, 10, 2);
             this.lbl_encodesPending.Name = "lbl_encodesPending";
-            this.lbl_encodesPending.Size = new System.Drawing.Size(122, 26);
+            this.lbl_encodesPending.Size = new System.Drawing.Size(122, 17);
             this.lbl_encodesPending.Text = "0 encode(s) pending";
             // 
-            // toolStripStatusLabel1
-            // 
-            this.toolStripStatusLabel1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
-            this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
-            this.toolStripStatusLabel1.Size = new System.Drawing.Size(57, 26);
-            this.toolStripStatusLabel1.Text = "Progress:";
-            // 
-            // progressBar
-            // 
-            this.progressBar.Name = "progressBar";
-            this.progressBar.Size = new System.Drawing.Size(500, 25);
-            this.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
-            // 
-            // lbl_progressValue
-            // 
-            this.lbl_progressValue.Name = "lbl_progressValue";
-            this.lbl_progressValue.Size = new System.Drawing.Size(34, 26);
-            this.lbl_progressValue.Text = " 0 %";
-            // 
             // OpenFile
             // 
             this.OpenFile.Filter = "HandBrake Queue|*.queue";
@@ -426,7 +401,7 @@ namespace Handbrake
             this.splitContainer1.Panel2.Controls.Add(this.panel3);
             this.splitContainer1.Panel2.Controls.Add(this.panel2);
             this.splitContainer1.Panel2.Controls.Add(this.panel1);
-            this.splitContainer1.Size = new System.Drawing.Size(779, 320);
+            this.splitContainer1.Size = new System.Drawing.Size(779, 329);
             this.splitContainer1.SplitterDistance = 94;
             this.splitContainer1.SplitterWidth = 1;
             this.splitContainer1.TabIndex = 74;
@@ -434,7 +409,7 @@ namespace Handbrake
             // panel3
             // 
             this.panel3.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.panel3.Location = new System.Drawing.Point(15, 210);
+            this.panel3.Location = new System.Drawing.Point(15, 219);
             this.panel3.Name = "panel3";
             this.panel3.Size = new System.Drawing.Size(749, 15);
             this.panel3.TabIndex = 77;
@@ -444,7 +419,7 @@ namespace Handbrake
             this.panel2.Dock = System.Windows.Forms.DockStyle.Right;
             this.panel2.Location = new System.Drawing.Point(764, 0);
             this.panel2.Name = "panel2";
-            this.panel2.Size = new System.Drawing.Size(15, 225);
+            this.panel2.Size = new System.Drawing.Size(15, 234);
             this.panel2.TabIndex = 76;
             // 
             // panel1
@@ -452,7 +427,7 @@ namespace Handbrake
             this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
             this.panel1.Location = new System.Drawing.Point(0, 0);
             this.panel1.Name = "panel1";
-            this.panel1.Size = new System.Drawing.Size(15, 225);
+            this.panel1.Size = new System.Drawing.Size(15, 234);
             this.panel1.TabIndex = 75;
             // 
             // frmQueue
@@ -510,9 +485,6 @@ namespace Handbrake
         private System.Windows.Forms.ColumnHeader EncoderVideo;
         private System.Windows.Forms.ColumnHeader Audio;
         private System.Windows.Forms.StatusStrip statusStrip1;
-        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
-        private System.Windows.Forms.ToolStripProgressBar progressBar;
-        private System.Windows.Forms.ToolStripStatusLabel lbl_progressValue;
         private System.Windows.Forms.ToolStripDropDownButton drop_button_queue;
         private System.Windows.Forms.ToolStripMenuItem mnu_batch;
         private System.Windows.Forms.ToolStripMenuItem mnu_import;
diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs
index 648deef89..ed1eb5a9b 100644
--- a/win/C#/frmQueue.cs
+++ b/win/C#/frmQueue.cs
@@ -44,18 +44,6 @@ namespace Handbrake
             queue = qw;
             redrawQueue();
             lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
-
-            // Recalculate the progress bar, but only if the queue has already started.       
-            if (progressBar.Value != 0)
-            {
-                progressBar.Value = 0;
-                if (queue.count() == 0)
-                    progressBar.Step = 100;
-                else
-                    progressBar.Step = 100 / queue.count();
-                progressBar.PerformStep();
-                lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
-            }
         }
 
         /// <summary>
@@ -84,12 +72,7 @@ namespace Handbrake
                     // Setup or reset some values
                     btn_encode.Enabled = false;
                     btn_stop.Visible = true;
-                    progressBar.Value = 0;
-                    lbl_progressValue.Text = "0 %";
-                    if (queue.count() == 0)
-                        progressBar.Step = 100;
-                    else
-                        progressBar.Step = 100 / queue.count();
+
                     Thread theQ = new Thread(startProc);
                     theQ.IsBackground = true;
                     theQ.Start();
@@ -101,6 +84,17 @@ namespace Handbrake
             }
         }
 
+        public void frmMain_cancelEncode()
+        {
+            Process[] aProc = Process.GetProcessesByName("HandBrakeCLI");
+            Process HandBrakeCLI;
+            if (aProc.Length > 0)
+            {
+                HandBrakeCLI = aProc[0];
+                HandBrakeCLI.Kill();
+            }
+        }
+
         // Redraw's the queue with the latest data from the Queue class
         private void redrawQueue()
         {
@@ -158,12 +152,7 @@ namespace Handbrake
                     // Setup or reset some values
                     btn_encode.Enabled = false;
                     btn_stop.Visible = true;
-                    progressBar.Value = 0;
-                    lbl_progressValue.Text = "0 %";
-                    if (queue.count() == 0)
-                        progressBar.Step = 100;
-                    else
-                        progressBar.Step = 100 / queue.count();
+
                     Thread theQ = new Thread(startProc);
                     theQ.IsBackground = true;
                     theQ.Start();
@@ -233,17 +222,6 @@ namespace Handbrake
                 btn_stop.Visible = false;
                 btn_encode.Enabled = true;
 
-                if (cancel == true)
-                {
-                    lbl_progressValue.Text = "Encode Queue Cancelled!";
-                }
-                else
-                {
-                    lbl_progressValue.Text = "Encode Queue Completed!";
-                }
-
-                progressBar.Value = 0;
-
                 lbl_source.Text = "-";
                 lbl_dest.Text = "-";
                 lbl_vEnc.Text = "-";
@@ -280,9 +258,6 @@ namespace Handbrake
                 }
 
                 redrawQueue();
-
-                progressBar.PerformStep();
-                lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
                 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
             }
             catch (Exception exc)
-- 
2.40.0