diff options
Diffstat (limited to 'win/C#/frmQueue.cs')
-rw-r--r-- | win/C#/frmQueue.cs | 298 |
1 files changed, 109 insertions, 189 deletions
diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs index 4ffa628ba..3444a167c 100644 --- a/win/C#/frmQueue.cs +++ b/win/C#/frmQueue.cs @@ -13,59 +13,46 @@ 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 encode queue Handlnig
-
- // Declarations
+ #region Queue Handling
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 (listview_queue.Items.Count != 0)
+ if (list_queue.Items.Count != 0)
{
// Setup or reset some values
btn_cancel.Visible = true;
progressBar.Value = 0;
lbl_progressValue.Text = "0 %";
- progressBar.Step = 100 / listview_queue.Items.Count;
+ progressBar.Step = 100 / list_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;
@@ -73,18 +60,21 @@ 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 (listview_queue.Items.Count != 0)
+ while (list_queue.Items.Count != 0)
{
- getItem();
- string query = foundQuery;
- query = query.Replace("ListViewItem: { ", "").Replace(" }", "").Trim();
- updateUIElements();
+ string query = list_queue.Items[0].ToString();
setEncValue();
-
+ updateUIElements();
+
Functions.CLI process = new Functions.CLI();
Process hbProc = process.runCli(this, query, false, false, false, false);
@@ -98,11 +88,11 @@ namespace Handbrake {
break;
}
-
+
}
resetQueue();
-
+
// Do something whent he encode ends.
switch (Properties.Settings.Default.CompletionOption)
{
@@ -134,72 +124,6 @@ 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
@@ -209,7 +133,7 @@ namespace Handbrake this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
return;
}
- this.listview_queue.Items.RemoveAt(0);
+ this.list_queue.Items.RemoveAt(0);
progressBar.PerformStep();
lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
@@ -235,11 +159,13 @@ 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;
@@ -259,144 +185,138 @@ namespace Handbrake MessageBox.Show(exc.ToString());
}
}
+
+ private void setEncValue()
+ {
+ try
+ {
+ if (this.InvokeRequired)
+ {
+ this.BeginInvoke(new setEncoding(setEncValue));
+ }
+
+ string query = query = list_queue.Items[0].ToString();
+
+ // found query is a global varible
+ Functions.QueryParser parsed = Functions.QueryParser.Parse(query);
+ 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
+ }
+ }
#endregion
#region Queue Management
+
private void btn_up_Click(object sender, EventArgs e)
{
- string cache;
- int selIdx;
- if (listview_queue.Items.Count != 0)
- {
- selIdx = listview_queue.SelectedItems[0].Index;
- // ignore moveup of row(0)
- if (selIdx == 0)
- return;
+ int count = list_queue.Items.Count;
+ int itemToMove = list_queue.SelectedIndex;
+ int previousItemint = 0;
+ String previousItem = "";
- // 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();
+ if (itemToMove > 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;
}
}
private void btn_down_Click(object sender, EventArgs e)
{
- string cache;
- int selIdx;
-
- if (listview_queue.Items.Count != 0)
- {
- selIdx = listview_queue.SelectedItems[0].Index;
+ int count = list_queue.Items.Count;
+ int itemToMove = list_queue.SelectedIndex;
+ int itemAfterInt = 0;
+ String itemAfter = "";
- // 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();
+ if (itemToMove < (count - 1))
+ {
+ 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;
}
}
private void btn_delete_Click(object sender, EventArgs e)
{
- for (int i = listview_queue.SelectedItems.Count - 1; i >= 0; i--)
- {
- ListViewItem item = listview_queue.SelectedItems[i];
- listview_queue.Items.Remove(item);
- }
+ list_queue.Items.Remove(list_queue.SelectedItem);
}
+
#endregion
- #region Modify Queue
+ #region Queue Item Modification
int listCount = 0;
- private void listview_queue_SelectedIndexChanged(object sender, EventArgs e)
- {
- modQ();
- listCount = listview_queue.Items.Count;
- }
- private void modQ()
+ private void btn_updateQuery_Click(object sender, EventArgs e)
{
- try
+ if (text_edit.Text != "")
{
- if (this.InvokeRequired)
+ if (list_queue.Items.Count != listCount)
{
- this.BeginInvoke(new modifyQueue(modQ));
+ 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);
}
-
- 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 btn_update_Click(object sender, EventArgs e)
- {
- try
- {
- if (txt_editQuery.Text != "")
+ else
{
- if (listview_queue.Items.Count != listCount)
+ if (list_queue.SelectedItem != null)
{
- 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());
- }
+ }
+
+ private void list_queue_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (list_queue.SelectedItem != null)
+ text_edit.Text = list_queue.SelectedItem.ToString();
+
+ listCount = list_queue.Items.Count;
}
#endregion
- protected override void OnClosing(CancelEventArgs e)
+ private void btn_Close_Click(object sender, EventArgs e)
{
- e.Cancel = true;
this.Hide();
- base.OnClosing(e);
}
- private void btn_Close_Click(object sender, EventArgs e)
+ protected override void OnClosing(CancelEventArgs e)
{
+ e.Cancel = true;
this.Hide();
+ base.OnClosing(e);
}
}
|