diff options
author | sr55 <[email protected]> | 2007-11-18 23:09:49 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2007-11-18 23:09:49 +0000 |
commit | 0690db87ecdd90d33c3c3f43113bedb497b6305d (patch) | |
tree | 01eeffc061b28f69556c834753d958c6918b4d4a /win/C#/frmQueue.cs | |
parent | af3277fd9e511b768a083bc77023e2e0437578fc (diff) |
WinGui:
- Changed Queue to a listview.
- Added human readable encode information for the item currently encoding.
- Window design improved.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1066 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/frmQueue.cs')
-rw-r--r-- | win/C#/frmQueue.cs | 260 |
1 files changed, 198 insertions, 62 deletions
diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs index eaa8904b1..4ffa628ba 100644 --- a/win/C#/frmQueue.cs +++ b/win/C#/frmQueue.cs @@ -13,45 +13,59 @@ namespace Handbrake {
public partial class frmQueue : Form
{
+ // Declarations
private delegate void ProgressUpdateHandler();
+ private delegate void getQueueItem();
+ private delegate void setEncoding();
+ private delegate void modifyQueue();
+ // Everything starts Here
public frmQueue()
{
InitializeComponent();
}
- #region Queue Handling
+ #region encode queue Handlnig
+
+ // Declarations
Boolean cancel = false;
+ string foundQuery = "";
+ [DllImport("user32.dll")]
+ public static extern void LockWorkStation();
+ [DllImport("user32.dll")]
+ public static extern int ExitWindowsEx(int uFlags, int dwReason);
+
+ // Methods
private void btn_q_encoder_Click(object sender, EventArgs e)
{
// Reset some values
-
+
lbl_status.Visible = false;
cancel = false;
// Start the encode
try
{
- if (list_queue.Items.Count != 0)
+ if (listview_queue.Items.Count != 0)
{
// Setup or reset some values
btn_cancel.Visible = true;
progressBar.Value = 0;
lbl_progressValue.Text = "0 %";
- progressBar.Step = 100 / list_queue.Items.Count;
+ progressBar.Step = 100 / listview_queue.Items.Count;
progressBar.Update();
//ThreadPool.QueueUserWorkItem(startProc);
// Testing a new way of launching a thread. Hopefully will fix a random freeze up of the main thread.
Thread theQ = new Thread(startProc);
theQ.Start();
- }
+ }
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
-
}
+
private void btn_cancel_Click(object sender, EventArgs e)
{
cancel = true;
@@ -59,21 +73,18 @@ namespace Handbrake 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);
}
- [DllImport("user32.dll")]
- public static extern void LockWorkStation();
- [DllImport("user32.dll")]
- public static extern int ExitWindowsEx(int uFlags, int dwReason);
-
private void startProc(object state)
{
try
{
- while (list_queue.Items.Count != 0)
+ while (listview_queue.Items.Count != 0)
{
- string query = list_queue.Items[0].ToString();
-
+ getItem();
+ string query = foundQuery;
+ query = query.Replace("ListViewItem: { ", "").Replace(" }", "").Trim();
updateUIElements();
-
+ setEncValue();
+
Functions.CLI process = new Functions.CLI();
Process hbProc = process.runCli(this, query, false, false, false, false);
@@ -87,11 +98,10 @@ namespace Handbrake {
break;
}
-
+
}
resetQueue();
-
// Do something whent he encode ends.
switch (Properties.Settings.Default.CompletionOption)
@@ -124,6 +134,72 @@ namespace Handbrake }
}
+ private void getItem()
+ {
+ try
+ {
+ if (this.InvokeRequired)
+ {
+ this.BeginInvoke(new getQueueItem(getItem));
+ }
+ foundQuery = this.listview_queue.Items[0].ToString();
+ }
+ catch (Exception)
+ {
+ // Do Nothing
+ }
+ }
+
+ private void setEncValue()
+ {
+ try
+ {
+ if (this.InvokeRequired)
+ {
+ this.BeginInvoke(new setEncoding(setEncValue));
+ }
+
+ string query = null;
+ ListView.SelectedListViewItemCollection name = null;
+ name = listview_queue.SelectedItems;
+
+ if (listview_queue.SelectedItems.Count != 0)
+ query = name[0].SubItems[0].Text;
+
+ // found query is a global varible
+ Functions.QueryParser parsed = Functions.QueryParser.Parse(foundQuery);
+ lbl_source.Text = parsed.Source;
+ lbl_dest.Text = parsed.Destination;
+
+
+ if (parsed.DVDTitle == 0)
+ lbl_title.Text = "Auto";
+ else
+ lbl_title.Text = parsed.DVDTitle.ToString();
+
+ string chatpers = "";
+ if (parsed.DVDChapterStart == 0)
+ {
+ lbl_chapt.Text = "Auto";
+ }
+ else
+ {
+ chatpers = parsed.DVDChapterStart.ToString();
+ if (parsed.DVDChapterFinish != 0)
+ chatpers = chatpers + " - " + parsed.DVDChapterFinish;
+ lbl_chapt.Text = parsed.DVDChapterStart + chatpers;
+ }
+
+ lbl_vEnc.Text = parsed.VideoEncoder;
+ lbl_aEnc.Text = parsed.AudioEncoder;
+ }
+ catch (Exception)
+ {
+ // Do Nothing
+ }
+
+ }
+
private void updateUIElements()
{
try
@@ -133,7 +209,7 @@ namespace Handbrake this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
return;
}
- this.list_queue.Items.RemoveAt(0);
+ this.listview_queue.Items.RemoveAt(0);
progressBar.PerformStep();
lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
@@ -159,19 +235,24 @@ namespace Handbrake {
lbl_status.Visible = true;
lbl_status.Text = "Encode Queue Cancelled!";
- text_edit.Text = "";
}
else
{
lbl_status.Visible = true;
lbl_status.Text = "Encode Queue Completed!";
- text_edit.Text = "";
}
btn_cancel.Visible = false;
lbl_progressValue.Text = "0 %";
progressBar.Value = 0;
progressBar.Update();
+
+ lbl_source.Text = "-";
+ lbl_dest.Text = "-";
+ lbl_vEnc.Text = "-";
+ lbl_aEnc.Text = "-";
+ lbl_title.Text = "-";
+ lbl_chapt.Text = "-";
}
catch (Exception exc)
{
@@ -184,83 +265,138 @@ namespace Handbrake #region Queue Management
private void btn_up_Click(object sender, EventArgs e)
{
- int count = list_queue.Items.Count;
- int itemToMove = list_queue.SelectedIndex;
- int previousItemint = 0;
- String previousItem = "";
-
- if (itemToMove > 0)
+ string cache;
+ int selIdx;
+ if (listview_queue.Items.Count != 0)
{
- previousItemint = itemToMove - 1;
- previousItem = list_queue.Items[previousItemint].ToString();
- list_queue.Items[previousItemint] = list_queue.Items[itemToMove];
- list_queue.Items[itemToMove] = previousItem;
- list_queue.SelectedIndex = list_queue.SelectedIndex - 1;
+ selIdx = listview_queue.SelectedItems[0].Index;
+ // ignore moveup of row(0)
+ if (selIdx == 0)
+ return;
+
+ // move the subitems for the previous row
+ // to cache to make room for the selected row
+ for (int i = 0; i < listview_queue.Items[selIdx].SubItems.Count; i++)
+ {
+ cache = listview_queue.Items[selIdx - 1].SubItems[i].Text;
+ listview_queue.Items[selIdx - 1].SubItems[i].Text =
+ listview_queue.Items[selIdx].SubItems[i].Text;
+ listview_queue.Items[selIdx].SubItems[i].Text = cache;
+ }
+ listview_queue.Items[selIdx - 1].Selected = true;
+ listview_queue.Refresh();
+ listview_queue.Focus();
}
}
private void btn_down_Click(object sender, EventArgs e)
{
- int count = list_queue.Items.Count;
- int itemToMove = list_queue.SelectedIndex;
- int itemAfterInt = 0;
- String itemAfter = "";
-
- if (itemToMove < (count - 1))
+ string cache;
+ int selIdx;
+
+ if (listview_queue.Items.Count != 0)
{
- itemAfterInt = itemToMove + 1;
- itemAfter = list_queue.Items[itemAfterInt].ToString();
- list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];
- list_queue.Items[itemToMove] = itemAfter;
- list_queue.SelectedIndex = list_queue.SelectedIndex + 1;
+ selIdx = listview_queue.SelectedItems[0].Index;
+
+ // ignore movedown of last item
+ if (selIdx == listview_queue.Items.Count - 1)
+ return;
+ // move the subitems for the next row
+ // to cache so we can move the selected row down
+ for (int i = 0; i < listview_queue.Items[selIdx].SubItems.Count; i++)
+ {
+ cache = listview_queue.Items[selIdx + 1].SubItems[i].Text;
+ listview_queue.Items[selIdx + 1].SubItems[i].Text =
+ listview_queue.Items[selIdx].SubItems[i].Text;
+ listview_queue.Items[selIdx].SubItems[i].Text = cache;
+ }
+ listview_queue.Items[selIdx + 1].Selected = true;
+ listview_queue.Refresh();
+ listview_queue.Focus();
}
}
private void btn_delete_Click(object sender, EventArgs e)
{
- list_queue.Items.Remove(list_queue.SelectedItem);
+ for (int i = listview_queue.SelectedItems.Count - 1; i >= 0; i--)
+ {
+ ListViewItem item = listview_queue.SelectedItems[i];
+ listview_queue.Items.Remove(item);
+ }
}
#endregion
- #region Queue Item Modification
+ #region Modify Queue
int listCount = 0;
+ private void listview_queue_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ modQ();
+ listCount = listview_queue.Items.Count;
+ }
- private void btn_updateQuery_Click(object sender, EventArgs e)
+ private void modQ()
{
- if (text_edit.Text != "")
+ try
{
- if (list_queue.Items.Count != listCount)
- {
- MessageBox.Show("Unable to modify the selected item. The number of items on the list has changed. \nPlease avoid modifying an item when a new encode is about to start!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
+ if (this.InvokeRequired)
{
- if (list_queue.SelectedItem != null)
- list_queue.Items[list_queue.SelectedIndex] = text_edit.Text;
+ this.BeginInvoke(new modifyQueue(modQ));
}
+
+ string query = null;
+ ListView.SelectedListViewItemCollection name = null;
+ name = listview_queue.SelectedItems;
+
+ if (listview_queue.SelectedItems.Count != 0)
+ query = name[0].SubItems[0].Text;
+
+ txt_editQuery.Text = query;
+
+ }
+ catch (Exception)
+ {
}
}
- private void list_queue_SelectedIndexChanged(object sender, EventArgs e)
+ private void btn_update_Click(object sender, EventArgs e)
{
- if (list_queue.SelectedItem != null)
- text_edit.Text = list_queue.SelectedItem.ToString();
-
- listCount = list_queue.Items.Count;
+ try
+ {
+ if (txt_editQuery.Text != "")
+ {
+ if (listview_queue.Items.Count != listCount)
+ {
+ MessageBox.Show("Unable to modify the selected item. The number of items on the list has changed. \nPlease avoid modifying an item when a new encode is about to start!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ else
+ {
+ if (listview_queue.SelectedItems != null)
+ {
+ int selectItm = listview_queue.SelectedIndices[0];
+ listview_queue.Items[selectItm].Text = txt_editQuery.Text;
+ }
+ }
+ }
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show(exc.ToString());
+ }
}
+
#endregion
- private void btn_Close_Click(object sender, EventArgs e)
+ protected override void OnClosing(CancelEventArgs e)
{
+ e.Cancel = true;
this.Hide();
+ base.OnClosing(e);
}
- protected override void OnClosing(CancelEventArgs e)
+ private void btn_Close_Click(object sender, EventArgs e)
{
- e.Cancel = true;
this.Hide();
- base.OnClosing(e);
}
}
|