diff options
author | sr55 <[email protected]> | 2009-01-05 22:28:52 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2009-01-05 22:28:52 +0000 |
commit | c243198c5f3e6fd2505f0a04ad33bfb72e2284ac (patch) | |
tree | cf7bebdffd5777b3f6047bf80afc90846aadee38 /win/C#/Queue | |
parent | 8bd864a502666482a0f47e22d5f671b7c502e027 (diff) |
WinGui:
- Queue Encoding code moved from frmQueue.cs to QueueHandler.cs
- QueueHandler now works has events to allow frmMain and frmQueue to update their UI elements based on event triggers (e.g an encode starting or ending).
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2063 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Queue')
-rw-r--r-- | win/C#/Queue/QueueHandler.cs | 136 |
1 files changed, 133 insertions, 3 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 |