VirtualBox

Changeset 90151 in vbox


Ignore:
Timestamp:
Jul 12, 2021 7:21:04 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9996: Validating hostname and domain name.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
8 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r90003 r90151  
    651651        src/wizards/addcloudvm/UIWizardAddCloudVMPageBasic1.h \
    652652        src/wizards/addcloudvm/UIWizardAddCloudVMPageExpert.h \
     653        src/wizards/editors/UIHostNameDomainEditor.h \
    653654        src/wizards/newcloudvm/UIWizardNewCloudVM.h \
    654655        src/wizards/newcloudvm/UIWizardNewCloudVMPageBasic1.h \
     
    11481149        src/wizards/addcloudvm/UIWizardAddCloudVMPageBasic1.cpp \
    11491150        src/wizards/addcloudvm/UIWizardAddCloudVMPageExpert.cpp \
     1151        src/wizards/editors/UIHostNameDomainEditor.cpp \
    11501152        src/wizards/newcloudvm/UIWizardNewCloudVM.cpp \
    11511153        src/wizards/newcloudvm/UIWizardNewCloudVMPageBasic1.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r90132 r90151  
    984984        unattendedInstallData.m_strUserName = comUnattendedInstaller.GetUser();
    985985        unattendedInstallData.m_strPassword = comUnattendedInstaller.GetPassword();
    986         unattendedInstallData.m_strHostname = comUnattendedInstaller.GetHostname();
    987986        unattendedInstallData.m_fInstallGuestAdditions = comUnattendedInstaller.GetInstallGuestAdditions();
    988987        unattendedInstallData.m_strGuestAdditionsISOPath = comUnattendedInstaller.GetAdditionsIsoPath();
     
    26562655    comUnattendedInstaller.SetPassword(unattendedData.m_strPassword);
    26572656    checkUnattendedInstallError(comUnattendedInstaller);
    2658     comUnattendedInstaller.SetHostname(unattendedData.m_strHostname);
     2657    comUnattendedInstaller.SetHostname(unattendedData.m_strHostnameDomain);
    26592658    checkUnattendedInstallError(comUnattendedInstaller);
    26602659    comUnattendedInstaller.SetProductKey(unattendedData.m_strProductKey);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.cpp

    r90124 r90151  
    381381            this, &UIUserNamePasswordEditor::sltUserNameChanged);
    382382
    383     /* Cache the original back color of the line edit to restore it correctly: */
    384     if (m_pUserNameLineEdit)
    385         m_orginalLineEditBaseColor = m_pUserNameLineEdit->palette().color(QPalette::Base);
    386 
    387383    retranslateUi();
    388384}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.h

    r90039 r90151  
    8888    QLabel *m_pPasswordLabel;
    8989    QLabel *m_pPasswordRepeatLabel;
    90     QColor m_orginalLineEditBaseColor;
    9190
    9291    bool m_fShowPlaceholderText;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIHostNameDomainEditor.cpp

    r90124 r90151  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIUserNamePasswordEditor class implementation.
     3 * VBox Qt GUI - UIHostNameDomainEditor class implementation.
    44 */
    55
     
    2020#include <QLabel>
    2121#include <QLineEdit>
     22#include <QRegularExpressionValidator>
    2223#include <QStyle>
    2324#include <QVBoxLayout>
     
    2930#include "UICommon.h"
    3031#include "UIIconPool.h"
    31 #include "UIUserNamePasswordEditor.h"
     32#include "UIHostNameDomainEditor.h"
    3233#include "UIWizardNewVM.h"
    3334
    34 /*********************************************************************************************************************************
    35 *   UIPasswordLineEdit definition.                                                                                        *
    36 *********************************************************************************************************************************/
    37 
    38 class UIPasswordLineEdit : public QLineEdit
    39 {
    40     Q_OBJECT;
    41 
    42 signals:
    43 
    44     void sigTextVisibilityToggled(bool fTextVisible);
    45 
    46 public:
    47 
    48     UIPasswordLineEdit(QWidget *pParent = 0);
    49     void toggleTextVisibility(bool fTextVisible);
    50     void mark(bool fError, const QString &strErrorToolTip);
    51 
    52 protected:
    53 
    54     virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
    55     virtual void paintEvent(QPaintEvent *pPaintEvent) /* override */;
    56 
    57 private slots:
    58 
    59     void sltHandleTextVisibilityChange();
    60 
    61 private:
    62 
    63     void prepare();
    64     void adjustTextVisibilityButtonGeometry();
    65 
    66     QIToolButton *m_pTextVisibilityButton;
    67     QIcon m_markIcon;
    68     QLabel *m_pErrorIconLabel;
    69     QString m_strErrorToolTip;
    70     /** When true the line edit is marked with some icon to indicate some error. */
    71     bool m_fMarkForError;
    72 };
    7335
    7436
    75 /*********************************************************************************************************************************
    76 *   UIPasswordLineEdit implementation.                                                                                           *
    77 *********************************************************************************************************************************/
    78 
    79 UIPasswordLineEdit::UIPasswordLineEdit(QWidget *pParent /*= 0 */)
    80     : QLineEdit(pParent)
    81     , m_pTextVisibilityButton(0)
    82     , m_pErrorIconLabel(0)
    83     , m_fMarkForError(false)
     37UIHostNameDomainEditor::UIHostNameDomainEditor(QWidget *pParent /*  = 0 */)
     38    : QIWithRetranslateUI<QWidget>(pParent)
     39    , m_pHostnameLineEdit(0)
     40    , m_pDomainLineEdit(0)
     41    , m_pHostnameLabel(0)
     42    , m_pDomainLabel(0)
    8443{
    8544    prepare();
    8645}
    8746
    88 void UIPasswordLineEdit::toggleTextVisibility(bool fTextVisible)
     47QString UIHostNameDomainEditor::hostname() const
    8948{
    90     AssertPtrReturnVoid(m_pTextVisibilityButton);
    91 
    92     if (fTextVisible)
    93     {
    94         setEchoMode(QLineEdit::Normal);
    95         if (m_pTextVisibilityButton)
    96             m_pTextVisibilityButton->setIcon(UIIconPool::iconSet(":/eye_closed_10px.png"));
    97     }
    98     else
    99     {
    100         setEchoMode(QLineEdit::Password);
    101         if (m_pTextVisibilityButton)
    102             m_pTextVisibilityButton->setIcon(UIIconPool::iconSet(":/eye_10px.png"));
    103     }
    104 }
    105 
    106 void UIPasswordLineEdit::mark(bool fError, const QString &strErrorToolTip)
    107 {
    108     if (m_fMarkForError == fError &&  m_strErrorToolTip == strErrorToolTip)
    109         return;
    110     m_fMarkForError = fError;
    111     m_strErrorToolTip = strErrorToolTip;
    112     update();
    113 }
    114 
    115 void UIPasswordLineEdit::prepare()
    116 {
    117     m_markIcon = UIIconPool::iconSet(":/status_error_16px.png");
    118     /* Prepare text visibility button: */
    119     m_pTextVisibilityButton = new QIToolButton(this);
    120     if (m_pTextVisibilityButton)
    121     {
    122         m_pTextVisibilityButton->setIconSize(QSize(10, 10));
    123         m_pTextVisibilityButton->setFocusPolicy(Qt::ClickFocus);
    124         m_pTextVisibilityButton->setCursor(Qt::ArrowCursor);
    125         m_pTextVisibilityButton->show();
    126         connect(m_pTextVisibilityButton, &QToolButton::clicked, this, &UIPasswordLineEdit::sltHandleTextVisibilityChange);
    127     }
    128     m_pErrorIconLabel = new QLabel(this);
    129     toggleTextVisibility(false);
    130     adjustTextVisibilityButtonGeometry();
    131 }
    132 
    133 void UIPasswordLineEdit::adjustTextVisibilityButtonGeometry()
    134 {
    135     AssertPtrReturnVoid(m_pTextVisibilityButton);
    136 
    137 #ifdef VBOX_WS_MAC
    138     /* Do not forget to update QIToolButton size on macOS, it's FIXED: */
    139     m_pTextVisibilityButton->setFixedSize(m_pTextVisibilityButton->minimumSizeHint());
    140     /* Calculate suitable position for a QIToolButton, it's FRAMELESS: */
    141     const int iWidth = m_pTextVisibilityButton->width();
    142     const int iMinHeight = qMin(height(), m_pTextVisibilityButton->height());
    143     const int iMaxHeight = qMax(height(), m_pTextVisibilityButton->height());
    144     const int iHalfHeightDiff = (iMaxHeight - iMinHeight) / 2;
    145     m_pTextVisibilityButton->setGeometry(width() - iWidth - iHalfHeightDiff, iHalfHeightDiff, iWidth, iWidth);
    146 #else
    147     int iFrameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    148     int iSize = height() - 2 * iFrameWidth;
    149     m_pTextVisibilityButton->setGeometry(width() - iSize, iFrameWidth, iSize, iSize);
    150 #endif
    151 }
    152 
    153 void UIPasswordLineEdit::resizeEvent(QResizeEvent *pEvent)
    154 {
    155     /* Call to base-class: */
    156     QLineEdit::resizeEvent(pEvent);
    157     adjustTextVisibilityButtonGeometry();
    158 }
    159 
    160 void UIPasswordLineEdit::paintEvent(QPaintEvent *pPaintEvent)
    161 {
    162     QLineEdit::paintEvent(pPaintEvent);
    163     if (m_fMarkForError)
    164     {
    165         const int iIconMargin = 1. * QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
    166         int iIconSize = height() - 2 * iIconMargin;
    167         if (!m_pErrorIconLabel)
    168             m_pErrorIconLabel = new QLabel(this);
    169         m_pErrorIconLabel->setPixmap(m_markIcon.pixmap(windowHandle(), QSize(iIconSize, iIconSize)));
    170         int iIconX = width() - iIconSize - iIconMargin;
    171         if (m_pTextVisibilityButton)
    172             iIconX -= m_pTextVisibilityButton->width() - iIconMargin;
    173         m_pErrorIconLabel->move(iIconX, iIconMargin);
    174         m_pErrorIconLabel->setToolTip(m_strErrorToolTip);
    175         m_pErrorIconLabel->show();
    176     }
    177     else
    178     {
    179         if (m_pErrorIconLabel)
    180             m_pErrorIconLabel->hide();
    181     }
    182 }
    183 
    184 void UIPasswordLineEdit::sltHandleTextVisibilityChange()
    185 {
    186     bool fTextVisible = false;
    187     if (echoMode() == QLineEdit::Normal)
    188         fTextVisible = false;
    189     else
    190         fTextVisible = true;
    191     toggleTextVisibility(fTextVisible);
    192     emit sigTextVisibilityToggled(fTextVisible);
    193 }
    194 
    195 
    196 /*********************************************************************************************************************************
    197 *   UIUserNamePasswordEditor implementation.                                                                                     *
    198 *********************************************************************************************************************************/
    199 
    200 UIUserNamePasswordEditor::UIUserNamePasswordEditor(QWidget *pParent /*  = 0 */)
    201     : QIWithRetranslateUI<QWidget>(pParent)
    202     , m_pUserNameLineEdit(0)
    203     , m_pPasswordLineEdit(0)
    204     , m_pPasswordRepeatLineEdit(0)
    205     , m_pUserNameLabel(0)
    206     , m_pPasswordLabel(0)
    207     , m_pPasswordRepeatLabel(0)
    208     , m_fShowPlaceholderText(true)
    209     , m_fLabelsVisible(true)
    210 {
    211     prepare();
    212 }
    213 
    214 QString UIUserNamePasswordEditor::userName() const
    215 {
    216     if (m_pUserNameLineEdit)
    217         return m_pUserNameLineEdit->text();
     49    if (m_pHostnameLineEdit)
     50        return m_pHostnameLineEdit->text();
    21851    return QString();
    21952}
    22053
    221 void UIUserNamePasswordEditor::setUserName(const QString &strUserName)
     54bool UIHostNameDomainEditor::isComplete() const
    22255{
    223     if (m_pUserNameLineEdit)
    224         return m_pUserNameLineEdit->setText(strUserName);
     56    return m_pHostnameLineEdit && m_pHostnameLineEdit->hasAcceptableInput() &&
     57        m_pDomainLineEdit && m_pDomainLineEdit->hasAcceptableInput();
    22558}
    22659
    227 QString UIUserNamePasswordEditor::password() const
     60void UIHostNameDomainEditor::setHostname(const QString &strHostname)
    22861{
    229     if (m_pPasswordLineEdit)
    230         return m_pPasswordLineEdit->text();
     62    if (m_pHostnameLineEdit)
     63        m_pHostnameLineEdit->setText(strHostname);
     64}
     65
     66QString UIHostNameDomainEditor::domain() const
     67{
     68    if (m_pDomainLineEdit)
     69        return m_pDomainLineEdit->text();
    23170    return QString();
    23271}
    23372
    234 void UIUserNamePasswordEditor::setPassword(const QString &strPassword)
     73void UIHostNameDomainEditor::setDomain(const QString &strDomain)
    23574{
    236     if (m_pPasswordLineEdit)
    237         m_pPasswordLineEdit->setText(strPassword);
    238     if (m_pPasswordRepeatLineEdit)
    239         m_pPasswordRepeatLineEdit->setText(strPassword);
     75    if (m_pDomainLineEdit)
     76        m_pDomainLineEdit->setText(strDomain);
    24077}
    24178
    242 bool UIUserNamePasswordEditor::isUserNameComplete()
     79QString UIHostNameDomainEditor::hostnameDomain() const
    24380{
    244     bool fComplete = (m_pUserNameLineEdit && !m_pUserNameLineEdit->text().isEmpty());
    245     if (m_pUserNameLineEdit)
    246         m_pUserNameLineEdit->mark(!fComplete, UIUserNamePasswordEditor::tr("Invalid username"));
    247     return fComplete;
     81    if (m_pHostnameLineEdit && m_pDomainLineEdit)
     82        return QString("%1.%2").arg(m_pHostnameLineEdit->text()).arg(m_pDomainLineEdit->text());
     83    return QString();
    24884}
    24985
    250 bool UIUserNamePasswordEditor::isPasswordComplete()
     86void UIHostNameDomainEditor::retranslateUi()
    25187{
    252     bool fPasswordOK = true;
    253     if (m_pPasswordLineEdit && m_pPasswordRepeatLineEdit)
     88    QString strHostnameTooltip(tr("Type the hostname which will be used in attended install:"));
     89    QString strDomainTooltip(tr("The domain name"));
     90    if (m_pHostnameLabel)
    25491    {
    255         if (m_pPasswordLineEdit->text() != m_pPasswordRepeatLineEdit->text())
    256             fPasswordOK = false;
    257         if (m_pPasswordLineEdit->text().isEmpty())
    258             fPasswordOK = false;
    259         m_pPasswordLineEdit->mark(!fPasswordOK, m_strPasswordError);
    260         m_pPasswordRepeatLineEdit->mark(!fPasswordOK, m_strPasswordError);
     92        m_pHostnameLabel->setText(tr("Hostna&me:"));
     93        m_pHostnameLabel->setToolTip(strHostnameTooltip);
    26194    }
    262     return fPasswordOK;
     95    if (m_pHostnameLineEdit)
     96        m_pHostnameLineEdit->setToolTip(strHostnameTooltip);
     97    if (m_pDomainLabel)
     98    {
     99        m_pDomainLabel->setText(tr("&Domain"));
     100        m_pDomainLabel->setToolTip(strDomainTooltip);
     101    }
     102    m_pDomainLineEdit->setToolTip(strDomainTooltip);
    263103}
    264104
    265 bool UIUserNamePasswordEditor::isComplete()
     105void UIHostNameDomainEditor::addLineEdit(int &iRow, QLabel *&pLabel, QILineEdit *&pLineEdit, QGridLayout *pLayout)
    266106{
    267     bool fUserNameField = isUserNameComplete();
    268     bool fPasswordField = isPasswordComplete();
    269     return fUserNameField && fPasswordField;
    270 }
     107    AssertReturnVoid(pLayout);
     108    if (pLabel || pLineEdit)
     109        return;
    271110
    272 void UIUserNamePasswordEditor::setPlaceholderTextEnabled(bool fEnabled)
    273 {
    274     if (m_fShowPlaceholderText == fEnabled)
    275         return;
    276     m_fShowPlaceholderText = fEnabled;
    277     retranslateUi();
    278 }
    279 
    280 void UIUserNamePasswordEditor::setLabelsVisible(bool fVisible)
    281 {
    282     if (m_fLabelsVisible == fVisible)
    283         return;
    284     m_fLabelsVisible = fVisible;
    285     m_pUserNameLabel->setVisible(fVisible);
    286     m_pPasswordLabel->setVisible(fVisible);
    287     m_pPasswordRepeatLabel->setVisible(fVisible);
    288 
    289 }
    290 
    291 void UIUserNamePasswordEditor::retranslateUi()
    292 {
    293     QString strPassword = UIUserNamePasswordEditor::tr("Pass&word");
    294     QString strRepeatPassword = UIUserNamePasswordEditor::tr("&Repeat Password");
    295     QString strUsername = UIUserNamePasswordEditor::tr("U&sername");
    296     if (m_pUserNameLabel)
    297     {
    298         m_pUserNameLabel->setText(QString("%1%2").arg(strUsername).arg(":"));
    299         m_pUserNameLabel->setToolTip(UIUserNamePasswordEditor::tr("Type the user name which will be used in attended install:"));
    300 
    301     }
    302     if (m_pPasswordLabel)
    303     {
    304         m_pPasswordLabel->setText(QString("%1%2").arg(strPassword).arg(":"));
    305         m_pPasswordLabel->setToolTip(UIUserNamePasswordEditor::tr("Type the password for the user name"));
    306 
    307     }
    308     if (m_pPasswordRepeatLabel)
    309     {
    310         m_pPasswordRepeatLabel->setText(QString("%1%2").arg(strRepeatPassword).arg(":"));
    311         m_pPasswordRepeatLabel->setToolTip(UIUserNamePasswordEditor::tr("Retype the password:"));
    312     }
    313 
    314     if (m_fShowPlaceholderText)
    315     {
    316         if(m_pUserNameLineEdit)
    317             m_pUserNameLineEdit->setPlaceholderText(strUsername.remove('&'));
    318         if (m_pPasswordLineEdit)
    319             m_pPasswordLineEdit->setPlaceholderText(strPassword.remove('&'));
    320         if (m_pPasswordRepeatLineEdit)
    321             m_pPasswordRepeatLineEdit->setPlaceholderText(strRepeatPassword.remove('&'));
    322     }
    323     else
    324     {
    325         if(m_pUserNameLineEdit)
    326             m_pUserNameLineEdit->setPlaceholderText(QString());
    327         if (m_pPasswordLineEdit)
    328             m_pPasswordLineEdit->setPlaceholderText(QString());
    329         if (m_pPasswordRepeatLineEdit)
    330             m_pPasswordRepeatLineEdit->setPlaceholderText(QString());
    331     }
    332     m_strPasswordError = UIUserNamePasswordEditor::tr("Invalid password pair");
    333 }
    334 
    335 template <class T>
    336 void UIUserNamePasswordEditor::addLineEdit(int &iRow, QLabel *&pLabel, T *&pLineEdit, QGridLayout *pLayout)
    337 {
    338     if (!pLayout || pLabel || pLineEdit)
    339         return;
    340111    pLabel = new QLabel;
    341     if (!pLabel)
    342         return;
     112    AssertReturnVoid(pLabel);
    343113    pLabel->setAlignment(Qt::AlignRight);
    344114    pLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
     
    346116    pLayout->addWidget(pLabel, iRow, 0, 1, 1);
    347117
    348     pLineEdit = new T;
    349     if (!pLineEdit)
    350         return;
     118    pLineEdit = new QILineEdit;
     119    AssertReturnVoid(pLineEdit);
     120
    351121    pLayout->addWidget(pLineEdit, iRow, 1, 1, 3);
     122    // QRegularExpression hostNameRegex("^[a-zA-Z0-9-.]{2,}\\.[a-zA-Z0-9-.]+$");^[a-zA-Z0-9-.]{2,}\.[a-zA-Z0-9-.]+$
     123    /* Host name and domain should be strings of minimum length of 2 and composed of alpha numerics, '-', and '.': */
     124    m_pHostnameLineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression("^[a-zA-Z0-9-.]{2,}"), this));
    352125
    353126    pLabel->setBuddy(pLineEdit);
     
    356129}
    357130
    358 void UIUserNamePasswordEditor::prepare()
     131void UIHostNameDomainEditor::prepare()
    359132{
    360133    QGridLayout *pMainLayout = new QGridLayout;
     
    366139    setLayout(pMainLayout);
    367140    int iRow = 0;
    368     addLineEdit<QILineEdit>(iRow, m_pUserNameLabel, m_pUserNameLineEdit, pMainLayout);
    369     addLineEdit<UIPasswordLineEdit>(iRow, m_pPasswordLabel, m_pPasswordLineEdit, pMainLayout);
    370     addLineEdit<UIPasswordLineEdit>(iRow, m_pPasswordRepeatLabel, m_pPasswordRepeatLineEdit, pMainLayout);
     141    addLineEdit(iRow, m_pHostnameLabel, m_pHostnameLineEdit, pMainLayout);
     142    addLineEdit(iRow, m_pDomainLabel, m_pDomainLineEdit, pMainLayout);
    371143
    372     connect(m_pPasswordLineEdit, &UIPasswordLineEdit::sigTextVisibilityToggled,
    373             this, &UIUserNamePasswordEditor::sltHandlePasswordVisibility);
    374     connect(m_pPasswordRepeatLineEdit, &UIPasswordLineEdit::sigTextVisibilityToggled,
    375             this, &UIUserNamePasswordEditor::sltHandlePasswordVisibility);
    376     connect(m_pPasswordLineEdit, &UIPasswordLineEdit::textChanged,
    377             this, &UIUserNamePasswordEditor::sltPasswordChanged);
    378     connect(m_pPasswordRepeatLineEdit, &UIPasswordLineEdit::textChanged,
    379             this, &UIUserNamePasswordEditor::sltPasswordChanged);
    380     connect(m_pUserNameLineEdit, &QILineEdit::textChanged,
    381             this, &UIUserNamePasswordEditor::sltUserNameChanged);
     144    connect(m_pHostnameLineEdit, &QILineEdit::textChanged,
     145            this, &UIHostNameDomainEditor::sltHostnameChanged);
     146    connect(m_pDomainLineEdit, &QILineEdit::textChanged,
     147            this, &UIHostNameDomainEditor::sltDomainChanged);
    382148
    383     /* Cache the original back color of the line edit to restore it correctly: */
    384     if (m_pUserNameLineEdit)
    385         m_orginalLineEditBaseColor = m_pUserNameLineEdit->palette().color(QPalette::Base);
    386149
    387150    retranslateUi();
    388151}
    389152
    390 void UIUserNamePasswordEditor::sltHandlePasswordVisibility(bool fPasswordVisible)
     153void UIHostNameDomainEditor::sltHostnameChanged()
    391154{
    392     if (m_pPasswordLineEdit)
    393         m_pPasswordLineEdit->toggleTextVisibility(fPasswordVisible);
    394     if (m_pPasswordRepeatLineEdit)
    395         m_pPasswordRepeatLineEdit->toggleTextVisibility(fPasswordVisible);
     155    m_pHostnameLineEdit->mark(!m_pHostnameLineEdit->hasAcceptableInput(),
     156                              tr("Hostname should be a string of length 2. Allowed characters are alphanumerics, '-', and '.'" ));
     157    emit sigHostnameDomainChanged(hostnameDomain());
    396158}
    397159
    398 void UIUserNamePasswordEditor::sltUserNameChanged()
     160void UIHostNameDomainEditor::sltDomainChanged()
    399161{
    400     isUserNameComplete();
    401     emit sigUserNameChanged(m_pUserNameLineEdit->text());
     162    m_pDomainLineEdit->mark(!m_pDomainLineEdit->hasAcceptableInput(),
     163                              tr("Domain name should be a string of length 2. Allowed characters are alphanumerics, '-', and '.'" ));
     164
     165    emit sigHostnameDomainChanged(hostnameDomain());
    402166}
    403 
    404 void UIUserNamePasswordEditor::sltPasswordChanged()
    405 {
    406     isPasswordComplete();
    407     emit sigPasswordChanged(m_pPasswordLineEdit->text());
    408 }
    409 
    410 
    411 #include "UIUserNamePasswordEditor.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIHostNameDomainEditor.h

    r90124 r90151  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIUserNamePasswordEditor class declaration.
     3 * VBox Qt GUI - UIHostNameDomainEditor class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_widgets_UIUserNamePasswordEditor_h
    19 #define FEQT_INCLUDED_SRC_widgets_UIUserNamePasswordEditor_h
     18#ifndef FEQT_INCLUDED_SRC_widgets_UIHostNameDomainEditor_h
     19#define FEQT_INCLUDED_SRC_widgets_UIHostNameDomainEditor_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
     
    3535class UIPasswordLineEdit;
    3636
    37 class UIUserNamePasswordEditor : public QIWithRetranslateUI<QWidget>
     37class UIHostNameDomainEditor : public QIWithRetranslateUI<QWidget>
    3838{
    3939
     
    4242signals:
    4343
    44     void sigUserNameChanged(const QString &strUserName);
    45     void sigPasswordChanged(const QString &strPassword);
     44    void sigHostnameDomainChanged(const QString &strHostNameDomain);
    4645
    4746public:
    4847
    49     UIUserNamePasswordEditor(QWidget *pParent = 0);
     48    UIHostNameDomainEditor(QWidget *pParent = 0);
    5049
    51     QString userName() const;
    52     void setUserName(const QString &strUserName);
     50    QString hostname() const;
     51    void setHostname(const QString &strHostname);
    5352
    54     QString password() const;
    55     void setPassword(const QString &strPassword);
     53    QString domain() const;
     54    void setDomain(const QString &strDomain);
    5655
    57     /** Returns false if username or password fields are empty, or password fields do not match. */
    58     bool isComplete();
     56    QString hostnameDomain() const;
    5957
    60     /** When fEnabled true place holder texts for the line edits are shown. */
    61     void setPlaceholderTextEnabled(bool fEnabled);
    62     void setLabelsVisible(bool fVisible);
     58    bool isComplete() const;
    6359
    6460protected:
     
    6864private slots:
    6965
    70     void sltHandlePasswordVisibility(bool fPasswordVisible);
    71     void sltUserNameChanged();
    72     void sltPasswordChanged();
     66    void sltHostnameChanged();
     67    void sltDomainChanged();
    7368
    7469private:
    7570
    7671    void prepare();
    77     template <class T>
    78     void addLineEdit(int &iRow, QLabel *&pLabel, T *&pLineEdit, QGridLayout *pLayout);
     72    void addLineEdit(int &iRow, QLabel *&pLabel, QILineEdit *&pLineEdit, QGridLayout *pLayout);
    7973
    80     bool isUserNameComplete();
    81     bool isPasswordComplete();
     74    QILineEdit  *m_pHostnameLineEdit;
     75    QILineEdit  *m_pDomainLineEdit;
    8276
    83     QILineEdit         *m_pUserNameLineEdit;
    84     UIPasswordLineEdit *m_pPasswordLineEdit;
    85     UIPasswordLineEdit *m_pPasswordRepeatLineEdit;
     77    QLabel *m_pHostnameLabel;
     78    QLabel *m_pDomainLabel;
    8679
    87     QLabel *m_pUserNameLabel;
    88     QLabel *m_pPasswordLabel;
    89     QLabel *m_pPasswordRepeatLabel;
    90     QColor m_orginalLineEditBaseColor;
    91 
    92     bool m_fShowPlaceholderText;
    93     bool m_fLabelsVisible;
    94 
    95     QString m_strPasswordError;
    9680};
    9781
    98 #endif /* !FEQT_INCLUDED_SRC_widgets_UIUserNamePasswordEditor_h */
     82#endif /* !FEQT_INCLUDED_SRC_widgets_UIHostNameDomainEditor_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp

    r90109 r90151  
    742742}
    743743
    744 const QString &UIWizardNewVM::hostname() const
    745 {
    746     return m_unattendedInstallData.m_strHostname;
    747 }
    748 
    749 void UIWizardNewVM::setHostname(const QString &strHostname)
    750 {
    751     m_unattendedInstallData.m_strHostname = strHostname;
     744const QString &UIWizardNewVM::hostnameDomain() const
     745{
     746    return m_unattendedInstallData.m_strHostnameDomain;
     747}
     748
     749void UIWizardNewVM::setHostnameDomain(const QString &strHostnameDomain)
     750{
     751    m_unattendedInstallData.m_strHostnameDomain = strHostnameDomain;
    752752}
    753753
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.h

    r90109 r90151  
    5252    QString m_strUserName;
    5353    QString m_strPassword;
    54     QString m_strHostname;
     54    QString m_strHostnameDomain;
    5555    QString m_strProductKey;
    5656    bool m_fInstallGuestAdditions;
     
    134134    void setGuestAdditionsISOPath(const QString &strGAISOPath);
    135135
    136     const QString &hostname() const;
    137     void setHostname(const QString &strHostname);
     136    const QString &hostnameDomain() const;
     137    void setHostnameDomain(const QString &strHostname);
    138138
    139139    const QString &productKey() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMUnattendedPageBasic.cpp

    r90106 r90151  
    3232#include "UIIconPool.h"
    3333#include "UIUserNamePasswordEditor.h"
     34#include "UIHostNameDomainEditor.h"
    3435#include "UIWizardNewVMUnattendedPageBasic.h"
    3536#include "UIWizardNewVM.h"
     
    6162    , m_pStartHeadlessCheckBox(0)
    6263    , m_pUserNamePasswordEditor(0)
    63     , m_pHostnameLineEdit(0)
    64     , m_pHostnameLabel(0)
     64    , m_pHostnameDomainEditor(0)
    6565    , m_pGAISOPathLabel(0)
    6666    , m_pGAISOFilePathSelector(0)
     
    101101        connect(m_pGAInstallationISOContainer, &QGroupBox::toggled,
    102102                this, &UIWizardNewVMUnattendedPageBasic::sltInstallGACheckBoxToggle);
    103     if (m_pHostnameLineEdit)
    104         connect(m_pHostnameLineEdit, &QLineEdit::textChanged,
    105                 this, &UIWizardNewVMUnattendedPageBasic::sltHostnameChanged);
     103    if (m_pHostnameDomainEditor)
     104        connect(m_pHostnameDomainEditor, &UIHostNameDomainEditor::sigHostnameDomainChanged,
     105                this, &UIWizardNewVMUnattendedPageBasic::sltHostnameDomainChanged);
    106106    if (m_pProductKeyLineEdit)
    107107        connect(m_pProductKeyLineEdit, &QLineEdit::textChanged,
     
    120120                                            "hostname. Additionally you can enable guest additions install. "
    121121                                            "For Microsoft Windows guests it is possible to provide a product key.</p>"));
    122     if (m_pHostnameLabel)
    123         m_pHostnameLabel->setText(UIWizardNewVM::tr("Hostna&me:"));
    124 
    125122    if (m_pGAISOPathLabel)
    126123        m_pGAISOPathLabel->setText(UIWizardNewVM::tr("GA I&nstallation ISO:"));
     
    166163        m_pUserNamePasswordEditor->blockSignals(false);
    167164    }
    168     if (m_pHostnameLineEdit && !m_userModifiedParameters.contains("Hostname"))
    169     {
    170         m_pHostnameLineEdit->blockSignals(true);
    171         m_pHostnameLineEdit->setText(pWizard->hostname());
    172         m_pHostnameLineEdit->blockSignals(false);
     165    if (m_pHostnameDomainEditor)
     166    {
     167        m_pHostnameDomainEditor->blockSignals(true);
     168
     169        if (!m_userModifiedParameters.contains("HostnameDomain"))
     170        {
     171            m_pHostnameDomainEditor->setHostname(pWizard->machineBaseName());
     172            m_pHostnameDomainEditor->setDomain("myguest.virtualbox.org");
     173            /* Initialize unattended hostname here since we cannot get the efault value from CUnattended this early (unlike username etc): */
     174            newVMWizardPropertySet(HostnameDomain, m_pHostnameDomainEditor->hostnameDomain());
     175        }
     176
     177        m_pHostnameDomainEditor->blockSignals(false);
    173178    }
    174179    if (m_pGAInstallationISOContainer && !m_userModifiedParameters.contains("InstallGuestAdditions"))
     
    196201    if (m_pUserNamePasswordEditor && !m_pUserNamePasswordEditor->isComplete())
    197202        return false;
     203    if (m_pHostnameDomainEditor && !m_pHostnameDomainEditor->isComplete())
     204        return false;
    198205    return true;
    199206}
     
    245252}
    246253
    247 void UIWizardNewVMUnattendedPageBasic::sltHostnameChanged(const QString &strHostname)
    248 {
    249     newVMWizardPropertySet(Hostname, strHostname);
    250     m_userModifiedParameters << "Hostname";
     254void UIWizardNewVMUnattendedPageBasic::sltHostnameDomainChanged(const QString &strHostnameDomain)
     255{
     256    newVMWizardPropertySet(HostnameDomain, strHostnameDomain);
     257    m_userModifiedParameters << "HostnameDomain";
     258    emit completeChanged();
    251259}
    252260
     
    304312    }
    305313
    306     m_pHostnameLabel = new QLabel;
    307     if (m_pHostnameLabel)
    308     {
    309         m_pHostnameLabel->setAlignment(Qt::AlignRight);
    310         m_pHostnameLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    311         pAdditionalOptionsContainerLayout->addWidget(m_pHostnameLabel, 1, 0);
    312     }
    313     m_pHostnameLineEdit = new QLineEdit;
    314     if (m_pHostnameLineEdit)
    315     {
    316         if (m_pHostnameLabel)
    317             m_pHostnameLabel->setBuddy(m_pHostnameLineEdit);
    318         pAdditionalOptionsContainerLayout->addWidget(m_pHostnameLineEdit, 1, 1, 1, 2);
     314    m_pHostnameDomainEditor = new UIHostNameDomainEditor;
     315    if (m_pHostnameDomainEditor)
     316    {
     317        // if (m_pHostnameLabel)
     318        //     m_pHostnameLabel->setBuddy(m_pHostnameLineEdit);
     319        // QRegularExpression hostNameRegex("^[a-zA-Z0-9-.]{2,}\\.[a-zA-Z0-9-.]+$");^[a-zA-Z0-9-.]{2,}\.[a-zA-Z0-9-.]+$
     320        // m_pHostnameLineEdit->setValidator(new QRegularExpressionValidator(hostNameRegex, this));
     321        // m_pHostnameLineEdit->setInputMask("NNNNN-NNNNN-NNNNN-NNNNN-NNNNN;#");
     322        pAdditionalOptionsContainerLayout->addWidget(m_pHostnameDomainEditor, 1, 0, 2, 3);
    319323    }
    320324
    321325    m_pStartHeadlessCheckBox = new QCheckBox;
    322326    if (m_pStartHeadlessCheckBox)
    323         pAdditionalOptionsContainerLayout->addWidget(m_pStartHeadlessCheckBox, 2, 1);
     327        pAdditionalOptionsContainerLayout->addWidget(m_pStartHeadlessCheckBox, 3, 1);
    324328
    325329    return m_pAdditionalOptionsContainer;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMUnattendedPageBasic.h

    r90101 r90151  
    3535class UIFilePathSelector;
    3636class UIUserNamePasswordEditor;
     37class UIHostNameDomainEditor;
    3738struct UIUnattendedInstallData;
    3839
     
    6465    void sltPasswordChanged(const QString &strPassword);
    6566    void sltUserNameChanged(const QString &strUserName);
    66     void sltHostnameChanged(const QString &strHostname);
     67    void sltHostnameDomainChanged(const QString &strHostname);
    6768    void sltProductKeyChanged(const QString &strProductKey);
    6869    void sltStartHeadlessChanged(bool fStartHeadless);
     
    9394        QCheckBox *m_pStartHeadlessCheckBox;
    9495        UIUserNamePasswordEditor *m_pUserNamePasswordEditor;
    95         QLineEdit *m_pHostnameLineEdit;
    96         QLabel    *m_pHostnameLabel;
     96        UIHostNameDomainEditor *m_pHostnameDomainEditor;
     97        // QLineEdit *m_pHostnameLineEdit;
     98        // QLabel    *m_pHostnameLabel;
    9799        QLabel    *m_pGAISOPathLabel;
    98100        UIFilePathSelector *m_pGAISOFilePathSelector;
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