VirtualBox

Changeset 36930 in vbox for trunk/src/VBox/Frontends


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

FE/Qt: 4989: UISettingsCache template integrated into Parallel 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/UIMachineSettingsParallel.cpp

    r36519 r36930  
    6161void UIMachineSettingsParallel::polishTab()
    6262{
     63    /* Polish port page: */
     64    ulong uIRQ, uIOBase;
     65    bool fStd = vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase);
    6366    mGbParallel->setEnabled(m_pParent->isMachineOffline());
    6467    mLbNumber->setEnabled(m_pParent->isMachineOffline());
    6568    mCbNumber->setEnabled(m_pParent->isMachineOffline());
    6669    mLbIRQ->setEnabled(m_pParent->isMachineOffline());
    67     mLeIRQ->setEnabled(m_pParent->isMachineOffline());
     70    mLeIRQ->setEnabled(!fStd && m_pParent->isMachineOffline());
    6871    mLbIOPort->setEnabled(m_pParent->isMachineOffline());
    69     mLeIOPort->setEnabled(m_pParent->isMachineOffline());
     72    mLeIOPort->setEnabled(!fStd && m_pParent->isMachineOffline());
    7073    mLbPath->setEnabled(m_pParent->isMachineOffline());
    7174    mLePath->setEnabled(m_pParent->isMachineOffline());
    7275}
    7376
    74 void UIMachineSettingsParallel::fetchPortData(const UIParallelPortData &data)
    75 {
    76     /* Load port slot number: */
    77     m_iSlot = data.m_iSlot;
    78 
    79     /* Fetch port data: */
    80     mGbParallel->setChecked(data.m_fPortEnabled);
    81     mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(data.m_uIRQ, data.m_uIOBase)));
    82     mLeIRQ->setText(QString::number(data.m_uIRQ));
    83     mLeIOPort->setText("0x" + QString::number(data.m_uIOBase, 16).toUpper());
    84     mLePath->setText(data.m_strPath);
     77void UIMachineSettingsParallel::fetchPortData(const UICacheSettingsMachineParallelPort &portCache)
     78{
     79    /* Get port data: */
     80    const UIDataSettingsMachineParallelPort &portData = portCache.base();
     81
     82    /* Load port number: */
     83    m_iSlot = portData.m_iSlot;
     84
     85    /* Load port data: */
     86    mGbParallel->setChecked(portData.m_fPortEnabled);
     87    mCbNumber->setCurrentIndex(mCbNumber->findText(vboxGlobal().toCOMPortName(portData.m_uIRQ, portData.m_uIOBase)));
     88    mLeIRQ->setText(QString::number(portData.m_uIRQ));
     89    mLeIOPort->setText("0x" + QString::number(portData.m_uIOBase, 16).toUpper());
     90    mLePath->setText(portData.m_strPath);
    8591
    8692    /* Ensure everything is up-to-date */
     
    8894}
    8995
    90 void UIMachineSettingsParallel::uploadPortData(UIParallelPortData &data)
    91 {
    92     /* Upload port data: */
    93     data.m_fPortEnabled = mGbParallel->isChecked();
    94     data.m_uIRQ = mLeIRQ->text().toULong(NULL, 0);
    95     data.m_uIOBase = mLeIOPort->text().toULong(NULL, 0);
    96     data.m_strPath = QDir::toNativeSeparators(mLePath->text());
     96void UIMachineSettingsParallel::uploadPortData(UICacheSettingsMachineParallelPort &portCache)
     97{
     98    /* Prepare port data: */
     99    UIDataSettingsMachineParallelPort portData = portCache.base();
     100
     101    /* Save port data: */
     102    portData.m_fPortEnabled = mGbParallel->isChecked();
     103    portData.m_uIRQ = mLeIRQ->text().toULong(NULL, 0);
     104    portData.m_uIOBase = mLeIOPort->text().toULong(NULL, 0);
     105    portData.m_strPath = QDir::toNativeSeparators(mLePath->text());
     106
     107    /* Cache port data: */
     108    portCache.cacheCurrentData(portData);
    97109}
    98110
     
    172184    layout->setContentsMargins (0, 5, 0, 5);
    173185    layout->addWidget (mTabWidget);
     186
     187    /* How many ports to display: */
     188    ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetParallelPortCount();
     189    /* Add corresponding tab pages to parent tab widget: */
     190    for (ulong uPort = 0; uPort < uCount; ++uPort)
     191    {
     192        /* Creating port page: */
     193        UIMachineSettingsParallel *pPage = new UIMachineSettingsParallel(this);
     194        mTabWidget->addTab(pPage, pPage->pageTitle());
     195    }
    174196}
    175197
     
    181203    UISettingsPageMachine::fetchData(data);
    182204
    183     /* Load port data: */
    184     ulong uCount = vboxGlobal().virtualBox().GetSystemProperties().GetParallelPortCount();
    185     for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
    186     {
    187         /* Get port: */
    188         const CParallelPort &port = m_machine.GetParallelPort(uSlot);
    189 
    190         /* Prepare port's data container: */
    191         UIParallelPortData data;
    192 
    193         /* Load options: */
    194         data.m_iSlot = uSlot;
    195         data.m_fPortEnabled = port.GetEnabled();
    196         data.m_uIRQ = port.GetIRQ();
    197         data.m_uIOBase = port.GetIOBase();
    198         data.m_strPath = port.GetPath();
    199 
    200         /* Append adapter's data container: */
    201         m_cache.m_items << data;
     205    /* For each parallel port: */
     206    for (int iSlot = 0; iSlot < mTabWidget->count(); ++iSlot)
     207    {
     208        /* Prepare port data: */
     209        UIDataSettingsMachineParallelPort portData;
     210
     211        /* Check if port is valid: */
     212        const CParallelPort &port = m_machine.GetParallelPort(iSlot);
     213        if (!port.isNull())
     214        {
     215            /* Gather options: */
     216            portData.m_iSlot = iSlot;
     217            portData.m_fPortEnabled = port.GetEnabled();
     218            portData.m_uIRQ = port.GetIRQ();
     219            portData.m_uIOBase = port.GetIOBase();
     220            portData.m_strPath = port.GetPath();
     221        }
     222
     223        /* Cache port data: */
     224        m_cache.child(iSlot).cacheInitialData(portData);
    202225    }
    203226
     
    210233void UIMachineSettingsParallelPage::getFromCache()
    211234{
     235    /* Setup tab order: */
    212236    Assert(firstWidget());
    213237    setTabOrder(firstWidget(), mTabWidget->focusProxy());
    214238    QWidget *pLastFocusWidget = mTabWidget->focusProxy();
    215239
    216     /* Apply internal variables data to QWidget(s): */
    217     for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
    218     {
    219         /* Creating port's page: */
    220         UIMachineSettingsParallel *pPage = new UIMachineSettingsParallel(this);
    221 
    222         /* Loading port's data into page: */
    223         pPage->fetchPortData(m_cache.m_items[iSlot]);
    224 
    225         /* Attach port's page to Tab Widget: */
    226         mTabWidget->addTab(pPage, pPage->pageTitle());
     240    /* For each parallel port: */
     241    for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
     242    {
     243        /* Get port page: */
     244        UIMachineSettingsParallel *pPage = qobject_cast<UIMachineSettingsParallel*>(mTabWidget->widget(iPort));
     245
     246        /* Load port data to page: */
     247        pPage->fetchPortData(m_cache.child(iPort));
    227248
    228249        /* Setup page validation: */
     
    244265void UIMachineSettingsParallelPage::putToCache()
    245266{
    246     /* Gather internal variables data from QWidget(s): */
    247     for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
    248     {
    249         /* Getting adapter's page: */
    250         UIMachineSettingsParallel *pPage = qobject_cast<UIMachineSettingsParallel*>(mTabWidget->widget(iSlot));
    251 
    252         /* Loading Adapter's data from page: */
    253         pPage->uploadPortData(m_cache.m_items[iSlot]);
     267    /* For each parallel port: */
     268    for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
     269    {
     270        /* Getting port page: */
     271        UIMachineSettingsParallel *pPage = qobject_cast<UIMachineSettingsParallel*>(mTabWidget->widget(iPort));
     272
     273        /* Gather & cache port data: */
     274        pPage->uploadPortData(m_cache.child(iPort));
    254275    }
    255276}
     
    262283    UISettingsPageMachine::fetchData(data);
    263284
    264     if (isMachineOffline())
    265     {
    266         /* Gather corresponding values from internal variables: */
    267         for (int iSlot = 0; iSlot < m_cache.m_items.size(); ++iSlot)
     285    /* Check if ports data was changed: */
     286    if (m_cache.wasChanged())
     287    {
     288        /* For each parallel port: */
     289        for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
    268290        {
    269             /* Get adapter: */
    270             CParallelPort port = m_machine.GetParallelPort(iSlot);
    271 
    272             /* Get cached data for this slot: */
    273             const UIParallelPortData &data = m_cache.m_items[iSlot];
    274 
    275             /* Save options: */
    276             port.SetIRQ(data.m_uIRQ);
    277             port.SetIOBase(data.m_uIOBase);
    278             port.SetPath(data.m_strPath);
    279             port.SetEnabled(data.m_fPortEnabled);
     291            /* Check if port data was changed: */
     292            const UICacheSettingsMachineParallelPort &portCache = m_cache.child(iPort);
     293            if (portCache.wasChanged())
     294            {
     295                /* Check if port still valid: */
     296                CParallelPort port = m_machine.GetParallelPort(iPort);
     297                if (!port.isNull())
     298                {
     299                    /* Get port data from cache: */
     300                    const UIDataSettingsMachineParallelPort &portData = portCache.data();
     301
     302                    /* Store adapter data: */
     303                    if (isMachineOffline())
     304                    {
     305                        port.SetIRQ(portData.m_uIRQ);
     306                        port.SetIOBase(portData.m_uIOBase);
     307                        port.SetPath(portData.m_strPath);
     308                        port.SetEnabled(portData.m_fPortEnabled);
     309                    }
     310                }
     311            }
    280312        }
    281313    }
     
    352384{
    353385    /* Get the count of parallel port tabs: */
    354     for (int iTabIndex = 0; iTabIndex < mTabWidget->count(); ++iTabIndex)
    355     {
    356         mTabWidget->setTabEnabled(iTabIndex,
     386    for (int iPort = 0; iPort < mTabWidget->count(); ++iPort)
     387    {
     388        mTabWidget->setTabEnabled(iPort,
    357389                                  isMachineOffline() ||
    358                                   (isMachineInValidMode() && m_cache.m_items[iTabIndex].m_fPortEnabled));
    359         UIMachineSettingsParallel *pTab = qobject_cast<UIMachineSettingsParallel*>(mTabWidget->widget(iTabIndex));
    360         Assert(pTab);
     390                                  (isMachineInValidMode() && m_cache.child(iPort).base().m_fPortEnabled));
     391        UIMachineSettingsParallel *pTab = qobject_cast<UIMachineSettingsParallel*>(mTabWidget->widget(iPort));
    361392        pTab->polishTab();
    362393    }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsParallel.h

    r36357 r36930  
    2828class QITabWidget;
    2929
    30 struct UIParallelPortData
     30/* Machine settings / Parallel page / Port data: */
     31struct UIDataSettingsMachineParallelPort
    3132{
     33    /* Default constructor: */
     34    UIDataSettingsMachineParallelPort()
     35        : m_iSlot(-1)
     36        , m_fPortEnabled(false)
     37        , m_uIRQ(0)
     38        , m_uIOBase(0)
     39        , m_strPath(QString()) {}
     40    /* Functions: */
     41    bool equal(const UIDataSettingsMachineParallelPort &other) const
     42    {
     43        return (m_iSlot == other.m_iSlot) &&
     44               (m_fPortEnabled == other.m_fPortEnabled) &&
     45               (m_uIRQ == other.m_uIRQ) &&
     46               (m_uIOBase == other.m_uIOBase) &&
     47               (m_strPath == other.m_strPath);
     48    }
     49    /* Operators: */
     50    bool operator==(const UIDataSettingsMachineParallelPort &other) const { return equal(other); }
     51    bool operator!=(const UIDataSettingsMachineParallelPort &other) const { return !equal(other); }
     52    /* Variables: */
    3253    int m_iSlot;
    3354    bool m_fPortEnabled;
     
    3657    QString m_strPath;
    3758};
     59typedef UISettingsCache<UIDataSettingsMachineParallelPort> UICacheSettingsMachineParallelPort;
    3860
    39 /* Machine settings / Parallel page / Cache: */
    40 struct UISettingsCacheMachineParallel
     61/* Machine settings / Parallel page / Ports data: */
     62struct UIDataSettingsMachineParallel
    4163{
    42     QList<UIParallelPortData> m_items;
     64    /* Default constructor: */
     65    UIDataSettingsMachineParallel() {}
     66    /* Operators: */
     67    bool operator==(const UIDataSettingsMachineParallel& /* other */) const { return true; }
     68    bool operator!=(const UIDataSettingsMachineParallel& /* other */) const { return false; }
    4369};
     70typedef UISettingsCachePool<UIDataSettingsMachineParallel, UICacheSettingsMachineParallelPort> UICacheSettingsMachineParallel;
    4471
    4572class UIMachineSettingsParallel : public QIWithRetranslateUI<QWidget>,
     
    5481    void polishTab();
    5582
    56     void fetchPortData(const UIParallelPortData &data);
    57     void uploadPortData(UIParallelPortData &data);
     83    void fetchPortData(const UICacheSettingsMachineParallelPort &portCache);
     84    void uploadPortData(UICacheSettingsMachineParallelPort &portCache);
    5885
    5986    void setValidator (QIWidgetValidator *aVal);
     
    117144    QITabWidget *mTabWidget;
    118145
    119     /* Internals: */
    120     UISettingsCacheMachineParallel m_cache;
     146    /* Cache: */
     147    UICacheSettingsMachineParallel m_cache;
    121148};
    122149
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