\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
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
/// </summary>\r
public void afterEncodeAction()\r
{\r
+ encoding = false;\r
// Do something whent he encode ends.\r
switch (Properties.Settings.Default.CompletionOption)\r
{\r
}\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
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
// 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
updateTextFromThread();\r
while (true)\r
{\r
- if (queueWindow.isEncoding() == true)\r
+ if (encodeHandler.isEncoding == true)\r
updateTextFromThread();\r
else\r
{\r
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
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
{\r
queueWindow.frmMain_cancelEncode();\r
if (!queueWindow.isEncoding())\r
- setEncodeStatus(0);\r
+ setEncodeFinished();\r
}\r
}\r
else\r
\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
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
/// 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
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
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
}\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
{\r
this.BeginInvoke(new ProgressUpdateHandler(resetQueue));\r
return;\r
-\r
}\r
btn_stop.Visible = false;\r
btn_encode.Enabled = true;\r
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