VirtualBox

Changeset 66365 in vbox


Ignore:
Timestamp:
Mar 30, 2017 2:06:36 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Machine settings: Parallel Port page: Proper loading, caching, saving.

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

    r66345 r66365  
    8181{
    8282    /** Constructs data. */
    83     UIDataSettingsMachineParallel() {}
     83    UIDataSettingsMachineParallel()
     84        : m_ports(QList<UIDataSettingsMachineParallelPort>())
     85    {}
    8486
    8587    /** Returns whether the @a other passed data is equal to this one. */
    86     bool operator==(const UIDataSettingsMachineParallel & /* other */) const { return true; }
     88    bool equal(const UIDataSettingsMachineParallel &other) const
     89    {
     90        return true
     91               && (m_ports == other.m_ports)
     92               ;
     93    }
     94
     95    /** Returns whether the @a other passed data is equal to this one. */
     96    bool operator==(const UIDataSettingsMachineParallel &other) const { return equal(other); }
    8797    /** Returns whether the @a other passed data is different from this one. */
    88     bool operator!=(const UIDataSettingsMachineParallel & /* other */) const { return false; }
     98    bool operator!=(const UIDataSettingsMachineParallel &other) const { return !equal(other); }
     99
     100    /** Holds the port list. */
     101    QList<UIDataSettingsMachineParallelPort> m_ports;
    89102};
    90103
     
    102115    void polishTab();
    103116
    104     void fetchPortData(const UISettingsCacheMachineParallelPort &portCache);
    105     void uploadPortData(UISettingsCacheMachineParallelPort &portCache);
    106 
    107     QWidget* setOrderAfter (QWidget *aAfter);
     117    void loadPortData(const UIDataSettingsMachineParallelPort &portData);
     118    void savePortData(UIDataSettingsMachineParallelPort &portData);
     119
     120    QWidget *setOrderAfter(QWidget *pAfter);
    108121
    109122    QString pageTitle() const;
     
    116129private slots:
    117130
    118     void mGbParallelToggled (bool aOn);
    119     void mCbNumberActivated (const QString &aText);
     131    void sltGbParallelToggled(bool fOn);
     132    void sltCbNumberActivated(const QString &strText);
    120133
    121134private:
     
    134147
    135148UIMachineSettingsParallel::UIMachineSettingsParallel(UIMachineSettingsParallelPage *pParent)
    136     : QIWithRetranslateUI<QWidget> (0)
     149    : QIWithRetranslateUI<QWidget>(0)
    137150    , m_pParent(pParent)
    138151    , m_iSlot(-1)
    139152{
    140     /* Apply UI decorations */
    141     Ui::UIMachineSettingsParallel::setupUi (this);
    142 
    143     /* Setup validation */
    144     mLeIRQ->setValidator (new QIULongValidator (0, 255, this));
    145     mLeIOPort->setValidator (new QIULongValidator (0, 0xFFFF, this));
    146     mLePath->setValidator (new QRegExpValidator (QRegExp (".+"), this));
    147 
    148     /* Setup constraints */
    149     mLeIRQ->setFixedWidth (mLeIRQ->fontMetrics().width ("8888"));
    150     mLeIOPort->setFixedWidth (mLeIOPort->fontMetrics().width ("8888888"));
    151 
    152     /* Set initial values */
     153    /* Apply UI decorations: */
     154    Ui::UIMachineSettingsParallel::setupUi(this);
     155
     156    /* Setup validation: */
     157    mLeIRQ->setValidator(new QIULongValidator(0, 255, this));
     158    mLeIOPort->setValidator(new QIULongValidator(0, 0xFFFF, this));
     159    mLePath->setValidator(new QRegExpValidator(QRegExp(".+"), this));
     160
     161    /* Setup constraints: */
     162    mLeIRQ->setFixedWidth(mLeIRQ->fontMetrics().width("8888"));
     163    mLeIOPort->setFixedWidth(mLeIOPort->fontMetrics().width("8888888"));
     164
     165    /* Set initial values: */
    153166    /* Note: If you change one of the following don't forget retranslateUi. */
    154     mCbNumber->insertItem (0, vboxGlobal().toCOMPortName (0, 0));
    155     mCbNumber->insertItems (0, vboxGlobal().COMPortNames());
    156 
    157     /* Setup connections */
    158     connect (mGbParallel, SIGNAL (toggled (bool)),
    159              this, SLOT (mGbParallelToggled (bool)));
    160     connect (mCbNumber, SIGNAL (activated (const QString &)),
    161              this, SLOT (mCbNumberActivated (const QString &)));
     167    mCbNumber->insertItem(0, vboxGlobal().toCOMPortName(0, 0));
     168    mCbNumber->insertItems(0, vboxGlobal().COMPortNames());
     169
     170    /* Setup connections: */
     171    connect(mGbParallel, SIGNAL(toggled(bool)),
     172            this, SLOT(sltGbParallelToggled(bool)));
     173    connect(mCbNumber, SIGNAL(activated(const QString &)),
     174            this, SLOT(sltCbNumberActivated(const QString &)));
    162175
    163176    /* Prepare validation: */
    164177    prepareValidation();
    165178
    166     /* Applying language settings */
     179    /* Apply language settings: */
    167180    retranslateUi();
    168181}
     
    172185    /* Polish port page: */
    173186    ulong uIRQ, uIOBase;
    174     bool fStd = vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase);
     187    const bool fStd = vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), uIRQ, uIOBase);
    175188    mGbParallel->setEnabled(m_pParent->isMachineOffline());
    176189    mLbNumber->setEnabled(m_pParent->isMachineOffline());
     
    184197}
    185198
    186 void UIMachineSettingsParallel::fetchPortData(const UISettingsCacheMachineParallelPort &portCache)
    187 {
    188     /* Get port data: */
    189     const UIDataSettingsMachineParallelPort &portData = portCache.base();
    190 
     199void UIMachineSettingsParallel::loadPortData(const UIDataSettingsMachineParallelPort &portData)
     200{
    191201    /* Load port number: */
    192202    m_iSlot = portData.m_iSlot;
     
    199209    mLePath->setText(portData.m_strPath);
    200210
    201     /* Ensure everything is up-to-date */
    202     mGbParallelToggled(mGbParallel->isChecked());
    203 }
    204 
    205 void UIMachineSettingsParallel::uploadPortData(UISettingsCacheMachineParallelPort &portCache)
    206 {
    207     /* Prepare port data: */
    208     UIDataSettingsMachineParallelPort portData = portCache.base();
    209 
     211    /* Ensure everything is up-to-date: */
     212    sltGbParallelToggled(mGbParallel->isChecked());
     213}
     214
     215void UIMachineSettingsParallel::savePortData(UIDataSettingsMachineParallelPort &portData)
     216{
    210217    /* Save port data: */
    211218    portData.m_fPortEnabled = mGbParallel->isChecked();
     
    213220    portData.m_uIOBase = mLeIOPort->text().toULong(NULL, 0);
    214221    portData.m_strPath = QDir::toNativeSeparators(mLePath->text());
    215 
    216     /* Cache port data: */
    217     portCache.cacheCurrentData(portData);
    218 }
    219 
    220 QWidget* UIMachineSettingsParallel::setOrderAfter (QWidget *aAfter)
    221 {
    222     setTabOrder (aAfter, mGbParallel);
    223     setTabOrder (mGbParallel, mCbNumber);
    224     setTabOrder (mCbNumber, mLeIRQ);
    225     setTabOrder (mLeIRQ, mLeIOPort);
    226     setTabOrder (mLeIOPort, mLePath);
     222}
     223
     224QWidget *UIMachineSettingsParallel::setOrderAfter(QWidget *pAfter)
     225{
     226    setTabOrder(pAfter, mGbParallel);
     227    setTabOrder(mGbParallel, mCbNumber);
     228    setTabOrder(mCbNumber, mLeIRQ);
     229    setTabOrder(mLeIRQ, mLeIOPort);
     230    setTabOrder(mLeIOPort, mLePath);
    227231    return mLePath;
    228232}
     
    236240{
    237241    ulong a, b;
    238     return !vboxGlobal().toCOMPortNumbers (mCbNumber->currentText(), a, b);
     242    return !vboxGlobal().toCOMPortNumbers(mCbNumber->currentText(), a, b);
    239243}
    240244
    241245void UIMachineSettingsParallel::retranslateUi()
    242246{
    243     /* Translate uic generated strings */
    244     Ui::UIMachineSettingsParallel::retranslateUi (this);
    245 
    246     mCbNumber->setItemText (mCbNumber->count() - 1, vboxGlobal().toCOMPortName (0, 0));
    247 }
    248 
    249 void UIMachineSettingsParallel::mGbParallelToggled (bool aOn)
    250 {
    251     if (aOn)
    252         mCbNumberActivated (mCbNumber->currentText());
     247    /* Translate uic generated strings: */
     248    Ui::UIMachineSettingsParallel::retranslateUi(this);
     249
     250    mCbNumber->setItemText(mCbNumber->count() - 1, vboxGlobal().toCOMPortName(0, 0));
     251}
     252
     253void UIMachineSettingsParallel::sltGbParallelToggled(bool fOn)
     254{
     255    if (fOn)
     256        sltCbNumberActivated(mCbNumber->currentText());
    253257
    254258    /* Revalidate: */
     
    256260}
    257261
    258 void UIMachineSettingsParallel::mCbNumberActivated (const QString &aText)
    259 {
    260     ulong IRQ, IOBase;
    261     bool std = vboxGlobal().toCOMPortNumbers (aText, IRQ, IOBase);
    262 
    263     mLeIRQ->setEnabled (!std);
    264     mLeIOPort->setEnabled (!std);
    265     if (std)
    266     {
    267         mLeIRQ->setText (QString::number (IRQ));
    268         mLeIOPort->setText ("0x" + QString::number (IOBase, 16).toUpper());
     262void UIMachineSettingsParallel::sltCbNumberActivated(const QString &strText)
     263{
     264    ulong uIRQ, uIOBase;
     265    bool fStd = vboxGlobal().toCOMPortNumbers(strText, uIRQ, uIOBase);
     266
     267    mLeIRQ->setEnabled(!fStd);
     268    mLeIOPort->setEnabled(!fStd);
     269    if (fStd)
     270    {
     271        mLeIRQ->setText(QString::number(uIRQ));
     272        mLeIOPort->setText("0x" + QString::number(uIOBase, 16).toUpper());
    269273    }
    270274
     
    313317    m_pCache->clear();
    314318
     319    /* Prepare initial data: */
     320    UIDataSettingsMachineParallel initialData;
     321
    315322    /* For each parallel port: */
    316323    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
    317324    {
    318325        /* Prepare port data: */
    319         UIDataSettingsMachineParallelPort portData;
     326        UIDataSettingsMachineParallelPort initialPortData;
    320327
    321328        /* Check if port is valid: */
     
    324331        {
    325332            /* Gather options: */
    326             portData.m_iSlot = iSlot;
    327             portData.m_fPortEnabled = port.GetEnabled();
    328             portData.m_uIRQ = port.GetIRQ();
    329             portData.m_uIOBase = port.GetIOBase();
    330             portData.m_strPath = port.GetPath();
    331         }
    332 
    333         /* Cache port data: */
    334         m_pCache->child(iSlot).cacheInitialData(portData);
    335     }
     333            initialPortData.m_iSlot = iSlot;
     334            initialPortData.m_fPortEnabled = port.GetEnabled();
     335            initialPortData.m_uIRQ = port.GetIRQ();
     336            initialPortData.m_uIOBase = port.GetIOBase();
     337            initialPortData.m_strPath = port.GetPath();
     338        }
     339
     340        /* Append initial port data: */
     341        initialData.m_ports << initialPortData;
     342    }
     343
     344    /* Cache initial data: */
     345    m_pCache->cacheInitialData(initialData);
    336346
    337347    /* Upload machine to data: */
     
    342352{
    343353    /* Setup tab order: */
    344     Assert(firstWidget());
     354    AssertPtrReturnVoid(firstWidget());
    345355    setTabOrder(firstWidget(), m_pTabWidget->focusProxy());
    346356    QWidget *pLastFocusWidget = m_pTabWidget->focusProxy();
     
    353363
    354364        /* Load port data to page: */
    355         pPage->fetchPortData(m_pCache->child(iPort));
     365        pPage->loadPortData(m_pCache->base().m_ports.at(iPort));
    356366
    357367        /* Setup tab order: */
     
    371381void UIMachineSettingsParallelPage::putToCache()
    372382{
     383    /* Prepare current data: */
     384    UIDataSettingsMachineParallel currentData;
     385
    373386    /* For each parallel port: */
    374387    for (int iPort = 0; iPort < m_pTabWidget->count(); ++iPort)
    375388    {
    376389        /* Getting port page: */
    377         UIMachineSettingsParallel *pPage = qobject_cast<UIMachineSettingsParallel*>(m_pTabWidget->widget(iPort));
    378 
    379         /* Gather & cache port data: */
    380         pPage->uploadPortData(m_pCache->child(iPort));
    381     }
     390        UIMachineSettingsParallel *pTab = qobject_cast<UIMachineSettingsParallel*>(m_pTabWidget->widget(iPort));
     391
     392        /* Prepare current port data: */
     393        UIDataSettingsMachineParallelPort currentPortData;
     394
     395        /* Gather current port data: */
     396        pTab->savePortData(currentPortData);
     397
     398        /* Cache current port data: */
     399        currentData.m_ports << currentPortData;
     400    }
     401
     402    /* Cache current data: */
     403    m_pCache->cacheCurrentData(currentData);
    382404}
    383405
     
    394416        {
    395417            /* Check if port data was changed: */
    396             const UISettingsCacheMachineParallelPort &portCache = m_pCache->child(iPort);
    397             if (portCache.wasChanged())
     418            const UIDataSettingsMachineParallelPort &initialPortData = m_pCache->base().m_ports.at(iPort);
     419            const UIDataSettingsMachineParallelPort &currentPortData = m_pCache->data().m_ports.at(iPort);
     420            if (currentPortData != initialPortData)
    398421            {
    399422                /* Check if port still valid: */
     
    401424                if (!port.isNull())
    402425                {
    403                     /* Get port data from cache: */
    404                     const UIDataSettingsMachineParallelPort &portData = portCache.data();
    405 
    406                     /* Store adapter data: */
     426                    /* Store port data: */
    407427                    if (isMachineOffline())
    408428                    {
    409                         port.SetIRQ(portData.m_uIRQ);
    410                         port.SetIOBase(portData.m_uIOBase);
    411                         port.SetPath(portData.m_strPath);
    412                         port.SetEnabled(portData.m_fPortEnabled);
     429                        /* Whether the port is enabled: */
     430                        if (   port.isOk()
     431                            && currentPortData.m_fPortEnabled != initialPortData.m_fPortEnabled)
     432                            port.SetEnabled(currentPortData.m_fPortEnabled);
     433                        /* Port IRQ: */
     434                        if (   port.isOk()
     435                            && currentPortData.m_uIRQ != initialPortData.m_uIRQ)
     436                            port.SetIRQ(currentPortData.m_uIRQ);
     437                        /* Port IO base: */
     438                        if (   port.isOk()
     439                            && currentPortData.m_uIOBase != initialPortData.m_uIOBase)
     440                            port.SetIOBase(currentPortData.m_uIOBase);
     441                        /* Port path: */
     442                        if (   port.isOk()
     443                            && currentPortData.m_strPath != initialPortData.m_strPath)
     444                            port.SetPath(currentPortData.m_strPath);
    413445                    }
    414446                }
     
    503535    {
    504536        m_pTabWidget->setTabEnabled(iPort,
    505                                   isMachineOffline() ||
    506                                   (isMachineInValidMode() && m_pCache->child(iPort).base().m_fPortEnabled));
     537                                    isMachineOffline() ||
     538                                    (isMachineInValidMode() && m_pCache->base().m_ports.at(iPort).m_fPortEnabled));
    507539        UIMachineSettingsParallel *pTab = qobject_cast<UIMachineSettingsParallel*>(m_pTabWidget->widget(iPort));
    508540        pTab->polishTab();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsParallel.h

    r66345 r66365  
    2727class UIMachineSettingsParallelPage;
    2828struct UIDataSettingsMachineParallel;
    29 struct UIDataSettingsMachineParallelPort;
    30 typedef UISettingsCache<UIDataSettingsMachineParallelPort> UISettingsCacheMachineParallelPort;
    31 typedef UISettingsCachePool<UIDataSettingsMachineParallel, UISettingsCacheMachineParallelPort> UISettingsCacheMachineParallel;
     29typedef UISettingsCache<UIDataSettingsMachineParallel> UISettingsCacheMachineParallel;
    3230
    3331
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