VirtualBox

Changeset 2394 in vbox for trunk


Ignore:
Timestamp:
Apr 27, 2007 11:39:11 AM (18 years ago)
Author:
vboxsync
Message:

1942: Improve automatic naming for "Add New..." Uis

Feature implemented as designed:
Search algorithm will find the last created default named interface (filter) and will use its index+1 as a starting index for the newly created ones.

Location:
trunk/src/VBox/Frontends/VirtualBox/ui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMNetworkSettings.ui

    r2187 r2394  
    788788<functions>
    789789    <function access="private" specifier="non virtual">init()</function>
    790     <function>loadList( const QStringList &amp; )</function>
     790    <function>loadList( const QStringList &amp;, int )</function>
    791791    <function>getFromAdapter( const CNetworkAdapter &amp; )</function>
    792792    <function>putBackToAdapter()</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMNetworkSettings.ui.h

    r2309 r2394  
    152152
    153153#if defined Q_WS_MAC
    154     /* no Host Interface Networking on the Mac yet */   
     154    /* no Host Interface Networking on the Mac yet */
    155155    grbTAP->setHidden (true);
    156156#endif
     
    171171}
    172172
    173 void VBoxVMNetworkSettings::loadList (const QStringList &aList)
    174 {
    175 #if defined Q_WS_WIN
     173void VBoxVMNetworkSettings::loadList (const QStringList &aList,
     174                                      int aInterfaceNumber)
     175{
     176#if defined Q_WS_WIN
     177    mInterfaceNumber = aInterfaceNumber;
    176178    /* save current list item name */
    177179    QString currentListItemName = leHostInterfaceName->text();
     
    188190#else
    189191    NOREF (aList);
     192    NOREF (aInterfaceNumber);
    190193#endif
    191194}
     
    393396    /* creating add host interface dialog */
    394397    VBoxAddNIDialog dlg (this, lbHostInterface->currentItem() != -1 ?
    395                          tr ("VirtualBox Host Interface %1").arg (++mInterfaceNumber) :
     398                         tr ("VirtualBox Host Interface %1").arg (mInterfaceNumber) :
    396399                         leHostInterfaceName->text());
    397400    if (dlg.exec() != QDialog::Accepted)
     
    408411        if (progress.GetResultCode() == 0)
    409412        {
     413            ++ mInterfaceNumber;
    410414            /* add&select newly created created interface */
    411415            delete lbHostInterface->findItem (mNoInterfaces);
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui

    r2240 r2394  
    27712771    <variable access="private">CMachine cmachine;</variable>
    27722772    <variable access="private">QStringList mInterfaceList;</variable>
     2773    <variable access="private">int mInterfaceNumber;</variable>
    27732774    <variable access="private">QWidgetStack *wstUSBFilters;</variable>
    27742775    <variable access="private">ulong mLastUSBFilterNum;</variable>
    27752776    <variable access="private">bool mUSBFilterListModified;</variable>
     2777    <variable access="private">QString mUSBFilterNamePrefix;</variable>
    27762778    <variable access="private">QTabWidget* tbwNetwork;</variable>
    27772779    <variable access="private">VBoxSharedFoldersSettings* mSharedFolders;</variable>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r2350 r2394  
    630630    mLastUSBFilterNum = 0;
    631631    mUSBFilterListModified = false;
     632    mUSBFilterNamePrefix = tr ("New Filter ", "usb");
    632633
    633634    /* VRDP Page */
     
    850851        set->revalidate();
    851852    }
     853    /* searching for max interface index */
     854    QString interfacePrefix = tr ("VirtualBox Host Interface ");
     855    QRegExp regExp (QString ("%1(\\d+)").arg (interfacePrefix));
     856    QStringList list = mInterfaceList.grep (regExp);
     857    int max = 0;
     858    for (QStringList::Iterator it = list.begin(); it != list.end(); ++ it)
     859    {
     860        int pos = regExp.search (*it);
     861        if (pos != -1)
     862            max = regExp.cap (1).toInt() > max ? regExp.cap (1).toInt() : max;
     863    }
     864    mInterfaceNumber = ++ max;
    852865#else
    853866    NOREF (aWidget);
     
    861874    updateInterfaces (0);
    862875    VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (aWidget);
    863     set->loadList (mInterfaceList);
     876    set->loadList (mInterfaceList, mInterfaceNumber);
    864877    set->revalidate();
    865878#endif
     
    14641477
    14651478            CUSBDeviceFilterEnumerator en = ctl.GetDeviceFilters().Enumerate();
     1479            /* loading filters & searching for max filter index */
     1480            int max = 0;
    14661481            while (en.HasMore())
    1467                 addUSBFilter (en.GetNext(), false /* isNew */);
     1482            {
     1483                const CUSBDeviceFilter &filter = en.GetNext();
     1484                QRegExp regExp (QString ("%1(\\d+)").arg (mUSBFilterNamePrefix));
     1485                int pos = regExp.search (filter.GetName());
     1486                if (pos != -1)
     1487                    max = regExp.cap (1).toInt() > max ?
     1488                          regExp.cap (1).toInt() : max;
     1489                addUSBFilter (filter, false /* isNew */);
     1490            }
     1491            mLastUSBFilterNum = max;
    14681492
    14691493            lvUSBFilters->setCurrentItem (lvUSBFilters->firstChild());
     
    17831807{
    17841808    VBoxVMNetworkSettings *page = new VBoxVMNetworkSettings();
    1785     page->loadList (mInterfaceList);
     1809    page->loadList (mInterfaceList, mInterfaceNumber);
    17861810    page->getFromAdapter (aAdapter);
    17871811    tbwNetwork->addTab (page, QString (tr ("Adapter %1", "network"))
     
    19581982{
    19591983    CUSBDeviceFilter filter = cmachine.GetUSBController()
    1960         .CreateDeviceFilter (tr ("New Filter %1", "usb")
    1961                                  .arg (++ mLastUSBFilterNum));
     1984        .CreateDeviceFilter (QString ("%1%2")
     1985        .arg (mUSBFilterNamePrefix).arg (++ mLastUSBFilterNum));
    19621986
    19631987    filter.SetActive (true);
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