OSDN Git Service

WinGui
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 3 Jan 2009 21:00:20 +0000 (21:00 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 3 Jan 2009 21:00:20 +0000 (21:00 +0000)
- Decoupled the Activity window from frmMain and frmQueue.

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

win/C#/Functions/Encode.cs
win/C#/frmActivityWindow.cs
win/C#/frmMain.cs
win/C#/frmQueue.cs

index 7c3f436..99db0bc 100644 (file)
@@ -25,6 +25,7 @@ namespace Handbrake.Functions
 \r
         // Declarations\r
         Process hbProc = new Process();\r
+        Boolean encoding = false;\r
 \r
         // CLI output is based on en-US locale,\r
         static readonly private CultureInfo Culture = new CultureInfo("en-US", false);\r
@@ -47,6 +48,7 @@ namespace Handbrake.Functions
                 if (Properties.Settings.Default.cli_minimized == "Checked")\r
                     cliStart.WindowStyle = ProcessWindowStyle.Minimized;\r
                 hbProc = Process.Start(cliStart);\r
+                encoding = true;\r
 \r
                 // Set the process Priority \r
                 switch (Properties.Settings.Default.processPriority)\r
@@ -83,6 +85,7 @@ namespace Handbrake.Functions
         /// </summary>\r
         public void afterEncodeAction()\r
         {\r
+            encoding = false;\r
             // Do something whent he encode ends.\r
             switch (Properties.Settings.Default.CompletionOption)\r
             {\r
@@ -168,5 +171,13 @@ namespace Handbrake.Functions
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Returns whether HandBrake is currently encoding or not.\r
+        /// </summary>\r
+        public Boolean isEncoding\r
+        {\r
+            get { if (encoding == false) return false; else return true; }\r
+        }\r
+\r
     }\r
 }\r
index 468e36c..d1a1376 100644 (file)
@@ -26,14 +26,13 @@ namespace Handbrake
         delegate void SetTextCallback(string text);\r
         String read_file;\r
         Thread monitor;\r
-        frmMain mainWindow;\r
-        frmQueue queueWindow;\r
+        Functions.Encode encodeHandler;\r
         int position = 0;  // Position in the arraylist reached by the current log output in the rtf box.\r
 \r
         /// <summary>\r
         /// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.\r
         /// </summary>\r
-        public frmActivityWindow(string file, frmMain fm, frmQueue fq)\r
+        public frmActivityWindow(string file, Functions.Encode eh)\r
         {\r
             InitializeComponent();\r
             this.rtf_actLog.Text = string.Empty;\r
@@ -41,8 +40,7 @@ namespace Handbrake
             // When the window closes, we want to abort the monitor thread.\r
             this.Disposed += new EventHandler(forceQuit);\r
 \r
-            mainWindow = fm;\r
-            queueWindow = fq;\r
+            encodeHandler = eh;\r
             read_file = file;\r
             position = 0;\r
 \r
@@ -162,7 +160,7 @@ namespace Handbrake
                 updateTextFromThread();\r
                 while (true)\r
                 {\r
-                    if (queueWindow.isEncoding() == true)\r
+                    if (encodeHandler.isEncoding == true)\r
                         updateTextFromThread();\r
                     else\r
                     {\r
index 8c7be7a..5110b0b 100644 (file)
@@ -22,8 +22,9 @@ namespace Handbrake
     public partial class frmMain : Form\r
     {\r
         // Objects which may be used by one or more other objects\r
+        private delegate void UpdateWindowHandler();\r
         Functions.Main hb_common_func = new Functions.Main();\r
-        Functions.Encode cliObj = new Functions.Encode();\r
+        Functions.Encode encodeHandler = new Functions.Encode();\r
         Queue.Queue encodeQueue = new Queue.Queue();\r
         Presets.PresetsHandler presetHandler = new Presets.PresetsHandler();\r
         Parsing.Title selectedTitle;\r
@@ -201,7 +202,7 @@ namespace Handbrake
             else\r
                 file = "hb_encode_log.dat";\r
 \r
-            frmActivityWindow dvdInfoWindow = new frmActivityWindow(file, this, queueWindow);\r
+            frmActivityWindow dvdInfoWindow = new frmActivityWindow(file, encodeHandler);\r
             dvdInfoWindow.Show();\r
         }\r
         private void mnu_options_Click(object sender, EventArgs e)\r
@@ -504,7 +505,7 @@ namespace Handbrake
                 {\r
                     queueWindow.frmMain_cancelEncode();\r
                     if (!queueWindow.isEncoding())\r
-                        setEncodeStatus(0);\r
+                        setEncodeFinished();\r
                 }\r
             }\r
             else\r
@@ -532,7 +533,7 @@ namespace Handbrake
 \r
                     queueWindow.frmMain_encode();\r
 \r
-                    setEncodeStatus(1); // Encode is running, so setup the GUI appropriately\r
+                    setEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
                 }\r
                 else if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)\r
                     MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
@@ -589,7 +590,7 @@ namespace Handbrake
             else\r
                 file = "hb_encode_log.dat";\r
 \r
-            frmActivityWindow ActivityWindow = new frmActivityWindow(file, this, queueWindow);\r
+            frmActivityWindow ActivityWindow = new frmActivityWindow(file, encodeHandler);\r
             ActivityWindow.Show();\r
         }\r
         #endregion\r
