UICloneVMWizard::UICloneVMWizard(QWidget *pParent, CMachine machine, CSnapshot snapshot /* = CSnapshot() */) : QIWizard(pParent) , m_machine(machine) , m_snapshot(snapshot) { /* Create & add pages: */ setPage(PageIntro, new UICloneVMWizardPage1(machine.GetName())); /* If we are having a snapshot we can show the "Linked" option. */ setPage(PageType, new UICloneVMWizardPage2(snapshot.isNull())); /* If the machine has no snapshots, we don't bother the user about options * for it. */ if (machine.GetSnapshotCount() > 0) setPage(PageMode, new UICloneVMWizardPage3(snapshot.isNull() ? false : snapshot.GetChildrenCount() > 0)); /* Translate wizard: */ retranslateUi(); /* Translate wizard pages: */ retranslateAllPages(); /* Resize wizard to 'golden ratio': */ resizeToGoldenRatio(); #ifdef Q_WS_MAC setMinimumSize(QSize(600, 400)); /* Assign background image: */ assignBackground(":/vmw_clone_bg.png"); #else /* Q_WS_MAC */ /* Assign watermark: */ assignWatermark(":/vmw_clone.png"); #endif /* Q_WS_MAC */ }
void VBoxSnapshotsWgt::sltCloneSnapshot() { SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); AssertReturn (item, (void) 0); CMachine machine; CSnapshot snapshot; if (item->isCurrentStateItem()) machine = item->machine(); else { snapshot = item->snapshot(); AssertReturn(!snapshot.isNull(), (void)0); machine = snapshot.GetMachine(); } AssertReturn(!machine.isNull(), (void)0); /* Show Clone VM wizard: */ UISafePointerWizard pWizard = new UIWizardCloneVM(this, machine, snapshot); pWizard->prepare(); pWizard->exec(); if (pWizard) delete pWizard; }
void VBoxSnapshotsWgt::onItemChanged (QTreeWidgetItem *aItem) { if (mEditProtector) return; SnapshotWgtItem *item = aItem ? static_cast <SnapshotWgtItem*> (aItem) : 0; if (item) { CSnapshot snap = item->snapshotId().isNull() ? CSnapshot() : mMachine.FindSnapshot(item->snapshotId()); if (!snap.isNull() && snap.isOk() && snap.GetName() != item->text (0)) snap.SetName (item->text (0)); } }
void VBoxSnapshotsWgt::sltShowSnapshotDetails() { SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); AssertReturn (item, (void) 0); CSnapshot snap = item->snapshot(); AssertReturn (!snap.isNull(), (void) 0); CMachine snapMachine = snap.GetMachine(); VBoxSnapshotDetailsDlg dlg (this); dlg.getFromSnapshot (snap); if (dlg.exec() == QDialog::Accepted) dlg.putBackToSnapshot(); }
void VBoxSnapshotsWgt::populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem) { SnapshotWgtItem *item = aItem ? new SnapshotWgtItem (aItem, aSnapshot) : new SnapshotWgtItem (mTreeWidget, aSnapshot); item->recache(); CSnapshot curSnapshot = mMachine.GetCurrentSnapshot(); if (!curSnapshot.isNull() && curSnapshot.GetId() == aSnapshot.GetId()) { item->setBold (true); mCurSnapshotItem = item; } CSnapshotVector snapshots = aSnapshot.GetChildren(); foreach (const CSnapshot &snapshot, snapshots) populateSnapshots (snapshot, item); item->setExpanded (true); item->setFlags (item->flags() | Qt::ItemIsEditable); }
bool UIVMItem::recache() { bool needsResort = true; m_strId = m_machine.GetId(); m_strSettingsFile = m_machine.GetSettingsFilePath(); m_fAccessible = m_machine.GetAccessible(); if (m_fAccessible) { QString name = m_machine.GetName(); CSnapshot snp = m_machine.GetCurrentSnapshot(); m_strSnapshotName = snp.isNull() ? QString::null : snp.GetName(); needsResort = name != m_strName; m_strName = name; m_machineState = m_machine.GetState(); m_lastStateChange.setTime_t(m_machine.GetLastStateChange() / 1000); m_sessionState = m_machine.GetSessionState(); m_strOSTypeId = m_machine.GetOSTypeId(); m_cSnaphot = m_machine.GetSnapshotCount(); if ( m_machineState == KMachineState_PoweredOff || m_machineState == KMachineState_Saved || m_machineState == KMachineState_Teleported || m_machineState == KMachineState_Aborted ) { m_pid = (ULONG) ~0; /// @todo Remove. See @c todo in #switchTo() below. #if 0 mWinId = (WId) ~0; #endif } else { m_pid = m_machine.GetSessionPID(); /// @todo Remove. See @c todo in #switchTo() below. #if 0 mWinId = FindWindowIdFromPid(m_pid); #endif } /* Determine configuration access level: */ m_configurationAccessLevel = ::configurationAccessLevel(m_sessionState, m_machineState); /* Also take restrictions into account: */ if ( m_configurationAccessLevel != ConfigurationAccessLevel_Null && !gEDataManager->machineReconfigurationEnabled(m_strId)) m_configurationAccessLevel = ConfigurationAccessLevel_Null; /* Should we show details for this item? */ m_fHasDetails = gEDataManager->showMachineInSelectorDetails(m_strId); } else { m_accessError = m_machine.GetAccessError(); /* this should be in sync with * UIMessageCenter::confirm_machineDeletion() */ QFileInfo fi(m_strSettingsFile); QString name = VBoxGlobal::hasAllowedExtension(fi.completeSuffix(), VBoxFileExts) ? fi.completeBaseName() : fi.fileName(); needsResort = name != m_strName; m_strName = name; m_machineState = KMachineState_Null; m_sessionState = KSessionState_Null; m_lastStateChange = QDateTime::currentDateTime(); m_strOSTypeId = QString::null; m_cSnaphot = 0; m_pid = (ULONG) ~0; /// @todo Remove. See @c todo in #switchTo() below. #if 0 mWinId = (WId) ~0; #endif /* Set configuration access level to NULL: */ m_configurationAccessLevel = ConfigurationAccessLevel_Null; /* Should we show details for this item? */ m_fHasDetails = true; } return needsResort; }
/** * 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; }
bool UIVMItem::recache() { bool needsResort = true; m_strId = m_machine.GetId(); m_strSettingsFile = m_machine.GetSettingsFilePath(); m_fAccessible = m_machine.GetAccessible(); if (m_fAccessible) { QString name = m_machine.GetName(); CSnapshot snp = m_machine.GetCurrentSnapshot(); m_strSnapshotName = snp.isNull() ? QString::null : snp.GetName(); needsResort = name != m_strName; m_strName = name; m_machineState = m_machine.GetState(); m_lastStateChange.setTime_t(m_machine.GetLastStateChange() / 1000); m_sessionState = m_machine.GetSessionState(); m_strOSTypeId = m_machine.GetOSTypeId(); m_cSnaphot = m_machine.GetSnapshotCount(); if ( m_machineState == KMachineState_PoweredOff || m_machineState == KMachineState_Saved || m_machineState == KMachineState_Teleported || m_machineState == KMachineState_Aborted ) { m_pid = (ULONG) ~0; /// @todo Remove. See @c todo in #switchTo() below. #if 0 mWinId = (WId) ~0; #endif } else { m_pid = m_machine.GetSessionPid(); /// @todo Remove. See @c todo in #switchTo() below. #if 0 mWinId = FindWindowIdFromPid(m_pid); #endif } } else { m_accessError = m_machine.GetAccessError(); /* this should be in sync with * UIMessageCenter::confirm_machineDeletion() */ QFileInfo fi(m_strSettingsFile); QString name = VBoxGlobal::hasAllowedExtension(fi.completeSuffix(), VBoxFileExts) ? fi.completeBaseName() : fi.fileName(); needsResort = name != m_strName; m_strName = name; m_machineState = KMachineState_Null; m_sessionState = KSessionState_Null; m_lastStateChange = QDateTime::currentDateTime(); m_strOSTypeId = QString::null; m_cSnaphot = 0; m_pid = (ULONG) ~0; /// @todo Remove. See @c todo in #switchTo() below. #if 0 mWinId = (WId) ~0; #endif } return needsResort; }