Ejemplo n.º 1
0
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;
        }
    }
Ejemplo n.º 2
0
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;
        }
    }
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());
    }
Ejemplo n.º 4
0
/**
 * 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;
}
Ejemplo n.º 5
0
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;
                    }
                }
            }
        }