VirtualBox

Changeset 36929 in vbox


Ignore:
Timestamp:
May 3, 2011 12:45:50 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 4989: UISettingsCache template integrated into Serial page.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.cpp

    r36519 r36929  
    6868void UIMachineSettingsSerial::polishTab()
    6969{
     70    ulong uIRQ, uIOBase;
     71    bool fStd = vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase);
     72    KPortMode mode = vboxGlobal().toPortMode(mCbMode->currentText());
     73
    7074    mGbSerial->setEnabled(m_pParent->isMachineOffline());
    7175    mLbNumber->setEnabled(m_pParent->isMachineOffline());
    7276    mCbNumber->setEnabled(m_pParent->isMachineOffline());
    7377    mLbIRQ->setEnabled(m_pParent->isMachineOffline());
    74     mLeIRQ->setEnabled(m_pParent->isMachineOffline());
     78    mLeIRQ->setEnabled(!fStd && m_pParent->isMachineOffline());
    7579    mLbIOPort->setEnabled(m_pParent->isMachineOffline());
    76     mLeIOPort->setEnabled(m_pParent->isMachineOffline());
     80    mLeIOPort->setEnabled(!fStd && m_pParent->isMachineOffline());
    7781    mLbMode->setEnabled(m_pParent->isMachineOffline());
    7882    mCbMode->setEnabled(m_pParent->isMachineOffline());
    79     mCbPipe->setEnabled(m_pParent->isMachineOffline());
     83    mCbPipe->setEnabled(mode == KPortMode_HostPipe && m_pParent->isMachineOffline());
    8084    mLbPath->setEnabled(m_pParent->isMachineOffline());
    81     mLePath->setEnabled(m_pParent->isMachineOffline());
    82 }
    83 
    84 void UIMachineSettingsSerial::fetchPortData(const UISerialPortData &data)
    85 {
    86     /* Load port slot number: */
    87     m_iSlot = data.m_iSlot;
    88 
    89     /* Fetch port data: */
    90     mGbSerial->setChecked(data.m_fPortEnabled);
    91     mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(data.m_uIRQ, data.m_uIOBase)));
    92     mLeIRQ->setText(QString::number(data.m_uIRQ));
    93     mLeIOPort->setText("0x" + QString::number(data.m_uIOBase, 16).toUpper());
    94     mCbMode->setCurrentIndex(mCbMode->findText(vboxGlobal().toString(data.m_hostMode)));
    95     mCbPipe->setChecked(data.m_fServer);
    96     mLePath->setText(data.m_strPath);
     85    mLePath->setEnabled(mode != KPortMode_Disconnected && m_pParent->isMachineOffline());
     86}
     87
     88void UIMachineSettingsSerial::fetchPortData(const UICacheSettingsMachineSerialPort &portCache)
     89{
     90    /* Get port data: */
     91    const UIDataSettingsMachineSerialPort &portData = portCache.base();
     92
     93    /* Load port number: */
     94    m_iSlot = portData.m_iSlot;
     95
     96    /* Load port data: */
     97    mGbSerial->setChecked(portData.m_fPortEnabled);
     98    mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(portData.m_uIRQ, portData.m_uIOBase)));
     99    mLeIRQ->setText(QString::number(portData.m_uIRQ));
     100    mLeIOPort->setText("0x" + QString::number(portData.m_uIOBase, 16).toUpper());
     101    mCbMode->setCurrentIndex(mCbMode->findText(vboxGlobal().toString(portData.m_hostMode)));
     102    mCbPipe->setChecked(portData.m_fServer);
     103    mLePath->setText(portData.m_strPath);
    97104
    98105    /* Ensure everything is up-to-date */
     
    100107}
    101108
    102 void UIMachineSettingsSerial::uploadPortData(UISerialPortData &data)
    103 {
    104     /* Upload port data: */
    105     data.m_fPortEnabled = mGbSerial->isChecked();
    106     data.m_uIRQ = mLeIRQ->text().toULong(NULL, 0);
    107     data.m_uIOBase = mLeIOPort->text().toULong (NULL, 0);
    108     data.m_fServer = mCbPipe->isChecked();
    109     data.m_hostMode = vboxGlobal().toPortMode(mCbMode->currentText());
    110     data.m_strPath = QDir::toNativeSeparators(mLePath->text());
     109void UIMachineSettingsSerial::uploadPortData(UICacheSettingsMachineSerialPort &portCache)
     110{
     111    /* Prepare port data: */
     112    UIDataSettingsMachineSerialPort portData = portCache.base();
     113
     114    /* Save port data: */
     115    portData.m_fPortEnabled = mGbSerial->isChecked();
     116    portData.m_uIRQ = mLeIRQ->text().toULong(NULL, 0);
     117    portData.m_uIOBase = mLeIOPort->text().toULong (NULL, 0);
     118    portData.m_fServer = mCbPipe->isChecked();
     119    portData.m_hostMode = vboxGlobal().toPortMode(mCbMode->currentText());
     120    portData.m_strPath = QDir::toNativeSeparators(mLePath->text());
     121
     122    /* Cache port data to port cache: */
     123    portCache.cacheCurrentData(portData);
    111124}
    112125
     
    206219    layout->addWidget (mTabWidget);
    207220
    208     /* Load port data: */
     221    /* How many ports to display: */
    209222    ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetSerialPortCount();
    210     /* Apply internal variables data to QWidget(s): */
    211     for (ulong iSlot = 0; iSlot < uCount; ++iSlot)
    212     {
    213         /* Creating port's page: */
     223    /* Add corresponding tab pages to parent tab widget: */
     224    for (ulong uPort = 0; uPort < uCount; ++uPort)
     225    {
     226        /* Creating port page: */
    214227        UIMachineSettingsSerial *pPage = new UIMachineSettingsSerial(this);
    215 
    216         /* Attach port's page to Tab Widget: */
    217228        mTabWidget->addTab(pPage, pPage->pageTitle());
    218 
    219     }
    220 
    221     /* Applying language settings */
    222     retranslateUi();
     229    }
    223230}
    224231
     
    230237    UISettingsPageMachine::fetchData(data);
    231238
    232     /* Load port data: */
    233     ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetSerialPortCount();
    234     for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
    235     {
    236         /* Get port: */
    237         const CSerialPort &port = m_machine.GetSerialPort(uSlot);
    238 
    239         /* Prepare port's data container: */
    240         UISerialPortData data;
    241 
    242         /* Load options: */
    243         data.m_iSlot = uSlot;
    244         data.m_fPortEnabled = port.GetEnabled();
    245         data.m_uIRQ = port.GetIRQ();
    246         data.m_uIOBase = port.GetIOBase();
    247         data.m_hostMode = port.GetHostMode();
    248         data.m_fServer = port.GetServer();
    249         data.m_strPath = port.GetPath();
    250 
    251         /* Append adapter's data container: */
    252         m_cache.m_items << data;
     239    /* For each serial port: */
     240    for (int iSlot = 0; iSlot < mTabWidget->count(); ++iSlot)
     241    {
     242        /* Prepare port data: */
     243        UIDataSettingsMachineSerialPort portData;
     244
     245        /* Check if port is valid: */
     246        const CSerialPort &port = m_machine.GetSerialPort(iSlot);
     247        if (!port.isNull())
     248        {
     249            /* Gather options: */
     250            portData.m_iSlot = iSlot;
     251            portData.m_fPortEnabled = port.GetEnabled();
     252            portData.m_uIRQ = port.GetIRQ();
     253            portData.m_uIOBase = port.GetIOBase();
     254            portData.m_hostMode = port.GetHostMode();
     255            portData.m_fServer = port.GetServer();
     256            portData.m_strPath = port.GetPath();
     257        }
     258
     259        /* Cache port data: */
     260        m_cache.child(iSlot).cacheInitialData(portData);
    253261    }
    254262
     
    261269void UIMachineSettingsSerialPage::getFromCache()
    262270{
     271    /* Setup tab order: */
    263272    Assert(firstWidget());
    264273    setTabOrder(firstWidget(), mTabWidget->focusProxy());
    265274    QWidget *pLastFocusWidget = mTabWidget->focusProxy();
    266275
    267     ulong uCount = qMin(mTabWidget->count(), m_cache.m_items.size());
    268     /* Apply internal variables data to QWidget(s): */
    269     for (ulong iSlot = 0; iSlot < uCount; ++iSlot)
    270     {
    271         /* Getting adapter's page: */
    272         UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iSlot));
    273 
    274         /* Loading port's data into page: */
    275         pPage->fetchPortData(m_cache.m_items[iSlot]);
     276    /* For each serial port: */
     277    for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
     278    {
     279        /* Get port page: */
     280        UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iPort));
     281
     282        /* Load port data to page: */
     283        pPage->fetchPortData(m_cache.child(iPort));
    276284
    277285        /* Setup page validation: */
     
    293301void UIMachineSettingsSerialPage::putToCache()
    294302{
    295     /* Gather internal variables data from QWidget(s): */
    296     for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
    297     {
    298         /* Getting adapter's page: */
    299         UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iSlot));
    300 
    301         /* Loading Adapter's data from page: */
    302         pPage->uploadPortData(m_cache.m_items[iSlot]);
     303    /* For each serial port: */
     304    for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
     305    {
     306        /* Getting port page: */
     307        UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iPort));
     308
     309        /* Gather & cache port data: */
     310        pPage->uploadPortData(m_cache.child(iPort));
    303311    }
    304312}
     
    311319    UISettingsPageMachine::fetchData(data);
    312320
    313     if (isMachineOffline())
    314     {
    315         /* Gather corresponding values from internal variables: */
    316         for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     321    /* Check if ports data was changed: */
     322    if (m_cache.wasChanged())
     323    {
     324        /* For each serial port: */
     325        for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
    317326        {
    318             /* Get adapter: */
    319             CSerialPort port = m_machine.GetSerialPort(iSlot);
    320 
    321             /* Get cached data for this slot: */
    322             const UISerialPortData &data = m_cache.m_items[iSlot];
    323 
    324             /* Save options: */
    325             port.SetEnabled(data.m_fPortEnabled);
    326             port.SetIRQ(data.m_uIRQ);
    327             port.SetIOBase(data.m_uIOBase);
    328             port.SetServer(data.m_fServer);
    329             port.SetPath(data.m_strPath);
    330             /* This *must* be last. The host mode will be changed to disconnected if
    331              * some of the necessary settings above will not meet the requirements for
    332              * the selected mode. */
    333             port.SetHostMode(data.m_hostMode);
     327            /* Check if port data was changed: */
     328            const UICacheSettingsMachineSerialPort &portCache = m_cache.child(iPort);
     329            if (portCache.wasChanged())
     330            {
     331                /* Check if port still valid: */
     332                CSerialPort port = m_machine.GetSerialPort(iPort);
     333                if (!port.isNull())
     334                {
     335                    /* Get port data: */
     336                    const UIDataSettingsMachineSerialPort &portData = portCache.data();
     337
     338                    /* Store adapter data: */
     339                    if (isMachineOffline())
     340                    {
     341                        port.SetEnabled(portData.m_fPortEnabled);
     342                        port.SetIRQ(portData.m_uIRQ);
     343                        port.SetIOBase(portData.m_uIOBase);
     344                        port.SetServer(portData.m_fServer);
     345                        port.SetPath(portData.m_strPath);
     346                        /* This *must* be last. The host mode will be changed to disconnected if
     347                         * some of the necessary settings above will not meet the requirements for
     348                         * the selected mode. */
     349                        port.SetHostMode(portData.m_hostMode);
     350                    }
     351                }
     352            }
    334353        }
    335354    }
     
    416435{
    417436    /* Get the count of serial port tabs: */
    418     for (int iTabIndex = 0; iTabIndex < mTabWidget->count(); ++iTabIndex)
    419     {
    420         mTabWidget->setTabEnabled(iTabIndex,
     437    for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
     438    {
     439        mTabWidget->setTabEnabled(iPort,
    421440                                  isMachineOffline() ||
    422                                   (isMachineInValidMode() && m_cache.m_items[iTabIndex].m_fPortEnabled));
    423         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iTabIndex));
    424         Assert(pTab);
     441                                  (isMachineInValidMode() && m_cache.child(iPort).base().m_fPortEnabled));
     442        UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(mTabWidget->widget(iPort));
    425443        pTab->polishTab();
    426444    }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.h

    r36357 r36929  
    2828class QITabWidget;
    2929
    30 /* Machine settings / Network page / Port data: */
    31 struct UISerialPortData
     30/* Machine settings / Serial page / Port data: */
     31struct UIDataSettingsMachineSerialPort
    3232{
     33    /* Default constructor: */
     34    UIDataSettingsMachineSerialPort()
     35        : m_iSlot(-1)
     36        , m_fPortEnabled(false)
     37        , m_uIRQ(0)
     38        , m_uIOBase(0)
     39        , m_hostMode(KPortMode_Disconnected)
     40        , m_fServer(false)
     41        , m_strPath(QString()) {}
     42    /* Functions: */
     43    bool equal(const UIDataSettingsMachineSerialPort &other) const
     44    {
     45        return (m_iSlot == other.m_iSlot) &&
     46               (m_fPortEnabled == other.m_fPortEnabled) &&
     47               (m_uIRQ == other.m_uIRQ) &&
     48               (m_uIOBase == other.m_uIOBase) &&
     49               (m_hostMode == other.m_hostMode) &&
     50               (m_fServer == other.m_fServer) &&
     51               (m_strPath == other.m_strPath);
     52    }
     53    /* Operators: */
     54    bool operator==(const UIDataSettingsMachineSerialPort &other) const { return equal(other); }
     55    bool operator!=(const UIDataSettingsMachineSerialPort &other) const { return !equal(other); }
     56    /* Variables: */
    3357    int m_iSlot;
    3458    bool m_fPortEnabled;
     
    3963    QString m_strPath;
    4064};
     65typedef UISettingsCache<UIDataSettingsMachineSerialPort> UICacheSettingsMachineSerialPort;
    4166
    42 /* Machine settings / Serial page / Cache: */
    43 struct UISettingsCacheMachineSerial
     67/* Machine settings / Serial page / Ports data: */
     68struct UIDataSettingsMachineSerial
    4469{
    45     QList<UISerialPortData> m_items;
     70    /* Default constructor: */
     71    UIDataSettingsMachineSerial() {}
     72    /* Operators: */
     73    bool operator==(const UIDataSettingsMachineSerial& /* other */) const { return true; }
     74    bool operator!=(const UIDataSettingsMachineSerial& /* other */) const { return false; }
    4675};
     76typedef UISettingsCachePool<UIDataSettingsMachineSerial, UICacheSettingsMachineSerialPort> UICacheSettingsMachineSerial;
    4777
    4878class UIMachineSettingsSerial : public QIWithRetranslateUI<QWidget>,
     
    5787    void polishTab();
    5888
    59     void fetchPortData(const UISerialPortData &data);
    60     void uploadPortData(UISerialPortData &data);
     89    void fetchPortData(const UICacheSettingsMachineSerialPort &data);
     90    void uploadPortData(UICacheSettingsMachineSerialPort &data);
    6191
    6292    void setValidator (QIWidgetValidator *aVal);
     
    122152
    123153    /* Cache: */
    124     UISettingsCacheMachineSerial m_cache;
     154    UICacheSettingsMachineSerial m_cache;
    125155};
    126156
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