@@ -1701,10 +1702,16 @@ namespace Handbrake
         /// 0 = Encode Finished.\r
         /// </summary>\r
         /// <param name="i">Int</param>\r
-        public void setEncodeStatus(int i)\r
+        public void setEncodeFinished()\r
         {\r
-            if (i == 0)\r
+            try\r
             {\r
+                if (this.InvokeRequired)\r
+                {\r
+                    this.BeginInvoke(new UpdateWindowHandler(setEncodeFinished));\r
+                    return;\r
+                }\r
+\r
                 lbl_encode.Text = "Encoding Finished";\r
                 btn_start.Text = "Start";\r
                 btn_start.ToolTipText = "Start the encoding process";\r
@@ -1716,15 +1723,33 @@ namespace Handbrake
                     notifyIcon.BalloonTipText = lbl_encode.Text;\r
                     notifyIcon.ShowBalloonTip(500);\r
                 }\r
+\r
             }\r
-            else\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show(exc.ToString());\r
+            }\r
+        }\r
+        public void setEncodeStarted()\r
+        {\r
+            try\r
             {\r
+                if (this.InvokeRequired)\r
+                {\r
+                    this.BeginInvoke(new UpdateWindowHandler(setEncodeStarted));\r
+                    return;\r
+                }\r
+\r
                 lbl_encode.Visible = true;\r
                 lbl_encode.Text = "Encoding in Progress";\r
                 btn_start.Text = "Stop";\r
                 btn_start.ToolTipText = "Stop the encoding process. \nWarning: This may break your file. Press ctrl-c in the CLI window if you wish it to exit cleanly.";\r
                 btn_start.Image = Properties.Resources.stop;\r
             }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show(exc.ToString());\r
+            }\r
         }\r
 \r
         /// <summary>\r
index 8e71a73..afa9f46 100644 (file)
@@ -153,7 +153,7 @@ namespace Handbrake
                     paused = false;\r
                     btn_encode.Enabled = false;\r
                     mainWindow.setLastAction("encode");\r
-                    mainWindow.setEncodeStatus(1);\r
+                    mainWindow.setEncodeStarted();\r
 \r
                     // Start the encode\r
                     try\r
@@ -207,8 +207,7 @@ namespace Handbrake
                 }\r
 \r
                 resetQueue();\r
-                mainWindow.setEncodeStatus(0); // Tell the main window encodes have finished.\r
-\r
+                \r
                 // After the encode is done, we may want to shutdown, suspend etc.\r
                 cliObj.afterEncodeAction();\r
             }\r
@@ -227,7 +226,6 @@ namespace Handbrake
                 {\r
                     this.BeginInvoke(new ProgressUpdateHandler(resetQueue));\r
                     return;\r
-\r
                 }\r
                 btn_stop.Visible = false;\r
                 btn_encode.Enabled = true;\r
@@ -240,6 +238,8 @@ namespace Handbrake
                 lbl_chapt.Text = "-";\r
 \r
                 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";\r
+\r
+                mainWindow.setEncodeFinished(); // Tell the main window encodes have finished.\r
             }\r
             catch (Exception exc)\r
             {\r