OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 15 Jan 2010 22:12:34 +0000 (22:12 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 15 Jan 2010 22:12:34 +0000 (22:12 +0000)
- Bit of re-factoring to the encode / queue code.

git-svn-id: svn://localhost/HandBrake/trunk@3071 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/EncodeQueue/Encode.cs [new file with mode: 0644]
win/C#/EncodeQueue/Job.cs
win/C#/EncodeQueue/Queue.cs [moved from win/C#/EncodeQueue/EncodeAndQueueHandler.cs with 53% similarity]
win/C#/HandBrakeCS.csproj
win/C#/frmMain.cs
win/C#/frmPreview.cs
win/C#/frmQueue.cs

diff --git a/win/C#/EncodeQueue/Encode.cs b/win/C#/EncodeQueue/Encode.cs
new file mode 100644 (file)
index 0000000..8061bc3
--- /dev/null
@@ -0,0 +1,215 @@
+/*  Encode.cs $\r
+       \r
+          This file is part of the HandBrake source code.\r
+          Homepage: <http://handbrake.fr/>.\r
+          It may be used under the terms of the GNU General Public License. */\r
+\r
+using System;\r
+using System.Diagnostics;\r
+using System.IO;\r
+using System.Windows.Forms;\r
+using Handbrake.Functions;\r
+\r
+namespace Handbrake.EncodeQueue\r
+{\r
+    public class Encode\r
+    {\r
+        public Process HbProcess { get; set; }\r
+        public int ProcessID { get; set; }\r
+        public IntPtr ProcessHandle { get; set; }\r
+        public String CurrentQuery { get; set; }\r
+        public Boolean IsEncoding { get; set; }\r
+\r
+        public event EventHandler EncodeStarted;\r
+        public event EventHandler EncodeEnded;\r
+\r
+        /// <summary>\r
+        /// Create a preview sample video\r
+        /// </summary>\r
+        /// <param name="query"></param>\r
+        public void CreatePreviewSampe(string query)\r
+        {\r
+            Run(query);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Execute a HandBrakeCLI process.\r
+        /// </summary>\r
+        /// <param name="query">The CLI Query</param>\r
+        protected void Run(string query)\r
+        {\r
+            try\r
+            {\r
+                if (EncodeStarted != null)\r
+                    EncodeStarted(this, new EventArgs());\r
+\r
+                IsEncoding = true;\r
+\r
+                string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
+                string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs", "last_encode_log.txt");\r
+                string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);\r
+                ProcessStartInfo cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);\r
+\r
+                if (Properties.Settings.Default.enocdeStatusInGui)\r
+                {\r
+                    cliStart.RedirectStandardOutput = true;\r
+                    cliStart.UseShellExecute = false;\r
+                }\r
+                if (Properties.Settings.Default.cli_minimized)\r
+                    cliStart.WindowStyle = ProcessWindowStyle.Minimized;\r
+\r
+                Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.\r
+                HbProcess = Process.Start(cliStart);\r
+                ProcessID = Main.GetCliProcess(before);\r
+                CurrentQuery = query;\r
+                if (HbProcess != null)\r
+                    ProcessHandle = HbProcess.MainWindowHandle; // Set the process Handle\r
+\r
+                // Set the process Priority\r
+                Process hbCliProcess = null;\r
+                if (ProcessID != -1)\r
+                    hbCliProcess = Process.GetProcessById(ProcessID);\r
+\r
+                if (hbCliProcess != null)\r
+                    switch (Properties.Settings.Default.processPriority)\r
+                    {\r
+                        case "Realtime":\r
+                            hbCliProcess.PriorityClass = ProcessPriorityClass.RealTime;\r
+                            break;\r
+                        case "High":\r
+                            hbCliProcess.PriorityClass = ProcessPriorityClass.High;\r
+                            break;\r
+                        case "Above Normal":\r
+                            hbCliProcess.PriorityClass = ProcessPriorityClass.AboveNormal;\r
+                            break;\r
+                        case "Normal":\r
+                            hbCliProcess.PriorityClass = ProcessPriorityClass.Normal;\r
+                            break;\r
+                        case "Low":\r
+                            hbCliProcess.PriorityClass = ProcessPriorityClass.Idle;\r
+                            break;\r
+                        default:\r
+                            hbCliProcess.PriorityClass = ProcessPriorityClass.BelowNormal;\r
+                            break;\r
+                    }\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show("It would appear that HandBrakeCLI has not started correctly. You should take a look at the Activity log as it may indicate the reason why.\n\n   Detailed Error Information: error occured in runCli()\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Kill the CLI process\r
+        /// </summary>\r
+        protected void Stop()\r
+        {\r
+            if (EncodeEnded != null)\r
+                EncodeEnded(this, new EventArgs());\r
+\r
+            if (HbProcess != null)\r
+                HbProcess.Kill();\r
+            IsEncoding = false;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Perform an action after an encode. e.g a shutdown, standby, restart etc.\r
+        /// </summary>\r
+        protected void Finish()\r
+        {\r
+            IsEncoding = false;\r
+            CurrentQuery = String.Empty;\r
+\r
+            //Growl\r
+            if (Properties.Settings.Default.growlQueue)\r
+                GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");\r
+\r
+            // Do something whent he encode ends.\r
+            switch (Properties.Settings.Default.CompletionOption)\r
+            {\r
+                case "Shutdown":\r
+                    Process.Start("Shutdown", "-s -t 60");\r
+                    break;\r
+                case "Log Off":\r
+                    Win32.ExitWindowsEx(0, 0);\r
+                    break;\r
+                case "Suspend":\r
+                    Application.SetSuspendState(PowerState.Suspend, true, true);\r
+                    break;\r
+                case "Hibernate":\r
+                    Application.SetSuspendState(PowerState.Hibernate, true, true);\r
+                    break;\r
+                case "Lock System":\r
+                    Win32.LockWorkStation();\r
+                    break;\r
+                case "Quit HandBrake":\r
+                    Application.Exit();\r
+                    break;\r
+                default:\r
+                    break;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Add the CLI Query to the Log File.\r
+        /// </summary>\r
+        /// <param name="encJob"></param>\r
+        protected void AddCLIQueryToLog(Job encJob)\r
+        {\r
+            string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+            string logPath = Path.Combine(logDir, "last_encode_log.txt");\r
+\r
+            StreamReader reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read));\r
+            String log = reader.ReadToEnd();\r
+            reader.Close();\r
+\r
+            StreamWriter writer = new StreamWriter(File.Create(logPath));\r
+\r
+            writer.Write("### CLI Query: " + encJob.Query + "\n\n");\r
+            writer.Write("### User Query: " + encJob.CustomQuery + "\n\n");\r
+            writer.Write("#########################################\n\n");\r
+            writer.WriteLine(log);\r
+            writer.Flush();\r
+            writer.Close();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Save a copy of the log to the users desired location or a default location\r
+        /// if this feature is enabled in options.\r
+        /// </summary>\r
+        /// <param name="destination"></param>\r
+        protected void CopyLog(string destination)\r
+        {\r
+            try\r
+            {\r
+                string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+                string tempLogFile = Path.Combine(logDir, "last_encode_log.txt");\r
+\r
+                string encodeDestinationPath = Path.GetDirectoryName(destination);\r
+                String destinationFile = Path.GetFileName(destination);\r
+                string encodeLogFile = destinationFile + " " + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".txt";\r
+\r
+                // Make sure the log directory exists.\r
+                if (!Directory.Exists(logDir))\r
+                    Directory.CreateDirectory(logDir);\r
+\r
+                // Copy the Log to HandBrakes log folder in the users applciation data folder.\r
+                File.Copy(tempLogFile, Path.Combine(logDir, encodeLogFile));\r
+\r
+                // Save a copy of the log file in the same location as the enocde.\r
+                if (Properties.Settings.Default.saveLogWithVideo)\r
+                    File.Copy(tempLogFile, Path.Combine(encodeDestinationPath, encodeLogFile));\r
+\r
+                // Save a copy of the log file to a user specified location\r
+                if (Directory.Exists(Properties.Settings.Default.saveLogPath))\r
+                    if (Properties.Settings.Default.saveLogPath != String.Empty && Properties.Settings.Default.saveLogToSpecifiedPath)\r
+                        File.Copy(tempLogFile, Path.Combine(Properties.Settings.Default.saveLogPath, encodeLogFile));\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show("Something went a bit wrong trying to copy your log file.\nError Information:\n\n" + exc, "Error",\r
+                                MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+            }\r
+        }\r
+    }\r
+}
\ No newline at end of file
index 7dfe7e5..5771ece 100644 (file)
@@ -5,6 +5,7 @@
           It may be used under the terms of the GNU General Public License. */\r
 \r
 using System;\r
+using Handbrake.Parsing;\r
 \r
 namespace Handbrake.EncodeQueue\r
 {\r
similarity index 53%
rename from win/C#/EncodeQueue/EncodeAndQueueHandler.cs
rename to win/C#/EncodeQueue/Queue.cs
index fce6729..f279a97 100644 (file)
@@ -1,4 +1,4 @@
-/*  EncodeAndQueueHandler.cs $\r
+/*  Queue.cs $\r
        \r
           This file is part of the HandBrake source code.\r
           Homepage: <http://handbrake.fr/>.\r
@@ -7,20 +7,20 @@
 using System;\r
 using System.Collections.Generic;\r
 using System.Collections.ObjectModel;\r
-using System.Diagnostics;\r
 using System.IO;\r
 using System.Threading;\r
 using System.Windows.Forms;\r
 using System.Xml.Serialization;\r
 using Handbrake.Functions;\r
+using Handbrake.Parsing;\r
 \r
 namespace Handbrake.EncodeQueue\r
 {\r
-    public class EncodeAndQueueHandler\r
+    public class Queue : Encode\r
     {\r
         private static XmlSerializer serializer;\r
-        private List<Job> queue = new List<Job>();\r
-        private int nextJobId;\r
+        private readonly List<Job> queue = new List<Job>();\r
+        private int NextJobId;\r
 \r
         #region Event Handlers\r
         /// <summary>\r
@@ -53,7 +53,7 @@ namespace Handbrake.EncodeQueue
         {\r
             Job job = queue[0];\r
             LastEncode = job;\r
-            RemoveJob(0); // Remove the item which we are about to pass out.\r
+            Remove(0); // Remove the item which we are about to pass out.\r
 \r
             WriteQueueStateToFile("hb_queue_recovery.xml");\r
 \r
@@ -82,10 +82,11 @@ namespace Handbrake.EncodeQueue
         /// <param name="query">The query that will be passed to the HandBrake CLI.</param>\r
         /// <param name="source">The location of the source video.</param>\r
         /// <param name="destination">The location where the encoded video will be.</param>\r
-        /// <param name="customJob"></param>\r
-        public void AddJob(string query, string source, string destination, bool customJob)\r
+        /// <param name="customJob">Custom job</param>\r
+        /// <param name="scanInfo">The Scan</param>\r
+        public void Add(string query, string source, string destination, bool customJob)\r
         {\r
-            Job newJob = new Job { Id = nextJobId++, Query = query, Source = source, Destination = destination, CustomQuery = customJob };\r
+            Job newJob = new Job { Id = NextJobId++, Query = query, Source = source, Destination = destination, CustomQuery = customJob };\r
 \r
             queue.Add(newJob);\r
             WriteQueueStateToFile("hb_queue_recovery.xml");\r
@@ -95,7 +96,7 @@ namespace Handbrake.EncodeQueue
         /// Removes an item from the queue.\r
         /// </summary>\r
         /// <param name="index">The zero-based location of the job in the queue.</param>\r
-        public void RemoveJob(int index)\r
+        public void Remove(int index)\r
         {\r
             queue.RemoveAt(index);\r
             WriteQueueStateToFile("hb_queue_recovery.xml");\r
@@ -268,7 +269,7 @@ namespace Handbrake.EncodeQueue
         /// Starts encoding the first job in the queue and continues encoding until all jobs\r
         /// have been encoded.\r
         /// </summary>\r
-        public void StartEncodeQueue()\r
+        public void Start()\r
         {\r
             if (this.Count != 0)\r
             {\r
@@ -279,7 +280,7 @@ namespace Handbrake.EncodeQueue
                     PauseRequested = false;\r
                     try\r
                     {\r
-                        Thread theQueue = new Thread(startProcess) { IsBackground = true };\r
+                        Thread theQueue = new Thread(StartQueue) { IsBackground = true };\r
                         theQueue.Start();\r
                     }\r
                     catch (Exception exc)\r
@@ -293,7 +294,7 @@ namespace Handbrake.EncodeQueue
         /// <summary>\r
         /// Requests a pause of the encode queue.\r
         /// </summary>\r
-        public void RequestPause()\r
+        public void Pause()\r
         {\r
             PauseRequested = true;\r
 \r
@@ -304,12 +305,12 @@ namespace Handbrake.EncodeQueue
         /// <summary>\r
         /// Stops the current job.\r
         /// </summary>\r
-        public void EndEncodeJob()\r
+        public void End()\r
         {\r
-            CloseCLI();\r
+            Stop();\r
         }\r
 \r
-        private void startProcess(object state)\r
+        private void StartQueue(object state)\r
         {\r
             // Run through each item on the queue\r
             while (this.Count != 0)\r
@@ -318,20 +319,20 @@ namespace Handbrake.EncodeQueue
                 string query = encJob.Query;\r
                 WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file\r
 \r
-                RunCli(query);\r
+                Run(query);\r
 \r
                 if (NewJobStarted != null)\r
                     NewJobStarted(this, new EventArgs());\r
 \r
-                hbProcess.WaitForExit();\r
+                HbProcess.WaitForExit();\r
 \r
                 AddCLIQueryToLog(encJob);\r
                 CopyLog(LastEncode.Destination);\r
 \r
-                hbProcess.Close();\r
-                hbProcess.Dispose();\r
+                HbProcess.Close();\r
+                HbProcess.Dispose();\r
 \r
-                isEncoding = false;\r
+                IsEncoding = false;\r
 \r
                 //Growl\r
                 if (Properties.Settings.Default.growlEncode)\r
@@ -342,7 +343,7 @@ namespace Handbrake.EncodeQueue
 \r
                 while (PauseRequested) // Need to find a better way of doing this.\r
                 {\r
-                    Thread.Sleep(5000);\r
+                    Thread.Sleep(2000);\r
                 }\r
             }\r
             LastEncode = new Job();\r
@@ -351,190 +352,9 @@ namespace Handbrake.EncodeQueue
                 QueueCompleted(this, new EventArgs());\r
 \r
             // After the encode is done, we may want to shutdown, suspend etc.\r
-            AfterEncodeAction();\r
+            Finish();\r
         }\r
 \r
         #endregion\r
-\r
-        #region CLI and Log Handling\r
-        public Process hbProcess { get; set; }\r
-        public int processID { get; set; }\r
-        public IntPtr processHandle { get; set; }\r
-        public String currentQuery { get; set; }\r
-        public Boolean isEncoding { get; set; }\r
-\r
-        /// <summary>\r
-        /// Execute a HandBrakeCLI process.\r
-        /// </summary>\r
-        /// <param name="query">The CLI Query</param>\r
-        public void RunCli(string query)\r
-        {\r
-            try\r
-            {\r
-                isEncoding = true;\r
-\r
-                string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
-                string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs", "last_encode_log.txt");\r
-                string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);\r
-                ProcessStartInfo cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);\r
-\r
-                if (Properties.Settings.Default.enocdeStatusInGui)\r
-                {\r
-                    cliStart.RedirectStandardOutput = true;\r
-                    cliStart.UseShellExecute = false;\r
-                }\r
-                if (Properties.Settings.Default.cli_minimized)\r
-                    cliStart.WindowStyle = ProcessWindowStyle.Minimized;\r
-\r
-                Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.\r
-                hbProcess = Process.Start(cliStart);\r
-                processID = Main.GetCliProcess(before);\r
-                currentQuery = query;\r
-                if (hbProcess != null)\r
-                    processHandle = hbProcess.MainWindowHandle; // Set the process Handle\r
-\r
-                // Set the process Priority\r
-                Process hbCliProcess = null;\r
-                if (processID != -1)\r
-                    hbCliProcess = Process.GetProcessById(processID);\r
-\r
-                if (hbCliProcess != null)\r
-                    switch (Properties.Settings.Default.processPriority)\r
-                    {\r
-                        case "Realtime":\r
-                            hbCliProcess.PriorityClass = ProcessPriorityClass.RealTime;\r
-                            break;\r
-                        case "High":\r
-                            hbCliProcess.PriorityClass = ProcessPriorityClass.High;\r
-                            break;\r
-                        case "Above Normal":\r
-                            hbCliProcess.PriorityClass = ProcessPriorityClass.AboveNormal;\r
-                            break;\r
-                        case "Normal":\r
-                            hbCliProcess.PriorityClass = ProcessPriorityClass.Normal;\r
-                            break;\r
-                        case "Low":\r
-                            hbCliProcess.PriorityClass = ProcessPriorityClass.Idle;\r
-                            break;\r
-                        default:\r
-                            hbCliProcess.PriorityClass = ProcessPriorityClass.BelowNormal;\r
-                            break;\r
-                    }\r
-            }\r
-            catch (Exception exc)\r
-            {\r
-                MessageBox.Show("It would appear that HandBrakeCLI has not started correctly. You should take a look at the Activity log as it may indicate the reason why.\n\n   Detailed Error Information: error occured in runCli()\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Kill the CLI process\r
-        /// </summary>\r
-        private void CloseCLI()\r
-        {\r
-            hbProcess.Kill();\r
-            isEncoding = false;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Perform an action after an encode. e.g a shutdown, standby, restart etc.\r
-        /// </summary>\r
-        private void AfterEncodeAction()\r
-        {\r
-            isEncoding = false;\r
-            currentQuery = String.Empty;\r
-\r
-            //Growl\r
-            if (Properties.Settings.Default.growlQueue)\r
-                GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");\r
-\r
-            // Do something whent he encode ends.\r
-            switch (Properties.Settings.Default.CompletionOption)\r
-            {\r
-                case "Shutdown":\r
-                    Process.Start("Shutdown", "-s -t 60");\r
-                    break;\r
-                case "Log Off":\r
-                    Win32.ExitWindowsEx(0, 0);\r
-                    break;\r
-                case "Suspend":\r
-                    Application.SetSuspendState(PowerState.Suspend, true, true);\r
-                    break;\r
-                case "Hibernate":\r
-                    Application.SetSuspendState(PowerState.Hibernate, true, true);\r
-                    break;\r
-                case "Lock System":\r
-                    Win32.LockWorkStation();\r
-                    break;\r
-                case "Quit HandBrake":\r
-                    Application.Exit();\r
-                    break;\r
-                default:\r
-                    break;\r
-            }\r
-        }\r
-\r
-        /// <summar>\r
-        /// Append the CLI query to the start of the log file.\r
-        /// </summary>\r
-        /// <param name="query"></param>\r
-        private static void AddCLIQueryToLog(Job encJob)\r
-        {\r
-            string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
-            string logPath = Path.Combine(logDir, "last_encode_log.txt");\r
-\r
-            StreamReader reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read));\r
-            String log = reader.ReadToEnd();\r
-            reader.Close();\r
-\r
-            StreamWriter writer = new StreamWriter(File.Create(logPath));\r
-\r
-            writer.Write("### CLI Query: " + encJob.Query + "\n\n");\r
-            writer.Write("### User Query: " + encJob.CustomQuery + "\n\n");\r
-            writer.Write("#########################################\n\n");\r
-            writer.WriteLine(log);\r
-            writer.Flush();\r
-            writer.Close();\r
-        }\r
-\r
-        /// <summary>\r
-        /// Save a copy of the log to the users desired location or a default location\r
-        /// if this feature is enabled in options.\r
-        /// </summary>\r
-        /// <param name="destination"></param>\r
-        private static void CopyLog(string destination)\r
-        {\r
-            try\r
-            {\r
-                string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
-                string tempLogFile = Path.Combine(logDir, "last_encode_log.txt");\r
-\r
-                string encodeDestinationPath = Path.GetDirectoryName(destination);\r
-                String destinationFile = Path.GetFileName(destination);\r
-                string encodeLogFile = destinationFile + " " + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".txt";\r
-\r
-                // Make sure the log directory exists.\r
-                if (!Directory.Exists(logDir))\r
-                    Directory.CreateDirectory(logDir);\r
-\r
-                // Copy the Log to HandBrakes log folder in the users applciation data folder.\r
-                File.Copy(tempLogFile, Path.Combine(logDir, encodeLogFile));\r
-\r
-                // Save a copy of the log file in the same location as the enocde.\r
-                if (Properties.Settings.Default.saveLogWithVideo)\r
-                    File.Copy(tempLogFile, Path.Combine(encodeDestinationPath, encodeLogFile));\r
-\r
-                // Save a copy of the log file to a user specified location\r
-                if (Directory.Exists(Properties.Settings.Default.saveLogPath))\r
-                    if (Properties.Settings.Default.saveLogPath != String.Empty && Properties.Settings.Default.saveLogToSpecifiedPath)\r
-                        File.Copy(tempLogFile, Path.Combine(Properties.Settings.Default.saveLogPath, encodeLogFile));\r
-            }\r
-            catch (Exception exc)\r
-            {\r
-                MessageBox.Show("Something went a bit wrong trying to copy your log file.\nError Information:\n\n" + exc, "Error",\r
-                                MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-            }\r
-        }\r
-        #endregion\r
     }\r
 }
\ No newline at end of file
index c31e0ff..6123b2c 100644 (file)
     <Compile Include="Controls\x264Panel.Designer.cs">\r
       <DependentUpon>x264Panel.cs</DependentUpon>\r
     </Compile>\r
+    <Compile Include="EncodeQueue\Encode.cs" />\r
     <Compile Include="frmPreview.cs">\r
       <SubType>Form</SubType>\r
     </Compile>\r
     <Compile Include="Presets\Import.cs" />\r
     <Compile Include="Presets\preset.cs" />\r
     <Compile Include="Presets\PresetsHandler.cs" />\r
-    <Compile Include="EncodeQueue\EncodeAndQueueHandler.cs" />\r
+    <Compile Include="EncodeQueue\Queue.cs" />\r
     <Compile Include="Functions\AppcastReader.cs" />\r
     <Compile Include="Functions\QueryParser.cs" />\r
     <Compile Include="Parsing\AudioTrack.cs" />\r
index cfcc727..822e8a7 100644 (file)
@@ -22,7 +22,7 @@ namespace Handbrake
     public partial class frmMain : Form\r
     {\r
         // Objects which may be used by one or more other objects *************\r
-        EncodeAndQueueHandler encodeQueue = new EncodeAndQueueHandler();\r
+        Queue encodeQueue = new Queue();\r
         PresetsHandler presetHandler = new PresetsHandler();\r
         QueryGenerator queryGen = new QueryGenerator();\r
 \r
@@ -38,6 +38,7 @@ namespace Handbrake
         private string dvdDrivePath;\r
         private string dvdDriveLabel;\r
         private Preset CurrentlySelectedPreset;\r
+        private DVD currentSource;\r
 \r
         // Delegates **********************************************************\r
         private delegate void UpdateWindowHandler();\r
@@ -667,10 +668,10 @@ namespace Handbrake
                 if (result == DialogResult.Yes)\r
                 {\r
                     // Pause The Queue\r
-                    encodeQueue.RequestPause();\r
+                    encodeQueue.Pause();\r
 \r
                     // Allow the CLI to exit cleanly\r
-                    Win32.SetForegroundWindow((int)encodeQueue.processHandle);\r
+                    Win32.SetForegroundWindow((int)encodeQueue.ProcessHandle);\r
                     SendKeys.Send("^C");\r
 \r
                     // Update the GUI\r
@@ -726,14 +727,14 @@ namespace Handbrake
                     if (overwrite == DialogResult.Yes)\r
                     {\r
                         if (encodeQueue.Count == 0)\r
-                            encodeQueue.AddJob(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
+                            encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
 \r
-                        queueWindow.setQueue();\r
+                        queueWindow.SetQueue();\r
                         if (encodeQueue.Count > 1)\r
                             queueWindow.Show(false);\r
 \r
                         setEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
-                        encodeQueue.StartEncodeQueue(); // Start The Queue Encoding Process\r
+                        encodeQueue.Start(); // Start The Queue Encoding Process\r
                         lastAction = "encode";   // Set the last action to encode - Used for activity window.\r
                     }\r
                     if (ActivityWindow != null)\r
@@ -760,11 +761,11 @@ namespace Handbrake
                     DialogResult result = MessageBox.Show("There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?",\r
                   "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
                     if (result == DialogResult.Yes)\r
-                        encodeQueue.AddJob(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
+                        encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
 \r
                 }\r
                 else\r
-                    encodeQueue.AddJob(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
+                    encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
 \r
                 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
 \r
@@ -1543,16 +1544,16 @@ namespace Handbrake
 \r
             try\r
             {\r
-                DVD thisDVD = SourceScan.SouceData();\r
+                currentSource = SourceScan.SouceData();\r
 \r
                 // Setup some GUI components\r
                 drp_dvdtitle.Items.Clear();\r
-                if (thisDVD.Titles.Count != 0)\r
-                    drp_dvdtitle.Items.AddRange(thisDVD.Titles.ToArray());\r
+                if (currentSource.Titles.Count != 0)\r
+                    drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());\r
 \r
                 // Now select the longest title\r
-                if (thisDVD.Titles.Count != 0)\r
-                    drp_dvdtitle.SelectedItem = Main.SelectLongestTitle(thisDVD);\r
+                if (currentSource.Titles.Count != 0)\r
+                    drp_dvdtitle.SelectedItem = Main.SelectLongestTitle(currentSource);\r
 \r
                 // Enable the creation of chapter markers if the file is an image of a dvd.\r
                 if (sourcePath.ToLower().Contains(".iso") || sourcePath.Contains("VIDEO_TS") || Directory.Exists(Path.Combine(sourcePath, "VIDEO_TS")))\r
@@ -1768,7 +1769,7 @@ namespace Handbrake
         protected override void OnFormClosing(FormClosingEventArgs e)\r
         {\r
             // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.\r
-            if ((encodeQueue.isEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))\r
+            if ((encodeQueue.IsEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))\r
             {\r
                 DialogResult result = MessageBox.Show("HandBrake has queue items to process. Closing HandBrake will not stop the current encoding, but will stop processing the queue.\n\nDo you want to close HandBrake?",\r
                     "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
@@ -1784,7 +1785,7 @@ namespace Handbrake
         {\r
             try\r
             {\r
-                Parser encode = new Parser(encodeQueue.hbProcess.StandardOutput.BaseStream);\r
+                Parser encode = new Parser(encodeQueue.HbProcess.StandardOutput.BaseStream);\r
                 encode.OnEncodeProgress += encodeOnEncodeProgress;\r
                 while (!encode.EndOfStream)\r
                     encode.readEncodeStatus();\r
index d0f5ebf..8cd51a6 100644 (file)
@@ -14,7 +14,7 @@ namespace Handbrake
     public partial class frmPreview : Form\r
     {\r
         readonly QueryGenerator HbCommonFunc = new QueryGenerator();\r
-        readonly EncodeAndQueueHandler Process = new EncodeAndQueueHandler();\r
+        readonly Queue Process = new Queue();\r
         private delegate void UpdateUIHandler();\r
         String CurrentlyPlaying = "";\r
         readonly frmMain MainWindow;\r
@@ -106,15 +106,15 @@ namespace Handbrake
         private void ProcMonitor(object state)\r
         {\r
             // Make sure we are not already encoding and if we are then display an error.\r
-            if (Process.hbProcess != null)\r
+            if (Process.HbProcess != null)\r
                 MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             else\r
             {\r
-                Process.RunCli((string)state);\r
-                if (Process.hbProcess != null)\r
+                Process.CreatePreviewSampe((string)state);\r
+                if (Process.HbProcess != null)\r
                 {\r
-                    Process.hbProcess.WaitForExit();\r
-                    Process.hbProcess = null;\r
+                    Process.HbProcess.WaitForExit();\r
+                    Process.HbProcess = null;\r
                 }\r
                 EncodeCompleted();\r
             }\r
index 3529789..3d3e28f 100644 (file)
@@ -16,40 +16,41 @@ namespace Handbrake
     public partial class frmQueue : Form\r
     {\r
         private delegate void UpdateHandler();\r
-        private EncodeAndQueueHandler queue;\r
+        private Queue queue;\r
 \r
-        public frmQueue(EncodeAndQueueHandler q)\r
+        public frmQueue(Queue q)\r
         {\r
             InitializeComponent();\r
 \r
             this.queue = q;\r
-            queue.NewJobStarted += new EventHandler(queueOnEncodeStart);\r
-            queue.QueueCompleted += new EventHandler(queueOnQueueFinished);\r
-            queue.QueuePauseRequested += new EventHandler(queueOnPaused);\r
+            queue.NewJobStarted += new EventHandler(QueueOnEncodeStart);\r
+            queue.QueueCompleted += new EventHandler(QueueOnQueueFinished);\r
+            queue.QueuePauseRequested += new EventHandler(QueueOnPaused);\r
         }\r
-        void queueOnPaused(object sender, EventArgs e)\r
+\r
+        private void QueueOnPaused(object sender, EventArgs e)\r
         {\r
-            setUIEncodeFinished();\r
-            updateUIElements();\r
+            SetUIEncodeFinished();\r
+            UpdateUIElements();\r
         }\r
-        void queueOnQueueFinished(object sender, EventArgs e)\r
+        private void QueueOnQueueFinished(object sender, EventArgs e)\r
         {\r
-            setUIEncodeFinished();\r
-            resetQueue(); // Reset the Queue Window\r
+            SetUIEncodeFinished();\r
+            ResetQueue(); // Reset the Queue Window\r
         }\r
-        void queueOnEncodeStart(object sender, EventArgs e)\r
+        private void QueueOnEncodeStart(object sender, EventArgs e)\r
         {\r
-            setUIEncodeStarted(); // make sure the UI is set correctly\r
-            setCurrentEncodeInformation();\r
-            updateUIElements(); // Redraw the Queue, a new encode has started.\r
+            SetUIEncodeStarted(); // make sure the UI is set correctly\r
+            SetCurrentEncodeInformation();\r
+            UpdateUIElements(); // Redraw the Queue, a new encode has started.\r
         }\r
 \r
         /// <summary>\r
         /// Initializes the Queue list with the Arraylist from the Queue class\r
         /// </summary>\r
-        public void setQueue()\r
+        public void SetQueue()\r
         {\r
-            updateUIElements();\r
+            UpdateUIElements();\r
         }\r
 \r
         /// <summary>\r
@@ -66,7 +67,7 @@ namespace Handbrake
         /// <param name="doSetQueue">Indicates whether to call setQueue() before showing the window</param>\r
         public void Show(bool doSetQueue)\r
         {\r
-            if (doSetQueue) setQueue();\r
+            if (doSetQueue) SetQueue();\r
             base.Show();\r
 \r
             //Activate();\r
@@ -77,48 +78,48 @@ namespace Handbrake
         {\r
             if (queue.PauseRequested)\r
             {\r
-                setUIEncodeStarted();\r
+                SetUIEncodeStarted();\r
                 MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
             }\r
 \r
-            if (!queue.isEncoding)\r
-                queue.StartEncodeQueue();\r
+            if (!queue.IsEncoding)\r
+                queue.Start();\r
 \r
         }\r
         private void btn_pause_Click(object sender, EventArgs e)\r
         {\r
-            queue.RequestPause();\r
-            setUIEncodeFinished();\r
-            resetQueue();\r
+            queue.Pause();\r
+            SetUIEncodeFinished();\r
+            ResetQueue();\r
             MessageBox.Show("No further items on the queue will start. The current encode process will continue until it is finished. \nClick 'Encode' when you wish to continue encoding the queue.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
         }\r
 \r
         // Window Display Management\r
-        private void setUIEncodeStarted()\r
+        private void SetUIEncodeStarted()\r
         {\r
             if (InvokeRequired)\r
             {\r
-                BeginInvoke(new UpdateHandler(setUIEncodeStarted));\r
+                BeginInvoke(new UpdateHandler(SetUIEncodeStarted));\r
                 return;\r
             }\r
             btn_encode.Enabled = false;\r
             btn_pause.Visible = true;\r
         }\r
-        private void setUIEncodeFinished()\r
+        private void SetUIEncodeFinished()\r
         {\r
             if (InvokeRequired)\r
             {\r
-                BeginInvoke(new UpdateHandler(setUIEncodeFinished));\r
+                BeginInvoke(new UpdateHandler(SetUIEncodeFinished));\r
                 return;\r
             }\r
             btn_pause.Visible = false;\r
             btn_encode.Enabled = true;\r
         }\r
-        private void resetQueue()\r
+        private void ResetQueue()\r
         {\r
             if (InvokeRequired)\r
             {\r
-                BeginInvoke(new UpdateHandler(resetQueue));\r
+                BeginInvoke(new UpdateHandler(ResetQueue));\r
                 return;\r
             }\r
             btn_pause.Visible = false;\r
@@ -133,11 +134,11 @@ namespace Handbrake
 \r
             lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";\r
         }\r
-        private void redrawQueue()\r
+        private void RedrawQueue()\r
         {\r
             if (InvokeRequired)\r
             {\r
-                BeginInvoke(new UpdateHandler(redrawQueue));\r
+                BeginInvoke(new UpdateHandler(RedrawQueue));\r
                 return;\r
             }\r
 \r
@@ -183,24 +184,24 @@ namespace Handbrake
                 list_queue.Items.Add(item);\r
             }\r
         }\r
-        private void updateUIElements()\r
+        private void UpdateUIElements()\r
         {\r
             if (InvokeRequired)\r
             {\r
-                BeginInvoke(new UpdateHandler(updateUIElements));\r
+                BeginInvoke(new UpdateHandler(UpdateUIElements));\r
                 return;\r
             }\r
 \r
-            redrawQueue();\r
+            RedrawQueue();\r
             lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";\r
         }\r
-        private void setCurrentEncodeInformation()\r
+        private void SetCurrentEncodeInformation()\r
         {\r
             try\r
             {\r
                 if (InvokeRequired)\r
                 {\r
-                    BeginInvoke(new UpdateHandler(setCurrentEncodeInformation));\r
+                    BeginInvoke(new UpdateHandler(SetCurrentEncodeInformation));\r
                 }\r
 \r
                 // found query is a global varible\r
@@ -238,7 +239,7 @@ namespace Handbrake
                 // Do Nothing\r
             }\r
         }\r
-        private void deleteSelectedItems()\r
+        private void DeleteSelectedItems()\r
         {\r
             // If there are selected items\r
             if (list_queue.SelectedIndices.Count > 0)\r
@@ -255,9 +256,9 @@ namespace Handbrake
 \r
                 // Remove each selected item\r
                 foreach (int selectedIndex in selectedIndices)\r
-                    queue.RemoveJob(selectedIndex);\r
+                    queue.Remove(selectedIndex);\r
 \r
-                updateUIElements();\r
+                UpdateUIElements();\r
 \r
                 // Select the item where the first deleted item was previously\r
                 if (firstSelectedIndex < list_queue.Items.Count)\r
@@ -270,34 +271,34 @@ namespace Handbrake
         // Queue Management\r
         private void mnu_up_Click(object sender, EventArgs e)\r
         {\r
-            moveUp();\r
+            MoveUp();\r
         }\r
         private void mnu_Down_Click(object sender, EventArgs e)\r
         {\r
-            moveDown();\r
+            MoveDown();\r
         }\r
         private void mnu_delete_Click(object sender, EventArgs e)\r
         {\r
-            deleteSelectedItems();\r
+            DeleteSelectedItems();\r
         }\r
         private void btn_up_Click(object sender, EventArgs e)\r
         {\r
-            moveUp();\r
+            MoveUp();\r
         }\r
         private void btn_down_Click(object sender, EventArgs e)\r
         {\r
-            moveDown();\r
+            MoveDown();\r
         }\r
         private void btn_delete_Click(object sender, EventArgs e)\r
         {\r
-            deleteSelectedItems();\r
+            DeleteSelectedItems();\r
         }\r
         private void list_queue_deleteKey(object sender, KeyEventArgs e)\r
         {\r
             if (e.KeyCode == Keys.Delete)\r
-                deleteSelectedItems();\r
+                DeleteSelectedItems();\r
         }\r
-        private void moveUp()\r
+        private void MoveUp()\r
         {\r
             // If there are selected items and the first item is not selected\r
             if (list_queue.SelectedIndices.Count > 0 && !list_queue.SelectedIndices.Contains(0))\r
@@ -311,7 +312,7 @@ namespace Handbrake
                 foreach (int selectedIndex in selectedIndices)\r
                     queue.MoveUp(selectedIndex);\r
 \r
-                updateUIElements();\r
+                UpdateUIElements();\r
 \r
                 // Keep the selected item(s) selected, now moved up one index\r
                 foreach (int selectedIndex in selectedIndices)\r
@@ -321,7 +322,7 @@ namespace Handbrake
 \r
             list_queue.Select(); // Activate the control to show the selected items\r
         }\r
-        private void moveDown()\r
+        private void MoveDown()\r
         {\r
             // If there are selected items and the last item is not selected\r
             if (list_queue.SelectedIndices.Count > 0 &&\r
@@ -339,7 +340,7 @@ namespace Handbrake
                 foreach (int selectedIndex in selectedIndices)\r
                     queue.MoveDown(selectedIndex);\r
 \r
-                updateUIElements();\r
+                UpdateUIElements();\r
 \r
                 // Keep the selected item(s) selected, now moved down one index\r
                 foreach (int selectedIndex in selectedIndices)\r
@@ -373,14 +374,14 @@ namespace Handbrake
             OpenFile.ShowDialog();\r
             if (OpenFile.FileName != String.Empty)\r
                 queue.LoadQueueFromFile(OpenFile.FileName);\r
-            updateUIElements();\r
+            UpdateUIElements();\r
         }\r
         private void mnu_readd_Click(object sender, EventArgs e)\r
         {\r
             if (!queue.LastEncode.IsEmpty)\r
             {\r
-                queue.AddJob(queue.LastEncode.Query, queue.LastEncode.Source, queue.LastEncode.Destination, queue.LastEncode.CustomQuery);\r
-                updateUIElements();\r
+                queue.Add(queue.LastEncode.Query, queue.LastEncode.Source, queue.LastEncode.Destination, queue.LastEncode.CustomQuery);\r
+                UpdateUIElements();\r
             }\r
         }\r
 \r