void UIMachineWindow::updateAppearanceOf(int iElement) { /* Update window title: */ if (iElement & UIVisualElement_WindowTitle) { /* Get machine state: */ KMachineState state = uisession()->machineState(); /* Prepare full name: */ QString strSnapshotName; if (machine().GetSnapshotCount() > 0) { CSnapshot snapshot = machine().GetCurrentSnapshot(); strSnapshotName = " (" + snapshot.GetName() + ")"; } QString strMachineName = machineName() + strSnapshotName; if (state != KMachineState_Null) strMachineName += " [" + gpConverter->toString(state) + "]"; /* Unusual on the Mac. */ #ifndef VBOX_WS_MAC const QString strUserProductName = uisession()->machineWindowNamePostfix(); strMachineName += " - " + (strUserProductName.isEmpty() ? defaultWindowTitle() : strUserProductName); #endif /* !VBOX_WS_MAC */ if (machine().GetMonitorCount() > 1) strMachineName += QString(" : %1").arg(m_uScreenId + 1); setWindowTitle(strMachineName); } }
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; }
/* static */ bool UIMachine::startMachine(const QString &strID) { /* Some restrictions: */ AssertMsgReturn(vboxGlobal().isValid(), ("VBoxGlobal is invalid.."), false); AssertMsgReturn(!vboxGlobal().virtualMachine(), ("Machine already started.."), false); /* Restore current snapshot if requested: */ if (vboxGlobal().shouldRestoreCurrentSnapshot()) { /* Create temporary session: */ CSession session = vboxGlobal().openSession(strID, KLockType_VM); if (session.isNull()) return false; /* Which VM we operate on? */ CMachine machine = session.GetMachine(); /* Which snapshot we are restoring? */ CSnapshot snapshot = machine.GetCurrentSnapshot(); /* Prepare restore-snapshot progress: */ CProgress progress = machine.RestoreSnapshot(snapshot); if (!machine.isOk()) return msgCenter().cannotRestoreSnapshot(machine, snapshot.GetName(), machine.GetName()); /* Show the snapshot-discarding progress: */ msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png"); if (progress.GetResultCode() != 0) return msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName()); /* Unlock session finally: */ session.UnlockMachine(); /* Clear snapshot-restoring request: */ vboxGlobal().setShouldRestoreCurrentSnapshot(false); } /* For separate process we should launch VM before UI: */ if (vboxGlobal().isSeparateProcess()) { /* Get corresponding machine: */ CMachine machine = vboxGlobal().virtualBox().FindMachine(vboxGlobal().managedVMUuid()); AssertMsgReturn(!machine.isNull(), ("VBoxGlobal::managedVMUuid() should have filter that case before!\n"), false); /* Try to launch corresponding machine: */ if (!vboxGlobal().launchMachine(machine, VBoxGlobal::LaunchMode_Separate)) return false; } /* Try to create machine UI: */ return create(); }
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::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false*/) { /* Get currently chosen item: */ SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0; AssertReturn(pItem, (void)0); /* Detemine snapshot id: */ QString strSnapshotId = pItem->snapshotId(); AssertReturn(!strSnapshotId.isNull(), (void)0); /* Get currently desired snapshot: */ CSnapshot snapshot = mMachine.FindSnapshot(strSnapshotId); /* Ask the user if he really wants to restore the snapshot: */ int iResultCode = AlertButton_Ok; if (!fSuppressNonCriticalWarnings || mMachine.GetCurrentStateModified()) { iResultCode = msgCenter().confirmSnapshotRestoring(snapshot.GetName(), mMachine.GetCurrentStateModified()); if (iResultCode & AlertButton_Cancel) return; } /* If user also confirmed new snapshot creation: */ if (iResultCode & AlertOption_CheckBox) { /* Take snapshot of changed current state: */ mTreeWidget->setCurrentItem(curStateItem()); if (!takeSnapshot()) return; } /* Open a direct session (this call will handle all errors): */ CSession session = vboxGlobal().openSession(mMachineId); if (session.isNull()) return; /* Restore chosen snapshot: */ CConsole console = session.GetConsole(); CProgress progress = console.RestoreSnapshot(snapshot); if (console.isOk()) { msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_restore_90px.png"); if (progress.GetResultCode() != 0) msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), mMachine.GetName()); } else msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), mMachine.GetName()); /* Unlock machine finally: */ session.UnlockMachine(); }
void VBoxSnapshotDetailsDlg::getFromSnapshot (const CSnapshot &aSnapshot) { mSnapshot = aSnapshot; CMachine machine = mSnapshot.GetMachine(); /* Get general properties */ mLeName->setText (aSnapshot.GetName()); mTeDescription->setText (aSnapshot.GetDescription()); /* Get timestamp info */ QDateTime timestamp; timestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000); bool dateTimeToday = timestamp.date() == QDate::currentDate(); QString dateTime = dateTimeToday ? timestamp.time().toString (Qt::LocalDate) : timestamp.toString (Qt::LocalDate); mTxTaken->setText (dateTime); /* Get thumbnail if present */ ULONG width = 0, height = 0; QVector <BYTE> thumbData = machine.ReadSavedThumbnailToArray (0, KBitmapFormat_BGR0, width, height); mThumbnail = thumbData.size() != 0 ? QPixmap::fromImage (QImage (thumbData.data(), width, height, QImage::Format_RGB32).copy()) : QPixmap(); QVector <BYTE> screenData = machine.ReadSavedScreenshotToArray (0, KBitmapFormat_PNG, width, height); mScreenshot = screenData.size() != 0 ? QPixmap::fromImage (QImage::fromData (screenData.data(), screenData.size(), "PNG")) : QPixmap(); QGridLayout *lt = qobject_cast <QGridLayout*> (layout()); Assert (lt); if (mThumbnail.isNull()) { lt->removeWidget (mLbThumbnail); mLbThumbnail->setHidden (true); lt->removeWidget (mLeName); lt->removeWidget (mTxTaken); lt->addWidget (mLeName, 0, 1, 1, 2); lt->addWidget (mTxTaken, 1, 1, 1, 2); } else { lt->removeWidget (mLeName); lt->removeWidget (mTxTaken); lt->addWidget (mLeName, 0, 1); lt->addWidget (mTxTaken, 1, 1); lt->removeWidget (mLbThumbnail); lt->addWidget (mLbThumbnail, 0, 2, 2, 1); mLbThumbnail->setHidden (false); } retranslateUi(); }
void VBoxSnapshotsWgt::sltDeleteSnapshot() { SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); AssertReturn (item, (void) 0); QString snapId = item->snapshotId(); AssertReturn (!snapId.isNull(), (void) 0); CSnapshot snapshot = mMachine.FindSnapshot(snapId); if (!msgCenter().confirmSnapshotRemoval(snapshot.GetName())) return; /** @todo check available space on the target filesystem etc etc. */ #if 0 if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(snapshot.GetName(), "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi", "59 GiB", "15 GiB")) return; #endif /* Open a direct session (this call will handle all errors) */ bool busy = mSessionState != KSessionState_Unlocked; CSession session; if (busy) session = vboxGlobal().openExistingSession(mMachineId); else session = vboxGlobal().openSession(mMachineId); if (session.isNull()) return; CConsole console = session.GetConsole(); CProgress progress = console.DeleteSnapshot (snapId); if (console.isOk()) { /* Show the progress dialog */ msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_discard_90px.png"); if (progress.GetResultCode() != 0) msgCenter().cannotRemoveSnapshot(progress, snapshot.GetName(), mMachine.GetName()); } else msgCenter().cannotRemoveSnapshot(console, snapshot.GetName(), mMachine.GetName()); session.UnlockMachine(); }
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); }
void UIMachineWindowFullscreen::updateAppearanceOf(int iElement) { /* Base class update: */ UIMachineWindow::updateAppearanceOf(iElement); /* If mini tool-bar is present: */ if (m_pMiniToolBar) { /* Get machine: */ CMachine machine = session().GetConsole().GetMachine(); /* Get snapshot(s): */ QString strSnapshotName; if (machine.GetSnapshotCount() > 0) { CSnapshot snapshot = machine.GetCurrentSnapshot(); strSnapshotName = " (" + snapshot.GetName() + ")"; } /* Update mini tool-bar text: */ m_pMiniToolBar->setDisplayText(machine.GetName() + strSnapshotName); } }
void UIMachineWindowFullscreen::updateAppearanceOf(int iElement) { /* Call to base-class: */ UIMachineWindow::updateAppearanceOf(iElement); /* Update mini-toolbar: */ if (iElement & UIVisualElement_MiniToolBar) { if (m_pMiniToolBar) { /* Get snapshot(s): */ QString strSnapshotName; if (machine().GetSnapshotCount() > 0) { CSnapshot snapshot = machine().GetCurrentSnapshot(); strSnapshotName = " (" + snapshot.GetName() + ")"; } /* Update mini-toolbar text: */ m_pMiniToolBar->setText(machineName() + strSnapshotName); } } }
bool CPackets::WriteStripSnapshot(UINT JobID, UINT StripRows, CSnapshot& Snap) { CMemFile mf; FRAP_STRIP_SNAPSHOT_HDR hdr; ZeroMemory(&hdr, sizeof(hdr)); mf.Write(&hdr, sizeof(hdr)); // reserve space for header { CArchive ar(&mf, CArchive::store); Snap.Serialize(ar); } DWORD PktLen = static_cast<DWORD>(mf.GetLength()); DWORD SnapLen = PktLen - sizeof(FRAP_STRIP_SNAPSHOT_HDR); FRAP_STRIP_SNAPSHOT *pp = (FRAP_STRIP_SNAPSHOT *)mf.Detach(); InitHdr(*pp, PMID_STRIP_SNAPSHOT, PktLen); pp->JobID = JobID; pp->StripRows = StripRows; pp->SnapLen = SnapLen; bool retc = Write(*pp, PktLen); delete pp; // buffer detached from CMemFile return(retc); }
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; }
void CServer::DoSnapshot() { GameServer()->OnPreSnap(); // create snapshot for demo recording if(m_DemoRecorder.IsRecording()) { char aData[CSnapshot::MAX_SIZE]; int SnapshotSize; // build snap and possibly add some messages m_SnapshotBuilder.Init(); GameServer()->OnSnap(-1); SnapshotSize = m_SnapshotBuilder.Finish(aData); // write snapshot m_DemoRecorder.RecordSnapshot(Tick(), aData, SnapshotSize); } // create snapshots for all clients for(int i = 0; i < MAX_CLIENTS; i++) { // client must be ingame to recive snapshots if(m_aClients[i].m_State != CClient::STATE_INGAME) continue; // this client is trying to recover, don't spam snapshots if(m_aClients[i].m_SnapRate == CClient::SNAPRATE_RECOVER && (Tick()%50) != 0) continue; // this client is trying to recover, don't spam snapshots if(m_aClients[i].m_SnapRate == CClient::SNAPRATE_INIT && (Tick()%10) != 0) continue; { char aData[CSnapshot::MAX_SIZE]; CSnapshot *pData = (CSnapshot*)aData; // Fix compiler warning for strict-aliasing char aDeltaData[CSnapshot::MAX_SIZE]; char aCompData[CSnapshot::MAX_SIZE]; int SnapshotSize; int Crc; static CSnapshot EmptySnap; CSnapshot *pDeltashot = &EmptySnap; int DeltashotSize; int DeltaTick = -1; int DeltaSize; m_SnapshotBuilder.Init(); GameServer()->OnSnap(i); // finish snapshot SnapshotSize = m_SnapshotBuilder.Finish(pData); Crc = pData->Crc(); // remove old snapshos // keep 3 seconds worth of snapshots m_aClients[i].m_Snapshots.PurgeUntil(m_CurrentGameTick-SERVER_TICK_SPEED*3); // save it the snapshot m_aClients[i].m_Snapshots.Add(m_CurrentGameTick, time_get(), SnapshotSize, pData, 0); // find snapshot that we can preform delta against EmptySnap.Clear(); { DeltashotSize = m_aClients[i].m_Snapshots.Get(m_aClients[i].m_LastAckedSnapshot, 0, &pDeltashot, 0); if(DeltashotSize >= 0) DeltaTick = m_aClients[i].m_LastAckedSnapshot; else { // no acked package found, force client to recover rate if(m_aClients[i].m_SnapRate == CClient::SNAPRATE_FULL) m_aClients[i].m_SnapRate = CClient::SNAPRATE_RECOVER; } } // create delta DeltaSize = m_SnapshotDelta.CreateDelta(pDeltashot, pData, aDeltaData); if(DeltaSize) { // compress it int SnapshotSize; const int MaxSize = MAX_SNAPSHOT_PACKSIZE; int NumPackets; SnapshotSize = CVariableInt::Compress(aDeltaData, DeltaSize, aCompData); NumPackets = (SnapshotSize+MaxSize-1)/MaxSize; for(int n = 0, Left = SnapshotSize; Left; n++) { int Chunk = Left < MaxSize ? Left : MaxSize; Left -= Chunk; if(NumPackets == 1) { CMsgPacker Msg(NETMSG_SNAPSINGLE); Msg.AddInt(m_CurrentGameTick); Msg.AddInt(m_CurrentGameTick-DeltaTick); Msg.AddInt(Crc); Msg.AddInt(Chunk); Msg.AddRaw(&aCompData[n*MaxSize], Chunk); SendMsgEx(&Msg, MSGFLAG_FLUSH, i, true); } else { CMsgPacker Msg(NETMSG_SNAP); Msg.AddInt(m_CurrentGameTick); Msg.AddInt(m_CurrentGameTick-DeltaTick); Msg.AddInt(NumPackets); Msg.AddInt(n); Msg.AddInt(Crc); Msg.AddInt(Chunk); Msg.AddRaw(&aCompData[n*MaxSize], Chunk); SendMsgEx(&Msg, MSGFLAG_FLUSH, i, true); } } } else { CMsgPacker Msg(NETMSG_SNAPEMPTY); Msg.AddInt(m_CurrentGameTick); Msg.AddInt(m_CurrentGameTick-DeltaTick); SendMsgEx(&Msg, MSGFLAG_FLUSH, i, true); } } } GameServer()->OnPostSnap(); }
/** * 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; }