diff options
author | sr55 <[email protected]> | 2009-07-24 15:42:39 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2009-07-24 15:42:39 +0000 |
commit | d16e56ddc7fa2c768dfd3013d1550fbf74eae641 (patch) | |
tree | e1ebc209f08d5c76f8f1974c6e6f40d7c59e264c /win/C# | |
parent | c27af07ac1576c950ba8f1967ee32b9a1fcf43f1 (diff) |
WinGui:
- Some minor improvements to the ActivityWindow. The window now correctly views the correct log when a user starts a new scan or new encode.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2727 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#')
-rw-r--r-- | win/C#/EncodeQueue/EncodeAndQueueHandler.cs | 2 | ||||
-rw-r--r-- | win/C#/frmActivityWindow.cs | 154 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 16 |
3 files changed, 50 insertions, 122 deletions
diff --git a/win/C#/EncodeQueue/EncodeAndQueueHandler.cs b/win/C#/EncodeQueue/EncodeAndQueueHandler.cs index 09d1f1419..319163de6 100644 --- a/win/C#/EncodeQueue/EncodeAndQueueHandler.cs +++ b/win/C#/EncodeQueue/EncodeAndQueueHandler.cs @@ -1,4 +1,4 @@ -/* QueueHandler.cs $
+/* EncodeAndQueueHandler.cs $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr/>.
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs index 84f9bddd5..c09920126 100644 --- a/win/C#/frmActivityWindow.cs +++ b/win/C#/frmActivityWindow.cs @@ -5,6 +5,7 @@ It may be used under the terms of the GNU General Public License. */
using System;
+using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Threading;
@@ -17,32 +18,22 @@ namespace Handbrake {
public partial class frmActivityWindow : Form
{
- delegate void SetTextCallback(string text);
- String read_file;
- Thread monitor;
- EncodeAndQueueHandler encodeQueue;
- int position; // Position in the arraylist reached by the current log output in the rtf box.
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ private delegate void SetTextCallback(string text);
+ private String read_file;
+ private Thread monitor;
+ private EncodeAndQueueHandler encodeQueue;
+ private int position; // Position in the arraylist reached by the current log output in the rtf box.
+ private string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
private frmMain mainWin;
+ private Boolean lastUpdate;
- /// <summary>
- /// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.
- /// </summary>
public frmActivityWindow(string file, EncodeAndQueueHandler eh, frmMain mw)
{
InitializeComponent();
- rtf_actLog.Text = string.Empty;
encodeQueue = eh;
- position = 0;
mainWin = mw;
- // When the window closes, we want to abort the monitor thread.
- this.Disposed += new EventHandler(forceQuit);
-
- // Print the Log header in the Rich text box.
- displayLogHeader();
-
if (file == "last_scan_log.txt")
setLogView(true);
else
@@ -53,11 +44,17 @@ namespace Handbrake }
/// <summary>
- /// Set the file which the log window is viewing.
+ /// Set the view which the Log window displays.
+ /// Scan = true;
+ /// Encode = false;
/// </summary>
- /// <param name="scan"></param>
+ /// <param name="scan">Boolean. Scan = true</param>
public void setLogView(Boolean scan)
{
+ position = 0;
+ rtf_actLog.Text = String.Empty;
+ displayLogHeader();
+
if (scan)
{
txt_log.Text = "Scan Log";
@@ -68,11 +65,8 @@ namespace Handbrake read_file = "last_encode_log.txt";
txt_log.Text = "Encode Log";
}
+ lastUpdate = false;
}
-
- /// <summary>
- /// Displays the Log header
- /// </summary>
private void displayLogHeader()
{
// Add a header to the log file indicating that it's from the Windows GUI and display the windows version
@@ -91,11 +85,6 @@ namespace Handbrake rtf_actLog.AppendText("#########################################\n\n");
}
}
-
- /// <summary>
- /// Starts a new thread which runs the autoUpdate function.
- /// </summary>
- /// <param name="file"> File which will be used to populate the Rich text box.</param>
private void startLogThread(string file)
{
try
@@ -103,9 +92,7 @@ namespace Handbrake string logFile = Path.Combine(logDir, file);
if (File.Exists(logFile))
{
- // Start a new thread to run the autoUpdate process
- monitor = new Thread(autoUpdate);
- monitor.IsBackground = true;
+ monitor = new Thread(autoUpdate) { IsBackground = true };
monitor.Start();
}
else
@@ -117,48 +104,36 @@ namespace Handbrake MessageBox.Show("startLogThread(): Exception: \n" + exc);
}
}
-
- /// <summary>
- /// Updates the log window with any new data which is in the log file.
- /// This is done every 5 seconds.
- /// </summary>
- /// <param name="state"></param>
private void autoUpdate(object state)
{
try
{
- Boolean lastUpdate = false;
+ lastUpdate = false;
updateTextFromThread();
while (true)
{
- if (encodeQueue.isEncoding || mainWin.isScanning)
- updateTextFromThread();
- else
+ if (IsHandleCreated)
{
- // The encode may just have stoped, so, refresh the log one more time before restarting it.
- if (lastUpdate == false)
+ if (encodeQueue.isEncoding || mainWin.isScanning)
updateTextFromThread();
-
- lastUpdate = true; // Prevents the log window from being updated when there is no encode going.
- position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused
+ else
+ {
+ // The encode may just have stoped, so, refresh the log one more time before restarting it.
+ if (lastUpdate == false)
+ updateTextFromThread();
+
+ lastUpdate = true; // Prevents the log window from being updated when there is no encode going.
+ position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused
+ }
}
- Thread.Sleep(5000);
+ Thread.Sleep(1000);
}
}
- catch (ThreadAbortException)
- {
- // Do Nothing. This is needed since we run thread.abort().
- // Should probably find a better way of making this work at some point.
- }
catch (Exception exc)
{
MessageBox.Show("autoUpdate(): Exception: \n" + exc);
}
}
-
- /// <summary>
- /// Finds any new text in the log file and calls a funciton to display this new text.
- /// </summary>
private void updateTextFromThread()
{
try
@@ -174,26 +149,17 @@ namespace Handbrake MessageBox.Show("updateTextFromThread(): Exception: \n" + exc);
}
}
-
- /// <summary>
- /// Updates the rich text box with anything in the string text.
- /// </summary>
- /// <param name="text"></param>
private void SetText(string text)
{
try
{
- // InvokeRequired required compares the thread ID of the
- // calling thread to the thread ID of the creating thread.
- // If these threads are different, it returns true.
- if (IsHandleCreated) // Make sure the windows has a handle before doing anything
+ if (IsHandleCreated)
{
if (rtf_actLog.InvokeRequired)
{
- SetTextCallback d = new SetTextCallback(SetText);
- Invoke(d, new object[] { text });
- }
- else
+ IAsyncResult invoked = BeginInvoke(new SetTextCallback(SetText), new object[] {text});
+ EndInvoke(invoked);
+ } else
rtf_actLog.AppendText(text);
}
}
@@ -202,11 +168,6 @@ namespace Handbrake MessageBox.Show("SetText(): Exception: \n" + exc);
}
}
-
- /// <summary>
- /// Read the log file, and store the data in a List.
- /// </summary>
- /// <returns></returns>
private String readFile()
{
String appendText = String.Empty;
@@ -249,24 +210,14 @@ namespace Handbrake return null;
}
- /// <summary>
- /// Kills the montior thead when the window is disposed of.
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void forceQuit(object sender, EventArgs e)
+ protected override void OnClosing(CancelEventArgs e)
{
- if (monitor != null)
- {
- while (monitor.IsAlive)
- monitor.Abort();
- }
-
- this.Close();
+ e.Cancel = true;
+ this.Hide();
+ base.OnClosing(e);
}
#region User Interface
-
private void mnu_copy_log_Click(object sender, EventArgs e)
{
if (rtf_actLog.SelectedText != "")
@@ -292,37 +243,15 @@ namespace Handbrake }
private void btn_scan_log_Click(object sender, EventArgs e)
{
- // Switch to the scan log.
-
- if (monitor != null)
- monitor.Abort();
-
- rtf_actLog.Clear();
- read_file = "last_scan_log.txt";
- displayLogHeader();
- startLogThread(read_file);
- txt_log.Text = "Scan Log";
+ setLogView(true);
}
private void btn_encode_log_Click(object sender, EventArgs e)
{
- // Switch to the encode log
-
- if (monitor != null)
- monitor.Abort();
-
- rtf_actLog.Clear();
- read_file = "last_encode_log.txt";
- position = 0;
- displayLogHeader();
- startLogThread(read_file);
- txt_log.Text = "Encode Log";
+ setLogView(false);
}
-
#endregion
#region System Information
-
-
/// <summary>
/// Returns the total physical ram in a system
/// </summary>
@@ -357,7 +286,6 @@ namespace Handbrake {
return Screen.PrimaryScreen;
}
-
#endregion
}
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index f385b1507..413847d51 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -31,8 +31,10 @@ namespace Handbrake private DVD thisDVD;
private frmQueue queueWindow;
private frmPreview qtpreview;
+ private frmActivityWindow ActivityWindow;
private Form splash;
public string sourcePath;
+ private string lastAction;
// Delegates **********************************************************
private delegate void UpdateWindowHandler();
@@ -713,6 +715,7 @@ namespace Handbrake queueWindow.Show(false);
setEncodeStarted(); // Encode is running, so setup the GUI appropriately
+ ActivityWindow.setLogView(false);
encodeQueue.StartEncodeQueue(); // Start The Queue Encoding Process
lastAction = "encode"; // Set the last action to encode - Used for activity window.
}
@@ -773,8 +776,9 @@ namespace Handbrake private void btn_ActivityWindow_Click(object sender, EventArgs e)
{
String file = lastAction == "scan" ? "last_scan_log.txt" : "last_encode_log.txt";
-
- frmActivityWindow ActivityWindow = new frmActivityWindow(file, encodeQueue, this);
+ if (ActivityWindow == null)
+ ActivityWindow = new frmActivityWindow(file, encodeQueue, this);
+
ActivityWindow.Show();
}
#endregion
@@ -1386,6 +1390,7 @@ namespace Handbrake {
lbl_encode.Visible = true;
lbl_encode.Text = "Scanning...";
+ ActivityWindow.setLogView(true);
isScanning = true;
ThreadPool.QueueUserWorkItem(scanProcess, filename);
}
@@ -1680,12 +1685,7 @@ namespace Handbrake presetHandler.getPresetPanel(ref treeView_presets);
treeView_presets.Update();
- }
-
- /// <summary>
- /// Either Encode or Scan was last performed.
- /// </summary>
- public string lastAction { get; set; }
+ }
#endregion
#region Overrides
|