VirtualBox

Ignore:
Timestamp:
Aug 23, 2007 7:01:31 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
23856
Message:

Main: Improved serial port API (mostly spelling);
FE/Qt: Improved serial port UI (spelling and duplicate handling).

Location:
trunk/src/VBox/Frontends/VirtualBox/ui
Files:
2 added
3 edited

Legend:

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

    r4071 r4324  
    2626*****************************************************************************/
    2727
    28 /**
    29  *  VBoxVMNetworkSettings class to use as network interface setup page.
    30  */
    3128void VBoxVMNetworkSettings::init()
    3229{
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui

    r4294 r4324  
    270270        <item>
    271271            <property name="text">
    272                 <string> Serial Port </string>
     272                <string> Serial Ports </string>
    273273            </property>
    274274            <property name="text">
     
    276276            </property>
    277277            <property name="text">
    278                 <string>#serial</string>
     278                <string>#serialPorts</string>
    279279            </property>
    280280            <property name="pixmap">
    281                 <pixmap>refresh_16px.png</pixmap>
     281                <pixmap></pixmap>
    282282            </property>
    283283            <property name="pixmap">
     
    27122712                    <number>9</number>
    27132713                </attribute>
     2714                <vbox>
     2715                    <property name="name">
     2716                        <cstring>unnamed</cstring>
     2717                    </property>
     2718                    <property name="margin">
     2719                        <number>0</number>
     2720                    </property>
     2721                    <widget class="QTabWidget">
     2722                        <property name="name">
     2723                            <cstring>tbwSerialPorts</cstring>
     2724                        </property>
     2725                        <property name="sizePolicy">
     2726                            <sizepolicy>
     2727                                <hsizetype>1</hsizetype>
     2728                                <vsizetype>1</vsizetype>
     2729                                <horstretch>0</horstretch>
     2730                                <verstretch>0</verstretch>
     2731                            </sizepolicy>
     2732                        </property>
     2733                    </widget>
     2734                </vbox>
    27142735            </widget>
    27152736        </widget>
     
    30553076    <include location="local" impldecl="in declaration">VBoxGlobal.h</include>
    30563077    <include location="local" impldecl="in implementation">VBoxVMNetworkSettings.h</include>
     3078    <include location="local" impldecl="in implementation">VBoxVMSerialPortSettings.h</include>
    30573079    <include location="local" impldecl="in implementation">VBoxUSBFilterSettings.h</include>
    30583080    <include location="local" impldecl="in implementation">VBoxSharedFoldersSettings.h</include>
     
    30663088    <forward>class VBoxUSBMenu</forward>
    30673089    <forward>class VBoxSharedFoldersSettings</forward>
    3068     <forward>class VBoxVMSerialPortSettings</forward>
    30693090    <forward>class QIRichLabel</forward>
    30703091    <forward>class BootItemsList</forward>
     
    30923113    <variable access="private">bool mUSBFilterListModified;</variable>
    30933114    <variable access="private">VBoxSharedFoldersSettings *mSharedFolders;</variable>
    3094     <variable access="private">VBoxVMSerialPortSettings *mSerialPorts;</variable>
    30953115    <variable access="private">QString warningString;</variable>
    30963116    <variable access="private">VBoxMediaComboBox *cbHDA;</variable>
     
    31163136    <slot>showImageManagerISOFloppy()</slot>
    31173137    <slot>showVDImageManager( QUuid *id, VBoxMediaComboBox *le, QLabel *tx = NULL )</slot>
    3118     <slot>addNetworkAdapter( const CNetworkAdapter &amp; adapter )</slot>
     3138    <slot>addNetworkAdapter( const CNetworkAdapter &amp; )</slot>
     3139    <slot>addSerialPort( const CSerialPort &amp; )</slot>
    31193140    <slot>slRAM_valueChanged( int val )</slot>
    31203141    <slot>leRAM_textChanged( const QString &amp; text )</slot>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r4300 r4324  
    470470
    471471
    472 class VBoxVMSerialPortSettings : public QWidget
    473 {
    474     Q_OBJECT
    475 
    476 public:
    477 
    478     VBoxVMSerialPortSettings (QWidget *aParent)
    479         : QWidget (aParent, "VBoxVMSerialPortSettings")
    480         , mTabWidget (0)
    481     {
    482         /* Basic initialization */
    483         mTabWidget = new QTabWidget (this, "mTabWidget");
    484         mTabWidget->setMargin (11);
    485         mTabWidget->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Preferred);
    486         QVBoxLayout *mainLayout = new QVBoxLayout (this);
    487         mainLayout->addWidget (mTabWidget);
    488         mainLayout->addItem (new QSpacerItem (0, 0, QSizePolicy::Preferred,
    489                                                     QSizePolicy::Expanding));
    490 
    491         /* Create a list of known COM interfaces configurations */
    492         mConfigList << PortConfig (0x3f8, 4, 1);
    493         mConfigList << PortConfig (0x2f8, 3, 2);
    494         mConfigList << PortConfig (0x3e8, 4, 3);
    495         mConfigList << PortConfig (0x2e8, 3, 4);
    496     }
    497 
    498     void getFromMachine (const CMachine &aMachine)
    499     {
    500         mMachine = aMachine;
    501 
    502         ulong count = vboxGlobal().virtualBox().GetSystemProperties().GetSerialPortCount();
    503         for (ulong slot = 0; slot < count; ++ slot)
    504         {
    505             CSerialPort port = mMachine.GetSerialPort (slot);
    506             addPage (port, slot);
    507         }
    508 
    509         /* Revalidate all pages */
    510         portConfigUpdate();
    511     }
    512 
    513     void putBackToMachine()
    514     {
    515         for (int slot = 0; slot < mTabWidget->count(); ++ slot)
    516         {
    517             CSerialPort port = mMachine.GetSerialPort (slot);
    518 
    519             port.SetEnabled (static_cast<QGroupBox*> (mTabWidget->page (slot))->isChecked());
    520 
    521             PortConfig config = parsePortConfig (mPortList.at (slot)->currentText());
    522             port.SetIOBase (config.io);
    523             port.SetIRQ (config.irq);
    524 
    525             port.SetHostMode (vboxGlobal().toSerialHostMode (mModeList.at (slot)->currentText()));
    526 
    527             QCheckBox *chbIsServer = mIsServerList.at (slot);
    528             port.SetServer (chbIsServer->isEnabled() ?
    529                             chbIsServer->isChecked() : false);
    530 
    531             QLineEdit *lePath = mPathList.at (slot);
    532             port.SetPath (lePath->isEnabled() ?
    533                           lePath->text() : QString::null);
    534         }
    535     }
    536 
    537 private slots:
    538 
    539     void portConfigUpdate()
    540     {
    541         for (int index = 0; index < mTabWidget->count(); ++ index)
    542         {
    543             QComboBox *cbPortConfig = mPortList.at (index);
    544             QString oldText = cbPortConfig->currentText();
    545             QStringList newList = portConfigList (index);
    546             cbPortConfig->clear();
    547             cbPortConfig->insertStringList (newList);
    548             cbPortConfig->setCurrentText (oldText);
    549         }
    550     }
    551 
    552     void hostModeUpdate (int aIndex = -1)
    553     {
    554         if (aIndex == -1)
    555             aIndex = mTabWidget->currentPageIndex();
    556         QCheckBox *chbIsServer = mIsServerList.at (aIndex);
    557         QLineEdit *lePath = mPathList.at (aIndex);
    558         CEnums::SerialHostMode mode = vboxGlobal().toSerialHostMode (
    559             mModeList.at (aIndex)->currentText());
    560         chbIsServer->setEnabled (mode == CEnums::HostPipe);
    561         lePath->setEnabled (mode != CEnums::Disconnected);
    562     }
    563 
    564 private:
    565 
    566     struct PortConfig
    567     {
    568         PortConfig ()
    569             : io (0), irq (0), number (0) {}
    570         PortConfig (ulong aIO, ulong aIRQ, ulong aNumber)
    571             : io (aIO), irq (aIRQ), number (aNumber) {}
    572 
    573         bool isNull() { return !io && !irq; }
    574 
    575         bool operator== (const PortConfig &aCfg) const
    576         {
    577             return io  == aCfg.io && irq == aCfg.irq;
    578         }
    579 
    580         static QString format()
    581         {
    582             return QString ("I/O Port = 0x%1, IRQ = %2");
    583         }
    584         QString toString()
    585         {
    586             QString info = format().arg (QString::number (io, 16)).arg (irq);
    587             if (number)
    588                 info += QString (" (COM%1)").arg (number);
    589             return info;
    590         }
    591 
    592         ulong io;
    593         ulong irq;
    594         ulong number;
    595     };
    596     typedef QValueList<PortConfig> PortConfigs;
    597 
    598     void addPage (const CSerialPort &aPort, ulong aSlot)
    599     {
    600         /* Create Serial Port page */
    601         QGroupBox *gBox = new QGroupBox (tr ("&Enable Serial Port"));
    602         gBox->setColumnLayout (0, Qt::Vertical);
    603         gBox->layout()->setMargin (11);
    604         gBox->layout()->setSpacing (6);
    605         gBox->setCheckable (true);
    606 
    607         QLabel *lbPort = new QLabel (tr ("Serial Port &Number"), gBox);
    608         QComboBox *cbPort = new QComboBox (gBox);
    609         lbPort->setBuddy (cbPort);
    610         connect (cbPort, SIGNAL (activated (int)),
    611                  this , SLOT (portConfigUpdate()));
    612 
    613         QLabel *lbType = new QLabel (tr ("Serial Port Host &Mode"), gBox);
    614         QComboBox *cbMode = new QComboBox (gBox);
    615         lbType->setBuddy (cbMode);
    616         cbMode->insertItem (vboxGlobal().toString (CEnums::Disconnected));
    617         cbMode->insertItem (vboxGlobal().toString (CEnums::HostPipe));
    618         cbMode->insertItem (vboxGlobal().toString (CEnums::HostDevice));
    619         connect (cbMode, SIGNAL (activated (int)),
    620                  this , SLOT (hostModeUpdate()));
    621 
    622         QCheckBox *chbIsServer = new QCheckBox (tr ("Create Pipe &Automatically"), gBox);
    623 
    624         QLabel *lbPath = new QLabel (tr ("Serial Port &Path"), gBox);
    625         QLineEdit *lePath = new QLineEdit (gBox);
    626         lbPath->setBuddy (lePath);
    627 
    628         QGridLayout *pageLayout = new QGridLayout (gBox->layout());
    629         pageLayout->setAlignment (Qt::AlignTop);
    630         pageLayout->addWidget (lbPort, 0, 0);
    631         pageLayout->addMultiCellWidget (cbPort, 0, 0, 1, 2);
    632         pageLayout->addWidget (lbType, 1, 0);
    633         pageLayout->addWidget (cbMode, 1, 1);
    634         pageLayout->addWidget (chbIsServer, 1, 2);
    635         pageLayout->addWidget (lbPath, 2, 0);
    636         pageLayout->addMultiCellWidget (lePath, 2, 2, 1, 2);
    637 
    638         /* Load machine information */
    639         gBox->setChecked (aPort.GetEnabled());
    640 
    641         PortConfig config (aPort.GetIOBase(), aPort.GetIRQ(), 0);
    642         if (!mConfigList.contains (config))
    643             mConfigList << config;
    644         cbPort->insertStringList (portConfigList (mTabWidget->count()));
    645         for (int id = 0; id < cbPort->count(); ++ id)
    646             if (parsePortConfig (cbPort->text (id)) == config)
    647                 cbPort->setCurrentItem (id);
    648 
    649         cbMode->setCurrentText (vboxGlobal().toString (aPort.GetHostMode()));
    650 
    651         chbIsServer->setChecked (aPort.GetServer());
    652 
    653         lePath->setText (aPort.GetPath());
    654 
    655         /* Append newly createrd widget */
    656         mTabWidget->addTab (gBox, tr ("Port &%1").arg (aSlot));
    657         mPortList.append (cbPort);
    658         mModeList.append (cbMode);
    659         mIsServerList.append (chbIsServer);
    660         mPathList.append (lePath);
    661 
    662         /* Revalidate page */
    663         hostModeUpdate (aSlot);
    664     }
    665 
    666     QStringList portConfigList (int aIndex)
    667     {
    668         QStringList list;
    669         PortConfigs config = portConfigs (aIndex);
    670         for (ulong id = 0; id < config.count(); ++ id)
    671             list << config [id].toString();
    672         return list;
    673     }
    674 
    675     PortConfigs portConfigs (int aIndex)
    676     {
    677         PortConfigs config (mConfigList);
    678         if (aIndex == mTabWidget->count())
    679             return config;
    680 
    681         for (int index = 0; index < mTabWidget->count(); ++ index)
    682         {
    683             if (index != aIndex)
    684             {
    685                 PortConfig used = parsePortConfig (mPortList.at (index)->currentText());
    686                 Assert (!used.isNull());
    687                 config.remove (used);
    688             }
    689         }
    690         return config;
    691     }
    692 
    693     PortConfig parsePortConfig (const QString &aString)
    694     {
    695         QRegExp regExp (PortConfig::format().arg ("([0-9a-f]+)").arg ("(\\d+)"));
    696         if (regExp.search (aString) != -1)
    697             return PortConfig (regExp.cap (1).toULong(0, 16),
    698                                regExp.cap (2).toULong(), 0);
    699         Assert (0);
    700         return PortConfig();
    701     }
    702 
    703     QTabWidget *mTabWidget;
    704     PortConfigs mConfigList;
    705 
    706     QPtrList<QComboBox> mPortList;
    707     QPtrList<QComboBox> mModeList;
    708     QPtrList<QCheckBox> mIsServerList;
    709     QPtrList<QLineEdit> mPathList;
    710 
    711     CMachine mMachine;
    712 };
    713 
    714 
    715472void VBoxVMSettingsDlg::init()
    716473{
     
    957714    QToolTip::add (pbHostRemove, tr ("Remove"));
    958715
     716    /* Serial Port Page */
     717
    959718    /* USB Page */
    960719
     
    1021780    mSharedFolders->setDialogType (VBoxSharedFoldersSettings::MachineType);
    1022781    pageFoldersLayout->addWidget (mSharedFolders);
    1023 
    1024     /* Serial Port Page */
    1025 
    1026     QVBoxLayout* pageSerialLayout = new QVBoxLayout (pageSerial, 0, 0);
    1027     mSerialPorts = new VBoxVMSerialPortSettings (pageSerial);
    1028     pageSerialLayout->addWidget (mSerialPorts);
    1029782
    1030783    /*
     
    15491302    Q_UNUSED (wval);
    15501303
     1304    /* reset the warning text; interested parties will set it during
     1305     * validation */
     1306    setWarning (QString::null);
     1307
    15511308    /* detect the overall validity */
    15521309    bool newValid = true;
     
    15671324        valid = newValid;
    15681325        buttonOk->setEnabled (valid);
    1569         if (valid)
    1570             setWarning(0);
    1571         warningLabel->setHidden(valid);
    1572         warningPixmap->setHidden(valid);
    1573     }
    1574 }
    1575 
    1576 
    1577 void VBoxVMSettingsDlg::revalidate( QIWidgetValidator *wval )
     1326        warningLabel->setHidden (valid);
     1327        warningPixmap->setHidden (valid);
     1328    }
     1329}
     1330
     1331
     1332void VBoxVMSettingsDlg::revalidate (QIWidgetValidator *wval)
    15781333{
    15791334    /* do individual validations for pages */
     
    15811336    bool valid = wval->isOtherValid();
    15821337
     1338    QString warningText;
     1339    QString pageTitle = ::path (listView->currentItem());
     1340
    15831341    if (pg == pageHDD)
    15841342    {
     
    15931351            {
    15941352                valid = false;
    1595                 setWarning (tr ("Primary Master hard disk is not selected."));
     1353                warningText = tr ("Primary Master hard disk is not selected");
    15961354            }
    15971355            else uuids << uuidHDA;
     
    16031361            {
    16041362                valid = false;
    1605                 setWarning (tr ("Primary Slave hard disk is not selected."));
     1363                warningText = tr ("Primary Slave hard disk is not selected");
    16061364            }
    16071365            else
     
    16161374                    uuids << uuidHDB;
    16171375                else
    1618                     setWarning (tr ("Primary Slave hard disk is already attached "
    1619                                     "to a different slot."));
     1376                    warningText = tr ("Primary Slave hard disk is already attached "
     1377                                      "to a different slot");
    16201378            }
    16211379        }
     
    16261384            {
    16271385                valid = false;
    1628                 setWarning (tr ("Secondary Slave hard disk is not selected."));
     1386                warningText = tr ("Secondary Slave hard disk is not selected");
    16291387            }
    16301388            else
     
    16391397                    uuids << uuidHDB;
    16401398                else
    1641                     setWarning (tr ("Secondary Slave hard disk is already attached "
    1642                                     "to a different slot."));
     1399                    warningText = tr ("Secondary Slave hard disk is already attached "
     1400                                      "to a different slot");
    16431401            }
    16441402        }
     
    16671425
    16681426        if (!valid)
    1669             setWarning (tr ("CD/DVD image file is not selected."));
     1427            warningText = tr ("CD/DVD image file is not selected");
    16701428    }
    16711429    else if (pg == pageFloppy)
     
    16841442
    16851443        if (!valid)
    1686             setWarning (tr ("Floppy image file is not selected."));
     1444            warningText = tr ("Floppy image file is not selected");
    16871445    }
    16881446    else if (pg == pageNetwork)
    16891447    {
     1448        QWidget *tab = NULL;
     1449        for (int index = 0; index < tbwNetwork->count(); ++ index)
     1450        {
     1451            QWidget *tab = tbwNetwork->page (index);
     1452            VBoxVMNetworkSettings *page =
     1453                static_cast <VBoxVMNetworkSettings *> (tab);
     1454            valid = page->isPageValid (mInterfaceList);
     1455            if (!valid) break;
     1456        }
     1457        if (!valid)
     1458        {
     1459            Assert (tab);
     1460            warningText = tr ("Incorrect host network interface is selected");
     1461            pageTitle += ": " + tbwNetwork->tabLabel (tab);
     1462        }
     1463    }
     1464    else if (pg == pageSerial)
     1465    {
     1466        QValueList <QString> ports;
     1467        QValueList <QString> paths;
     1468
    16901469        int index = 0;
    1691         for (; index < tbwNetwork->count(); ++index)
    1692         {
    1693             QWidget *tab = tbwNetwork->page (index);
    1694             VBoxVMNetworkSettings *set = static_cast<VBoxVMNetworkSettings*> (tab);
    1695             valid = set->isPageValid (mInterfaceList);
    1696             if (!valid) break;
    1697         }
    1698         if (!valid)
    1699             setWarning (tr ("Incorrect host network interface is selected "
    1700                             "for Adapter %1.").arg (index));
     1470        for (; index < tbwSerialPorts->count(); ++ index)
     1471        {
     1472            QWidget *tab = tbwSerialPorts->page (index);
     1473            VBoxVMSerialPortSettings *page =
     1474                static_cast <VBoxVMSerialPortSettings *> (tab);
     1475
     1476            /* skip disabled ports */
     1477            if (!page->mSerialPortBox->isChecked())
     1478                continue;
     1479            /* check the predefined port number unicity */
     1480            if (!page->isUserDefined())
     1481            {
     1482                QString port = page->mPortNumCombo->currentText();
     1483                valid = !ports.contains (port);
     1484                if (!valid)
     1485                {
     1486                    warningText = tr ("Duplicate port number is selected ");
     1487                    pageTitle += ": " + tbwSerialPorts->tabLabel (tab);
     1488                    break;
     1489                }
     1490                ports << port;
     1491            }
     1492            /* check the port path unicity */
     1493            CEnums::PortMode mode =
     1494                vboxGlobal().toPortMode (page->mHostModeCombo->currentText());
     1495            if (mode != CEnums::DisconnectedPort)
     1496            {
     1497                QString path = page->mPortPathLine->text();
     1498                valid = !paths.contains (path);
     1499                if (!valid)
     1500                {
     1501                    warningText = tr ("Duplicate port path is entered ");
     1502                    pageTitle += ": " + tbwSerialPorts->tabLabel (tab);
     1503                    break;
     1504                }
     1505                paths << path;
     1506            }
     1507        }
    17011508    }
    17021509    else if (pg == pageVRDP)
     
    17071514                    (leVRDPPort->text().isEmpty() || leVRDPTimeout->text().isEmpty()));
    17081515            if (!valid && leVRDPPort->text().isEmpty())
    1709                 setWarning (tr ("VRDP Port is not set."));
     1516                warningText = tr ("VRDP Port is not set ");
    17101517            if (!valid && leVRDPTimeout->text().isEmpty())
    1711                 setWarning (tr ("VRDP Timeout is not set."));
     1518                warningText = tr ("VRDP Timeout is not set ");
    17121519        }
    17131520        else
    17141521            valid = true;
    17151522    }
     1523
     1524    if (!valid)
     1525        setWarning (tr ("%1 on the <b>%2</b> page.")
     1526                    .arg (warningText, pageTitle));
    17161527
    17171528    wval->setOtherValid (valid);
     
    19801791    }
    19811792
     1793    /* serial ports */
     1794    {
     1795        ulong count = vbox.GetSystemProperties().GetSerialPortCount();
     1796        for (ulong slot = 0; slot < count; ++ slot)
     1797        {
     1798            CSerialPort port = machine.GetSerialPort (slot);
     1799            addSerialPort (port);
     1800        }
     1801    }
     1802
    19821803    /* USB */
    19831804    {
     
    20491870    {
    20501871        mSharedFolders->getFromMachine (machine);
    2051     }
    2052 
    2053     /* serial ports */
    2054     {
    2055         mSerialPorts->getFromMachine (machine);
    20561872    }
    20571873
     
    22542070    }
    22552071
     2072    /* serial ports */
     2073    {
     2074        for (int index = 0; index < tbwSerialPorts->count(); index++)
     2075        {
     2076            VBoxVMSerialPortSettings *page =
     2077                (VBoxVMSerialPortSettings *) tbwSerialPorts->page (index);
     2078            Assert (page);
     2079            page->putBackToPort();
     2080        }
     2081    }
     2082
    22562083    /* usb */
    22572084    {
     
    23162143    }
    23172144
    2318     /* serial ports */
    2319     {
    2320         mSerialPorts->putBackToMachine();
    2321     }
    2322 
    23232145    return COMResult();
    23242146}
     
    24002222
    24012223#endif
     2224}
     2225
     2226void VBoxVMSettingsDlg::addSerialPort (const CSerialPort &aPort)
     2227{
     2228    VBoxVMSerialPortSettings *page = new VBoxVMSerialPortSettings();
     2229    page->getFromPort (aPort);
     2230    tbwSerialPorts->addTab (page, QString (tr ("Port %1", "serial ports"))
     2231                                               .arg (aPort.GetSlot()));
     2232
     2233    /* fix the tab order so that main dialog's buttons are always the last */
     2234    setTabOrder (page->mPortPathLine, buttonHelp);
     2235    setTabOrder (buttonHelp, buttonOk);
     2236    setTabOrder (buttonOk, buttonCancel);
     2237
     2238    /* setup validation */
     2239    QIWidgetValidator *wval = new QIWidgetValidator (pageSerial, this);
     2240    connect (page->mSerialPortBox, SIGNAL (toggled (bool)),
     2241             wval, SLOT (revalidate()));
     2242    connect (page->mIRQLine, SIGNAL (textChanged (const QString &)),
     2243             wval, SLOT (revalidate()));
     2244    connect (page->mIOPortLine, SIGNAL (textChanged (const QString &)),
     2245             wval, SLOT (revalidate()));
     2246    connect (page->mHostModeCombo, SIGNAL (activated (const QString &)),
     2247             wval, SLOT (revalidate()));
     2248    connect (wval, SIGNAL (validityChanged (const QIWidgetValidator *)),
     2249             this, SLOT (enableOk (const QIWidgetValidator *)));
     2250    connect (wval, SIGNAL (isValidRequested (QIWidgetValidator *)),
     2251             this, SLOT (revalidate (QIWidgetValidator *)));
     2252
     2253    wval->revalidate();
    24022254}
    24032255
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette