private void AddMachine(VirtualMachine machine) { AppendValues (machine); machine.Started += OnMachineChanged; machine.Stopped += OnMachineChanged; }
private void RemoveMachine(VirtualMachine machine) { TreeIter iter; if (FindMachine (machine, out iter)) { machine.Started -= OnMachineChanged; machine.Stopped -= OnMachineChanged; Remove (ref iter); } }
private bool FindMachine(VirtualMachine machine, out TreeIter iter) { for (int i = 0; i < IterNChildren (); i++) { IterNthChild (out iter, i); VirtualMachine machine2 = (VirtualMachine) GetValue (iter, 0); if (machine.Equals (machine2)) { return true; } } iter = TreeIter.Zero; return false; }
public void AddMachine(VirtualMachine machine) { foreach (VirtualMachine existing in machines) { if (existing.FileName == machine.FileName) { return; } } AddMachineInternal (machine); SaveMachines (); VirtualMachineHandler handler = Added; if (handler != null) { handler (this, new VirtualMachineArgs (machine)); } }
public DeviceModel(VirtualMachine machine) : base(typeof (IVirtualDevice)) { foreach (VirtualHardDisk disk in machine.HardDisks) { AddDevice (disk); } foreach (VirtualCdDrive drive in machine.CdDrives) { AddDevice (drive); } foreach (VirtualEthernet dev in machine.EthernetDevices) { AddDevice (dev); } machine.HardDiskAdded += OnHardDiskAdded; machine.HardDiskRemoved += OnHardDiskRemoved; machine.CdDriveAdded += OnCdDriveAdded; machine.CdDriveRemoved += OnCdDriveRemoved; machine.EthernetDeviceAdded += OnEthernetDeviceAdded; machine.EthernetDeviceRemoved += OnEthernetDeviceRemoved; }
public VirtualMachineArgs(VirtualMachine machine) { this.machine = machine; }
public static VirtualMachine Create(string file, string name) { VirtualMachine machine = new VirtualMachine (); machine.LoadDefaults (); machine.FileName = file; machine.Name = name; machine["nvram"] = name + ".nvram"; machine["checkpoint.vmState"] = name + ".vmss"; return machine; }
private void OnDragDataReceived(object sender, DragDataReceivedArgs args) { if (args.SelectionData.Length > 0 && args.SelectionData.Format == 8) { string uris = Encoding.ASCII.GetString (args.SelectionData.Data, 0, args.SelectionData.Length); foreach (string str in uris.Trim ().Split ('\n')) { string uristr = str.Trim (); // remove the '\r' if (uristr == String.Empty) continue; Uri uri = new Uri (uristr); if (!uri.IsFile) { continue; } try { VirtualMachine machine = new VirtualMachine (uri.LocalPath); controller.Manager.AddMachine (machine); } catch (Exception e) { Console.Error.WriteLine ("Could not load virtual machine: " + e); } } } }
public ConfigDialog(VirtualMachine machine, MainWindow parent) : base("Configure Virtual Machine", parent, DialogFlags.NoSeparator, Stock.Cancel, ResponseType.Cancel, Stock.Ok, ResponseType.Ok) { this.mainWindow = parent; this.machine = machine; IconThemeUtils.SetWindowIcon (this); ActionEntry[] actionList = { new ActionEntry ("AddHardDisk", null, Catalog.GetString ("Hard Disk"), null, Catalog.GetString ("Add a hard disk"), OnAddHardDisk), new ActionEntry ("AddCdDrive", null, Catalog.GetString ("CD-ROM"), null, Catalog.GetString ("Add a CD-ROM drive"), OnAddCdDrive), new ActionEntry ("AddEthernet", null, Catalog.GetString ("Ethernet"), null, Catalog.GetString ("Add an ethernet device"), OnAddEthernet), new ActionEntry ("AddFloppy", null, Catalog.GetString ("Floppy"), null, Catalog.GetString ("Add a floppy drive"), OnAddFloppy), }; actions = new ActionGroup ("VmxManager Device Actions"); actions.Add (actionList); ui = new UIManager (); ui.InsertActionGroup (actions, 0); ui.AddUiFromResource ("vmx-manager-config.xml"); Glade.XML xml = new Glade.XML ("vmx-manager.glade", "configDialogContent"); xml.Autoconnect (this); guestOsCombo.Model = new OSModel (); CellRendererText renderer = new CellRendererText (); guestOsCombo.PackStart (renderer, false); guestOsCombo.AddAttribute (renderer, "text", 0); guestOsCombo.Changed += OnGuestOsChanged; devview = new DeviceView (); devview.RowActivated += delegate { OnConfigureDevice (this, new EventArgs ()); }; devview.Selection.Changed += OnDeviceSelectionChanged; devmodel = new DeviceModel (machine); devview.Model = devmodel; deviceContent.Add (devview); devview.Show (); addDeviceButton.Toggled += delegate { if (addDeviceButton.Active) { Menu popup = (Menu) ui.GetWidget ("/ui/AddDevicePopup"); popup.Unmapped += delegate { addDeviceButton.Active = false; }; popup.Popup (null, null, OnPopupPosition, 0, Gtk.Global.CurrentEventTime); } }; removeDeviceButton.Clicked += OnRemoveDevice; configureDeviceButton.Clicked += OnConfigureDevice; VBox.Add (configDialogContent); DefaultHeight = 400; int maxmem = Utility.GetHostMemorySize (); if (maxmem > 0) { memorySpin.SetRange (1.0, (double) (maxmem - 128)); } Load (); }
private void LoadMachines() { using (StreamReader reader = new StreamReader (File.OpenRead (ConfigFile))) { string line; while ((line = reader.ReadLine ()) != null) { try { VirtualMachine machine = new VirtualMachine (line); AddMachineInternal (machine); } catch (Exception e) { File.Delete (GetDesktopFileName (line)); Console.Error.WriteLine ("Failed to load virtual machine '{0}': {1}", line, e); } } } }
private void DeleteDesktopFile(VirtualMachine machine) { string file = GetDesktopFileName (machine); if (File.Exists (file)) { File.Delete (file); } }
private string CreateDesktopFile(VirtualMachine machine, bool overwrite) { string file = GetDesktopFileName (machine); if (!overwrite && File.Exists (file)) { return file; } StringBuilder builder = new StringBuilder (); builder.Append ("[Desktop Entry]\nVersion=1.0\nEncoding=UTF-8\n"); builder.AppendFormat ("Name={0}\n", machine.Name); builder.Append (String.Format ("GenericName={0}\n", Catalog.GetString ("VMware Virtual Machine Launcher"))); builder.AppendFormat ("Exec=vmplayer \"{0}\"\n", machine.FileName); builder.Append ("Icon=vmx-manager\nStartupNotify=true\nTerminal=false\n"); builder.Append ("Type=Application"); if (!Directory.Exists (DesktopFileDirectory)) { Directory.CreateDirectory (DesktopFileDirectory); } using (StreamWriter writer = new StreamWriter (File.Open (file, FileMode.Create))) { writer.Write (builder.ToString ()); } return file; }
private void AddMachineInternal(VirtualMachine machine) { machines.Add (machine); machine.NameChanged += OnMachineNameChanged; machine.FileNameChanged += delegate { SaveMachines (); }; // UGH: fake a name change in case it changed between now and when it was created OnMachineNameChanged (machine, new EventArgs ()); }
public void StartMachine(VirtualMachine machine) { if (machine.Status == VirtualMachineStatus.Running) { return; } IntPtr ditem = gnome_desktop_item_new_from_file (GetDesktopFileName (machine), 0, IntPtr.Zero); if (ditem == IntPtr.Zero) { throw new ApplicationException (Catalog.GetString ("Failed to load launcher")); } gnome_desktop_item_launch (ditem, IntPtr.Zero, 0, IntPtr.Zero); }
public void RemoveMachine(VirtualMachine machine) { machines.Remove (machine); SaveMachines (); DeleteDesktopFile (machine); VirtualMachineHandler handler = Removed; if (handler != null) { handler (this, new VirtualMachineArgs (machine)); } }
public string GetDesktopFileName(VirtualMachine machine) { return GetDesktopFileName (machine.FileName); }