/* $Id$ */
/** @file
* VBox Qt GUI - UIMedium class implementation.
*/
/*
* Copyright (C) 2009-2015 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
# include <precomp.h>
#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
/* Qt includes: */
# include <QDir>
/* GUI includes: */
# include "UIMedium.h"
# include "VBoxGlobal.h"
# include "UIConverter.h"
# include "UIMessageCenter.h"
# include "UIExtraDataManager.h"
# include "UIIconPool.h"
/* COM includes: */
# include "CMachine.h"
# include "CSnapshot.h"
#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
{
refresh();
}
{
refresh();
}
{
refresh();
}
{
*this = other;
}
{
return *this;
}
{
/* Ignore for NULL medium: */
return;
/* Acquire actual medium state: */
/* Save the result to distinguish between
* inaccessible and e.g. uninitialized objects: */
{
}
else
/* Refresh finally: */
refresh();
}
{
/* Reset ID parameters: */
m_strRootId = nullID();
m_strParentId = nullID();
/* Reset cache parameters: */
//m_strKey = nullID();
/* Reset size parameters: */
m_strLogicalSize = QString();
/* Reset hard drive related parameters: */
m_strHardDiskType = QString();
/* Reset data parameters: */
m_strUsage = QString();
m_strToolTip = QString();
/* Reset m_noDiffs: */
/* Reset flags: */
m_fHidden = false;
m_fUsedByHiddenMachinesOnly = false;
m_fReadOnly = false;
m_fUsedInSnapshots = false;
m_fHostDrive = false;
/* For non NULL medium: */
{
/* Refresh medium ID: */
/* Refresh root medium ID: */
/* Init medium key if necessary: */
/* Check whether this is host-drive medium: */
/* Refresh medium name: */
if (!m_fHostDrive)
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)
/* Refresh medium size and logical size: */
if (!m_fHostDrive)
{
/* Only for created and accessible mediums: */
{
if (m_type == UIMediumType_HardDisk)
else
}
}
/* For hard drive medium: */
if (m_type == UIMediumType_HardDisk)
{
/* Refresh hard drive disk type: */
/* Refresh hard drive format: */
/* Refresh hard drive storage details: */
/* Check whether this is read-only hard drive: */
/* Refresh parent hard drive ID: */
if (!parentMedium.isNull())
/* Only for created and accessible mediums: */
{
/* Refresh root hard drive ID: */
while (!parentMedium.isNull())
{
}
}
}
/* Check whether this is hidden medium: */
{
m_fHidden = true;
}
/* Refresh usage data: */
if (m_machineIds.size() > 0)
{
/* Get CVirtualBox object: */
/* By default we assuming that this medium is attached
* to 'hidden' machines only, if at least one machine present: */
m_fUsedByHiddenMachinesOnly = true;
/* Prepare machine usage: */
/* Walk through all the machines this medium attached to: */
{
/* Look for the corresponding machine: */
/* 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. */
{
/* Since we can't precisely check 'hidden' status for that machine in such case,
* we have to assume that medium attached not only to 'hidden' machines: */
m_fUsedByHiddenMachinesOnly = false;
continue;
}
/* Finally we can precisely check if current machine is 'hidden': */
m_fUsedByHiddenMachinesOnly = false;
/* Prepare snapshot usage: */
/* Walk through all the snapshots this medium attached to: */
{
if (strSnapshotID == strMachineID)
{
/* 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. */
continue;
}
/* Look for the corresponding snapshot: */
/* Snapshot can be NULL while takeSnaphot is in progress: */
continue;
/* Refresh snapshot usage flag: */
m_fUsedInSnapshots = true;
/* Append snapshot usage: */
if (!strSnapshotUsage.isNull())
strSnapshotUsage += ", ";
}
/* Append machine usage: */
if (!strMachineUsage.isNull())
strMachineUsage += ", ";
/* Append snapshot usage: */
if (!strSnapshotUsage.isNull())
}
/* Append machine usage: */
if (!strMachineUsage.isEmpty())
}
/* Refresh tool-tip: */
m_strToolTip = m_sstrRow.arg(QString("<p style=white-space:pre><b>%1</b></p>").arg(m_fHostDrive ? m_strName : m_strLocation));
if (m_type == UIMediumType_HardDisk)
{
m_strToolTip += m_sstrRow.arg(VBoxGlobal::tr("<p style=white-space:pre>Type (Format): %1 (%2)</p>", "medium")
}
switch (m_state)
{
case KMediumState_NotCreated:
{
break;
}
{
{
/* Not Accessible: */
m_strToolTip += m_sstrRow.arg("<hr>") + m_sstrRow.arg(VBoxGlobal::highlight(m_strLastAccessError, true /* aToolTip */));
}
else
{
/* Accessibility check (eg GetState()) itself failed: */
m_strToolTip += m_sstrRow.arg("<hr>") + m_sstrRow.arg(VBoxGlobal::tr("Failed to check accessibility of disk image files.", "medium")) +
}
break;
}
default:
break;
}
}
}
{
m_strParentId = nullID();
if (m_type == UIMediumType_HardDisk)
{
if (!parentMedium.isNull())
}
}
QString UIMedium::toolTip(bool fNoDiffs /* = false */, bool fCheckRO /* = false */, bool fNullAllowed /* = false */) const
{
{
strTip = fNullAllowed ? m_sstrRow.arg(VBoxGlobal::tr("<b>No disk image file selected</b>", "medium")) +
m_sstrRow.arg(VBoxGlobal::tr("You can create or add disk image files in the virtual machine settings."));
}
else
{
if (fCheckRO && m_fReadOnly)
"a newly created differencing hard drive.", "medium"));
}
}
{
if (fCheckRO && m_fReadOnly)
{
}
return pixmap;
}
bool fPredictDiff /* = false */,
bool fUseHTML /* = false */) const
{
// @todo the below check is rough; if m_medium becomes uninitialized, any
// of getters called afterwards will also fail. The same relates to the
// root hard drive object (that will be the hard drive itself in case of
// non-differencing disks). However, this check was added to fix a
// particular use case: when the hard drive is a differencing hard drive and
// it happens to be discarded (and uninitialized) after this method is
// called but before we read all its properties (yes, it's possible!), the
// root object will be null and calling methods on it will assert in the
// debug builds. This check seems to be enough as a quick solution (fresh
// hard drive attachments will be re-read by a machine state change signal
// after the discard operation is finished, so the user will eventually see
// correct data), but in order to solve the problem properly we need to use
// exceptions everywhere (or check the result after every method call). See
// @bugref{2149}.
return m_strName;
return QString();
/* Note: root accessible only if medium enumerated: */
if (m_type == UIMediumType_HardDisk)
{
if (fNoDiffs)
{
}
else
{
}
}
switch (eState)
{
case KMediumState_NotCreated:
break;
break;
default:
break;
}
strDetails = fUseHTML ?
QString("%1 (<nobr>%2</nobr>)").arg(VBoxGlobal::locationForHTML(rootMedium.m_strName), strDetails) :
return strDetails;
}
/* static */
{
return m_sstrNullID;
}
/* static */
{
/* Iterate till the root: */
do
{
/* Ignore medium if its hidden
* or attached to hidden machines only: */
if (mediumIterator.isHidden())
return true;
/* Move iterator to parent: */
}
while (!mediumIterator.isNull());
/* False by default: */
return false;
}
{
/* Redirect call to VBoxGlobal: */
}
{
/* Redirect call to VBoxGlobal: */
}
{
return;
for (UIMedium parentMedium = parent(); !parentMedium.isNull(); parentMedium = parentMedium.parent())
{
{
"are inaccessible. Please use the Virtual Medium "
"Manager to inspect these files.", "medium"));
{
break;
}
}
}
{
"the following differencing hard drive:", "medium")) +
}
}