VBoxTakeSnapshotDlg::VBoxTakeSnapshotDlg(QWidget *pParent, const CMachine &machine) : QIWithRetranslateUI<QIDialog>(pParent) { /* Apply UI decorations */ Ui::VBoxTakeSnapshotDlg::setupUi(this); /* Alt key filter */ QIAltKeyFilter *altKeyFilter = new QIAltKeyFilter(this); altKeyFilter->watchOn(mLeName); /* Setup connections */ connect (mButtonBox, SIGNAL(helpRequested()), &msgCenter(), SLOT(sltShowHelpHelpDialog())); connect (mLeName, SIGNAL(textChanged(const QString &)), this, SLOT(nameChanged(const QString &))); /* Check if machine have immutable attachments */ int immutableMediums = 0; if (machine.GetState() == KMachineState_Paused) { foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments()) { CMedium medium = attachment.GetMedium(); if (!medium.isNull() && !medium.GetParent().isNull() && medium.GetBase().GetType() == KMediumType_Immutable) ++ immutableMediums; } }
VBoxTakeSnapshotDlg::VBoxTakeSnapshotDlg(QWidget *pParent, const CMachine &machine) : QIWithRetranslateUI<QIDialog>(pParent) { #ifdef Q_WS_MAC /* No sheets in another mode than normal for now. Firstly it looks ugly and * secondly in some cases it is broken. */ if ( vboxGlobal().isSheetWindowsAllowed(pParent) || qobject_cast<VBoxSnapshotsWgt*>(pParent)) setWindowFlags(Qt::Sheet); #endif /* Q_WS_MAC */ /* Apply UI decorations */ Ui::VBoxTakeSnapshotDlg::setupUi(this); /* Alt key filter */ QIAltKeyFilter *altKeyFilter = new QIAltKeyFilter(this); altKeyFilter->watchOn(mLeName); /* Setup connections */ connect (mButtonBox, SIGNAL(helpRequested()), &msgCenter(), SLOT(sltShowHelpHelpDialog())); connect (mLeName, SIGNAL(textChanged(const QString &)), this, SLOT(nameChanged(const QString &))); /* Check if machine have immutable attachments */ int immutableMediums = 0; if (machine.GetState() == KMachineState_Paused) { foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments()) { CMedium medium = attachment.GetMedium(); if (!medium.isNull() && !medium.GetParent().isNull() && medium.GetBase().GetType() == KMediumType_Immutable) ++ immutableMediums; } }
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; }
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; }
void CSimulator::InitMedia(TConfigurationNode& t_tree) { try { /* Cycle through the media */ TConfigurationNodeIterator itMedia; for(itMedia = itMedia.begin(&t_tree); itMedia != itMedia.end(); ++itMedia) { /* Create the medium */ CMedium* pcMedium = CFactory<CMedium>::New(itMedia->Value()); try { /* Initialize the medium */ pcMedium->Init(*itMedia); /* Check that an medium with that ID does not exist yet */ if(m_mapMedia.find(pcMedium->GetId()) == m_mapMedia.end()) { /* Add it to the lists */ m_mapMedia[pcMedium->GetId()] = pcMedium; m_vecMedia.push_back(pcMedium); } else { /* Duplicate id -> error */ THROW_ARGOSEXCEPTION("A medium with id \"" << pcMedium->GetId() << "\" exists already. The ids must be unique!"); } } catch(CARGoSException& ex) { /* Error while executing medium init, destroy what done to prevent memory leaks */ pcMedium->Destroy(); delete pcMedium; THROW_ARGOSEXCEPTION_NESTED("Error initializing medium type \"" << itMedia->Value() << "\"", ex); } } } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize the media. Parse error in the <media> subtree.", ex); } }
/* Insert hard-disks to the passed uimedium map. * Get existing one from the previous map if any. */ foreach (CMedium medium, inputMediums) { /* If VBoxGlobal is cleaning up, abort immediately: */ if (vboxGlobal().isCleaningUp()) break; /* Prepare uimedium on the basis of current medium: */ QString strMediumID = medium.GetId(); UIMedium uimedium = m_mediums.contains(strMediumID) ? m_mediums[strMediumID] : UIMedium(medium, mediumType); /* Insert uimedium into map: */ outputMediums.insert(uimedium.id(), uimedium); }
UIWizardCloneVDPageBasic1::UIWizardCloneVDPageBasic1(const CMedium &sourceVirtualDisk) { /* Create widgets: */ QVBoxLayout *pMainLayout = new QVBoxLayout(this); { m_pLabel = new QIRichTextLabel(this); QHBoxLayout *pSourceDiskLayout = new QHBoxLayout; { m_pSourceDiskSelector = new VBoxMediaComboBox(this); { m_pSourceDiskSelector->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); m_pSourceDiskSelector->setType(UIMediumType_HardDisk); m_pSourceDiskSelector->setCurrentItem(sourceVirtualDisk.GetId()); m_pSourceDiskSelector->repopulate(); } m_pSourceDiskOpenButton = new QIToolButton(this); { m_pSourceDiskOpenButton->setAutoRaise(true); m_pSourceDiskOpenButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", ":/select_file_disabled_16px.png")); } pSourceDiskLayout->addWidget(m_pSourceDiskSelector); pSourceDiskLayout->addWidget(m_pSourceDiskOpenButton); } pMainLayout->addWidget(m_pLabel); pMainLayout->addLayout(pSourceDiskLayout); pMainLayout->addStretch(); } /* Setup connections: */ connect(m_pSourceDiskSelector, SIGNAL(currentIndexChanged(int)), this, SIGNAL(completeChanged())); connect(m_pSourceDiskOpenButton, SIGNAL(clicked()), this, SLOT(sltHandleOpenSourceDiskClick())); /* Register classes: */ qRegisterMetaType<CMedium>(); /* Register fields: */ registerField("sourceVirtualDisk", this, "sourceVirtualDisk"); }
void UIWizardCloneVDPage1::setSourceVirtualDisk(const CMedium &sourceVirtualDisk) { m_pSourceDiskSelector->setCurrentItem(sourceVirtualDisk.GetId()); }
UIWizardCloneVDPageExpert::UIWizardCloneVDPageExpert(const CMedium &sourceVirtualDisk) { /* Create widgets: */ QGridLayout *pMainLayout = new QGridLayout(this); { pMainLayout->setContentsMargins(8, 6, 8, 6); pMainLayout->setSpacing(10); m_pSourceDiskCnt = new QGroupBox(this); { m_pSourceDiskCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QHBoxLayout *pSourceDiskCntLayout = new QHBoxLayout(m_pSourceDiskCnt); { m_pSourceDiskSelector = new VBoxMediaComboBox(m_pSourceDiskCnt); { m_pSourceDiskSelector->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); m_pSourceDiskSelector->setType(UIMediumType_HardDisk); m_pSourceDiskSelector->setCurrentItem(sourceVirtualDisk.GetId()); m_pSourceDiskSelector->repopulate(); } m_pSourceDiskOpenButton = new QIToolButton(m_pSourceDiskCnt); { m_pSourceDiskOpenButton->setAutoRaise(true); m_pSourceDiskOpenButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", ":/select_file_disabled_16px.png")); } pSourceDiskCntLayout->addWidget(m_pSourceDiskSelector); pSourceDiskCntLayout->addWidget(m_pSourceDiskOpenButton); } } m_pDestinationCnt = new QGroupBox(this); { m_pDestinationCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QHBoxLayout *pLocationCntLayout = new QHBoxLayout(m_pDestinationCnt); { m_pDestinationDiskEditor = new QLineEdit(m_pDestinationCnt); m_pDestinationDiskOpenButton = new QIToolButton(m_pDestinationCnt); { m_pDestinationDiskOpenButton->setAutoRaise(true); m_pDestinationDiskOpenButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", "select_file_disabled_16px.png")); } } pLocationCntLayout->addWidget(m_pDestinationDiskEditor); pLocationCntLayout->addWidget(m_pDestinationDiskOpenButton); } m_pFormatCnt = new QGroupBox(this); { m_pFormatCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QVBoxLayout *pFormatCntLayout = new QVBoxLayout(m_pFormatCnt); { m_pFormatButtonGroup = new QButtonGroup(m_pFormatCnt); { /* Enumerate medium formats in special order: */ CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties(); const QVector<CMediumFormat> &formats = properties.GetMediumFormats(); QMap<QString, CMediumFormat> vdi, preferred, others; foreach (const CMediumFormat &format, formats) { /* VDI goes first: */ if (format.GetName() == "VDI") vdi[format.GetId()] = format; else { const QVector<KMediumFormatCapabilities> &capabilities = format.GetCapabilities(); /* Then goes preferred: */ if (capabilities.contains(KMediumFormatCapabilities_Preferred)) preferred[format.GetId()] = format; /* Then others: */ else others[format.GetId()] = format; } } /* Create buttons for VDI, preferred and others: */ foreach (const QString &strId, vdi.keys()) addFormatButton(this, pFormatCntLayout, vdi.value(strId), true); foreach (const QString &strId, preferred.keys()) addFormatButton(this, pFormatCntLayout, preferred.value(strId), true); foreach (const QString &strId, others.keys()) addFormatButton(this, pFormatCntLayout, others.value(strId)); if (!m_pFormatButtonGroup->buttons().isEmpty()) { m_pFormatButtonGroup->button(0)->click(); m_pFormatButtonGroup->button(0)->setFocus(); } } } } m_pVariantCnt = new QGroupBox(this); { m_pVariantCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QVBoxLayout *pVariantCntLayout = new QVBoxLayout(m_pVariantCnt); { m_pVariantButtonGroup = new QButtonGroup(m_pVariantCnt); { m_pDynamicalButton = new QRadioButton(m_pVariantCnt); { m_pDynamicalButton->click(); m_pDynamicalButton->setFocus(); } m_pFixedButton = new QRadioButton(m_pVariantCnt); m_pVariantButtonGroup->addButton(m_pDynamicalButton, 0); m_pVariantButtonGroup->addButton(m_pFixedButton, 1); } m_pSplitBox = new QCheckBox(m_pVariantCnt); pVariantCntLayout->addWidget(m_pDynamicalButton); pVariantCntLayout->addWidget(m_pFixedButton); pVariantCntLayout->addWidget(m_pSplitBox); } } pMainLayout->addWidget(m_pSourceDiskCnt, 0, 0, 1, 2); pMainLayout->addWidget(m_pDestinationCnt, 1, 0, 1, 2); pMainLayout->addWidget(m_pFormatCnt, 2, 0, Qt::AlignTop); pMainLayout->addWidget(m_pVariantCnt, 2, 1, Qt::AlignTop); sltHandleSourceDiskChange(); sltMediumFormatChanged(); } /* Setup connections: */ connect(m_pSourceDiskSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(sltHandleSourceDiskChange())); connect(m_pSourceDiskOpenButton, SIGNAL(clicked()), this, SLOT(sltHandleOpenSourceDiskClick())); connect(m_pFormatButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(sltMediumFormatChanged())); connect(m_pVariantButtonGroup, SIGNAL(buttonClicked(QAbstractButton *)), this, SIGNAL(completeChanged())); connect(m_pSplitBox, SIGNAL(stateChanged(int)), this, SIGNAL(completeChanged())); connect(m_pDestinationDiskEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged())); connect(m_pDestinationDiskOpenButton, SIGNAL(clicked()), this, SLOT(sltSelectLocationButtonClicked())); /* Register classes: */ qRegisterMetaType<CMedium>(); qRegisterMetaType<CMediumFormat>(); /* Register fields: */ registerField("sourceVirtualDisk", this, "sourceVirtualDisk"); registerField("mediumFormat", this, "mediumFormat"); registerField("mediumVariant", this, "mediumVariant"); registerField("mediumPath", this, "mediumPath"); registerField("mediumSize", this, "mediumSize"); }
void UIGInformationUpdateTaskStorage::run() { /* Acquire corresponding machine: */ CMachine machine = property("machine").value<CMachine>(); if (machine.isNull()) return; /* Prepare table: */ UITextTable table; /* Gather information: */ if (machine.GetAccessible()) { /* Iterate over all the machine controllers: */ bool fSomeInfo = false; foreach (const CStorageController &controller, machine.GetStorageControllers()) { /* Add controller information: */ QString strControllerName = QApplication::translate("UIMachineSettingsStorage", "Controller: %1"); table << UITextTableLine(strControllerName.arg(controller.GetName()), QString()); fSomeInfo = true; /* Populate map (its sorted!): */ QMap<StorageSlot, QString> attachmentsMap; foreach (const CMediumAttachment &attachment, machine.GetMediumAttachmentsOfController(controller.GetName())) { /* Prepare current storage slot: */ StorageSlot attachmentSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice()); AssertMsg(controller.isOk(), ("Unable to acquire controller data: %s\n", msgCenter().formatRC(controller.lastRC()).toAscii().constData())); if (!controller.isOk()) continue; /* Prepare attachment information: */ QString strAttachmentInfo = vboxGlobal().details(attachment.GetMedium(), false, false); /* That temporary hack makes sure 'Inaccessible' word is always bold: */ { // hack QString strInaccessibleString(VBoxGlobal::tr("Inaccessible", "medium")); QString strBoldInaccessibleString(QString("<b>%1</b>").arg(strInaccessibleString)); strAttachmentInfo.replace(strInaccessibleString, strBoldInaccessibleString); } // hack /* Append 'device slot name' with 'device type name' for optical devices only: */ KDeviceType deviceType = attachment.GetType(); QString strDeviceType = deviceType == KDeviceType_DVD ? QApplication::translate("UIGInformation", "[Optical Drive]", "details (storage)") : QString(); if (!strDeviceType.isNull()) strDeviceType.append(' '); /* Insert that attachment information into the map: */ if (!strAttachmentInfo.isNull()) { /* Configure hovering anchors: */ const QString strAnchorType = deviceType == KDeviceType_DVD || deviceType == KDeviceType_Floppy ? QString("mount") : deviceType == KDeviceType_HardDisk ? QString("attach") : QString(); const CMedium medium = attachment.GetMedium(); const QString strMediumLocation = medium.isNull() ? QString() : medium.GetLocation(); attachmentsMap.insert(attachmentSlot, QString("<a href=#%1,%2,%3,%4>%5</a>") .arg(strAnchorType, controller.GetName(), gpConverter->toString(attachmentSlot), strMediumLocation, strDeviceType + strAttachmentInfo)); } } /* Iterate over the sorted map: */ QList<StorageSlot> storageSlots = attachmentsMap.keys(); QList<QString> storageInfo = attachmentsMap.values(); for (int i = 0; i < storageSlots.size(); ++i) table << UITextTableLine(QString(" ") + gpConverter->toString(storageSlots[i]), storageInfo[i]); } if (!fSomeInfo) table << UITextTableLine(QApplication::translate("UIGInformation", "Not Attached", "details (storage)"), QString()); }
/** * Refreshes the precomposed strings containing such media parameters as * location, size by querying the respective data from the associated * media object. * * Note that some string such as #size() are meaningless if the media state is * KMediumState_NotCreated (i.e. the medium has not yet been checked for * accessibility). */ void UIMedium::refresh() { /* Detect basic parameters */ mId = mMedium.isNull() ? QUuid().toString().remove ('{').remove ('}') : mMedium.GetId(); mIsHostDrive = mMedium.isNull() ? false : mMedium.GetHostDrive(); if (mMedium.isNull()) mName = VBoxGlobal::tr ("Empty", "medium"); else if (!mIsHostDrive) mName = mMedium.GetName(); else if (mMedium.GetDescription().isEmpty()) mName = VBoxGlobal::tr ("Host Drive '%1'", "medium").arg (QDir::toNativeSeparators (mMedium.GetLocation())); else mName = VBoxGlobal::tr ("Host Drive %1 (%2)", "medium").arg (mMedium.GetDescription(), mMedium.GetName()); mLocation = mMedium.isNull() || mIsHostDrive ? QString ("--") : QDir::toNativeSeparators (mMedium.GetLocation()); if (mType == UIMediumType_HardDisk) { mHardDiskFormat = mMedium.GetFormat(); mHardDiskType = vboxGlobal().mediumTypeString (mMedium); mStorageDetails = gpConverter->toString((KMediumVariant)mMedium.GetVariant()); mIsReadOnly = mMedium.GetReadOnly(); /* Adjust the parent if its possible */ CMedium parentMedium = mMedium.GetParent(); Assert (!parentMedium.isNull() || mParent == NULL); if (!parentMedium.isNull() && (mParent == NULL || mParent->mMedium != parentMedium)) { /* Search for the parent (might be there) */ const VBoxMediaList &list = vboxGlobal().currentMediaList(); for (VBoxMediaList::const_iterator it = list.begin(); it != list.end(); ++ it) { if ((*it).mType != UIMediumType_HardDisk) break; if ((*it).mMedium == parentMedium) { mParent = unconst (&*it); break; } } } } else { mHardDiskFormat = QString::null; mHardDiskType = QString::null; mIsReadOnly = false; } /* Detect sizes */ if (mState != KMediumState_Inaccessible && mState != KMediumState_NotCreated && !mIsHostDrive) { mSize = vboxGlobal().formatSize (mMedium.GetSize()); if (mType == UIMediumType_HardDisk) mLogicalSize = vboxGlobal().formatSize(mMedium.GetLogicalSize()); else mLogicalSize = mSize; } else { mSize = mLogicalSize = QString ("--"); } /* Detect usage */ mUsage = QString::null; if (!mMedium.isNull()) { mCurStateMachineIds.clear(); QVector <QString> machineIds = mMedium.GetMachineIds(); if (machineIds.size() > 0) { QString sUsage; CVirtualBox vbox = vboxGlobal().virtualBox(); for (QVector <QString>::ConstIterator it = machineIds.begin(); it != machineIds.end(); ++ it) { CMachine machine = vbox.FindMachine(*it); /* UIMedium object can wrap newly created CMedium object which belongs to * not yet registered machine, like while creating VM clone. * We can skip such a machines in usage string. * CVirtualBox::FindMachine() will return null machine for such case. */ if (machine.isNull()) continue; QString sName = machine.GetName(); QString sSnapshots; QVector <QString> snapIds = mMedium.GetSnapshotIds (*it); for (QVector <QString>::ConstIterator jt = snapIds.begin(); jt != snapIds.end(); ++ jt) { if (*jt == *it) { /* The medium is attached to the machine in the current * state, we don't distinguish this for now by always * giving the VM name in front of snapshot names. */ mCurStateMachineIds.push_back (*jt); continue; } CSnapshot snapshot = machine.FindSnapshot(*jt); if (!snapshot.isNull()) // can be NULL while takeSnaphot is in progress { if (!sSnapshots.isNull()) sSnapshots += ", "; sSnapshots += snapshot.GetName(); } } if (!sUsage.isNull()) sUsage += ", "; sUsage += sName; if (!sSnapshots.isNull()) { sUsage += QString (" (%2)").arg (sSnapshots); mIsUsedInSnapshots = true; } else mIsUsedInSnapshots = false; } if (!sUsage.isEmpty()) mUsage = sUsage; } } /* Compose the tooltip */ if (!mMedium.isNull()) { mToolTip = mRow.arg (QString ("<p style=white-space:pre><b>%1</b></p>").arg (mIsHostDrive ? mName : mLocation)); if (mType == UIMediumType_HardDisk) { mToolTip += mRow.arg (VBoxGlobal::tr ("<p style=white-space:pre>Type (Format): %1 (%2)</p>", "medium") .arg (mHardDiskType).arg (mHardDiskFormat)); } mToolTip += mRow.arg (VBoxGlobal::tr ("<p>Attached to: %1</p>", "image") .arg (mUsage.isNull() ? VBoxGlobal::tr ("<i>Not Attached</i>", "image") : mUsage)); switch (mState) { case KMediumState_NotCreated: { mToolTip += mRow.arg (VBoxGlobal::tr ("<i>Checking accessibility...</i>", "medium")); break; } case KMediumState_Inaccessible: { if (mResult.isOk()) { /* Not Accessible */ mToolTip += mRow.arg ("<hr>") + mRow.arg (VBoxGlobal::highlight (mLastAccessError, true /* aToolTip */)); } else { /* Accessibility check (eg GetState()) itself failed */ mToolTip += mRow.arg ("<hr>") + mRow.arg (VBoxGlobal::tr ("Failed to check media accessibility.", "medium")) + mRow.arg (UIMessageCenter::formatErrorInfo (mResult) + "."); } break; } default: break; } } /* Reset mNoDiffs */ mNoDiffs.isSet = false; }
void UIMedium::refresh() { /* Reset ID parameters: */ m_strId = nullID(); m_strRootId = nullID(); m_strParentId = nullID(); /* Reset cache parameters: */ //m_strKey = nullID(); /* Reset name/location/size parameters: */ m_strName = VBoxGlobal::tr("Empty", "medium"); m_strLocation = m_strSize = m_strLogicalSize = QString("--"); /* Reset hard drive related parameters: */ m_strHardDiskType = QString(); m_strHardDiskFormat = QString(); m_strStorageDetails = QString(); m_strEncryptionPasswordID = QString(); /* Reset data parameters: */ m_strUsage = QString(); m_strToolTip = QString(); m_machineIds.clear(); m_curStateMachineIds.clear(); /* Reset m_noDiffs: */ m_noDiffs.isSet = false; /* Reset flags: */ m_fHidden = false; m_fUsedByHiddenMachinesOnly = false; m_fReadOnly = false; m_fUsedInSnapshots = false; m_fHostDrive = false; m_fEncrypted = false; /* For non NULL medium: */ if (!m_medium.isNull()) { /* Refresh medium ID: */ m_strId = normalizedID(m_medium.GetId()); /* Refresh root medium ID: */ m_strRootId = m_strId; /* Init medium key if necessary: */ if (m_strKey.isNull()) m_strKey = m_strId; /* Check whether this is host-drive medium: */ m_fHostDrive = m_medium.GetHostDrive(); /* Refresh medium name: */ if (!m_fHostDrive) m_strName = m_medium.GetName(); else if (m_medium.GetDescription().isEmpty()) m_strName = VBoxGlobal::tr("Host Drive '%1'", "medium").arg(QDir::toNativeSeparators(m_medium.GetLocation())); else m_strName = VBoxGlobal::tr("Host Drive %1 (%2)", "medium").arg(m_medium.GetDescription(), m_medium.GetName()); /* Refresh medium location: */ if (!m_fHostDrive) m_strLocation = QDir::toNativeSeparators(m_medium.GetLocation()); /* Refresh medium size and logical size: */ if (!m_fHostDrive) { /* Only for created and accessible mediums: */ if (m_state != KMediumState_Inaccessible && m_state != KMediumState_NotCreated) { m_strSize = vboxGlobal().formatSize(m_medium.GetSize()); if (m_type == UIMediumType_HardDisk) m_strLogicalSize = vboxGlobal().formatSize(m_medium.GetLogicalSize()); else m_strLogicalSize = m_strSize; } } /* For hard drive medium: */ if (m_type == UIMediumType_HardDisk) { /* Refresh hard drive disk type: */ m_strHardDiskType = vboxGlobal().mediumTypeString(m_medium); /* Refresh hard drive format: */ m_strHardDiskFormat = m_medium.GetFormat(); /* Refresh hard drive storage details: */ qlonglong iMediumVariant = 0; foreach (const KMediumVariant &enmVariant, m_medium.GetVariant()) iMediumVariant |= enmVariant; m_strStorageDetails = gpConverter->toString((KMediumVariant)iMediumVariant); /* Check whether this is read-only hard drive: */ m_fReadOnly = m_medium.GetReadOnly(); /* Refresh parent hard drive ID: */ CMedium parentMedium = m_medium.GetParent(); if (!parentMedium.isNull()) m_strParentId = normalizedID(parentMedium.GetId()); /* Only for created and accessible mediums: */ if (m_state != KMediumState_Inaccessible && m_state != KMediumState_NotCreated) { /* Refresh root hard drive ID: */ while (!parentMedium.isNull()) { m_strRootId = normalizedID(parentMedium.GetId()); parentMedium = parentMedium.GetParent(); } /* Refresh encryption attributes: */ if (m_strRootId != m_strId) { m_strEncryptionPasswordID = root().encryptionPasswordID(); m_fEncrypted = root().isEncrypted(); } else { QString strCipher; CMedium medium(m_medium); const QString strEncryptionPasswordID = medium.GetEncryptionSettings(strCipher); if (medium.isOk()) { m_strEncryptionPasswordID = strEncryptionPasswordID; m_fEncrypted = true; } } } }
void UIMachineSettingsGeneral::loadToCacheFrom(QVariant &data) { /* Fetch data to machine: */ UISettingsPageMachine::fetchData(data); /* Clear cache initially: */ m_cache.clear(); /* Prepare general data: */ UIDataSettingsMachineGeneral generalData; /* 'Basic' tab data: */ generalData.m_strName = m_machine.GetName(); generalData.m_strGuestOsTypeId = m_machine.GetOSTypeId(); /* 'Advanced' tab data: */ generalData.m_strSnapshotsFolder = m_machine.GetSnapshotFolder(); generalData.m_strSnapshotsHomeDir = QFileInfo(m_machine.GetSettingsFilePath()).absolutePath(); generalData.m_clipboardMode = m_machine.GetClipboardMode(); generalData.m_dndMode = m_machine.GetDnDMode(); /* 'Description' tab data: */ generalData.m_strDescription = m_machine.GetDescription(); /* 'Encryption' tab data: */ QString strCipher; bool fEncryptionCipherCommon = true; /* Prepare the map of the encrypted mediums: */ EncryptedMediumMap encryptedMediums; foreach (const CMediumAttachment &attachment, m_machine.GetMediumAttachments()) { /* Acquire hard-drive attachments only: */ if (attachment.GetType() == KDeviceType_HardDisk) { /* Get the attachment medium base: */ const CMedium medium = attachment.GetMedium(); /* Check medium encryption attributes: */ QString strCurrentCipher; const QString strCurrentPasswordId = medium.GetEncryptionSettings(strCurrentCipher); if (medium.isOk()) { encryptedMediums.insert(strCurrentPasswordId, medium.GetId()); if (strCurrentCipher != strCipher) { if (strCipher.isNull()) strCipher = strCurrentCipher; else fEncryptionCipherCommon = false; } } } } generalData.m_fEncryptionEnabled = !encryptedMediums.isEmpty(); generalData.m_fEncryptionCipherChanged = false; generalData.m_fEncryptionPasswordChanged = false; if (fEncryptionCipherCommon) generalData.m_iEncryptionCipherIndex = m_encryptionCiphers.indexOf(strCipher); if (generalData.m_iEncryptionCipherIndex == -1) generalData.m_iEncryptionCipherIndex = 0; generalData.m_encryptedMediums = encryptedMediums; /* Cache general data: */ m_cache.cacheInitialData(generalData); /* Upload machine to data: */ UISettingsPageMachine::uploadData(data); }
void UIMachineSettingsGeneral::saveFromCacheTo(QVariant &data) { /* Fetch data to machine: */ UISettingsPageMachine::fetchData(data); /* Check if general data was changed: */ if (m_cache.wasChanged()) { /* Get general data from cache: */ const UIDataSettingsMachineGeneral &generalData = m_cache.data(); if (isMachineInValidMode()) { /* 'Advanced' tab data: */ if (generalData.m_clipboardMode != m_cache.base().m_clipboardMode) m_machine.SetClipboardMode(generalData.m_clipboardMode); if (generalData.m_dndMode != m_cache.base().m_dndMode) m_machine.SetDnDMode(generalData.m_dndMode); /* 'Description' tab: */ if (generalData.m_strDescription != m_cache.base().m_strDescription) m_machine.SetDescription(generalData.m_strDescription); } if (isMachineOffline()) { /* 'Basic' tab data: Must update long mode CPU feature bit when os type changes. */ if (generalData.m_strGuestOsTypeId != m_cache.base().m_strGuestOsTypeId) { m_machine.SetOSTypeId(generalData.m_strGuestOsTypeId); CVirtualBox vbox = vboxGlobal().virtualBox(); CGuestOSType newType = vbox.GetGuestOSType(generalData.m_strGuestOsTypeId); m_machine.SetCPUProperty(KCPUPropertyType_LongMode, newType.GetIs64Bit()); } /* 'Advanced' tab data: */ if (generalData.m_strSnapshotsFolder != m_cache.base().m_strSnapshotsFolder) m_machine.SetSnapshotFolder(generalData.m_strSnapshotsFolder); /* 'Basic' (again) tab data: */ /* VM name must be last as otherwise its VM rename magic * can collide with other settings in the config, * especially with the snapshot folder: */ if (generalData.m_strName != m_cache.base().m_strName) m_machine.SetName(generalData.m_strName); /* Encryption tab data: */ if (generalData.m_fEncryptionEnabled != m_cache.base().m_fEncryptionEnabled || generalData.m_fEncryptionCipherChanged != m_cache.base().m_fEncryptionCipherChanged || generalData.m_fEncryptionPasswordChanged != m_cache.base().m_fEncryptionPasswordChanged) { /* Cipher attribute changed? */ QString strNewCipher; if (generalData.m_fEncryptionCipherChanged) { strNewCipher = generalData.m_fEncryptionEnabled ? m_encryptionCiphers.at(generalData.m_iEncryptionCipherIndex) : QString(); } /* Password attribute changed? */ QString strNewPassword; QString strNewPasswordId; if (generalData.m_fEncryptionPasswordChanged) { strNewPassword = generalData.m_fEncryptionEnabled ? generalData.m_strEncryptionPassword : QString(); strNewPasswordId = generalData.m_fEncryptionEnabled ? m_machine.GetName() : QString(); } /* Get the maps of encrypted mediums and their passwords: */ const EncryptedMediumMap &encryptedMedium = generalData.m_encryptedMediums; const EncryptionPasswordMap &encryptionPasswords = generalData.m_encryptionPasswords; /* Enumerate attachments: */ foreach (const CMediumAttachment &attachment, m_machine.GetMediumAttachments()) { /* Enumerate hard-drives only: */ if (attachment.GetType() == KDeviceType_HardDisk) { /* Get corresponding medium: */ CMedium medium = attachment.GetMedium(); /* Check if old password exists/provided: */ QString strOldPasswordId = encryptedMedium.key(medium.GetId()); QString strOldPassword = encryptionPasswords.value(strOldPasswordId); /* Update encryption: */ CProgress cprogress = medium.ChangeEncryption(strOldPassword, strNewCipher, strNewPassword, strNewPasswordId); if (!medium.isOk()) { QMetaObject::invokeMethod(this, "sigOperationProgressError", Qt::BlockingQueuedConnection, Q_ARG(QString, UIMessageCenter::formatErrorInfo(medium))); continue; } UIProgress uiprogress(cprogress); connect(&uiprogress, SIGNAL(sigProgressChange(ulong, QString, ulong, ulong)), this, SIGNAL(sigOperationProgressChange(ulong, QString, ulong, ulong)), Qt::QueuedConnection); connect(&uiprogress, SIGNAL(sigProgressError(QString)), this, SIGNAL(sigOperationProgressError(QString)), Qt::BlockingQueuedConnection); uiprogress.run(350); } } } } }
UIWizardCloneVDPageExpert::UIWizardCloneVDPageExpert(const CMedium &sourceVirtualDisk) { /* Create widgets: */ QGridLayout *pMainLayout = new QGridLayout(this); { pMainLayout->setContentsMargins(8, 6, 8, 6); pMainLayout->setSpacing(10); m_pSourceDiskCnt = new QGroupBox(this); { m_pSourceDiskCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QHBoxLayout *pSourceDiskCntLayout = new QHBoxLayout(m_pSourceDiskCnt); { m_pSourceDiskSelector = new VBoxMediaComboBox(m_pSourceDiskCnt); { m_pSourceDiskSelector->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); m_pSourceDiskSelector->setType(UIMediumType_HardDisk); m_pSourceDiskSelector->setCurrentItem(sourceVirtualDisk.GetId()); m_pSourceDiskSelector->repopulate(); } m_pSourceDiskOpenButton = new QIToolButton(m_pSourceDiskCnt); { m_pSourceDiskOpenButton->setAutoRaise(true); m_pSourceDiskOpenButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", ":/select_file_disabled_16px.png")); } pSourceDiskCntLayout->addWidget(m_pSourceDiskSelector); pSourceDiskCntLayout->addWidget(m_pSourceDiskOpenButton); } } m_pDestinationCnt = new QGroupBox(this); { m_pDestinationCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QHBoxLayout *pLocationCntLayout = new QHBoxLayout(m_pDestinationCnt); { m_pDestinationDiskEditor = new QLineEdit(m_pDestinationCnt); m_pDestinationDiskOpenButton = new QIToolButton(m_pDestinationCnt); { m_pDestinationDiskOpenButton->setAutoRaise(true); m_pDestinationDiskOpenButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", "select_file_disabled_16px.png")); } } pLocationCntLayout->addWidget(m_pDestinationDiskEditor); pLocationCntLayout->addWidget(m_pDestinationDiskOpenButton); } m_pFormatCnt = new QGroupBox(this); { m_pFormatCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QVBoxLayout *pFormatCntLayout = new QVBoxLayout(m_pFormatCnt); { m_pFormatButtonGroup = new QButtonGroup(this); { CSystemProperties systemProperties = vboxGlobal().virtualBox().GetSystemProperties(); const QVector<CMediumFormat> &medFormats = systemProperties.GetMediumFormats(); for (int i = 0; i < medFormats.size(); ++i) { const CMediumFormat &medFormat = medFormats[i]; if (medFormat.GetName() == "VDI") addFormatButton(m_pFormatCnt, pFormatCntLayout, medFormat); } for (int i = 0; i < medFormats.size(); ++i) { const CMediumFormat &medFormat = medFormats[i]; if (medFormat.GetName() != "VDI") addFormatButton(m_pFormatCnt, pFormatCntLayout, medFormat); } if (!m_pFormatButtonGroup->buttons().isEmpty()) { m_pFormatButtonGroup->button(0)->click(); m_pFormatButtonGroup->button(0)->setFocus(); } } } } m_pVariantCnt = new QGroupBox(this); { m_pVariantCnt->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QVBoxLayout *pVariantCntLayout = new QVBoxLayout(m_pVariantCnt); { m_pVariantButtonGroup = new QButtonGroup(m_pVariantCnt); { m_pDynamicalButton = new QRadioButton(m_pVariantCnt); { m_pDynamicalButton->click(); m_pDynamicalButton->setFocus(); } m_pFixedButton = new QRadioButton(m_pVariantCnt); m_pVariantButtonGroup->addButton(m_pDynamicalButton, 0); m_pVariantButtonGroup->addButton(m_pFixedButton, 1); } m_pSplitBox = new QCheckBox(m_pVariantCnt); pVariantCntLayout->addWidget(m_pDynamicalButton); pVariantCntLayout->addWidget(m_pFixedButton); pVariantCntLayout->addWidget(m_pSplitBox); } } pMainLayout->addWidget(m_pSourceDiskCnt, 0, 0, 1, 2); pMainLayout->addWidget(m_pDestinationCnt, 1, 0, 1, 2); pMainLayout->addWidget(m_pFormatCnt, 2, 0, Qt::AlignTop); pMainLayout->addWidget(m_pVariantCnt, 2, 1, Qt::AlignTop); sltHandleSourceDiskChange(); sltMediumFormatChanged(); } /* Setup connections: */ connect(m_pSourceDiskSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(sltHandleSourceDiskChange())); connect(m_pSourceDiskOpenButton, SIGNAL(clicked()), this, SLOT(sltHandleOpenSourceDiskClick())); connect(m_pFormatButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(sltMediumFormatChanged())); connect(m_pVariantButtonGroup, SIGNAL(buttonClicked(QAbstractButton *)), this, SIGNAL(completeChanged())); connect(m_pSplitBox, SIGNAL(stateChanged(int)), this, SIGNAL(completeChanged())); connect(m_pDestinationDiskEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged())); connect(m_pDestinationDiskOpenButton, SIGNAL(clicked()), this, SLOT(sltSelectLocationButtonClicked())); /* Register classes: */ qRegisterMetaType<CMedium>(); qRegisterMetaType<CMediumFormat>(); /* Register fields: */ registerField("sourceVirtualDisk", this, "sourceVirtualDisk"); registerField("mediumFormat", this, "mediumFormat"); registerField("mediumVariant", this, "mediumVariant"); registerField("mediumPath", this, "mediumPath"); registerField("mediumSize", this, "mediumSize"); }