using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using NEROLib;
namespace NeroFiddlesCOM.NET
{
///
/// Summary description for ChooseSession.
///
public class ChooseSessionForm : System.Windows.Forms.Form
{
private NeroDrive m_drive;
private _INeroDriveEvents_OnDoneCDInfoEventHandler m_evOnDoneCDInfo;
private ControlEnabler m_controlEnabler;
private System.Windows.Forms.Button c_OK;
private System.Windows.Forms.Button c_Cancel;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ListView c_PreviousVMS;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ListView c_PreviousSessions;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.Button c_Refresh;
private System.Windows.Forms.Label label6;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public ChooseSessionForm(NeroDrive drive)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
m_drive = drive;
m_controlEnabler = new ControlEnabler (this);
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.c_OK = new System.Windows.Forms.Button();
this.c_Cancel = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.c_PreviousVMS = new System.Windows.Forms.ListView();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.c_PreviousSessions = new System.Windows.Forms.ListView();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.c_Refresh = new System.Windows.Forms.Button();
this.label6 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// c_OK
//
this.c_OK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.c_OK.Location = new System.Drawing.Point(224, 24);
this.c_OK.Name = "c_OK";
this.c_OK.TabIndex = 5;
this.c_OK.Text = "OK";
//
// c_Cancel
//
this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.c_Cancel.Location = new System.Drawing.Point(224, 56);
this.c_Cancel.Name = "c_Cancel";
this.c_Cancel.TabIndex = 6;
this.c_Cancel.Text = "Cancel";
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 8);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(100, 16);
this.label5.TabIndex = 0;
this.label5.Text = "Previous sessions:";
//
// c_PreviousVMS
//
this.c_PreviousVMS.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader4,
this.columnHeader2});
this.c_PreviousVMS.Enabled = false;
this.c_PreviousVMS.FullRowSelect = true;
this.c_PreviousVMS.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.c_PreviousVMS.HideSelection = false;
this.c_PreviousVMS.Location = new System.Drawing.Point(8, 160);
this.c_PreviousVMS.MultiSelect = false;
this.c_PreviousVMS.Name = "c_PreviousVMS";
this.c_PreviousVMS.Size = new System.Drawing.Size(208, 112);
this.c_PreviousVMS.TabIndex = 3;
this.c_PreviousVMS.View = System.Windows.Forms.View.Details;
//
// columnHeader4
//
this.columnHeader4.Text = "T#";
this.columnHeader4.Width = 33;
//
// columnHeader2
//
this.columnHeader2.Text = "Session Name";
this.columnHeader2.Width = 152;
//
// c_PreviousSessions
//
this.c_PreviousSessions.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader3,
this.columnHeader1});
this.c_PreviousSessions.Enabled = false;
this.c_PreviousSessions.FullRowSelect = true;
this.c_PreviousSessions.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.c_PreviousSessions.HideSelection = false;
this.c_PreviousSessions.Location = new System.Drawing.Point(8, 24);
this.c_PreviousSessions.MultiSelect = false;
this.c_PreviousSessions.Name = "c_PreviousSessions";
this.c_PreviousSessions.Size = new System.Drawing.Size(208, 112);
this.c_PreviousSessions.TabIndex = 1;
this.c_PreviousSessions.View = System.Windows.Forms.View.Details;
//
// columnHeader3
//
this.columnHeader3.Text = "Session number";
this.columnHeader3.Width = 97;
//
// columnHeader1
//
this.columnHeader1.Text = "Track number";
this.columnHeader1.Width = 85;
//
// c_Refresh
//
this.c_Refresh.Location = new System.Drawing.Point(224, 112);
this.c_Refresh.Name = "c_Refresh";
this.c_Refresh.TabIndex = 4;
this.c_Refresh.Text = "Refresh";
this.c_Refresh.Click += new System.EventHandler(this.c_Refresh_Click);
//
// label6
//
this.label6.Location = new System.Drawing.Point(8, 144);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(100, 16);
this.label6.TabIndex = 2;
this.label6.Text = "Previous VMS:";
//
// ChooseSessionForm
//
this.AcceptButton = this.c_OK;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.c_Cancel;
this.ClientSize = new System.Drawing.Size(306, 280);
this.Controls.Add(this.label5);
this.Controls.Add(this.c_PreviousVMS);
this.Controls.Add(this.c_PreviousSessions);
this.Controls.Add(this.c_Refresh);
this.Controls.Add(this.label6);
this.Controls.Add(this.c_OK);
this.Controls.Add(this.c_Cancel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ChooseSessionForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "ChooseSession";
this.ResumeLayout(false);
}
#endregion
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
// On load, display the sessions.
//
RefreshSessions ();
}
private void RefreshSessions()
{
// Subscribe to the OnDoneCDInfo event.
//
m_evOnDoneCDInfo = new _INeroDriveEvents_OnDoneCDInfoEventHandler(m_drive_OnDoneCDInfo);
m_drive.OnDoneCDInfo += m_evOnDoneCDInfo;
// We could do a this.Enabled=false here but then the wait
// cursor will always be the arrow.
//
m_controlEnabler.EnableAllControls (false);
this.Cursor = Cursors.WaitCursor;
// When everything is setup, do the disc info.
//
m_drive.CDInfo (0);
}
private void c_Refresh_Click(object sender, System.EventArgs e)
{
// Refresh everything on request...
//
RefreshSessions ();
}
private void m_drive_OnDoneCDInfo(INeroCDInfo pCDInfo)
{
// When the disc info event fires, we should return
// to the previous state of all controls, restore the
// cursor and unsubscribe from the event.
//
m_controlEnabler.EnableAllControls (true);
m_drive.OnDoneCDInfo -= m_evOnDoneCDInfo;
c_PreviousSessions.Items.Clear ();
c_PreviousVMS.Items.Clear ();
NeroCDInfo cdinfo = (NeroCDInfo) pCDInfo;
if (cdinfo != null)
{
// If we got a disc information, let's add all the data
// tracks to the list view.
//
int iTrackCount = 0;
foreach (NeroTrack trk in cdinfo.Tracks)
{
if (trk.TrackType == NERO_TRACK_TYPE.NERO_TT_DATA)
{
iTrackCount ++;
ListViewItem lvi = c_PreviousSessions.Items.Add (trk.SessionNumber.ToString ());
lvi.SubItems.Add (trk.TrackNumber.ToString ());
}
}
int iVMSCount = 0;
bool bVMS = 0 != (cdinfo.MediumFlags & NERO_MEDIUM_FLAGS.NCDIMF_VIRTUALMULTISESSION);
// If there is VMS info, display that as well.
//
if (bVMS)
{
NeroVMSInfo vmsInfo = m_drive.GetVMSInfo ();
if (vmsInfo != null)
{
iVMSCount = vmsInfo.Count;
int i = 1;
foreach (NeroVMSSession vmsSession in vmsInfo)
{
ListViewItem lvi = c_PreviousVMS.Items.Add (i.ToString ());
lvi.SubItems.Add (vmsSession.SessionName);
i++;
}
}
}
c_PreviousSessions.Enabled = !bVMS && iTrackCount > 0;
c_PreviousVMS.Enabled = bVMS && iVMSCount > 0;
}
else
{
c_PreviousSessions.Enabled = false;
c_PreviousVMS.Enabled = false;
}
this.Cursor = Cursors.Default;
}
// This is a public function for the outside world to
// find out which is the selected previous session,
// if any. It is required that NERO_IMPORT_ISO_TRACK_FLAGS
// variable is passed by reference so that it is modified
// if needed.
//
public int GetTrackNumber (ref NERO_IMPORT_ISO_TRACK_FLAGS importFlags)
{
int iTrackNumber = -1;
if (c_PreviousSessions.Enabled && c_PreviousSessions.SelectedIndices.Count > 0)
{
iTrackNumber = Convert.ToInt32 (c_PreviousSessions.SelectedItems[0].SubItems[0].Text);
}
else if (c_PreviousVMS.Enabled && c_PreviousVMS.SelectedIndices.Count > 0)
{
iTrackNumber = Convert.ToInt32 (c_PreviousVMS.SelectedItems[0].Text);
importFlags = (NERO_IMPORT_ISO_TRACK_FLAGS) ((uint)importFlags + (uint)NERO_IMPORT_ISO_TRACK_FLAGS.NERO_IMPORT_VMS_SESSION);
}
return iTrackNumber;
}
// This is a ToString override that returns the description of
// the currently selected session.
//
public new string ToString ()
{
NERO_IMPORT_ISO_TRACK_FLAGS importFlags = 0;
int iTrackNumber = GetTrackNumber (ref importFlags);
if (iTrackNumber != -1)
{
return iTrackNumber.ToString () + (0 != (importFlags & NERO_IMPORT_ISO_TRACK_FLAGS.NERO_IMPORT_VMS_SESSION)? " (VMS)" : "");
}
else
{
return "";
}
}
}
}