Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-43651, one inconsistency, layout tweaks, and minor refactoring on MultipleDvdIsoList. #3248

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions XenAdmin/ConsoleView/VNCTabView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,10 +1291,12 @@ internal void VMPowerOff()
{
toggleConsoleButton.Enabled = false;

VBD cddrive = source.FindVMCDROM();
bool allowEject = cddrive != null ? cddrive.allowed_operations.Contains(vbd_operations.eject) : false;
bool allowInsert = cddrive != null ? cddrive.allowed_operations.Contains(vbd_operations.insert) : false;
multipleDvdIsoList1.Enabled = (source.power_state == vm_power_state.Halted) && (allowEject || allowInsert);
VBD cdDrive = source.FindVMCDROM();

multipleDvdIsoList1.Enabled = cdDrive == null ||
source.power_state == vm_power_state.Halted &&
(cdDrive.allowed_operations.Contains(vbd_operations.eject) ||
cdDrive.allowed_operations.Contains(vbd_operations.insert));

sendCAD.Enabled = false;
}
Expand Down
2 changes: 2 additions & 0 deletions XenAdmin/Controls/ComboBoxes/ISODropDownBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ private void AddSR(ToStringWrapper<SR> srWrapper)
}
}

[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IXenConnection connection
{
set
Expand Down
33 changes: 11 additions & 22 deletions XenAdmin/Controls/MultipleDvdIsoList.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 71 additions & 77 deletions XenAdmin/Controls/MultipleDvdIsoList.cs
danilo-delbusso marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace XenAdmin.Controls
{
public partial class MultipleDvdIsoList : UserControl
{
bool inRefresh = false;
private bool _inRefresh;

public MultipleDvdIsoList()
{
Expand All @@ -61,7 +61,7 @@ public VM VM
cdChanger1.VM = value;
if (value != null)
cdChanger1.VM.PropertyChanged += vm_PropertyChanged;
refreshDrives();
RefreshDrives();
}
get => cdChanger1.VM;
}
Expand All @@ -72,24 +72,24 @@ public VM VM
[Category("Appearance")]
public Color LabelSingleDvdForeColor
{
get { return labelSingleDvd.ForeColor; }
set { labelSingleDvd.ForeColor = value; }
get => labelSingleDvd.ForeColor;
set => labelSingleDvd.ForeColor = value;
}

[Browsable(true)]
[Category("Appearance")]
public Color LabelNewCdForeColor
{
get { return newCDLabel.ForeColor; }
set { newCDLabel.ForeColor = value; }
get => newCDLabel.ForeColor;
set => newCDLabel.ForeColor = value;
}

[Browsable(true)]
[Category("Appearance")]
public Color LinkLabelLinkColor
{
get { return linkLabel1.LinkColor; }
set { linkLabel1.LinkColor = value; }
get => linkLabelEject.LinkColor;
set => linkLabelEject.LinkColor = value;
}

#endregion
Expand All @@ -115,24 +115,25 @@ internal virtual void DeregisterEvents()
cdChanger1.DeregisterEvents();
}

void vm_PropertyChanged(object sender, PropertyChangedEventArgs e)
private void vm_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "VBDs")
refreshDrives();
RefreshDrives();
}

private void refreshDrives()
private void RefreshDrives()
{
VbdCombiItem prevSelection = comboBoxDrive.SelectedItem as VbdCombiItem;
inRefresh = true;
_inRefresh = true;

foreach (object o in comboBoxDrive.Items)
{
VbdCombiItem v = o as VbdCombiItem;
v.vbd.PropertyChanged -= new PropertyChangedEventHandler(vbd_PropertyChanged);
if (o is VbdCombiItem v)
v.Vbd.PropertyChanged -= vbd_PropertyChanged;
}

comboBoxDrive.Items.Clear();

if (VM != null && !VM.is_control_domain)
{
List<VBD> vbds = VM.Connection.ResolveAll(VM.VBDs);
Expand All @@ -142,122 +143,115 @@ private void refreshDrives()
VM.Connection.CachePopulated += CachePopulatedMethod;
return;
}

vbds.RemoveAll(vbd => !vbd.IsCDROM() && !vbd.IsFloppyDrive());
vbds.Sort();

int dvdCount = 0;
int floppyCount = 0;

foreach (VBD vbd in vbds)
{
vbd.PropertyChanged +=new PropertyChangedEventHandler(vbd_PropertyChanged);
vbd.PropertyChanged += vbd_PropertyChanged;
VbdCombiItem item;

if (vbd.IsCDROM())
{
dvdCount++;
VbdCombiItem i = new VbdCombiItem();
i.name = string.Format(Messages.DVD_DRIVE_LABEL_NUMBERED, dvdCount);
i.vbd = vbd;
comboBoxDrive.Items.Add(i);
item = new VbdCombiItem(string.Format(Messages.DVD_DRIVE_LABEL_NUMBERED, dvdCount), vbd);
}
else
{
floppyCount++;
VbdCombiItem i = new VbdCombiItem();
i.name = string.Format(Messages.FLOPPY_DRIVE_LABEL_NUMBERED, floppyCount);
i.vbd = vbd;
comboBoxDrive.Items.Add(i);
}
item = new VbdCombiItem(string.Format(Messages.FLOPPY_DRIVE_LABEL_NUMBERED, floppyCount), vbd);
}
comboBoxDrive.Items.Add(item);
}
}
if (comboBoxDrive.Items.Count == 0)
{
comboBoxDrive.Visible = false;
cdChanger1.Visible = false;
labelSingleDvd.Visible = false;
linkLabel1.Visible = false;
panel1.Visible = false;
newCDLabel.Visible = VM != null && !VM.is_control_domain;

}
else if (comboBoxDrive.Items.Count == 1)
{
comboBoxDrive.Visible = false;
cdChanger1.Visible = true;

labelSingleDvd.Visible = comboBoxDrive.Items.Count == 1;
if (labelSingleDvd.Visible)
labelSingleDvd.Text = comboBoxDrive.Items[0].ToString();
labelSingleDvd.Visible = true;
tableLayoutPanel1.ColumnStyles[0].Width = labelSingleDvd.Width;
newCDLabel.Visible = false;
panel1.Visible = true;
linkLabel1.Visible = true;
}
else
{
comboBoxDrive.Visible = true;
cdChanger1.Visible = true;
labelSingleDvd.Visible = false;
panel1.Visible = true;
newCDLabel.Visible = false;
linkLabel1.Visible = true;
}
inRefresh = false;

