void UIWizardNewVDPage1::addFormatButton(QWidget *pParent, QVBoxLayout *pFormatLayout, CMediumFormat medFormat) { /* Check that medium format supports creation: */ ULONG uFormatCapabilities = 0; QVector<KMediumFormatCapabilities> capabilities; capabilities = medFormat.GetCapabilities(); for (int i = 0; i < capabilities.size(); i++) uFormatCapabilities |= capabilities[i]; if (!(uFormatCapabilities & MediumFormatCapabilities_CreateFixed || uFormatCapabilities & MediumFormatCapabilities_CreateDynamic)) return; /* Check that medium format supports creation of virtual hard-disks: */ QVector<QString> fileExtensions; QVector<KDeviceType> deviceTypes; medFormat.DescribeFileExtensions(fileExtensions, deviceTypes); if (!deviceTypes.contains(KDeviceType_HardDisk)) return; /* Create/add corresponding radio-button: */ QRadioButton *pFormatButton = new QRadioButton(pParent); pFormatLayout->addWidget(pFormatButton); m_formats << medFormat; m_formatNames << medFormat.GetName(); m_pFormatButtonGroup->addButton(pFormatButton, m_formatNames.size() - 1); }
bool UIWizardCloneVD::copyVirtualDisk() { /* Gather attributes: */ CMedium sourceVirtualDisk = field("sourceVirtualDisk").value<CMedium>(); CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>(); qulonglong uVariant = field("mediumVariant").toULongLong(); QString strMediumPath = field("mediumPath").toString(); qulonglong uSize = field("mediumSize").toULongLong(); /* Check attributes: */ AssertReturn(!strMediumPath.isNull(), false); AssertReturn(uSize > 0, false); /* Get VBox object: */ CVirtualBox vbox = vboxGlobal().virtualBox(); /* Create new virtual hard-disk: */ CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath); if (!vbox.isOk()) { msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this); return false; } /* Compose medium-variant: */ QVector<KMediumVariant> variants(sizeof(qulonglong)*8); for (int i = 0; i < variants.size(); ++i) { qulonglong temp = uVariant; temp &= 1<<i; variants[i] = (KMediumVariant)temp; } /* Copy existing virtual-disk to the new virtual-disk: */ CProgress progress = sourceVirtualDisk.CloneTo(virtualDisk, variants, CMedium()); if (!sourceVirtualDisk.isOk()) { msgCenter().cannotCreateHardDiskStorage(sourceVirtualDisk, strMediumPath, this); return false; } /* Show creation progress: */ msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this); if (progress.GetCanceled()) return false; if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotCreateHardDiskStorage(progress, strMediumPath, this); return false; } /* Remember created virtual-disk: */ m_virtualDisk = virtualDisk; /* Just close the created medium, it is not necessary yet: */ m_virtualDisk.Close(); return true; }
bool UIWizardNewVD::createVirtualDisk() { /* Gather attributes: */ CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>(); qulonglong uVariant = field("mediumVariant").toULongLong(); QString strMediumPath = field("mediumPath").toString(); qulonglong uSize = field("mediumSize").toULongLong(); /* Check attributes: */ AssertReturn(!strMediumPath.isNull(), false); AssertReturn(uSize > 0, false); /* Get VBox object: */ CVirtualBox vbox = vboxGlobal().virtualBox(); /* Create new virtual hard-disk: */ CMedium virtualDisk = vbox.CreateMedium(mediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk); if (!vbox.isOk()) { msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this); return false; } /* Compose medium-variant: */ QVector<KMediumVariant> variants(sizeof(qulonglong)*8); for (int i = 0; i < variants.size(); ++i) { qulonglong temp = uVariant; temp &= UINT64_C(1)<<i; variants[i] = (KMediumVariant)temp; } /* Create base storage for the new virtual-disk: */ CProgress progress = virtualDisk.CreateBaseStorage(uSize, variants); if (!virtualDisk.isOk()) { msgCenter().cannotCreateHardDiskStorage(virtualDisk, strMediumPath, this); return false; } /* Show creation progress: */ msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this); if (progress.GetCanceled()) return false; if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotCreateHardDiskStorage(progress, strMediumPath, this); return false; } /* Remember created virtual-disk: */ m_virtualDisk = virtualDisk; /* Inform VBoxGlobal about it: */ vboxGlobal().createMedium(UIMedium(m_virtualDisk, UIMediumType_HardDisk, KMediumState_Created)); return true; }
void UIWizardNewVDPage3::onSelectLocationButtonClicked() { /* Get current folder and filename: */ QFileInfo fullFilePath(mediumPath()); QDir folder = fullFilePath.path(); QString strFileName = fullFilePath.fileName(); /* Set the first parent folder that exists as the current: */ while (!folder.exists() && !folder.isRoot()) { QFileInfo folderInfo(folder.absolutePath()); if (folder == QDir(folderInfo.absolutePath())) break; folder = folderInfo.absolutePath(); } /* But if it doesn't exists at all: */ if (!folder.exists() || folder.isRoot()) { /* Use recommended one folder: */ QFileInfo defaultFilePath(absoluteFilePath(strFileName, m_strDefaultPath)); folder = defaultFilePath.path(); } /* Prepare backends list: */ QVector<QString> fileExtensions; QVector<KDeviceType> deviceTypes; CMediumFormat mediumFormat = fieldImp("mediumFormat").value<CMediumFormat>(); mediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes); QStringList validExtensionList; for (int i = 0; i < fileExtensions.size(); ++i) if (deviceTypes[i] == KDeviceType_HardDisk) validExtensionList << QString("*.%1").arg(fileExtensions[i]); /* Compose full filter list: */ QString strBackendsList = QString("%1 (%2)").arg(mediumFormat.GetName()).arg(validExtensionList.join(" ")); /* Open corresponding file-dialog: */ QString strChosenFilePath = QIFileDialog::getSaveFileName(folder.absoluteFilePath(strFileName), strBackendsList, thisImp(), VBoxGlobal::tr("Please choose a location for new virtual hard drive file")); /* If there was something really chosen: */ if (!strChosenFilePath.isEmpty()) { /* If valid file extension is missed, append it: */ if (QFileInfo(strChosenFilePath).suffix().isEmpty()) strChosenFilePath += QString(".%1").arg(m_strDefaultExtension); m_pLocationEditor->setText(QDir::toNativeSeparators(strChosenFilePath)); m_pLocationEditor->selectAll(); m_pLocationEditor->setFocus(); } }
bool UIWizardNewVD::createVirtualDisk() { /* Gather attributes: */ CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>(); qulonglong uVariant = field("mediumVariant").toULongLong(); QString strMediumPath = field("mediumPath").toString(); qulonglong uSize = field("mediumSize").toULongLong(); /* Check attributes: */ AssertReturn(!strMediumPath.isNull(), false); AssertReturn(uSize > 0, false); /* Get vbox object: */ CVirtualBox vbox = vboxGlobal().virtualBox(); /* Create new virtual disk: */ CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath); CProgress progress; if (!vbox.isOk()) { msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress); return false; } /* Create base storage for the new hard disk: */ progress = virtualDisk.CreateBaseStorage(uSize, uVariant); if (!virtualDisk.isOk()) { msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress); return false; } /* Show creation progress: */ msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this, true); if (progress.GetCanceled()) return false; if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress); return false; } /* Remember created virtual-disk: */ m_virtualDisk = virtualDisk; /* Inform everybody there is a new medium: */ vboxGlobal().addMedium(UIMedium(m_virtualDisk, UIMediumType_HardDisk, KMediumState_Created)); return true; }