VirtualBox

Changeset 74610 in vbox for trunk


Ignore:
Timestamp:
Oct 4, 2018 12:07:36 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9260. Adding import options for keeping MAC addresses

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceImportEditorWidget.cpp

    r73137 r74610  
    2222/* Qt includes: */
    2323# include <QCheckBox>
     24# include <QGridLayout>
    2425# include <QLabel>
    2526# include <QTextEdit>
     
    6263    , m_pPathSelectorLabel(0)
    6364    , m_pPathSelector(0)
    64     , m_pCheckBoxReinitMACs(0)
    6565    , m_pImportHDsAsVDI(0)
    66 
     66    , m_pMACComboBoxLabel(0)
     67    , m_pMACComboBox(0)
     68    , m_pOptionsLayout(0)
    6769{
    6870    prepareWidgets();
     
    8587        m_pLayout->addWidget(m_pPathSelector);
    8688    }
    87     m_pCheckBoxReinitMACs = new QCheckBox;
    88     {
    89         m_pLayout->addWidget(m_pCheckBoxReinitMACs);
    90     }
     89
     90    m_pOptionsLayout = new QGridLayout;
     91
     92    m_pMACComboBox = new QComboBox;
     93    if (m_pMACComboBox)
     94    {
     95        m_pMACComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::QSizePolicy::Preferred);
     96        /* Add into layout: */
     97        m_pOptionsLayout->addWidget(m_pMACComboBox, 0, 1);
     98    }
     99
     100        /* Create format combo-box label: */
     101    m_pMACComboBoxLabel = new QLabel;
     102    if (m_pMACComboBoxLabel)
     103    {
     104        m_pMACComboBoxLabel->setAlignment(Qt::AlignLeft | Qt::AlignTrailing | Qt::AlignVCenter);
     105        /* Add into layout: */
     106        m_pOptionsLayout->addWidget(m_pMACComboBoxLabel, 0, 0);
     107    }
     108
     109    if (m_pMACComboBoxLabel)
     110        m_pMACComboBoxLabel->setBuddy(m_pMACComboBox);
    91111
    92112    m_pImportHDsAsVDI = new QCheckBox;
    93113    {
    94         m_pLayout->addWidget(m_pImportHDsAsVDI);
     114        m_pOptionsLayout->addWidget(m_pImportHDsAsVDI, 2, 1);
    95115        m_pImportHDsAsVDI->setCheckState(Qt::Checked);
    96116    }
    97117
     118
     119    m_pLayout->addLayout(m_pOptionsLayout);
     120    populateMACAddressImportPolicies();
     121    connect(m_pMACComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
     122            this, &UIApplianceImportEditorWidget::sltHandleMACAddressImportPolicyComboChange);
    98123    retranslateUi();
    99124}
     
    197222        CProgress progress;
    198223        QVector<KImportOptions> options;
    199         if (!m_pCheckBoxReinitMACs->isChecked())
    200             options.append(KImportOptions_KeepAllMACs);
     224        if (m_pMACComboBox)
     225        {
     226            MACAddressImportPolicy macPolicy = static_cast<MACAddressImportPolicy>(m_pMACComboBox->currentIndex());
     227            switch (macPolicy)
     228            {
     229                case MACAddressImportPolicy_KeepAllMACs:
     230                    options.append(KImportOptions_KeepAllMACs);
     231                    break;
     232                case MACAddressImportPolicy_KeepNATMACs:
     233                    options.append(KImportOptions_KeepNATMACs);
     234                    break;
     235                default:
     236                    break;
     237            }
     238        }
     239
    201240        if (m_pImportHDsAsVDI->isChecked())
    202241            options.append(KImportOptions_ImportToVDI);
     
    251290        m_pPathSelectorLabel->setText(UIWizardImportApp::tr("You can modify the base folder which will host all the virtual machines.\n"
    252291                                                            "Home folders can also be individually (per virtual machine)  modified."));
    253     if (m_pCheckBoxReinitMACs)
    254     {
    255         m_pCheckBoxReinitMACs->setText(tr("&Reinitialize the MAC address of all network cards"));
    256         m_pCheckBoxReinitMACs->setToolTip(tr("When checked a new unique MAC address will assigned to all configured network cards."));
    257     }
    258 
    259292    if (m_pImportHDsAsVDI)
    260293    {
     
    262295        m_pImportHDsAsVDI->setToolTip(tr("When checked a all the hard drives that belong to this appliance will be imported in VDI format"));
    263296    }
     297
     298    /* Translate MAC address policy combo-box: */
     299    m_pMACComboBoxLabel->setText(tr("MAC Address &Policy:"));
     300    m_pMACComboBox->setItemText(MACAddressImportPolicy_KeepAllMACs,
     301                                tr("Include all network adapter MAC addresses"));
     302    m_pMACComboBox->setItemText(MACAddressImportPolicy_KeepNATMACs,
     303                                tr("Include only NAT network adapter MAC addresses"));
     304    m_pMACComboBox->setItemText(MACAddressImportPolicy_StripAllMACs,
     305                                tr("Generate new MAC addresses for all network adapters"));
     306    m_pMACComboBox->setItemData(MACAddressImportPolicy_KeepAllMACs,
     307                                tr("Include all network adapter MAC addresses in exported "
     308                                                    "during cloning."), Qt::ToolTipRole);
     309    m_pMACComboBox->setItemData(MACAddressImportPolicy_KeepNATMACs,
     310                                tr("Include only NAT network adapter MAC addresses "
     311                                                    "during cloning."), Qt::ToolTipRole);
     312    m_pMACComboBox->setItemData(MACAddressImportPolicy_StripAllMACs,
     313                                tr("Generate new MAC addresses for all network adapters "
     314                                                    "during cloning."), Qt::ToolTipRole);
    264315}
    265316
     
    268319    setVirtualSystemBaseFolder(newPath);
    269320}
     321
     322void UIApplianceImportEditorWidget::populateMACAddressImportPolicies()
     323{
     324    AssertReturnVoid(m_pMACComboBox->count() == 0);
     325
     326    /* Apply hardcoded policies list: */
     327    for (int i = 0; i < (int)MACAddressImportPolicy_MAX; ++i)
     328    {
     329        m_pMACComboBox->addItem(QString::number(i));
     330        m_pMACComboBox->setItemData(i, i);
     331    }
     332
     333    /* Set default: */
     334    setMACAddressImportPolicy(MACAddressImportPolicy_KeepNATMACs);
     335}
     336
     337void UIApplianceImportEditorWidget::setMACAddressImportPolicy(MACAddressImportPolicy enmMACAddressImportPolicy)
     338{
     339    const int iIndex = m_pMACComboBox->findData((int)enmMACAddressImportPolicy);
     340    AssertMsg(iIndex != -1, ("Data not found!"));
     341    m_pMACComboBox->setCurrentIndex(iIndex);
     342}
     343
     344void UIApplianceImportEditorWidget::sltHandleMACAddressImportPolicyComboChange()
     345{
     346    /* Update tool-tip: */
     347    updateMACAddressImportPolicyComboToolTip();
     348}
     349
     350void UIApplianceImportEditorWidget::updateMACAddressImportPolicyComboToolTip()
     351{
     352    const int iCurrentIndex = m_pMACComboBox->currentIndex();
     353    const QString strCurrentToolTip = m_pMACComboBox->itemData(iCurrentIndex, Qt::ToolTipRole).toString();
     354    AssertMsg(!strCurrentToolTip.isEmpty(), ("Data not found!"));
     355    m_pMACComboBox->setToolTip(strCurrentToolTip);
     356}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceImportEditorWidget.h

    r73137 r74610  
    2525class UIFilePathSelector;
    2626class QIRichTextLabel;
     27class QComboBox;
     28class QGridLayout;
     29
     30/** MAC address policies. */
     31enum MACAddressImportPolicy
     32{
     33    MACAddressImportPolicy_KeepAllMACs,
     34    MACAddressImportPolicy_KeepNATMACs,
     35    MACAddressImportPolicy_StripAllMACs,
     36    MACAddressImportPolicy_MAX
     37};
    2738
    2839class UIApplianceImportEditorWidget: public UIApplianceEditorWidget
     
    4556private slots:
    4657
    47     void sltHandlePathChanged(const QString &newPath);
     58    void    sltHandlePathChanged(const QString &newPath);
    4859
    4960private:
    5061
    51     void      prepareWidgets();
     62    void    prepareWidgets();
     63    /** Populates MAC address policies. */
     64    void    populateMACAddressImportPolicies();
     65    void    setMACAddressImportPolicy(MACAddressImportPolicy enmMACAddressImportPolicy);
     66    void    sltHandleMACAddressImportPolicyComboChange();
     67    void    updateMACAddressImportPolicyComboToolTip();
     68
    5269    QIRichTextLabel    *m_pPathSelectorLabel;
    5370    UIFilePathSelector *m_pPathSelector;
    54 
    55     /** Holds the 'reinit MACs' check-box instance. */
    56     QCheckBox *m_pCheckBoxReinitMACs;
    57     /** Holds the checkbox that controls 'imprt HDs as VDI' behaviour. */
    58     QCheckBox *m_pImportHDsAsVDI;
    59 
     71    /** Holds the checkbox that controls 'import HDs as VDI' behaviour. */
     72    QCheckBox          *m_pImportHDsAsVDI;
     73    QLabel             *m_pMACComboBoxLabel;
     74    QComboBox          *m_pMACComboBox;
     75    QGridLayout        *m_pOptionsLayout;
    6076};
    6177
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageExpert.cpp

    r70805 r74610  
    136136    return fResult;
    137137}
    138 
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