comboBoxDrive.Visible = comboBoxDrive.Items.Count > 1;
cdChanger1.Visible = comboBoxDrive.Items.Count > 0;
linkLabelEject.Visible = comboBoxDrive.Items.Count > 0;
newCDLabel.Visible = comboBoxDrive.Items.Count == 0 && VM != null && !VM.is_control_domain;

_inRefresh = false;

// Restore prev selection or select the top item by default
if (prevSelection != null)
{
foreach (object o in comboBoxDrive.Items)
{
VbdCombiItem v = o as VbdCombiItem;
if (v.vbd.uuid == prevSelection.vbd.uuid)
if (o is VbdCombiItem v && v.Vbd.uuid == prevSelection.Vbd.uuid)
{
comboBoxDrive.SelectedItem = o;
return;
}
}
}
if (comboBoxDrive.Items.Count == 0)
comboBoxDrive.SelectedItem = null;
else
comboBoxDrive.SelectedItem = comboBoxDrive.Items[0];

comboBoxDrive.SelectedItem = comboBoxDrive.Items.Count == 0 ? null : comboBoxDrive.Items[0];
}

void vbd_PropertyChanged(object sender, PropertyChangedEventArgs e)
private void vbd_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
refreshDrives();
RefreshDrives();
}

private void CachePopulatedMethod(IXenConnection conn)
{
VM.Connection.CachePopulated -= CachePopulatedMethod;
refreshDrives();
RefreshDrives();
}

internal class VbdCombiItem
private class VbdCombiItem
{
public string name;
public VBD vbd;
public string Name { get; }
public VBD Vbd { get; }

public VbdCombiItem(string name, VBD vbd)
{
Name = name;
Vbd = vbd;
}

public override string ToString()
{
return name;
return Name;
}
}

private void comboBoxDrive_SelectedIndexChanged(object sender, EventArgs e)
{
if (inRefresh)
if (_inRefresh)
return;

cdChanger1.Drive = (comboBoxDrive.SelectedItem as VbdCombiItem)?.vbd;
cdChanger1.Drive = (comboBoxDrive.SelectedItem as VbdCombiItem)?.Vbd;
}


private void newCDLabel_Click(object sender, EventArgs e)
{
if (VM != null)
{
var createDriveAction = new CreateCdDriveAction(VM);
createDriveAction.ShowUserInstruction += CreateDriveAction_ShowUserInstruction;
if (VM == null)
return;

using (var dlg = new ActionProgressDialog(createDriveAction, ProgressBarStyle.Marquee))
dlg.ShowDialog(this);
if (VM.IsHVM())
{
using (var dialog = new WarningDialog(
string.Format(Messages.NEW_DVD_DRIVE_CREATE_CONFIRMATION, VM.Name()),
new ThreeButtonDialog.TBDButton(Messages.NEW_DVD_DRIVE_CREATE_YES_BUTTON, DialogResult.Yes, ThreeButtonDialog.ButtonType.ACCEPT, true),
ThreeButtonDialog.ButtonNo))
if (dialog.ShowDialog(Program.MainWindow) != DialogResult.Yes)
danilo-delbusso marked this conversation as resolved.
Show resolved Hide resolved
return;
}

var createDriveAction = new CreateCdDriveAction(VM);
createDriveAction.ShowUserInstruction += CreateDriveAction_ShowUserInstruction;

using (var dlg = new ActionProgressDialog(createDriveAction, ProgressBarStyle.Marquee))
dlg.ShowDialog(this);
}

private void CreateDriveAction_ShowUserInstruction(string message)
Expand All @@ -272,7 +266,7 @@ private void CreateDriveAction_ShowUserInstruction(string message)
});
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
private void linkLabelEject_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (cdChanger1.Drive != null)
cdChanger1.ChangeCD(null);
Expand Down
Loading
Loading