diff options
author | sr55 <[email protected]> | 2008-12-15 12:58:04 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2008-12-15 12:58:04 +0000 |
commit | 0137a81794777bc60e5dd34ea1af2b8336971a9d (patch) | |
tree | 6de8ca518a7b1d7f04f0a3695ad218f2c9d0c036 | |
parent | 213f5a897b6a9cf5d2ce9a84c39455e3590ada88 (diff) |
WinGui:
- MainWindow now uses the Queue for encoding. Essentially works the same as the MacGUI. You start an encode in either window, and the other shows the encoding status. This prevents users from starting 2 encodes at once (1 Queue, 1 Main Window)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2032 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | win/C#/frmActivityWindow.cs | 2 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 91 | ||||
-rw-r--r-- | win/C#/frmQueue.cs | 82 |
3 files changed, 81 insertions, 94 deletions
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs index d21eecd51..468e36cce 100644 --- a/win/C#/frmActivityWindow.cs +++ b/win/C#/frmActivityWindow.cs @@ -162,7 +162,7 @@ namespace Handbrake updateTextFromThread();
while (true)
{
- if ((mainWindow.isEncoding() == true) || (queueWindow.isEncoding() == true))
+ if (queueWindow.isEncoding() == true)
updateTextFromThread();
else
{
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index f70643731..0f2d4dfae 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -35,7 +35,6 @@ namespace Handbrake QueryGenerator queryGen = new QueryGenerator();
// Globals: Mainly used for tracking.
- internal Process hbProc;
private frmQueue queueWindow;
private string lastAction = null;
public int maxWidth = 0;
@@ -470,13 +469,12 @@ namespace Handbrake else
query = queryGen.GenerateTheQuery(this);
- ThreadPool.QueueUserWorkItem(procMonitor, query);
- lbl_encode.Visible = true;
- lbl_encode.Text = "Encoding in Progress";
+ encodeQueue.add(query, text_source.Text, text_destination.Text);
+ encodeQueue.write2disk("hb_queue_recovery.xml");
+ queueWindow.setQueue(encodeQueue);
+ queueWindow.frmMain_encode();
- btn_start.Text = "Stop";
- 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.";
- btn_start.Image = Properties.Resources.stop;
+ setEncodeStatus(1); // Encode is running, so setup the GUI appropriately
}
}
private void btn_add2Queue_Click(object sender, EventArgs e)
@@ -485,7 +483,6 @@ namespace Handbrake MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
{
-
String query = queryGen.GenerateTheQuery(this);
if (rtf_query.Text != "")
query = rtf_query.Text;
@@ -1452,52 +1449,6 @@ namespace Handbrake // MainWindow Components, Actions and Functions ***********************
- #region Encoding
-
- // Declarations
- private delegate void UpdateUIHandler();
-
- // Encoding Functions
- private void procMonitor(object state)
- {
- // Make sure we are not already encoding and if we are then display an error.
- if (hbProc != null)
- hbProc.CloseMainWindow();
- else
- {
- hbProc = cliObj.runCli(this, (string)state);
- hbProc.WaitForExit();
- setEncodeLabelFinished();
- hbProc = null;
-
- // If the window is minimized, display the notification in a popup.
- if (FormWindowState.Minimized == this.WindowState)
- {
- notifyIcon.BalloonTipText = lbl_encode.Text;
- notifyIcon.ShowBalloonTip(500);
- }
-
- // After the encode is done, we may want to shutdown, suspend etc.
- cliObj.addCLIQueryToLog((string)state);
- cliObj.copyLog((string)state, text_destination.Text); // Make a copy of the log in the users desired location if necessary
- cliObj.afterEncodeAction();
- }
- }
- private void setEncodeLabelFinished()
- {
- if (this.InvokeRequired)
- {
- this.BeginInvoke(new UpdateUIHandler(setEncodeLabelFinished));
- return;
- }
- lbl_encode.Text = "Encoding Finished";
- btn_start.Text = "Start";
- btn_start.ToolTipText = "Start the encoding process";
- btn_start.Image = Properties.Resources.Play;
- }
-
- #endregion
-
#region DVD Drive Detection
// Source Button Drive Detection
private delegate void ProgressUpdateHandler();
@@ -1841,15 +1792,35 @@ namespace Handbrake #region Public Methods
/// <summary>
- /// Is the mainWindow currently monitoring an encoding session
+ /// Setup the GUI for Encoding or finished Encoding.
+ /// 1 = Encode Running
+ /// 0 = Encode Finished.
/// </summary>
- /// <returns>boolean</returns>
- public Boolean isEncoding()
+ /// <param name="i">Int</param>
+ public void setEncodeStatus(int i)
{
- if (hbProc == null)
- return false;
+ if (i == 0)
+ {
+ lbl_encode.Text = "Encoding Finished";
+ btn_start.Text = "Start";
+ btn_start.ToolTipText = "Start the encoding process";
+ btn_start.Image = Properties.Resources.Play;
+
+ // If the window is minimized, display the notification in a popup.
+ if (FormWindowState.Minimized == this.WindowState)
+ {
+ notifyIcon.BalloonTipText = lbl_encode.Text;
+ notifyIcon.ShowBalloonTip(500);
+ }
+ }
else
- return true;
+ {
+ lbl_encode.Visible = true;
+ lbl_encode.Text = "Encoding in Progress";
+ btn_start.Text = "Stop";
+ 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.";
+ btn_start.Image = Properties.Resources.stop;
+ }
}
/// <summary>
diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs index 765c940b7..86ae4b5bd 100644 --- a/win/C#/frmQueue.cs +++ b/win/C#/frmQueue.cs @@ -49,7 +49,10 @@ namespace Handbrake if (progressBar.Value != 0)
{
progressBar.Value = 0;
- progressBar.Step = 100 / queue.count();
+ if (queue.count() == 0)
+ progressBar.Step = 100;
+ else
+ progressBar.Step = 100 / queue.count();
progressBar.PerformStep();
lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
}
@@ -67,6 +70,28 @@ namespace Handbrake return true;
}
+ /// <summary>
+ /// This disables encoding from the queue when a single encode from the main window is running.
+ /// </summary>
+ public void frmMain_encode()
+ {
+ cancel = false;
+ // Start the encode
+ try
+ {
+ if (queue.count() != 0)
+ {
+ Thread theQ = new Thread(startProc);
+ theQ.IsBackground = true;
+ theQ.Start();
+ }
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show(exc.ToString());
+ }
+ }
+
// Redraw's the queue with the latest data from the Queue class
private void redrawQueue()
{
@@ -111,6 +136,7 @@ namespace Handbrake private void btn_encode_Click(object sender, EventArgs e)
{
mainWindow.setLastAction("encode");
+ mainWindow.setEncodeStatus(1);
if (queue.count() != 0)
{
@@ -124,10 +150,14 @@ namespace Handbrake if (queue.count() != 0)
{
// Setup or reset some values
+ btn_encode.Enabled = false;
btn_stop.Visible = true;
progressBar.Value = 0;
lbl_progressValue.Text = "0 %";
- progressBar.Step = 100 / queue.count();
+ if (queue.count() == 0)
+ progressBar.Step = 100;
+ else
+ progressBar.Step = 100 / queue.count();
Thread theQ = new Thread(startProc);
theQ.IsBackground = true;
theQ.Start();
@@ -151,7 +181,8 @@ namespace Handbrake queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
setEncValue();
- updateUIElements();
+ if (this.Created)
+ updateUIElements();
hbProc = cliObj.runCli(this, query);
@@ -171,6 +202,7 @@ namespace Handbrake }
resetQueue();
+ mainWindow.setEncodeStatus(0); // Tell the main window encodes have finished.
// After the encode is done, we may want to shutdown, suspend etc.
cliObj.afterEncodeAction();
@@ -296,7 +328,7 @@ namespace Handbrake }
}
- // Move an item up the Queue
+ // Queue Management
private void btn_up_Click(object sender, EventArgs e)
{
if (list_queue.SelectedIndices.Count != 0)
@@ -313,8 +345,6 @@ namespace Handbrake list_queue.Select();
}
}
-
- // Move an item down the Queue
private void btn_down_Click(object sender, EventArgs e)
{
if (list_queue.SelectedIndices.Count != 0)
@@ -331,8 +361,6 @@ namespace Handbrake list_queue.Select();
}
}
-
- // Remove an item from the queue
private void btn_delete_Click(object sender, EventArgs e)
{
if (list_queue.SelectedIndices.Count != 0)
@@ -343,8 +371,20 @@ namespace Handbrake lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
}
}
+ private void list_queue_deleteKey(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Delete)
+ {
+ if (list_queue.SelectedIndices.Count != 0)
+ {
+ queue.remove(list_queue.SelectedIndices[0]);
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
+ redrawQueue();
+ }
+ }
+ }
- // Generate a Saveable batch script on the users request
+ // Queue Import/Export Features
private void mnu_batch_Click(object sender, EventArgs e)
{
SaveFile.FileName = "";
@@ -353,8 +393,6 @@ namespace Handbrake if (SaveFile.FileName != String.Empty)
queue.writeBatchScript(SaveFile.FileName);
}
-
- // Export the HandBrake Queue to a file.
private void mnu_export_Click(object sender, EventArgs e)
{
SaveFile.FileName = "";
@@ -363,8 +401,6 @@ namespace Handbrake if (SaveFile.FileName != String.Empty)
queue.write2disk(SaveFile.FileName);
}
-
- // Import an exported queue
private void mnu_import_Click(object sender, EventArgs e)
{
OpenFile.FileName = "";
@@ -374,26 +410,6 @@ namespace Handbrake redrawQueue();
}
- // Delete a selected item on the queue, if the delete key is pressed.
- private void list_queue_deleteKey(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Delete)
- {
- if (list_queue.SelectedIndices.Count != 0)
- {
- queue.remove(list_queue.SelectedIndices[0]);
- queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
- redrawQueue();
- }
- }
- }
-
- // Hide's the window from the users view.
- private void btn_Close_Click(object sender, EventArgs e)
- {
- this.Hide();
- }
-
// Hide's the window when the user tries to "x" out of the window instead of closing it.
protected override void OnClosing(CancelEventArgs e)
{
|