VirtualBox

Ignore:
Timestamp:
Jul 16, 2021 8:49:52 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9996. Working on expert page initialization. Still much to do.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.cpp

    r90217 r90223  
    1919#include <QButtonGroup>
    2020#include <QCheckBox>
     21#include <QDir>
     22#include <QFileInfo>
    2123#include <QLabel>
    2224#include <QRadioButton>
     
    6668}
    6769
     70const CMediumFormat &UIDiskFormatsGroupBox::VDIMeiumFormat() const
     71{
     72    return m_comVDIMediumFormat;
     73}
     74
    6875void UIDiskFormatsGroupBox::prepare()
    6976{
     
    7885    foreach (const CMediumFormat &format, formats)
    7986    {
    80         /* VDI goes first: */
    8187        if (format.GetName() == "VDI")
     88        {
    8289            vdi[format.GetId()] = format;
     90            m_comVDIMediumFormat = format;
     91        }
    8392        else
    8493        {
    8594            const QVector<KMediumFormatCapabilities> &capabilities = format.GetCapabilities();
    86             /* Then goes preferred: */
    8795            if (capabilities.contains(KMediumFormatCapabilities_Preferred))
    8896                preferred[format.GetId()] = format;
    89             /* Then others: */
    9097            else
    9198                others[format.GetId()] = format;
     
    165172}
    166173
     174/* static */
    167175QString UIDiskFormatsGroupBox::defaultExtension(const CMediumFormat &mediumFormatRef)
    168176{
     
    182190}
    183191
     192const QStringList UIDiskFormatsGroupBox::formatExtensions() const
     193{
     194    return m_formatExtensions;
     195}
     196
    184197/*********************************************************************************************************************************
    185198*   UIDiskVariantGroupBox implementation.                                                                                   *
     
    220233}
    221234
     235qulonglong UIDiskVariantGroupBox::mediumVariant() const
     236{
     237    /* Initial value: */
     238    qulonglong uMediumVariant = (qulonglong)KMediumVariant_Max;
     239
     240    /* Exclusive options: */
     241    if (m_pFixedCheckBox && m_pFixedCheckBox->isChecked())
     242        uMediumVariant = (qulonglong)KMediumVariant_Fixed;
     243    else
     244        uMediumVariant = (qulonglong)KMediumVariant_Standard;
     245
     246    /* Additional options: */
     247    if (m_pSplitBox && m_pSplitBox->isChecked())
     248        uMediumVariant |= (qulonglong)KMediumVariant_VmdkSplit2G;
     249
     250    /* Return options: */
     251    return uMediumVariant;
     252}
     253
     254void UIDiskVariantGroupBox::setMediumVariant(qulonglong uMediumVariant)
     255{
     256    /* Exclusive options: */
     257    if (uMediumVariant & (qulonglong)KMediumVariant_Fixed)
     258    {
     259        m_pFixedCheckBox->click();
     260        m_pFixedCheckBox->setFocus();
     261    }
     262
     263    /* Additional options: */
     264    m_pSplitBox->setChecked(uMediumVariant & (qulonglong)KMediumVariant_VmdkSplit2G);
     265}
     266
     267void UIDiskVariantGroupBox::setWidgetVisibility(CMediumFormat &mediumFormat)
     268{
     269    ULONG uCapabilities = 0;
     270    QVector<KMediumFormatCapabilities> capabilities;
     271    capabilities = mediumFormat.GetCapabilities();
     272    for (int i = 0; i < capabilities.size(); i++)
     273        uCapabilities |= capabilities[i];
     274
     275    bool fIsCreateDynamicPossible = uCapabilities & KMediumFormatCapabilities_CreateDynamic;
     276    bool fIsCreateFixedPossible = uCapabilities & KMediumFormatCapabilities_CreateFixed;
     277    bool fIsCreateSplitPossible = uCapabilities & KMediumFormatCapabilities_CreateSplit2G;
     278    if (m_pFixedCheckBox)
     279    {
     280        if (!fIsCreateDynamicPossible)
     281        {
     282            m_pFixedCheckBox->setChecked(true);
     283            m_pFixedCheckBox->setEnabled(false);
     284        }
     285        if (!fIsCreateFixedPossible)
     286        {
     287            m_pFixedCheckBox->setChecked(false);
     288            m_pFixedCheckBox->setEnabled(false);
     289        }
     290    }
     291    if (m_pFixedCheckBox)
     292        m_pFixedCheckBox->setHidden(!fIsCreateFixedPossible);
     293    if (m_pSplitBox)
     294        m_pSplitBox->setHidden(!fIsCreateSplitPossible);
     295}
     296
     297void UIDiskVariantGroupBox::updateMediumVariantWidgetsAfterFormatChange(const CMediumFormat &mediumFormat)
     298{
     299    /* Enable/disable widgets: */
     300    ULONG uCapabilities = 0;
     301    QVector<KMediumFormatCapabilities> capabilities;
     302    capabilities = mediumFormat.GetCapabilities();
     303    for (int i = 0; i < capabilities.size(); i++)
     304        uCapabilities |= capabilities[i];
     305
     306    bool fIsCreateDynamicPossible = uCapabilities & KMediumFormatCapabilities_CreateDynamic;
     307    bool fIsCreateFixedPossible = uCapabilities & KMediumFormatCapabilities_CreateFixed;
     308    bool fIsCreateSplitPossible = uCapabilities & KMediumFormatCapabilities_CreateSplit2G;
     309
     310    if (m_pFixedCheckBox)
     311    {
     312        m_pFixedCheckBox->setEnabled(fIsCreateDynamicPossible || fIsCreateFixedPossible);
     313        if (!fIsCreateDynamicPossible)
     314            m_pFixedCheckBox->setChecked(true);
     315        if (!fIsCreateFixedPossible)
     316            m_pFixedCheckBox->setChecked(false);
     317    }
     318    m_pSplitBox->setEnabled(fIsCreateSplitPossible);
     319}
     320
     321bool UIDiskVariantGroupBox::isComplete() const
     322{
     323    /* Make sure medium variant is correct: */
     324    return mediumVariant() != (qulonglong)KMediumVariant_Max;
     325}
     326
    222327
    223328/*********************************************************************************************************************************
     
    286391        m_pLocationEditor->setText(strLocation);
    287392}
     393
     394void UIDiskSizeAndLocationGroupBox::updateLocationEditorAfterFormatChange(const CMediumFormat &mediumFormat, const QStringList &formatExtensions)
     395{
     396    /* Compose virtual-disk extension: */
     397    QString strDefaultExtension = UIDiskFormatsGroupBox::defaultExtension(mediumFormat);
     398    /* Update m_pLocationEditor's text if necessary: */
     399    if (!m_pLocationEditor->text().isEmpty() && !strDefaultExtension.isEmpty())
     400    {
     401        QFileInfo fileInfo(m_pLocationEditor->text());
     402        if (fileInfo.suffix() != strDefaultExtension)
     403        {
     404            QFileInfo newFileInfo(QDir(fileInfo.absolutePath()),
     405                                  QString("%1.%2").
     406                                  arg(stripFormatExtension(fileInfo.fileName(), formatExtensions)).
     407                                  arg(strDefaultExtension));
     408            m_pLocationEditor->setText(newFileInfo.absoluteFilePath());
     409        }
     410    }
     411}
     412
     413/* static */
     414QString UIDiskSizeAndLocationGroupBox::stripFormatExtension(const QString &strFileName, const QStringList &formatExtensions)
     415{
     416    QString result(strFileName);
     417    foreach (const QString &strExtension, formatExtensions)
     418    {
     419        if (strFileName.endsWith(strExtension, Qt::CaseInsensitive))
     420        {
     421            /* Add the dot to extenstion: */
     422            QString strExtensionWithDot(strExtension);
     423            strExtensionWithDot.prepend('.');
     424            int iIndex = strFileName.lastIndexOf(strExtensionWithDot, -1, Qt::CaseInsensitive);
     425            result.remove(iIndex, strExtensionWithDot.length());
     426        }
     427    }
     428    return result;
     429}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.h

    r90217 r90223  
    6161    CMediumFormat mediumFormat() const;
    6262    void setMediumFormat(const CMediumFormat &mediumFormat);
     63    const CMediumFormat &VDIMeiumFormat() const;
     64    static QString defaultExtension(const CMediumFormat &mediumFormatRef);
     65    const QStringList formatExtensions() const;
    6366
    6467private:
     
    6669    void prepare();
    6770    void addFormatButton(QVBoxLayout *pFormatLayout, CMediumFormat medFormat, bool fPreferred = false);
    68     QString defaultExtension(const CMediumFormat &mediumFormatRef);
     71
    6972    virtual void retranslateUi() /* override final */;
    7073
    7174    QList<CMediumFormat>  m_formats;
     75    CMediumFormat m_comVDIMediumFormat;
    7276    QStringList           m_formatNames;
    7377    QStringList m_formatExtensions;
     
    8589
    8690    UIDiskVariantGroupBox(QWidget *pParent = 0);
     91    void updateMediumVariantWidgetsAfterFormatChange(const CMediumFormat &mediumFormat);
     92    qulonglong mediumVariant() const;
     93    void setMediumVariant(qulonglong uMediumVariant);
     94    void setWidgetVisibility(CMediumFormat &mediumFormat);
     95    bool isComplete() const;
    8796
    8897private:
     
    110119    QString location() const;
    111120    void setLocation(const QString &strLocation);
     121    void updateLocationEditorAfterFormatChange(const CMediumFormat &mediumFormat, const QStringList &formatExtensions);
    112122
    113123private:
     
    115125    void prepare();
    116126    virtual void retranslateUi() /* override final */;
     127    static QString stripFormatExtension(const QString &strFileName,
     128                                        const QStringList &formatExtensions);
     129
    117130
    118131    QLabel *m_pLocationLabel;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMNameOSTypePageBasic.cpp

    r90101 r90223  
    179179};
    180180
    181 void UIWizardNewVMNameOSTypePage::onNameChanged(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName)
     181void UIWizardNewVMNameOSTypePage::guessOSTypeFromName(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName)
    182182{
    183183    CHost host = uiCommon().host();
     
    366366void UIWizardNewVMNameOSTypePageBasic::sltNameChanged(const QString &strNewName)
    367367{
    368     UIWizardNewVMNameOSTypePage::onNameChanged(m_pNameAndSystemEditor, strNewName);
     368    if (!m_userModifiedParameters.contains("GuestOSType"))
     369        UIWizardNewVMNameOSTypePage::guessOSTypeFromName(m_pNameAndSystemEditor, strNewName);
    369370    UIWizardNewVMNameOSTypePage::composeMachineFilePath(m_pNameAndSystemEditor, qobject_cast<UIWizardNewVM*>(wizard()));
    370371    emit completeChanged();
     
    379380void UIWizardNewVMNameOSTypePageBasic::sltOsTypeChanged()
    380381{
    381     /* If the user manually edited the OS type, we didn't want our automatic OS type guessing anymore.
    382      * So simply disconnect the text-edit signal. */
     382    m_userModifiedParameters << "GuestOSType";
    383383    if (m_pNameAndSystemEditor)
    384     {
    385         m_pNameAndSystemEditor->disconnect(SIGNAL(sigNameChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));
    386384        newVMWizardPropertySet(GuestOSType, m_pNameAndSystemEditor->type());
    387     }
    388385}
    389386
     
    453450    if (pWizard)
    454451    {
    455         if (!pWizard->detectedOSTypeId().isEmpty())
    456             UIWizardNewVMNameOSTypePage::onNameChanged(m_pNameAndSystemEditor, pWizard->detectedOSTypeId());
     452        if (!pWizard->detectedOSTypeId().isEmpty() && !m_userModifiedParameters.contains("GuestOSType"))
     453            UIWizardNewVMNameOSTypePage::guessOSTypeFromName(m_pNameAndSystemEditor, pWizard->detectedOSTypeId());
    457454        pWizard->setISOFilePath(strPath);
    458455    }
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMNameOSTypePageBasic.h

    r90095 r90223  
    4040namespace UIWizardNewVMNameOSTypePage
    4141{
    42     void onNameChanged(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName);
     42    void guessOSTypeFromName(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName);
    4343    bool createMachineFolder(UINameAndSystemEditor *pNameAndSystemEditor,
    4444                             UINativeWizardPage *pCaller,
     
    104104        QIRichTextLabel       *m_pNameOSTypeLabel;
    105105    /** @} */
     106    QSet<QString> m_userModifiedParameters;
    106107};
    107108
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp

    r90217 r90223  
    120120void UIWizardNewVMPageExpert::sltNameChanged(const QString &strNewName)
    121121{
    122     UIWizardNewVMNameOSTypePage::onNameChanged(m_pNameAndSystemEditor, strNewName);
     122    if (!m_userModifiedParameters.contains("GuestOSType"))
     123        UIWizardNewVMNameOSTypePage::guessOSTypeFromName(m_pNameAndSystemEditor, strNewName);
    123124    UIWizardNewVMNameOSTypePage::composeMachineFilePath(m_pNameAndSystemEditor, qobject_cast<UIWizardNewVM*>(wizard()));
    124125    updateVirtualDiskPathFromMachinePathName();
     
    135136void UIWizardNewVMPageExpert::sltOsTypeChanged()
    136137{
    137     // onOsTypeChanged();
    138     // setOSTypeDependedValues();
    139     // emit completeChanged();
     138    m_userModifiedParameters << "GuestOSType";
     139    if (m_pNameAndSystemEditor)
     140        newVMWizardPropertySet(GuestOSType, m_pNameAndSystemEditor->type());
     141    //setOSTypeDependedValues() ??!!!
    140142}
    141143
     
    216218        connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigNameChanged,
    217219                this, &UIWizardNewVMPageExpert::sltNameChanged);
    218     //     connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigPathChanged,
    219     //             this, &UIWizardNewVMPageExpert::sltPathChanged);
    220     //     connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOsTypeChanged,
    221     //             this, &UIWizardNewVMPageExpert::sltOsTypeChanged);
     220        connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigPathChanged,
     221                this, &UIWizardNewVMPageExpert::sltPathChanged);
     222        connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOsTypeChanged,
     223                this, &UIWizardNewVMPageExpert::sltOsTypeChanged);
    222224    //     connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOSFamilyChanged,
    223225    //             this, &UIWizardNewVMPageExpert::sltOSFamilyTypeChanged);
     
    277279void UIWizardNewVMPageExpert::setOSTypeDependedValues()
    278280{
    279     // if (!field("type").canConvert<CGuestOSType>())
    280     //     return;
    281 
    282     // /* Get recommended 'ram' field value: */
    283     // CGuestOSType type = field("type").value<CGuestOSType>();
    284     // ULONG recommendedRam = type.GetRecommendedRAM();
    285 
    286     // if (m_pBaseMemoryEditor && !m_userSetWidgets.contains(m_pBaseMemoryEditor))
    287     // {
    288     //     m_pBaseMemoryEditor->blockSignals(true);
    289     //     m_pBaseMemoryEditor->setValue(recommendedRam);
    290     //     m_pBaseMemoryEditor->blockSignals(false);
    291     // }
     281    UIWizardNewVM *pWizard = qobject_cast<UIWizardNewVM*>(wizard());
     282    AssertReturnVoid(pWizard);
     283
     284    /* Get recommended 'ram' field value: */
     285    const CGuestOSType &type = pWizard->guestOSType();
     286    ULONG recommendedRam = type.GetRecommendedRAM();
     287
     288    /* Set memory size of the widget and (through signals) wizard: */
     289    if (m_pHardwareWidgetContainer && !m_userModifiedParameters.contains("MemorySize"))
     290        m_pHardwareWidgetContainer->setMemorySize(recommendedRam);
     291
    292292
    293293    // KFirmwareType fwType = type.GetRecommendedFirmware();
     
    342342    AssertReturnVoid(pWizard);
    343343    /* Initialize wizard properties: */
     344    if (m_pNameAndSystemEditor)
     345    {
     346        /* Guest OS type: */
     347        newVMWizardPropertySet(GuestOSFamilyId, m_pNameAndSystemEditor->familyId());
     348        newVMWizardPropertySet(GuestOSType, m_pNameAndSystemEditor->type());
     349        /* Vm name, folder, file path etc. will be initilized by composeMachineFilePath: */
     350    }
     351
     352
    344353    if (m_pFormatButtonGroup)
    345354        newVMWizardPropertySet(MediumFormat, m_pFormatButtonGroup->mediumFormat());
     
    347356
    348357    // disableEnableUnattendedRelatedWidgets(isUnattendedEnabled());
    349     // setOSTypeDependedValues();
     358    setOSTypeDependedValues();
    350359    // disableEnableUnattendedRelatedWidgets(isUnattendedEnabled());
    351360    updateVirtualDiskPathFromMachinePathName();
     361
    352362    // updateWidgetAterMediumFormatChange();
    353363    // setSkipCheckBoxEnable();
     
    669679void UIWizardNewVMPageExpert::updateWidgetAterMediumFormatChange()
    670680{
    671     // CMediumFormat comMediumFormat = mediumFormat();
    672     // if (comMediumFormat.isNull())
    673     // {
    674     //     AssertMsgFailed(("No medium format set!"));
    675     //     return;
    676     // }
    677     // updateMediumVariantWidgetsAfterFormatChange(comMediumFormat);
    678     // updateLocationEditorAfterFormatChange(comMediumFormat, m_formatExtensions);
     681    UIWizardNewVM *pWizard = qobject_cast<UIWizardNewVM*>(wizard());
     682    AssertReturnVoid(pWizard && m_pDiskVariantGroupBox && m_pSizeAndLocationGroup && m_pFormatButtonGroup);
     683    const CMediumFormat &comMediumFormat = pWizard->mediumFormat();
     684    AssertReturnVoid(!comMediumFormat.isNull());
     685    m_pDiskVariantGroupBox->updateMediumVariantWidgetsAfterFormatChange(comMediumFormat);
     686    m_pSizeAndLocationGroup->updateLocationEditorAfterFormatChange(comMediumFormat, m_pFormatButtonGroup->formatExtensions());
    679687}
    680688
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette