예제 #1
0
        private void AddMachine(VirtualMachine machine)
        {
            AppendValues (machine);

            machine.Started += OnMachineChanged;
            machine.Stopped += OnMachineChanged;
        }
예제 #2
0
        private void RemoveMachine(VirtualMachine machine)
        {
            TreeIter iter;
            if (FindMachine (machine, out iter)) {
                machine.Started -= OnMachineChanged;
                machine.Stopped -= OnMachineChanged;

                Remove (ref iter);
            }
        }
예제 #3
0
        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;
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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;
        }
예제 #6
0
 public VirtualMachineArgs(VirtualMachine machine)
 {
     this.machine = machine;
 }
예제 #7
0
        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;
        }
예제 #8
0
파일: VMView.cs 프로젝트: snorp/vmx-manager
        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);
                    }
                }
            }
        }
예제 #9
0
        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 ();
        }
예제 #10
0
 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);
             }
         }
     }
 }
예제 #11
0
 private void DeleteDesktopFile(VirtualMachine machine)
 {
     string file = GetDesktopFileName (machine);
     if (File.Exists (file)) {
         File.Delete (file);
     }
 }
예제 #12
0
        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;
        }
예제 #13
0
        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 ());
        }
예제 #14
0
        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);
        }
예제 #15
0
        public void RemoveMachine(VirtualMachine machine)
        {
            machines.Remove (machine);
            SaveMachines ();

            DeleteDesktopFile (machine);

            VirtualMachineHandler handler = Removed;
            if (handler != null) {
                handler (this, new VirtualMachineArgs (machine));
            }
        }
예제 #16
0
 public string GetDesktopFileName(VirtualMachine machine)
 {
     return GetDesktopFileName (machine.FileName);
 }