VirtualBox

Changeset 87972 in vbox


Ignore:
Timestamp:
Mar 5, 2021 2:55:53 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9950. Initializing medium path widgets in expert mode

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic2.cpp

    r87941 r87972  
    174174}
    175175
     176void UIWizardNewVDPage2::updateMediumVariantWidgetsAfterFormatChange(const CMediumFormat &mediumFormat)
     177{
     178    /* Enable/disable widgets: */
     179    ULONG uCapabilities = 0;
     180    QVector<KMediumFormatCapabilities> capabilities;
     181    capabilities = mediumFormat.GetCapabilities();
     182    for (int i = 0; i < capabilities.size(); i++)
     183        uCapabilities |= capabilities[i];
     184
     185    bool fIsCreateDynamicPossible = uCapabilities & KMediumFormatCapabilities_CreateDynamic;
     186    bool fIsCreateFixedPossible = uCapabilities & KMediumFormatCapabilities_CreateFixed;
     187    bool fIsCreateSplitPossible = uCapabilities & KMediumFormatCapabilities_CreateSplit2G;
     188
     189    if (m_pFixedCheckBox)
     190    {
     191        m_pFixedCheckBox->setEnabled(fIsCreateDynamicPossible || fIsCreateFixedPossible);
     192        if (!fIsCreateDynamicPossible)
     193            m_pFixedCheckBox->setChecked(true);
     194        if (!fIsCreateFixedPossible)
     195            m_pFixedCheckBox->setChecked(false);
     196    }
     197    m_pSplitBox->setEnabled(fIsCreateSplitPossible);
     198}
     199
    176200UIWizardNewVDPageBasic2::UIWizardNewVDPageBasic2()
    177201{
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic2.h

    r87929 r87972  
    4646    /** Check Medium format capability and decide if certain widgets can be shown. */
    4747    void setWidgetVisibility(CMediumFormat &mediumFormat);
     48    void updateMediumVariantWidgetsAfterFormatChange(const CMediumFormat &mediumFormat);
    4849    /** @name Widgets
    4950     * @{ */
    50         QCheckBox    *m_pFixedCheckBox;
     51        QCheckBox *m_pFixedCheckBox;
    5152        QCheckBox *m_pSplitBox;
    5253    /** @} */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.cpp

    r87941 r87972  
    231231}
    232232
     233/* static */
     234QString UIWizardNewVDPage3::stripFormatExtension(const QString &strFileName, const QStringList &formatExtensions)
     235{
     236    QString result(strFileName);
     237    foreach (const QString &strExtension, formatExtensions)
     238    {
     239        if (strFileName.endsWith(strExtension, Qt::CaseInsensitive))
     240        {
     241            /* Add the dot to extenstion: */
     242            QString strExtensionWithDot(strExtension);
     243            strExtensionWithDot.prepend('.');
     244            int iIndex = strFileName.lastIndexOf(strExtensionWithDot, -1, Qt::CaseInsensitive);
     245            result.remove(iIndex, strExtensionWithDot.length());
     246        }
     247    }
     248    return result;
     249}
     250
     251void UIWizardNewVDPage3::updateLocationEditorAfterFormatChange(const CMediumFormat &mediumFormat, const QStringList &formatExtensions)
     252{
     253    /* Compose virtual-disk extension: */
     254    m_strDefaultExtension = defaultExtension(mediumFormat);
     255    /* Update m_pLocationEditor's text if necessary: */
     256    if (!m_pLocationEditor->text().isEmpty() && !m_strDefaultExtension.isEmpty())
     257    {
     258        QFileInfo fileInfo(m_pLocationEditor->text());
     259        if (fileInfo.suffix() != m_strDefaultExtension)
     260        {
     261            QFileInfo newFileInfo(fileInfo.absolutePath(),
     262                                  QString("%1.%2").
     263                                  arg(stripFormatExtension(fileInfo.fileName(), formatExtensions)).
     264                                  arg(m_strDefaultExtension));
     265            m_pLocationEditor->setText(newFileInfo.absoluteFilePath());
     266        }
     267    }
     268}
     269
    233270void UIWizardNewVDPage3::retranslateWidgets()
    234271{
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageBasic3.h

    r87938 r87972  
    5858
    5959    virtual QString mediumPath() const;
     60    /** A utility function thar strips the format extension from the @p strFileName.
     61      * foo.dd.vdi becomes foo.dd. any extension which is not a format extension is left alone. */
     62    static QString stripFormatExtension(const QString &strFileName, const QStringList &formatExtensions);
     63    void updateLocationEditorAfterFormatChange(const CMediumFormat &mediumFormat, const QStringList &formatExtensions);
    6064
    6165    qulonglong mediumSize() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.cpp

    r87946 r87972  
    128128    registerField("mediumPath", this, "mediumPath");
    129129    registerField("mediumSize", this, "mediumSize");
    130 
    131     /* Initialization of m_strDefaultExtension is done  here
    132        since first m_formats should be populated and fields should be registered: */
    133     m_strDefaultExtension = defaultExtension(mediumFormat());
    134     if (m_pLocationEditor)
    135         m_pLocationEditor->setText(absoluteFilePath(m_strDefaultName, m_strDefaultPath, m_strDefaultExtension));
    136130}
    137131
     
    146140    }
    147141
    148     /* Enable/disable widgets: */
    149     ULONG uCapabilities = 0;
    150     QVector<KMediumFormatCapabilities> capabilities;
    151     capabilities = mf.GetCapabilities();
    152     for (int i = 0; i < capabilities.size(); i++)
    153         uCapabilities |= capabilities[i];
    154 
    155     bool fIsCreateDynamicPossible = uCapabilities & KMediumFormatCapabilities_CreateDynamic;
    156     bool fIsCreateFixedPossible = uCapabilities & KMediumFormatCapabilities_CreateFixed;
    157     bool fIsCreateSplitPossible = uCapabilities & KMediumFormatCapabilities_CreateSplit2G;
    158 
    159     if (m_pFixedCheckBox)
    160     {
    161         if (!fIsCreateDynamicPossible)
    162         {
    163             m_pFixedCheckBox->setEnabled(false);
    164             m_pFixedCheckBox->setChecked(true);
    165         }
    166         if (!fIsCreateFixedPossible)
    167         {
    168             m_pFixedCheckBox->setEnabled(false);
    169             m_pFixedCheckBox->setChecked(false);
    170         }
    171     }
    172     m_pSplitBox->setEnabled(fIsCreateSplitPossible);
    173 
    174     /* Compose virtual-disk extension: */
    175     m_strDefaultExtension = defaultExtension(mf);
    176     /* Update m_pLocationEditor's text if necessary: */
    177     if (!m_pLocationEditor->text().isEmpty() && !m_strDefaultExtension.isEmpty())
    178     {
    179         QFileInfo fileInfo(m_pLocationEditor->text());
    180         if (fileInfo.suffix() != m_strDefaultExtension)
    181         {
    182             QFileInfo newFileInfo(fileInfo.absolutePath(),
    183                                   QString("%1.%2").arg(stripFormatExtension(fileInfo.fileName())).arg(m_strDefaultExtension));
    184             m_pLocationEditor->setText(newFileInfo.absoluteFilePath());
    185         }
    186     }
     142    updateMediumVariantWidgetsAfterFormatChange(mf);
     143
     144    updateLocationEditorAfterFormatChange(mf, m_formatExtensions);
    187145
    188146    /* Broadcast complete-change: */
     
    226184void UIWizardNewVDPageExpert::initializePage()
    227185{
     186    /* Get default extension for new virtual-disk: */
     187    m_strDefaultExtension = defaultExtension(field("mediumFormat").value<CMediumFormat>());
     188    /* Set default name as text for location editor: */
     189    if (m_pLocationEditor)
     190        m_pLocationEditor->setText(absoluteFilePath(m_strDefaultName, m_strDefaultPath, m_strDefaultExtension));
     191
     192
    228193    /* Translate page: */
    229194    retranslateUi();
     
    274239    return fResult;
    275240}
    276 
    277 QString UIWizardNewVDPageExpert::stripFormatExtension(const QString &strFileName)
    278 {
    279     QString result(strFileName);
    280     foreach (const QString &strExtension, m_formatExtensions)
    281     {
    282         if (strFileName.endsWith(strExtension, Qt::CaseInsensitive))
    283         {
    284             /* Add the dot to extenstion: */
    285             QString strExtensionWithDot(strExtension);
    286             strExtensionWithDot.prepend('.');
    287             int iIndex = strFileName.lastIndexOf(strExtensionWithDot, -1, Qt::CaseInsensitive);
    288             result.remove(iIndex, strExtensionWithDot.length());
    289         }
    290     }
    291     return result;
    292 }
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageExpert.h

    r87850 r87972  
    7373    bool isComplete() const;
    7474    bool validatePage();
    75     /** Strips the format extension from the @p strFileName. foo.dd.vdi becomes foo.dd. any extension which is not
    76       * a format extension is left alone. */
    77     QString stripFormatExtension(const QString &strFileName);
    7875
    7976    /* Widgets: */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp

    r87958 r87972  
    4444#include "UIWizardNewVMPageExpert.h"
    4545
     46/* COM includes: */
     47#include "CSystemProperties.h"
    4648
    4749UIWizardNewVMPageExpert::UIWizardNewVMPageExpert(const QString &strGroup)
     
    9395    registerField("EFIEnabled", this, "EFIEnabled");
    9496
     97    registerField("mediumPath", this, "mediumPath");
     98    registerField("mediumFormat", this, "mediumFormat");
     99
    95100    disableEnableUnattendedRelatedWidgets(isUnattendedEnabled());
    96101}
     
    102107
    103108    composeMachineFilePath();
     109    updateVirtualDiskPathFromMachinePathName();
    104110    /* Broadcast complete-change: */
    105111    emit completeChanged();
     
    110116    Q_UNUSED(strNewPath);
    111117    composeMachineFilePath();
     118    updateVirtualDiskPathFromMachinePathName();
    112119}
    113120
     
    330337    setOSTypeDependedValues();
    331338    disableEnableUnattendedRelatedWidgets(isUnattendedEnabled());
     339    updateVirtualDiskPathFromMachinePathName();
    332340}
    333341
     
    398406
    399407    /* Disk file size widgets: */
    400     QLabel *pSizeEditorLabel = new QLabel("Disk Size:");
    401     pSizeEditorLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
     408    m_pSizeEditorLabel = new QLabel;
     409    m_pSizeEditorLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    402410    m_pSizeEditor = new UIMediumSizeEditor;
    403     pSizeEditorLabel->setBuddy(m_pSizeEditor);
     411    m_pSizeEditorLabel->setBuddy(m_pSizeEditor);
    404412
    405413    /* Disk file format widgets: */
     
    418426    pDiskContainerLayout->addWidget(m_pLocationOpenButton, 0, 3, 1, 1);
    419427
    420     pDiskContainerLayout->addWidget(pSizeEditorLabel, 1, 0, 1, 1);
     428    pDiskContainerLayout->addWidget(m_pSizeEditorLabel, 1, 0, 1, 1);
    421429    pDiskContainerLayout->addWidget(m_pSizeEditor, 1, 1, 1, 3);
    422430
     
    548556    m_userSetWidgets << pSenderWidget;
    549557}
     558
     559void UIWizardNewVMPageExpert::updateVirtualDiskPathFromMachinePathName()
     560{
     561    QString strDiskFileName = machineBaseName().isEmpty() ? QString("NewVirtualDisk1") : machineBaseName();
     562    QString strDiskPath = machineFolder();
     563    if (strDiskPath.isEmpty())
     564    {
     565        if (m_pNameAndSystemEditor)
     566            strDiskPath = m_pNameAndSystemEditor->path();
     567        else
     568            strDiskPath = uiCommon().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
     569    }
     570    QString strExtension = defaultExtension(mediumFormat());
     571    if (m_pLocationEditor)
     572        m_pLocationEditor->setText(absoluteFilePath(strDiskFileName, strDiskPath, strExtension));
     573}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.h

    r87958 r87972  
    6767    Q_PROPERTY(bool EFIEnabled READ EFIEnabled);
    6868
     69
     70    // Q_PROPERTY(CMedium virtualDisk READ virtualDisk WRITE setVirtualDisk);
     71    // Q_PROPERTY(SelectedDiskSource selectedDiskSource READ selectedDiskSource WRITE setSelectedDiskSource);
     72    Q_PROPERTY(CMediumFormat mediumFormat READ mediumFormat);
     73    // Q_PROPERTY(qulonglong mediumVariant READ mediumVariant WRITE setMediumVariant);
     74    Q_PROPERTY(QString mediumPath READ mediumPath);
     75    // Q_PROPERTY(qulonglong mediumSize READ mediumSize WRITE setMediumSize);
     76
    6977public:
    7078
     
    128136    QWidget *createUnattendedWidgets();
    129137    virtual QWidget *createNewDiskWidgets() /* override */;
     138    void updateVirtualDiskPathFromMachinePathName();
    130139
    131140    UIToolBox  *m_pToolBox;
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