diff options
-rw-r--r-- | win/C#/Queue/QueueHandler.cs | 136 | ||||
-rw-r--r-- | win/C#/frmMain.Designer.cs | 78 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 56 | ||||
-rw-r--r-- | win/C#/frmMain.resx | 6 | ||||
-rw-r--r-- | win/C#/frmQueue.Designer.cs | 38 | ||||
-rw-r--r-- | win/C#/frmQueue.cs | 233 |
6 files changed, 323 insertions, 224 deletions
diff --git a/win/C#/Queue/QueueHandler.cs b/win/C#/Queue/QueueHandler.cs index 956801401..aabce4f41 100644 --- a/win/C#/Queue/QueueHandler.cs +++ b/win/C#/Queue/QueueHandler.cs @@ -17,9 +17,10 @@ namespace Handbrake.Queue int id = 0; // Unique identifer number for each job
private QueueItem lastItem;
+ #region Queue Handling
public List<QueueItem> getQueue()
{
- return queue;
+ return queue;
}
/// <summary>
@@ -199,9 +200,138 @@ namespace Handbrake.Queue foreach (QueueItem item in list)
queue.Add(item);
+
+ if (file != "hb_queue_recovery.xml")
+ write2disk("hb_queue_recovery.xml");
+ }
+ }
+ }
+ }
+ #endregion
+
+ //------------------------------------------------------------------------
+ Functions.Encode encodeHandler = new Functions.Encode();
+ private Boolean started = false;
+ private Boolean paused = false;
+ private Boolean encoding = false;
+
+ #region Encoding
+
+ public Boolean isEncodeStarted
+ {
+ get { return started; }
+ }
+ public Boolean isPaused
+ {
+ get { return paused; }
+ }
+ public Boolean isEncoding
+ {
+ get { return encoding; }
+ }
+
+ public void startEncode()
+ {
+ Thread theQueue;
+ if (this.count() != 0)
+ {
+ if (paused == true)
+ paused = false;
+ else
+ {
+ paused = false;
+ try
+ {
+ theQueue = new Thread(startProc);
+ theQueue.IsBackground = true;
+ theQueue.Start();
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show(exc.ToString());
+ }
+ }
+ }
+ }
+ public void pauseEncode()
+ {
+ paused = true;
+ EncodePaused(null);
+ }
+
+ private void startProc(object state)
+ {
+ Process hbProc = new Process();
+ try
+ {
+ // Run through each item on the queue
+ while (this.count() != 0)
+ {
+ string query = getNextItemForEncoding();
+ write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
+
+ EncodeStarted(null);
+ hbProc = encodeHandler.runCli(this, query);
+ hbProc.WaitForExit();
+
+ encodeHandler.addCLIQueryToLog(query);
+ encodeHandler.copyLog(query, getLastQueryItem().Destination);
+
+ hbProc.Close();
+ hbProc.Dispose();
+ hbProc = null;
+ query = "";
+ EncodeFinished(null);
+
+ while (paused == true) // Need to find a better way of doing this.
+ {
+ Thread.Sleep(10000);
}
}
+ EncodeQueueFinished(null);
+
+ // After the encode is done, we may want to shutdown, suspend etc.
+ encodeHandler.afterEncodeAction();
+ }
+ catch (Exception exc)
+ {
+ throw new Exception(exc.ToString());
}
}
- }
-}
+ #endregion
+
+ #region Events
+ public event EventHandler OnEncodeStart;
+ public event EventHandler OnPaused;
+ public event EventHandler OnEncodeEnded;
+ public event EventHandler OnQueueFinished;
+
+ // Invoke the Changed event; called whenever encodestatus changes:
+ protected virtual void EncodeStarted(EventArgs e)
+ {
+ if (OnEncodeStart != null)
+ OnEncodeStart(this, e);
+
+ encoding = true;
+ }
+ protected virtual void EncodePaused(EventArgs e)
+ {
+ if (OnPaused != null)
+ OnPaused(this, e);
+ }
+ protected virtual void EncodeFinished(EventArgs e)
+ {
+ if (OnEncodeEnded != null)
+ OnEncodeEnded(this, e);
+
+ encoding = false;
+ }
+ protected virtual void EncodeQueueFinished(EventArgs e)
+ {
+ if (OnQueueFinished != null)
+ OnQueueFinished(this, e);
+ }
+ #endregion
+
+ }
+}
\ No newline at end of file diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs index 37dcd055a..d814262d4 100644 --- a/win/C#/frmMain.Designer.cs +++ b/win/C#/frmMain.Designer.cs @@ -38,7 +38,7 @@ namespace Handbrake System.Windows.Forms.Label Label38;
System.Windows.Forms.ContextMenuStrip notifyIconMenu;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
+ System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.btn_restore = new System.Windows.Forms.ToolStripMenuItem();
this.DVD_Save = new System.Windows.Forms.SaveFileDialog();
this.File_Save = new System.Windows.Forms.SaveFileDialog();
@@ -171,6 +171,7 @@ namespace Handbrake this.Label46 = new System.Windows.Forms.Label();
this.Label40 = new System.Windows.Forms.Label();
this.TabPage1 = new System.Windows.Forms.TabPage();
+ this.lbl_test = new System.Windows.Forms.Label();
this.slider_deblock = new System.Windows.Forms.TrackBar();
this.label8 = new System.Windows.Forms.Label();
this.lbl_deblockVal = new System.Windows.Forms.Label();
@@ -244,13 +245,13 @@ namespace Handbrake this.btn_add2Queue = new System.Windows.Forms.ToolStripButton();
this.btn_showQueue = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
+ this.tb_preview = new System.Windows.Forms.ToolStripDropDownButton();
+ this.mnu_qtpreview = new System.Windows.Forms.ToolStripMenuItem();
+ this.mnu_vlcpreview = new System.Windows.Forms.ToolStripMenuItem();
this.btn_ActivityWindow = new System.Windows.Forms.ToolStripButton();
this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.StatusStrip = new System.Windows.Forms.StatusStrip();
this.lbl_encode = new System.Windows.Forms.ToolStripStatusLabel();
- this.tb_preview = new System.Windows.Forms.ToolStripDropDownButton();
- this.mnu_qtpreview = new System.Windows.Forms.ToolStripMenuItem();
- this.mnu_vlcpreview = new System.Windows.Forms.ToolStripMenuItem();
Label38 = new System.Windows.Forms.Label();
notifyIconMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
notifyIconMenu.SuspendLayout();
@@ -644,9 +645,9 @@ namespace Handbrake //
// number
//
- dataGridViewCellStyle3.Format = "N0";
- dataGridViewCellStyle3.NullValue = null;
- this.number.DefaultCellStyle = dataGridViewCellStyle3;
+ dataGridViewCellStyle1.Format = "N0";
+ dataGridViewCellStyle1.NullValue = null;
+ this.number.DefaultCellStyle = dataGridViewCellStyle1;
this.number.HeaderText = "Chapter Number";
this.number.MaxInputLength = 3;
this.number.Name = "number";
@@ -1963,6 +1964,7 @@ namespace Handbrake // TabPage1
//
this.TabPage1.BackColor = System.Drawing.Color.Transparent;
+ this.TabPage1.Controls.Add(this.lbl_test);
this.TabPage1.Controls.Add(this.slider_deblock);
this.TabPage1.Controls.Add(this.label8);
this.TabPage1.Controls.Add(this.lbl_deblockVal);
@@ -2002,6 +2004,15 @@ namespace Handbrake this.TabPage1.TabIndex = 0;
this.TabPage1.Text = "Picture Settings";
//
+ // lbl_test
+ //
+ this.lbl_test.AutoSize = true;
+ this.lbl_test.Location = new System.Drawing.Point(83, 217);
+ this.lbl_test.Name = "lbl_test";
+ this.lbl_test.Size = new System.Drawing.Size(48, 13);
+ this.lbl_test.TabIndex = 39;
+ this.lbl_test.Text = "label12";
+ //
// slider_deblock
//
this.slider_deblock.Location = new System.Drawing.Point(407, 264);
@@ -2844,6 +2855,32 @@ namespace Handbrake this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(6, 39);
//
+ // tb_preview
+ //
+ this.tb_preview.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.mnu_qtpreview,
+ this.mnu_vlcpreview});
+ this.tb_preview.Image = global::Handbrake.Properties.Resources.picture;
+ this.tb_preview.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
+ this.tb_preview.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.tb_preview.Name = "tb_preview";
+ this.tb_preview.Size = new System.Drawing.Size(90, 36);
+ this.tb_preview.Text = "Preview";
+ //
+ // mnu_qtpreview
+ //
+ this.mnu_qtpreview.Name = "mnu_qtpreview";
+ this.mnu_qtpreview.Size = new System.Drawing.Size(185, 22);
+ this.mnu_qtpreview.Text = "Preview in QuickTime";
+ this.mnu_qtpreview.Click += new System.EventHandler(this.mnu_qtpreview_Click);
+ //
+ // mnu_vlcpreview
+ //
+ this.mnu_vlcpreview.Name = "mnu_vlcpreview";
+ this.mnu_vlcpreview.Size = new System.Drawing.Size(185, 22);
+ this.mnu_vlcpreview.Text = "Preview in VLC";
+ this.mnu_vlcpreview.Click += new System.EventHandler(this.mnu_vlcpreview_Click);
+ //
// btn_ActivityWindow
//
this.btn_ActivityWindow.Image = global::Handbrake.Properties.Resources.ActivityWindow;
@@ -2883,32 +2920,6 @@ namespace Handbrake this.lbl_encode.Size = new System.Drawing.Size(31, 17);
this.lbl_encode.Text = "{0}";
//
- // tb_preview
- //
- this.tb_preview.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.mnu_qtpreview,
- this.mnu_vlcpreview});
- this.tb_preview.Image = global::Handbrake.Properties.Resources.picture;
- this.tb_preview.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
- this.tb_preview.ImageTransparentColor = System.Drawing.Color.Magenta;
- this.tb_preview.Name = "tb_preview";
- this.tb_preview.Size = new System.Drawing.Size(90, 36);
- this.tb_preview.Text = "Preview";
- //
- // mnu_qtpreview
- //
- this.mnu_qtpreview.Name = "mnu_qtpreview";
- this.mnu_qtpreview.Size = new System.Drawing.Size(185, 22);
- this.mnu_qtpreview.Text = "Preview in QuickTime";
- this.mnu_qtpreview.Click += new System.EventHandler(this.mnu_qtpreview_Click);
- //
- // mnu_vlcpreview
- //
- this.mnu_vlcpreview.Name = "mnu_vlcpreview";
- this.mnu_vlcpreview.Size = new System.Drawing.Size(185, 22);
- this.mnu_vlcpreview.Text = "Preview in VLC";
- this.mnu_vlcpreview.Click += new System.EventHandler(this.mnu_vlcpreview_Click);
- //
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -3187,6 +3198,7 @@ namespace Handbrake private System.Windows.Forms.ToolStripDropDownButton tb_preview;
private System.Windows.Forms.ToolStripMenuItem mnu_qtpreview;
private System.Windows.Forms.ToolStripMenuItem mnu_vlcpreview;
+ private System.Windows.Forms.Label lbl_test;
}
}
\ No newline at end of file diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 7fcd2fb32..ff9c69abc 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -88,7 +88,7 @@ namespace Handbrake loadPresetPanel(); // Load the Preset Panel
treeView_presets.ExpandAll();
lbl_encode.Text = "";
- queueWindow = new frmQueue(this); // Prepare the Queue
+ queueWindow = new frmQueue(encodeQueue); // Prepare the Queue
if (Properties.Settings.Default.QueryEditorTab != "Checked")
tabs_panel.TabPages.RemoveAt(5); // Remove the query editor tab if the user does not want it enabled.
@@ -133,11 +133,10 @@ namespace Handbrake this.Enabled = true;
// Event Handlers
- if (Properties.Settings.Default.MainWindowMinimize == "Checked")
- this.Resize += new EventHandler(frmMain_Resize);
+ events();
// Queue Recovery
- queueRecovery();
+ queueRecovery();
}
// Startup Functions
@@ -180,6 +179,34 @@ namespace Handbrake }
#endregion
+ #region Events
+ // Encoding Events for setting up the GUI
+ private void events()
+ {
+ // Handle Window Resize
+ if (Properties.Settings.Default.MainWindowMinimize == "Checked")
+ this.Resize += new EventHandler(frmMain_Resize);
+
+ // Handle Encode Start
+ encodeQueue.OnEncodeEnded += new EventHandler(encodeEnded);
+ encodeQueue.OnPaused += new EventHandler(encodePaused);
+ encodeQueue.OnEncodeStart += new EventHandler(encodeStarted);
+ }
+ private void encodeStarted(object sender, EventArgs e)
+ {
+ setLastAction("encode");
+ setEncodeStarted();
+ }
+ private void encodeEnded(object sender, EventArgs e)
+ {
+ setEncodeFinished();
+ }
+ private void encodePaused(object sender, EventArgs e)
+ {
+ setEncodeFinished();
+ }
+ #endregion
+
// User Interface Menus / Tool Strips *********************************
#region File Menu
@@ -192,7 +219,7 @@ namespace Handbrake #region Tools Menu
private void mnu_encode_Click(object sender, EventArgs e)
{
- queueWindow.setQueue(encodeQueue);
+ queueWindow.setQueue();
queueWindow.Show();
}
private void mnu_encodeLog_Click(object sender, EventArgs e)
@@ -504,6 +531,10 @@ namespace Handbrake if (result == DialogResult.Yes)
{
+ // Pause The Queue
+ encodeQueue.pauseEncode();
+
+ // Kill the current process.
Process[] aProc = Process.GetProcessesByName("HandBrakeCLI");
Process HandBrakeCLI;
if (aProc.Length > 0)
@@ -511,8 +542,9 @@ namespace Handbrake HandBrakeCLI = aProc[0];
HandBrakeCLI.Kill();
}
- if (!queueWindow.isEncoding())
- setEncodeFinished();
+
+ // Update the GUI
+ setEncodeFinished();
}
}
else
@@ -534,13 +566,13 @@ namespace Handbrake encodeQueue.add(query, text_source.Text, text_destination.Text);
encodeQueue.write2disk("hb_queue_recovery.xml");
}
- queueWindow.setQueue(encodeQueue);
+ queueWindow.setQueue();
if (encodeQueue.count() > 1)
queueWindow.Show();
- queueWindow.frmMain_encode();
-
setEncodeStarted(); // Encode is running, so setup the GUI appropriately
+ encodeQueue.startEncode(); // Start The Queue Encoding Process
+
}
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);
@@ -560,13 +592,13 @@ namespace Handbrake encodeQueue.add(query, text_source.Text, text_destination.Text);
encodeQueue.write2disk("hb_queue_recovery.xml"); // Writes the queue to the recovery file, just incase the GUI crashes.
- queueWindow.setQueue(encodeQueue);
+ queueWindow.setQueue();
queueWindow.Show();
}
}
private void btn_showQueue_Click(object sender, EventArgs e)
{
- queueWindow.setQueue(encodeQueue);
+ queueWindow.setQueue();
queueWindow.Show();
}
private void mnu_vlcpreview_Click(object sender, EventArgs e)
diff --git a/win/C#/frmMain.resx b/win/C#/frmMain.resx index 0039ebd87..d6bf08e3e 100644 --- a/win/C#/frmMain.resx +++ b/win/C#/frmMain.resx @@ -155,12 +155,6 @@ Make sure you have selected a "Title" from the "Source" box above otherwise the list will not be populated with the correct amount of chapters.
Note: Do not change any of the chapter numbers!</value>
</data>
- <metadata name="number.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
- <value>True</value>
- </metadata>
- <metadata name="name.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
- <value>True</value>
- </metadata>
<data name="check_Cabac.ToolTip" xml:space="preserve">
<value>CABAC, or context adaptive binary arithmetic coding, is used by x264 to reduce the bitrate needed for a given quality by 15%.
This makes it very cool and very useful, and it should be left on whenever possible. However, it is incompatible with the iPod 5.5G, and makes the AppleTV struggle.
diff --git a/win/C#/frmQueue.Designer.cs b/win/C#/frmQueue.Designer.cs index 0682c3c85..a775c9648 100644 --- a/win/C#/frmQueue.Designer.cs +++ b/win/C#/frmQueue.Designer.cs @@ -51,7 +51,7 @@ namespace Handbrake this.label3 = new System.Windows.Forms.Label();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.btn_encode = new System.Windows.Forms.ToolStripButton();
- this.btn_stop = new System.Windows.Forms.ToolStripButton();
+ this.btn_pause = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.drop_button_queue = new System.Windows.Forms.ToolStripDropDownButton();
this.mnu_batch = new System.Windows.Forms.ToolStripMenuItem();
@@ -218,7 +218,7 @@ namespace Handbrake this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.btn_encode,
- this.btn_stop,
+ this.btn_pause,
this.toolStripSeparator1,
this.drop_button_queue});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
@@ -234,21 +234,21 @@ namespace Handbrake this.btn_encode.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
this.btn_encode.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btn_encode.Name = "btn_encode";
- this.btn_encode.Size = new System.Drawing.Size(84, 36);
+ this.btn_encode.Size = new System.Drawing.Size(78, 36);
this.btn_encode.Text = "Encode";
this.btn_encode.Click += new System.EventHandler(this.btn_encode_Click);
//
- // btn_stop
+ // btn_pause
//
- this.btn_stop.Image = global::Handbrake.Properties.Resources.Pause;
- this.btn_stop.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
- this.btn_stop.ImageTransparentColor = System.Drawing.Color.Magenta;
- this.btn_stop.Name = "btn_stop";
- this.btn_stop.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;
- this.btn_stop.Size = new System.Drawing.Size(75, 36);
- this.btn_stop.Text = "Pause";
- this.btn_stop.Visible = false;
- this.btn_stop.Click += new System.EventHandler(this.btn_stop_Click);
+ this.btn_pause.Image = global::Handbrake.Properties.Resources.Pause;
+ this.btn_pause.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
+ this.btn_pause.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.btn_pause.Name = "btn_pause";
+ this.btn_pause.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;
+ this.btn_pause.Size = new System.Drawing.Size(72, 36);
+ this.btn_pause.Text = "Pause";
+ this.btn_pause.Visible = false;
+ this.btn_pause.Click += new System.EventHandler(this.btn_pause_Click);
//
// toolStripSeparator1
//
@@ -265,14 +265,14 @@ namespace Handbrake this.drop_button_queue.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
this.drop_button_queue.ImageTransparentColor = System.Drawing.Color.Magenta;
this.drop_button_queue.Name = "drop_button_queue";
- this.drop_button_queue.Size = new System.Drawing.Size(89, 36);
+ this.drop_button_queue.Size = new System.Drawing.Size(84, 36);
this.drop_button_queue.Text = "Queue";
//
// mnu_batch
//
this.mnu_batch.Image = global::Handbrake.Properties.Resources.Output_Small;
this.mnu_batch.Name = "mnu_batch";
- this.mnu_batch.Size = new System.Drawing.Size(207, 22);
+ this.mnu_batch.Size = new System.Drawing.Size(190, 22);
this.mnu_batch.Text = "Generate Batch Script";
this.mnu_batch.Click += new System.EventHandler(this.mnu_batch_Click);
//
@@ -280,7 +280,7 @@ namespace Handbrake //
this.mnu_import.Image = global::Handbrake.Properties.Resources.folder;
this.mnu_import.Name = "mnu_import";
- this.mnu_import.Size = new System.Drawing.Size(207, 22);
+ this.mnu_import.Size = new System.Drawing.Size(190, 22);
this.mnu_import.Text = "Import Queue";
this.mnu_import.Click += new System.EventHandler(this.mnu_import_Click);
//
@@ -288,7 +288,7 @@ namespace Handbrake //
this.mnu_export.Image = global::Handbrake.Properties.Resources.save;
this.mnu_export.Name = "mnu_export";
- this.mnu_export.Size = new System.Drawing.Size(207, 22);
+ this.mnu_export.Size = new System.Drawing.Size(190, 22);
this.mnu_export.Text = "Export Queue";
this.mnu_export.Click += new System.EventHandler(this.mnu_export_Click);
//
@@ -364,7 +364,7 @@ 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, 17);
+ this.lbl_encodesPending.Size = new System.Drawing.Size(105, 17);
this.lbl_encodesPending.Text = "0 encode(s) pending";
//
// OpenFile
@@ -475,7 +475,7 @@ namespace Handbrake private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton btn_encode;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
- private System.Windows.Forms.ToolStripButton btn_stop;
+ private System.Windows.Forms.ToolStripButton btn_pause;
private System.Windows.Forms.SaveFileDialog SaveFile;
private System.Windows.Forms.ListView list_queue;
private System.Windows.Forms.ColumnHeader Title;
diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs index 43f198a86..2fb6169a2 100644 --- a/win/C#/frmQueue.cs +++ b/win/C#/frmQueue.cs @@ -21,173 +21,113 @@ namespace Handbrake {
public partial class frmQueue : Form
{
- private delegate void ProgressUpdateHandler();
- private delegate void setEncoding();
- Functions.Encode cliObj = new Functions.Encode();
- Boolean paused = false;
- Process hbProc = null;
+ private delegate void UpdateHandler();
Queue.QueueHandler queue;
- frmMain mainWindow = null;
- Thread theQ;
- public frmQueue(frmMain main)
+ public frmQueue(Queue.QueueHandler q)
{
InitializeComponent();
- mainWindow = main;
- }
- /// <summary>
- /// Initializes the Queue list with the Arraylist from the Queue class
- /// </summary>
- /// <param name="qw"></param>
- public void setQueue(Queue.QueueHandler qw)
+ this.queue = q;
+ queue.OnEncodeStart += new EventHandler(queue_OnEncodeStart);
+ queue.OnQueueFinished += new EventHandler(queue_OnQueueFinished);
+ queue.OnPaused += new EventHandler(queue_OnPaused);
+ }
+ void queue_OnPaused(object sender, EventArgs e)
{
- queue = qw;
- redrawQueue();
- lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
+ setUIEncodeFinished();
+ updateUIElements();
}
-
- /// <summary>
- /// Returns if there is currently an item being encoded by the queue
- /// </summary>
- /// <returns>Boolean true if encoding</returns>
- public Boolean isEncoding()
+ void queue_OnQueueFinished(object sender, EventArgs e)
+ {
+ setUIEncodeFinished();
+ resetQueue(); // Reset the Queue Window
+ }
+ void queue_OnEncodeStart(object sender, EventArgs e)
{
- if (hbProc == null)
- return false;
- else
- return true;
+ setUIEncodeStarted(); // make sure the UI is set correctly
+ setCurrentEncodeInformation();
+ updateUIElements(); // Redraw the Queue, a new encode has started.
}
/// <summary>
- /// Allows frmMain to start an encode.
- /// Should probably find a cleaner way of doing this.
+ /// Initializes the Queue list with the Arraylist from the Queue class
/// </summary>
- public void frmMain_encode()
+ /// <param name="qw"></param>
+ public void setQueue()
{
- btn_encode_Click(this, null);
+ updateUIElements();
}
// Start and Stop Controls
private void btn_encode_Click(object sender, EventArgs e)
{
- if (queue.count() != 0)
+ if (queue.isPaused == true)
{
- if (paused == true)
- {
- paused = false;
- btn_encode.Enabled = false;
- btn_stop.Visible = true;
- }
- else
- {
- paused = false;
- btn_encode.Enabled = false;
- mainWindow.setLastAction("encode");
- mainWindow.setEncodeStarted();
+ setUIEncodeStarted();
+ MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
- // Start the encode
- try
- {
- // Setup or reset some values
- btn_encode.Enabled = false;
- btn_stop.Visible = true;
+ if (!queue.isEncodeStarted)
+ queue.startEncode();
- theQ = new Thread(startProc);
- theQ.IsBackground = true;
- theQ.Start();
- }
- catch (Exception exc)
- {
- MessageBox.Show(exc.ToString());
- }
- }
- }
}
- private void btn_stop_Click(object sender, EventArgs e)
+ private void btn_pause_Click(object sender, EventArgs e)
{
- paused = true;
- btn_stop.Visible = false;
- btn_encode.Enabled = true;
- mainWindow.setEncodeFinished();
+ queue.pauseEncode();
+ setUIEncodeFinished();
resetQueue();
MessageBox.Show("No further items on the queue will start. The current encode process will continue until it is finished. \nClick 'Encode Video' when you wish to continue encoding the queue.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
- // Starts the encoding process
- private void startProc(object state)
+ // Window Display Management
+ private void setUIEncodeStarted()
{
- try
+ if (this.InvokeRequired)
{
- // Run through each item on the queue
- while (queue.count() != 0)
- {
- string query = queue.getNextItemForEncoding();
- queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
-
- setCurrentEncodeInformation();
- if (this.Created)
- updateUIElements();
-
- hbProc = cliObj.runCli(this, query);
-
- hbProc.WaitForExit();
- cliObj.addCLIQueryToLog(query);
- cliObj.copyLog(query, queue.getLastQueryItem().Destination);
-
- hbProc.Close();
- hbProc.Dispose();
- hbProc = null;
- query = "";
-
- while (paused == true) // Need to find a better way of doing this.
- {
- Thread.Sleep(10000);
- }
- }
-
- resetQueue();
-
- // After the encode is done, we may want to shutdown, suspend etc.
- cliObj.afterEncodeAction();
+ this.BeginInvoke(new UpdateHandler(setUIEncodeStarted));
+ return;
}
- catch (Exception exc)
+ btn_encode.Enabled = false;
+ btn_pause.Visible = true;
+ }
+ private void setUIEncodeFinished()
+ {
+ if (this.InvokeRequired)
{
- MessageBox.Show(exc.ToString());
+ this.BeginInvoke(new UpdateHandler(setUIEncodeFinished));
+ return;
}
+ btn_pause.Visible = false;
+ btn_encode.Enabled = true;
}
-
- // Window Display Management
- private void resetQueue()
+ private void resetQueue()
{
- try
+ if (this.InvokeRequired)
{
- if (this.InvokeRequired)
- {
- this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
- return;
- }
- btn_stop.Visible = false;
- btn_encode.Enabled = true;
-
- lbl_source.Text = "-";
- lbl_dest.Text = "-";
- lbl_vEnc.Text = "-";
- lbl_aEnc.Text = "-";
- lbl_title.Text = "-";
- lbl_chapt.Text = "-";
+ this.BeginInvoke(new UpdateHandler(resetQueue));
+ return;
+ }
+ btn_pause.Visible = false;
+ btn_encode.Enabled = true;
- lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
+ lbl_source.Text = "-";
+ lbl_dest.Text = "-";
+ lbl_vEnc.Text = "-";
+ lbl_aEnc.Text = "-";
+ lbl_title.Text = "-";
+ lbl_chapt.Text = "-";
- mainWindow.setEncodeFinished(); // Tell the main window encodes have finished.
- }
- catch (Exception exc)
- {
- MessageBox.Show(exc.ToString());
- }
+ lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
}
- private void redrawQueue()
+ private void redrawQueue()
{
+ if (this.InvokeRequired)
+ {
+ this.BeginInvoke(new UpdateHandler(redrawQueue));
+ return;
+ }
+
list_queue.Items.Clear();
List<Queue.QueueItem> theQueue = queue.getQueue();
foreach (Queue.QueueItem queue_item in theQueue)
@@ -224,31 +164,24 @@ namespace Handbrake list_queue.Items.Add(item);
}
}
- private void updateUIElements()
+ private void updateUIElements()
{
- try
+ if (this.InvokeRequired)
{
- if (this.InvokeRequired)
- {
- this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
- return;
- }
-
- redrawQueue();
- lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
- }
- catch (Exception exc)
- {
- MessageBox.Show(exc.ToString());
+ this.BeginInvoke(new UpdateHandler(updateUIElements));
+ return;
}
+
+ redrawQueue();
+ lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
}
- private void setCurrentEncodeInformation()
+ private void setCurrentEncodeInformation()
{
try
{
if (this.InvokeRequired)
{
- this.BeginInvoke(new setEncoding(setCurrentEncodeInformation));
+ this.BeginInvoke(new UpdateHandler(setCurrentEncodeInformation));
}
// found query is a global varible
@@ -256,7 +189,6 @@ namespace Handbrake lbl_source.Text = queue.getLastQueryItem().Source;
lbl_dest.Text = queue.getLastQueryItem().Destination;
-
if (parsed.DVDTitle == 0)
lbl_title.Text = "Auto";
else
@@ -293,7 +225,7 @@ namespace Handbrake queue.moveUp(selected);
queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
- redrawQueue();
+ updateUIElements();
if (selected - 1 > 0)
list_queue.Items[selected - 1].Selected = true;
@@ -309,7 +241,7 @@ namespace Handbrake queue.moveDown(list_queue.SelectedIndices[0]);
queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
- redrawQueue();
+ updateUIElements();
if (selected + 1 < list_queue.Items.Count)
list_queue.Items[selected + 1].Selected = true;
@@ -323,7 +255,7 @@ namespace Handbrake {
queue.remove(list_queue.SelectedIndices[0]);
queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
- redrawQueue();
+ updateUIElements();
lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
}
}
@@ -335,7 +267,7 @@ namespace Handbrake {
queue.remove(list_queue.SelectedIndices[0]);
queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
- redrawQueue();
+ updateUIElements();
}
}
}
@@ -363,7 +295,7 @@ namespace Handbrake OpenFile.ShowDialog();
if (OpenFile.FileName != String.Empty)
queue.recoverQueue(OpenFile.FileName);
- redrawQueue();
+ updateUIElements();
}
// Hide's the window when the user tries to "x" out of the window instead of closing it.
@@ -373,6 +305,5 @@ namespace Handbrake this.Hide();
base.OnClosing(e);
}
-
}
}
\ No newline at end of file |