VirtualBox

Changeset 1628 in vbox


Ignore:
Timestamp:
Mar 22, 2007 4:38:51 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
19755
Message:

Network Interfaces Settings rework:

  1. Network Interfaces List with Add/Remove interface buttons is currently accessible in any “attached to” adapter state (not only in Attached to Host Interface case).
  2. Add/Remove keys changed to auto-raise tool-buttons. These keys are currently situated at the right vertical tool-bar near the interface’s list.
  3. Add Interface functionality is done through additional modal “Add Host Interface” Dialog.
  4. Remove Interface functionality has additional message-box with Ok/Cancel question about removing selected interface.
  5. Synchronization between all the adaptors interface’s lists done for add/remove functionality.
Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited

Legend:

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

    r1459 r1628  
    8181        ui/VBoxVMSettingsDlg.ui.h \
    8282        ui/VBoxSharedFoldersSettings.ui.h
     83ifeq ($(BUILD_TARGET),win)
     84VirtualBox_QT_MOCUIHDRS += ui/VBoxVMNetworkSettings.ui.h
     85endif
    8386
    8487VirtualBox_GENSRCS = \
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMNetworkSettings.ui

    r1517 r1628  
    2727            <x>0</x>
    2828            <y>0</y>
    29             <width>307</width>
    30             <height>312</height>
     29            <width>361</width>
     30            <height>368</height>
    3131        </rect>
    3232    </property>
     
    3434        <string>VBoxVMNetworkSettings</string>
    3535    </property>
    36     <grid>
     36    <vbox>
    3737        <property name="name">
    3838            <cstring>unnamed</cstring>
     
    4141            <number>10</number>
    4242        </property>
    43         <widget class="QGroupBox" row="0" column="0">
     43        <widget class="QGroupBox">
    4444            <property name="name">
    4545                <cstring>grbEnabled</cstring>
     
    219219                    </property>
    220220                    <property name="flat">
    221                         <bool>true</bool>
     221                        <bool>false</bool>
    222222                    </property>
    223223                    <vbox>
     
    225225                            <cstring>unnamed</cstring>
    226226                        </property>
    227                         <property name="margin">
    228                             <number>0</number>
    229                         </property>
    230227                        <widget class="QLayoutWidget">
    231228                            <property name="name">
    232                                 <cstring>layout34</cstring>
     229                                <cstring>layout33</cstring>
    233230                            </property>
    234231                            <hbox>
     
    236233                                    <cstring>unnamed</cstring>
    237234                                </property>
     235                                <property name="spacing">
     236                                    <number>0</number>
     237                                </property>
    238238                                <widget class="QFrame">
    239239                                    <property name="name">
     
    246246                                        <enum>Raised</enum>
    247247                                    </property>
    248                                     <vbox>
     248                                    <grid>
    249249                                        <property name="name">
    250250                                            <cstring>unnamed</cstring>
     
    253253                                            <number>0</number>
    254254                                        </property>
    255                                         <widget class="QLayoutWidget">
    256                                             <property name="name">
    257                                                 <cstring>layout14</cstring>
     255                                        <property name="spacing">
     256                                            <number>6</number>
     257                                        </property>
     258                                        <widget class="QLayoutWidget" row="0" column="0">
     259                                            <property name="name">
     260                                                <cstring>layout31</cstring>
    258261                                            </property>
    259262                                            <hbox>
     
    284287                                                        <cstring>leHostInterfaceName</cstring>
    285288                                                    </property>
     289                                                    <property name="focusPolicy">
     290                                                        <enum>NoFocus</enum>
     291                                                    </property>
     292                                                    <property name="readOnly">
     293                                                        <bool>true</bool>
     294                                                    </property>
    286295                                                    <property name="whatsThis" stdset="0">
    287                                                         <string>Enter name for the new interface here</string>
    288                                                     </property>
    289                                                 </widget>
    290                                                 <widget class="QToolButton">
    291                                                     <property name="name">
    292                                                         <cstring>pbHostAdd</cstring>
    293                                                     </property>
    294                                                     <property name="text">
    295                                                         <string>...</string>
    296                                                     </property>
    297                                                     <property name="toolTip" stdset="0">
    298                                                         <string></string>
    299                                                     </property>
    300                                                     <property name="whatsThis" stdset="0">
    301                                                         <string>Add a new host interface</string>
    302                                                     </property>
    303                                                 </widget>
    304                                                 <widget class="QToolButton">
    305                                                     <property name="name">
    306                                                         <cstring>pbHostRemove</cstring>
    307                                                     </property>
    308                                                     <property name="text">
    309                                                         <string>...</string>
    310                                                     </property>
    311                                                     <property name="toolTip" stdset="0">
    312                                                         <string></string>
    313                                                     </property>
    314                                                     <property name="whatsThis" stdset="0">
    315                                                         <string>Remove
    316                                                         the selected host interface</string>
     296                                                        <string>The name of the interface selected for the current adapter</string>
    317297                                                    </property>
    318298                                                </widget>
    319299                                            </hbox>
    320300                                        </widget>
    321                                         <widget class="QListBox">
     301                                        <widget class="QListBox" row="1" column="0">
    322302                                            <property name="name">
    323303                                                <cstring>lbHostInterface</cstring>
     
    335315                                            </property>
    336316                                        </widget>
    337                                     </vbox>
     317                                        <widget class="QLayoutWidget" row="1" column="1">
     318                                            <property name="name">
     319                                                <cstring>layout27</cstring>
     320                                            </property>
     321                                            <vbox>
     322                                                <property name="name">
     323                                                    <cstring>unnamed</cstring>
     324                                                </property>
     325                                                <property name="margin">
     326                                                    <number>0</number>
     327                                                </property>
     328                                                <property name="spacing">
     329                                                    <number>0</number>
     330                                                </property>
     331                                                <widget class="QToolButton">
     332                                                    <property name="name">
     333                                                        <cstring>pbHostAdd</cstring>
     334                                                    </property>
     335                                                    <property name="focusPolicy">
     336                                                        <enum>StrongFocus</enum>
     337                                                    </property>
     338                                                    <property name="text">
     339                                                        <string>...</string>
     340                                                    </property>
     341                                                    <property name="autoRaise">
     342                                                        <bool>true</bool>
     343                                                    </property>
     344                                                    <property name="toolTip" stdset="0">
     345                                                        <string></string>
     346                                                    </property>
     347                                                    <property name="whatsThis" stdset="0">
     348                                                        <string>Add a new host interface</string>
     349                                                    </property>
     350                                                </widget>
     351                                                <widget class="QToolButton">
     352                                                    <property name="name">
     353                                                        <cstring>pbHostRemove</cstring>
     354                                                    </property>
     355                                                    <property name="focusPolicy">
     356                                                        <enum>StrongFocus</enum>
     357                                                    </property>
     358                                                    <property name="text">
     359                                                        <string>...</string>
     360                                                    </property>
     361                                                    <property name="autoRaise">
     362                                                        <bool>true</bool>
     363                                                    </property>
     364                                                    <property name="toolTip" stdset="0">
     365                                                        <string></string>
     366                                                    </property>
     367                                                    <property name="whatsThis" stdset="0">
     368                                                        <string>Remove
     369                                                        the selected host interface</string>
     370                                                    </property>
     371                                                </widget>
     372                                                <spacer>
     373                                                    <property name="name">
     374                                                        <cstring>spacer7</cstring>
     375                                                    </property>
     376                                                    <property name="orientation">
     377                                                        <enum>Vertical</enum>
     378                                                    </property>
     379                                                    <property name="sizeType">
     380                                                        <enum>Expanding</enum>
     381                                                    </property>
     382                                                    <property name="sizeHint">
     383                                                        <size>
     384                                                            <width>10</width>
     385                                                            <height>10</height>
     386                                                        </size>
     387                                                    </property>
     388                                                </spacer>
     389                                            </vbox>
     390                                        </widget>
     391                                        <spacer row="0" column="1">
     392                                            <property name="name">
     393                                                <cstring>spacer11</cstring>
     394                                            </property>
     395                                            <property name="orientation">
     396                                                <enum>Horizontal</enum>
     397                                            </property>
     398                                            <property name="sizeType">
     399                                                <enum>Minimum</enum>
     400                                            </property>
     401                                            <property name="sizeHint">
     402                                                <size>
     403                                                    <width>20</width>
     404                                                    <height>20</height>
     405                                                </size>
     406                                            </property>
     407                                        </spacer>
     408                                    </grid>
    338409                                </widget>
    339410                                <widget class="QLayoutWidget">
     
    639710            </vbox>
    640711        </widget>
    641     </grid>
     712    </vbox>
    642713</widget>
    643714<connections>
     
    690761    <include location="global" impldecl="in implementation">qfiledialog.h</include>
    691762    <include location="local" impldecl="in declaration">COMDefs.h</include>
     763    <include location="local" impldecl="in declaration">QIWidgetValidator.h</include>
    692764    <include location="local" impldecl="in implementation">VBoxGlobal.h</include>
    693765    <include location="local" impldecl="in implementation">VBoxProblemReporter.h</include>
    694766</includes>
    695767<variables>
    696     <variable access="private">QStringList networkInterfaceList;</variable>
    697768    <variable access="private">CNetworkAdapter cadapter;</variable>
    698     <variable access="private">QString NoSuitableIfaces;</variable>
     769    <variable access="private">int mInterfaceNumber;</variable>
     770    <variable access="private">QIWidgetValidator *mWalidator;</variable>
     771    <variable access="private">QString mNoInterfaces;</variable>
    699772</variables>
     773<signals>
     774        <signal>listChanged( QWidget* )</signal>
     775</signals>
    700776<slots>
    701777    <slot>cbNetworkAttachment_activated( const QString &amp; string )</slot>
     
    703779    <slot>pbTAPSetup_clicked()</slot>
    704780    <slot>pbTAPTerminate_clicked()</slot>
    705     <slot access="protected">hostInterfaceAdd()</slot>
     781        <slot access="protected">hostInterfaceAdd()</slot>
    706782    <slot access="protected">hostInterfaceRemove()</slot>
    707783    <slot access="protected">lbHostInterface_highlighted( QListBoxItem* item )</slot>
     784    <slot access="protected">grbEnabledToggled( bool )</slot>
    708785</slots>
    709786<functions>
    710787    <function access="private" specifier="non virtual">init()</function>
    711     <function>getFromAdapter( const CNetworkAdapter &amp; adapter )</function>
     788    <function>loadList( const QStringList &amp; )</function>
     789    <function>getFromAdapter( const CNetworkAdapter &amp; )</function>
    712790    <function>putBackToAdapter()</function>
    713     <function access="private">updateInterfaceList()</function>
    714     <function returnType="bool">checkNetworkInterface( QString input )</function>
     791    <function>setValidator( QIWidgetValidator* )</function>
     792    <function>revalidate()</function>
     793    <function returnType="bool">isPageValid( const QStringList &amp; )</function>
     794    <function access="private">selectListItem( const QString &amp; )</function>
     795    <function access="private" returnType="bool">isInterfaceInvalid( const QStringList &amp;, const QString &amp; )</function>
    715796</functions>
    716797<pixmapinproject/>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMNetworkSettings.ui.h

    r1521 r1628  
    3030*****************************************************************************/
    3131
     32/**
     33 *  QDialog class reimplementation to use for adding network interface.
     34 *  It has one line-edit field for entering network interface's name and
     35 *  common dialog's ok/cancel buttons.
     36 */
     37#if defined Q_WS_WIN
     38class VBoxAddNIDialog : public QDialog
     39{
     40    Q_OBJECT
     41
     42public:
     43
     44    VBoxAddNIDialog (QWidget *aParent, const QString &aIfaceName) :
     45        QDialog (aParent, "VBoxAddNIDialog", true /* modal */),
     46        mLeName (0)
     47    {
     48        setCaption (tr ("Add Host Interface"));
     49        QVBoxLayout *mainLayout = new QVBoxLayout (this, 10, 10, "mainLayout");
     50
     51        /* Setup Input layout */
     52        QHBoxLayout *inputLayout = new QHBoxLayout (mainLayout, 10, "inputLayout");
     53        QLabel *lbName = new QLabel ("Interface Name", this);
     54        mLeName = new QLineEdit (aIfaceName, this);
     55        QWhatsThis::add (mLeName, tr ("Enter name for the interface to be created"));
     56        inputLayout->addWidget (lbName);
     57        inputLayout->addWidget (mLeName);
     58        connect (mLeName, SIGNAL (textChanged (const QString &)),
     59                 this, SLOT (validate()));
     60
     61        /* Setup Button layout */
     62        QHBoxLayout *buttonLayout = new QHBoxLayout (mainLayout, 10, "buttonLayout");
     63        mBtOk = new QPushButton ("OK", this, "btOk");
     64        QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
     65        QPushButton *btCancel = new QPushButton ("Cancel", this, "btCancel");
     66        connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
     67        connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
     68        buttonLayout->addWidget (mBtOk);
     69        buttonLayout->addItem (spacer);
     70        buttonLayout->addWidget (btCancel);
     71
     72        /* Validate interface name field */
     73        validate();
     74    }
     75
     76    ~VBoxAddNIDialog() {}
     77
     78    QString getName() { return mLeName->text(); }
     79
     80private slots:
     81
     82    void validate()
     83    {
     84        mBtOk->setEnabled (!mLeName->text().isEmpty());
     85    }
     86
     87private:
     88
     89    void showEvent (QShowEvent *aEvent)
     90    {
     91        setFixedHeight (height());
     92        QDialog::showEvent (aEvent);
     93    }
     94
     95    QPushButton *mBtOk;
     96    QLineEdit *mLeName;
     97};
     98#endif
     99
     100
     101/**
     102 *  VBoxVMNetworkSettings class to use as network interface setup page.
     103 */
    32104void VBoxVMNetworkSettings::init()
    33105{
    34     /* set initial values
    35      * -------------------------------------------------------------------- */
     106    mInterfaceNumber = 0;
     107    mNoInterfaces = tr ("<No suitable interfaces>");
    36108
    37109    leMACAddress->setValidator (new QRegExpValidator (QRegExp ("[0-9,A-F]{12,12}"), this));
    38110
    39 #if defined Q_WS_X11
    40     leTAPDescriptor->setValidator (new QIntValidator (-1, std::numeric_limits <LONG>::max(), this));
    41 #endif
    42 
    43     /* set initial values
    44      * -------------------------------------------------------------------- */
    45 
    46     NoSuitableIfaces = tr ("<No suitable interfaces>");
    47 
    48 #if defined Q_WS_WIN
    49     updateInterfaceList();
    50 #endif
    51    
    52111    cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::NoNetworkAttachment));
    53112    cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::NATNetworkAttachment));
     
    55114    cbNetworkAttachment->insertItem (vboxGlobal().toString (CEnums::InternalNetworkAttachment));
    56115
    57     grbTAP->setEnabled (false); /* initially disabled */
     116#if defined Q_WS_X11
     117    leTAPDescriptor->setValidator (new QIntValidator (-1, std::numeric_limits <LONG>::max(), this));
     118#else
     119    /* hide unavailable settings (TAP setup and terminate apps) */
     120    frmTAPSetupTerminate->setHidden (true);
     121#endif
    58122
    59123#if defined Q_WS_WIN
    60124    /* disable unused interface name UI */
    61125    frmHostInterface_X11->setHidden (true);
    62     /* setup iconsets -- qdesigner is not capable... */
     126    /* setup iconsets */
    63127    pbHostAdd->setIconSet (VBoxGlobal::iconSet ("add_host_iface_16px.png",
    64128                                                "add_host_iface_disabled_16px.png"));
    65129    pbHostRemove->setIconSet (VBoxGlobal::iconSet ("remove_host_iface_16px.png",
    66130                                                   "remove_host_iface_disabled_16px.png"));
     131    connect (grbEnabled, SIGNAL (toggled (bool)),
     132             this, SLOT (grbEnabledToggled (bool)));
    67133#else
    68134    /* disable unused interface name UI */
    69135    frmHostInterface_WIN->setHidden (true);
    70     /* setup iconsets -- qdesigner is not capable... */
     136    /* setup iconsets */
    71137    pbTAPSetup->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
    72138                                                 "select_file_dis_16px.png"));
     
    75141#endif
    76142
    77 #if !defined Q_WS_X11
    78     /* hide unavailable settings (TAP setup and terminate apps) */
    79     frmTAPSetupTerminate->setHidden (true);
    80 #endif
    81 
    82143    /* the TAP file descriptor setting is always invisible -- currently not used
    83144     * (remove the relative code at all? -- just leave for some time...) */
     
    85146}
    86147
    87 void VBoxVMNetworkSettings::updateInterfaceList()
    88 {
    89 #if defined Q_WS_WIN
    90     /* clear lists */
    91     networkInterfaceList.clear();
     148bool VBoxVMNetworkSettings::isPageValid (const QStringList &aList)
     149{
     150#if defined Q_WS_WIN
     151    CEnums::NetworkAttachmentType type =
     152        vboxGlobal().toNetworkAttachmentType (cbNetworkAttachment->currentText());
     153
     154    return !(type == CEnums::HostInterfaceNetworkAttachment &&
     155             isInterfaceInvalid (aList, leHostInterfaceName->text()));
     156#else
     157    NOREF (aList);
     158    return true;
     159#endif
     160}
     161
     162void VBoxVMNetworkSettings::loadList (const QStringList &aList)
     163{
     164#if defined Q_WS_WIN
     165    /* save current list item name */
     166    QString currentListItemName = leHostInterfaceName->text();
     167    /* load current list items */
     168    lbHostInterface->clearFocus();
    92169    lbHostInterface->clear();
    93     /* read a QStringList of interface names */
    94     CHostNetworkInterfaceEnumerator en =
    95         vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
    96     while (en.HasMore())
    97         networkInterfaceList += en.GetNext().GetName();
    98     /* setup a list of interface names */
    99     if (networkInterfaceList.count())
    100         lbHostInterface->insertStringList (networkInterfaceList);
     170    if (aList.count())
     171        lbHostInterface->insertStringList (aList);
    101172    else
    102         lbHostInterface->insertItem (NoSuitableIfaces);
     173        lbHostInterface->insertItem (mNoInterfaces);
     174    selectListItem (currentListItemName);
    103175    /* disable interface delete button */
    104     pbHostRemove->setEnabled (!networkInterfaceList.isEmpty());
     176    pbHostRemove->setEnabled (!aList.isEmpty());
     177#else
     178    NOREF (aList);
    105179#endif
    106180}
     
    127201
    128202#if defined Q_WS_WIN
    129     if (adapter.GetHostInterface().isEmpty())
    130         lbHostInterface->setCurrentItem (0);
    131     else
    132     {
    133         QListBoxItem* adapterNode = lbHostInterface->findItem(adapter.GetHostInterface());
    134         if (adapterNode)
    135             lbHostInterface->setCurrentItem(adapterNode);
    136     }
     203    selectListItem (adapter.GetHostInterface());
    137204#else
    138205    leHostInterface->setText (adapter.GetHostInterface());
     
    140207
    141208#if defined Q_WS_X11
    142     leTAPDescriptor->setText (QString::number(adapter.GetTAPFileDescriptor()));
     209    leTAPDescriptor->setText (QString::number (adapter.GetTAPFileDescriptor()));
    143210    leTAPSetup->setText (adapter.GetTAPSetupApplication());
    144211    leTAPTerminate->setText (adapter.GetTAPTerminateApplication());
     
    194261}
    195262
    196 void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &string)
    197 {
    198     grbTAP->setEnabled (vboxGlobal().toNetworkAttachmentType (string) ==
    199                         CEnums::HostInterfaceNetworkAttachment);
    200 }
    201 
    202 void VBoxVMNetworkSettings::lbHostInterface_highlighted(QListBoxItem* /*item*/)
    203 {
    204     leHostInterfaceName->clear();
    205 }
    206 
    207 bool VBoxVMNetworkSettings::checkNetworkInterface (QString ni)
    208 {
    209 #if defined Q_WS_WIN
    210     return networkInterfaceList.find (ni) != networkInterfaceList.end() ? 1 : 0;
    211 #else
    212     NOREF(ni);
    213     return true;
     263void VBoxVMNetworkSettings::setValidator (QIWidgetValidator *aWalidator)
     264{
     265    mWalidator = aWalidator;
     266}
     267
     268void VBoxVMNetworkSettings::revalidate()
     269{
     270    mWalidator->revalidate();
     271}
     272
     273void VBoxVMNetworkSettings::grbEnabledToggled (bool aOn)
     274{
     275#if defined Q_WS_WIN
     276    if (!aOn)
     277    {
     278        lbHostInterface->clearFocus();
     279        cbNetworkAttachment->setCurrentItem (0);
     280        cbNetworkAttachment_activated (cbNetworkAttachment->currentText());
     281        if (lbHostInterface->selectedItem())
     282            lbHostInterface->setSelected (lbHostInterface->selectedItem(), false);
     283    }
     284    if (lbHostInterface->currentItem() != -1)
     285        lbHostInterface->setSelected (lbHostInterface->currentItem(), aOn);
     286#else
     287    NOREF (aOn);
     288#endif
     289}
     290
     291void VBoxVMNetworkSettings::selectListItem (const QString &aItemName)
     292{
     293    if (!aItemName.isEmpty())
     294    {
     295#if defined Q_WS_WIN
     296        leHostInterfaceName->setText (aItemName);
     297        QListBoxItem* adapterNode = lbHostInterface->findItem (aItemName);
     298        if (adapterNode)
     299        {
     300            lbHostInterface->setCurrentItem (adapterNode);
     301            lbHostInterface->setSelected (adapterNode, true);
     302        }
     303#endif
     304    }
     305}
     306
     307void VBoxVMNetworkSettings::cbNetworkAttachment_activated (const QString &aString)
     308{
     309#if defined Q_WS_WIN
     310    bool enableHostIf = vboxGlobal().toNetworkAttachmentType (aString) ==
     311                        CEnums::HostInterfaceNetworkAttachment;
     312    txHostInterface_WIN->setEnabled (enableHostIf);
     313    leHostInterfaceName->setEnabled (enableHostIf);
     314    lbHostInterface_highlighted (lbHostInterface->selectedItem());
     315#else
     316    NOREF (aString);
     317#endif
     318}
     319
     320void VBoxVMNetworkSettings::lbHostInterface_highlighted (QListBoxItem *aItem)
     321{
     322    if (!aItem) return;
     323#if defined Q_WS_WIN
     324    leHostInterfaceName->setText (leHostInterfaceName->isEnabled() ?
     325                                  aItem->text() : QString::null);
     326    if (!lbHostInterface->isSelected (aItem))
     327        lbHostInterface->setSelected (aItem, true);
     328#endif
     329}
     330
     331bool VBoxVMNetworkSettings::isInterfaceInvalid (const QStringList &aList,
     332                                                const QString &aIface)
     333{
     334#if defined Q_WS_WIN
     335    return aList.find (aIface) == aList.end();
     336#else
     337    NOREF (aList);
     338    NOREF (aIface);
     339    return false;
    214340#endif
    215341}
     
    223349void VBoxVMNetworkSettings::pbTAPSetup_clicked()
    224350{
    225 //    QFileDialog dlg ("/", QString::null, this);
    226 //    dlg.setMode (QFileDialog::ExistingFile);
    227 //    dlg.setViewMode (QFileDialog::List);
    228 //    dlg.setCaption (tr ("Select TAP setup application"));
    229 //    if (dlg.exec() == QDialog::Accepted)
    230 //        leTAPSetup->setText (dlg.selectedFile());
    231 
    232351    QString selected = QFileDialog::getOpenFileName (
    233352        "/",
     
    243362void VBoxVMNetworkSettings::pbTAPTerminate_clicked()
    244363{
    245 //    QFileDialog dlg ("/", QString::null, this);
    246 //    dlg.setMode (QFileDialog::ExistingFile);
    247 //    dlg.setViewMode (QFileDialog::List);
    248 //    dlg.setCaption (tr ("Select TAP terminate application"));
    249 //    if (dlg.exec() == QDialog::Accepted)
    250 //        leTAPTerminate->setText (dlg.selectedFile());
    251 
    252364    QString selected = QFileDialog::getOpenFileName (
    253365        "/",
     
    268380    AllowSetForegroundWindow (ASFW_ANY);
    269381
    270     /* check interface name */
    271     QString iName = leHostInterfaceName->text();
    272     if (iName.isEmpty() || iName == NoSuitableIfaces)
    273     {
    274         vboxProblem().message (this, VBoxProblemReporter::Error,
    275             tr ("Host network interface name cannot be empty"));
     382    /* creating add host interface dialog */
     383    VBoxAddNIDialog dlg (this, lbHostInterface->currentItem() != -1 ?
     384                         tr ("Host Interface %1").arg (++mInterfaceNumber) :
     385                         leHostInterfaceName->text());
     386    if (dlg.exec() != QDialog::Accepted)
    276387        return;
    277     }
     388    QString iName = dlg.getName();
    278389
    279390    /* create interface */
     
    286397        if (progress.GetResultCode() == 0)
    287398        {
    288             updateInterfaceList();
    289             /* move the selection to the new created item */
    290             QListBoxItem *createdNode =
    291                 lbHostInterface->findItem (leHostInterfaceName->text());
    292             if (createdNode)
    293                 lbHostInterface->setCurrentItem (createdNode);
    294             else
    295                 lbHostInterface->setCurrentItem (0);
     399            /* add&select newly created created interface */
     400            delete lbHostInterface->findItem (mNoInterfaces);
     401            lbHostInterface->insertItem (iName);
     402            selectListItem (iName);
     403            emit listChanged (this);
    296404        }
    297405        else
    298406            vboxProblem().cannotCreateHostInterface (progress, iName, this);
    299 
    300407    }
    301408    else
     
    320427        return;
    321428
     429    /* asking user about deleting selected network interface */
     430    int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question,
     431        tr ("<p>Do you want to remove selected network interface "
     432            "<nobr><b>%1</b>?</nobr></p>"
     433            "<p>If this interface is currently selected you should "
     434            "apply VM settings changes to avoid VM using of non-existing "
     435            "interface</p>").arg (iName),
     436        0, /* autoConfirmId */
     437        QIMessageBox::Ok | QIMessageBox::Default,
     438        QIMessageBox::Cancel | QIMessageBox::Escape);
     439    if (delNetIface == QIMessageBox::Cancel)
     440        return;
     441
    322442    CHost host = vboxGlobal().virtualBox().GetHost();
    323443    CHostNetworkInterface iFace = host.GetNetworkInterfaces().FindByName (iName);
     
    325445    {
    326446        /* delete interface */
    327          CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
     447        CProgress progress = host.RemoveHostNetworkInterface (iFace.GetId(), iFace);
    328448        if (host.isOk())
    329449        {
     
    331451            if (progress.GetResultCode() == 0)
    332452            {
    333                 updateInterfaceList();
    334                 /* move the selection to the start of the list */
    335                 lbHostInterface->setCurrentItem(0);
    336                 lbHostInterface->setSelected(0, true);
     453                if (lbHostInterface->count() == 1)
     454                    lbHostInterface->insertItem (mNoInterfaces);
     455                delete lbHostInterface->findItem (iName);
     456                emit listChanged (this);
    337457            }
    338458            else
     
    345465#endif
    346466}
     467
     468#if defined Q_WS_WIN
     469#include "VBoxVMNetworkSettings.ui.moc"
     470#endif
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui

    r1455 r1628  
    26632663    <variable access="private">QValueVector &lt; CHostFloppyDrive &gt; hostFloppies;</variable>
    26642664    <variable access="private">CMachine cmachine;</variable>
    2665     <variable access="private">QStringList bootDevicesInUse;</variable>
     2665    <variable access="private">QStringList mInterfaceList;</variable>
    26662666    <variable access="private">QWidgetStack *wstUSBFilters;</variable>
    26672667    <variable access="private">ulong mLastUSBFilterNum;</variable>
     
    26902690    <slot>showImageManagerISOFloppy()</slot>
    26912691    <slot>showVDImageManager( QUuid *id, VBoxMediaComboBox *le, QLabel *tx = NULL )</slot>
    2692     <slot>addNetworkAdapter( const CNetworkAdapter &amp; adapter, bool select )</slot>
     2692    <slot>addNetworkAdapter( const CNetworkAdapter &amp; adapter )</slot>
    26932693    <slot>slRAM_valueChanged( int val )</slot>
    26942694    <slot>leRAM_textChanged( const QString &amp; text )</slot>
     
    27132713    <slot>fdMediaChanged()</slot>
    27142714    <slot>processAdjustSize()</slot>
     2715    <slot>updateInterfaces( QWidget* )</slot>
     2716    <slot>networkPageUpdate( QWidget* )</slot>
    27152717</slots>
    27162718<functions>
     
    27182720    <function>setup( const QString &amp;, const QString &amp; )</function>
    27192721    <function>getFromMachine( const CMachine &amp; machine )</function>
     2722    <function returnType="bool">eventFilter( QObject * watched, QEvent * e )</function>
    27202723    <function returnType="COMResult">putBackToMachine()</function>
    2721     <function access="protected">setWarning( const QString &amp; )</function>
    2722     <function access="protected">showEvent( QShowEvent * )</function>
    2723     <function returnType="bool">eventFilter( QObject * watched, QEvent * e )</function>
    2724     <function access="protected">updateShortcuts()</function>
    2725     <function access="protected" returnType="QString">getHdInfo( QGroupBox*, QUuid )</function>
     2724    <function access="private">setWarning( const QString &amp; )</function>
     2725    <function access="private">showEvent( QShowEvent * )</function>
     2726    <function access="private">updateShortcuts()</function>
     2727    <function access="private" returnType="QString">getHdInfo( QGroupBox*, QUuid )</function>
    27262728</functions>
    27272729<pixmapinproject/>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r1557 r1628  
    721721    /* Network Page */
    722722
     723    updateInterfaces (0);
     724
    723725    /*
    724726     *  update the Ok button state for pages with validation
     
    822824        cbISOFloppy->refresh();
    823825    }
     826}
     827
     828
     829void VBoxVMSettingsDlg::updateInterfaces (QWidget *aWidget)
     830{
     831#if defined Q_WS_WIN
     832    /* clear list */
     833    mInterfaceList.clear();
     834    /* write a QStringList of interface names */
     835    CHostNetworkInterfaceEnumerator en =
     836        vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
     837    while (en.HasMore())
     838        mInterfaceList += en.GetNext().GetName();
     839    if (aWidget)
     840    {
     841        VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (aWidget);
     842        set->revalidate();
     843    }
     844#else
     845    NOREF (aWidget);
     846#endif
     847}
     848
     849void VBoxVMSettingsDlg::networkPageUpdate (QWidget *aWidget)
     850{
     851    if (!aWidget) return;
     852#if defined Q_WS_WIN
     853    updateInterfaces (0);
     854    VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (aWidget);
     855    set->loadList (mInterfaceList);
     856    set->revalidate();
     857#endif
    824858}
    825859
     
    11311165    else if (pg == pageNetwork)
    11321166    {
    1133         int slot = -1;
    1134         for (int index = 0; index < tbwNetwork->count(); index++)
    1135         {
    1136             QWidget* pTab = tbwNetwork->page (index);
    1137             Assert(pTab);
    1138             VBoxVMNetworkSettings* pNetSet = static_cast <VBoxVMNetworkSettings*>(pTab);
    1139             if (!pNetSet->grbEnabled->isChecked())
    1140             {
    1141                 pNetSet->cbNetworkAttachment->setCurrentItem (0);
    1142                 pNetSet->cbNetworkAttachment_activated (pNetSet->cbNetworkAttachment->currentText());
    1143             }
    1144 
    1145             CEnums::NetworkAttachmentType type =
    1146                 vboxGlobal().toNetworkAttachmentType (pNetSet->cbNetworkAttachment->currentText());
    1147             valid = (slot == -1) &&
    1148                     !(type == CEnums::HostInterfaceNetworkAttachment &&
    1149                       !pNetSet->checkNetworkInterface (pNetSet->lbHostInterface->currentText()));
    1150             if (slot == -1 && !valid)
    1151                 slot = index;
     1167        int index = 0;
     1168        for (; index < tbwNetwork->count(); ++index)
     1169        {
     1170            QWidget *tab = tbwNetwork->page (index);
     1171            VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (tab);
     1172            valid = set->isPageValid (mInterfaceList);
     1173            if (!valid) break;
    11521174        }
    11531175        if (!valid)
    1154             setWarning (tr ("Incorrect host network interface is selected for Adapter %1.")
    1155                         .arg (slot));
     1176            setWarning (tr ("Incorrect host network interface is selected "
     1177                            "for Adapter %1.").arg (index));
    11561178    }
    11571179    else if (pg == pageVRDP)
     
    13971419    {
    13981420        ulong count = vbox.GetSystemProperties().GetNetworkAdapterCount();
    1399         for (ulong slot = 0; slot < count; slot ++)
     1421        for (ulong slot = 0; slot < count; ++ slot)
    14001422        {
    14011423            CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
    1402             addNetworkAdapter (adapter, false);
     1424            addNetworkAdapter (adapter);
    14031425        }
    14041426    }
     
    17441766}
    17451767
    1746 void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &adapter,
    1747                                            bool /* select */)
    1748 {
    1749     VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings ();
    1750     page->getFromAdapter (adapter);
    1751     tbwNetwork->addTab(page, QString("Adapter %1").arg(adapter.GetSlot()));
     1768void VBoxVMSettingsDlg::addNetworkAdapter (const CNetworkAdapter &aAdapter)
     1769{
     1770    VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings();
     1771    page->loadList (mInterfaceList);
     1772    page->getFromAdapter (aAdapter);
     1773    tbwNetwork->addTab (page, QString ("Adapter %1").arg (aAdapter.GetSlot()));
    17521774
    17531775    /* fix the tab order so that main dialog's buttons are always the last */
     
    17581780    /* setup validation */
    17591781    QIWidgetValidator *wval = new QIWidgetValidator (pageNetwork, this);
     1782    connect (page->grbEnabled, SIGNAL (toggled (bool)), wval, SLOT (revalidate()));
    17601783    connect (page->cbNetworkAttachment, SIGNAL (activated (const QString &)),
    17611784             wval, SLOT (revalidate()));
    17621785
    1763     connect (page->lbHostInterface, SIGNAL ( selectionChanged () ),
     1786#if defined Q_WS_WIN
     1787    connect (page->lbHostInterface, SIGNAL (highlighted (QListBoxItem*)),
    17641788             wval, SLOT (revalidate()));
    1765     connect (page->lbHostInterface, SIGNAL ( currentChanged ( QListBoxItem * ) ),
    1766              wval, SLOT (revalidate()));
    1767     connect (page->lbHostInterface, SIGNAL ( highlighted ( QListBoxItem * ) ),
    1768              wval, SLOT (revalidate()));
    1769     connect (page->grbEnabled, SIGNAL (toggled (bool)),
    1770              wval, SLOT (revalidate()));
     1789    connect (tbwNetwork, SIGNAL (currentChanged (QWidget*)),
     1790             this, SLOT (networkPageUpdate (QWidget*)));
     1791    connect (page, SIGNAL (listChanged (QWidget*)),
     1792             this, SLOT (updateInterfaces (QWidget*)));
     1793#endif
    17711794
    17721795    connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
     
    17751798             this, SLOT (revalidate( QIWidgetValidator *)));
    17761799
    1777     wval->revalidate();
     1800    page->setValidator (wval);
     1801    page->revalidate();
    17781802}
    17791803
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