VirtualBox

Changeset 74550 in vbox for trunk/src


Ignore:
Timestamp:
Oct 1, 2018 12:57:05 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: ​bugref: 9260: Extend the clone vm wizard to include additional options related to MAC addresses

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVM.cpp

    r72696 r74550  
    5959    QString strSettingsFile = field("cloneFilePath").toString();
    6060
    61     /* Should we reinit mac status? */
    62     bool fReinitMACs = field("reinitMACs").toBool();
    6361    /* Should we create linked clone? */
    6462    bool fLinked = field("linkedClone").toBool();
     
    131129    }
    132130
    133     /* Add the keep all MACs option to the import settings when requested. */
     131    /* Set the selected MAC address policy: */
    134132    QVector<KCloneOptions> options;
    135     if (!fReinitMACs)
    136         options.append(KCloneOptions_KeepAllMACs);
     133    switch (field("macAddressClonePolicy").value<MACAddressClonePolicy>())
     134    {
     135        case MACAddressClonePolicy_KeepAllMACs:
     136            options.append(KCloneOptions_KeepAllMACs);
     137            break;
     138        case MACAddressClonePolicy_KeepNATMACs:
     139            options.append(KCloneOptions_KeepNATMACs);
     140            break;
     141        default:
     142            break;
     143    }
     144
    137145    /* Linked clones requested? */
    138146    if (fLinked)
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageBasic1.cpp

    r74519 r74550  
    2222/* Qt includes: */
    2323# include <QCheckBox>
     24# include <QComboBox>
     25# include <QGridLayout>
    2426# include <QLabel>
    2527# include <QVBoxLayout>
     
    4345    , m_strDefaultPath(strDefaultPath)
    4446    , m_strGroup(strGroup)
    45     , m_pReinitMACsCheckBox(0)
    4647    , m_pNameLineEdit(0)
    4748    , m_pPathSelector(0)
    4849    , m_pNameLabel(0)
    4950    , m_pPathLabel(0)
     51    , m_pMACComboBoxLabel(0)
     52    , m_pMACComboBox(0)
    5053{
    5154}
     
    8891        return;
    8992    m_strCloneFilePath = path;
    90 }
    91 
    92 
    93 bool UIWizardCloneVMPage1::isReinitMACsChecked() const
    94 {
    95     if (!m_pReinitMACsCheckBox)
    96         return false;
    97     return m_pReinitMACsCheckBox->isChecked();
    9893}
    9994
     
    109104}
    110105
     106void UIWizardCloneVMPage1::updateMACAddressClonePolicyComboToolTip()
     107{
     108    const int iCurrentIndex = m_pMACComboBox->currentIndex();
     109    const QString strCurrentToolTip = m_pMACComboBox->itemData(iCurrentIndex, Qt::ToolTipRole).toString();
     110    AssertMsg(!strCurrentToolTip.isEmpty(), ("Data not found!"));
     111    m_pMACComboBox->setToolTip(strCurrentToolTip);
     112}
     113
     114MACAddressClonePolicy UIWizardCloneVMPage1::macAddressClonePolicy() const
     115{
     116    const int iIndex = m_pMACComboBox->currentIndex();
     117    return (MACAddressClonePolicy)m_pMACComboBox->itemData(iIndex).toInt();
     118}
     119
     120void UIWizardCloneVMPage1::setMACAddressClonePolicy(MACAddressClonePolicy enmMACAddressClonePolicy)
     121{
     122    const int iIndex = m_pMACComboBox->findData((int)enmMACAddressClonePolicy);
     123    AssertMsg(iIndex != -1, ("Data not found!"));
     124    m_pMACComboBox->setCurrentIndex(iIndex);
     125}
     126
     127void UIWizardCloneVMPage1::populateMACAddressClonePolicies()
     128{
     129    AssertReturnVoid(m_pMACComboBox->count() == 0);
     130
     131    /* Apply hardcoded policies list: */
     132    for (int i = 0; i < (int)MACAddressClonePolicy_MAX; ++i)
     133    {
     134        m_pMACComboBox->addItem(QString::number(i));
     135        m_pMACComboBox->setItemData(i, i);
     136    }
     137
     138    /* Set default: */
     139    setMACAddressClonePolicy(MACAddressClonePolicy_KeepNATMACs);
     140}
     141
    111142UIWizardCloneVMPageBasic1::UIWizardCloneVMPageBasic1(const QString &strOriginalName, const QString &strDefaultPath, const QString &strGroup)
    112143    : UIWizardCloneVMPage1(strOriginalName, strDefaultPath, strGroup)
    113144    , m_pMainLabel(0)
     145    , m_pContainerLayout(0)
    114146{
    115147    /* Create widgets: */
     
    128160    {
    129161        pMainLayout->addWidget(pContainerWidget);
    130         QGridLayout *pContainerLayout = new QGridLayout(pContainerWidget);
    131         pContainerLayout->setContentsMargins(0, 0, 0, 0);
     162        m_pContainerLayout = new QGridLayout(pContainerWidget);
     163        m_pContainerLayout->setContentsMargins(0, 0, 0, 0);
    132164
    133165        m_pNameLabel = new QLabel;
     
    136168            m_pNameLabel->setAlignment(Qt::AlignRight);
    137169            m_pNameLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    138             pContainerLayout->addWidget(m_pNameLabel, 0, 0, 1, 1);
     170            m_pContainerLayout->addWidget(m_pNameLabel, 0, 0, 1, 1);
    139171        }
    140172
     
    142174        if (m_pNameLineEdit)
    143175        {
    144             pContainerLayout->addWidget(m_pNameLineEdit, 0, 1, 1, 1);
     176            m_pContainerLayout->addWidget(m_pNameLineEdit, 0, 1, 1, 1);
    145177            m_pNameLineEdit->setText(UIWizardCloneVM::tr("%1 Clone").arg(m_strOriginalName));
    146178        }
     
    151183            m_pPathLabel->setAlignment(Qt::AlignRight);
    152184            m_pPathLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    153             pContainerLayout->addWidget(m_pPathLabel, 1, 0, 1, 1);
     185            m_pContainerLayout->addWidget(m_pPathLabel, 1, 0, 1, 1);
    154186        }
    155187
     
    157189        if (m_pPathSelector)
    158190        {
    159             pContainerLayout->addWidget(m_pPathSelector, 1, 1, 1, 1);
     191            m_pContainerLayout->addWidget(m_pPathSelector, 1, 1, 1, 1);
    160192            m_pPathSelector->setPath(m_strDefaultPath);
    161 
    162         }
    163 
    164          m_pReinitMACsCheckBox = new QCheckBox(this);
    165          if (m_pReinitMACsCheckBox)
    166          {
    167              pContainerLayout->addWidget(m_pReinitMACsCheckBox, 2, 0, 1, 2);
    168              m_pReinitMACsCheckBox->setChecked(true);
    169          }
     193        }
     194
     195        /* Create MAC policy combo-box: */
     196        m_pMACComboBox = new QComboBox;
     197        if (m_pMACComboBox)
     198        {
     199            /* Add into layout: */
     200            m_pContainerLayout->addWidget(m_pMACComboBox, 2, 1, 1, 1);
     201        }
     202
     203        /* Create format combo-box label: */
     204        m_pMACComboBoxLabel = new QLabel;
     205        if (m_pMACComboBoxLabel)
     206        {
     207            m_pMACComboBoxLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
     208            m_pMACComboBoxLabel->setBuddy(m_pMACComboBox);
     209            /* Add into layout: */
     210            m_pContainerLayout->addWidget(m_pMACComboBoxLabel, 2, 0, 1, 1);
     211        }
    170212    }
    171213    pMainLayout->addStretch();
     214
     215    /* Populate MAC address policies: */
     216    populateMACAddressClonePolicies();
     217
     218    /* Register fields: */
     219    registerField("cloneName", this, "cloneName");
     220    registerField("cloneFilePath", this, "cloneFilePath");
     221    registerField("macAddressClonePolicy", this, "macAddressClonePolicy");
     222
     223    composeCloneFilePath();
    172224
    173225    /* Setup connections: */
     
    177229    connect(m_pNameLineEdit, &QILineEdit::textChanged, this, &UIWizardCloneVMPageBasic1::sltNameChanged);
    178230    connect(m_pPathSelector, &UIFilePathSelector::pathChanged, this, &UIWizardCloneVMPageBasic1::sltPathChanged);
    179 
    180     /* Register fields: */
    181     registerField("cloneName", this, "cloneName");
    182     registerField("cloneFilePath", this, "cloneFilePath");
    183     registerField("reinitMACs", this, "reinitMACs");
    184     composeCloneFilePath();
     231    connect(m_pMACComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
     232            this, &UIWizardCloneVMPageBasic1::sltHandleMACAddressClonePolicyComboChange);
    185233}
    186234
     
    201249    if (m_pPathLabel)
    202250        m_pPathLabel->setText(UIWizardCloneVM::tr("Path:"));
    203     if (m_pReinitMACsCheckBox)
    204     {
    205         m_pReinitMACsCheckBox->setToolTip(UIWizardCloneVM::tr("When checked a new unique MAC address will be assigned to all configured network cards."));
    206         m_pReinitMACsCheckBox->setText(UIWizardCloneVM::tr("&Reinitialize the MAC address of all network cards"));
    207     }
     251
     252    /* Translate MAC address policy combo-box: */
     253    m_pMACComboBoxLabel->setText(UIWizardCloneVM::tr("MAC Address &Policy:"));
     254    m_pMACComboBox->setItemText(MACAddressClonePolicy_KeepAllMACs,
     255                                UIWizardCloneVM::tr("Include all network adapter MAC addresses"));
     256    m_pMACComboBox->setItemText(MACAddressClonePolicy_KeepNATMACs,
     257                                UIWizardCloneVM::tr("Include only NAT network adapter MAC addresses"));
     258    m_pMACComboBox->setItemText(MACAddressClonePolicy_StripAllMACs,
     259                                UIWizardCloneVM::tr("Generate new MAC addresses for all network adapters"));
     260    m_pMACComboBox->setItemData(MACAddressClonePolicy_KeepAllMACs,
     261                                UIWizardCloneVM::tr("Include all network adapter MAC addresses in exported "
     262                                                      "during cloning."), Qt::ToolTipRole);
     263    m_pMACComboBox->setItemData(MACAddressClonePolicy_KeepNATMACs,
     264                                UIWizardCloneVM::tr("Include only NAT network adapter MAC addresses "
     265                                                      "during cloning."), Qt::ToolTipRole);
     266    m_pMACComboBox->setItemData(MACAddressClonePolicy_StripAllMACs,
     267                                UIWizardCloneVM::tr("Generate new MAC addresses for all network adapters "
     268                                                      "during cloning."), Qt::ToolTipRole);
     269
     270    /* Adjust label widths: */
     271    QList<QWidget*> labels;
     272    labels << m_pMACComboBoxLabel;
     273    labels <<m_pNameLabel;
     274    labels << m_pPathLabel;
     275
     276    int iMaxWidth = 0;
     277    foreach (QWidget *pLabel, labels)
     278        iMaxWidth = qMax(iMaxWidth, pLabel->minimumSizeHint().width());
     279    m_pContainerLayout->setColumnMinimumWidth(0, iMaxWidth);
    208280}
    209281
     
    238310    composeCloneFilePath();
    239311}
     312
     313void UIWizardCloneVMPageBasic1::sltHandleMACAddressClonePolicyComboChange()
     314{
     315    /* Update tool-tip: */
     316    updateMACAddressClonePolicyComboToolTip();
     317}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageBasic1.h

    r72288 r74550  
    2525class QILineEdit;
    2626class QCheckBox;
     27class QComboBox;
     28class QGridLayout;
    2729class QLabel;
    2830class QIRichTextLabel;
    2931class UIFilePathSelector;
     32
     33/** MAC address policies. */
     34enum MACAddressClonePolicy
     35{
     36    MACAddressClonePolicy_KeepAllMACs,
     37    MACAddressClonePolicy_KeepNATMACs,
     38    MACAddressClonePolicy_StripAllMACs,
     39    MACAddressClonePolicy_MAX
     40};
     41Q_DECLARE_METATYPE(MACAddressClonePolicy);
    3042
    3143/* 1st page of the Clone Virtual Machine wizard (base part): */
     
    4557    void setCloneFilePath(const QString &path);
    4658
    47     bool isReinitMACsChecked() const;
    4859    /** calls CVirtualBox::ComposeMachineFilename(...) and sets related member variables */
    4960    void composeCloneFilePath();
     61    /** Populates MAC address policies. */
     62    void populateMACAddressClonePolicies();
    5063
    51     QString     m_strOriginalName;
    52     QString     m_strDefaultPath;
    53     QString     m_strGroup;
     64    /** Updates MAC address policy combo tool-tips. */
     65    void updateMACAddressClonePolicyComboToolTip();
     66    /** Returns MAC address clone policy. */
     67    MACAddressClonePolicy macAddressClonePolicy() const;
     68    /** Defines @a enmMACAddressClonePolicy. */
     69    void setMACAddressClonePolicy(MACAddressClonePolicy enmMACAddressClonePolicy);
     70
     71    QString      m_strOriginalName;
     72    QString      m_strDefaultPath;
     73    QString      m_strGroup;
    5474    /** Full, non-native path of the clone machines setting file. Generated by CVirtualBox::ComposeMachineFilename(...) */
    55     QString     m_strCloneFilePath;
     75    QString      m_strCloneFilePath;
    5676    /** The full path of the folder where clone machine's settings file is located.
    5777     * Generated from the m_strCloneFilePath by removing base file name */
    58     QString     m_strCloneFolder;
    59     QCheckBox  *m_pReinitMACsCheckBox;
    60     QILineEdit *m_pNameLineEdit;
     78    QString      m_strCloneFolder;
     79    QILineEdit  *m_pNameLineEdit;
    6180    UIFilePathSelector *m_pPathSelector;
    62     QLabel     *m_pNameLabel;
    63     QLabel     *m_pPathLabel;
    64 
     81    QLabel      *m_pNameLabel;
     82    QLabel      *m_pPathLabel;
     83    QLabel      *m_pMACComboBoxLabel;
     84    QComboBox   *m_pMACComboBox;
    6585};
    6686
     
    7191    Q_PROPERTY(QString cloneName READ cloneName WRITE setCloneName);
    7292    Q_PROPERTY(QString cloneFilePath READ cloneFilePath WRITE setCloneFilePath);
    73     Q_PROPERTY(bool reinitMACs READ isReinitMACsChecked);
     93    Q_PROPERTY(MACAddressClonePolicy macAddressClonePolicy READ macAddressClonePolicy WRITE setMACAddressClonePolicy);
    7494
    7595public:
     
    81101    void sltNameChanged();
    82102    void sltPathChanged();
     103    /** Handles change in MAC address policy combo-box. */
     104    void sltHandleMACAddressClonePolicyComboChange();
    83105
    84106private:
     
    91113
    92114    QIRichTextLabel *m_pMainLabel;
     115    QGridLayout     *m_pContainerLayout;
    93116};
    94117
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageExpert.cpp

    r74519 r74550  
    120120            }
    121121        }
    122         m_pReinitMACsCheckBox = new QCheckBox(this);
    123         m_pReinitMACsCheckBox->setChecked(true);
     122        m_pCloneOptionsCnt = new QGroupBox(this);
     123        if (m_pCloneOptionsCnt)
     124        {
     125            m_pCloneOptionsLayout = new QGridLayout(m_pCloneOptionsCnt);
     126            //m_pCloneOptionsLayout->setContentsMargins(0, 0, 0, 0);
     127            /* Create MAC policy combo-box: */
     128            m_pMACComboBox = new QComboBox;
     129            if (m_pMACComboBox)
     130            {
     131                /* Add into layout: */
     132                m_pCloneOptionsLayout->addWidget(m_pMACComboBox, 0, 1, 1, 1);
     133            }
     134
     135            /* Create format combo-box label: */
     136            m_pMACComboBoxLabel = new QLabel;
     137            if (m_pMACComboBoxLabel)
     138            {
     139                m_pMACComboBoxLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
     140                m_pMACComboBoxLabel->setBuddy(m_pMACComboBox);
     141                /* Add into layout: */
     142                m_pCloneOptionsLayout->addWidget(m_pMACComboBoxLabel, 0, 0, 1, 1);
     143            }
     144        }
     145
    124146        pMainLayout->addWidget(m_pNameCnt, 0, 0, 1, 2);
    125147        pMainLayout->addWidget(m_pCloneTypeCnt, 1, 0, Qt::AlignTop);
    126148        pMainLayout->addWidget(m_pCloneModeCnt, 1, 1, Qt::AlignTop);
    127         pMainLayout->addWidget(m_pReinitMACsCheckBox, 2, 0, 1, 2);
     149        pMainLayout->addWidget(m_pCloneOptionsCnt, 2, 0, 1, 2, Qt::AlignTop);
    128150        pMainLayout->setRowStretch(3, 1);
    129151    }
     
    143165    /* Register classes: */
    144166    qRegisterMetaType<KCloneMode>();
     167
     168    /* Populate MAC address policies: */
     169    populateMACAddressClonePolicies();
     170
    145171    /* Register fields: */
    146172    registerField("cloneName", this, "cloneName");
    147173    registerField("cloneFilePath", this, "cloneFilePath");
    148     registerField("reinitMACs", this, "reinitMACs");
    149174    registerField("linkedClone", this, "linkedClone");
    150175    registerField("cloneMode", this, "cloneMode");
     176    registerField("macAddressClonePolicy", this, "macAddressClonePolicy");
    151177    composeCloneFilePath();
    152178}
     
    176202    m_pMachineAndChildsRadio->setText(UIWizardCloneVM::tr("Current &snapshot tree branch"));
    177203    m_pAllRadio->setText(UIWizardCloneVM::tr("&Everything"));
    178     m_pReinitMACsCheckBox->setToolTip(UIWizardCloneVM::tr("When checked a new unique MAC address will be assigned to all configured network cards."));
    179     m_pReinitMACsCheckBox->setText(UIWizardCloneVM::tr("&Reinitialize the MAC address of all network cards"));
    180204    m_pNameLabel->setText(UIWizardCloneVM::tr("Name:"));
    181205    m_pPathLabel->setText(UIWizardCloneVM::tr("Path:"));
     206
     207    m_pCloneOptionsCnt->setTitle(UIWizardCloneVM::tr("Additional &options"));
     208
     209    /* Translate MAC address policy combo-box: */
     210    m_pMACComboBoxLabel->setText(UIWizardCloneVM::tr("MAC Address &Policy:"));
     211    m_pMACComboBox->setItemText(MACAddressClonePolicy_KeepAllMACs,
     212                                UIWizardCloneVM::tr("Include all network adapter MAC addresses"));
     213    m_pMACComboBox->setItemText(MACAddressClonePolicy_KeepNATMACs,
     214                                UIWizardCloneVM::tr("Include only NAT network adapter MAC addresses"));
     215    m_pMACComboBox->setItemText(MACAddressClonePolicy_StripAllMACs,
     216                                UIWizardCloneVM::tr("Generate new MAC addresses for all network adapters"));
     217    m_pMACComboBox->setItemData(MACAddressClonePolicy_KeepAllMACs,
     218                                UIWizardCloneVM::tr("Include all network adapter MAC addresses in exported "
     219                                                      "during cloning."), Qt::ToolTipRole);
     220    m_pMACComboBox->setItemData(MACAddressClonePolicy_KeepNATMACs,
     221                                UIWizardCloneVM::tr("Include only NAT network adapter MAC addresses "
     222                                                      "during cloning."), Qt::ToolTipRole);
     223    m_pMACComboBox->setItemData(MACAddressClonePolicy_StripAllMACs,
     224                                UIWizardCloneVM::tr("Generate new MAC addresses for all network adapters "
     225                                                      "during cloning."), Qt::ToolTipRole);
     226
     227    /* Adjust label widths: */
     228    QList<QWidget*> labels;
     229    labels << m_pMACComboBoxLabel;
     230
     231    int iMaxWidth = 0;
     232    foreach (QWidget *pLabel, labels)
     233        iMaxWidth = qMax(iMaxWidth, pLabel->minimumSizeHint().width());
     234    m_pCloneOptionsLayout->setColumnMinimumWidth(0, iMaxWidth);
    182235}
    183236
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageExpert.h

    r72554 r74550  
    3636    Q_PROPERTY(QString cloneName READ cloneName WRITE setCloneName);
    3737    Q_PROPERTY(QString cloneFilePath READ cloneFilePath WRITE setCloneFilePath);
    38     Q_PROPERTY(bool reinitMACs READ isReinitMACsChecked);
    3938    Q_PROPERTY(bool linkedClone READ isLinkedClone);
    4039    Q_PROPERTY(KCloneMode cloneMode READ cloneMode WRITE setCloneMode);
     40    Q_PROPERTY(MACAddressClonePolicy macAddressClonePolicy READ macAddressClonePolicy WRITE setMACAddressClonePolicy);
    4141
    4242public:
     
    6666
    6767    /* Widgets: */
    68     QGroupBox *m_pNameCnt;
    69     QGroupBox *m_pCloneTypeCnt;
    70     QGroupBox *m_pCloneModeCnt;
     68    QGroupBox   *m_pNameCnt;
     69    QGroupBox   *m_pCloneTypeCnt;
     70    QGroupBox   *m_pCloneModeCnt;
     71    QGroupBox   *m_pCloneOptionsCnt;
     72    QGridLayout *m_pCloneOptionsLayout;
    7173};
    7274
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